1
Fork 0

migrate: OverruledAttribute

This commit is contained in:
Rejyr 2022-08-19 20:47:05 -04:00
parent 32e445af74
commit 7a6ae2367d
3 changed files with 75 additions and 12 deletions

View file

@ -394,6 +394,16 @@ lint_builtin_deref_nullptr = dereferencing a null pointer
lint_builtin_asm_labels = avoid using named labels in inline assembly lint_builtin_asm_labels = avoid using named labels in inline assembly
lint_overruled_attribute = {$lint_level}({$lint_source}) incompatible with previous forbid
.label = overruled by previous forbid
lint_default_source = `forbid` lint level is the default for {$id}
lint_node_source = `forbid` level set here
.note = {$reason}
lint_command_line_source = `forbid` lint level was set on command line
lint_malformed_attribute = malformed lint attribute input lint_malformed_attribute = malformed lint attribute input
lint_bad_attribute_argument = bad attribute argument lint_bad_attribute_argument = bad attribute argument

View file

@ -1,6 +1,46 @@
use rustc_errors::{fluent, AddSubdiagnostic};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic)]
#[error(lint::overruled_attribute, code = "E0453")]
pub struct OverruledAttribute {
#[primary_span]
pub span: Span,
#[label]
pub overruled: Span,
pub lint_level: String,
pub lint_source: Symbol,
#[subdiagnostic]
pub sub: OverruledAttributeSub,
}
//
pub enum OverruledAttributeSub {
DefaultSource { id: String },
NodeSource { span: Span, reason: Option<Symbol> },
CommandLineSource,
}
impl AddSubdiagnostic for OverruledAttributeSub {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self {
OverruledAttributeSub::DefaultSource { id } => {
diag.note(fluent::lint::default_source);
diag.set_arg("id", id);
}
OverruledAttributeSub::NodeSource { span, reason } => {
diag.span_label(span, fluent::lint::node_source);
if let Some(rationale) = reason {
diag.note(rationale.as_str());
}
}
OverruledAttributeSub::CommandLineSource => {
diag.note(fluent::lint::command_line_source);
}
}
}
}
#[derive(SessionDiagnostic)] #[derive(SessionDiagnostic)]
#[error(lint::malformed_attribute, code = "E0452")] #[error(lint::malformed_attribute, code = "E0452")]
pub struct MalformedAttribute { pub struct MalformedAttribute {

View file

@ -6,7 +6,7 @@ use crate::late::unerased_lint_store;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, LintDiagnosticBuilder, MultiSpan}; use rustc_errors::{Applicability, Diagnostic, LintDiagnosticBuilder, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{intravisit, HirId}; use rustc_hir::{intravisit, HirId};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -26,7 +26,10 @@ use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use tracing::debug; use tracing::debug;
use crate::errors::{MalformedAttribute, MalformedAttributeSub, UnknownTool}; use crate::errors::{
MalformedAttribute, MalformedAttributeSub, OverruledAttribute, OverruledAttributeSub,
UnknownTool,
};
fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
let store = unerased_lint_store(tcx); let store = unerased_lint_store(tcx);
@ -191,16 +194,26 @@ impl<'s> LintLevelsBuilder<'s> {
} }
}; };
if !fcw_warning { if !fcw_warning {
let mut diag_builder = struct_span_err!( self.sess.emit_err(OverruledAttribute {
self.sess, span: src.span(),
src.span(), overruled: src.span(),
E0453, lint_level: level.as_str().to_string(),
"{}({}) incompatible with previous forbid", lint_source: src.name(),
level.as_str(), sub: match old_src {
src.name(), LintLevelSource::Default => {
); OverruledAttributeSub::DefaultSource { id: id.to_string() }
decorate_diag(&mut diag_builder); }
diag_builder.emit(); LintLevelSource::Node(_, forbid_source_span, reason) => {
OverruledAttributeSub::NodeSource {
span: forbid_source_span,
reason,
}
}
LintLevelSource::CommandLine(_, _) => {
OverruledAttributeSub::CommandLineSource
}
},
});
} else { } else {
self.struct_lint( self.struct_lint(
FORBIDDEN_LINT_GROUPS, FORBIDDEN_LINT_GROUPS,