Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay a bug when we see SelfCtor in ref pattern #95918

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,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