Skip to content

Commit 285b9d1

Browse files
Delay a bug when we see SelfCtor in ref pattern
1 parent 18f32b7 commit 285b9d1

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
@@ -1870,6 +1870,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18701870
// These entities are explicitly allowed to be shadowed by fresh bindings.
18711871
None
18721872
}
1873+
Res::SelfCtor(_) => {
1874+
// We resolve `Self` in pattern position as an ident sometimes during recovery,
1875+
// so delay a bug instead of ICEing.
1876+
self.r.session.delay_span_bug(
1877+
ident.span,
1878+
"unexpected `SelfCtor` in pattern, expected identifier"
1879+
);
1880+
None
1881+
}
18731882
_ => span_bug!(
18741883
ident.span,
18751884
"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)