about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2025-05-28 09:34:08 +0800
committeryukang <moorekang@gmail.com>2025-05-28 09:35:10 +0800
commitadcd0bf5c36ee49acf390f0d75125da4efda35ac (patch)
treedd319a5fce944ec07504cd6538415c891ef80b40 /tests
parent0fc6f1672bdde8163164f10e46d2d9ffcaeb2161 (diff)
downloadrust-adcd0bf5c36ee49acf390f0d75125da4efda35ac.tar.gz
rust-adcd0bf5c36ee49acf390f0d75125da4efda35ac.zip
Fix ICE in tokenstream with contracts from parser recovery
Diffstat (limited to 'tests')
-rw-r--r--tests/crashes/140683.rs5
-rw-r--r--tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.rs13
-rw-r--r--tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.stderr34
-rw-r--r--tests/ui/macros/no-close-delim-issue-139248.rs5
-rw-r--r--tests/ui/macros/no-close-delim-issue-139248.stderr16
5 files changed, 54 insertions, 19 deletions
diff --git a/tests/crashes/140683.rs b/tests/crashes/140683.rs
deleted file mode 100644
index 74ea5c2533b..00000000000
--- a/tests/crashes/140683.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-//@ known-bug: #140683
-impl T {
-#[core::contracts::ensures]
-  fn b() { (loop) }
-}
diff --git a/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.rs b/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.rs
new file mode 100644
index 00000000000..68346a00ae1
--- /dev/null
+++ b/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.rs
@@ -0,0 +1,13 @@
+#![feature(contracts)]
+#![allow(incomplete_features)]
+
+struct T;
+
+impl T {
+    #[core::contracts::ensures] //~ ERROR expected a `Fn(&_)` closure, found `()`
+    fn b() {(loop)}
+    //~^ ERROR expected `{`, found `)`
+    //~| ERROR expected `{`, found `)`
+}
+
+fn main() {}
diff --git a/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.stderr b/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.stderr
new file mode 100644
index 00000000000..f1ffda2a9be
--- /dev/null
+++ b/tests/ui/macros/ice-in-tokenstream-for-contracts-issue-140683.stderr
@@ -0,0 +1,34 @@
+error: expected `{`, found `)`
+  --> $DIR/ice-in-tokenstream-for-contracts-issue-140683.rs:8:18
+   |
+LL |     fn b() {(loop)}
+   |              ----^ expected `{`
+   |              |
+   |              while parsing this `loop` expression
+
+error: expected `{`, found `)`
+  --> $DIR/ice-in-tokenstream-for-contracts-issue-140683.rs:8:18
+   |
+LL |     fn b() {(loop)}
+   |              ----^ expected `{`
+   |              |
+   |              while parsing this `loop` expression
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error[E0277]: expected a `Fn(&_)` closure, found `()`
+  --> $DIR/ice-in-tokenstream-for-contracts-issue-140683.rs:7:5
+   |
+LL |     #[core::contracts::ensures]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     expected an `Fn(&_)` closure, found `()`
+   |     required by a bound introduced by this call
+   |
+   = help: the trait `for<'a> Fn(&'a _)` is not implemented for `()`
+note: required by a bound in `build_check_ensures`
+  --> $SRC_DIR/core/src/contracts.rs:LL:COL
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/macros/no-close-delim-issue-139248.rs b/tests/ui/macros/no-close-delim-issue-139248.rs
index 86583b2724e..f15234eaff1 100644
--- a/tests/ui/macros/no-close-delim-issue-139248.rs
+++ b/tests/ui/macros/no-close-delim-issue-139248.rs
@@ -2,9 +2,8 @@
 
 macro_rules! m {
     (static a : () = $e:expr) => {
-        static a : () = $e;
-        //~^ ERROR macro expansion ends with an incomplete expression: expected expression
-    }
+        static a: () = $e;
+    };
 }
 
 m! { static a : () = (if b) }
diff --git a/tests/ui/macros/no-close-delim-issue-139248.stderr b/tests/ui/macros/no-close-delim-issue-139248.stderr
index 6ed41ae9b46..8aa39851b4b 100644
--- a/tests/ui/macros/no-close-delim-issue-139248.stderr
+++ b/tests/ui/macros/no-close-delim-issue-139248.stderr
@@ -1,33 +1,27 @@
 error: expected `{`, found `)`
-  --> $DIR/no-close-delim-issue-139248.rs:10:27
+  --> $DIR/no-close-delim-issue-139248.rs:9:27
    |
 LL | m! { static a : () = (if b) }
    |                           ^ expected `{`
    |
 note: the `if` expression is missing a block after this condition
-  --> $DIR/no-close-delim-issue-139248.rs:10:26
+  --> $DIR/no-close-delim-issue-139248.rs:9:26
    |
 LL | m! { static a : () = (if b) }
    |                          ^
 
 error: expected `{`, found `)`
-  --> $DIR/no-close-delim-issue-139248.rs:10:27
+  --> $DIR/no-close-delim-issue-139248.rs:9:27
    |
 LL | m! { static a : () = (if b) }
    |                           ^ expected `{`
    |
 note: the `if` expression is missing a block after this condition
-  --> $DIR/no-close-delim-issue-139248.rs:10:26
+  --> $DIR/no-close-delim-issue-139248.rs:9:26
    |
 LL | m! { static a : () = (if b) }
    |                          ^
    = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
 
-error: macro expansion ends with an incomplete expression: expected expression
-  --> $DIR/no-close-delim-issue-139248.rs:5:28
-   |
-LL |         static a : () = $e;
-   |                            ^ expected expression
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors