Skip to content

Commit 8972a23

Browse files
committed
Do not recurse into const generic args when resolving self lifetime elision.
1 parent 89158e2 commit 8972a23

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

compiler/rustc_resolve/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20752075
}
20762076
visit::walk_ty(self, ty)
20772077
}
2078+
2079+
// A type may have an expression as a const generic argument.
2080+
// We do not want to recurse into those.
2081+
fn visit_expr(&mut self, _: &'a Expr) {}
20782082
}
20792083

20802084
let impl_self = self

tests/ui/self/elision/nested-item.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for #110899.
2+
// When looking for the elided lifetime for `wrap`,
3+
// we must not consider the lifetimes in `bar` as candidates.
4+
5+
fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
6+
//~^ ERROR `self` parameter is only allowed in associated functions
7+
//~| ERROR `self` parameter is only allowed in associated functions
8+
//~| ERROR missing lifetime specifier
9+
//~| ERROR cannot find type `Wrap` in this scope
10+
&()
11+
}
12+
13+
fn main() {}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: `self` parameter is only allowed in associated functions
2+
--> $DIR/nested-item.rs:5:9
3+
|
4+
LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
5+
| ^^^^ not semantically valid as function parameter
6+
|
7+
= note: associated functions are those in `impl` or `trait` definitions
8+
9+
error: `self` parameter is only allowed in associated functions
10+
--> $DIR/nested-item.rs:5:29
11+
|
12+
LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
13+
| ^^^^^ not semantically valid as function parameter
14+
|
15+
= note: associated functions are those in `impl` or `trait` definitions
16+
17+
error[E0106]: missing lifetime specifier
18+
--> $DIR/nested-item.rs:5:46
19+
|
20+
LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
21+
| ^ expected named lifetime parameter
22+
|
23+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
24+
help: consider using the `'static` lifetime
25+
|
26+
LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &'static () {
27+
| +++++++
28+
29+
error[E0412]: cannot find type `Wrap` in this scope
30+
--> $DIR/nested-item.rs:5:15
31+
|
32+
LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() {
33+
| ^^^^ not found in this scope
34+
35+
error: aborting due to 4 previous errors
36+
37+
Some errors have detailed explanations: E0106, E0412.
38+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)