Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aacf5a9

Browse files
authoredNov 23, 2024
Unrolled build for rust-lang#133286
Rollup merge of rust-lang#133286 - jieyouxu:bug-ourselves, r=compiler-errors Re-delay a resolve `bug` related to `Self`-ctor in patterns For the code pattern reported in <rust-lang#133272>, ```rs impl Foo { fn fun() { let S { ref Self } = todo!(); } } ``` <rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case. Follow-up to rust-lang#121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps). Fixes rust-lang#133272.
2 parents ff1737b + 5d30436 commit aacf5a9

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed
 

‎compiler/rustc_resolve/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3940,12 +3940,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39403940
}
39413941
Res::SelfCtor(_) => {
39423942
// We resolve `Self` in pattern position as an ident sometimes during recovery,
3943-
// so delay a bug instead of ICEing. (Note: is this no longer true? We now ICE. If
3944-
// this triggers, please convert to a delayed bug and add a test.)
3945-
self.r.dcx().span_bug(
3943+
// so delay a bug instead of ICEing.
3944+
self.r.dcx().span_delayed_bug(
39463945
ident.span,
39473946
"unexpected `SelfCtor` in pattern, expected identifier"
39483947
);
3948+
None
39493949
}
39503950
_ => span_bug!(
39513951
ident.span,

‎tests/ui/pattern/self-ctor-133272.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/133272>, where a `ref Self` ctor
2+
//! makes it possible to hit a `delayed_bug` that was converted into a `span_bug` in
3+
//! <https://github.com/rust-lang/rust/pull/121208>, and hitting this reveals that we did not have
4+
//! test coverage for this specific code pattern (heh) previously.
5+
//!
6+
//! # References
7+
//!
8+
//! - ICE bug report: <https://github.com/rust-lang/rust/issues/133272>.
9+
//! - Previous PR to change `delayed_bug` -> `span_bug`:
10+
//! <https://github.com/rust-lang/rust/pull/121208>
11+
#![crate_type = "lib"]
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
fn fun() {
17+
let S { ref Self } = todo!();
18+
//~^ ERROR expected identifier, found keyword `Self`
19+
//~| ERROR cannot find struct, variant or union type `S` in this scope
20+
}
21+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: expected identifier, found keyword `Self`
2+
--> $DIR/self-ctor-133272.rs:17:21
3+
|
4+
LL | let S { ref Self } = todo!();
5+
| ^^^^ expected identifier, found keyword
6+
7+
error[E0422]: cannot find struct, variant or union type `S` in this scope
8+
--> $DIR/self-ctor-133272.rs:17:13
9+
|
10+
LL | let S { ref Self } = todo!();
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0422`.

0 commit comments

Comments
 (0)
Failed to load comments.