Skip to content

Commit

Permalink
Prevent ICE from expected future breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Jun 25, 2024
1 parent b124b36 commit 1d667a0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ impl Emitter for JsonEmitter {
let data: Vec<FutureBreakageItem<'_>> = diags
.into_iter()
.map(|mut diag| {
if diag.level == crate::Level::Allow {
// The `FutureBreakageItem` is collected and serialized.
// However, the `allow` and `expect` lint levels can't usually
// be serialized. The lint level is overwritten to allow the
// serialization again and force a lint emission.
// (This is an educated guess. I didn't originally add this)
if matches!(diag.level, crate::Level::Allow | crate::Level::Expect(..)) {
diag.level = crate::Level::Warning;
}
FutureBreakageItem {
Expand Down
21 changes: 18 additions & 3 deletions tests/ui/lint/expect-future_breakage-crash-issue-126521.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ check-pass

// This test covers similar crashes from both #126521 and #126751.

macro_rules! foo {
Expand All @@ -12,12 +14,25 @@ macro_rules! bar {
};
}

fn main() {
fn allow() {
#[allow(semicolon_in_expressions_from_macros)]
let _ = foo!(x);

#[allow(semicolon_in_expressions_from_macros)]
let _ = bar!(x);
}

// The `semicolon_in_expressions_from_macros` lint seems to be emitted even if the
// lint level is `allow` as shown in the function above. The behavior of `expect`
// should mirror this behavior. However, no `unfulfilled_lint_expectation` lint
// is emitted, since the expectation is theoretically fulfilled.
fn expect() {
#[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);
}

fn main() {
}
61 changes: 45 additions & 16 deletions tests/ui/lint/expect-future_breakage-crash-issue-126521.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
error[E0658]: the `#[expect]` attribute is an experimental feature
--> $DIR/expect-future_breakage-crash-issue-126521.rs:16:5
Future incompatibility report: Future breakage diagnostic:
warning: trailing semicolon in macro used in expression position
--> $DIR/expect-future_breakage-crash-issue-126521.rs:7:13
|
LL | #[expect(semicolon_in_expressions_from_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | true;
| ^
...
LL | let _ = foo!(x);
| ------- in this macro invocation
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: the `#[expect]` attribute is an experimental feature
--> $DIR/expect-future_breakage-crash-issue-126521.rs:20:5
Future breakage diagnostic:
warning: trailing semicolon in macro used in expression position
--> $DIR/expect-future_breakage-crash-issue-126521.rs:13:35
|
LL | #[expect(semicolon_in_expressions_from_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | (5_i32.overflowing_sub(3));
| ^
...
LL | let _ = bar!(x);
| ------- in this macro invocation
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: this warning originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
Future breakage diagnostic:
warning: trailing semicolon in macro used in expression position
--> $DIR/expect-future_breakage-crash-issue-126521.rs:7:13
|
LL | true;
| ^
...
LL | let _ = foo!(x);
| ------- in this macro invocation
|
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

Future breakage diagnostic:
warning: trailing semicolon in macro used in expression position
--> $DIR/expect-future_breakage-crash-issue-126521.rs:13:35
|
LL | (5_i32.overflowing_sub(3));
| ^
...
LL | let _ = bar!(x);
| ------- in this macro invocation
|
= note: this warning originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info)

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

0 comments on commit 1d667a0

Please sign in to comment.