about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2024-11-21 18:40:36 +0800
committerJieyou Xu <jieyouxu@outlook.com>2024-11-21 18:40:36 +0800
commit5d30436d244d207406ec8e4a2fbeb510555cba20 (patch)
tree02d6dbe9880b49697eaf526992cdb68640f20079 /tests/ui/pattern
parent318f96a8cf3eca5c4aaf60a992f349bce5c3fd41 (diff)
downloadrust-5d30436d244d207406ec8e4a2fbeb510555cba20.tar.gz
rust-5d30436d244d207406ec8e4a2fbeb510555cba20.zip
Re-delay a resolve `bug`
For the code pattern reported in
<https://github.com/rust-lang/rust/issues/133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<https://github.com/rust-lang/rust/pull/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 target tested case.
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/self-ctor-133272.rs21
-rw-r--r--tests/ui/pattern/self-ctor-133272.stderr15
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/pattern/self-ctor-133272.rs b/tests/ui/pattern/self-ctor-133272.rs
new file mode 100644
index 00000000000..ad64d6b88cd
--- /dev/null
+++ b/tests/ui/pattern/self-ctor-133272.rs
@@ -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
+    }
+}
diff --git a/tests/ui/pattern/self-ctor-133272.stderr b/tests/ui/pattern/self-ctor-133272.stderr
new file mode 100644
index 00000000000..bca55a43d9c
--- /dev/null
+++ b/tests/ui/pattern/self-ctor-133272.stderr
@@ -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`.