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

Re-delay a resolve bug related to Self-ctor in patterns #133286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3940,12 +3940,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
Res::SelfCtor(_) => {
// We resolve `Self` in pattern position as an ident sometimes during recovery,
// so delay a bug instead of ICEing. (Note: is this no longer true? We now ICE. If
// this triggers, please convert to a delayed bug and add a test.)
self.r.dcx().span_bug(
// so delay a bug instead of ICEing.
self.r.dcx().span_delayed_bug(
ident.span,
"unexpected `SelfCtor` in pattern, expected identifier"
);
None
}
_ => span_bug!(
ident.span,
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/pattern/self-ctor-133272.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/133272>, where a `ref Self` ctor
//! makes it possible to hit a `delayed_bug` that was converted into a `span_bug` in
//! <https://github.com/rust-lang/rust/pull/121208>, and hitting this reveals that we did not have
//! test coverage for this specific code pattern (heh) previously.
//!
//! # References
//!
//! - ICE bug report: <https://github.com/rust-lang/rust/issues/133272>.
//! - Previous PR to change `delayed_bug` -> `span_bug`:
//! <https://github.com/rust-lang/rust/pull/121208>
#![crate_type = "lib"]

struct Foo;

impl Foo {
fn fun() {
let S { ref Self } = todo!();
//~^ ERROR expected identifier, found keyword `Self`
//~| ERROR cannot find struct, variant or union type `S` in this scope
}
}
15 changes: 15 additions & 0 deletions tests/ui/pattern/self-ctor-133272.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: expected identifier, found keyword `Self`
--> $DIR/self-ctor-133272.rs:17:21
|
LL | let S { ref Self } = todo!();
| ^^^^ expected identifier, found keyword

error[E0422]: cannot find struct, variant or union type `S` in this scope
--> $DIR/self-ctor-133272.rs:17:13
|
LL | let S { ref Self } = todo!();
| ^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0422`.
Loading