-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve expect
impl and handle #[expect(unfulfilled_lint_expectations)]
(RFC 2383)
#94670
Changes from all commits
47f3f66
165b558
d39d609
be84049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wondered why this doesn't warn here. It should override the But I would argue, that this is generally surprising behavior. Is this documented somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the source and this. But both say that it behaves like a lint group and not overrides the level. I think this is fine for now as it behaves like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed. Nothing to do in this PR. I just wanted to point out this behavior, because I thought it is generally unexpected/surprising. |
||
let mut v = vec![1, 1, 2, 3, 5]; | ||
} | ||
|
||
fn main() {} |
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior makes sense to me (as we discussed in the last PR) but before stabilization, we should decide if this is the correct approach. After stabilization, changing the behavior here will be potentially breaking. If we make this a hard error, then we can always relax that later backwards-compatibly.