diff options
Diffstat (limited to 'src')
35 files changed, 701 insertions, 191 deletions
diff --git a/src/test/ui/async-await/async-fn-path-elision.stderr b/src/test/ui/async-await/async-fn-path-elision.stderr index 3d18d9c4125..5e0c8c29989 100644 --- a/src/test/ui/async-await/async-fn-path-elision.stderr +++ b/src/test/ui/async-await/async-fn-path-elision.stderr @@ -2,9 +2,13 @@ error[E0726]: implicit elided lifetime not allowed here --> $DIR/async-fn-path-elision.rs:5:20 | LL | async fn error(lt: HasLifetime) { - | ^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>` + | ^^^^^^^^^^^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +LL | async fn error(lt: HasLifetime<'_>) { + | ++++ error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr index 317897ae70f..1792d8db292 100644 --- a/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr +++ b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr @@ -2,9 +2,17 @@ error[E0261]: use of undeclared lifetime name `'x` --> $DIR/gat-in-trait-path-undeclared-lifetime.rs:8:35 | LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {} - | - ^^ undeclared lifetime - | | - | help: consider introducing lifetime `'x` here: `<'x>` + | ^^ 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 `'x` lifetime + | +LL | fn _f(arg : Box<dyn for<'x, 'a> X<Y<'x> = &'a [u32]>>) {} + | +++ +help: consider introducing lifetime `'x` here + | +LL | fn _f<'x>(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {} + | ++++ error[E0582]: binding for associated type `Y` references lifetime `'a`, which does not appear in the trait input types --> $DIR/gat-in-trait-path-undeclared-lifetime.rs:8:33 diff --git a/src/test/ui/generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr b/src/test/ui/generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr index bf0ca871503..a4bb361900f 100644 --- a/src/test/ui/generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr +++ b/src/test/ui/generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr @@ -4,14 +4,19 @@ error[E0261]: use of undeclared lifetime name `'b` LL | + Deref<Target = Self::Item<'b>>; | ^^ undeclared lifetime | -help: consider introducing lifetime `'b` here + = 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 `'b` lifetime | -LL | trait Iterable<'b> { - | ++++ +LL | + for<'b> Deref<Target = Self::Item<'b>>; + | +++++++ help: consider introducing lifetime `'b` here | LL | type Iter<'b, 'a>: Iterator<Item = Self::Item<'a>> | +++ +help: consider introducing lifetime `'b` here + | +LL | trait Iterable<'b> { + | ++++ error[E0261]: use of undeclared lifetime name `'undeclared` --> $DIR/generic_associated_type_undeclared_lifetimes.rs:11:41 @@ -21,12 +26,12 @@ LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>; | help: consider introducing lifetime `'undeclared` here | -LL | trait Iterable<'undeclared> { - | +++++++++++++ -help: consider introducing lifetime `'undeclared` here - | LL | fn iter<'undeclared, 'a>(&'a self) -> Self::Iter<'undeclared>; | ++++++++++++ +help: consider introducing lifetime `'undeclared` here + | +LL | trait Iterable<'undeclared> { + | +++++++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/generic-associated-types/issue-67510.rs b/src/test/ui/generic-associated-types/issue-67510.rs index e81a5b231a0..5725b660ab2 100644 --- a/src/test/ui/generic-associated-types/issue-67510.rs +++ b/src/test/ui/generic-associated-types/issue-67510.rs @@ -4,9 +4,9 @@ trait X { type Y<'a>; } -fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {} - //~^ ERROR: use of undeclared lifetime name `'a` - //~| ERROR: use of undeclared lifetime name `'a` - +fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {} +//~^ ERROR: use of undeclared lifetime name `'a` +//~| ERROR: use of undeclared lifetime name `'a` +//~| ERROR: the trait `X` cannot be made into an object [E0038] fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-67510.stderr b/src/test/ui/generic-associated-types/issue-67510.stderr index abc02b33e0e..8aeda22bad7 100644 --- a/src/test/ui/generic-associated-types/issue-67510.stderr +++ b/src/test/ui/generic-associated-types/issue-67510.stderr @@ -1,19 +1,50 @@ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/issue-67510.rs:7:21 | -LL | fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {} - | - ^^ undeclared lifetime - | | - | help: consider introducing lifetime `'a` here: `<'a>` +LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {} + | ^^ 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 `'a` lifetime + | +LL | fn f(x: Box<dyn for<'a> X<Y<'a> = &'a ()>>) {} + | +++++++ +help: consider introducing lifetime `'a` here + | +LL | fn f<'a>(x: Box<dyn X<Y<'a> = &'a ()>>) {} + | ++++ error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/issue-67510.rs:7:26 + --> $DIR/issue-67510.rs:7:28 + | +LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {} + | ^^ undeclared lifetime + | +help: consider making the bound lifetime-generic with a new `'a` lifetime + | +LL | fn f(x: Box<dyn for<'a> X<Y<'a> = &'a ()>>) {} + | +++++++ +help: consider introducing lifetime `'a` here + | +LL | fn f<'a>(x: Box<dyn X<Y<'a> = &'a ()>>) {} + | ++++ + +error[E0038]: the trait `X` cannot be made into an object + --> $DIR/issue-67510.rs:7:13 + | +LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {} + | ^^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $DIR/issue-67510.rs:4:10 | -LL | fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {} - | - ^^ undeclared lifetime - | | - | help: consider introducing lifetime `'a` here: `<'a>` +LL | trait X { + | - this trait cannot be made into an object... +LL | type Y<'a>; + | ^ ...because it contains the generic associated type `Y` + = help: consider moving `Y` to another trait -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0261`. +Some errors have detailed explanations: E0038, E0261. +For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/generic-associated-types/issue-70304.rs b/src/test/ui/generic-associated-types/issue-70304.rs index ae64f9310d1..448d7ec2873 100644 --- a/src/test/ui/generic-associated-types/issue-70304.rs +++ b/src/test/ui/generic-associated-types/issue-70304.rs @@ -12,13 +12,10 @@ impl Document for DocumentImpl { type Cursor<'a> = DocCursorImpl<'a>; fn cursor(&self) -> Self::Cursor<'_> { - DocCursorImpl { - document: &self, - } + DocCursorImpl { document: &self } } } - trait DocCursor<'a> {} struct DocCursorImpl<'a> { @@ -35,7 +32,6 @@ where _phantom: std::marker::PhantomData<&'d ()>, } - impl<'d, Cursor> Lexer<'d, Cursor> where Cursor: DocCursor<'d>, @@ -44,15 +40,12 @@ where where Doc: Document<Cursor<'d> = Cursor>, { - Lexer { - cursor: document.cursor(), - _phantom: std::marker::PhantomData, - } + Lexer { cursor: document.cursor(), _phantom: std::marker::PhantomData } } } fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> { - //~^ ERROR: missing lifetime specifier + //~^ ERROR: missing lifetime specifier DocumentImpl {} } diff --git a/src/test/ui/generic-associated-types/issue-70304.stderr b/src/test/ui/generic-associated-types/issue-70304.stderr index c53dbf63a3c..c5f59a24057 100644 --- a/src/test/ui/generic-associated-types/issue-70304.stderr +++ b/src/test/ui/generic-associated-types/issue-70304.stderr @@ -1,5 +1,5 @@ error[E0106]: missing lifetime specifier - --> $DIR/issue-70304.rs:54:41 + --> $DIR/issue-70304.rs:47:41 | LL | fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> { | ^^ expected named lifetime parameter diff --git a/src/test/ui/generics/generic-extern-lifetime.stderr b/src/test/ui/generics/generic-extern-lifetime.stderr index 909848604ec..33332e760f5 100644 --- a/src/test/ui/generics/generic-extern-lifetime.stderr +++ b/src/test/ui/generics/generic-extern-lifetime.stderr @@ -2,7 +2,9 @@ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/generic-extern-lifetime.rs:6:26 | LL | pub fn life2<'b>(x: &'a i32, y: &'b i32); - | ^^ undeclared lifetime + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `'a,` error[E0261]: use of undeclared lifetime name `'a` --> $DIR/generic-extern-lifetime.rs:8:37 @@ -13,8 +15,12 @@ LL | pub fn life4<'b>(x: for<'c> fn(&'a i32)); = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html help: consider making the type lifetime-generic with a new `'a` lifetime | -LL | pub fn life4<'b>(x: for<'c, 'a> fn(&'a i32)); - | ++++ +LL | pub fn life4<'b>(x: for<'a, 'c> fn(&'a i32)); + | +++ +help: consider introducing lifetime `'a` here + | +LL | pub fn life4<'a, 'b>(x: for<'c> fn(&'a i32)); + | +++ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/generic-extern-lifetime.rs:11:39 @@ -22,11 +28,14 @@ error[E0261]: use of undeclared lifetime name `'a` LL | pub fn life7<'b>() -> for<'c> fn(&'a i32); | ^^ undeclared lifetime | - = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html help: consider making the type lifetime-generic with a new `'a` lifetime | -LL | pub fn life7<'b>() -> for<'c, 'a> fn(&'a i32); - | ++++ +LL | pub fn life7<'b>() -> for<'a, 'c> fn(&'a i32); + | +++ +help: consider introducing lifetime `'a` here + | +LL | pub fn life7<'a, 'b>() -> for<'c> fn(&'a i32); + | +++ error: aborting due to 3 previous errors diff --git a/src/test/ui/impl-header-lifetime-elision/path-elided.stderr b/src/test/ui/impl-header-lifetime-elision/path-elided.stderr index 90522a885ab..0b7d3f1e851 100644 --- a/src/test/ui/impl-header-lifetime-elision/path-elided.stderr +++ b/src/test/ui/impl-header-lifetime-elision/path-elided.stderr @@ -2,9 +2,13 @@ error[E0726]: implicit elided lifetime not allowed here --> $DIR/path-elided.rs:7:18 | LL | impl MyTrait for Foo { - | ^^^- help: indicate the anonymous lifetime: `<'_>` + | ^^^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +LL | impl MyTrait for Foo<'_> { + | ++++ error: aborting due to previous error diff --git a/src/test/ui/impl-header-lifetime-elision/trait-elided.rs b/src/test/ui/impl-header-lifetime-elision/trait-elided.rs index 102d259b0c8..c3e76d9cb5a 100644 --- a/src/test/ui/impl-header-lifetime-elision/trait-elided.rs +++ b/src/test/ui/impl-header-lifetime-elision/trait-elided.rs @@ -1,9 +1,8 @@ #![allow(warnings)] -trait MyTrait<'a> { } +trait MyTrait<'a> {} -impl MyTrait for u32 { - //~^ ERROR implicit elided lifetime not allowed here -} +impl MyTrait for u32 {} +//~^ ERROR implicit elided lifetime not allowed here fn main() {} diff --git a/src/test/ui/impl-header-lifetime-elision/trait-elided.stderr b/src/test/ui/impl-header-lifetime-elision/trait-elided.stderr index 15bc3f106b9..412bba6be71 100644 --- a/src/test/ui/impl-header-lifetime-elision/trait-elided.stderr +++ b/src/test/ui/impl-header-lifetime-elision/trait-elided.stderr @@ -1,10 +1,14 @@ error[E0726]: implicit elided lifetime not allowed here --> $DIR/trait-elided.rs:5:6 | -LL | impl MyTrait for u32 { - | ^^^^^^^- help: indicate the anonymous lifetime: `<'_>` +LL | impl MyTrait for u32 {} + | ^^^^^^^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +LL | impl MyTrait<'_> for u32 {} + | ++++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-10412.rs b/src/test/ui/issues/issue-10412.rs index 02058513685..0de170161b5 100644 --- a/src/test/ui/issues/issue-10412.rs +++ b/src/test/ui/issues/issue-10412.rs @@ -1,16 +1,20 @@ -trait Serializable<'self, T> { //~ ERROR lifetimes cannot use keyword names - fn serialize(val : &'self T) -> Vec<u8>; //~ ERROR lifetimes cannot use keyword names - fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names +trait Serializable<'self, T> { + //~^ ERROR lifetimes cannot use keyword names + fn serialize(val: &'self T) -> Vec<u8>; //~ ERROR lifetimes cannot use keyword names + fn deserialize(repr: &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names } -impl<'self> Serializable<str> for &'self str { //~ ERROR lifetimes cannot use keyword names +impl<'self> Serializable<str> for &'self str { //~^ ERROR lifetimes cannot use keyword names + //~| ERROR lifetimes cannot use keyword names //~| ERROR implicit elided lifetime not allowed here - //~| ERROR the size for values of type `str` cannot be known at compilation time - fn serialize(val : &'self str) -> Vec<u8> { //~ ERROR lifetimes cannot use keyword names + //~| ERROR the size for values of type `str` cannot be known at compilation time [E0277] + fn serialize(val: &'self str) -> Vec<u8> { + //~^ ERROR lifetimes cannot use keyword names vec![1] } - fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR lifetimes cannot use keyword names + fn deserialize(repr: &[u8]) -> &'self str { + //~^ ERROR lifetimes cannot use keyword names "hi" } } diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index a91b3c90ebb..46b9fd541ad 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -5,51 +5,55 @@ LL | trait Serializable<'self, T> { | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:2:25 + --> $DIR/issue-10412.rs:3:24 | -LL | fn serialize(val : &'self T) -> Vec<u8>; - | ^^^^^ +LL | fn serialize(val: &'self T) -> Vec<u8>; + | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:3:38 + --> $DIR/issue-10412.rs:4:37 | -LL | fn deserialize(repr : &[u8]) -> &'self T; - | ^^^^^ +LL | fn deserialize(repr: &[u8]) -> &'self T; + | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:6:6 + --> $DIR/issue-10412.rs:7:6 | LL | impl<'self> Serializable<str> for &'self str { | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:6:36 + --> $DIR/issue-10412.rs:7:36 | LL | impl<'self> Serializable<str> for &'self str { | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:10:25 + --> $DIR/issue-10412.rs:12:24 | -LL | fn serialize(val : &'self str) -> Vec<u8> { - | ^^^^^ +LL | fn serialize(val: &'self str) -> Vec<u8> { + | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:13:37 + --> $DIR/issue-10412.rs:16:37 | LL | fn deserialize(repr: &[u8]) -> &'self str { | ^^^^^ error[E0726]: implicit elided lifetime not allowed here - --> $DIR/issue-10412.rs:6:13 + --> $DIR/issue-10412.rs:7:13 | LL | impl<'self> Serializable<str> for &'self str { - | ^^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Serializable<'_, str>` + | ^^^^^^^^^^^^^^^^^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +LL | impl<'self> Serializable<'_, str> for &'self str { + | +++ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/issue-10412.rs:6:13 + --> $DIR/issue-10412.rs:7:13 | LL | impl<'self> Serializable<str> for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time diff --git a/src/test/ui/lifetimes/issue-91763.stderr b/src/test/ui/lifetimes/issue-91763.stderr index 1b1912c8e45..6ccf008c003 100644 --- a/src/test/ui/lifetimes/issue-91763.stderr +++ b/src/test/ui/lifetimes/issue-91763.stderr @@ -2,13 +2,17 @@ error: hidden lifetime parameters in types are deprecated --> $DIR/issue-91763.rs:8:20 | LL | fn f() -> Ptr<Thing>; - | ^ expected named lifetime parameter + | ^ expected lifetime parameter | note: the lint level is defined here --> $DIR/issue-91763.rs:3:9 | LL | #![deny(elided_lifetimes_in_paths)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +help: indicate the anonymous lifetime + | +LL | fn f() -> Ptr<Thing><'_>; + | ++++ error: aborting due to previous error 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 cb459f31cd2..0d6ade41511 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 @@ -9,6 +9,8 @@ LL | a: &'b str, error[E0261]: use of undeclared lifetime name `'b` --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9 | +LL | #[derive(Eq, PartialEq)] + | -- lifetime `'b` is missing in item created through this procedural macro LL | struct Test { | - help: consider introducing lifetime `'b` here: `<'b>` LL | a: &'b str, @@ -22,12 +24,12 @@ LL | fn foo(&'b self) {} | help: consider introducing lifetime `'b` here | -LL | impl<'b> T for Test { - | ++++ -help: consider introducing lifetime `'b` here - | LL | fn foo<'b>(&'b self) {} | ++++ +help: consider introducing lifetime `'b` here + | +LL | impl<'b> T for Test { + | ++++ error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr index f5e8b41b163..ac98b5896ca 100644 --- a/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr @@ -2,13 +2,13 @@ warning: hidden lifetime parameters in types are deprecated --> $DIR/allowed-by-default-lint.rs:9:12 | LL | fn foo(x: &Foo) {} - | ^^^ expected named lifetime parameter + | ^^^ expected lifetime parameter | = note: requested on the command line with `--force-warn elided-lifetimes-in-paths` -help: consider using the `'_` lifetime +help: indicate the anonymous lifetime | LL | fn foo(x: &Foo<'_>) {} - | ~~~~~~~ + | ++++ warning: 1 warning emitted diff --git a/src/test/ui/lint/reasons.rs b/src/test/ui/lint/reasons.rs index b1792e2e9cb..da1c740c4a3 100644 --- a/src/test/ui/lint/reasons.rs +++ b/src/test/ui/lint/reasons.rs @@ -19,9 +19,9 @@ pub struct CheaterDetectionMechanism {} impl fmt::Debug for CheaterDetectionMechanism { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { //~^ WARN hidden lifetime parameters in types are deprecated - //~| NOTE expected named lifetime parameter + //~| NOTE expected lifetime parameter //~| NOTE explicit anonymous lifetimes aid - //~| HELP consider using the `'_` lifetime + //~| HELP indicate the anonymous lifetime fmt.debug_struct("CheaterDetectionMechanism").finish() } } diff --git a/src/test/ui/lint/reasons.stderr b/src/test/ui/lint/reasons.stderr index a692d6af703..cd8412153f1 100644 --- a/src/test/ui/lint/reasons.stderr +++ b/src/test/ui/lint/reasons.stderr @@ -2,7 +2,9 @@ warning: hidden lifetime parameters in types are deprecated --> $DIR/reasons.rs:20:34 | LL | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - | ^^^^^^^^^ expected named lifetime parameter + | -----^^^^^^^^^ + | | + | expected lifetime parameter | = note: explicit anonymous lifetimes aid reasoning about ownership note: the lint level is defined here @@ -10,10 +12,10 @@ note: the lint level is defined here | LL | #![warn(elided_lifetimes_in_paths, | ^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider using the `'_` lifetime +help: indicate the anonymous lifetime | LL | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - | ~~~~~~~~~~~~~ + | ++++ warning: variable `Social_exchange_psychology` should have a snake case name --> $DIR/reasons.rs:30:9 diff --git a/src/test/ui/methods/method-call-lifetime-args-unresolved.rs b/src/test/ui/methods/method-call-lifetime-args-unresolved.rs index d16ba3df47b..ba7231070a0 100644 --- a/src/test/ui/methods/method-call-lifetime-args-unresolved.rs +++ b/src/test/ui/methods/method-call-lifetime-args-unresolved.rs @@ -1,3 +1,6 @@ fn main() { - 0.clone::<'a>(); //~ ERROR use of undeclared lifetime name `'a` + 0.clone::<'a>(); + //~^ ERROR use of undeclared lifetime name `'a` + //~| WARN cannot specify lifetime arguments explicitly if late bound + //~| WARN this was previously accepted by the compiler } diff --git a/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr b/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr index c9f235c4f7d..78af19586a1 100644 --- a/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr +++ b/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr @@ -6,6 +6,21 @@ LL | fn main() { LL | 0.clone::<'a>(); | ^^ undeclared lifetime -error: aborting due to previous error +warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present + --> $DIR/method-call-lifetime-args-unresolved.rs:2:15 + | +LL | 0.clone::<'a>(); + | ^^ + | + ::: $SRC_DIR/core/src/clone.rs:LL:COL + | +LL | fn clone(&self) -> Self; + | - the late bound lifetime parameter is introduced here + | + = note: `#[warn(late_bound_lifetime_arguments)]` on by default + = 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 #42868 <https://github.com/rust-lang/rust/issues/42868> + +error: aborting due to previous error; 1 warning emitted For more information about this error, try `rustc --explain E0261`. diff --git a/src/test/ui/regions/regions-name-static.rs b/src/test/ui/regions/regions-name-static.rs index 730fd99aa68..da316c6ef5e 100644 --- a/src/test/ui/regions/regions-name-static.rs +++ b/src/test/ui/regions/regions-name-static.rs @@ -1,5 +1,6 @@ -struct Foo<'static> { //~ ERROR invalid lifetime parameter name: `'static` - x: &'static isize +struct Foo<'static> { + //~^ ERROR invalid lifetime parameter name: `'static` + x: &'static isize, } fn main() {} diff --git a/src/test/ui/regions/regions-name-undeclared.rs b/src/test/ui/regions/regions-name-undeclared.rs index b8f50a40c45..7b6ede19341 100644 --- a/src/test/ui/regions/regions-name-undeclared.rs +++ b/src/test/ui/regions/regions-name-undeclared.rs @@ -23,14 +23,14 @@ fn bar<'a>(x: &'a isize) { let y: &'a isize = x; // &'a is not visible to *items*: - type X = Option<&'a isize>; //~ ERROR undeclared lifetime + type X = Option<&'a isize>; //~ ERROR can't use generic parameters from outer item enum E { - E1(&'a isize) //~ ERROR undeclared lifetime + E1(&'a isize) //~ ERROR can't use generic parameters from outer item } struct S { - f: &'a isize //~ ERROR undeclared lifetime + f: &'a isize //~ ERROR can't use generic parameters from outer item } - fn f(a: &'a isize) { } //~ ERROR undeclared lifetime + fn f(a: &'a isize) { } //~ ERROR can't use generic parameters from outer item // &'a CAN be declared on functions and used then: fn g<'a>(a: &'a isize) { } // OK diff --git a/src/test/ui/regions/regions-name-undeclared.stderr b/src/test/ui/regions/regions-name-undeclared.stderr index 4399263f716..532603de5f7 100644 --- a/src/test/ui/regions/regions-name-undeclared.stderr +++ b/src/test/ui/regions/regions-name-undeclared.stderr @@ -1,19 +1,3 @@ -error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/regions-name-undeclared.rs:28:13 - | -LL | enum E { - | - help: consider introducing lifetime `'a` here: `<'a>` -LL | E1(&'a isize) - | ^^ undeclared lifetime - -error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/regions-name-undeclared.rs:31:13 - | -LL | struct S { - | - help: consider introducing lifetime `'a` here: `<'a>` -LL | f: &'a isize - | ^^ undeclared lifetime - error[E0261]: use of undeclared lifetime name `'b` --> $DIR/regions-name-undeclared.rs:16:24 | @@ -22,12 +6,12 @@ LL | fn m4(&self, arg: &'b isize) { } | help: consider introducing lifetime `'b` here | -LL | impl<'b, 'a> Foo<'a> { - | +++ -help: consider introducing lifetime `'b` here - | LL | fn m4<'b>(&self, arg: &'b isize) { } | ++++ +help: consider introducing lifetime `'b` here + | +LL | impl<'b, 'a> Foo<'a> { + | +++ error[E0261]: use of undeclared lifetime name `'b` --> $DIR/regions-name-undeclared.rs:17:12 @@ -37,12 +21,12 @@ LL | fn m5(&'b self) { } | help: consider introducing lifetime `'b` here | -LL | impl<'b, 'a> Foo<'a> { - | +++ -help: consider introducing lifetime `'b` here - | LL | fn m5<'b>(&'b self) { } | ++++ +help: consider introducing lifetime `'b` here + | +LL | impl<'b, 'a> Foo<'a> { + | +++ error[E0261]: use of undeclared lifetime name `'b` --> $DIR/regions-name-undeclared.rs:18:27 @@ -52,26 +36,54 @@ LL | fn m6(&self, arg: Foo<'b>) { } | help: consider introducing lifetime `'b` here | -LL | impl<'b, 'a> Foo<'a> { - | +++ -help: consider introducing lifetime `'b` here - | LL | fn m6<'b>(&self, arg: Foo<'b>) { } | ++++ +help: consider introducing lifetime `'b` here + | +LL | impl<'b, 'a> Foo<'a> { + | +++ -error[E0261]: use of undeclared lifetime name `'a` +error[E0401]: can't use generic parameters from outer item --> $DIR/regions-name-undeclared.rs:26:22 | +LL | fn bar<'a>(x: &'a isize) { + | -- lifetime parameter from outer item +... LL | type X = Option<&'a isize>; - | - ^^ undeclared lifetime + | - ^^ use of generic parameter from outer item | | | help: consider introducing lifetime `'a` here: `<'a>` -error[E0261]: use of undeclared lifetime name `'a` +error[E0401]: can't use generic parameters from outer item + --> $DIR/regions-name-undeclared.rs:28:13 + | +LL | fn bar<'a>(x: &'a isize) { + | -- lifetime parameter from outer item +... +LL | enum E { + | - help: consider introducing lifetime `'a` here: `<'a>` +LL | E1(&'a isize) + | ^^ use of generic parameter from outer item + +error[E0401]: can't use generic parameters from outer item + --> $DIR/regions-name-undeclared.rs:31:13 + | +LL | fn bar<'a>(x: &'a isize) { + | -- lifetime parameter from outer item +... +LL | struct S { + | - help: consider introducing lifetime `'a` here: `<'a>` +LL | f: &'a isize + | ^^ use of generic parameter from outer item + +error[E0401]: can't use generic parameters from outer item --> $DIR/regions-name-undeclared.rs:33:14 | +LL | fn bar<'a>(x: &'a isize) { + | -- lifetime parameter from outer item +... LL | fn f(a: &'a isize) { } - | - ^^ undeclared lifetime + | - ^^ use of generic parameter from outer item | | | help: consider introducing lifetime `'a` here: `<'a>` @@ -90,14 +102,14 @@ LL | ... &'b isize, | ^^ 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 `'b` lifetime + | +LL | b: Box<dyn for<'b, 'a> FnOnce(&'a isize, + | +++ help: consider introducing lifetime `'b` here | LL | fn fn_types<'b>(a: &'a isize, | ++++ -help: consider making the bound lifetime-generic with a new `'b` lifetime - | -LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize, - | ++++ error[E0261]: use of undeclared lifetime name `'b` --> $DIR/regions-name-undeclared.rs:46:36 @@ -105,15 +117,14 @@ error[E0261]: use of undeclared lifetime name `'b` LL | ... &'b isize)>, | ^^ 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 `'b` lifetime + | +LL | b: Box<dyn for<'b, 'a> FnOnce(&'a isize, + | +++ help: consider introducing lifetime `'b` here | LL | fn fn_types<'b>(a: &'a isize, | ++++ -help: consider making the bound lifetime-generic with a new `'b` lifetime - | -LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize, - | ++++ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/regions-name-undeclared.rs:47:17 @@ -132,13 +143,14 @@ LL | async fn buggy(&self) -> &'a str { | help: consider introducing lifetime `'a` here | -LL | impl<'a> Bug { - | ++++ -help: consider introducing lifetime `'a` here - | LL | async fn buggy<'a>(&self) -> &'a str { | ++++ +help: consider introducing lifetime `'a` here + | +LL | impl<'a> Bug { + | ++++ error: aborting due to 12 previous errors -For more information about this error, try `rustc --explain E0261`. +Some errors have detailed explanations: E0261, E0401. +For more information about an error, try `rustc --explain E0261`. diff --git a/src/test/ui/suggestions/fn-missing-lifetime-in-item.stderr b/src/test/ui/suggestions/fn-missing-lifetime-in-item.stderr index 7c0f8d199a9..a761ec59167 100644 --- a/src/test/ui/suggestions/fn-missing-lifetime-in-item.stderr +++ b/src/test/ui/suggestions/fn-missing-lifetime-in-item.stderr @@ -5,14 +5,14 @@ LL | struct S1<F: Fn(&i32, &i32) -> &'a i32>(F); | ^^ undeclared lifetime | = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html -help: consider introducing lifetime `'a` here - | -LL | struct S1<'a, F: Fn(&i32, &i32) -> &'a i32>(F); - | +++ help: consider making the bound lifetime-generic with a new `'a` lifetime | LL | struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F); | +++++++ +help: consider introducing lifetime `'a` here + | +LL | struct S1<'a, F: Fn(&i32, &i32) -> &'a i32>(F); + | +++ error[E0106]: missing lifetime specifier --> $DIR/fn-missing-lifetime-in-item.rs:2:32 diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr new file mode 100644 index 00000000000..0ae629676fe --- /dev/null +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr @@ -0,0 +1,106 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/missing-lifetimes-in-signature.rs:38:11 + | +LL | fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `'a,` + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/missing-lifetimes-in-signature.rs:19:5 + | +LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + | ------ hidden type `[closure@$DIR/missing-lifetimes-in-signature.rs:19:5: 22:6]` captures the anonymous lifetime defined here +... +LL | / move || { +LL | | +LL | | *dest = g.get(); +LL | | } + | |_____^ + | +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound + | +LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ++++ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:32:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:26:26 + | +LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:55:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:49:34 + | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:65:9 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_________^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:62:47 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | ^^^^^^ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:77:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:72:34 + | +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ^^^^^^ + +error[E0621]: explicit lifetime required in the type of `dest` + --> $DIR/missing-lifetimes-in-signature.rs:77:5 + | +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ------ help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T` +... +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ lifetime `'a` required + +error[E0309]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:89:5 + | +LL | / move || { +LL | | *dest = g.get(); +LL | | } + | |_____^ + | + = help: consider adding an explicit lifetime bound `G: 'a`... + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0261, E0309, E0621, E0700. +For more information about an error, try `rustc --explain E0261`. diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.rs b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.rs index dd434ea5318..647b343fe06 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.rs +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.rs @@ -14,28 +14,31 @@ impl Get<usize> for Foo { fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() where - G: Get<T> + G: Get<T>, { move || { + //~^ ERROR hidden type for `impl Trait` captures lifetime *dest = g.get(); } } // After applying suggestion for `foo`: fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +//~^ ERROR the parameter type `G` may not live long enough where - G: Get<T> + G: Get<T>, { + //~^ ERROR the parameter type `G` may not live long enough move || { *dest = g.get(); } } - // After applying suggestion for `bar`: -fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ //~ ERROR undeclared lifetime +fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +//~^ ERROR undeclared lifetime name `'a` where - G: Get<T> + G: Get<T>, { move || { *dest = g.get(); @@ -44,9 +47,11 @@ where // After applying suggestion for `baz`: fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +//~^ ERROR the parameter type `G` may not live long enough where - G: Get<T> + G: Get<T>, { + //~^ ERROR the parameter type `G` may not live long enough move || { *dest = g.get(); } @@ -55,6 +60,8 @@ where // Same as above, but show that we pay attention to lifetime names from parent item impl<'a> Foo { fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + //~^ ERROR the parameter type `G` may not live long enough + //~| ERROR the parameter type `G` may not live long enough move || { *dest = g.get(); } @@ -63,8 +70,9 @@ impl<'a> Foo { // After applying suggestion for `qux`: fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a +//~^ ERROR explicit lifetime required in the type of `dest` where - G: Get<T> + G: Get<T>, { move || { *dest = g.get(); @@ -73,19 +81,20 @@ where // Potential incorrect attempt: fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a +//~^ ERROR the parameter type `G` may not live long enough where - G: Get<T> + G: Get<T>, { + //~^ ERROR the parameter type `G` may not live long enough move || { *dest = g.get(); } } - // We need to tie the lifetime of `G` with the lifetime of `&mut T` and the returned closure: fn ok<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a where - G: Get<T> + G: Get<T>, { move || { *dest = g.get(); @@ -95,7 +104,7 @@ where // This also works. The `'_` isn't necessary but it's where we arrive to following the suggestions: fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + '_ + 'a where - G: Get<T> + G: Get<T>, { move || { *dest = g.get(); diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr index 916a6c2bf12..6d538dfd609 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr @@ -1,11 +1,234 @@ error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/missing-lifetimes-in-signature.rs:36:11 + --> $DIR/missing-lifetimes-in-signature.rs:38:11 | LL | fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | - ^^ undeclared lifetime | | | help: consider introducing lifetime `'a` here: `'a,` -error: aborting due to previous error +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/missing-lifetimes-in-signature.rs:19:5 + | +LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + | ------ hidden type `[closure@$DIR/missing-lifetimes-in-signature.rs:19:5: 22:6]` captures the anonymous lifetime defined here +... +LL | / move || { +LL | | +LL | | *dest = g.get(); +LL | | } + | |_____^ + | +help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound + | +LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ++++ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:26:37 + | +LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^^^^^^^^^^^^^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:26:26 + | +LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:32:5: 34:6]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:26:37 + | +LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^^^^^^^^^^^^^ +help: consider introducing an explicit lifetime bound + | +LL | fn bar<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ~~~~~ ++++ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:30:1 + | +LL | / { +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:26:26 + | +LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:32:5: 34:6]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:30:1 + | +LL | / { +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_^ +help: consider introducing an explicit lifetime bound + | +LL ~ fn bar<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +LL | +LL | where +LL | G: Get<T>, +LL | { +LL | + ... + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:49:45 + | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^^^^^^^^^^^^^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:49:34 + | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:55:5: 57:6]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:49:45 + | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^^^^^^^^^^^^^ +help: consider introducing an explicit lifetime bound + | +LL | fn qux<'b, 'a, G: 'b + 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'b + | +++ ~~~~~~~ ++++ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:53:1 + | +LL | / { +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:49:34 + | +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:55:5: 57:6]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:53:1 + | +LL | / { +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_^ +help: consider introducing an explicit lifetime bound + | +LL ~ fn qux<'b, 'a, G: 'b + 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +LL | +LL | where +LL | G: Get<T>, +LL | { +LL | + ... + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:62:58 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | ^^^^^^^^^^^^^^^^^^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:62:47 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:65:9: 67:10]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:62:58 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | ^^^^^^^^^^^^^^^^^^ +help: consider introducing an explicit lifetime bound + | +LL | fn qux<'c, 'b, G: 'c + Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'c { + | +++ ~~~~~~~ ++++ + +error[E0311]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:62:77 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | _____________________________________________________________________________^ +LL | | +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_____^ + | +note: the parameter type `G` must be valid for the anonymous lifetime defined here... + --> $DIR/missing-lifetimes-in-signature.rs:62:47 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | ^^^^^^ +note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:65:9: 67:10]` will meet its required lifetime bounds + --> $DIR/missing-lifetimes-in-signature.rs:62:77 + | +LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | _____________________________________________________________________________^ +LL | | +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_____^ +help: consider introducing an explicit lifetime bound + | +LL ~ fn qux<'c, 'b, G: 'c + Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { +LL | +LL | +LL | move || { +LL | *dest = g.get(); +LL | } + ... + +error[E0621]: explicit lifetime required in the type of `dest` + --> $DIR/missing-lifetimes-in-signature.rs:72:45 + | +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ------ ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required + | | + | help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T` + +error[E0309]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:83:44 + | +LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a + | - ^^^^^^^^^^^^^^^^^^ ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:89:5: 91:6]` will meet its required lifetime bounds + | | + | help: consider adding an explicit lifetime bound...: `G: 'a` + +error[E0309]: the parameter type `G` may not live long enough + --> $DIR/missing-lifetimes-in-signature.rs:87:1 + | +LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a + | - help: consider adding an explicit lifetime bound...: `G: 'a` +... +LL | / { +LL | | +LL | | move || { +LL | | *dest = g.get(); +LL | | } +LL | | } + | |_^ ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:89:5: 91:6]` will meet its required lifetime bounds + +error: aborting due to 11 previous errors -For more information about this error, try `rustc --explain E0261`. +Some errors have detailed explanations: E0261, E0309, E0621, E0700. +For more information about an error, try `rustc --explain E0261`. diff --git a/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs b/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs index 6732902c09a..b0de8bf6aa4 100644 --- a/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs +++ b/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs @@ -18,5 +18,7 @@ type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; //~^ ERROR use of undeclared lifetime name `'a` fn my_fun() -> Return<()> {} +//~^ ERROR non-defining opaque type use in defining scope +//~| ERROR non-defining opaque type use in defining scope fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr b/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr index fe45e39d938..d038fbbe1b4 100644 --- a/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr @@ -2,10 +2,42 @@ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:65 | LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; - | - ^^ undeclared lifetime - | | - | help: consider introducing lifetime `'a` here: `'a,` + | ^^ 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 `'a` lifetime + | +LL | type Return<A> = impl for<'a> WithAssoc<A, AssocType = impl SomeTrait + 'a>; + | +++++++ +help: consider introducing lifetime `'a` here + | +LL | type Return<'a, A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; + | +++ + +error: non-defining opaque type use in defining scope + --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27 + | +LL | fn my_fun() -> Return<()> {} + | ^^ + | +note: used non-generic type `()` for generic parameter + --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:13 + | +LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; + | ^ + +error: non-defining opaque type use in defining scope + --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27 + | +LL | fn my_fun() -> Return<()> {} + | ^^ + | +note: used non-generic type `()` for generic parameter + --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:13 + | +LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; + | ^ -error: aborting due to previous error +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0261`. diff --git a/src/test/ui/underscore-lifetime/in-binder.rs b/src/test/ui/underscore-lifetime/in-binder.rs index e4ee5e8cb27..74dc331b00a 100644 --- a/src/test/ui/underscore-lifetime/in-binder.rs +++ b/src/test/ui/underscore-lifetime/in-binder.rs @@ -10,22 +10,22 @@ impl<'_> IceCube<'_> {} //~^ ERROR `'_` cannot be used here struct Struct<'_> { -//~^ ERROR `'_` cannot be used here + //~^ ERROR `'_` cannot be used here v: Vec<&'static char> } enum Enum<'_> { -//~^ ERROR `'_` cannot be used here + //~^ ERROR `'_` cannot be used here Variant } union Union<'_> { -//~^ ERROR `'_` cannot be used here + //~^ ERROR `'_` cannot be used here a: u32 } trait Trait<'_> { -//~^ ERROR `'_` cannot be used here + //~^ ERROR `'_` cannot be used here } fn foo<'_>() { diff --git a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr index ba624507c21..16d19872552 100644 --- a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr +++ b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr @@ -2,9 +2,13 @@ error[E0726]: implicit elided lifetime not allowed here --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:16 | LL | impl Trait for Ref {} - | ^^^- help: indicate the anonymous lifetime: `<'_>` + | ^^^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +LL | impl Trait for Ref<'_> {} + | ++++ error: incompatible lifetime on type --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21 diff --git a/src/test/ui/where-clauses/where-lifetime-resolution.stderr b/src/test/ui/where-clauses/where-lifetime-resolution.stderr index 6c52664154b..e8df02fbad6 100644 --- a/src/test/ui/where-clauses/where-lifetime-resolution.stderr +++ b/src/test/ui/where-clauses/where-lifetime-resolution.stderr @@ -1,20 +1,41 @@ error[E0261]: use of undeclared lifetime name `'a` --> $DIR/where-lifetime-resolution.rs:6:38 | -LL | fn f() where - | - help: consider introducing lifetime `'a` here: `<'a>` -LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK LL | (dyn for<'a> Trait1<'a>): Trait1<'a>, | ^^ 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 `'a` lifetime + | +LL | (dyn for<'a> Trait1<'a>): for<'a> Trait1<'a>, + | +++++++ +help: consider making the bound lifetime-generic with a new `'a` lifetime + | +LL | for<'a> (dyn for<'a> Trait1<'a>): Trait1<'a>, + | +++++++ +help: consider introducing lifetime `'a` here + | +LL | fn f<'a>() where + | ++++ error[E0261]: use of undeclared lifetime name `'b` --> $DIR/where-lifetime-resolution.rs:8:52 | -LL | fn f() where - | - help: consider introducing lifetime `'b` here: `<'b>` -... LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>, | ^^ undeclared lifetime + | +help: consider making the bound lifetime-generic with a new `'b` lifetime + | +LL | for<'a> dyn for<'b> Trait2<'a, 'b>: for<'b> Trait2<'a, 'b>, + | +++++++ +help: consider making the bound lifetime-generic with a new `'b` lifetime + | +LL | for<'b, 'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>, + | +++ +help: consider introducing lifetime `'b` here + | +LL | fn f<'b>() where + | ++++ error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/unused_unit.stderr b/src/tools/clippy/tests/ui/unused_unit.stderr index 02038b5fb6b..0d2cb77855b 100644 --- a/src/tools/clippy/tests/ui/unused_unit.stderr +++ b/src/tools/clippy/tests/ui/unused_unit.stderr @@ -1,8 +1,8 @@ error: unneeded unit return type - --> $DIR/unused_unit.rs:19:28 + --> $DIR/unused_unit.rs:19:58 | LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` + | ^^^^^^ help: remove the `-> ()` | note: the lint level is defined here --> $DIR/unused_unit.rs:12:9 @@ -11,16 +11,16 @@ LL | #![deny(clippy::unused_unit)] | ^^^^^^^^^^^^^^^^^^^ error: unneeded unit return type - --> $DIR/unused_unit.rs:20:18 + --> $DIR/unused_unit.rs:19:28 | -LL | where G: Fn() -> () { - | ^^^^^^ help: remove the `-> ()` +LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> () + | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> $DIR/unused_unit.rs:19:58 + --> $DIR/unused_unit.rs:20:18 | -LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> () - | ^^^^^^ help: remove the `-> ()` +LL | where G: Fn() -> () { + | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type --> $DIR/unused_unit.rs:21:26 diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 92f423bbb62..ad2502b0418 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -204,12 +204,11 @@ impl<'a> FnSig<'a> { pub(crate) fn from_fn_kind( fn_kind: &'a visit::FnKind<'_>, - generics: &'a ast::Generics, decl: &'a ast::FnDecl, defaultness: ast::Defaultness, ) -> FnSig<'a> { match *fn_kind { - visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, _) => match fn_ctxt { + visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, generics, _) => match fn_ctxt { visit::FnCtxt::Assoc(..) => { let mut fn_sig = FnSig::from_method_sig(fn_sig, generics, vis); fn_sig.defaultness = defaultness; @@ -3180,8 +3179,14 @@ impl Rewrite for ast::ForeignItem { let inner_attrs = inner_attributes(&self.attrs); let fn_ctxt = visit::FnCtxt::Foreign; visitor.visit_fn( - visit::FnKind::Fn(fn_ctxt, self.ident, sig, &self.vis, Some(body)), - generics, + visit::FnKind::Fn( + fn_ctxt, + self.ident, + sig, + &self.vis, + generics, + Some(body), + ), &sig.decl, self.span, defaultness, diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs index 3ebfa551d1c..1621eb406b1 100644 --- a/src/tools/rustfmt/src/visitor.rs +++ b/src/tools/rustfmt/src/visitor.rs @@ -382,7 +382,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { pub(crate) fn visit_fn( &mut self, fk: visit::FnKind<'_>, - generics: &ast::Generics, fd: &ast::FnDecl, s: Span, defaultness: ast::Defaultness, @@ -391,12 +390,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let indent = self.block_indent; let block; let rewrite = match fk { - visit::FnKind::Fn(_, ident, _, _, Some(ref b)) => { + visit::FnKind::Fn(_, ident, _, _, _, Some(ref b)) => { block = b; self.rewrite_fn_before_block( indent, ident, - &FnSig::from_fn_kind(&fk, generics, fd, defaultness), + &FnSig::from_fn_kind(&fk, fd, defaultness), mk_sp(s.lo(), b.span.lo()), ) } @@ -552,8 +551,14 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { _ => visit::FnCtxt::Foreign, }; self.visit_fn( - visit::FnKind::Fn(fn_ctxt, item.ident, sig, &item.vis, Some(body)), - generics, + visit::FnKind::Fn( + fn_ctxt, + item.ident, + sig, + &item.vis, + generics, + Some(body), + ), &sig.decl, item.span, defaultness, @@ -642,8 +647,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let inner_attrs = inner_attributes(&ai.attrs); let fn_ctxt = visit::FnCtxt::Assoc(assoc_ctxt); self.visit_fn( - visit::FnKind::Fn(fn_ctxt, ai.ident, sig, &ai.vis, Some(body)), - generics, + visit::FnKind::Fn(fn_ctxt, ai.ident, sig, &ai.vis, generics, Some(body)), &sig.decl, ai.span, defaultness, |
