diff options
Diffstat (limited to '')
21 files changed, 264 insertions, 14 deletions
diff --git a/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed new file mode 100644 index 000000000..aa3bce294 --- /dev/null +++ b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed @@ -0,0 +1,45 @@ +// run-rustfix + +trait Greeter0 { + fn greet(&self); +} + +trait Greeter1 { + fn greet(&self); +} + +type BoxedGreeter<'a> = (Box<dyn Greeter0 + 'a>, Box<dyn Greeter1 + 'a>); +//~^ HELP to declare that the trait object captures data from argument `self`, you can add a lifetime parameter `'a` in the type alias + +struct FixedGreeter<'a>(pub &'a str); + +impl Greeter0 for FixedGreeter<'_> { + fn greet(&self) { + println!("0 {}", self.0) + } +} + +impl Greeter1 for FixedGreeter<'_> { + fn greet(&self) { + println!("1 {}", self.0) + } +} + +struct Greetings(pub Vec<String>); + +impl Greetings { + pub fn get(&self, i: usize) -> BoxedGreeter { + (Box::new(FixedGreeter(&self.0[i])), Box::new(FixedGreeter(&self.0[i]))) + //~^ ERROR lifetime may not live long enough + } +} + +fn main() { + let mut g = Greetings {0 : vec!()}; + g.0.push("a".to_string()); + g.0.push("b".to_string()); + g.get(0).0.greet(); + g.get(0).1.greet(); + g.get(1).0.greet(); + g.get(1).1.greet(); +} diff --git a/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs new file mode 100644 index 000000000..20c88ec69 --- /dev/null +++ b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs @@ -0,0 +1,45 @@ +// run-rustfix + +trait Greeter0 { + fn greet(&self); +} + +trait Greeter1 { + fn greet(&self); +} + +type BoxedGreeter = (Box<dyn Greeter0>, Box<dyn Greeter1>); +//~^ HELP to declare that the trait object captures data from argument `self`, you can add a lifetime parameter `'a` in the type alias + +struct FixedGreeter<'a>(pub &'a str); + +impl Greeter0 for FixedGreeter<'_> { + fn greet(&self) { + println!("0 {}", self.0) + } +} + +impl Greeter1 for FixedGreeter<'_> { + fn greet(&self) { + println!("1 {}", self.0) + } +} + +struct Greetings(pub Vec<String>); + +impl Greetings { + pub fn get(&self, i: usize) -> BoxedGreeter { + (Box::new(FixedGreeter(&self.0[i])), Box::new(FixedGreeter(&self.0[i]))) + //~^ ERROR lifetime may not live long enough + } +} + +fn main() { + let mut g = Greetings {0 : vec!()}; + g.0.push("a".to_string()); + g.0.push("b".to_string()); + g.get(0).0.greet(); + g.get(0).1.greet(); + g.get(1).0.greet(); + g.get(1).1.greet(); +} diff --git a/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr new file mode 100644 index 000000000..808d8bb90 --- /dev/null +++ b/tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr @@ -0,0 +1,15 @@ +error: lifetime may not live long enough + --> $DIR/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs:32:9 + | +LL | pub fn get(&self, i: usize) -> BoxedGreeter { + | - let's call the lifetime of this reference `'1` +LL | (Box::new(FixedGreeter(&self.0[i])), Box::new(FixedGreeter(&self.0[i]))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `self`, you can add a lifetime parameter `'a` in the type alias + | +LL | type BoxedGreeter<'a> = (Box<dyn Greeter0 + 'a>, Box<dyn Greeter1 + 'a>); + | ++++ ++++ ++++ + +error: aborting due to previous error + diff --git a/tests/ui/lifetimes/issue-104432-unused-lifetimes-in-expansion.rs b/tests/ui/lifetimes/issue-104432-unused-lifetimes-in-expansion.rs new file mode 100644 index 000000000..5d5429ec8 --- /dev/null +++ b/tests/ui/lifetimes/issue-104432-unused-lifetimes-in-expansion.rs @@ -0,0 +1,12 @@ +// check-pass + +#![deny(unused_lifetimes)] +trait Trait2 { + type As; +} + +// we should not warn about an unused lifetime about code generated from this proc macro here +#[derive(Clone)] +struct ShimMethod4<T: Trait2 + 'static>(pub &'static dyn for<'s> Fn(&'s mut T::As)); + +pub fn main() {} diff --git a/tests/ui/lifetimes/issue-105227.stderr b/tests/ui/lifetimes/issue-105227.stderr index d21145937..b514db461 100644 --- a/tests/ui/lifetimes/issue-105227.stderr +++ b/tests/ui/lifetimes/issue-105227.stderr @@ -2,7 +2,9 @@ error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime tha --> $DIR/issue-105227.rs:7:5 | LL | fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> { - | ----- hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here + | ----- -------------------------- opaque type defined here + | | + | hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here LL | LL | v.0.chars().chain(v.1.chars()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +18,9 @@ error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime tha --> $DIR/issue-105227.rs:13:5 | LL | fn chars1(v0 : & str, v1 : &str) -> impl Iterator<Item = char> { - | ----- hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here + | ----- -------------------------- opaque type defined here + | | + | hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here LL | LL | v0.chars().chain(v1.chars()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +35,10 @@ error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime tha | LL | fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) -> | ---- hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here -... +LL | +LL | (impl Iterator<Item = char>, &'b str) + | -------------------------- opaque type defined here +LL | { LL | (v0.chars().chain(v1.chars()), v2) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.rs b/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.rs new file mode 100644 index 000000000..f129035d0 --- /dev/null +++ b/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.rs @@ -0,0 +1,6 @@ +pub struct DefaultLifetime<'a, 'b = 'static> { + //~^ ERROR unexpected default lifetime parameter + _marker: std::marker::PhantomData<&'a &'b ()>, +} + +fn main(){} diff --git a/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.stderr b/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.stderr new file mode 100644 index 000000000..c235c3180 --- /dev/null +++ b/tests/ui/lifetimes/issue-107492-default-value-for-lifetime.stderr @@ -0,0 +1,8 @@ +error: unexpected default lifetime parameter + --> $DIR/issue-107492-default-value-for-lifetime.rs:1:35 + | +LL | pub struct DefaultLifetime<'a, 'b = 'static> { + | ^^^^^^^^^ lifetime parameters cannot have default values + +error: aborting due to previous error + diff --git a/tests/ui/lifetimes/issue-107988.rs b/tests/ui/lifetimes/issue-107988.rs new file mode 100644 index 000000000..92cb60a06 --- /dev/null +++ b/tests/ui/lifetimes/issue-107988.rs @@ -0,0 +1,13 @@ +pub trait TraitEngine<'tcx>: 'tcx {} + +pub trait TraitEngineExt<'tcx> { + fn register_predicate_obligations(&mut self); +} + +impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + //~^ ERROR use of undeclared lifetime name `'tcx` + //~| ERROR use of undeclared lifetime name `'tcx` + fn register_predicate_obligations(&mut self) {} +} + +fn main() {} diff --git a/tests/ui/lifetimes/issue-107988.stderr b/tests/ui/lifetimes/issue-107988.stderr new file mode 100644 index 000000000..c2d8c7050 --- /dev/null +++ b/tests/ui/lifetimes/issue-107988.stderr @@ -0,0 +1,27 @@ +error[E0261]: use of undeclared lifetime name `'tcx` + --> $DIR/issue-107988.rs:7:52 + | +LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | - ^^^^ undeclared lifetime + | | + | help: consider introducing lifetime `'tcx` here: `'tcx,` + +error[E0261]: use of undeclared lifetime name `'tcx` + --> $DIR/issue-107988.rs:7:30 + | +LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | ^^^^ undeclared lifetime + | + = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html +help: consider making the bound lifetime-generic with a new `'tcx` lifetime + | +LL | impl<T: ?Sized + for<'tcx> TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | +++++++++ +help: consider introducing lifetime `'tcx` here + | +LL | impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | +++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0261`. diff --git a/tests/ui/lifetimes/issue-17728.stderr b/tests/ui/lifetimes/issue-17728.stderr index 3b25902d7..535073d6e 100644 --- a/tests/ui/lifetimes/issue-17728.stderr +++ b/tests/ui/lifetimes/issue-17728.stderr @@ -9,7 +9,7 @@ LL | | "n" | "north" => RoomDirection::North, LL | | "down" => RoomDirection::Down, | | ------------------- this and all prior arms are found to be of type `RoomDirection` LL | | _ => None - | | ^^^^ expected enum `RoomDirection`, found enum `Option` + | | ^^^^ expected `RoomDirection`, found `Option<_>` LL | | } | |_____- `match` arms have incompatible types | diff --git a/tests/ui/lifetimes/issue-26638.stderr b/tests/ui/lifetimes/issue-26638.stderr index 98d39d614..30afcecf8 100644 --- a/tests/ui/lifetimes/issue-26638.stderr +++ b/tests/ui/lifetimes/issue-26638.stderr @@ -38,11 +38,11 @@ error[E0308]: mismatched types --> $DIR/issue-26638.rs:1:69 | LL | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() } - | ---- ^^^^^^^^^^^ expected `&str`, found enum `Option` + | ---- ^^^^^^^^^^^ expected `&str`, found `Option<&str>` | | - | expected `&'static str` because of return type + | expected `&str` because of return type | - = note: expected reference `&'static str` + = note: expected reference `&str` found enum `Option<&str>` error[E0061]: this function takes 1 argument but 0 arguments were supplied @@ -60,7 +60,7 @@ error[E0308]: mismatched types --> $DIR/issue-26638.rs:5:47 | LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } - | ---- ^^^^^^ expected `str`, found `u8` + | ---- ^^^^^^ expected `&str`, found `&u8` | | | expected `&'static str` because of return type | diff --git a/tests/ui/lifetimes/issue-69314.fixed b/tests/ui/lifetimes/issue-69314.fixed new file mode 100644 index 000000000..41116d4ea --- /dev/null +++ b/tests/ui/lifetimes/issue-69314.fixed @@ -0,0 +1,22 @@ +// run-rustfix +// edition:2021 +#![allow(dead_code, unused_mut, unused_variables)] +struct A {} +struct Msg<'a> { + s: &'a [i32], +} +impl A { + async fn g(buf: &[i32]) -> Msg<'_> { + Msg { s: &buf[0..1] } + } + async fn f() { + let mut buf = [0; 512]; + let m2 = &buf[..]; //~ ERROR `buf` does not live long enough + let m = Self::g(m2).await; + Self::f2(m).await; + } + async fn f2(m: Msg<'_>) {} + //~^ ERROR implicit elided lifetime not allowed here +} + +fn main() {} diff --git a/tests/ui/lifetimes/issue-69314.rs b/tests/ui/lifetimes/issue-69314.rs new file mode 100644 index 000000000..17445341e --- /dev/null +++ b/tests/ui/lifetimes/issue-69314.rs @@ -0,0 +1,22 @@ +// run-rustfix +// edition:2021 +#![allow(dead_code, unused_mut, unused_variables)] +struct A {} +struct Msg<'a> { + s: &'a [i32], +} +impl A { + async fn g(buf: &[i32]) -> Msg<'_> { + Msg { s: &buf[0..1] } + } + async fn f() { + let mut buf = [0; 512]; + let m2 = &buf[..]; //~ ERROR `buf` does not live long enough + let m = Self::g(m2).await; + Self::f2(m).await; + } + async fn f2(m: Msg) {} + //~^ ERROR implicit elided lifetime not allowed here +} + +fn main() {} diff --git a/tests/ui/lifetimes/issue-69314.stderr b/tests/ui/lifetimes/issue-69314.stderr new file mode 100644 index 000000000..7ae678928 --- /dev/null +++ b/tests/ui/lifetimes/issue-69314.stderr @@ -0,0 +1,26 @@ +error[E0726]: implicit elided lifetime not allowed here + --> $DIR/issue-69314.rs:18:20 + | +LL | async fn f2(m: Msg) {} + | ^^^ expected lifetime parameter + | +help: indicate the anonymous lifetime + | +LL | async fn f2(m: Msg<'_>) {} + | ++++ + +error[E0597]: `buf` does not live long enough + --> $DIR/issue-69314.rs:14:19 + | +LL | let m2 = &buf[..]; + | ^^^ borrowed value does not live long enough +LL | let m = Self::g(m2).await; + | ----------- argument requires that `buf` is borrowed for `'static` +LL | Self::f2(m).await; +LL | } + | - `buf` dropped here while still borrowed + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0597, E0726. +For more information about an error, try `rustc --explain E0597`. diff --git a/tests/ui/lifetimes/issue-90600-expected-return-static-indirect.stderr b/tests/ui/lifetimes/issue-90600-expected-return-static-indirect.stderr index 99e1e7217..3602de8dd 100644 --- a/tests/ui/lifetimes/issue-90600-expected-return-static-indirect.stderr +++ b/tests/ui/lifetimes/issue-90600-expected-return-static-indirect.stderr @@ -1,6 +1,8 @@ error[E0597]: `foo` does not live long enough --> $DIR/issue-90600-expected-return-static-indirect.rs:7:32 | +LL | fn inner(mut foo: &[u8]) { + | ------- binding `foo` declared here LL | let refcell = RefCell::new(&mut foo); | ^^^^^^^^ borrowed value does not live long enough LL | diff --git a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr index 4bcd7cf95..6fd7f67d1 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr @@ -7,7 +7,7 @@ LL | fn foo<'a>(&self, x: &'a i32) -> &i32 { | lifetime `'a` defined here LL | LL | x - | ^ associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` + | ^ method was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` error: aborting due to previous error diff --git a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr index 34a64f8a6..2687266e0 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-self-is-anon.stderr @@ -7,7 +7,7 @@ LL | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo { | lifetime `'a` defined here LL | LL | if true { x } else { self } - | ^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` + | ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` error: aborting due to previous error diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr index 5601335d2..9ff5e42d7 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr @@ -6,7 +6,7 @@ LL | fn foo<'a>(&self, x: &i32) -> &i32 { | | | let's call the lifetime of this reference `'2` LL | x - | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` + | ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr index e221902c4..e4c855e11 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr @@ -6,7 +6,7 @@ LL | fn foo<'a>(&self, x: &Foo) -> &Foo { | | | let's call the lifetime of this reference `'2` LL | if true { x } else { self } - | ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` + | ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` | help: consider introducing a named lifetime parameter and update trait if needed | diff --git a/tests/ui/lifetimes/unusual-rib-combinations.rs b/tests/ui/lifetimes/unusual-rib-combinations.rs index b4c86aab8..1c122f42e 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.rs +++ b/tests/ui/lifetimes/unusual-rib-combinations.rs @@ -23,6 +23,6 @@ fn c<T = u8()>() {} // 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 +//~| ERROR `S<'_>` is forbidden as the type of a const generic parameter fn main() {} diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 6d7b42506..68f4fce01 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -46,7 +46,7 @@ LL | fn a() -> [u8; foo::()] { = note: expected type `usize` found fn item `fn() {foo}` -error: `S<'static>` is forbidden as the type of a const generic parameter +error: `S<'_>` is forbidden as the type of a const generic parameter --> $DIR/unusual-rib-combinations.rs:24:15 | LL | fn d<const C: S>() {} |