Skip to content

Commit 91813a7

Browse files
authored
Rollup merge of #95918 - compiler-errors:issue-95878, r=cjgillot
Delay a bug when we see SelfCtor in ref pattern Fixes #95878
2 parents 6aa875a + 285b9d1 commit 91813a7

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

compiler/rustc_resolve/src/late.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18881888
// These entities are explicitly allowed to be shadowed by fresh bindings.
18891889
None
18901890
}
1891+
Res::SelfCtor(_) => {
1892+
// We resolve `Self` in pattern position as an ident sometimes during recovery,
1893+
// so delay a bug instead of ICEing.
1894+
self.r.session.delay_span_bug(
1895+
ident.span,
1896+
"unexpected `SelfCtor` in pattern, expected identifier"
1897+
);
1898+
None
1899+
}
18911900
_ => span_bug!(
18921901
ident.span,
18931902
"unexpected resolution for an identifier in pattern: {:?}",

src/test/ui/pattern/issue-95878.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct Foo<'a>(&'a ());
2+
3+
impl<'a> Foo<'a> {
4+
fn spam(&mut self, baz: &mut Vec<u32>) {
5+
match 15 {
6+
ref Self => (),
7+
//~^ ERROR expected identifier, found keyword `Self`
8+
}
9+
}
10+
}
11+
12+
fn main() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected identifier, found keyword `Self`
2+
--> $DIR/issue-95878.rs:6:17
3+
|
4+
LL | ref Self => (),
5+
| ^^^^ expected identifier, found keyword
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)