Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk
lint: add diagnostic translation migration lints Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic` or `AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. These lints are intended to be temporary - once all diagnostics have been changed then we can just change the APIs we have and that will enforce these constraints thereafter. r? `````@oli-obk`````
This commit is contained in:
commit
d8333a7b59
15 changed files with 327 additions and 37 deletions
|
@ -118,6 +118,9 @@ impl CheckAttrVisitor<'_> {
|
|||
sym::rustc_lint_query_instability => {
|
||||
self.check_rustc_lint_query_instability(&attr, span, target)
|
||||
}
|
||||
sym::rustc_lint_diagnostics => {
|
||||
self.check_rustc_lint_diagnostics(&attr, span, target)
|
||||
}
|
||||
sym::rustc_clean
|
||||
| sym::rustc_dirty
|
||||
| sym::rustc_if_this_changed
|
||||
|
@ -1624,12 +1627,9 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_rustc_lint_query_instability(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
/// Helper function for checking that the provided attribute is only applied to a function or
|
||||
/// method.
|
||||
fn check_applied_to_fn_or_method(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
let is_function = matches!(target, Target::Fn | Target::Method(..));
|
||||
if !is_function {
|
||||
self.tcx
|
||||
|
@ -1643,6 +1643,23 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks that the `#[rustc_lint_query_instability]` attribute is only applied to a function
|
||||
/// or method.
|
||||
fn check_rustc_lint_query_instability(
|
||||
&self,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
self.check_applied_to_fn_or_method(attr, span, target)
|
||||
}
|
||||
|
||||
/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
|
||||
/// method.
|
||||
fn check_rustc_lint_diagnostics(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
self.check_applied_to_fn_or_method(attr, span, target)
|
||||
}
|
||||
|
||||
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
|
||||
/// option is passed to the compiler.
|
||||
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue