Add a lint for duplicate feature attributes
This commit is contained in:
parent
3584601715
commit
fc99ea7ffa
3 changed files with 15 additions and 0 deletions
|
@ -111,6 +111,12 @@ declare_lint! {
|
||||||
"unknown features found in crate-level #[feature] directives"
|
"unknown features found in crate-level #[feature] directives"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_lint! {
|
||||||
|
pub DUPLICATE_FEATURES,
|
||||||
|
Deny,
|
||||||
|
"duplicate features found in crate-level #[feature] directives"
|
||||||
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
pub STABLE_FEATURES,
|
pub STABLE_FEATURES,
|
||||||
Warn,
|
Warn,
|
||||||
|
@ -369,6 +375,7 @@ impl LintPass for HardwiredLints {
|
||||||
WARNINGS,
|
WARNINGS,
|
||||||
UNUSED_FEATURES,
|
UNUSED_FEATURES,
|
||||||
UNKNOWN_FEATURES,
|
UNKNOWN_FEATURES,
|
||||||
|
DUPLICATE_FEATURES,
|
||||||
STABLE_FEATURES,
|
STABLE_FEATURES,
|
||||||
UNKNOWN_CRATE_TYPES,
|
UNKNOWN_CRATE_TYPES,
|
||||||
TRIVIAL_CASTS,
|
TRIVIAL_CASTS,
|
||||||
|
|
|
@ -826,6 +826,13 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
|
|
||||||
let mut remaining_lib_features = FxHashMap();
|
let mut remaining_lib_features = FxHashMap();
|
||||||
for (feature, span) in declared_lib_features.clone().into_iter() {
|
for (feature, span) in declared_lib_features.clone().into_iter() {
|
||||||
|
// Warn if the user enables a feature multiple times.
|
||||||
|
if remaining_lib_features.contains_key(&feature) {
|
||||||
|
tcx.lint_node(lint::builtin::DUPLICATE_FEATURES,
|
||||||
|
ast::CRATE_NODE_ID,
|
||||||
|
span,
|
||||||
|
&format!("duplicate `{}` feature attribute", feature));
|
||||||
|
}
|
||||||
remaining_lib_features.insert(feature, span);
|
remaining_lib_features.insert(feature, span);
|
||||||
}
|
}
|
||||||
// FIXME(varkor): we don't properly handle lib features behind `cfg` attributes yet,
|
// FIXME(varkor): we don't properly handle lib features behind `cfg` attributes yet,
|
||||||
|
|
|
@ -189,6 +189,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||||
UNUSED_EXTERN_CRATES,
|
UNUSED_EXTERN_CRATES,
|
||||||
UNUSED_FEATURES,
|
UNUSED_FEATURES,
|
||||||
UNKNOWN_FEATURES,
|
UNKNOWN_FEATURES,
|
||||||
|
DUPLICATE_FEATURES,
|
||||||
UNUSED_LABELS,
|
UNUSED_LABELS,
|
||||||
UNUSED_PARENS);
|
UNUSED_PARENS);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue