summaryrefslogtreecommitdiffstats
path: root/src/test/ui/lifetimes
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs11
-rw-r--r--src/test/ui/lifetimes/fullwidth-ampersand.rs7
-rw-r--r--src/test/ui/lifetimes/fullwidth-ampersand.stderr26
-rw-r--r--src/test/ui/lifetimes/issue-26638.stderr2
-rw-r--r--src/test/ui/lifetimes/issue-79187-2.stderr2
-rw-r--r--src/test/ui/lifetimes/issue-79187.stderr2
-rw-r--r--src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs6
-rw-r--r--src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr14
-rw-r--r--src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr2
-rw-r--r--src/test/ui/lifetimes/missing-lifetime-in-alias.rs2
-rw-r--r--src/test/ui/lifetimes/missing-lifetime-in-alias.stderr10
-rw-r--r--src/test/ui/lifetimes/nested-binder-print.rs10
-rw-r--r--src/test/ui/lifetimes/nested-binder-print.stderr14
-rw-r--r--src/test/ui/lifetimes/re-empty-in-error.stderr2
-rw-r--r--src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.rs9
-rw-r--r--src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr24
-rw-r--r--src/test/ui/lifetimes/unusual-rib-combinations.rs28
-rw-r--r--src/test/ui/lifetimes/unusual-rib-combinations.stderr61
18 files changed, 219 insertions, 13 deletions
diff --git a/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs
new file mode 100644
index 000000000..c1425fa42
--- /dev/null
+++ b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+struct S<T> {
+ _t: T,
+}
+
+fn f(S::<&i8> { .. }: S<&i8>) {}
+
+fn main() {
+ f(S { _t: &42_i8 });
+}
diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.rs b/src/test/ui/lifetimes/fullwidth-ampersand.rs
new file mode 100644
index 000000000..7d8948bd8
--- /dev/null
+++ b/src/test/ui/lifetimes/fullwidth-ampersand.rs
@@ -0,0 +1,7 @@
+// Verify that we do not ICE when the user uses a multubyte ampersand.
+
+fn f(_: &&()) -> &() { todo!() }
+//~^ ERROR unknown start of token: \u{ff06}
+//~| ERROR missing lifetime specifier [E0106]
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/fullwidth-ampersand.stderr b/src/test/ui/lifetimes/fullwidth-ampersand.stderr
new file mode 100644
index 000000000..4645254f4
--- /dev/null
+++ b/src/test/ui/lifetimes/fullwidth-ampersand.stderr
@@ -0,0 +1,26 @@
+error: unknown start of token: \u{ff06}
+ --> $DIR/fullwidth-ampersand.rs:3:10
+ |
+LL | fn f(_: &&()) -> &() { todo!() }
+ | ^^
+ |
+help: Unicode character '&' (Fullwidth Ampersand) looks like '&' (Ampersand), but it is not
+ |
+LL | fn f(_: &&()) -> &() { todo!() }
+ | ~
+
+error[E0106]: missing lifetime specifier
+ --> $DIR/fullwidth-ampersand.rs:3:18
+ |
+LL | fn f(_: &&()) -> &() { todo!() }
+ | ----- ^ expected named lifetime parameter
+ |
+ = help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
+help: consider introducing a named lifetime parameter
+ |
+LL | fn f<'a>(_: &'a &'a ()) -> &'a () { todo!() }
+ | ++++ ++ ++ ++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0106`.
diff --git a/src/test/ui/lifetimes/issue-26638.stderr b/src/test/ui/lifetimes/issue-26638.stderr
index f3af5cf5a..98d39d614 100644
--- a/src/test/ui/lifetimes/issue-26638.stderr
+++ b/src/test/ui/lifetimes/issue-26638.stderr
@@ -54,7 +54,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
help: provide the argument
|
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter(/* &u8 */) }
- | ~~~~~~~~~~~~~~~
+ | ~~~~~~~~~~~
error[E0308]: mismatched types
--> $DIR/issue-26638.rs:5:47
diff --git a/src/test/ui/lifetimes/issue-79187-2.stderr b/src/test/ui/lifetimes/issue-79187-2.stderr
index 9322e6171..c5f654b37 100644
--- a/src/test/ui/lifetimes/issue-79187-2.stderr
+++ b/src/test/ui/lifetimes/issue-79187-2.stderr
@@ -31,7 +31,7 @@ error[E0308]: mismatched types
LL | take_foo(|a| a);
| ^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r i32,)>`
+ = note: expected trait `for<'a> Fn<(&'a i32,)>`
found trait `Fn<(&i32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187-2.rs:8:14
diff --git a/src/test/ui/lifetimes/issue-79187.stderr b/src/test/ui/lifetimes/issue-79187.stderr
index 3e75e7fed..ee6e7b89d 100644
--- a/src/test/ui/lifetimes/issue-79187.stderr
+++ b/src/test/ui/lifetimes/issue-79187.stderr
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | thing(f);
| ^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> FnOnce<(&'r u32,)>`
+ = note: expected trait `for<'a> FnOnce<(&'a u32,)>`
found trait `FnOnce<(&u32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187.rs:4:13
diff --git a/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
index 7a2eba518..d0a8fe795 100644
--- a/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
+++ b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
@@ -42,4 +42,10 @@ fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
panic!()
}
+fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
+//~^ ERROR missing lifetime specifier
+
+// This is ok because both `'a` are for the same parameter.
+fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
+
fn main() {}
diff --git a/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr
index d07754879..5eee953ef 100644
--- a/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr
+++ b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr
@@ -70,6 +70,18 @@ help: consider using the `'a` lifetime
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
| ++
-error: aborting due to 6 previous errors
+error[E0106]: missing lifetime specifier
+ --> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:45:37
+ |
+LL | fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
+ | ------- ------- ^ expected named lifetime parameter
+ |
+ = help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
+help: consider using the `'a` lifetime
+ |
+LL | fn l<'a>(_: &'a str, _: &'a str) -> &'a str { "" }
+ | ++
+
+error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0106`.
diff --git a/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr b/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
index d82b2684c..7049f28e2 100644
--- a/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
+++ b/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
@@ -15,7 +15,7 @@ error[E0308]: mismatched types
LL | f(data, identity)
| ^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r T,)>`
+ = note: expected trait `for<'a> Fn<(&'a T,)>`
found trait `Fn<(&T,)>`
note: the lifetime requirement is introduced here
--> $DIR/issue_74400.rs:8:34
diff --git a/src/test/ui/lifetimes/missing-lifetime-in-alias.rs b/src/test/ui/lifetimes/missing-lifetime-in-alias.rs
index af7b64127..51c564c01 100644
--- a/src/test/ui/lifetimes/missing-lifetime-in-alias.rs
+++ b/src/test/ui/lifetimes/missing-lifetime-in-alias.rs
@@ -1,5 +1,3 @@
-#![feature(generic_associated_types)]
-
trait Trait<'a> {
type Foo;
diff --git a/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr b/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr
index b8c68a460..428b8f14b 100644
--- a/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr
+++ b/src/test/ui/lifetimes/missing-lifetime-in-alias.stderr
@@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
- --> $DIR/missing-lifetime-in-alias.rs:22:24
+ --> $DIR/missing-lifetime-in-alias.rs:20:24
|
LL | type B<'a> = <A<'a> as Trait>::Foo;
| ^^^^^ expected named lifetime parameter
@@ -10,13 +10,13 @@ LL | type B<'a> = <A<'a> as Trait<'a>>::Foo;
| ++++
error[E0106]: missing lifetime specifier
- --> $DIR/missing-lifetime-in-alias.rs:26:28
+ --> $DIR/missing-lifetime-in-alias.rs:24: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
+ --> $DIR/missing-lifetime-in-alias.rs:24:8
|
LL | type C<'a, 'b> = <A<'a> as Trait>::Bar;
| ^^ ^^
@@ -26,13 +26,13 @@ LL | type C<'a, 'b> = <A<'a> as Trait<'lifetime>>::Bar;
| +++++++++++
error[E0107]: missing generics for associated type `Trait::Bar`
- --> $DIR/missing-lifetime-in-alias.rs:26:36
+ --> $DIR/missing-lifetime-in-alias.rs:24: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
+ --> $DIR/missing-lifetime-in-alias.rs:4:10
|
LL | type Bar<'b>
| ^^^ --
diff --git a/src/test/ui/lifetimes/nested-binder-print.rs b/src/test/ui/lifetimes/nested-binder-print.rs
new file mode 100644
index 000000000..f97f349fd
--- /dev/null
+++ b/src/test/ui/lifetimes/nested-binder-print.rs
@@ -0,0 +1,10 @@
+struct TwoLt<'a, 'b>(&'a (), &'b ());
+type Foo<'a> = fn(TwoLt<'_, 'a>);
+
+fn foo() {
+ let y: for<'a> fn(Foo<'a>);
+ let x: u32 = y;
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/nested-binder-print.stderr b/src/test/ui/lifetimes/nested-binder-print.stderr
new file mode 100644
index 000000000..32dd89693
--- /dev/null
+++ b/src/test/ui/lifetimes/nested-binder-print.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/nested-binder-print.rs:6:18
+ |
+LL | let x: u32 = y;
+ | --- ^ expected `u32`, found fn pointer
+ | |
+ | expected due to this
+ |
+ = note: expected type `u32`
+ found fn pointer `for<'a> fn(for<'b> fn(TwoLt<'b, 'a>))`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/lifetimes/re-empty-in-error.stderr b/src/test/ui/lifetimes/re-empty-in-error.stderr
index 72bb0782f..c35d8ecec 100644
--- a/src/test/ui/lifetimes/re-empty-in-error.stderr
+++ b/src/test/ui/lifetimes/re-empty-in-error.stderr
@@ -4,7 +4,7 @@ error: higher-ranked lifetime error
LL | foo(&10);
| ^^^^^^^^
|
- = note: could not prove `for<'b, 'r> &'b (): 'r`
+ = note: could not prove `for<'b> &'b (): 'a`
error: aborting due to previous error
diff --git a/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.rs b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.rs
new file mode 100644
index 000000000..645bc7db0
--- /dev/null
+++ b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.rs
@@ -0,0 +1,9 @@
+fn no_restriction<T>(x: &()) -> &() {
+ with_restriction::<T>(x) //~ ERROR the parameter type `T` may not live long enough
+}
+
+fn with_restriction<'b, T: 'b>(x: &'b ()) -> &'b () {
+ x
+}
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr
new file mode 100644
index 000000000..31fd8a4d6
--- /dev/null
+++ b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr
@@ -0,0 +1,24 @@
+error[E0311]: the parameter type `T` may not live long enough
+ --> $DIR/suggest-introducing-and-adding-missing-lifetime.rs:2:5
+ |
+LL | with_restriction::<T>(x)
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the parameter type `T` must be valid for the anonymous lifetime defined here...
+ --> $DIR/suggest-introducing-and-adding-missing-lifetime.rs:1:25
+ |
+LL | fn no_restriction<T>(x: &()) -> &() {
+ | ^^^
+note: ...so that the type `T` will meet its required lifetime bounds
+ --> $DIR/suggest-introducing-and-adding-missing-lifetime.rs:2:5
+ |
+LL | with_restriction::<T>(x)
+ | ^^^^^^^^^^^^^^^^^^^^^
+help: consider adding an explicit lifetime bound...
+ |
+LL | fn no_restriction<'a, T: 'a>(x: &()) -> &() {
+ | +++ ++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/lifetimes/unusual-rib-combinations.rs b/src/test/ui/lifetimes/unusual-rib-combinations.rs
new file mode 100644
index 000000000..b4c86aab8
--- /dev/null
+++ b/src/test/ui/lifetimes/unusual-rib-combinations.rs
@@ -0,0 +1,28 @@
+#![feature(inline_const)]
+
+struct S<'a>(&'a u8);
+fn foo() {}
+
+// Paren generic args in AnonConst
+fn a() -> [u8; foo::()] {
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+//~| ERROR mismatched types
+ panic!()
+}
+
+// Paren generic args in ConstGeneric
+fn b<const C: u8()>() {}
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+
+// Paren generic args in AnonymousReportError
+fn c<T = u8()>() {}
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+//~| ERROR defaults for type parameters are only allowed in
+//~| WARN this was previously accepted
+
+// Elided lifetime in path in ConstGeneric
+fn d<const C: S>() {}
+//~^ ERROR missing lifetime specifier
+//~| ERROR `S<'static>` is forbidden as the type of a const generic parameter
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/unusual-rib-combinations.stderr b/src/test/ui/lifetimes/unusual-rib-combinations.stderr
new file mode 100644
index 000000000..6d7b42506
--- /dev/null
+++ b/src/test/ui/lifetimes/unusual-rib-combinations.stderr
@@ -0,0 +1,61 @@
+error[E0106]: missing lifetime specifier
+ --> $DIR/unusual-rib-combinations.rs:24:15
+ |
+LL | fn d<const C: S>() {}
+ | ^ expected named lifetime parameter
+ |
+help: consider introducing a named lifetime parameter
+ |
+LL | fn d<'a, const C: S<'a>>() {}
+ | +++ ++++
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:7:16
+ |
+LL | fn a() -> [u8; foo::()] {
+ | ^^^^^^^ only `Fn` traits may use parentheses
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:14:15
+ |
+LL | fn b<const C: u8()>() {}
+ | ^^^^ only `Fn` traits may use parentheses
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:18:10
+ |
+LL | fn c<T = u8()>() {}
+ | ^^^^ only `Fn` traits may use parentheses
+
+error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+ --> $DIR/unusual-rib-combinations.rs:18:6
+ |
+LL | fn c<T = u8()>() {}
+ | ^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+ = note: `#[deny(invalid_type_param_default)]` on by default
+
+error[E0308]: mismatched types
+ --> $DIR/unusual-rib-combinations.rs:7:16
+ |
+LL | fn a() -> [u8; foo::()] {
+ | ^^^^^^^ expected `usize`, found fn item
+ |
+ = note: expected type `usize`
+ found fn item `fn() {foo}`
+
+error: `S<'static>` is forbidden as the type of a const generic parameter
+ --> $DIR/unusual-rib-combinations.rs:24:15
+ |
+LL | fn d<const C: S>() {}
+ | ^
+ |
+ = note: the only supported types are integers, `bool` and `char`
+ = help: more complex types are supported with `#![feature(adt_const_params)]`
+
+error: aborting due to 7 previous errors
+
+Some errors have detailed explanations: E0106, E0214, E0308.
+For more information about an error, try `rustc --explain E0106`.