forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#94670 - xFrednet:rfc-2383-expect-impl-after…
…-party, r=flip1995,wesleywiser Improve `expect` impl and handle `#[expect(unfulfilled_lint_expectations)]` (RFC 2383) This PR updates unstable `ExpectationIds` in stashed diagnostics and adds some asserts to ensure that the stored expectations are really empty in the end. Additionally, it handles the `#[expect(unfulfilled_lint_expectations)]` case. According to the [Errors and lints docs](https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-levels) the `error` level should only be used _"when the compiler detects a problem that makes it unable to compile the program"_. As this isn't the case with `#[expect(unfulfilled_lint_expectations)]` I decided to only create a warning. To avoid adding a new lint only for this case, I simply emit a `unfulfilled_lint_expectations` diagnostic with an additional note. --- r? `@wesleywiser` I'm requesting a review from you since you reviewed the previous PR rust-lang#87835. You are welcome to reassign it if you're busy 🙃 rfc: [RFC-2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html) tracking issue: rust-lang#85549 cc: `@flip1995` In case you're also interested in this :)
- Loading branch information
Showing
8 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// check-pass | ||
// ignore-tidy-linelength | ||
|
||
#![feature(lint_reasons)] | ||
#![warn(unused_mut)] | ||
|
||
#![expect(unfulfilled_lint_expectations, reason = "idk why you would expect this")] | ||
//~^ WARNING this lint expectation is unfulfilled | ||
//~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default | ||
//~| NOTE idk why you would expect this | ||
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
|
||
#[expect(unfulfilled_lint_expectations, reason = "a local: idk why you would expect this")] | ||
//~^ WARNING this lint expectation is unfulfilled | ||
//~| NOTE a local: idk why you would expect this | ||
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
pub fn normal_test_fn() { | ||
#[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")] | ||
//~^ WARNING this lint expectation is unfulfilled | ||
//~| NOTE this expectation will create a diagnostic with the default lint level | ||
let mut v = vec![1, 1, 2, 3, 5]; | ||
v.sort(); | ||
|
||
// Check that lint lists including `unfulfilled_lint_expectations` are also handled correctly | ||
#[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")] | ||
//~^ WARNING this lint expectation is unfulfilled | ||
//~| NOTE the expectation for `unused` should be fulfilled | ||
//~| NOTE the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
let value = "I'm unused"; | ||
} | ||
|
||
#[expect(warnings, reason = "this suppresses all warnings and also suppresses itself. No warning will be issued")] | ||
pub fn expect_warnings() { | ||
// This lint trigger will be suppressed | ||
#[warn(unused_mut)] | ||
let mut v = vec![1, 1, 2, 3, 5]; | ||
} | ||
|
||
fn main() {} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
warning: this lint expectation is unfulfilled | ||
--> $DIR/expect_unfulfilled_expectation.rs:7:11 | ||
| | ||
LL | #![expect(unfulfilled_lint_expectations, reason = "idk why you would expect this")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unfulfilled_lint_expectations)]` on by default | ||
= note: idk why you would expect this | ||
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
|
||
warning: this lint expectation is unfulfilled | ||
--> $DIR/expect_unfulfilled_expectation.rs:13:10 | ||
| | ||
LL | #[expect(unfulfilled_lint_expectations, reason = "a local: idk why you would expect this")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: a local: idk why you would expect this | ||
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
|
||
warning: this lint expectation is unfulfilled | ||
--> $DIR/expect_unfulfilled_expectation.rs:18:14 | ||
| | ||
LL | #[expect(unused_mut, reason = "this expectation will create a diagnostic with the default lint level")] | ||
| ^^^^^^^^^^ | ||
| | ||
= note: this expectation will create a diagnostic with the default lint level | ||
|
||
warning: this lint expectation is unfulfilled | ||
--> $DIR/expect_unfulfilled_expectation.rs:25:22 | ||
| | ||
LL | #[expect(unused, unfulfilled_lint_expectations, reason = "the expectation for `unused` should be fulfilled")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the expectation for `unused` should be fulfilled | ||
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message | ||
|
||
warning: 4 warnings emitted | ||
|