mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Remove AttributeLintKind::InvalidTarget variant
This commit is contained in:
@@ -131,3 +131,23 @@ pub(crate) struct EmptyAttributeList<'a> {
|
||||
pub attr_path: &'a str,
|
||||
pub valid_without_list: bool,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`#[{$name}]` attribute cannot be used on {$target}")]
|
||||
#[warning(
|
||||
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
|
||||
)]
|
||||
#[help("`#[{$name}]` can {$only}be applied to {$applied}")]
|
||||
pub(crate) struct InvalidTargetLint {
|
||||
pub name: String,
|
||||
pub target: &'static str,
|
||||
pub applied: DiagArgValue,
|
||||
pub only: &'static str,
|
||||
#[suggestion(
|
||||
"remove the attribute",
|
||||
code = "",
|
||||
applicability = "machine-applicable",
|
||||
style = "tool-only"
|
||||
)]
|
||||
pub attr_span: Span,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_ast::AttrStyle;
|
||||
use rustc_errors::{DiagArgValue, MultiSpan, StashKey};
|
||||
use rustc_errors::{DiagArgValue, Diagnostic, MultiSpan, StashKey};
|
||||
use rustc_feature::Features;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
use rustc_hir::lints::AttributeLintKind;
|
||||
@@ -11,7 +11,8 @@
|
||||
use crate::AttributeParser;
|
||||
use crate::context::{AcceptContext, Stage};
|
||||
use crate::errors::{
|
||||
InvalidAttrAtCrateLevel, ItemFollowingInnerAttr, UnsupportedAttributesInWhere,
|
||||
InvalidAttrAtCrateLevel, InvalidTargetLint, ItemFollowingInnerAttr,
|
||||
UnsupportedAttributesInWhere,
|
||||
};
|
||||
use crate::session_diagnostics::InvalidTarget;
|
||||
use crate::target_checking::Policy::Allow;
|
||||
@@ -142,14 +143,19 @@ pub(crate) fn check_target(
|
||||
};
|
||||
|
||||
let attr_span = cx.attr_span;
|
||||
cx.emit_lint(
|
||||
cx.emit_dyn_lint(
|
||||
lint,
|
||||
AttributeLintKind::InvalidTarget {
|
||||
name: name.to_string(),
|
||||
target: target.plural_name(),
|
||||
only: if only { "only " } else { "" },
|
||||
applied,
|
||||
attr_span,
|
||||
move |dcx, level| {
|
||||
InvalidTargetLint {
|
||||
name: name.to_string(),
|
||||
target: target.plural_name(),
|
||||
only: if only { "only " } else { "" },
|
||||
applied: DiagArgValue::StrListSepByAnd(
|
||||
applied.iter().map(|i| Cow::Owned(i.to_string())).collect(),
|
||||
),
|
||||
attr_span,
|
||||
}
|
||||
.into_diag(dcx, level)
|
||||
},
|
||||
attr_span,
|
||||
);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::any::Any;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_data_structures::sync::DynSend;
|
||||
use rustc_errors::{Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, Level};
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
|
||||
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::Session;
|
||||
@@ -35,18 +34,6 @@ pub struct DecorateAttrLint<'a, 'sess, 'tcx> {
|
||||
impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
match self.diagnostic {
|
||||
AttributeLintKind::InvalidTarget { name, target, applied, only, attr_span } => {
|
||||
lints::InvalidTargetLint {
|
||||
name: name.clone(),
|
||||
target,
|
||||
applied: DiagArgValue::StrListSepByAnd(
|
||||
applied.into_iter().map(|i| Cow::Owned(i.to_string())).collect(),
|
||||
),
|
||||
only,
|
||||
attr_span: *attr_span,
|
||||
}
|
||||
.into_diag(dcx, level)
|
||||
}
|
||||
&AttributeLintKind::InvalidStyle {
|
||||
ref name,
|
||||
is_used_as_inner,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::formatting::DiagMessageAddArg;
|
||||
use rustc_errors::{
|
||||
Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
|
||||
Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
|
||||
EmissionGuarantee, Level, Subdiagnostic, SuggestionStyle, msg,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
@@ -3282,26 +3282,6 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("`#[{$name}]` attribute cannot be used on {$target}")]
|
||||
#[warning(
|
||||
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
|
||||
)]
|
||||
#[help("`#[{$name}]` can {$only}be applied to {$applied}")]
|
||||
pub(crate) struct InvalidTargetLint {
|
||||
pub name: String,
|
||||
pub target: &'static str,
|
||||
pub applied: DiagArgValue,
|
||||
pub only: &'static str,
|
||||
#[suggestion(
|
||||
"remove the attribute",
|
||||
code = "",
|
||||
applicability = "machine-applicable",
|
||||
style = "tool-only"
|
||||
)]
|
||||
pub attr_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(
|
||||
"{$is_used_as_inner ->
|
||||
|
||||
@@ -654,88 +654,35 @@ pub enum DeprecatedSinceKind {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AttributeLintKind {
|
||||
InvalidTarget {
|
||||
name: String,
|
||||
target: &'static str,
|
||||
applied: Vec<String>,
|
||||
only: &'static str,
|
||||
attr_span: Span,
|
||||
},
|
||||
InvalidStyle {
|
||||
name: String,
|
||||
is_used_as_inner: bool,
|
||||
target: &'static str,
|
||||
target_span: Span,
|
||||
},
|
||||
InvalidStyle { name: String, is_used_as_inner: bool, target: &'static str, target_span: Span },
|
||||
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
|
||||
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
|
||||
DuplicateDocAlias {
|
||||
first_definition: Span,
|
||||
},
|
||||
DuplicateDocAlias { first_definition: Span },
|
||||
DocAutoCfgExpectsHideOrShow,
|
||||
DocAutoCfgHideShowUnexpectedItem {
|
||||
attr_name: Symbol,
|
||||
},
|
||||
DocAutoCfgHideShowExpectsList {
|
||||
attr_name: Symbol,
|
||||
},
|
||||
DocAutoCfgHideShowUnexpectedItem { attr_name: Symbol },
|
||||
DocAutoCfgHideShowExpectsList { attr_name: Symbol },
|
||||
DocInvalid,
|
||||
AmbiguousDeriveHelpers,
|
||||
DocUnknownInclude {
|
||||
span: Span,
|
||||
inner: &'static str,
|
||||
value: Symbol,
|
||||
},
|
||||
DocUnknownSpotlight {
|
||||
span: Span,
|
||||
},
|
||||
DocUnknownPasses {
|
||||
name: Symbol,
|
||||
span: Span,
|
||||
},
|
||||
DocUnknownPlugins {
|
||||
span: Span,
|
||||
},
|
||||
DocUnknownAny {
|
||||
name: Symbol,
|
||||
},
|
||||
DocUnknownInclude { span: Span, inner: &'static str, value: Symbol },
|
||||
DocUnknownSpotlight { span: Span },
|
||||
DocUnknownPasses { name: Symbol, span: Span },
|
||||
DocUnknownPlugins { span: Span },
|
||||
DocUnknownAny { name: Symbol },
|
||||
DocAutoCfgWrongLiteral,
|
||||
DocTestTakesList,
|
||||
DocTestUnknown {
|
||||
name: Symbol,
|
||||
},
|
||||
DocTestUnknown { name: Symbol },
|
||||
DocTestLiteral,
|
||||
AttrCrateLevelOnly,
|
||||
DoNotRecommendDoesNotExpectArgs,
|
||||
CrateTypeUnknown {
|
||||
span: Span,
|
||||
suggested: Option<Symbol>,
|
||||
},
|
||||
CrateTypeUnknown { span: Span, suggested: Option<Symbol> },
|
||||
MalformedDoc,
|
||||
ExpectedNoArgs,
|
||||
ExpectedNameValue,
|
||||
MalFormedDiagnosticAttribute {
|
||||
attribute: &'static str,
|
||||
options: &'static str,
|
||||
span: Span,
|
||||
},
|
||||
MalformedDiagnosticFormat {
|
||||
warning: FormatWarning,
|
||||
},
|
||||
DiagnosticWrappedParserError {
|
||||
description: String,
|
||||
label: String,
|
||||
span: Span,
|
||||
},
|
||||
IgnoredDiagnosticOption {
|
||||
option_name: Symbol,
|
||||
first_span: Span,
|
||||
later_span: Span,
|
||||
},
|
||||
MissingOptionsForDiagnosticAttribute {
|
||||
attribute: &'static str,
|
||||
options: &'static str,
|
||||
},
|
||||
MalFormedDiagnosticAttribute { attribute: &'static str, options: &'static str, span: Span },
|
||||
MalformedDiagnosticFormat { warning: FormatWarning },
|
||||
DiagnosticWrappedParserError { description: String, label: String, span: Span },
|
||||
IgnoredDiagnosticOption { option_name: Symbol, first_span: Span, later_span: Span },
|
||||
MissingOptionsForDiagnosticAttribute { attribute: &'static str, options: &'static str },
|
||||
NonMetaItemDiagnosticAttribute,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user