-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implementation of the expect
attribute (RFC 2383)
#87835
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
Merged
bors
merged 13 commits into
rust-lang:master
from
xFrednet:rfc-2383-expect-attribute-with-ids
Mar 3, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fef3d9
Added `Expect` lint level and attribute (RFC-2383)
xFrednet f467a58
Added `unfulfilled_lint_expectations` lint for (RFC-2383)
xFrednet 2ca9037
Set `LintExpectationId` in level and collect fulfilled ones (RFC-2383)
xFrednet 44cb8fa
Check lint expectations and emit lint if unfulfilled (RFC-2383)
xFrednet 33a5945
Make `LintExpectationId` stable between compilation sessions (RFC-2383)
xFrednet a9bf9ea
Add UI tests for the `expect` attribute (RFC-2383)
xFrednet aa2a0a8
Expect each lint in attribute individually (RFC-2383)
xFrednet 43dc430
Test `expect` with `forbid` and fix doc errors (RFC-2383)
xFrednet a14456f
Reduced the size of `LintExpectationId` by 12 bytes (RFC-2383)
xFrednet 3414ad9
Emit `unfullfilled_lint_expectation` using a `HirId` for performance …
xFrednet 4887eb7
Added `panics` for unreachable states for expectations (RFC 2383)
xFrednet defc056
Address review comments
xFrednet 5275d02
Use Vec for expectations to have a constant order (RFC-2383)
xFrednet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
use crate::builtin; | ||
use rustc_hir::HirId; | ||
use rustc_middle::{lint::LintExpectation, ty::TyCtxt}; | ||
use rustc_session::lint::LintExpectationId; | ||
use rustc_span::symbol::sym; | ||
|
||
pub fn check_expectations(tcx: TyCtxt<'_>) { | ||
if !tcx.sess.features_untracked().enabled(sym::lint_reasons) { | ||
xFrednet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids(); | ||
let lint_expectations = &tcx.lint_levels(()).lint_expectations; | ||
|
||
for (id, expectation) in lint_expectations { | ||
if !fulfilled_expectations.contains(id) { | ||
// This check will always be true, since `lint_expectations` only | ||
xFrednet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// holds stable ids | ||
if let LintExpectationId::Stable { hir_id, .. } = id { | ||
emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation); | ||
} else { | ||
unreachable!("at this stage all `LintExpectationId`s are stable"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn emit_unfulfilled_expectation_lint( | ||
tcx: TyCtxt<'_>, | ||
hir_id: HirId, | ||
expectation: &LintExpectation, | ||
) { | ||
// FIXME: The current implementation doesn't cover cases where the | ||
// `unfulfilled_lint_expectations` is actually expected by another lint | ||
// expectation. This can be added here by checking the lint level and | ||
// retrieving the `LintExpectationId` if it was expected. | ||
tcx.struct_span_lint_hir( | ||
builtin::UNFULFILLED_LINT_EXPECTATIONS, | ||
hir_id, | ||
expectation.emission_span, | ||
|diag| { | ||
let mut diag = diag.build("this lint expectation is unfulfilled"); | ||
if let Some(rationale) = expectation.reason { | ||
diag.note(&rationale.as_str()); | ||
} | ||
diag.emit(); | ||
}, | ||
); | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.