]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14740 : P1start/rust/name-warnings, r=alexcrichton
authorbors <bors@rust-lang.org>
Mon, 9 Jun 2014 06:26:57 +0000 (23:26 -0700)
committerbors <bors@rust-lang.org>
Mon, 9 Jun 2014 06:26:57 +0000 (23:26 -0700)
This updates identifier warnings such as ``struct `foo_bar` should have a
camel case identifier`` to provide an example.

Closes #14738.

32 files changed:
src/etc/licenseck.py
src/libcollections/bitv.rs
src/libcollections/dlist.rs
src/libcollections/smallintmap.rs
src/libcollections/vec.rs
src/libcore/cmp.rs
src/libcore/simd.rs
src/libcore/str.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/lint.rs
src/librustc/middle/typeck/check/_match.rs
src/librustdoc/clean/mod.rs
src/librustdoc/test.rs
src/libserialize/json.rs
src/libstd/io/comm_adapters.rs
src/libstd/io/mod.rs
src/libstd/io/process.rs
src/libstd/io/stdio.rs
src/libstd/io/timer.rs
src/libstd/num/strconv.rs
src/libstd/os.rs
src/libstd/path/windows.rs
src/libstd/rt/thread.rs
src/libsyntax/attr.rs
src/libsyntax/visit.rs
src/test/bench/shootout-fannkuch-redux.rs
src/test/bench/shootout-regex-dna.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/match-range-fail.rs
src/test/compile-fail/unused-attr.rs [new file with mode: 0644]

index 1122fc96d249cc2cccbffb500e29e7481a6f890c..8b93f6e61bff1153edeef2604a498ad3cf17af2f 100644 (file)
@@ -42,7 +42,9 @@ exceptions = [
     "libstd/sync/spsc_queue.rs", # BSD
     "libstd/sync/mpmc_bounded_queue.rs", # BSD
     "libsync/mpsc_intrusive.rs", # BSD
+    "test/bench/shootout-fannkuch-redux.rs", # BSD
     "test/bench/shootout-meteor.rs", # BSD
+    "test/bench/shootout-regex-dna.rs", # BSD
 ]
 
 def check_license(name, contents):
index 58f081b25e3e541f820ce60fa46738c7850624cc..79e0c2ffea877772a93700e26780ee0a0adc2f39 100644 (file)
@@ -18,6 +18,7 @@
 use core::ops;
 use core::slice;
 use core::uint;
+use std::hash;
 
 use vec::Vec;
 
@@ -34,12 +35,12 @@ fn small_mask(nbits: uint) -> uint {
 }
 
 impl SmallBitv {
-    pub fn new(bits: uint) -> SmallBitv {
+    fn new(bits: uint) -> SmallBitv {
         SmallBitv {bits: bits}
     }
 
     #[inline]
-    pub fn bits_op(&mut self,
+    fn bits_op(&mut self,
                    right_bits: uint,
                    nbits: uint,
                    f: |uint, uint| -> uint)
@@ -52,32 +53,32 @@ pub fn bits_op(&mut self,
     }
 
     #[inline]
-    pub fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool {
+    fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool {
         self.bits_op(s.bits, nbits, |u1, u2| u1 | u2)
     }
 
     #[inline]
-    pub fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool {
+    fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool {
         self.bits_op(s.bits, nbits, |u1, u2| u1 & u2)
     }
 
     #[inline]
-    pub fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool {
+    fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool {
         self.bits_op(s.bits, nbits, |_u1, u2| u2)
     }
 
     #[inline]
-    pub fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool {
+    fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool {
         self.bits_op(s.bits, nbits, |u1, u2| u1 & !u2)
     }
 
     #[inline]
-    pub fn get(&self, i: uint) -> bool {
+    fn get(&self, i: uint) -> bool {
         (self.bits & (1 << i)) != 0
     }
 
     #[inline]
-    pub fn set(&mut self, i: uint, x: bool) {
+    fn set(&mut self, i: uint, x: bool) {
         if x {
             self.bits |= 1<<i;
         }
@@ -87,29 +88,29 @@ pub fn set(&mut self, i: uint, x: bool) {
     }
 
     #[inline]
-    pub fn equals(&self, b: &SmallBitv, nbits: uint) -> bool {
+    fn equals(&self, b: &SmallBitv, nbits: uint) -> bool {
         let mask = small_mask(nbits);
         mask & self.bits == mask & b.bits
     }
 
     #[inline]
-    pub fn clear(&mut self) { self.bits = 0; }
+    fn clear(&mut self) { self.bits = 0; }
 
     #[inline]
-    pub fn set_all(&mut self) { self.bits = !0; }
+    fn set_all(&mut self) { self.bits = !0; }
 
     #[inline]
-    pub fn all(&self, nbits: uint) -> bool {
+    fn all(&self, nbits: uint) -> bool {
         small_mask(nbits) & !self.bits == 0
     }
 
     #[inline]
-    pub fn none(&self, nbits: uint) -> bool {
+    fn none(&self, nbits: uint) -> bool {
         small_mask(nbits) & self.bits == 0
     }
 
     #[inline]
-    pub fn negate(&mut self) { self.bits = !self.bits; }
+    fn negate(&mut self) { self.bits = !self.bits; }
 }
 
 #[deriving(Clone)]
@@ -134,12 +135,12 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
 }
 
 impl BigBitv {
-    pub fn new(storage: Vec<uint>) -> BigBitv {
+    fn new(storage: Vec<uint>) -> BigBitv {
         BigBitv {storage: storage}
     }
 
     #[inline]
-    pub fn process(&mut self,
+    fn process(&mut self,
                    b: &BigBitv,
                    nbits: uint,
                    op: |uint, uint| -> uint)
@@ -163,37 +164,37 @@ pub fn process(&mut self,
     }
 
     #[inline]
-    pub fn each_storage(&mut self, op: |v: &mut uint| -> bool) -> bool {
+    fn each_storage(&mut self, op: |v: &mut uint| -> bool) -> bool {
         self.storage.mut_iter().advance(|elt| op(elt))
     }
 
     #[inline]
-    pub fn negate(&mut self) {
+    fn negate(&mut self) {
         self.each_storage(|w| { *w = !*w; true });
     }
 
     #[inline]
-    pub fn union(&mut self, b: &BigBitv, nbits: uint) -> bool {
+    fn union(&mut self, b: &BigBitv, nbits: uint) -> bool {
         self.process(b, nbits, |w1, w2| w1 | w2)
     }
 
     #[inline]
-    pub fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool {
+    fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool {
         self.process(b, nbits, |w1, w2| w1 & w2)
     }
 
     #[inline]
-    pub fn become(&mut self, b: &BigBitv, nbits: uint) -> bool {
+    fn become(&mut self, b: &BigBitv, nbits: uint) -> bool {
         self.process(b, nbits, |_, w| w)
     }
 
     #[inline]
-    pub fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool {
+    fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool {
         self.process(b, nbits, |w1, w2| w1 & !w2)
     }
 
     #[inline]
-    pub fn get(&self, i: uint) -> bool {
+    fn get(&self, i: uint) -> bool {
         let w = i / uint::BITS;
         let b = i % uint::BITS;
         let x = 1 & self.storage.get(w) >> b;
@@ -201,7 +202,7 @@ pub fn get(&self, i: uint) -> bool {
     }
 
     #[inline]
-    pub fn set(&mut self, i: uint, x: bool) {
+    fn set(&mut self, i: uint, x: bool) {
         let w = i / uint::BITS;
         let b = i % uint::BITS;
         let flag = 1 << b;
@@ -210,7 +211,7 @@ pub fn set(&mut self, i: uint, x: bool) {
     }
 
     #[inline]
-    pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
+    fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
         for (i, elt) in b.storage.iter().enumerate() {
             let mask = big_mask(nbits, i);
             if mask & *self.storage.get(i) != mask & *elt {
@@ -596,6 +597,20 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+impl<S: hash::Writer> hash::Hash<S> for Bitv {
+    fn hash(&self, state: &mut S) {
+        self.nbits.hash(state);
+        match self.rep {
+            Small(ref s) => (s.bits & small_mask(self.nbits)).hash(state),
+            Big(ref b) => {
+                for (i, ele) in b.storage.iter().enumerate() {
+                    (ele & big_mask(self.nbits, i)).hash(state);
+                }
+            }
+        }
+    }
+}
+
 #[inline]
 fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
     if bits == 0 {
@@ -834,6 +849,14 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+impl<S: hash::Writer> hash::Hash<S> for BitvSet {
+    fn hash(&self, state: &mut S) {
+        for pos in self.iter() {
+            pos.hash(state);
+        }
+    }
+}
+
 impl Container for BitvSet {
     #[inline]
     fn len(&self) -> uint { self.size }
index 94c617b58e8d2683ae20224cfabb349b8883663f..9d0e8e83698d8bac04832f23bcb5a63a7580d447 100644 (file)
@@ -24,6 +24,7 @@
 use core::prelude::*;
 
 use alloc::owned::Box;
+use core::fmt;
 use core::iter;
 use core::mem;
 use core::ptr;
@@ -608,6 +609,19 @@ fn clone(&self) -> DList<A> {
     }
 }
 
+impl<A: fmt::Show> fmt::Show for DList<A> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "["));
+
+        for (i, e) in self.iter().enumerate() {
+            if i != 0 { try!(write!(f, ", ")); }
+            try!(write!(f, "{}", *e));
+        }
+
+        write!(f, "]")
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use std::prelude::*;
@@ -1027,6 +1041,17 @@ fn test_fuzz() {
         }
     }
 
+    #[test]
+    fn test_show() {
+        let list: DList<int> = range(0, 10).collect();
+        assert!(list.to_str().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
+
+        let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
+                                                                   .map(|&s| s)
+                                                                   .collect();
+        assert!(list.to_str().as_slice() == "[just, one, test, more]");
+    }
+
     #[cfg(test)]
     fn fuzz_test(sz: int) {
         let mut m: DList<int> = DList::new();
index f3118181bdcdd148f682b96e3b9d73360e8f28e3..45584dd4b28ba4eccda480616bd855e23cbc1bcb 100644 (file)
@@ -17,6 +17,7 @@
 
 use core::prelude::*;
 
+use core::fmt;
 use core::iter::{Enumerate, FilterMap};
 use core::mem::replace;
 
@@ -176,6 +177,18 @@ pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool {
     }
 }
 
+impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, r"\{"));
+
+        for (i, (k, v)) in self.iter().enumerate() {
+            if i != 0 { try!(write!(f, ", ")); }
+            try!(write!(f, "{}: {}", k, *v));
+        }
+
+        write!(f, r"\}")
+    }
+}
 
 macro_rules! iterator {
     (impl $name:ident -> $elem:ty, $getter:ident) => {
@@ -461,6 +474,20 @@ fn test_move_iter() {
         assert!(called);
         m.insert(2, box 1);
     }
+
+    #[test]
+    fn test_show() {
+        let mut map = SmallIntMap::new();
+        let empty = SmallIntMap::<int>::new();
+
+        map.insert(1, 2);
+        map.insert(3, 4);
+
+        let map_str = map.to_str();
+        let map_str = map_str.as_slice();
+        assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
+        assert_eq!(format!("{}", empty), "{}".to_string());
+    }
 }
 
 #[cfg(test)]
index 6ca21262f51cc8754bdcc6fb7120577377edf9fc..37546f64d5f7b9690033cba19054f146bd18b322 100644 (file)
@@ -1532,7 +1532,7 @@ fn from_vec(mut v: Vec<T>) -> ~[T] {
 
         // In a post-DST world, we can attempt to reuse the Vec allocation by calling
         // shrink_to_fit() on it. That may involve a reallocation+memcpy, but that's no
-        // diffrent than what we're doing manually here.
+        // different than what we're doing manually here.
 
         let vp = v.as_mut_ptr();
 
index ef00643177bef822c882103e10e887d6fd7dd844..b25f69bca40b8f361e080b7b65221033d9a979c4 100644 (file)
 
 /// Trait for values that can be compared for equality and inequality.
 ///
-/// This trait allows partial equality, where types can be unordered instead of
-/// strictly equal or unequal. For example, with the built-in floating-point
-/// types `a == b` and `a != b` will both evaluate to false if either `a` or
-/// `b` is NaN (cf. IEEE 754-2008 section 5.11).
+/// This trait allows for partial equality, for types that do not have an
+/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
+/// so floating point types implement `PartialEq` but not `Eq`.
 ///
-/// PartialEq only requires the `eq` method to be implemented; `ne` is its negation by
-/// default.
+/// PartialEq only requires the `eq` method to be implemented; `ne` is defined
+/// in terms of it by default. Any manual implementation of `ne` *must* respect
+/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
+/// only if `a != b`.
 ///
 /// Eventually, this will be implemented by default for types that implement
 /// `Eq`.
@@ -147,9 +148,10 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
 /// PartialOrd only requires implementation of the `lt` method,
 /// with the others generated from default implementations.
 ///
-/// However it remains possible to implement the others separately,
-/// for compatibility with floating-point NaN semantics
-/// (cf. IEEE 754-2008 section 5.11).
+/// However it remains possible to implement the others separately for types
+/// which do not have a total order. For example, for floating point numbers,
+/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section
+/// 5.11).
 #[lang="ord"]
 pub trait PartialOrd: PartialEq {
     /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
index 99b802f9918f10e8c8528f9093e8cc9e64bbe65e..54e7d077bb141cb63fc1ef92cbdecee60fe209b6 100644 (file)
@@ -31,7 +31,7 @@
 //!
 //! ## Stability Note
 //!
-//! These are all experimental. The inferface may change entirely, without
+//! These are all experimental. The interface may change entirely, without
 //! warning.
 
 #![allow(non_camel_case_types)]
index 936b698d4b10a771f5f6ed22190025e4862d9d25..87177b4ac90dc50430b94cbc20d8d38897e3df1f 100644 (file)
@@ -478,7 +478,7 @@ fn maximal_suffix(arr: &[u8], reversed: bool) -> (uint, uint) {
 }
 
 /// The internal state of an iterator that searches for matches of a substring
-/// within a larger string using a dynamically chosed search algorithm
+/// within a larger string using a dynamically chosen search algorithm
 #[deriving(Clone)]
 enum Searcher {
     Naive(NaiveSearcher),
@@ -1120,7 +1120,7 @@ pub trait StrSlice<'a> {
     ///
     /// That is, each returned value `(start, end)` satisfies
     /// `self.slice(start, end) == sep`. For matches of `sep` within
-    /// `self` that overlap, only the indicies corresponding to the
+    /// `self` that overlap, only the indices corresponding to the
     /// first match are returned.
     ///
     /// # Example
index 2e00c4d12ffbf933b69938d645df7070ca4d5447..748c29cd92c42d56ffc1d2dfbcba3a1d9d46f040 100644 (file)
@@ -187,11 +187,11 @@ pub fn collect(&mut self, krate: &ast::Crate) {
 
 pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
     for attribute in attrs.iter() {
-        match attribute.name_str_pair() {
-            Some((ref key, ref value)) if key.equiv(&("lang")) => {
-                return Some((*value).clone());
+        match attribute.value_str() {
+            Some(ref value) if attribute.check_name("lang") => {
+                return Some(value.clone());
             }
-            Some(..) | None => {}
+            _ => {}
         }
     }
 
index c0d856c8d09d17b083c0e847a6c32c8626acb7f2..a3ee8003a455f12b5b4e123fedfec91456a63167 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,94 +1088,7 @@ 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, attrs: &[ast::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
         "doc",
@@ -1218,15 +1123,37 @@ fn check_unused_attribute(cx: &Context, attrs: &[ast::Attribute]) {
         "stable",
         "unstable",
     ];
-    for attr in attrs.iter() {
-        for &name in ATTRIBUTE_WHITELIST.iter() {
-            if attr.check_name(name) {
-                break;
-            }
+
+    static CRATE_ATTRS: &'static [&'static str] = &'static [
+        "crate_type",
+        "feature",
+        "no_start",
+        "no_main",
+        "no_std",
+        "crate_id",
+        "desc",
+        "comment",
+        "license",
+        "copyright",
+        "no_builtins",
+    ];
+
+    for &name in ATTRIBUTE_WHITELIST.iter() {
+        if attr.check_name(name) {
+            break;
         }
+    }
 
-        if !attr::is_used(attr) {
-            cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
+    if !attr::is_used(attr) {
+        cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
+        if CRATE_ATTRS.contains(&attr.name().get()) {
+            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(UnusedAttribute, attr.span, msg);
         }
     }
 }
@@ -1869,8 +1796,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_unused_attribute(cx, it.attrs.as_slice());
             check_raw_ptr_deriving(cx, it);
 
             cx.visit_ids(|v| v.visit_item(it, ()));
@@ -1881,15 +1806,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, ());
@@ -1971,7 +1893,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),
@@ -1996,7 +1917,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, ());
@@ -2020,7 +1940,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, ());
         })
@@ -2029,7 +1948,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, ());
         })
@@ -2037,6 +1955,10 @@ fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, _: ()) {
 
     // FIXME(#10894) should continue recursing
     fn visit_ty(&mut self, _t: &ast::Ty, _: ()) {}
+
+    fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
+        check_unused_attribute(self, attr);
+    }
 }
 
 impl<'a> IdVisitingOperation for Context<'a> {
@@ -2085,10 +2007,8 @@ 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_unused_attribute(cx, krate.attrs.as_slice());
         check_missing_doc_attrs(cx,
                                 None,
                                 krate.attrs.as_slice(),
index df774b215042b6cccd73a6740b4797873643ccf4..cb8de7502fdb2933095fc7a347e28a2cf8afe3ce 100644 (file)
@@ -460,7 +460,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
         {
             // no-op
         } else if !ty::type_is_numeric(b_ty) && !ty::type_is_char(b_ty) {
-            tcx.sess.span_err(pat.span, "non-numeric type used in range");
+            tcx.sess.span_err(pat.span,
+                "only char and numeric types are allowed in range");
         } else {
             match valid_range_bounds(fcx.ccx, begin, end) {
                 Some(false) => {
index 3cb5c663c4ea5a4d64db78b9c57b2b639baf7fb1..650cd749af69e1e8d949f0bc2139887f3d3036f1 100644 (file)
@@ -429,17 +429,11 @@ fn value_str(&self) -> Option<InternedString> {
         }
     }
     fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
-    fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
-        None
-    }
 }
 impl<'a> attr::AttrMetaMethods for &'a Attribute {
     fn name(&self) -> InternedString { (**self).name() }
     fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
     fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
-    fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
-        None
-    }
 }
 
 #[deriving(Clone, Encodable, Decodable)]
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 046d25f98e43a9f1a2003ddfc4308524ca5ef584..9907faae52bc4bd0c1b193e5211e4b639d3865b7 100644 (file)
@@ -992,7 +992,7 @@ enum ParserState {
     ParseObject(bool),
     // Parse ',' or ']' after an element in an object.
     ParseObjectComma,
-    // Initialial state.
+    // Initial state.
     ParseStart,
     // Expecting the stream to end.
     ParseBeforeFinish,
@@ -1152,7 +1152,7 @@ pub struct Parser<T> {
     // We maintain a stack representing where we are in the logical structure
     // of the JSON stream.
     stack: Stack,
-    // A state machine is kept to make it possible to interupt and resume parsing.
+    // A state machine is kept to make it possible to interrupt and resume parsing.
     state: ParserState,
 }
 
@@ -1449,7 +1449,7 @@ fn parse_str(&mut self) -> Result<String, ParserError> {
     // information to return a JsonEvent.
     // Manages an internal state so that parsing can be interrupted and resumed.
     // Also keeps track of the position in the logical structure of the json
-    // stream int the form of a stack that can be queried by the user usng the
+    // stream int the form of a stack that can be queried by the user using the
     // stack() method.
     fn parse(&mut self) -> JsonEvent {
         loop {
index 45f783698cd3b9b2f3812ced16d1927b5ba07ecc..84b7242970aade29221014c7b18c6f51a6b7f32a 100644 (file)
@@ -17,7 +17,8 @@
 use result::{Ok, Err};
 use super::{Reader, Writer, IoResult};
 use str::StrSlice;
-use slice::{bytes, CloneableVector, MutableVector, ImmutableVector};
+use slice::{bytes, MutableVector, ImmutableVector};
+use vec::Vec;
 
 /// Allows reading from a rx.
 ///
 /// # drop(tx);
 /// let mut reader = ChanReader::new(rx);
 ///
-/// let mut buf = ~[0u8, ..100];
+/// let mut buf = [0u8, ..100];
 /// match reader.read(buf) {
 ///     Ok(nread) => println!("Read {} bytes", nread),
 ///     Err(e) => println!("read error: {}", e),
 /// }
 /// ```
 pub struct ChanReader {
-    buf: Option<~[u8]>,  // A buffer of bytes received but not consumed.
-    pos: uint,           // How many of the buffered bytes have already be consumed.
-    rx: Receiver<~[u8]>,   // The rx to pull data from.
-    closed: bool,        // Whether the pipe this rx connects to has been closed.
+    buf: Option<Vec<u8>>,  // A buffer of bytes received but not consumed.
+    pos: uint,             // How many of the buffered bytes have already be consumed.
+    rx: Receiver<Vec<u8>>, // The Receiver to pull data from.
+    closed: bool,          // Whether the channel this Receiver connects to has been closed.
 }
 
 impl ChanReader {
     /// Wraps a `Port` in a `ChanReader` structure
-    pub fn new(rx: Receiver<~[u8]>) -> ChanReader {
+    pub fn new(rx: Receiver<Vec<u8>>) -> ChanReader {
         ChanReader {
             buf: None,
             pos: 0,
@@ -99,12 +100,12 @@ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
 /// writer.write("hello, world".as_bytes());
 /// ```
 pub struct ChanWriter {
-    tx: Sender<~[u8]>,
+    tx: Sender<Vec<u8>>,
 }
 
 impl ChanWriter {
     /// Wraps a channel in a `ChanWriter` structure
-    pub fn new(tx: Sender<~[u8]>) -> ChanWriter {
+    pub fn new(tx: Sender<Vec<u8>>) -> ChanWriter {
         ChanWriter { tx: tx }
     }
 }
@@ -117,7 +118,7 @@ fn clone(&self) -> ChanWriter {
 
 impl Writer for ChanWriter {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
-        self.tx.send_opt(buf.to_owned()).map_err(|_| {
+        self.tx.send_opt(Vec::from_slice(buf)).map_err(|_| {
             io::IoError {
                 kind: io::BrokenPipe,
                 desc: "Pipe closed",
@@ -139,40 +140,40 @@ mod test {
     fn test_rx_reader() {
         let (tx, rx) = channel();
         task::spawn(proc() {
-          tx.send(box [1u8, 2u8]);
-          tx.send(box []);
-          tx.send(box [3u8, 4u8]);
-          tx.send(box [5u8, 6u8]);
-          tx.send(box [7u8, 8u8]);
+          tx.send(vec![1u8, 2u8]);
+          tx.send(vec![]);
+          tx.send(vec![3u8, 4u8]);
+          tx.send(vec![5u8, 6u8]);
+          tx.send(vec![7u8, 8u8]);
         });
 
         let mut reader = ChanReader::new(rx);
-        let mut buf = box [0u8, ..3];
+        let mut buf = [0u8, ..3];
 
 
         assert_eq!(Ok(0), reader.read([]));
 
         assert_eq!(Ok(3), reader.read(buf));
-        assert_eq!(box [1,2,3], buf);
+        assert_eq!(&[1,2,3], buf.as_slice());
 
         assert_eq!(Ok(3), reader.read(buf));
-        assert_eq!(box [4,5,6], buf);
+        assert_eq!(&[4,5,6], buf.as_slice());
 
         assert_eq!(Ok(2), reader.read(buf));
-        assert_eq!(box [7,8,6], buf);
+        assert_eq!(&[7,8,6], buf.as_slice());
 
         match reader.read(buf) {
             Ok(..) => fail!(),
             Err(e) => assert_eq!(e.kind, io::EndOfFile),
         }
-        assert_eq!(box [7,8,6], buf);
+        assert_eq!(&[7,8,6], buf.as_slice());
 
         // Ensure it continues to fail in the same way.
         match reader.read(buf) {
             Ok(..) => fail!(),
             Err(e) => assert_eq!(e.kind, io::EndOfFile),
         }
-        assert_eq!(box [7,8,6], buf);
+        assert_eq!(&[7,8,6], buf.as_slice());
     }
 
     #[test]
@@ -181,7 +182,7 @@ fn test_chan_writer() {
         let mut writer = ChanWriter::new(tx);
         writer.write_be_u32(42).unwrap();
 
-        let wanted = box [0u8, 0u8, 0u8, 42u8];
+        let wanted = vec![0u8, 0u8, 0u8, 42u8];
         let got = task::try(proc() { rx.recv() }).unwrap();
         assert_eq!(wanted, got);
 
index c72cc0ded9bc3ca7c5f0210de3de15f75c394302..7b655693395005ccbdb515a1f5a3155ff5a203db 100644 (file)
@@ -910,7 +910,7 @@ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
 
 /// Returns a slice of `v` between `start` and `end`.
 ///
-/// Similar to `slice()` except this function only bounds the sclie on the
+/// Similar to `slice()` except this function only bounds the slice on the
 /// capacity of `v`, not the length.
 ///
 /// # Failure
index 059286339a6fa2db624ed892dc33b838737e4099..3cb2fe1c8f1b3bc35a446b05ceafe465f628a2ef 100644 (file)
@@ -873,7 +873,7 @@ pub fn sleeper() -> Process {
     pub fn sleeper() -> Process {
         // There's a `timeout` command on windows, but it doesn't like having
         // its output piped, so instead just ping ourselves a few times with
-        // gaps inbetweeen so we're sure this process is alive for awhile
+        // gaps in between so we're sure this process is alive for awhile
         Command::new("ping").arg("127.0.0.1").arg("-n").arg("1000").spawn().unwrap()
     }
 
index 5db09076c98e0316e67ecee567d5861e433bbff7..84b91814c877902571a87c6bccee98dc93dba925 100644 (file)
@@ -102,7 +102,7 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
 pub fn stdin() -> BufferedReader<StdReader> {
     // The default buffer capacity is 64k, but apparently windows doesn't like
     // 64k reads on stdin. See #13304 for details, but the idea is that on
-    // windows we use a slighly smaller buffer that's been seen to be
+    // windows we use a slightly smaller buffer that's been seen to be
     // acceptable.
     if cfg!(windows) {
         BufferedReader::with_capacity(8 * 1024, stdin_raw())
index 78b8e55c65174419db0b87f0b26642e1edf4f2de..1529cf8f92d6b50af9683b741d9929d83ab5c103 100644 (file)
@@ -96,12 +96,39 @@ pub fn sleep(&mut self, msecs: u64) {
     }
 
     /// Creates a oneshot receiver which will have a notification sent when
-    /// `msecs` milliseconds has elapsed. This does *not* block the current
-    /// task, but instead returns immediately.
+    /// `msecs` milliseconds has elapsed.
+    ///
+    /// This does *not* block the current task, but instead returns immediately.
     ///
     /// Note that this invalidates any previous receiver which has been created
     /// by this timer, and that the returned receiver will be invalidated once
-    /// the timer is destroyed (when it falls out of scope).
+    /// the timer is destroyed (when it falls out of scope). In particular, if
+    /// this is called in method-chaining style, the receiver will be
+    /// invalidated at the end of that statement, and all `recv` calls will
+    /// fail.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// use std::io::timer::Timer;
+    ///
+    /// let mut timer = Timer::new().unwrap();
+    /// let ten_milliseconds = timer.oneshot(10);
+    ///
+    /// for _ in range(0, 100) { /* do work */ }
+    ///
+    /// // blocks until 10 ms after the `oneshot` call
+    /// ten_milliseconds.recv();
+    /// ```
+    ///
+    /// ```rust
+    /// use std::io::timer::Timer;
+    ///
+    /// // Incorrect, method chaining-style:
+    /// let mut five_ms = Timer::new().unwrap().oneshot(5);
+    /// // The timer object was destroyed, so this will always fail:
+    /// // five_ms.recv()
+    /// ```
     pub fn oneshot(&mut self, msecs: u64) -> Receiver<()> {
         let (tx, rx) = channel();
         self.obj.oneshot(msecs, box TimerCallback { tx: tx });
@@ -109,14 +136,47 @@ pub fn oneshot(&mut self, msecs: u64) -> Receiver<()> {
     }
 
     /// Creates a receiver which will have a continuous stream of notifications
-    /// being sent every `msecs` milliseconds. This does *not* block the
-    /// current task, but instead returns immediately. The first notification
-    /// will not be received immediately, but rather after `msec` milliseconds
-    /// have passed.
+    /// being sent every `msecs` milliseconds.
+    ///
+    /// This does *not* block the current task, but instead returns
+    /// immediately. The first notification will not be received immediately,
+    /// but rather after `msec` milliseconds have passed.
     ///
     /// Note that this invalidates any previous receiver which has been created
     /// by this timer, and that the returned receiver will be invalidated once
-    /// the timer is destroyed (when it falls out of scope).
+    /// the timer is destroyed (when it falls out of scope). In particular, if
+    /// this is called in method-chaining style, the receiver will be
+    /// invalidated at the end of that statement, and all `recv` calls will
+    /// fail.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// use std::io::timer::Timer;
+    ///
+    /// let mut timer = Timer::new().unwrap();
+    /// let ten_milliseconds = timer.periodic(10);
+    ///
+    /// for _ in range(0, 100) { /* do work */ }
+    ///
+    /// // blocks until 10 ms after the `periodic` call
+    /// ten_milliseconds.recv();
+    ///
+    /// for _ in range(0, 100) { /* do work */ }
+    ///
+    /// // blocks until 20 ms after the `periodic` call (*not* 10ms after the
+    /// // previous `recv`)
+    /// ten_milliseconds.recv();
+    /// ```
+    ///
+    /// ```rust
+    /// use std::io::timer::Timer;
+    ///
+    /// // Incorrect, method chaining-style.
+    /// let mut five_ms = Timer::new().unwrap().periodic(5);
+    /// // The timer object was destroyed, so this will always fail:
+    /// // five_ms.recv()
+    /// ```
     pub fn periodic(&mut self, msecs: u64) -> Receiver<()> {
         let (tx, rx) = channel();
         self.obj.period(msecs, box TimerCallback { tx: tx });
@@ -158,7 +218,7 @@ mod test {
     iotest!(fn test_io_timer_oneshot_then_sleep() {
         let mut timer = Timer::new().unwrap();
         let rx = timer.oneshot(100000000000);
-        timer.sleep(1); // this should inalidate rx
+        timer.sleep(1); // this should invalidate rx
 
         assert_eq!(rx.recv_opt(), Err(()));
     })
@@ -292,7 +352,7 @@ mod test {
         let mut timer1 = Timer::new().unwrap();
         timer1.oneshot(1);
         let mut timer2 = Timer::new().unwrap();
-        // while sleeping, the prevous timer should fire and not have its
+        // while sleeping, the previous timer should fire and not have its
         // callback do something terrible.
         timer2.sleep(2);
     })
@@ -301,7 +361,7 @@ mod test {
         let mut timer1 = Timer::new().unwrap();
         timer1.periodic(1);
         let mut timer2 = Timer::new().unwrap();
-        // while sleeping, the prevous timer should fire and not have its
+        // while sleeping, the previous timer should fire and not have its
         // callback do something terrible.
         timer2.sleep(2);
     })
index 133a8db90facc6832ab16c6ff82ef74b59c44d95..48962ca59d890235b768d8df95fea332b3b64660 100644 (file)
@@ -636,7 +636,7 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Div<T,T>+
                     if accum_positive && accum <= last_accum { return NumStrConv::inf(); }
                     if !accum_positive && accum >= last_accum { return NumStrConv::neg_inf(); }
 
-                    // Detect overflow by reversing the shift-and-add proccess
+                    // Detect overflow by reversing the shift-and-add process
                     if accum_positive &&
                         (last_accum != ((accum - cast(digit as int).unwrap())/radix_gen.clone())) {
                         return NumStrConv::inf();
index 9a7e061c47282b260cc02b6ec79746e1a1c4d1fa..dd692d3fc016bdcf7544477c140e3630cb6ed0ce 100644 (file)
@@ -320,7 +320,7 @@ fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> {
 /// let key = "HOME";
 /// match std::os::getenv(key) {
 ///     Some(val) => println!("{}: {}", key, val),
-///     None => println!("{} is not defined in the environnement.", key)
+///     None => println!("{} is not defined in the environment.", key)
 /// }
 /// ```
 pub fn getenv(n: &str) -> Option<String> {
index e53842ecd8faf741443369a0122d41b4719ab393..9bb137edb82811a912391f590e1abad2f5e91562 100644 (file)
@@ -186,7 +186,7 @@ unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
         ret
     }
 
-    /// See `GenericPathUnsafe::set_filename_unchecekd`.
+    /// See `GenericPathUnsafe::set_filename_unchecked`.
     ///
     /// # Failure
     ///
index 81dcf909706dd3263e7e68c77284fd58c553ad30..5a077e511c0d482ea4336a02e538ee381cf21827 100644 (file)
@@ -243,7 +243,7 @@ pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
                 // EINVAL means |stack_size| is either too small or not a
                 // multiple of the system page size.  Because it's definitely
                 // >= PTHREAD_STACK_MIN, it must be an alignment issue.
-                // Round up to the neareast page and try again.
+                // Round up to the nearest page and try again.
                 let page_size = os::page_size();
                 let stack_size = (stack_size + page_size - 1) & (-(page_size - 1) - 1);
                 assert_eq!(pthread_attr_setstacksize(&mut attr, stack_size as libc::size_t), 0);
index a8f30c0514b80a2e193531d203700133c7460023..6005513af110df18e5a1f495552207176854cea8 100644 (file)
@@ -53,12 +53,6 @@ fn check_name(&self, name: &str) -> bool {
     fn value_str(&self) -> Option<InternedString>;
     /// Gets a list of inner meta items from a list MetaItem type.
     fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]>;
-
-    /**
-     * If the meta item is a name-value type with a string value then returns
-     * a tuple containing the name and string value, otherwise `None`
-     */
-    fn name_str_pair(&self) -> Option<(InternedString,InternedString)>;
 }
 
 impl AttrMetaMethods for Attribute {
@@ -76,9 +70,6 @@ fn value_str(&self) -> Option<InternedString> {
     fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
         self.node.value.meta_item_list()
     }
-    fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
-        self.meta().name_str_pair()
-    }
 }
 
 impl AttrMetaMethods for MetaItem {
@@ -108,10 +99,6 @@ fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
             _ => None
         }
     }
-
-    fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
-        self.value_str().map(|s| (self.name(), s))
-    }
 }
 
 // Annoying, but required to get test_cfg to work
@@ -121,9 +108,6 @@ fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
     fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
         (**self).meta_item_list()
     }
-    fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
-        (**self).name_str_pair()
-    }
 }
 
 
index efa8c8e66640fe92d377c431d3dd459b24cbdafd..906f0c16f396478e0b904bc496962bf048a1c03d 100644 (file)
@@ -128,6 +128,7 @@ fn visit_mac(&mut self, macro: &Mac, e: E) {
     fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) {
         walk_path(self, path, e)
     }
+    fn visit_attribute(&mut self, _attr: &Attribute, _e: E) {}
 }
 
 pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
@@ -142,7 +143,10 @@ pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
 
 
 pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, krate: &Crate, env: E) {
-    visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env)
+    visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env.clone());
+    for attr in krate.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) {
@@ -158,7 +162,7 @@ pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E)
 pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) {
     match vi.node {
         ViewItemExternCrate(name, _, _) => {
-            visitor.visit_ident(vi.span, name, env)
+            visitor.visit_ident(vi.span, name, env.clone())
         }
         ViewItemUse(ref vp) => {
             match vp.node {
@@ -178,6 +182,9 @@ pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, e
             }
         }
     }
+    for attr in vi.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
@@ -213,7 +220,7 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
     match item.node {
         ItemStatic(typ, _, expr) => {
             visitor.visit_ty(typ, env.clone());
-            visitor.visit_expr(expr, env);
+            visitor.visit_expr(expr, env.clone());
         }
         ItemFn(declaration, fn_style, abi, ref generics, body) => {
             visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi),
@@ -221,10 +228,10 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
                              body,
                              item.span,
                              item.id,
-                             env)
+                             env.clone())
         }
         ItemMod(ref module) => {
-            visitor.visit_mod(module, item.span, item.id, env)
+            visitor.visit_mod(module, item.span, item.id, env.clone())
         }
         ItemForeignMod(ref foreign_module) => {
             for view_item in foreign_module.view_items.iter() {
@@ -236,11 +243,11 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
         }
         ItemTy(typ, ref type_parameters) => {
             visitor.visit_ty(typ, env.clone());
-            visitor.visit_generics(type_parameters, env)
+            visitor.visit_generics(type_parameters, env.clone())
         }
         ItemEnum(ref enum_definition, ref type_parameters) => {
             visitor.visit_generics(type_parameters, env.clone());
-            walk_enum_def(visitor, enum_definition, type_parameters, env)
+            walk_enum_def(visitor, enum_definition, type_parameters, env.clone())
         }
         ItemImpl(ref type_parameters,
                  ref trait_reference,
@@ -263,7 +270,7 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
                                      item.ident,
                                      generics,
                                      item.id,
-                                     env)
+                                     env.clone())
         }
         ItemTrait(ref generics, _, ref trait_paths, ref methods) => {
             visitor.visit_generics(generics, env.clone());
@@ -276,7 +283,10 @@ pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &Item, env: E)
                 visitor.visit_trait_method(method, env.clone())
             }
         }
-        ItemMac(ref macro) => visitor.visit_mac(macro, env),
+        ItemMac(ref macro) => visitor.visit_mac(macro, env.clone()),
+    }
+    for attr in item.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
     }
 }
 
@@ -310,9 +320,12 @@ pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V,
         }
     }
     match variant.node.disr_expr {
-        Some(expr) => visitor.visit_expr(expr, env),
+        Some(expr) => visitor.visit_expr(expr, env.clone()),
         None => ()
     }
+    for attr in variant.node.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) {
@@ -469,9 +482,13 @@ pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
     match foreign_item.node {
         ForeignItemFn(function_declaration, ref generics) => {
             walk_fn_decl(visitor, function_declaration, env.clone());
-            visitor.visit_generics(generics, env)
+            visitor.visit_generics(generics, env.clone())
         }
-        ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env),
+        ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env.clone()),
+    }
+
+    for attr in foreign_item.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
     }
 }
 
@@ -525,7 +542,10 @@ pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V,
                      method.body,
                      method.span,
                      method.id,
-                     env)
+                     env.clone());
+    for attr in method.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V,
@@ -560,7 +580,10 @@ pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
         visitor.visit_ty(argument_type.ty, env.clone())
     }
     visitor.visit_generics(&method_type.generics, env.clone());
-    visitor.visit_ty(method_type.decl.output, env);
+    visitor.visit_ty(method_type.decl.output, env.clone());
+    for attr in method_type.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn walk_trait_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
@@ -596,7 +619,11 @@ pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V,
         _ => {}
     }
 
-    visitor.visit_ty(struct_field.node.ty, env)
+    visitor.visit_ty(struct_field.node.ty, env.clone());
+
+    for attr in struct_field.node.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
 
 pub fn walk_block<E: Clone, V: Visitor<E>>(visitor: &mut V, block: &Block, env: E) {
@@ -784,5 +811,8 @@ pub fn walk_arm<E: Clone, V: Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
         visitor.visit_pat(*pattern, env.clone())
     }
     walk_expr_opt(visitor, arm.guard, env.clone());
-    visitor.visit_expr(arm.body, env)
+    visitor.visit_expr(arm.body, env.clone());
+    for attr in arm.attrs.iter() {
+        visitor.visit_attribute(attr, env.clone());
+    }
 }
index 9cc8f2f23ff26aa4a3a24f422d86a94fe34aa43a..99eb2e5484d72c6f2bc2e50661c694e0ea3b9835 100644 (file)
@@ -1,12 +1,42 @@
-// 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.
+// The Computer Language Benchmarks Game
+// http://benchmarksgame.alioth.debian.org/
 //
-// 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.
+// contributed by the Rust Project Developers
+
+// Copyright (c) 2014 The Rust Project Developers
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// - Redistributions of source code must retain the above copyright
+//   notice, this list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright
+//   notice, this list of conditions and the following disclaimer in
+//   the documentation and/or other materials provided with the
+//   distribution.
+//
+// - Neither the name of "The Computer Language Benchmarks Game" nor
+//   the name of "The Computer Language Shootout Benchmarks" nor the
+//   names of its contributors may be used to endorse or promote
+//   products derived from this software without specific prior
+//   written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
 
 use std::cmp::max;
 
index 002eaf2bbf92167ea9fa9889d221e7504add4543..c2f0a58a288e5e5c769b8c41f39f7f0272c5e0d7 100644 (file)
@@ -1,12 +1,42 @@
-// 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.
+// The Computer Language Benchmarks Game
+// http://benchmarksgame.alioth.debian.org/
 //
-// 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.
+// contributed by the Rust Project Developers
+
+// Copyright (c) 2014 The Rust Project Developers
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// - Redistributions of source code must retain the above copyright
+//   notice, this list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright
+//   notice, this list of conditions and the following disclaimer in
+//   the documentation and/or other materials provided with the
+//   distribution.
+//
+// - Neither the name of "The Computer Language Benchmarks Game" nor
+//   the name of "The Computer Language Shootout Benchmarks" nor the
+//   names of its contributors may be used to endorse or promote
+//   products derived from this software without specific prior
+//   written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
 
 // FIXME(#13725) windows needs fixing.
 // ignore-win32
index f7db5c97aab111fec139dbabff50502ad6eeb653..dea712e976b35b8c5bfc48f093a141a63bc08823 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
+                           //~^ ERROR should be in the root module
 }
 
-#[crate_type = "bin"] fn main() {} //~ ERROR: crate-level attribute
-                                   //~^ ERROR: unused attribute
+#[crate_type = "bin"] fn main() {} //~ ERROR unused attribute
+                                   //~^ ERROR should be an inner
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 dc7ebaefd01400072af0b31a0d540c1e04bc09ad..5ac1eb8572fda197bcba8b6d00135955902d14c1 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 //error-pattern: lower range bound
-//error-pattern: non-numeric
+//error-pattern: only char and numeric types
 //error-pattern: mismatched types
 
 fn main() {
diff --git a/src/test/compile-fail/unused-attr.rs b/src/test/compile-fail/unused-attr.rs
new file mode 100644 (file)
index 0000000..3e1e08c
--- /dev/null
@@ -0,0 +1,58 @@
+// 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.
+#![deny(unused_attribute)]
+#![allow(dead_code, unused_imports)]
+
+#![foo] //~ ERROR unused attribute
+
+#[foo] //~ ERROR unused attribute
+extern crate std;
+
+#[foo] //~ ERROR unused attribute
+use std::collections;
+
+#[foo] //~ ERROR unused attribute
+extern "C" {
+    #[foo] //~ ERROR unused attribute
+    fn foo();
+}
+
+#[foo] //~ ERROR unused attribute
+mod foo {
+    #[foo] //~ ERROR unused attribute
+    pub enum Foo {
+        #[foo] //~ ERROR unused attribute
+        Bar,
+    }
+}
+
+#[foo] //~ ERROR unused attribute
+fn bar(f: foo::Foo) {
+    match f {
+        #[foo] //~ ERROR unused attribute
+        foo::Bar => {}
+    }
+}
+
+#[foo] //~ ERROR unused attribute
+struct Foo {
+    #[foo] //~ ERROR unused attribute
+    a: int
+}
+
+#[foo] //~ ERROR unused attribute
+trait Baz {
+    #[foo] //~ ERROR unused attribute
+    fn blah();
+    #[foo] //~ ERROR unused attribute
+    fn blah2() {}
+}
+
+fn main() {}