diff options
| author | Brian Anderson <banderson@mozilla.com> | 2015-02-02 20:25:42 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-02-04 23:18:24 -0800 |
| commit | 456d23e73ee5d8c22b67336061ed7b457742d7ff (patch) | |
| tree | f7dae7a2172d56835c9df818c6b50c52985a5217 /src/libsyntax | |
| parent | ba2f13ef0667ce90f55ab0f1506bf5ee7b852d96 (diff) | |
| download | rust-456d23e73ee5d8c22b67336061ed7b457742d7ff.tar.gz rust-456d23e73ee5d8c22b67336061ed7b457742d7ff.zip | |
Add a lint for writing `#[feature]` for stable features, warn by default.
The 'stable_features' lint helps people progress from unstable to stable Rust by telling them when they no longer need a `feature` attribute because upstream Rust has declared it stable. This compares to the existing 'unstable_features', which is used to implement feature staging, and triggers on *any* use of `#[feature]`.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index d7a51e1149f..59cdb15296a 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -149,7 +149,10 @@ pub struct Features { pub old_orphan_check: bool, pub simd_ffi: bool, pub unmarked_api: bool, - pub lib_features: Vec<(InternedString, Span)> + /// spans of #![feature] attrs for stable language features. for error reporting + pub declared_stable_lang_features: Vec<Span>, + /// #![feature] attrs for non-language (library) features + pub declared_lib_features: Vec<(InternedString, Span)> } impl Features { @@ -162,7 +165,8 @@ impl Features { old_orphan_check: false, simd_ffi: false, unmarked_api: false, - lib_features: Vec::new() + declared_stable_lang_features: Vec::new(), + declared_lib_features: Vec::new() } } } @@ -511,6 +515,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C cm: cm, }; + let mut accepted_features = Vec::new(); let mut unknown_features = Vec::new(); for attr in &krate.attrs { @@ -550,8 +555,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C span_handler.span_err(mi.span, "feature has been removed"); } Some(&(_, _, Accepted)) => { - span_handler.span_warn(mi.span, "feature has been added to Rust, \ - directive not necessary"); + accepted_features.push(mi.span); } None => { unknown_features.push((name, mi.span)); @@ -572,7 +576,8 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C old_orphan_check: cx.has_feature("old_orphan_check"), simd_ffi: cx.has_feature("simd_ffi"), unmarked_api: cx.has_feature("unmarked_api"), - lib_features: unknown_features + declared_stable_lang_features: accepted_features, + declared_lib_features: unknown_features } } |
