diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 098b5a0c92e..3b371740022 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -758,7 +758,10 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // We don't need to deal with patterns in parameters, because // they are not possible for foreign or bodiless functions. self.with_lifetime_rib( - LifetimeRibKind::AnonymousPassThrough(fn_id, false), + LifetimeRibKind::AnonymousCreateParameter { + binder: fn_id, + report_in_path: false, + }, |this| walk_list!(this, visit_param, &sig.decl.inputs), ); self.with_lifetime_rib( @@ -792,18 +795,13 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // generic parameters. This is especially useful for `async fn`, where // these fresh generic parameters can be applied to the opaque `impl Trait` // return type. - let rib = if async_node_id.is_some() { - // Only emit a hard error for `async fn`, since this kind of - // elision has always been allowed in regular `fn`s. + this.with_lifetime_rib( LifetimeRibKind::AnonymousCreateParameter { binder: fn_id, - report_in_path: true, - } - } else { - LifetimeRibKind::AnonymousPassThrough(fn_id, false) - }; - this.with_lifetime_rib( - rib, + // Only emit a hard error for `async fn`, since this kind of + // elision has always been allowed in regular `fn`s. + report_in_path: async_node_id.is_some(), + }, // Add each argument to the rib. |this| this.resolve_params(&declaration.inputs), ); diff --git a/src/test/ui/generic-associated-types/bugs/issue-87748.stderr b/src/test/ui/generic-associated-types/bugs/issue-87748.stderr index 60bb48efbc8..ac197dfe6ff 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87748.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-87748.stderr @@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied LL | fn do_sth(_: u32) {} | ^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the anonymous lifetime #2 defined here +note: lifetime parameter instantiated with the anonymous lifetime as defined here --> $DIR/issue-87748.rs:18:5 | LL | fn do_sth(_: u32) {} | ^^^^^^^^^^^^^^^^^ -note: but lifetime parameter must outlive the anonymous lifetime #1 defined here +note: but lifetime parameter must outlive the anonymous lifetime as defined here --> $DIR/issue-87748.rs:18:5 | LL | fn do_sth(_: u32) {} diff --git a/src/test/ui/generic-associated-types/issue-95305.rs b/src/test/ui/generic-associated-types/issue-95305.rs index 2365daada11..78d4bb913b8 100644 --- a/src/test/ui/generic-associated-types/issue-95305.rs +++ b/src/test/ui/generic-associated-types/issue-95305.rs @@ -11,7 +11,10 @@ trait Foo { fn foo(x: &impl Foo = u32>) { } //~^ ERROR `'_` cannot be used here [E0637] +// Ok: the anonymous lifetime is bound to the function. fn bar(x: &impl for<'a> Foo = &'_ u32>) { } - //~^ ERROR missing lifetime specifier + +// Ok: the anonymous lifetime is bound to the function. +fn baz(x: &impl for<'a> Foo = &u32>) { } fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-95305.stderr b/src/test/ui/generic-associated-types/issue-95305.stderr index 8624d880d4e..d8557525f54 100644 --- a/src/test/ui/generic-associated-types/issue-95305.stderr +++ b/src/test/ui/generic-associated-types/issue-95305.stderr @@ -4,18 +4,6 @@ error[E0637]: `'_` cannot be used here LL | fn foo(x: &impl Foo = u32>) { } | ^^ `'_` is a reserved lifetime name -error[E0106]: missing lifetime specifier - --> $DIR/issue-95305.rs:14:41 - | -LL | fn bar(x: &impl for<'a> Foo = &'_ u32>) { } - | ^^ expected named lifetime parameter - | -help: consider using the `'a` lifetime - | -LL | fn bar(x: &impl for<'a> Foo = &'a u32>) { } - | ~~ +error: aborting due to previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0106, E0637. -For more information about an error, try `rustc --explain E0106`. +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/issues/issue-37884.stderr b/src/test/ui/issues/issue-37884.stderr index e83590a8f59..e9f50b41f6a 100644 --- a/src/test/ui/issues/issue-37884.stderr +++ b/src/test/ui/issues/issue-37884.stderr @@ -6,7 +6,7 @@ LL | fn next(&'a mut self) -> Option | = note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> Option<_>` found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> Option<_>` -note: the anonymous lifetime #1 defined here... +note: the anonymous lifetime as defined here... --> $DIR/issue-37884.rs:6:5 | LL | fn next(&'a mut self) -> Option diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr index 42d9f057aaa..06256ebbc29 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -2,14 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/impl-trait-captures.rs:11:5 | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { - | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0)) T` captures the anonymous lifetime defined here + | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here LL | x | ^ | -help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0))` lifetime bound +help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound | -LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0)) { - | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) { + | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime.rs b/src/test/ui/suggestions/impl-trait-missing-lifetime.rs index 22dc448c97f..2ef0f5a4853 100644 --- a/src/test/ui/suggestions/impl-trait-missing-lifetime.rs +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime.rs @@ -1,2 +1,8 @@ -fn f(_: impl Iterator) {} //~ ERROR missing lifetime specifier +// This is understood as `fn foo<'_1>(_: impl Iterator) {}`. +fn f(_: impl Iterator) {} + +// But that lifetime does not participate in resolution. +fn g(x: impl Iterator) -> Option<&'_ ()> { x.next() } +//~^ ERROR missing lifetime specifier + fn main() {} diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr b/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr index a3a339b13c4..a09ef8121d7 100644 --- a/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr +++ b/src/test/ui/suggestions/impl-trait-missing-lifetime.stderr @@ -1,13 +1,14 @@ error[E0106]: missing lifetime specifier - --> $DIR/impl-trait-missing-lifetime.rs:1:31 + --> $DIR/impl-trait-missing-lifetime.rs:5:50 | -LL | fn f(_: impl Iterator) {} - | ^^ expected named lifetime parameter +LL | fn g(x: impl Iterator) -> Option<&'_ ()> { x.next() } + | ^^ expected named lifetime parameter | -help: consider introducing a 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 `'static` lifetime | -LL | fn f<'a>(_: impl Iterator) {} - | ++++ ~~ +LL | fn g(x: impl Iterator) -> Option<&'static ()> { x.next() } + | ~~~~~~~ error: aborting due to previous error 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 f976466841c..94f6dc26624 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 @@ -21,11 +21,11 @@ note: because this has an unmet lifetime requirement | LL | pub struct Wrapper(T); | ^^^^^ introduces a `'static` lifetime requirement -note: the anonymous lifetime #1 defined here... - --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5 +note: the anonymous lifetime as defined here... + --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:29 | LL | pub fn repro(_: Wrapper); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl` --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:1 |