summaryrefslogtreecommitdiffstats
path: root/tests/ui/shadowed
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/shadowed')
-rw-r--r--tests/ui/shadowed/shadowed-lifetime.rs24
-rw-r--r--tests/ui/shadowed/shadowed-lifetime.stderr19
-rw-r--r--tests/ui/shadowed/shadowed-trait-methods.rs14
-rw-r--r--tests/ui/shadowed/shadowed-trait-methods.stderr18
-rw-r--r--tests/ui/shadowed/shadowed-type-parameter.rs30
-rw-r--r--tests/ui/shadowed/shadowed-type-parameter.stderr29
-rw-r--r--tests/ui/shadowed/shadowed-use-visibility.rs16
-rw-r--r--tests/ui/shadowed/shadowed-use-visibility.stderr37
-rw-r--r--tests/ui/shadowed/shadowing-in-the-same-pattern.rs7
-rw-r--r--tests/ui/shadowed/shadowing-in-the-same-pattern.stderr16
10 files changed, 210 insertions, 0 deletions
diff --git a/tests/ui/shadowed/shadowed-lifetime.rs b/tests/ui/shadowed/shadowed-lifetime.rs
new file mode 100644
index 000000000..9487b4f4e
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-lifetime.rs
@@ -0,0 +1,24 @@
+// Test that shadowed lifetimes generate an error.
+
+struct Foo<'a>(&'a isize);
+
+impl<'a> Foo<'a> {
+ fn shadow_in_method<'a>(&'a self) -> &'a isize {
+ //~^ ERROR lifetime name `'a` shadows a lifetime name that is already in scope
+ self.0
+ }
+
+ fn shadow_in_type<'b>(&'b self) -> &'b isize {
+ let x: for<'b> fn(&'b isize) = panic!();
+ //~^ ERROR lifetime name `'b` shadows a lifetime name that is already in scope
+ self.0
+ }
+
+ fn not_shadow_in_item<'b>(&'b self) {
+ struct Bar<'a, 'b>(&'a isize, &'b isize); // not a shadow, separate item
+ fn foo<'a, 'b>(x: &'a isize, y: &'b isize) { } // same
+ }
+}
+
+fn main() {
+}
diff --git a/tests/ui/shadowed/shadowed-lifetime.stderr b/tests/ui/shadowed/shadowed-lifetime.stderr
new file mode 100644
index 000000000..68cc505d3
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-lifetime.stderr
@@ -0,0 +1,19 @@
+error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
+ --> $DIR/shadowed-lifetime.rs:6:25
+ |
+LL | impl<'a> Foo<'a> {
+ | -- first declared here
+LL | fn shadow_in_method<'a>(&'a self) -> &'a isize {
+ | ^^ lifetime `'a` already in scope
+
+error[E0496]: lifetime name `'b` shadows a lifetime name that is already in scope
+ --> $DIR/shadowed-lifetime.rs:12:20
+ |
+LL | fn shadow_in_type<'b>(&'b self) -> &'b isize {
+ | -- first declared here
+LL | let x: for<'b> fn(&'b isize) = panic!();
+ | ^^ lifetime `'b` already in scope
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0496`.
diff --git a/tests/ui/shadowed/shadowed-trait-methods.rs b/tests/ui/shadowed/shadowed-trait-methods.rs
new file mode 100644
index 000000000..f9c25d979
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-trait-methods.rs
@@ -0,0 +1,14 @@
+// Test that methods from shadowed traits cannot be used
+
+mod foo {
+ pub trait T { fn f(&self) {} }
+ impl T for () {}
+}
+
+mod bar { pub use foo::T; }
+
+fn main() {
+ pub use bar::*;
+ struct T;
+ ().f() //~ ERROR no method
+}
diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr
new file mode 100644
index 000000000..c3b9084af
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-trait-methods.stderr
@@ -0,0 +1,18 @@
+error[E0599]: no method named `f` found for unit type `()` in the current scope
+ --> $DIR/shadowed-trait-methods.rs:13:8
+ |
+LL | pub trait T { fn f(&self) {} }
+ | - the method is available for `()` here
+...
+LL | ().f()
+ | ^ method not found in `()`
+ |
+ = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+ |
+LL | use foo::T;
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/shadowed/shadowed-type-parameter.rs b/tests/ui/shadowed/shadowed-type-parameter.rs
new file mode 100644
index 000000000..66fd68a9f
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-type-parameter.rs
@@ -0,0 +1,30 @@
+// Test that shadowed lifetimes generate an error.
+
+
+struct Foo<T>(T);
+
+
+impl<T> Foo<T> {
+ fn shadow_in_method<T>(&self) {}
+ //~^ ERROR the name `T` is already used
+
+ fn not_shadow_in_item<U>(&self) {
+ struct Bar<T, U>(T,U); // not a shadow, separate item
+ fn foo<T, U>() {} // same
+ }
+}
+
+trait Bar<T> {
+ fn dummy(&self) -> T;
+
+ fn shadow_in_required<T>(&self);
+ //~^ ERROR the name `T` is already used
+
+ fn shadow_in_provided<T>(&self) {}
+ //~^ ERROR the name `T` is already used
+
+ fn not_shadow_in_required<U>(&self);
+ fn not_shadow_in_provided<U>(&self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/shadowed/shadowed-type-parameter.stderr b/tests/ui/shadowed/shadowed-type-parameter.stderr
new file mode 100644
index 000000000..0ea82f983
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-type-parameter.stderr
@@ -0,0 +1,29 @@
+error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
+ --> $DIR/shadowed-type-parameter.rs:8:25
+ |
+LL | impl<T> Foo<T> {
+ | - first use of `T`
+LL | fn shadow_in_method<T>(&self) {}
+ | ^ already used
+
+error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
+ --> $DIR/shadowed-type-parameter.rs:20:27
+ |
+LL | trait Bar<T> {
+ | - first use of `T`
+...
+LL | fn shadow_in_required<T>(&self);
+ | ^ already used
+
+error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
+ --> $DIR/shadowed-type-parameter.rs:23:27
+ |
+LL | trait Bar<T> {
+ | - first use of `T`
+...
+LL | fn shadow_in_provided<T>(&self) {}
+ | ^ already used
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0403`.
diff --git a/tests/ui/shadowed/shadowed-use-visibility.rs b/tests/ui/shadowed/shadowed-use-visibility.rs
new file mode 100644
index 000000000..6b801972f
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-use-visibility.rs
@@ -0,0 +1,16 @@
+mod foo {
+ pub fn f() {}
+
+ use foo as bar;
+ pub use self::f as bar;
+}
+
+mod bar {
+ use foo::bar::f as g; //~ ERROR module import `bar` is private
+
+ use foo as f;
+ pub use foo::*;
+}
+
+use bar::f::f; //~ ERROR module import `f` is private
+fn main() {}
diff --git a/tests/ui/shadowed/shadowed-use-visibility.stderr b/tests/ui/shadowed/shadowed-use-visibility.stderr
new file mode 100644
index 000000000..1a642ae6e
--- /dev/null
+++ b/tests/ui/shadowed/shadowed-use-visibility.stderr
@@ -0,0 +1,37 @@
+error[E0603]: module import `bar` is private
+ --> $DIR/shadowed-use-visibility.rs:9:14
+ |
+LL | use foo::bar::f as g;
+ | ^^^ private module import
+ |
+note: the module import `bar` is defined here...
+ --> $DIR/shadowed-use-visibility.rs:4:9
+ |
+LL | use foo as bar;
+ | ^^^^^^^^^^
+note: ...and refers to the module `foo` which is defined here
+ --> $DIR/shadowed-use-visibility.rs:1:1
+ |
+LL | mod foo {
+ | ^^^^^^^
+
+error[E0603]: module import `f` is private
+ --> $DIR/shadowed-use-visibility.rs:15:10
+ |
+LL | use bar::f::f;
+ | ^ private module import
+ |
+note: the module import `f` is defined here...
+ --> $DIR/shadowed-use-visibility.rs:11:9
+ |
+LL | use foo as f;
+ | ^^^^^^^^
+note: ...and refers to the module `foo` which is defined here
+ --> $DIR/shadowed-use-visibility.rs:1:1
+ |
+LL | mod foo {
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0603`.
diff --git a/tests/ui/shadowed/shadowing-in-the-same-pattern.rs b/tests/ui/shadowed/shadowing-in-the-same-pattern.rs
new file mode 100644
index 000000000..f5872f9fb
--- /dev/null
+++ b/tests/ui/shadowed/shadowing-in-the-same-pattern.rs
@@ -0,0 +1,7 @@
+// Test for issue #14581.
+
+fn f((a, a): (isize, isize)) {} //~ ERROR identifier `a` is bound more than once
+
+fn main() {
+ let (a, a) = (1, 1); //~ ERROR identifier `a` is bound more than once
+}
diff --git a/tests/ui/shadowed/shadowing-in-the-same-pattern.stderr b/tests/ui/shadowed/shadowing-in-the-same-pattern.stderr
new file mode 100644
index 000000000..1c51653db
--- /dev/null
+++ b/tests/ui/shadowed/shadowing-in-the-same-pattern.stderr
@@ -0,0 +1,16 @@
+error[E0415]: identifier `a` is bound more than once in this parameter list
+ --> $DIR/shadowing-in-the-same-pattern.rs:3:10
+ |
+LL | fn f((a, a): (isize, isize)) {}
+ | ^ used as parameter more than once
+
+error[E0416]: identifier `a` is bound more than once in the same pattern
+ --> $DIR/shadowing-in-the-same-pattern.rs:6:13
+ |
+LL | let (a, a) = (1, 1);
+ | ^ used in a pattern more than once
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0415, E0416.
+For more information about an error, try `rustc --explain E0415`.