Skip to content

Commit

Permalink
Rollup merge of #95918 - compiler-errors:issue-95878, r=cjgillot
Browse files Browse the repository at this point in the history
Delay a bug when we see SelfCtor in ref pattern

Fixes #95878
  • Loading branch information
Dylan-DPC committed Apr 12, 2022
2 parents 6aa875a + 285b9d1 commit 91813a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// These entities are explicitly allowed to be shadowed by fresh bindings.
None
}
Res::SelfCtor(_) => {
// We resolve `Self` in pattern position as an ident sometimes during recovery,
// so delay a bug instead of ICEing.
self.r.session.delay_span_bug(
ident.span,
"unexpected `SelfCtor` in pattern, expected identifier"
);
None
}
_ => span_bug!(
ident.span,
"unexpected resolution for an identifier in pattern: {:?}",
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/pattern/issue-95878.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
fn spam(&mut self, baz: &mut Vec<u32>) {
match 15 {
ref Self => (),
//~^ ERROR expected identifier, found keyword `Self`
}
}
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/pattern/issue-95878.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected identifier, found keyword `Self`
--> $DIR/issue-95878.rs:6:17
|
LL | ref Self => (),
| ^^^^ expected identifier, found keyword

error: aborting due to previous error

0 comments on commit 91813a7

Please sign in to comment.