about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-06-21 09:12:38 +0200
committerGitHub <noreply@github.com>2024-06-21 09:12:38 +0200
commitd86736c9be8c06988470dc90d086d12d9cbcd1bb (patch)
tree3d7d46c076a16743d963263914b749a97c889863
parentf577d808b7701cd76a8906b83a1edd839555a5f2 (diff)
parentd6efcbb760ae0a17ed05e843bdced7afee74695a (diff)
downloadrust-d86736c9be8c06988470dc90d086d12d9cbcd1bb.tar.gz
rust-d86736c9be8c06988470dc90d086d12d9cbcd1bb.zip
Rollup merge of #126774 - nnethercote:fix-126751, r=oli-obk
Fix another assertion failure for some Expect diagnostics.

Very similar to #126719. So much so that I added a new case to the test from that PR rather than creating a new one.

r? `@oli-obk`
-rw-r--r--compiler/rustc_errors/src/lib.rs8
-rw-r--r--tests/ui/lint/expect-future_breakage-crash-issue-126521.rs12
-rw-r--r--tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr14
3 files changed, 28 insertions, 6 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 620f56c01e8..91112a57277 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -1456,10 +1456,10 @@ impl DiagCtxtInner {
         }
 
         if diagnostic.has_future_breakage() {
-            // Future breakages aren't emitted if they're `Level::Allow`,
-            // but they still need to be constructed and stashed below,
-            // so they'll trigger the must_produce_diag check.
-            assert!(matches!(diagnostic.level, Error | Warning | Allow));
+            // Future breakages aren't emitted if they're `Level::Allow` or
+            // `Level::Expect`, but they still need to be constructed and
+            // stashed below, so they'll trigger the must_produce_diag check.
+            assert!(matches!(diagnostic.level, Error | Warning | Allow | Expect(_)));
             self.future_breakage_diagnostics.push(diagnostic.clone());
         }
 
diff --git a/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs b/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs
index a3c8544613b..0e622ff3aaf 100644
--- a/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs
+++ b/tests/ui/lint/expect-future_breakage-crash-issue-126521.rs
@@ -1,11 +1,23 @@
+// This test covers similar crashes from both #126521 and #126751.
+
 macro_rules! foo {
     ($val:ident) => {
         true;
     };
 }
 
+macro_rules! bar {
+    ($val:ident) => {
+        (5_i32.overflowing_sub(3));
+    };
+}
+
 fn main() {
     #[expect(semicolon_in_expressions_from_macros)]
     //~^ ERROR the `#[expect]` attribute is an experimental feature
     let _ = foo!(x);
+
+    #[expect(semicolon_in_expressions_from_macros)]
+    //~^ ERROR the `#[expect]` attribute is an experimental feature
+    let _ = bar!(x);
 }
diff --git a/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr b/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr
index b24831b1ae4..994630ec23b 100644
--- a/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr
+++ b/tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr
@@ -1,5 +1,5 @@
 error[E0658]: the `#[expect]` attribute is an experimental feature
-  --> $DIR/expect-future_breakage-crash-issue-126521.rs:8:5
+  --> $DIR/expect-future_breakage-crash-issue-126521.rs:16:5
    |
 LL |     #[expect(semicolon_in_expressions_from_macros)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,6 +8,16 @@ LL |     #[expect(semicolon_in_expressions_from_macros)]
    = help: add `#![feature(lint_reasons)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error: aborting due to 1 previous error
+error[E0658]: the `#[expect]` attribute is an experimental feature
+  --> $DIR/expect-future_breakage-crash-issue-126521.rs:20:5
+   |
+LL |     #[expect(semicolon_in_expressions_from_macros)]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #54503 <https://github.com/rust-lang/rust/issues/54503> for more information
+   = help: add `#![feature(lint_reasons)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0658`.