From 2b03718618d66e7e672663230be1ee857d3fb89a Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sat, 28 Feb 2015 23:24:05 -0800 Subject: [PATCH] Enable recursion for visit_ty in lint visitor * The lint visitor's visit_ty method did not recurse, and had a reference to the now closed #10894 * The newly enabled recursion has only affected the `deprectated` lint which now detects uses of deprecated items in trait impls and function return types * Renamed some references to `CowString` and `CowVec` to `Cow` and `Cow<[T]>`, respectively, which appear outside of the crate which defines them * Replaced a few instances of `InvariantType` with `PhantomData>` * Disabled the `deprecated` lint in several places that reference/implement traits on deprecated items which will get cleaned up in the future * Disabled the `exceeding_bitshifts` lint for compile-fail/huge-array-simple test so it doesn't shadow the expected error on 32bit systems * Unfortunately, this means that if a library declares `#![deny(deprecated)]` and marks anything as deprecated, it will have to disable the lint for any uses of said item, e.g. any impl the now deprecated item For any library that denies deprecated items but has deprecated items of its own, this is a [breaking-change] --- src/libcollections/str.rs | 1 + src/libcollections/vec.rs | 12 ++++++------ src/libcore/atomic.rs | 2 ++ src/libcore/raw.rs | 1 + src/libcore/str/mod.rs | 2 ++ src/libgraphviz/lib.rs | 4 ++-- src/librustc/lint/context.rs | 2 +- src/librustc/middle/ty.rs | 4 ++-- src/libstd/ffi/os_str.rs | 8 ++++---- src/libstd/sys/common/wtf8.rs | 7 +++---- src/libstd/sys/unix/os_str.rs | 5 +++-- src/libstd/sys/windows/os_str.rs | 5 +++-- src/libstd/thread_local/scoped.rs | 5 +++-- src/test/compile-fail/huge-array-simple.rs | 1 + 14 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 86fcac3e4b8..599b92d05dd 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -756,6 +756,7 @@ pub trait StrExt: Index { /// ``` #[unstable(feature = "collections")] #[deprecated(since = "1.0.0", reason = "use `split()` with a `&str`")] + #[allow(deprecated) /* for SplitStr */] fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> { core_str::StrExt::split_str(&self[..], pat) } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 805e4623396..a4d39974c70 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1499,9 +1499,9 @@ impl Extend for Vec { __impl_slice_eq1! { Vec, Vec } __impl_slice_eq2! { Vec, &'b [B] } __impl_slice_eq2! { Vec, &'b mut [B] } -__impl_slice_eq2! { CowVec<'a, A>, &'b [B], Clone } -__impl_slice_eq2! { CowVec<'a, A>, &'b mut [B], Clone } -__impl_slice_eq2! { CowVec<'a, A>, Vec, Clone } +__impl_slice_eq2! { Cow<'a, [A]>, &'b [B], Clone } +__impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B], Clone } +__impl_slice_eq2! { Cow<'a, [A]>, Vec, Clone } macro_rules! array_impls { ($($N: expr)+) => { @@ -1510,9 +1510,9 @@ macro_rules! array_impls { __impl_slice_eq2! { Vec, [B; $N] } __impl_slice_eq2! { Vec, &'b [B; $N] } // __impl_slice_eq2! { Vec, &'b mut [B; $N] } - // __impl_slice_eq2! { CowVec<'a, A>, [B; $N], Clone } - // __impl_slice_eq2! { CowVec<'a, A>, &'b [B; $N], Clone } - // __impl_slice_eq2! { CowVec<'a, A>, &'b mut [B; $N], Clone } + // __impl_slice_eq2! { Cow<'a, [A]>, [B; $N], Clone } + // __impl_slice_eq2! { Cow<'a, [A]>, &'b [B; $N], Clone } + // __impl_slice_eq2! { Cow<'a, [A]>, &'b mut [B; $N], Clone } )+ } } diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 38e2bd98ef9..c316236a804 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -1067,6 +1067,7 @@ pub struct AtomicInt { v: UnsafeCell, } +#[allow(deprecated)] unsafe impl Sync for AtomicInt {} #[unstable(feature = "core")] @@ -1077,6 +1078,7 @@ pub struct AtomicUint { v: UnsafeCell, } +#[allow(deprecated)] unsafe impl Sync for AtomicUint {} #[unstable(feature = "core")] diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 5cc210df5b4..35dfc762687 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -70,6 +70,7 @@ impl Copy for Slice {} #[deprecated(reason = "unboxed new closures do not have a universal representation; \ `&Fn` (etc) trait objects should use `TraitObject` instead", since= "1.0.0")] +#[allow(deprecated) /* for deriving Copy impl */] pub struct Closure { pub code: *mut (), pub env: *mut (), diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index b354116993c..facc62a8659 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -935,6 +935,7 @@ impl<'a, P: Pattern<'a>> Iterator for MatchIndices<'a, P> { #[unstable(feature = "core")] #[deprecated(since = "1.0.0", reason = "use `Split` with a `&str`")] pub struct SplitStr<'a, P: Pattern<'a>>(Split<'a, P>); +#[allow(deprecated)] impl<'a, P: Pattern<'a>> Iterator for SplitStr<'a, P> { type Item = &'a str; @@ -1325,6 +1326,7 @@ pub trait StrExt { fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P>; fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P>; fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P>; + #[allow(deprecated) /* for SplitStr */] fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P>; fn lines<'a>(&'a self) -> Lines<'a>; fn lines_any<'a>(&'a self) -> LinesAny<'a>; diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 09fbf4935e4..2f60a9e2cca 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -37,7 +37,7 @@ //! Each node label is derived directly from the int representing the node, //! while the edge labels are all empty strings. //! -//! This example also illustrates how to use `CowVec` to return +//! This example also illustrates how to use `Cow<[T]>` to return //! an owned vector or a borrowed slice as appropriate: we construct the //! node vector from scratch, but borrow the edge list (rather than //! constructing a copy of all the edges from scratch). @@ -502,7 +502,7 @@ pub type Edges<'a,E> = Cow<'a,[E]>; /// that is bound by the self lifetime `'a`. /// /// The `nodes` and `edges` method each return instantiations of -/// `CowVec` to leave implementers the freedom to create +/// `Cow<[T]>` to leave implementers the freedom to create /// entirely new vectors or to pass back slices into internally owned /// vectors. pub trait GraphWalk<'a, N, E> { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f635c77af9b..a777e1f7f75 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -568,9 +568,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { }) } - // FIXME(#10894) should continue recursing fn visit_ty(&mut self, t: &ast::Ty) { run_lints!(self, check_ty, t); + visit::walk_ty(self, t); } fn visit_ident(&mut self, sp: Span, id: ast::Ident) { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index aaba840825e..5cd2d3ca312 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -76,7 +76,7 @@ use std::hash::{Hash, SipHasher, Hasher}; use std::mem; use std::ops; use std::rc::Rc; -use std::vec::{CowVec, IntoIter}; +use std::vec::IntoIter; use collections::enum_set::{EnumSet, CLike}; use std::collections::{HashMap, HashSet}; use syntax::abi; @@ -5580,7 +5580,7 @@ pub fn predicates<'tcx>( /// Get the attributes of a definition. pub fn get_attrs<'tcx>(tcx: &'tcx ctxt, did: DefId) - -> CowVec<'tcx, ast::Attribute> { + -> Cow<'tcx, [ast::Attribute]> { if is_local(did) { let item = tcx.map.expect_item(did.node); Cow::Borrowed(&item.attrs) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index fe0df1728ef..926d8e03f2c 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -34,10 +34,10 @@ use core::prelude::*; -use borrow::{Borrow, ToOwned}; +use borrow::{Borrow, Cow, ToOwned}; use fmt::{self, Debug}; use mem; -use string::{String, CowString}; +use string::String; use ops; use cmp; use hash::{Hash, Hasher}; @@ -183,10 +183,10 @@ impl OsStr { self.inner.to_str() } - /// Convert an `OsStr` to a `CowString`. + /// Convert an `OsStr` to a `Cow`. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. - pub fn to_string_lossy(&self) -> CowString { + pub fn to_string_lossy(&self) -> Cow { self.inner.to_string_lossy() } diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index fb9d6fef1fa..bea2b6c6b40 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -38,7 +38,7 @@ use num::Int; use ops; use slice; use str; -use string::{String, CowString}; +use string::String; use sys_common::AsInner; use unicode::str::{Utf16Item, utf16_items}; use vec::Vec; @@ -530,7 +530,7 @@ impl Wtf8 { /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”). /// /// This only copies the data if necessary (if it contains any surrogate). - pub fn to_string_lossy(&self) -> CowString { + pub fn to_string_lossy(&self) -> Cow { let surrogate_pos = match self.next_surrogate(0) { None => return Cow::Borrowed(unsafe { str::from_utf8_unchecked(&self.bytes) }), Some((pos, _)) => pos, @@ -844,7 +844,6 @@ mod tests { use borrow::Cow; use super::*; use mem::transmute; - use string::CowString; #[test] fn code_point_from_u32() { @@ -1224,7 +1223,7 @@ mod tests { assert_eq!(Wtf8::from_str("aé 💩").to_string_lossy(), Cow::Borrowed("aé 💩")); let mut string = Wtf8Buf::from_str("aé 💩"); string.push(CodePoint::from_u32(0xD800).unwrap()); - let expected: CowString = Cow::Owned(String::from_str("aé 💩�")); + let expected: Cow = Cow::Owned(String::from_str("aé 💩�")); assert_eq!(string.to_string_lossy(), expected); } diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index 023d951dc4f..c8ac524876b 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -13,11 +13,12 @@ use core::prelude::*; +use borrow::Cow; use fmt::{self, Debug}; use vec::Vec; use slice::SliceExt as StdSliceExt; use str; -use string::{String, CowString}; +use string::String; use mem; #[derive(Clone, Hash)] @@ -76,7 +77,7 @@ impl Slice { str::from_utf8(&self.inner).ok() } - pub fn to_string_lossy(&self) -> CowString { + pub fn to_string_lossy(&self) -> Cow { String::from_utf8_lossy(&self.inner) } diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs index af94b56bf1f..ad1e6c4b0e7 100644 --- a/src/libstd/sys/windows/os_str.rs +++ b/src/libstd/sys/windows/os_str.rs @@ -11,9 +11,10 @@ /// The underlying OsString/OsStr implementation on Windows is a /// wrapper around the "WTF-8" encoding; see the `wtf8` module for more. +use borrow::Cow; use fmt::{self, Debug}; use sys_common::wtf8::{Wtf8, Wtf8Buf}; -use string::{String, CowString}; +use string::String; use result::Result; use option::Option; use mem; @@ -70,7 +71,7 @@ impl Slice { self.inner.as_str() } - pub fn to_string_lossy(&self) -> CowString { + pub fn to_string_lossy(&self) -> Cow { self.inner.to_string_lossy() } diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index a2a5d8b81f4..d89d69e9497 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -119,7 +119,7 @@ macro_rules! __scoped_thread_local_inner { const _INIT: __Key<$t> = __Key { inner: ::std::thread_local::scoped::__impl::KeyInner { inner: ::std::thread_local::scoped::__impl::OS_INIT, - marker: ::std::marker::InvariantType, + marker: ::std::marker::PhantomData::<::std::cell::Cell<$t>>, } }; @@ -244,12 +244,13 @@ mod imp { target_arch = "aarch64"))] mod imp { use marker; + use std::cell::Cell; use sys_common::thread_local::StaticKey as OsStaticKey; #[doc(hidden)] pub struct KeyInner { pub inner: OsStaticKey, - pub marker: marker::InvariantType, + pub marker: marker::PhantomData>, } unsafe impl ::marker::Sync for KeyInner { } diff --git a/src/test/compile-fail/huge-array-simple.rs b/src/test/compile-fail/huge-array-simple.rs index 1e04e685e41..105f885f287 100644 --- a/src/test/compile-fail/huge-array-simple.rs +++ b/src/test/compile-fail/huge-array-simple.rs @@ -9,6 +9,7 @@ // except according to those terms. // error-pattern: too big for the current +#![allow(exceeding_bitshifts)] fn main() { let fat : [u8; (1<<61)+(1<<31)] = [0; (1u64<<61) as usize +(1u64<<31) as usize];