diff options
| author | varkor <github@varkor.com> | 2018-07-23 01:22:01 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-08-05 15:54:49 +0100 |
| commit | fc99ea7ffa1f2dc3407e4f2b7eb64e36532cb5f9 (patch) | |
| tree | acea196cf385721de55d6638586bc61a630a4384 /src | |
| parent | 358460171580272faf1f68dfc06d58c08bb5fcb1 (diff) | |
| download | rust-fc99ea7ffa1f2dc3407e4f2b7eb64e36532cb5f9.tar.gz rust-fc99ea7ffa1f2dc3407e4f2b7eb64e36532cb5f9.zip | |
Add a lint for duplicate feature attributes
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lint/builtin.rs | 7 | ||||
| -rw-r--r-- | src/librustc/middle/stability.rs | 7 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 6536ab6ea73..2301055e5ce 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -112,6 +112,12 @@ declare_lint! { } declare_lint! { + pub DUPLICATE_FEATURES, + Deny, + "duplicate features found in crate-level #[feature] directives" +} + +declare_lint! { pub STABLE_FEATURES, Warn, "stable features found in #[feature] directive" @@ -369,6 +375,7 @@ impl LintPass for HardwiredLints { WARNINGS, UNUSED_FEATURES, UNKNOWN_FEATURES, + DUPLICATE_FEATURES, STABLE_FEATURES, UNKNOWN_CRATE_TYPES, TRIVIAL_CASTS, diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 50f94985487..9b5a9dfd5b3 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -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, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 396e5e869f3..4d8cee294e3 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -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); |
