]> git.lizzy.rs Git - rust.git/commitdiff
Remove the attribute_usage lint
authorSteven Fackler <sfackler@gmail.com>
Sun, 8 Jun 2014 06:46:32 +0000 (23:46 -0700)
committerSteven Fackler <sfackler@gmail.com>
Sun, 8 Jun 2014 06:46:32 +0000 (23:46 -0700)
It has been superseded by the unused_attribute lint.

[breaking change]

src/librustc/middle/lint.rs
src/librustdoc/test.rs
src/test/compile-fail/lint-misplaced-attr.rs
src/test/compile-fail/lint-obsolete-attr.rs
src/test/compile-fail/lint-unknown-attr.rs
src/test/compile-fail/unused-attr.rs

index f9ee65a2c499abf6c52fb40e1ecdbdb0af476f65..8d76535af7f99dfdcbd6c9ad4fa8b9465e5c20b6 100644 (file)
@@ -92,7 +92,6 @@ pub enum Lint {
     TypeOverflow,
     UnusedUnsafe,
     UnsafeBlock,
-    AttributeUsage,
     UnusedAttribute,
     UnknownFeatures,
     UnknownCrateType,
@@ -294,13 +293,6 @@ pub enum LintSource {
         default: Allow
     }),
 
-    ("attribute_usage",
-     LintSpec {
-        lint: AttributeUsage,
-        desc: "detects bad use of attributes",
-        default: Warn
-    }),
-
     ("unused_attribute",
      LintSpec {
          lint: UnusedAttribute,
@@ -1096,93 +1088,6 @@ fn check_raw_ptr_deriving(cx: &mut Context, item: &ast::Item) {
     }
 }
 
-static crate_attrs: &'static [&'static str] = &[
-    "crate_type", "feature", "no_start", "no_main", "no_std", "crate_id",
-    "desc", "comment", "license", "copyright", // not used in rustc now
-    "no_builtins",
-];
-
-
-static obsolete_attrs: &'static [(&'static str, &'static str)] = &[
-    ("abi", "Use `extern \"abi\" fn` instead"),
-    ("auto_encode", "Use `#[deriving(Encodable)]` instead"),
-    ("auto_decode", "Use `#[deriving(Decodable)]` instead"),
-    ("fast_ffi", "Remove it"),
-    ("fixed_stack_segment", "Remove it"),
-    ("rust_stack", "Remove it"),
-];
-
-static other_attrs: &'static [&'static str] = &[
-    // item-level
-    "address_insignificant", // can be crate-level too
-    "thread_local", // for statics
-    "allow", "deny", "forbid", "warn", // lint options
-    "deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
-    "cfg", "doc", "export_name", "link_section",
-    "no_mangle", "static_assert", "unsafe_no_drop_flag", "packed",
-    "simd", "repr", "deriving", "unsafe_destructor", "link", "phase",
-    "macro_export", "must_use", "automatically_derived",
-
-    //mod-level
-    "path", "link_name", "link_args", "macro_escape", "no_implicit_prelude",
-
-    // fn-level
-    "test", "bench", "should_fail", "ignore", "inline", "lang", "main", "start",
-    "no_split_stack", "cold", "macro_registrar", "linkage",
-
-    // internal attribute: bypass privacy inside items
-    "!resolve_unexported",
-];
-
-fn check_crate_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
-
-    for attr in attrs.iter() {
-        let name = attr.node.value.name();
-        let mut iter = crate_attrs.iter().chain(other_attrs.iter());
-        if !iter.any(|other_attr| { name.equiv(other_attr) }) {
-            cx.span_lint(AttributeUsage, attr.span, "unknown crate attribute");
-        }
-        if name.equiv(&("link")) {
-            cx.tcx.sess.span_err(attr.span,
-                                 "obsolete crate `link` attribute");
-            cx.tcx.sess.note("the link attribute has been superceded by the crate_id \
-                             attribute, which has the format `#[crate_id = \"name#version\"]`");
-        }
-    }
-}
-
-fn check_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
-    // check if element has crate-level, obsolete, or any unknown attributes.
-
-    for attr in attrs.iter() {
-        let name = attr.node.value.name();
-        for crate_attr in crate_attrs.iter() {
-            if name.equiv(crate_attr) {
-                let msg = match attr.node.style {
-                    ast::AttrOuter => "crate-level attribute should be an inner attribute: \
-                                       add an exclamation mark: #![foo]",
-                    ast::AttrInner => "crate-level attribute should be in the root module",
-                };
-                cx.span_lint(AttributeUsage, attr.span, msg);
-                return;
-            }
-        }
-
-        for &(obs_attr, obs_alter) in obsolete_attrs.iter() {
-            if name.equiv(&obs_attr) {
-                cx.span_lint(AttributeUsage, attr.span,
-                             format!("obsolete attribute: {:s}",
-                                     obs_alter).as_slice());
-                return;
-            }
-        }
-
-        if !other_attrs.iter().any(|other_attr| { name.equiv(other_attr) }) {
-            cx.span_lint(AttributeUsage, attr.span, "unknown attribute");
-        }
-    }
-}
-
 fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
     static ATTRIBUTE_WHITELIST: &'static [&'static str] = &'static [
         // FIXME: #14408 whitelist docs since rustdoc looks at them
@@ -1834,7 +1739,6 @@ fn visit_item(&mut self, it: &ast::Item, _: ()) {
             check_item_non_uppercase_statics(cx, it);
             check_heap_item(cx, it);
             check_missing_doc_item(cx, it);
-            check_attrs_usage(cx, it.attrs.as_slice());
             check_raw_ptr_deriving(cx, it);
 
             cx.visit_ids(|v| v.visit_item(it, ()));
@@ -1845,15 +1749,12 @@ fn visit_item(&mut self, it: &ast::Item, _: ()) {
 
     fn visit_foreign_item(&mut self, it: &ast::ForeignItem, _: ()) {
         self.with_lint_attrs(it.attrs.as_slice(), |cx| {
-            check_attrs_usage(cx, it.attrs.as_slice());
             visit::walk_foreign_item(cx, it, ());
         })
     }
 
     fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
         self.with_lint_attrs(i.attrs.as_slice(), |cx| {
-            check_attrs_usage(cx, i.attrs.as_slice());
-
             cx.visit_ids(|v| v.visit_view_item(i, ()));
 
             visit::walk_view_item(cx, i, ());
@@ -1935,7 +1836,6 @@ fn visit_fn(&mut self, fk: &visit::FnKind, decl: &ast::FnDecl,
             visit::FkMethod(ident, _, m) => {
                 self.with_lint_attrs(m.attrs.as_slice(), |cx| {
                     check_missing_doc_method(cx, m);
-                    check_attrs_usage(cx, m.attrs.as_slice());
 
                     match method_context(cx, m) {
                         PlainImpl => check_snake_case(cx, "method", ident, span),
@@ -1960,7 +1860,6 @@ fn visit_fn(&mut self, fk: &visit::FnKind, decl: &ast::FnDecl,
     fn visit_ty_method(&mut self, t: &ast::TypeMethod, _: ()) {
         self.with_lint_attrs(t.attrs.as_slice(), |cx| {
             check_missing_doc_ty_method(cx, t);
-            check_attrs_usage(cx, t.attrs.as_slice());
             check_snake_case(cx, "trait method", t.ident, t.span);
 
             visit::walk_ty_method(cx, t, ());
@@ -1984,7 +1883,6 @@ fn visit_struct_def(&mut self,
     fn visit_struct_field(&mut self, s: &ast::StructField, _: ()) {
         self.with_lint_attrs(s.node.attrs.as_slice(), |cx| {
             check_missing_doc_struct_field(cx, s);
-            check_attrs_usage(cx, s.node.attrs.as_slice());
 
             visit::walk_struct_field(cx, s, ());
         })
@@ -1993,7 +1891,6 @@ fn visit_struct_field(&mut self, s: &ast::StructField, _: ()) {
     fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, _: ()) {
         self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
             check_missing_doc_variant(cx, v);
-            check_attrs_usage(cx, v.node.attrs.as_slice());
 
             visit::walk_variant(cx, v, g, ());
         })
@@ -2053,7 +1950,6 @@ pub fn check_crate(tcx: &ty::ctxt,
             visit::walk_crate(v, krate, ());
         });
 
-        check_crate_attrs_usage(cx, krate.attrs.as_slice());
         // since the root module isn't visited as an item (because it isn't an item), warn for it
         // here.
         check_missing_doc_attrs(cx,
index bc1da5b629e13030eac9690045178aa239f369d8..745e29508d218a3554996d5078513db04f45a51d 100644 (file)
@@ -205,7 +205,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, lints: bool) -> String {
     if lints {
         prog.push_str(r"
 #![deny(warnings)]
-#![allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)]
+#![allow(unused_variable, dead_assignment, unused_mut, unused_attribute, dead_code)]
 ");
     }
 
index f7db5c97aab111fec139dbabff50502ad6eeb653..9af48527435c576ff057c297883c9668ef23199c 100644 (file)
 // When denying at the crate level, be sure to not get random warnings from the
 // injected intrinsics by the compiler.
 
-#![deny(attribute_usage)]
 #![deny(unused_attribute)]
 
 mod a {
-    #![crate_type = "bin"] //~ ERROR: crate-level attribute
-                           //~^ ERROR: unused attribute
+    #![crate_type = "bin"] //~ ERROR unused attribute
 }
 
-#[crate_type = "bin"] fn main() {} //~ ERROR: crate-level attribute
-                                   //~^ ERROR: unused attribute
+#[crate_type = "bin"] fn main() {} //~ ERROR unused attribute
index 32058737ed3023e755d9128a759197474420fb1e..6b46a0c19bdddbddd766df080c5249156d9cc6d0 100644 (file)
 // When denying at the crate level, be sure to not get random warnings from the
 // injected intrinsics by the compiler.
 
-#![deny(attribute_usage)]
 #![deny(unused_attribute)]
 #![allow(dead_code)]
 
-#[abi="stdcall"] extern {} //~ ERROR: obsolete attribute
-                           //~^ ERROR: unused attribute
+#[abi="stdcall"] extern {} //~ ERROR unused attribute
 
-#[fixed_stack_segment] fn f() {} //~ ERROR: obsolete attribute
-                                 //~^ ERROR: unused attribute
+#[fixed_stack_segment] fn f() {} //~ ERROR unused attribute
 
 fn main() {}
index 32c0722d1ac2609df16a4859f7c349f66c46d1a4..020ed80c0fbbadc00274f9c9025abab650bbcdb2 100644 (file)
 // When denying at the crate level, be sure to not get random warnings from the
 // injected intrinsics by the compiler.
 
-#![deny(attribute_usage)]
 #![deny(unused_attribute)]
 
-#![mutable_doc] //~ ERROR: unknown crate attribute
-                //~^ ERROR: unused attribute
+#![mutable_doc] //~ ERROR unused attribute
 
-#[dance] mod a {} //~ ERROR: unknown attribute
-                //~^ ERROR: unused attribute
+#[dance] mod a {} //~ ERROR unused attribute
 
-#[dance] fn main() {} //~ ERROR: unknown attribute
-                //~^ ERROR: unused attribute
+#[dance] fn main() {} //~ ERROR unused attribute
index 750dcdf2c5f20de880abc6f15629e3366179f7de..3e1e08c7b58dd5c084e6f3facabca4f692d1bb76 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 #![deny(unused_attribute)]
-#![allow(attribute_usage, dead_code, unused_imports)]
+#![allow(dead_code, unused_imports)]
 
 #![foo] //~ ERROR unused attribute