Prevent ICE from expected future breakage

This commit is contained in:
xFrednet 2024-06-25 20:05:37 +02:00
parent b124b3666e
commit 1d667a0937
No known key found for this signature in database
GPG key ID: F5C59D0E669E5302
3 changed files with 69 additions and 20 deletions

View file

@ -135,7 +135,12 @@ fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>) {
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 {

View file

@ -1,3 +1,5 @@
//@ check-pass
// This test covers similar crashes from both #126521 and #126751.
macro_rules! foo {
@ -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() {
}

View file

@ -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`.