]> git.lizzy.rs Git - rust.git/commitdiff
Get "make check" to work with unused-attribute
authorSteven Fackler <sfackler@gmail.com>
Fri, 23 May 2014 05:29:13 +0000 (22:29 -0700)
committerSteven Fackler <sfackler@gmail.com>
Sat, 24 May 2014 23:49:46 +0000 (16:49 -0700)
There's a fair number of attributes that have to be whitelisted since
they're either looked for by rustdoc, in trans, or as needed. These can
be cleaned up in the future.

19 files changed:
src/doc/rust.md
src/doc/rustdoc.md
src/doc/tutorial.md
src/librustc/driver/driver.rs
src/librustc/front/test.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/lint.rs
src/librustdoc/clean.rs
src/libsyntax/attr.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/run-pass/attr-mix-new.rs
src/test/run-pass/backtrace.rs
src/test/run-pass/class-attributes-1.rs
src/test/run-pass/class-attributes-2.rs
src/test/run-pass/issue-3250.rs [deleted file]
src/test/run-pass/item-attributes.rs
src/test/run-pass/method-attributes.rs

index d686a02b2fe64c533a5283794c60221e0e97af1b..b8fa4075e7a758656e6e1b5c3fd609c714193bb6 100644 (file)
@@ -661,6 +661,7 @@ Attributes on the anonymous crate module define important metadata that influenc
 the behavior of the compiler.
 
 ~~~~ {.rust}
+# #![allow(unused_attribute)]
 // Crate ID
 #![crate_id = "projx#2.5"]
 
index d6cb782bd83bb8235148ba2dbfd1453f5e84880e..af9cff7be67b0b432f39bd891c177f6473433e82 100644 (file)
@@ -11,6 +11,7 @@ Documenting Rust APIs is quite simple. To document a given item, we have "doc
 comments":
 
 ~~~
+# #![allow(unused_attribute)]
 // the "link" crate attribute is currently required for rustdoc, but normally
 // isn't needed.
 #![crate_id = "universe"]
index da78869d9fa84a69856a8272d151865537a861a7..d85734508bc137f87d5c2aa1d4fc083aa881fb80 100644 (file)
@@ -3166,6 +3166,7 @@ without conflict.
 Therefore, if you plan to compile your crate as a library, you should annotate it with that information:
 
 ~~~~
+# #![allow(unused_attribute)]
 // `lib.rs`
 
 # #![crate_type = "lib"]
@@ -3189,6 +3190,7 @@ Other crate settings and metadata include things like enabling/disabling certain
 or setting the crate type (library or executable) explicitly:
 
 ~~~~
+# #![allow(unused_attribute)]
 // `lib.rs`
 // ...
 
@@ -3208,6 +3210,7 @@ Now for something that you can actually compile yourself.
 We define two crates, and use one of them as a library in the other.
 
 ~~~~
+# #![allow(unused_attribute)]
 // `world.rs`
 #![crate_id = "world#0.42"]
 
@@ -3282,11 +3285,13 @@ fn main() {
 Both auto-insertions can be disabled with an attribute if necessary:
 
 ~~~
+# #![allow(unused_attribute)]
 // In the crate root:
 #![no_std]
 ~~~
 
 ~~~
+# #![allow(unused_attribute)]
 // In any module:
 #![no_implicit_prelude]
 ~~~
index 4e682e8e34bb2d2848e27244741c5ce46dfa8c38..ee9b10a805901d2eddd0707aa99cd7236e3111b5 100644 (file)
@@ -716,6 +716,45 @@ fn expand_err_details(r: io::IoResult<()>) -> io::IoResult<()> {
 
 pub fn collect_crate_types(session: &Session,
                            attrs: &[ast::Attribute]) -> Vec<config::CrateType> {
+    // Unconditionally collect crate types from attributes to make them used
+    let attr_types: Vec<config::CrateType> = attrs.iter().filter_map(|a| {
+        if a.check_name("crate_type") {
+            match a.value_str() {
+                Some(ref n) if n.equiv(&("rlib")) => {
+                    Some(config::CrateTypeRlib)
+                }
+                Some(ref n) if n.equiv(&("dylib")) => {
+                    Some(config::CrateTypeDylib)
+                }
+                Some(ref n) if n.equiv(&("lib")) => {
+                    Some(config::default_lib_output())
+                }
+                Some(ref n) if n.equiv(&("staticlib")) => {
+                    Some(config::CrateTypeStaticlib)
+                }
+                Some(ref n) if n.equiv(&("bin")) => Some(config::CrateTypeExecutable),
+                Some(_) => {
+                    session.add_lint(lint::UnknownCrateType,
+                                     ast::CRATE_NODE_ID,
+                                     a.span,
+                                     "invalid `crate_type` \
+                                      value".to_strbuf());
+                    None
+                }
+                _ => {
+                    session.add_lint(lint::UnknownCrateType,
+                                     ast::CRATE_NODE_ID,
+                                     a.span,
+                                     "`crate_type` requires a \
+                                      value".to_strbuf());
+                    None
+                }
+            }
+        } else {
+            None
+        }
+    }).collect();
+
     // If we're generating a test executable, then ignore all other output
     // styles at all other locations
     if session.opts.test {
@@ -729,44 +768,7 @@ pub fn collect_crate_types(session: &Session,
     if base.len() > 0 {
         return base
     } else {
-        let iter = attrs.iter().filter_map(|a| {
-            if a.name().equiv(&("crate_type")) {
-                match a.value_str() {
-                    Some(ref n) if n.equiv(&("rlib")) => {
-                        Some(config::CrateTypeRlib)
-                    }
-                    Some(ref n) if n.equiv(&("dylib")) => {
-                        Some(config::CrateTypeDylib)
-                    }
-                    Some(ref n) if n.equiv(&("lib")) => {
-                        Some(config::default_lib_output())
-                    }
-                    Some(ref n) if n.equiv(&("staticlib")) => {
-                        Some(config::CrateTypeStaticlib)
-                    }
-                    Some(ref n) if n.equiv(&("bin")) => Some(config::CrateTypeExecutable),
-                    Some(_) => {
-                        session.add_lint(lint::UnknownCrateType,
-                                         ast::CRATE_NODE_ID,
-                                         a.span,
-                                         "invalid `crate_type` \
-                                          value".to_strbuf());
-                        None
-                    }
-                    _ => {
-                        session.add_lint(lint::UnknownCrateType,
-                                         ast::CRATE_NODE_ID,
-                                         a.span,
-                                         "`crate_type` requires a \
-                                          value".to_strbuf());
-                        None
-                    }
-                }
-            } else {
-                None
-            }
-        });
-        base.extend(iter);
+        base.extend(attr_types.move_iter());
         if base.len() == 0 {
             base.push(config::CrateTypeExecutable);
         }
index d5e9192cd7496b73e6251a50890b0f941e835434..679444238085542c49e2e450da2120bb938d6cc9 100644 (file)
@@ -253,7 +253,7 @@ fn has_test_signature(i: @ast::Item) -> bool {
 fn is_ignored(cx: &TestCtxt, i: @ast::Item) -> bool {
     i.attrs.iter().any(|attr| {
         // check ignore(cfg(foo, bar))
-        attr.name().equiv(&("ignore")) && match attr.meta_item_list() {
+        attr.check_name("ignore") && match attr.meta_item_list() {
             Some(ref cfgs) => {
                 attr::test_cfg(cx.config.as_slice(), cfgs.iter().map(|x| *x))
             }
index a06c6e59ea1dea5645e0d2a8bc2f85364db8d4d8..2e3dc360ac29185b142cd07a817cf8c247531a0f 100644 (file)
@@ -1447,7 +1447,7 @@ fn synthesize_crateid_attr(ecx: &EncodeContext) -> Attribute {
 
     let mut attrs = Vec::new();
     for attr in krate.attrs.iter() {
-        if !attr.name().equiv(&("crate_id")) {
+        if !attr.check_name("crate_id") {
             attrs.push(*attr);
         }
     }
index 5315b223344c24c65b3db317c99005fcf025d8ce..25a0f1510904d811a40bbe16cb455bab18cfbed1 100644 (file)
@@ -293,7 +293,7 @@ enum LintSource {
      LintSpec {
          lint: UnusedAttribute,
          desc: "detects attributes that were not used by the compiler",
-         default: Allow
+         default: Warn
     }),
 
     ("unused_variable",
@@ -1148,8 +1148,38 @@ fn check_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
 fn check_unused_attribute(cx: &Context, attrs: &[ast::Attribute]) {
     for attr in attrs.iter() {
         // whitelist docs since rustdoc looks at them
+        attr.check_name("automatically_derived");
         attr.check_name("doc");
 
+        // these are processed in trans, which happens after the lint pass
+        attr.check_name("address_insignificant");
+        attr.check_name("cold");
+        attr.check_name("inline");
+        attr.check_name("link");
+        attr.check_name("link_name");
+        attr.check_name("link_section");
+        attr.check_name("no_builtins");
+        attr.check_name("no_mangle");
+        attr.check_name("no_split_stack");
+        attr.check_name("packed");
+        attr.check_name("static_assert");
+        attr.check_name("thread_local");
+
+        // not used anywhere (!?) but apparently we want to keep them around
+        attr.check_name("comment");
+        attr.check_name("desc");
+        attr.check_name("license");
+
+        // these are only looked at on-demand so we can't guarantee they'll have
+        // already been checked
+        attr.check_name("deprecated");
+        attr.check_name("experimental");
+        attr.check_name("frozen");
+        attr.check_name("locked");
+        attr.check_name("must_use");
+        attr.check_name("stable");
+        attr.check_name("unstable");
+
         if !attr::is_used(attr) {
             cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
         }
index fb2a80333e82d0e6377c70458135cbb240b3fe19..6f3c6e4cd6f397cec5d6723f93cf004fcff8a92c 100644 (file)
@@ -314,9 +314,9 @@ fn clean(&self) -> Attribute {
 }
 
 // This is a rough approximation that gets us what we want.
-impl<'a> attr::AttrMetaMethods for &'a Attribute {
+impl attr::AttrMetaMethods for Attribute {
     fn name(&self) -> InternedString {
-        match **self {
+        match *self {
             Word(ref n) | List(ref n, _) | NameValue(ref n, _) => {
                 token::intern_and_get_ident(n.as_slice())
             }
@@ -324,7 +324,7 @@ fn name(&self) -> InternedString {
     }
 
     fn value_str(&self) -> Option<InternedString> {
-        match **self {
+        match *self {
             NameValue(_, ref v) => {
                 Some(token::intern_and_get_ident(v.as_slice()))
             }
index bbd333163b593edfcd48948d25b380e188f3f227..1d43ac898f1fa63041edadbbec2f7955e4c23487 100644 (file)
@@ -350,9 +350,9 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
 
     // this would be much nicer as a chain of iterator adaptors, but
     // this doesn't work.
-    let some_cfg_matches = metas.any(|mi| {
+    let some_cfg_matches = metas.fold(false, |matches, mi| {
         debug!("testing name: {}", mi.name());
-        if mi.check_name("cfg") { // it is a #[cfg()] attribute
+        let this_matches = if mi.check_name("cfg") { // it is a #[cfg()] attribute
             debug!("is cfg");
             no_cfgs = false;
              // only #[cfg(...)] ones are understood.
@@ -380,7 +380,8 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
             }
         } else {
             false
-        }
+        };
+        matches || this_matches
     });
     debug!("test_cfg (no_cfgs={}, some_cfg_matches={})", no_cfgs, some_cfg_matches);
     no_cfgs || some_cfg_matches
index d422dfc513d26424b420d0d2920b35e10a0609d9..f7db5c97aab111fec139dbabff50502ad6eeb653 100644 (file)
 // 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"] fn main() {} //~ ERROR: crate-level attribute
+                                   //~^ ERROR: unused attribute
index 8b70953146da783ddc8ec4bfb40f7d2723e7f461..32058737ed3023e755d9128a759197474420fb1e 100644 (file)
 // injected intrinsics by the compiler.
 
 #![deny(attribute_usage)]
+#![deny(unused_attribute)]
 #![allow(dead_code)]
 
 #[abi="stdcall"] extern {} //~ ERROR: obsolete attribute
+                           //~^ ERROR: unused attribute
 
 #[fixed_stack_segment] fn f() {} //~ ERROR: obsolete attribute
+                                 //~^ ERROR: unused attribute
 
 fn main() {}
index dbbf91f725dc0f97b1600ecf2cba3470be625383..32c0722d1ac2609df16a4859f7c349f66c46d1a4 100644 (file)
 // injected intrinsics by the compiler.
 
 #![deny(attribute_usage)]
+#![deny(unused_attribute)]
 
 #![mutable_doc] //~ ERROR: unknown crate attribute
+                //~^ ERROR: unused attribute
 
 #[dance] mod a {} //~ ERROR: unknown attribute
+                //~^ ERROR: unused attribute
 
 #[dance] fn main() {} //~ ERROR: unknown attribute
+                //~^ ERROR: unused attribute
index af615912f2823e79d56b50ea826d1a4298107753..55ca75b4b7131256a7252a5d57b805a014d1dafa 100644 (file)
@@ -7,6 +7,7 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
+#![allow(unused_attribute)]
 
 #[foo(bar)]
 mod foo {
index 7f2c9e14af10d747728660012a1b616c79548566..cf6126a37fa851a188c4cdf41e5302b626fa98c1 100644 (file)
@@ -9,8 +9,6 @@
 // except according to those terms.
 
 // ignore-win32 FIXME #13259
-#![no_uv]
-
 extern crate native;
 
 use std::os;
index 55cf41d73d5915b5f5c62d1177953374f9e3c8ad..186fec45c4bb3ab969dee4957a196337454e9ffd 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 // pp-exact - Make sure we actually print the attributes
+#![allow(unused_attribute)]
 
 struct cat {
     name: StrBuf,
index b1ed70278ef32702f10c61de291edea44f738a54..6da8123c8c49cc7b58f97adb87be2c0bb629cab9 100644 (file)
@@ -7,6 +7,7 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
+#![allow(unused_attribute)]
 
 struct cat {
   name: StrBuf,
diff --git a/src/test/run-pass/issue-3250.rs b/src/test/run-pass/issue-3250.rs
deleted file mode 100644 (file)
index 255f6b1..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#[auto_serialize]
-
-type t = (uint, uint);
-
-pub fn main() { }
index ef825826ea4956b01dbb901579c8a2c4cc254d7c..bf94af601fea0624c7738d1429f546c2ac729df2 100644 (file)
@@ -11,6 +11,7 @@
 // These are attributes of the implicit crate. Really this just needs to parse
 // for completeness since .rs files linked from .rc files support this
 // notation to specify their module's attributes
+#![allow(unused_attribute)]
 #![attr1 = "val"]
 #![attr2 = "val"]
 #![attr3]
index 87c43da9ebcf4d8e373f268ff63b9359e1990454..c015244d520cee80fc484c3ffc7c75825a028d3c 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 // pp-exact - Make sure we print all the attributes
+#![allow(unused_attribute)]
 
 #[frobable]
 trait frobable {