-
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
Implementation of the expect
attribute (RFC 2383)
#87835
Implementation of the expect
attribute (RFC 2383)
#87835
Conversation
This comment has been minimized.
This comment has been minimized.
b7c9122
to
bb85726
Compare
I don't think I can help much with this. You might want to add a test for macros however. |
That's a very good pointer, thank you for taking a look 🙃 |
d79019e
to
3cdf066
Compare
This comment has been minimized.
This comment has been minimized.
3cdf066
to
9e43706
Compare
Hello, I believe that this PR is ready for review. There is definitely one To-Do that has to be addressed before the merge when it comes to incremental compilation and the stability of the @flip1995 You offered in the last PR to aid with the review. I would appreciate it if you could take a look at this one and maybe give some feedback 🙃. r? @wesleywiser Would you be willing to take over the main review of this? 🙃 |
src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.rs
Outdated
Show resolved
Hide resolved
Something that came to my mind this morning under the shower: What if you expect an EarlyLintPass and a LateLintPass lint at the same item. So: #[expect(some_early_lints)]
#[expect(some_late_lints)]
fn foo() {
// code triggering all specified lints
} I think this isn't a problem after #87337 gets merged, but I would add a test for it anyway. |
That's a good thought. The expectations are currently checked at the end of the last lint pass, meaning that it should still work as expected. Adding a test for it is still a very good idea. I'll look up some lints for a test like that. What are your thoughts on an example where an item has multiple expect attributes with the same lint? For instance #[expect(unused_variables)] // 1
#[expect(unused_variables)] // 2
fn main() {
let x = 0;
} A test with normal lint levels shows that they are processed in order top-down (example playground). This means that the current implementation would mark the second expectation as fulfilled, and lint about the first one. Does this seem reasonable? 🙃 |
Intuitively I would expect no warning in this case, if adding 2 identical |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
5c1229f
to
5275d02
Compare
The usage of @bors try |
⌛ Trying commit 5275d02 with merge 5d83a73fa38efb9763fdd19f1d6ffdb90cc99de7... |
☀️ Try build successful - checks-actions |
@bors r+ |
📌 Commit 5275d02 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (10913c0): comparison url. Summary: This benchmark run did not return any relevant results. 9 results were found to be statistically significant but too small to be relevant. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
…-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 :)
…-warn, r=wesleywiser,flip1995 Support lint expectations for `--force-warn` lints (RFC 2383) Rustc has a `--force-warn` flag, which overrides lint level attributes and forces the diagnostics to always be warn. This means, that for lint expectations, the diagnostic can't be suppressed as usual. This also means that the expectation would not be fulfilled, even if a lint had been triggered in the expected scope. This PR now also tracks the expectation ID in the `ForceWarn` level. I've also made some minor adjustments, to possibly catch more bugs and make the whole implementation more robust. This will probably conflict with rust-lang#97718. That PR should ideally be reviewed and merged first. The conflict itself will be trivial to fix. --- r? `@wesleywiser` cc: `@flip1995` since you've helped with the initial review and also discussed this topic with me. 🙃 Follow-up of: rust-lang#87835 Issue: rust-lang#85549 Yeah, and that's it.
…wesleywiser,flip1995 Support lint expectations for `--force-warn` lints (RFC 2383) Rustc has a `--force-warn` flag, which overrides lint level attributes and forces the diagnostics to always be warn. This means, that for lint expectations, the diagnostic can't be suppressed as usual. This also means that the expectation would not be fulfilled, even if a lint had been triggered in the expected scope. This PR now also tracks the expectation ID in the `ForceWarn` level. I've also made some minor adjustments, to possibly catch more bugs and make the whole implementation more robust. This will probably conflict with rust-lang/rust#97718. That PR should ideally be reviewed and merged first. The conflict itself will be trivial to fix. --- r? `@wesleywiser` cc: `@flip1995` since you've helped with the initial review and also discussed this topic with me. 🙃 Follow-up of: rust-lang/rust#87835 Issue: rust-lang/rust#85549 Yeah, and that's it.
This is an implementation of the
expect
attribute as described in RFC-2383. The attribute allows the suppression of lint message by expecting them. Unfulfilled lint expectations (meaning no expected lint was caught) will emit theunfulfilled_lint_expectations
lint at theexpect
attribute.Example
input
output
Implementation
This implementation introduces
Expect
as a new lint level for diagnostics, which have been expected. All lint expectations marked via theexpect
attribute are collected in theLintLevelsBuilder
and assigned an ID that is stored in the new lint level. TheLintLevelsBuilder
stores all found expectations and the data needed to emit theunfulfilled_lint_expectations
in theLintLevelsMap
which is the result of thelint_levels()
query.The
rustc_errors::HandlerInner
is the central error handler in rustc and handles the emission of all diagnostics. Lint message with the levelExpect
are suppressed during this emission, while the expectation ID is stored in a set which marks them as fulfilled. The last step is then so simply check if all expectations collected by theLintLevelsBuilder
in theLintLevelsMap
have been marked as fulfilled in therustc_errors::HandlerInner
. Otherwise, a new lint message will be emitted.The implementation of the
LintExpectationId
required some special handling to make it stable between sessions. Lints can be emitted duringEarlyLintPass
es. At this stage, it's not possible to create a stable identifier. The level instead stores an unstable identifier, which is later converted to a stableLintExpectationId
.Followup TO-DOs
Moved to: #85549
Open questions
I also have a few open questions where I would like to get feedback on:
expect
attribute to something else. (Initiated by @Ixrec here, suggestion from @scottmcm to use#[should_lint(...)]
here). No real conclusion was drawn on that point from my understanding. Is this still open for discussion, or was this discarded with the merge of the RFC?force-warn
lint level?This approach was inspired by a discussion with @LeSeulArtichaut.
RFC tracking issue: #54503
Mentoring/Implementation issue: #85549