mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
Add a lint for duplicate feature attributes
This commit is contained in:
@@ -111,6 +111,12 @@
|
||||
"unknown features found in crate-level #[feature] directives"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub DUPLICATE_FEATURES,
|
||||
Deny,
|
||||
"duplicate features found in crate-level #[feature] directives"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub STABLE_FEATURES,
|
||||
Warn,
|
||||
@@ -369,6 +375,7 @@ fn get_lints(&self) -> LintArray {
|
||||
WARNINGS,
|
||||
UNUSED_FEATURES,
|
||||
UNKNOWN_FEATURES,
|
||||
DUPLICATE_FEATURES,
|
||||
STABLE_FEATURES,
|
||||
UNKNOWN_CRATE_TYPES,
|
||||
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();
|
||||
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);
|
||||
}
|
||||
// FIXME(varkor): we don't properly handle lib features behind `cfg` attributes yet,
|
||||
|
||||
@@ -189,6 +189,7 @@ macro_rules! add_lint_group {
|
||||
UNUSED_EXTERN_CRATES,
|
||||
UNUSED_FEATURES,
|
||||
UNKNOWN_FEATURES,
|
||||
DUPLICATE_FEATURES,
|
||||
UNUSED_LABELS,
|
||||
UNUSED_PARENS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user