Add a lint for duplicate feature attributes

This commit is contained in:
varkor 2018-07-23 01:22:01 +01:00
parent 3584601715
commit fc99ea7ffa
3 changed files with 15 additions and 0 deletions

View file

@ -111,6 +111,12 @@ declare_lint! {
"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 @@ impl LintPass for HardwiredLints {
WARNINGS,
UNUSED_FEATURES,
UNKNOWN_FEATURES,
DUPLICATE_FEATURES,
STABLE_FEATURES,
UNKNOWN_CRATE_TYPES,
TRIVIAL_CASTS,

View file

@ -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,

View file

@ -189,6 +189,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_EXTERN_CRATES,
UNUSED_FEATURES,
UNKNOWN_FEATURES,
DUPLICATE_FEATURES,
UNUSED_LABELS,
UNUSED_PARENS);