Skip to content

Commit 031b2c5

Browse files
committed
Always use CreateParameter mode for function definitions.
1 parent a639f89 commit 031b2c5

File tree

9 files changed

+39
-43
lines changed

9 files changed

+39
-43
lines changed

compiler/rustc_resolve/src/late.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,10 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
758758
// We don't need to deal with patterns in parameters, because
759759
// they are not possible for foreign or bodiless functions.
760760
self.with_lifetime_rib(
761-
LifetimeRibKind::AnonymousPassThrough(fn_id, false),
761+
LifetimeRibKind::AnonymousCreateParameter {
762+
binder: fn_id,
763+
report_in_path: false,
764+
},
762765
|this| walk_list!(this, visit_param, &sig.decl.inputs),
763766
);
764767
self.with_lifetime_rib(
@@ -792,18 +795,13 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
792795
// generic parameters. This is especially useful for `async fn`, where
793796
// these fresh generic parameters can be applied to the opaque `impl Trait`
794797
// return type.
795-
let rib = if async_node_id.is_some() {
796-
// Only emit a hard error for `async fn`, since this kind of
797-
// elision has always been allowed in regular `fn`s.
798+
this.with_lifetime_rib(
798799
LifetimeRibKind::AnonymousCreateParameter {
799800
binder: fn_id,
800-
report_in_path: true,
801-
}
802-
} else {
803-
LifetimeRibKind::AnonymousPassThrough(fn_id, false)
804-
};
805-
this.with_lifetime_rib(
806-
rib,
801+
// Only emit a hard error for `async fn`, since this kind of
802+
// elision has always been allowed in regular `fn`s.
803+
report_in_path: async_node_id.is_some(),
804+
},
807805
// Add each argument to the rib.
808806
|this| this.resolve_params(&declaration.inputs),
809807
);

src/test/ui/generic-associated-types/bugs/issue-87748.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied
44
LL | fn do_sth(_: u32) {}
55
| ^^^^^^^^^^^^^^^^^
66
|
7-
note: lifetime parameter instantiated with the anonymous lifetime #2 defined here
7+
note: lifetime parameter instantiated with the anonymous lifetime as defined here
88
--> $DIR/issue-87748.rs:18:5
99
|
1010
LL | fn do_sth(_: u32) {}
1111
| ^^^^^^^^^^^^^^^^^
12-
note: but lifetime parameter must outlive the anonymous lifetime #1 defined here
12+
note: but lifetime parameter must outlive the anonymous lifetime as defined here
1313
--> $DIR/issue-87748.rs:18:5
1414
|
1515
LL | fn do_sth(_: u32) {}

src/test/ui/generic-associated-types/issue-95305.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ trait Foo {
1111
fn foo(x: &impl Foo<Item<'_> = u32>) { }
1212
//~^ ERROR `'_` cannot be used here [E0637]
1313

14+
// Ok: the anonymous lifetime is bound to the function.
1415
fn bar(x: &impl for<'a> Foo<Item<'a> = &'_ u32>) { }
15-
//~^ ERROR missing lifetime specifier
16+
17+
// Ok: the anonymous lifetime is bound to the function.
18+
fn baz(x: &impl for<'a> Foo<Item<'a> = &u32>) { }
1619

1720
fn main() {}

src/test/ui/generic-associated-types/issue-95305.stderr

+2-14
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ error[E0637]: `'_` cannot be used here
44
LL | fn foo(x: &impl Foo<Item<'_> = u32>) { }
55
| ^^ `'_` is a reserved lifetime name
66

7-
error[E0106]: missing lifetime specifier
8-
--> $DIR/issue-95305.rs:14:41
9-
|
10-
LL | fn bar(x: &impl for<'a> Foo<Item<'a> = &'_ u32>) { }
11-
| ^^ expected named lifetime parameter
12-
|
13-
help: consider using the `'a` lifetime
14-
|
15-
LL | fn bar(x: &impl for<'a> Foo<Item<'a> = &'a u32>) { }
16-
| ~~
17-
18-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
198

20-
Some errors have detailed explanations: E0106, E0637.
21-
For more information about an error, try `rustc --explain E0106`.
9+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/issues/issue-37884.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn next(&'a mut self) -> Option<Self::Item>
66
|
77
= note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> Option<_>`
88
found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> Option<_>`
9-
note: the anonymous lifetime #1 defined here...
9+
note: the anonymous lifetime as defined here...
1010
--> $DIR/issue-37884.rs:6:5
1111
|
1212
LL | fn next(&'a mut self) -> Option<Self::Item>

src/test/ui/nll/ty-outlives/impl-trait-captures.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
22
--> $DIR/impl-trait-captures.rs:11:5
33
|
44
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
5-
| -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0)) T` captures the anonymous lifetime defined here
5+
| -- 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
66
LL | x
77
| ^
88
|
9-
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
9+
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
1010
|
11-
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrAnon(0)) {
12-
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11+
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::'_), '_)) {
12+
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1313

1414
error: aborting due to previous error
1515

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
fn f(_: impl Iterator<Item = &'_ ()>) {} //~ ERROR missing lifetime specifier
1+
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
2+
fn f(_: impl Iterator<Item = &'_ ()>) {}
3+
4+
// But that lifetime does not participate in resolution.
5+
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
6+
//~^ ERROR missing lifetime specifier
7+
28
fn main() {}

src/test/ui/suggestions/impl-trait-missing-lifetime.stderr

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/impl-trait-missing-lifetime.rs:1:31
2+
--> $DIR/impl-trait-missing-lifetime.rs:5:50
33
|
4-
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
5-
| ^^ expected named lifetime parameter
4+
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
5+
| ^^ expected named lifetime parameter
66
|
7-
help: consider introducing a named lifetime parameter
7+
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
8+
help: consider using the `'static` lifetime
89
|
9-
LL | fn f<'a>(_: impl Iterator<Item = &'a ()>) {}
10-
| ++++ ~~
10+
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() }
11+
| ~~~~~~~
1112

1213
error: aborting due to previous error
1314

src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ note: because this has an unmet lifetime requirement
2121
|
2222
LL | pub struct Wrapper<T: Trait>(T);
2323
| ^^^^^ introduces a `'static` lifetime requirement
24-
note: the anonymous lifetime #1 defined here...
25-
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5
24+
note: the anonymous lifetime as defined here...
25+
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:29
2626
|
2727
LL | pub fn repro(_: Wrapper<Ref>);
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
| ^^^
2929
note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
3030
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:1
3131
|

0 commit comments

Comments
 (0)