about summary refs log tree commit diff
path: root/src/test/ui/lifetimes
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-02-09 18:42:32 -0800
committerMichael Goulet <michael@errs.io>2022-02-24 18:50:33 -0800
commitbb548a918adc8a4cf63320d3f8b9f1d2ff2622ea (patch)
treebbba240088f42c91fdd598b607655e2f2dc7db54 /src/test/ui/lifetimes
parent4e82f35492ea5c78e19609bf4468f0a686d9a756 (diff)
downloadrust-bb548a918adc8a4cf63320d3f8b9f1d2ff2622ea.tar.gz
rust-bb548a918adc8a4cf63320d3f8b9f1d2ff2622ea.zip
Remove in-band lifetimes
Diffstat (limited to 'src/test/ui/lifetimes')
-rw-r--r--src/test/ui/lifetimes/missing-lifetime-in-alias.rs33
-rw-r--r--src/test/ui/lifetimes/missing-lifetime-in-alias.stderr43
-rw-r--r--src/test/ui/lifetimes/nested.rs7
-rw-r--r--src/test/ui/lifetimes/shadow.rs8
-rw-r--r--src/test/ui/lifetimes/shadow.stderr20
-rw-r--r--src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr5
6 files changed, 111 insertions, 5 deletions
diff --git a/src/test/ui/lifetimes/missing-lifetime-in-alias.rs b/src/test/ui/lifetimes/missing-lifetime-in-alias.rs
new file mode 100644
index 00000000000..af7b6412780
--- /dev/null
+++ b/src/test/ui/lifetimes/missing-lifetime-in-alias.rs
@@ -0,0 +1,33 @@
+#![feature(generic_associated_types)]
+
+trait Trait<'a> {
+    type Foo;
+
+    type Bar<'b>
+    //~^ NOTE associated type defined here, with 1 lifetime parameter
+    //~| NOTE
+    where
+        Self: 'b;
+}
+
+struct Impl<'a>(&'a ());
+
+impl<'a> Trait<'a> for Impl<'a> {
+    type Foo = &'a ();
+    type Bar<'b> = &'b ();
+}
+
+type A<'a> = Impl<'a>;
+
+type B<'a> = <A<'a> as Trait>::Foo;
+//~^ ERROR missing lifetime specifier
+//~| NOTE expected named lifetime parameter
+
+type C<'a, 'b> = <A<'a> as Trait>::Bar;
+//~^ ERROR missing lifetime specifier
+//~| ERROR missing generics for associated type
+//~| NOTE expected named lifetime parameter
+//~| NOTE these named lifetimes are available to use
+//~| NOTE expected 1 lifetime argument
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr b/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr
new file mode 100644
index 00000000000..b16b792aefe
--- /dev/null
+++ b/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr
@@ -0,0 +1,43 @@
+error[E0106]: missing lifetime specifier
+  --> $DIR/missing-lifetime-in-alias.rs:22:24
+   |
+LL | type B<'a> = <A<'a> as Trait>::Foo;
+   |                        ^^^^^ expected named lifetime parameter
+   |
+help: consider using the `'a` lifetime
+   |
+LL | type B<'a> = <A<'a> as Trait<'a>>::Foo;
+   |                        ~~~~~~~~~
+
+error[E0106]: missing lifetime specifier
+  --> $DIR/missing-lifetime-in-alias.rs:26:28
+   |
+LL | type C<'a, 'b> = <A<'a> as Trait>::Bar;
+   |                            ^^^^^ expected named lifetime parameter
+   |
+note: these named lifetimes are available to use
+  --> $DIR/missing-lifetime-in-alias.rs:26:8
+   |
+LL | type C<'a, 'b> = <A<'a> as Trait>::Bar;
+   |        ^^  ^^
+
+error[E0107]: missing generics for associated type `Trait::Bar`
+  --> $DIR/missing-lifetime-in-alias.rs:26:36
+   |
+LL | type C<'a, 'b> = <A<'a> as Trait>::Bar;
+   |                                    ^^^ expected 1 lifetime argument
+   |
+note: associated type defined here, with 1 lifetime parameter: `'b`
+  --> $DIR/missing-lifetime-in-alias.rs:6:10
+   |
+LL |     type Bar<'b>
+   |          ^^^ --
+help: add missing lifetime argument
+   |
+LL | type C<'a, 'b> = <A<'a> as Trait>::Bar<'a>;
+   |                                    ~~~~~~~
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0106, E0107.
+For more information about an error, try `rustc --explain E0106`.
diff --git a/src/test/ui/lifetimes/nested.rs b/src/test/ui/lifetimes/nested.rs
new file mode 100644
index 00000000000..f3f1f2016f2
--- /dev/null
+++ b/src/test/ui/lifetimes/nested.rs
@@ -0,0 +1,7 @@
+// check-pass
+
+fn method<'a>(_i: &'a i32) {
+    fn inner<'a>(_j: &'a f32) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/shadow.rs b/src/test/ui/lifetimes/shadow.rs
new file mode 100644
index 00000000000..e2124887e0f
--- /dev/null
+++ b/src/test/ui/lifetimes/shadow.rs
@@ -0,0 +1,8 @@
+struct Foo<T>(T);
+
+impl<'s> Foo<&'s u8> {
+    fn bar<'s>(&self, x: &'s u8) {} //~ ERROR shadows a lifetime name
+    fn baz(x: for<'s> fn(&'s u32)) {} //~ ERROR shadows a lifetime name
+}
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/shadow.stderr b/src/test/ui/lifetimes/shadow.stderr
new file mode 100644
index 00000000000..b834e90d8d0
--- /dev/null
+++ b/src/test/ui/lifetimes/shadow.stderr
@@ -0,0 +1,20 @@
+error[E0496]: lifetime name `'s` shadows a lifetime name that is already in scope
+  --> $DIR/shadow.rs:4:12
+   |
+LL | impl<'s> Foo<&'s u8> {
+   |      -- first declared here
+LL |     fn bar<'s>(&self, x: &'s u8) {}
+   |            ^^ lifetime `'s` already in scope
+
+error[E0496]: lifetime name `'s` shadows a lifetime name that is already in scope
+  --> $DIR/shadow.rs:5:19
+   |
+LL | impl<'s> Foo<&'s u8> {
+   |      -- first declared here
+LL |     fn bar<'s>(&self, x: &'s u8) {}
+LL |     fn baz(x: for<'s> fn(&'s u32)) {}
+   |                   ^^ lifetime `'s` already in scope
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0496`.
diff --git a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr
index a2086895234..cb459f31cd2 100644
--- a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr
+++ b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr
@@ -5,8 +5,6 @@ LL | struct Test {
    |            - help: consider introducing lifetime `'b` here: `<'b>`
 LL |     a: &'b str,
    |         ^^ undeclared lifetime
-   |
-   = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
 
 error[E0261]: use of undeclared lifetime name `'b`
   --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
@@ -15,8 +13,6 @@ LL | struct Test {
    |            - help: consider introducing lifetime `'b` here: `<'b>`
 LL |     a: &'b str,
    |         ^^ undeclared lifetime
-   |
-   = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
 
 error[E0261]: use of undeclared lifetime name `'b`
   --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:13:13
@@ -24,7 +20,6 @@ error[E0261]: use of undeclared lifetime name `'b`
 LL |     fn foo(&'b self) {}
    |             ^^ undeclared lifetime
    |
-   = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
 help: consider introducing lifetime `'b` here
    |
 LL | impl<'b> T for Test {