Skip to content

Commit 8d66f01

Browse files
authored
Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkov
Do not recurse into const generic args when resolving self lifetime elision. Fixes #110899 r? `@petrochenkov`
2 parents 0ac8ebd + 8972a23 commit 8d66f01

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Diff for: compiler/rustc_resolve/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20702070
}
20712071
visit::walk_ty(self, ty)
20722072
}
2073+
2074+
// A type may have an expression as a const generic argument.
2075+
// We do not want to recurse into those.
2076+
fn visit_expr(&mut self, _: &'a Expr) {}
20732077
}
20742078

20752079
let impl_self = self

Diff for: 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() {}

Diff for: tests/ui/self/elision/nested-item.stderr

+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)