mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Remove more BuiltinLintDiag in rustc_attr_parsing
This commit is contained in:
@@ -2,18 +2,18 @@
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{AttrStyle, NodeId, token};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_feature::{AttributeTemplate, Features};
|
||||
use rustc_hir::attrs::CfgEntry;
|
||||
use rustc_hir::{AttrPath, Target};
|
||||
use rustc_parse::exp;
|
||||
use rustc_parse::parser::{Parser, Recovery};
|
||||
use rustc_session::Session;
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::UNREACHABLE_CFG_SELECT_PREDICATES;
|
||||
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
|
||||
|
||||
use crate::parser::{AllowExprMetavar, MetaItemOrLitParser};
|
||||
use crate::{AttributeParser, ParsedDescription, ShouldEmit, parse_cfg_entry};
|
||||
use crate::{AttributeParser, ParsedDescription, ShouldEmit, errors, parse_cfg_entry};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum CfgSelectPredicate {
|
||||
@@ -153,11 +153,17 @@ fn lint_unreachable(
|
||||
|
||||
let branch_is_unreachable = |predicate: CfgSelectPredicate, wildcard_span| {
|
||||
let span = predicate.span();
|
||||
p.psess.buffer_lint(
|
||||
p.psess.dyn_buffer_lint(
|
||||
UNREACHABLE_CFG_SELECT_PREDICATES,
|
||||
span,
|
||||
lint_node_id,
|
||||
BuiltinLintDiag::UnreachableCfg { span, wildcard_span },
|
||||
move |dcx, level| match wildcard_span {
|
||||
Some(wildcard_span) => {
|
||||
errors::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
|
||||
.into_diag(dcx, level)
|
||||
}
|
||||
None => errors::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ pub(crate) struct ItemFollowingInnerAttr {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("unreachable configuration predicate")]
|
||||
pub(crate) struct UnreachableCfgSelectPredicate {
|
||||
#[label("this configuration predicate is never reached")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("most attributes are not supported in `where` clauses")]
|
||||
#[help("only `#[cfg]` and `#[cfg_attr]` are supported")]
|
||||
@@ -33,3 +40,13 @@ pub(crate) struct UnsupportedAttributesInWhere {
|
||||
#[primary_span]
|
||||
pub span: MultiSpan,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("unreachable configuration predicate")]
|
||||
pub(crate) struct UnreachableCfgSelectPredicateWildcard {
|
||||
#[label("this configuration predicate is never reached")]
|
||||
pub span: Span,
|
||||
|
||||
#[label("always matches")]
|
||||
pub wildcard_span: Span,
|
||||
}
|
||||
|
||||
@@ -224,13 +224,6 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
|
||||
}
|
||||
.into_diag(dcx, level)
|
||||
}
|
||||
BuiltinLintDiag::UnreachableCfg { span, wildcard_span } => match wildcard_span {
|
||||
Some(wildcard_span) => {
|
||||
lints::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
|
||||
.into_diag(dcx, level)
|
||||
}
|
||||
None => lints::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
|
||||
},
|
||||
|
||||
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
|
||||
lints::UnusedCrateDependency { extern_crate, local_crate }.into_diag(dcx, level)
|
||||
|
||||
@@ -3709,23 +3709,6 @@ pub(crate) struct UnknownCrateTypesSuggestion {
|
||||
pub snippet: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("unreachable configuration predicate")]
|
||||
pub(crate) struct UnreachableCfgSelectPredicate {
|
||||
#[label("this configuration predicate is never reached")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("unreachable configuration predicate")]
|
||||
pub(crate) struct UnreachableCfgSelectPredicateWildcard {
|
||||
#[label("this configuration predicate is never reached")]
|
||||
pub span: Span,
|
||||
|
||||
#[label("always matches")]
|
||||
pub wildcard_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("positional format arguments are not allowed here")]
|
||||
#[help(
|
||||
|
||||
@@ -732,10 +732,6 @@ pub enum BuiltinLintDiag {
|
||||
local_crate: Symbol,
|
||||
},
|
||||
AttributeLint(AttributeLintKind),
|
||||
UnreachableCfg {
|
||||
span: Span,
|
||||
wildcard_span: Option<Span>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
|
||||
Reference in New Issue
Block a user