From 78c7faf5a61dbadb757122e35abed4ab9549898d Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Thu, 8 Jan 2015 08:03:00 +0100 Subject: [PATCH 01/25] Fix: `libc::c_char` is not always `i8` --- src/librustc_trans/back/lto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index ecf2e9ed72425..0ddba47cdfe5f 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -142,7 +142,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef, let cstrs: Vec = reachable.iter().map(|s| { CString::from_slice(s.as_bytes()) }).collect(); - let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect(); + let arr: Vec<*const libc::c_char> = cstrs.iter().map(|c| c.as_ptr()).collect(); let ptr = arr.as_ptr(); unsafe { llvm::LLVMRustRunRestrictionPass(llmod, From 1f70acbf4c4f345265a7626bd927187d3bfed91f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 7 Jan 2015 15:48:16 -0800 Subject: [PATCH 02/25] Improvements to feature staging This gets rid of the 'experimental' level, removes the non-staged_api case (i.e. stability levels for out-of-tree crates), and lets the staged_api attributes use 'unstable' and 'deprecated' lints. This makes the transition period to the full feature staging design a bit nicer. --- src/liballoc/arc.rs | 16 ++--- src/liballoc/boxed.rs | 2 +- src/liballoc/lib.rs | 2 +- src/liballoc/rc.rs | 26 +++---- src/libarena/lib.rs | 2 +- src/libcollections/lib.rs | 2 +- src/libcollections/slice.rs | 34 +++++----- src/libcollections/string.rs | 18 ++--- src/libcollections/vec.rs | 20 +++--- src/libcore/any.rs | 2 +- src/libcore/array.rs | 2 +- src/libcore/cell.rs | 6 +- src/libcore/clone.rs | 2 +- src/libcore/cmp.rs | 4 +- src/libcore/finally.rs | 2 +- src/libcore/fmt/mod.rs | 20 +++--- src/libcore/fmt/rt.rs | 2 +- src/libcore/intrinsics.rs | 4 +- src/libcore/iter.rs | 44 ++++++------ src/libcore/lib.rs | 2 +- src/libcore/nonzero.rs | 2 +- src/libcore/num/mod.rs | 44 ++++++------ src/libcore/option.rs | 4 +- src/libcore/ptr.rs | 2 +- src/libcore/raw.rs | 2 +- src/libcore/result.rs | 2 +- src/libcore/simd.rs | 22 +++--- src/libcore/slice.rs | 52 +++++++------- src/libcoretest/cell.rs | 2 +- src/libflate/lib.rs | 2 +- src/libfmt_macros/lib.rs | 2 +- src/libgetopts/lib.rs | 2 +- src/libgraphviz/lib.rs | 2 +- src/liblibc/lib.rs | 2 +- src/liblog/lib.rs | 2 +- src/librand/distributions/mod.rs | 2 +- src/librand/lib.rs | 2 +- src/librbml/lib.rs | 2 +- src/libregex/lib.rs | 2 +- src/libregex/re.rs | 4 +- src/librustc/lib.rs | 2 +- src/librustc/lint/builtin.rs | 37 +++------- src/librustc/lint/context.rs | 25 ++++--- src/librustc/lint/mod.rs | 4 +- src/librustc_back/lib.rs | 2 +- src/librustc_borrowck/lib.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_llvm/lib.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_trans/lib.rs | 2 +- src/librustc_typeck/lib.rs | 2 +- src/librustdoc/lib.rs | 2 +- src/libstd/ascii.rs | 16 ++--- src/libstd/bitflags.rs | 2 +- src/libstd/collections/hash/table.rs | 2 +- src/libstd/dynamic_lib.rs | 2 +- src/libstd/failure.rs | 2 +- src/libstd/fmt.rs | 4 +- src/libstd/io/mod.rs | 2 +- src/libstd/io/net/pipe.rs | 12 ++-- src/libstd/io/net/tcp.rs | 22 +++--- src/libstd/io/net/udp.rs | 20 +++--- src/libstd/io/process.rs | 6 +- src/libstd/macros.rs | 4 +- src/libstd/num/f32.rs | 14 ++-- src/libstd/num/f64.rs | 14 ++-- src/libstd/num/float_macros.rs | 2 +- src/libstd/num/int_macros.rs | 2 +- src/libstd/num/mod.rs | 2 +- src/libstd/num/uint_macros.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/path/mod.rs | 2 +- src/libstd/rand/mod.rs | 2 +- src/libstd/rt/mod.rs | 2 +- src/libstd/rt/unwind.rs | 2 +- src/libstd/rtdeps.rs | 2 +- src/libstd/sync/mpsc/mpsc_queue.rs | 2 +- src/libstd/sync/mpsc/select.rs | 2 +- src/libstd/sync/mpsc/spsc_queue.rs | 2 +- src/libstd/sys/unix/ext.rs | 2 +- src/libstd/sys/windows/ext.rs | 2 +- src/libstd/thread.rs | 6 +- src/libstd/time/duration.rs | 2 +- src/libsyntax/lib.rs | 2 +- src/libterm/lib.rs | 2 +- src/libtest/lib.rs | 2 +- src/libunicode/lib.rs | 2 +- src/libunicode/u_char.rs | 20 +++--- src/test/auxiliary/inherited_stability.rs | 5 +- src/test/auxiliary/lint_output_format.rs | 3 +- src/test/auxiliary/lint_stability.rs | 23 ++++--- src/test/auxiliary/stability_cfg1.rs | 1 + src/test/auxiliary/stability_cfg2.rs | 4 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/compile-fail/issue-17337.rs | 1 + src/test/compile-fail/lint-forbid-attr.rs | 4 +- src/test/compile-fail/lint-forbid-cmdline.rs | 5 +- src/test/compile-fail/lint-output-format.rs | 7 +- src/test/compile-fail/lint-stability.rs | 71 ++++++++++---------- src/test/compile-fail/simd-binop.rs | 2 +- src/test/compile-fail/simd-experimental.rs | 2 +- src/test/debuginfo/simd.rs | 2 +- src/test/run-pass/simd-binop.rs | 2 +- src/test/run-pass/simd-issue-10604.rs | 2 +- src/test/run-pass/tcp-connect-timeouts.rs | 2 +- 105 files changed, 386 insertions(+), 392 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 48136bc1d96e2..290dd21d666a4 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -126,7 +126,7 @@ unsafe impl Sync for Arc { } /// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles /// between `Arc` pointers. #[unsafe_no_drop_flag] -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] pub struct Weak { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -179,7 +179,7 @@ impl Arc { /// /// let weak_five = five.downgrade(); /// ``` - #[experimental = "Weak pointers may not belong in this module."] + #[unstable = "Weak pointers may not belong in this module."] pub fn downgrade(&self) -> Weak { // See the clone() impl for why this is relaxed self.inner().weak.fetch_add(1, Relaxed); @@ -200,12 +200,12 @@ impl Arc { /// Get the number of weak references to this value. #[inline] -#[experimental] +#[unstable] pub fn weak_count(this: &Arc) -> uint { this.inner().weak.load(SeqCst) - 1 } /// Get the number of strong references to this value. #[inline] -#[experimental] +#[unstable] pub fn strong_count(this: &Arc) -> uint { this.inner().strong.load(SeqCst) } #[stable] @@ -271,7 +271,7 @@ impl Arc { /// let mut_five = five.make_unique(); /// ``` #[inline] - #[experimental] + #[unstable] pub fn make_unique(&mut self) -> &mut T { // Note that we hold a strong reference, which also counts as a weak reference, so we only // clone if there is an additional reference of either kind. @@ -355,7 +355,7 @@ impl Drop for Arc { } } -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] impl Weak { /// Upgrades a weak reference to a strong reference. /// @@ -393,7 +393,7 @@ impl Weak { } } -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] impl Clone for Weak { /// Makes a clone of the `Weak`. /// @@ -604,7 +604,7 @@ impl> Hash for Arc { } #[cfg(test)] -#[allow(experimental)] +#[allow(unstable)] mod tests { use std::clone::Clone; use std::sync::mpsc::channel; diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 97b198164ebd8..458eb3dce57a8 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -44,7 +44,7 @@ use core::ops::{Deref, DerefMut}; /// } /// ``` #[lang = "exchange_heap"] -#[experimental = "may be renamed; uncertain about custom allocator design"] +#[unstable = "may be renamed; uncertain about custom allocator design"] pub static HEAP: () = (); /// A type that represents a uniquely-owned value. diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0bb8ba669ec25..916015539a03b 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -57,7 +57,7 @@ //! default global allocator. It is not compatible with the libc allocator API. #![crate_name = "alloc"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 27b3f03002fb9..f42c6dbdc15a5 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -221,7 +221,7 @@ impl Rc { /// /// let weak_five = five.downgrade(); /// ``` - #[experimental = "Weak pointers may not belong in this module"] + #[unstable = "Weak pointers may not belong in this module"] pub fn downgrade(&self) -> Weak { self.inc_weak(); Weak { @@ -234,12 +234,12 @@ impl Rc { /// Get the number of weak references to this value. #[inline] -#[experimental] +#[unstable] pub fn weak_count(this: &Rc) -> uint { this.weak() - 1 } /// Get the number of strong references to this value. #[inline] -#[experimental] +#[unstable] pub fn strong_count(this: &Rc) -> uint { this.strong() } /// Returns true if there are no other `Rc` or `Weak` values that share the same inner value. @@ -255,7 +255,7 @@ pub fn strong_count(this: &Rc) -> uint { this.strong() } /// rc::is_unique(&five); /// ``` #[inline] -#[experimental] +#[unstable] pub fn is_unique(rc: &Rc) -> bool { weak_count(rc) == 0 && strong_count(rc) == 1 } @@ -277,7 +277,7 @@ pub fn is_unique(rc: &Rc) -> bool { /// assert_eq!(rc::try_unwrap(x), Err(Rc::new(4u))); /// ``` #[inline] -#[experimental] +#[unstable] pub fn try_unwrap(rc: Rc) -> Result> { if is_unique(&rc) { unsafe { @@ -311,7 +311,7 @@ pub fn try_unwrap(rc: Rc) -> Result> { /// assert!(rc::get_mut(&mut x).is_none()); /// ``` #[inline] -#[experimental] +#[unstable] pub fn get_mut<'a, T>(rc: &'a mut Rc) -> Option<&'a mut T> { if is_unique(rc) { let inner = unsafe { &mut **rc._ptr }; @@ -337,7 +337,7 @@ impl Rc { /// let mut_five = five.make_unique(); /// ``` #[inline] - #[experimental] + #[unstable] pub fn make_unique(&mut self) -> &mut T { if !is_unique(self) { *self = Rc::new((**self).clone()) @@ -615,7 +615,7 @@ impl> Hash for Rc { } } -#[experimental = "Show is experimental."] +#[unstable = "Show is experimental."] impl fmt::Show for Rc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Rc({:?})", **self) @@ -635,7 +635,7 @@ impl fmt::String for Rc { /// /// See the [module level documentation](../index.html) for more. #[unsafe_no_drop_flag] -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] pub struct Weak { // FIXME #12808: strange names to try to avoid interfering with // field accesses of the contained type via Deref @@ -644,7 +644,7 @@ pub struct Weak { _noshare: marker::NoSync } -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] impl Weak { /// Upgrades a weak reference to a strong reference. /// @@ -717,7 +717,7 @@ impl Drop for Weak { } } -#[experimental = "Weak pointers may not belong in this module."] +#[unstable = "Weak pointers may not belong in this module."] impl Clone for Weak { /// Makes a clone of the `Weak`. /// @@ -739,7 +739,7 @@ impl Clone for Weak { } } -#[experimental = "Show is experimental."] +#[unstable = "Show is experimental."] impl fmt::Show for Weak { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "(Weak)") @@ -780,7 +780,7 @@ impl RcBoxPtr for Weak { } #[cfg(test)] -#[allow(experimental)] +#[allow(unstable)] mod tests { use super::{Rc, Weak, weak_count, strong_count}; use std::cell::RefCell; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index f208ff9dc0517..2456d70e65e5d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -20,7 +20,7 @@ //! more complex, slower arena which can hold objects of any type. #![crate_name = "arena"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 7692c1558a70f..8d57cfb6a5d24 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -14,7 +14,7 @@ #![crate_name = "collections"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index cb3fbd461cdf6..9a1f22ef7a643 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -166,7 +166,7 @@ pub trait SliceExt { /// assert_eq!(num_moved, 3); /// assert!(a == [6i, 7, 8, 4, 5]); /// ``` - #[experimental = "uncertain about this API approach"] + #[unstable = "uncertain about this API approach"] fn move_from(&mut self, src: Vec, start: uint, end: uint) -> uint; /// Returns a subslice spanning the interval [`start`, `end`). @@ -175,7 +175,7 @@ pub trait SliceExt { /// original slice (i.e. when `end > self.len()`) or when `start > end`. /// /// Slicing with `start` equal to `end` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice(&self, start: uint, end: uint) -> &[Self::Item]; /// Returns a subslice from `start` to the end of the slice. @@ -183,7 +183,7 @@ pub trait SliceExt { /// Panics when `start` is strictly greater than the length of the original slice. /// /// Slicing from `self.len()` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice_from(&self, start: uint) -> &[Self::Item]; /// Returns a subslice from the start of the slice to `end`. @@ -191,7 +191,7 @@ pub trait SliceExt { /// Panics when `end` is strictly greater than the length of the original slice. /// /// Slicing to `0` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice_to(&self, end: uint) -> &[Self::Item]; /// Divides one slice into two at an index. @@ -284,11 +284,11 @@ pub trait SliceExt { fn first(&self) -> Option<&Self::Item>; /// Returns all but the first element of a slice. - #[experimental = "likely to be renamed"] + #[unstable = "likely to be renamed"] fn tail(&self) -> &[Self::Item]; /// Returns all but the last element of a slice. - #[experimental = "likely to be renamed"] + #[unstable = "likely to be renamed"] fn init(&self) -> &[Self::Item]; /// Returns the last element of a slice, or `None` if it is empty. @@ -384,7 +384,7 @@ pub trait SliceExt { /// original slice (i.e. when `end > self.len()`) or when `start > end`. /// /// Slicing with `start` equal to `end` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item]; /// Returns a mutable subslice from `start` to the end of the slice. @@ -392,7 +392,7 @@ pub trait SliceExt { /// Panics when `start` is strictly greater than the length of the original slice. /// /// Slicing from `self.len()` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item]; /// Returns a mutable subslice from the start of the slice to `end`. @@ -400,7 +400,7 @@ pub trait SliceExt { /// Panics when `end` is strictly greater than the length of the original slice. /// /// Slicing to `0` yields an empty slice. - #[experimental = "will be replaced by slice syntax"] + #[unstable = "will be replaced by slice syntax"] fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item]; /// Returns an iterator that allows modifying each value @@ -412,11 +412,11 @@ pub trait SliceExt { fn first_mut(&mut self) -> Option<&mut Self::Item>; /// Returns all but the first element of a mutable slice - #[experimental = "likely to be renamed or removed"] + #[unstable = "likely to be renamed or removed"] fn tail_mut(&mut self) -> &mut [Self::Item]; /// Returns all but the last element of a mutable slice - #[experimental = "likely to be renamed or removed"] + #[unstable = "likely to be renamed or removed"] fn init_mut(&mut self) -> &mut [Self::Item]; /// Returns a mutable pointer to the last item in the slice. @@ -588,7 +588,7 @@ pub trait SliceExt { /// assert!(dst.clone_from_slice(&src2) == 3); /// assert!(dst == [3i, 4, 5]); /// ``` - #[experimental] + #[unstable] fn clone_from_slice(&mut self, &[Self::Item]) -> uint where Self::Item: Clone; /// Sorts the slice, in place. @@ -677,11 +677,11 @@ pub trait SliceExt { fn prev_permutation(&mut self) -> bool where Self::Item: Ord; /// Find the first index containing a matching value. - #[experimental] + #[unstable] fn position_elem(&self, t: &Self::Item) -> Option where Self::Item: PartialEq; /// Find the last index containing a matching value. - #[experimental] + #[unstable] fn rposition_elem(&self, t: &Self::Item) -> Option where Self::Item: PartialEq; /// Return true if the slice contains an element with the given value. @@ -697,7 +697,7 @@ pub trait SliceExt { fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq; /// Convert `self` into a vector without clones or allocation. - #[experimental] + #[unstable] fn into_vec(self: Box) -> Vec; } @@ -1034,7 +1034,7 @@ impl> SliceConcatExt> for [V] { /// /// The last generated swap is always (0, 1), and it returns the /// sequence to its initial order. -#[experimental] +#[unstable] #[derive(Clone)] pub struct ElementSwaps { sdir: Vec, @@ -1046,7 +1046,7 @@ pub struct ElementSwaps { impl ElementSwaps { /// Creates an `ElementSwaps` iterator for a sequence of `length` elements. - #[experimental] + #[unstable] pub fn new(length: uint) -> ElementSwaps { // Initialize `sdir` with a direction that position should move in // (all negative at the beginning) and the `size` of the diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 1bb0be05b1e82..ae99a07c0ab11 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -92,7 +92,7 @@ impl String { /// assert_eq!(s.as_slice(), "hello"); /// ``` #[inline] - #[experimental = "needs investigation to see if to_string() can match perf"] + #[unstable = "needs investigation to see if to_string() can match perf"] pub fn from_str(string: &str) -> String { String { vec: ::slice::SliceExt::to_vec(string.as_bytes()) } } @@ -719,7 +719,7 @@ impl<'a> FromIterator<&'a str> for String { } } -#[experimental = "waiting on Extend stabilization"] +#[unstable = "waiting on Extend stabilization"] impl Extend for String { fn extend>(&mut self, mut iterator: I) { let (lower_bound, _) = iterator.size_hint(); @@ -730,7 +730,7 @@ impl Extend for String { } } -#[experimental = "waiting on Extend stabilization"] +#[unstable = "waiting on Extend stabilization"] impl<'a> Extend<&'a str> for String { fn extend>(&mut self, mut iterator: I) { // A guess that at least one byte per iterator element will be needed. @@ -790,7 +790,7 @@ impl<'a, 'b> PartialEq> for &'b str { fn ne(&self, other: &CowString<'a>) -> bool { PartialEq::ne(&**self, &**other) } } -#[experimental = "waiting on Str stabilization"] +#[unstable = "waiting on Str stabilization"] impl Str for String { #[inline] #[stable] @@ -814,14 +814,14 @@ impl fmt::String for String { } } -#[experimental = "waiting on fmt stabilization"] +#[unstable = "waiting on fmt stabilization"] impl fmt::Show for String { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Show::fmt(&**self, f) } } -#[experimental = "waiting on Hash stabilization"] +#[unstable = "waiting on Hash stabilization"] #[cfg(stage0)] impl hash::Hash for String { #[inline] @@ -829,7 +829,7 @@ impl hash::Hash for String { (**self).hash(hasher) } } -#[experimental = "waiting on Hash stabilization"] +#[unstable = "waiting on Hash stabilization"] #[cfg(not(stage0))] impl hash::Hash for String { #[inline] @@ -887,7 +887,7 @@ impl ops::Deref for String { } /// Wrapper type providing a `&String` reference via `Deref`. -#[experimental] +#[unstable] pub struct DerefString<'a> { x: DerefVec<'a, u8> } @@ -914,7 +914,7 @@ impl<'a> Deref for DerefString<'a> { /// let string = as_string("foo").clone(); /// string_consumer(string); /// ``` -#[experimental] +#[unstable] pub fn as_string<'a>(x: &'a str) -> DerefString<'a> { DerefString { x: as_vec(x.as_bytes()) } } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 69a3947df2b5b..47afc78bc1213 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -376,7 +376,7 @@ impl Vec { /// Note that this will drop any excess capacity. Calling this and /// converting back to a vector with `into_vec()` is equivalent to calling /// `shrink_to_fit()`. - #[experimental] + #[unstable] pub fn into_boxed_slice(mut self) -> Box<[T]> { self.shrink_to_fit(); unsafe { @@ -777,7 +777,7 @@ impl Vec { /// let newtyped_bytes = bytes.map_in_place(|x| Newtype(x)); /// assert_eq!(newtyped_bytes.as_slice(), [Newtype(0x11), Newtype(0x22)].as_slice()); /// ``` - #[experimental = "API may change to provide stronger guarantees"] + #[unstable = "API may change to provide stronger guarantees"] pub fn map_in_place(self, mut f: F) -> Vec where F: FnMut(T) -> U { // FIXME: Assert statically that the types `T` and `U` have the same // size. @@ -995,7 +995,7 @@ impl Vec { /// assert_eq!(vec, vec![1, 2, 3, 4]); /// ``` #[inline] - #[experimental = "likely to be replaced by a more optimized extend"] + #[unstable = "likely to be replaced by a more optimized extend"] pub fn push_all(&mut self, other: &[T]) { self.reserve(other.len()); @@ -1200,7 +1200,7 @@ impl> Hash for Vec { } } -#[experimental = "waiting on Index stability"] +#[unstable = "waiting on Index stability"] impl Index for Vec { type Output = T; @@ -1304,7 +1304,7 @@ impl FromIterator for Vec { } } -#[experimental = "waiting on Extend stability"] +#[unstable = "waiting on Extend stability"] impl Extend for Vec { #[inline] fn extend>(&mut self, mut iterator: I) { @@ -1457,7 +1457,7 @@ impl Default for Vec { } } -#[experimental = "waiting on Show stability"] +#[unstable = "waiting on Show stability"] impl fmt::Show for Vec { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Show::fmt(self.as_slice(), f) @@ -1475,7 +1475,7 @@ impl<'a> fmt::Writer for Vec { // Clone-on-write //////////////////////////////////////////////////////////////////////////////// -#[experimental = "unclear how valuable this alias is"] +#[unstable = "unclear how valuable this alias is"] /// A clone-on-write vector pub type CowVec<'a, T> = Cow<'a, Vec, [T]>; @@ -1693,13 +1693,13 @@ impl<'a, T> Drop for Drain<'a, T> { //////////////////////////////////////////////////////////////////////////////// /// Wrapper type providing a `&Vec` reference via `Deref`. -#[experimental] +#[unstable] pub struct DerefVec<'a, T> { x: Vec, l: ContravariantLifetime<'a> } -#[experimental] +#[unstable] impl<'a, T> Deref for DerefVec<'a, T> { type Target = Vec; @@ -1719,7 +1719,7 @@ impl<'a, T> Drop for DerefVec<'a, T> { } /// Convert a slice to a wrapper type providing a `&Vec` reference. -#[experimental] +#[unstable] pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> { unsafe { DerefVec { diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 25007bfde93a9..797687a9ad96e 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -89,7 +89,7 @@ use intrinsics::TypeId; #[stable] pub trait Any: 'static { /// Get the `TypeId` of `self` - #[experimental = "this method will likely be replaced by an associated static"] + #[unstable = "this method will likely be replaced by an associated static"] fn get_type_id(&self) -> TypeId; } diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 0cea0b3d88e14..c07fac108d6f3 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -12,7 +12,7 @@ //! up to a certain length. Eventually we should able to generalize //! to all lengths. -#![experimental] // not yet reviewed +#![unstable] // not yet reviewed use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 674364269f1da..6db01b7cb7afe 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -202,7 +202,7 @@ impl Cell { /// /// This function is `unsafe` because `UnsafeCell`'s field is public. #[inline] - #[experimental] + #[unstable] pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell { &self.value } @@ -332,7 +332,7 @@ impl RefCell { /// /// This function is `unsafe` because `UnsafeCell`'s field is public. #[inline] - #[experimental] + #[unstable] pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell { &self.value } @@ -424,7 +424,7 @@ impl<'b, T> Deref for Ref<'b, T> { /// /// A `Clone` implementation would interfere with the widespread /// use of `r.borrow().clone()` to clone the contents of a `RefCell`. -#[experimental = "likely to be moved to a method, pending language changes"] +#[unstable = "likely to be moved to a method, pending language changes"] pub fn clone_ref<'b, T:Clone>(orig: &Ref<'b, T>) -> Ref<'b, T> { Ref { _value: orig._value, diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 3149247a83aed..ffa6d0855435e 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -81,7 +81,7 @@ clone_impl! { char } macro_rules! extern_fn_clone { ($($A:ident),*) => ( - #[experimental = "this may not be sufficient for fns with region parameters"] + #[unstable = "this may not be sufficient for fns with region parameters"] impl<$($A,)* ReturnType> Clone for extern "Rust" fn($($A),*) -> ReturnType { /// Return a copy of a function pointer #[inline] diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index c3dfd5f51595f..c1f1997df740e 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -290,7 +290,7 @@ pub fn max(v1: T, v2: T) -> T { /// /// Returns the first argument if the comparison determines them to be equal. #[inline] -#[experimental] +#[unstable] pub fn partial_min(v1: T, v2: T) -> Option { match v1.partial_cmp(&v2) { Some(Less) | Some(Equal) => Some(v1), @@ -303,7 +303,7 @@ pub fn partial_min(v1: T, v2: T) -> Option { /// /// Returns the first argument if the comparison determines them to be equal. #[inline] -#[experimental] +#[unstable] pub fn partial_max(v1: T, v2: T) -> Option { match v1.partial_cmp(&v2) { Some(Less) => Some(v2), diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs index 2b48b2bf81afb..a21ec892dd77a 100644 --- a/src/libcore/finally.rs +++ b/src/libcore/finally.rs @@ -32,7 +32,7 @@ //! # } //! ``` -#![experimental] +#![unstable] use ops::{Drop, FnMut, FnOnce}; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 1d3767c9e336f..67d5482898ee5 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -36,7 +36,7 @@ mod num; mod float; pub mod rt; -#[experimental = "core and I/O reconciliation may alter this definition"] +#[unstable = "core and I/O reconciliation may alter this definition"] /// The type returned by formatter methods. pub type Result = result::Result<(), Error>; @@ -45,7 +45,7 @@ pub type Result = result::Result<(), Error>; /// This type does not support transmission of an error other than that an error /// occurred. Any extra information must be arranged to be transmitted through /// some other means. -#[experimental = "core and I/O reconciliation may alter this definition"] +#[unstable = "core and I/O reconciliation may alter this definition"] #[derive(Copy)] pub struct Error; @@ -58,7 +58,7 @@ pub struct Error; /// This trait should generally not be implemented by consumers of the standard /// library. The `write!` macro accepts an instance of `io::Writer`, and the /// `io::Writer` trait is favored over implementing this trait. -#[experimental = "waiting for core and I/O reconciliation"] +#[unstable = "waiting for core and I/O reconciliation"] pub trait Writer { /// Writes a slice of bytes into this writer, returning whether the write /// succeeded. @@ -123,7 +123,7 @@ enum Void {} /// family of functions. It contains a function to format the given value. At /// compile time it is ensured that the function and the value have the correct /// types, and then this struct is used to canonicalize arguments to one type. -#[experimental = "implementation detail of the `format_args!` macro"] +#[unstable = "implementation detail of the `format_args!` macro"] #[derive(Copy)] pub struct Argument<'a> { value: &'a Void, @@ -162,7 +162,7 @@ impl<'a> Arguments<'a> { /// When using the format_args!() macro, this function is used to generate the /// Arguments structure. #[doc(hidden)] #[inline] - #[experimental = "implementation detail of the `format_args!` macro"] + #[unstable = "implementation detail of the `format_args!` macro"] pub fn new(pieces: &'a [&'a str], args: &'a [Argument<'a>]) -> Arguments<'a> { Arguments { @@ -179,7 +179,7 @@ impl<'a> Arguments<'a> { /// created with `argumentuint`. However, failing to do so doesn't cause /// unsafety, but will ignore invalid . #[doc(hidden)] #[inline] - #[experimental = "implementation detail of the `format_args!` macro"] + #[unstable = "implementation detail of the `format_args!` macro"] pub fn with_placeholders(pieces: &'a [&'a str], fmt: &'a [rt::Argument<'a>], args: &'a [Argument<'a>]) -> Arguments<'a> { @@ -301,7 +301,7 @@ pub trait UpperExp { /// /// * output - the buffer to write output to /// * args - the precompiled arguments generated by `format_args!` -#[experimental = "libcore and I/O have yet to be reconciled, and this is an \ +#[unstable = "libcore and I/O have yet to be reconciled, and this is an \ implementation detail which should not otherwise be exported"] pub fn write(output: &mut Writer, args: Arguments) -> Result { let mut formatter = Formatter { @@ -563,7 +563,7 @@ impl<'a> Formatter<'a> { } /// Flags for formatting (packed version of rt::Flag) - #[experimental = "return type may change and method was just created"] + #[unstable = "return type may change and method was just created"] pub fn flags(&self) -> uint { self.flags } /// Character used as 'fill' whenever there is alignment @@ -592,7 +592,7 @@ impl Show for Error { /// This is a function which calls are emitted to by the compiler itself to /// create the Argument structures that are passed into the `format` function. #[doc(hidden)] #[inline] -#[experimental = "implementation detail of the `format_args!` macro"] +#[unstable = "implementation detail of the `format_args!` macro"] pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result, t: &'a T) -> Argument<'a> { Argument::new(t, f) @@ -601,7 +601,7 @@ pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result, /// When the compiler determines that the type of an argument *must* be a uint /// (such as for width and precision), then it invokes this method. #[doc(hidden)] #[inline] -#[experimental = "implementation detail of the `format_args!` macro"] +#[unstable = "implementation detail of the `format_args!` macro"] pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> { Argument::from_uint(s) } diff --git a/src/libcore/fmt/rt.rs b/src/libcore/fmt/rt.rs index 6dbda3d84459e..8d8e8c4b70303 100644 --- a/src/libcore/fmt/rt.rs +++ b/src/libcore/fmt/rt.rs @@ -14,7 +14,7 @@ //! These definitions are similar to their `ct` equivalents, but differ in that //! these can be statically allocated and are slightly optimized for the runtime -#![experimental = "implementation detail of the `format_args!` macro"] +#![unstable = "implementation detail of the `format_args!` macro"] pub use self::Alignment::*; pub use self::Count::*; diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index c8b3616a4042e..5924d515dda59 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -39,7 +39,7 @@ //! guaranteed to happen in order. This is the standard mode for working //! with atomic types and is equivalent to Java's `volatile`. -#![experimental] +#![unstable] #![allow(missing_docs)] #[cfg(not(stage0))] @@ -333,7 +333,7 @@ extern "rust-intrinsic" { /// Invokes memset on the specified pointer, setting `count * size_of::()` /// bytes of memory starting at `dst` to `c`. - #[experimental = "uncertain about naming and semantics"] + #[unstable = "uncertain about naming and semantics"] pub fn set_memory(dst: *mut T, val: u8, count: uint); /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 273a51665ce8a..d4aa4c99a76bd 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -942,7 +942,7 @@ pub trait IteratorExt: Iterator + Sized { } /// Use an iterator to reverse a container in place. - #[experimental = "uncertain about placement or widespread use"] + #[unstable = "uncertain about placement or widespread use"] fn reverse_in_place<'a, T: 'a>(&mut self) where Self: Iterator + DoubleEndedIterator { @@ -974,7 +974,7 @@ pub trait DoubleEndedIterator: Iterator { /// Calling `next()` or `next_back()` on a `RandomAccessIterator` /// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)` /// after `it.next()` is called. -#[experimental = "not widely used, may be better decomposed into Index and ExactSizeIterator"] +#[unstable = "not widely used, may be better decomposed into Index and ExactSizeIterator"] pub trait RandomAccessIterator: Iterator { /// Return the number of indexable elements. At most `std::uint::MAX` /// elements are indexable, even if the iterator represents a longer range. @@ -1049,7 +1049,7 @@ impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { fn next_back(&mut self) -> Option<::Item> { self.iter.next() } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Rev where I: DoubleEndedIterator + RandomAccessIterator { #[inline] fn indexable(&self) -> uint { self.iter.indexable() } @@ -1084,7 +1084,7 @@ impl<'a, I> DoubleEndedIterator for ByRef<'a, I> where I: 'a + DoubleEndedIterat } /// A trait for iterators over elements which can be added together -#[experimental = "needs to be re-evaluated as part of numerics reform"] +#[unstable = "needs to be re-evaluated as part of numerics reform"] pub trait AdditiveIterator { /// Iterates over the entire iterator, summing up all the elements /// @@ -1102,7 +1102,7 @@ pub trait AdditiveIterator { macro_rules! impl_additive { ($A:ty, $init:expr) => { - #[experimental = "trait is experimental"] + #[unstable = "trait is experimental"] impl> AdditiveIterator<$A> for T { #[inline] fn sum(self) -> $A { @@ -1125,7 +1125,7 @@ impl_additive! { f32, 0.0 } impl_additive! { f64, 0.0 } /// A trait for iterators over elements which can be multiplied together. -#[experimental = "needs to be re-evaluated as part of numerics reform"] +#[unstable = "needs to be re-evaluated as part of numerics reform"] pub trait MultiplicativeIterator { /// Iterates over the entire iterator, multiplying all the elements /// @@ -1146,7 +1146,7 @@ pub trait MultiplicativeIterator { macro_rules! impl_multiplicative { ($A:ty, $init:expr) => { - #[experimental = "trait is experimental"] + #[unstable = "trait is experimental"] impl> MultiplicativeIterator<$A> for T { #[inline] fn product(self) -> $A { @@ -1287,7 +1287,7 @@ impl Iterator for Cycle where I: Clone + Iterator { } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Cycle where I: Clone + RandomAccessIterator, { @@ -1372,7 +1372,7 @@ impl DoubleEndedIterator for Chain where } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Chain where A: RandomAccessIterator, B: RandomAccessIterator, @@ -1464,7 +1464,7 @@ impl DoubleEndedIterator for Zip where } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Zip where A: RandomAccessIterator, B: RandomAccessIterator, @@ -1546,7 +1546,7 @@ impl DoubleEndedIterator for Map where } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Map where I: RandomAccessIterator, F: FnMut(A) -> B, @@ -1735,7 +1735,7 @@ impl DoubleEndedIterator for Enumerate where } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Enumerate where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { @@ -1961,7 +1961,7 @@ impl Iterator for Skip where I: Iterator { } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Skip where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { @@ -2016,7 +2016,7 @@ impl Iterator for Take where I: Iterator{ } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Take where I: RandomAccessIterator{ #[inline] fn indexable(&self) -> uint { @@ -2229,7 +2229,7 @@ impl DoubleEndedIterator for Fuse where I: DoubleEndedIterator { } // Allow RandomAccessIterators to be fused without affecting random-access behavior -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Fuse where I: RandomAccessIterator { #[inline] fn indexable(&self) -> uint { @@ -2246,7 +2246,7 @@ impl Fuse { /// Resets the fuse such that the next call to .next() or .next_back() will /// call the underlying iterator again even if it previously returned None. #[inline] - #[experimental = "seems marginal"] + #[unstable = "seems marginal"] pub fn reset_fuse(&mut self) { self.done = false } @@ -2315,7 +2315,7 @@ impl DoubleEndedIterator for Inspect where } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Inspect where I: RandomAccessIterator, F: FnMut(&A), @@ -2364,7 +2364,7 @@ impl RandomAccessIterator for Inspect where /// println!("{}", i); /// } /// ``` -#[experimental] +#[unstable] pub struct Unfold where F: FnMut(&mut St) -> Option { f: F, /// Internal state that will be passed to the closure on the next iteration @@ -2385,7 +2385,7 @@ impl Clone for Unfold where } } -#[experimental] +#[unstable] impl Unfold where F: FnMut(&mut St) -> Option { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the closure @@ -2778,7 +2778,7 @@ impl DoubleEndedIterator for Repeat { fn next_back(&mut self) -> Option { self.idx(0) } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl RandomAccessIterator for Repeat { #[inline] fn indexable(&self) -> uint { uint::MAX } @@ -2790,12 +2790,12 @@ type IterateState = (F, Option, bool); /// An iterator that repeatedly applies a given function, starting /// from a given seed value. -#[experimental] +#[unstable] pub type Iterate = Unfold, fn(&mut IterateState) -> Option>; /// Create a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. -#[experimental] +#[unstable] pub fn iterate(seed: T, f: F) -> Iterate where T: Clone, F: FnMut(T) -> T, diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index af5aba53bf478..8c4c8a0e78efa 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -48,7 +48,7 @@ // separate crate, libcoretest, to avoid bizarre issues. #![crate_name = "core"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 087404da62434..abaf252932300 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -32,7 +32,7 @@ unsafe impl Zeroable for u64 {} /// NULL or 0 that might allow certain optimizations. #[lang="non_zero"] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Show)] -#[experimental] +#[unstable] pub struct NonZero(T); impl NonZero { diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 91fed8a31bd40..57415f4331d6d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -726,7 +726,7 @@ impl UnsignedInt for u32 {} impl UnsignedInt for u64 {} /// A generic trait for converting a value to a number. -#[experimental = "trait is likely to be removed"] +#[unstable = "trait is likely to be removed"] pub trait ToPrimitive { /// Converts the value of `self` to an `int`. #[inline] @@ -991,7 +991,7 @@ impl_to_primitive_float! { f32 } impl_to_primitive_float! { f64 } /// A generic trait for converting a number to a value. -#[experimental = "trait is likely to be removed"] +#[unstable = "trait is likely to be removed"] pub trait FromPrimitive : ::marker::Sized { /// Convert an `int` to return an optional value of this type. If the /// value cannot be represented by this value, the `None` is returned. @@ -1073,73 +1073,73 @@ pub trait FromPrimitive : ::marker::Sized { } /// A utility function that just calls `FromPrimitive::from_int`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_int(n: int) -> Option { FromPrimitive::from_int(n) } /// A utility function that just calls `FromPrimitive::from_i8`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_i8(n: i8) -> Option { FromPrimitive::from_i8(n) } /// A utility function that just calls `FromPrimitive::from_i16`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_i16(n: i16) -> Option { FromPrimitive::from_i16(n) } /// A utility function that just calls `FromPrimitive::from_i32`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_i32(n: i32) -> Option { FromPrimitive::from_i32(n) } /// A utility function that just calls `FromPrimitive::from_i64`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_i64(n: i64) -> Option { FromPrimitive::from_i64(n) } /// A utility function that just calls `FromPrimitive::from_uint`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_uint(n: uint) -> Option { FromPrimitive::from_uint(n) } /// A utility function that just calls `FromPrimitive::from_u8`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_u8(n: u8) -> Option { FromPrimitive::from_u8(n) } /// A utility function that just calls `FromPrimitive::from_u16`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_u16(n: u16) -> Option { FromPrimitive::from_u16(n) } /// A utility function that just calls `FromPrimitive::from_u32`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_u32(n: u32) -> Option { FromPrimitive::from_u32(n) } /// A utility function that just calls `FromPrimitive::from_u64`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_u64(n: u64) -> Option { FromPrimitive::from_u64(n) } /// A utility function that just calls `FromPrimitive::from_f32`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_f32(n: f32) -> Option { FromPrimitive::from_f32(n) } /// A utility function that just calls `FromPrimitive::from_f64`. -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn from_f64(n: f64) -> Option { FromPrimitive::from_f64(n) } @@ -1190,13 +1190,13 @@ impl_from_primitive! { f64, to_f64 } /// ``` /// #[inline] -#[experimental = "likely to be removed"] +#[unstable = "likely to be removed"] pub fn cast(n: T) -> Option { NumCast::from(n) } /// An interface for casting between machine scalars. -#[experimental = "trait is likely to be removed"] +#[unstable = "trait is likely to be removed"] pub trait NumCast: ToPrimitive { /// Creates a number from another value that can be converted into a primitive via the /// `ToPrimitive` trait. @@ -1394,20 +1394,20 @@ pub trait Float } /// A generic trait for converting a string with a radix (base) to a value -#[experimental = "might need to return Result"] +#[unstable = "might need to return Result"] pub trait FromStrRadix { fn from_str_radix(str: &str, radix: uint) -> Option; } /// A utility function that just calls FromStrRadix::from_str_radix. -#[experimental = "might need to return Result"] +#[unstable = "might need to return Result"] pub fn from_str_radix(str: &str, radix: uint) -> Option { FromStrRadix::from_str_radix(str, radix) } macro_rules! from_str_radix_float_impl { ($T:ty) => { - #[experimental = "might need to return Result"] + #[unstable = "might need to return Result"] impl FromStr for $T { /// Convert a string in base 10 to a float. /// Accepts an optional decimal exponent. @@ -1440,7 +1440,7 @@ macro_rules! from_str_radix_float_impl { } } - #[experimental = "might need to return Result"] + #[unstable = "might need to return Result"] impl FromStrRadix for $T { /// Convert a string in a given base to a float. /// @@ -1604,7 +1604,7 @@ from_str_radix_float_impl! { f64 } macro_rules! from_str_radix_int_impl { ($T:ty) => { - #[experimental = "might need to return Result"] + #[unstable = "might need to return Result"] impl FromStr for $T { #[inline] fn from_str(src: &str) -> Option<$T> { @@ -1612,7 +1612,7 @@ macro_rules! from_str_radix_int_impl { } } - #[experimental = "might need to return Result"] + #[unstable = "might need to return Result"] impl FromStrRadix for $T { fn from_str_radix(src: &str, radix: uint) -> Option<$T> { assert!(radix >= 2 && radix <= 36, diff --git a/src/libcore/option.rs b/src/libcore/option.rs index deee67b6d2fd7..41eecb4649d97 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -477,7 +477,7 @@ impl Option { /// assert_eq!(x.ok_or(0i), Err(0i)); /// ``` #[inline] - #[experimental] + #[unstable] pub fn ok_or(self, err: E) -> Result { match self { Some(v) => Ok(v), @@ -498,7 +498,7 @@ impl Option { /// assert_eq!(x.ok_or_else(|| 0i), Err(0i)); /// ``` #[inline] - #[experimental] + #[unstable] pub fn ok_or_else E>(self, err: F) -> Result { match self { Some(v) => Ok(v), diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index a17cd410303a5..ab1e69f006064 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -106,7 +106,7 @@ pub use intrinsics::copy_nonoverlapping_memory; #[unstable] pub use intrinsics::copy_memory; -#[experimental = "uncertain about naming and semantics"] +#[unstable = "uncertain about naming and semantics"] pub use intrinsics::set_memory; diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 1ad6d43f76f09..13a387c7cb0ed 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(missing_docs)] -#![experimental] +#![unstable] //! Contains struct definitions for the layout of compiler built-in types. //! diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7868ec67c8a3a..f7421203336c3 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -953,7 +953,7 @@ impl> FromIterator> for Result { /// If an `Err` is encountered, it is immediately returned. /// Otherwise, the folded value is returned. #[inline] -#[experimental] +#[unstable] pub fn fold SliceExt for [T] { self.binary_search_by(|p| p.cmp(x)) } - #[experimental] + #[unstable] fn next_permutation(&mut self) -> bool where T: Ord { // These cases only have 1 permutation each, so we can't do anything. if self.len() < 2 { return false; } @@ -488,7 +488,7 @@ impl SliceExt for [T] { true } - #[experimental] + #[unstable] fn prev_permutation(&mut self) -> bool where T: Ord { // These cases only have 1 permutation each, so we can't do anything. if self.len() < 2 { return false; } @@ -630,25 +630,25 @@ impl ops::IndexMut for [T] { //////////////////////////////////////////////////////////////////////////////// /// Data that is viewable as a slice. -#[experimental = "will be replaced by slice syntax"] +#[unstable = "will be replaced by slice syntax"] pub trait AsSlice { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a [T]; } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl AsSlice for [T] { #[inline(always)] fn as_slice<'a>(&'a self) -> &'a [T] { self } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl<'a, T, U: ?Sized + AsSlice> AsSlice for &'a U { #[inline(always)] fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl<'a, T, U: ?Sized + AsSlice> AsSlice for &'a mut U { #[inline(always)] fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) } @@ -754,7 +754,7 @@ pub struct Iter<'a, T: 'a> { marker: marker::ContravariantLifetime<'a> } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; #[inline] @@ -763,7 +763,7 @@ impl<'a, T> ops::Index> for Iter<'a, T> { } } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; #[inline] @@ -772,7 +772,7 @@ impl<'a, T> ops::Index> for Iter<'a, T> { } } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; #[inline] @@ -781,7 +781,7 @@ impl<'a, T> ops::Index> for Iter<'a, T> { } } -#[experimental] +#[unstable] impl<'a, T> ops::Index for Iter<'a, T> { type Output = [T]; #[inline] @@ -795,7 +795,7 @@ impl<'a, T> Iter<'a, T> { /// /// This has the same lifetime as the original slice, and so the /// iterator can continue to be used while this exists. - #[experimental] + #[unstable] pub fn as_slice(&self) -> &'a [T] { make_slice!(T => &'a [T]: self.ptr, self.end) } @@ -813,7 +813,7 @@ impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { *self } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl<'a, T> RandomAccessIterator for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -847,7 +847,7 @@ pub struct IterMut<'a, T: 'a> { } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -855,7 +855,7 @@ impl<'a, T> ops::Index> for IterMut<'a, T> { self.index(&ops::FullRange).index(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -863,7 +863,7 @@ impl<'a, T> ops::Index> for IterMut<'a, T> { self.index(&ops::FullRange).index(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -871,7 +871,7 @@ impl<'a, T> ops::Index> for IterMut<'a, T> { self.index(&ops::FullRange).index(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::Index for IterMut<'a, T> { type Output = [T]; #[inline] @@ -880,7 +880,7 @@ impl<'a, T> ops::Index for IterMut<'a, T> { } } -#[experimental] +#[unstable] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -888,7 +888,7 @@ impl<'a, T> ops::IndexMut> for IterMut<'a, T> { self.index_mut(&ops::FullRange).index_mut(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -896,7 +896,7 @@ impl<'a, T> ops::IndexMut> for IterMut<'a, T> { self.index_mut(&ops::FullRange).index_mut(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { type Output = [T]; #[inline] @@ -904,7 +904,7 @@ impl<'a, T> ops::IndexMut> for IterMut<'a, T> { self.index_mut(&ops::FullRange).index_mut(index) } } -#[experimental] +#[unstable] impl<'a, T> ops::IndexMut for IterMut<'a, T> { type Output = [T]; #[inline] @@ -921,7 +921,7 @@ impl<'a, T> IterMut<'a, T> { /// to consume the iterator. Consider using the `Slice` and /// `SliceMut` implementations for obtaining slices with more /// restricted lifetimes that do not consume the iterator. - #[experimental] + #[unstable] pub fn into_slice(self) -> &'a mut [T] { make_slice!(T => &'a mut [T]: self.ptr, self.end) } @@ -1269,7 +1269,7 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { } } -#[experimental = "trait is experimental"] +#[unstable = "trait is experimental"] impl<'a, T> RandomAccessIterator for Chunks<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -1417,7 +1417,7 @@ pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: uint) -> &'a mut [T] { // /// Operations on `[u8]`. -#[experimental = "needs review"] +#[unstable = "needs review"] pub mod bytes { use ptr; use slice::SliceExt; @@ -1430,7 +1430,7 @@ pub mod bytes { impl MutableByteVector for [u8] { #[inline] - #[allow(experimental)] + #[allow(unstable)] fn set_memory(&mut self, value: u8) { unsafe { ptr::set_memory(self.as_mut_ptr(), value, self.len()) }; } @@ -1506,7 +1506,7 @@ impl PartialOrd for [T] { } /// Extension methods for slices containing integers. -#[experimental] +#[unstable] pub trait IntSliceExt { /// Converts the slice to an immutable slice of unsigned integers with the same width. fn as_unsigned<'a>(&'a self) -> &'a [U]; @@ -1521,7 +1521,7 @@ pub trait IntSliceExt { macro_rules! impl_int_slice { ($u:ty, $s:ty, $t:ty) => { - #[experimental] + #[unstable] impl IntSliceExt<$u, $s> for [$t] { #[inline] fn as_unsigned(&self) -> &[$u] { unsafe { transmute(self) } } diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 86f34ecd15efe..a808593ffbd7d 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -114,7 +114,7 @@ fn discard_doesnt_unborrow() { } #[test] -#[allow(experimental)] +#[allow(unstable)] fn clone_ref_updates_flag() { let x = RefCell::new(0i); { diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 1896bdd182ae0..e7e1ead664cbc 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -15,7 +15,7 @@ //! [mz]: https://code.google.com/p/miniz/ #![crate_name = "flate"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 02eea5d024c7a..a16fc88d58a38 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -15,7 +15,7 @@ //! generated instead. #![crate_name = "fmt_macros"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 1d6c99542b58e..a85c8eed5e241 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -78,7 +78,7 @@ //! ``` #![crate_name = "getopts"] -#![experimental = "use the crates.io `getopts` library instead"] +#![unstable = "use the crates.io `getopts` library instead"] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 9d2318e253e72..d6d76b986e4bd 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -265,7 +265,7 @@ //! * [DOT language](http://www.graphviz.org/doc/info/lang.html) #![crate_name = "graphviz"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index c39fd074387f5..be630995e24a0 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -10,7 +10,7 @@ #![crate_name = "libc"] #![crate_type = "rlib"] -#![cfg_attr(not(feature = "cargo-build"), experimental)] +#![cfg_attr(not(feature = "cargo-build"), unstable)] #![cfg_attr(not(feature = "cargo-build"), staged_api)] #![no_std] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 0d5f6b65827a4..96d31444eee94 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -156,7 +156,7 @@ //! if logging is disabled, none of the components of the log will be executed. #![crate_name = "log"] -#![experimental = "use the crates.io `log` library instead"] +#![unstable = "use the crates.io `log` library instead"] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 2fdba8a6c4f96..e248de10df496 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -17,7 +17,7 @@ //! internally. The `IndependentSample` trait is for generating values //! that do not need to record state. -#![experimental] +#![unstable] use core::prelude::*; use core::num::{Float, Int}; diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 497e339b316c1..a533739ee3b92 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -24,7 +24,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] -#![experimental] +#![unstable] #![staged_api] #[macro_use] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index da803aa50119c..19cbead5489e9 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -16,7 +16,7 @@ //! http://www.matroska.org/technical/specs/rfc/index.html #![crate_name = "rbml"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index d19ce3b460ae5..bbc2e315409e2 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -16,7 +16,7 @@ #![crate_name = "regex"] #![crate_type = "rlib"] #![crate_type = "dylib"] -#![experimental = "use the crates.io `regex` library instead"] +#![unstable = "use the crates.io `regex` library instead"] #![staged_api] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 16dd32b6be220..abc51d6240409 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -255,7 +255,7 @@ impl Regex { } #[doc(hidden)] - #[experimental] + #[unstable] pub fn names_iter<'a>(&'a self) -> NamesIter<'a> { match *self { Native(ref n) => NamesIterNative(n.names.iter()), @@ -410,7 +410,7 @@ pub struct Captures<'t> { } impl<'t> Captures<'t> { - #[allow(experimental)] + #[allow(unstable)] fn new(re: &Regex, search: &'t str, locs: CaptureLocs) -> Option> { if !has_match(&locs) { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index e0143917a7cff..138a49d09557a 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -15,7 +15,7 @@ //! This API is completely unstable and subject to change. #![crate_name = "rustc"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 7d893f3a106cc..7df2de3218235 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1630,36 +1630,29 @@ declare_lint! { Warn, "detects use of #[deprecated] items" } -// FIXME #6875: Change to Warn after std library stabilization is complete -declare_lint! { - EXPERIMENTAL, - Allow, - "detects use of #[experimental] items" -} declare_lint! { UNSTABLE, - Allow, + Warn, "detects use of #[unstable] items (incl. items with no stability attribute)" } -declare_lint!(STAGED_EXPERIMENTAL, Warn, - "detects use of #[experimental] items in staged builds"); - -declare_lint!(STAGED_UNSTABLE, Warn, - "detects use of #[unstable] items (incl. items with no stability attribute) \ - in staged builds"); - -/// Checks for use of items with `#[deprecated]`, `#[experimental]` and +/// Checks for use of items with `#[deprecated]`, `#[unstable]` and /// `#[unstable]` attributes, or no stability attribute. #[derive(Copy)] -pub struct Stability; +pub struct Stability { this_crate_staged: bool } impl Stability { + pub fn new() -> Stability { Stability { this_crate_staged: false } } + fn lint(&self, cx: &Context, id: ast::DefId, span: Span) { let ref stability = stability::lookup(cx.tcx, id); let cross_crate = !ast_util::is_local(id); + let staged = (!cross_crate && self.this_crate_staged) + || (cross_crate && stability::is_staged_api(cx.tcx, id)); + + if !staged { return } // stability attributes are promises made across crates; only // check DEPRECATED for crate-local usage. @@ -1668,21 +1661,12 @@ impl Stability { None if cross_crate => (UNSTABLE, "unmarked"), Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate => (UNSTABLE, "unstable"), - Some(attr::Stability { level: attr::Experimental, .. }) if cross_crate => - (EXPERIMENTAL, "experimental"), Some(attr::Stability { level: attr::Deprecated, .. }) => (DEPRECATED, "deprecated"), _ => return }; output(cx, span, stability, lint, label); - if cross_crate && stability::is_staged_api(cx.tcx, id) { - if lint.name == UNSTABLE.name { - output(cx, span, stability, STAGED_UNSTABLE, label); - } else if lint.name == EXPERIMENTAL.name { - output(cx, span, stability, STAGED_EXPERIMENTAL, label); - } - } fn output(cx: &Context, span: Span, stability: &Option, lint: &'static Lint, label: &'static str) { @@ -1706,7 +1690,7 @@ impl Stability { impl LintPass for Stability { fn get_lints(&self) -> LintArray { - lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE, STAGED_EXPERIMENTAL, STAGED_UNSTABLE) + lint_array!(DEPRECATED, UNSTABLE) } fn check_crate(&mut self, _: &Context, c: &ast::Crate) { @@ -1717,6 +1701,7 @@ impl LintPass for Stability { match attr.node.value.node { ast::MetaWord(_) => { attr::mark_used(attr); + self.this_crate_staged = true; } _ => (/*pass*/) } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index db4d99fe4940d..95e1e8d44bfc5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -209,7 +209,6 @@ impl LintStore { UnsafeBlocks, UnusedMut, UnusedAllocation, - Stability, MissingCopyImplementations, UnstableFeatures, ); @@ -218,6 +217,7 @@ impl LintStore { TypeLimits, RawPointerDerive, MissingDoc, + Stability, ); add_lint_group!(sess, "bad_style", @@ -308,18 +308,21 @@ impl LintStore { UnstableFeatures::Cheat => Allow }; match self.by_name.get("unstable_features") { - Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), - Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), - None => unreachable!() - } - match self.by_name.get("staged_unstable") { - Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), - Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), + Some(&Id(lint_id)) => if self.get_level_source(lint_id).0 != Forbid { + self.set_level(lint_id, (lvl, ReleaseChannel)) + }, + Some(&Renamed(_, lint_id)) => if self.get_level_source(lint_id).0 != Forbid { + self.set_level(lint_id, (lvl, ReleaseChannel)) + }, None => unreachable!() } - match self.by_name.get("staged_experimental") { - Some(&Id(lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), - Some(&Renamed(_, lint_id)) => self.set_level(lint_id, (lvl, ReleaseChannel)), + match self.by_name.get("unstable") { + Some(&Id(lint_id)) => if self.get_level_source(lint_id).0 != Forbid { + self.set_level(lint_id, (lvl, ReleaseChannel)) + }, + Some(&Renamed(_, lint_id)) => if self.get_level_source(lint_id).0 != Forbid { + self.set_level(lint_id, (lvl, ReleaseChannel)) + }, None => unreachable!() } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 8a266a2530b53..826a35e3bb529 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -40,7 +40,7 @@ use syntax::ast; pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs}; /// Specification of a single lint. -#[derive(Copy)] +#[derive(Copy, Show)] pub struct Lint { /// A string identifier for the lint. /// @@ -208,7 +208,7 @@ impl LintId { } /// Setting for how to handle a lint. -#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord)] +#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Show)] pub enum Level { Allow, Warn, Deny, Forbid } diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index fcd20158c0a29..7aac644659710 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -22,7 +22,7 @@ //! build speedups. #![crate_name = "rustc_back"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 452eaaaa52dab..162880d185691 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -9,7 +9,7 @@ // except according to those terms. #![crate_name = "rustc_borrowck"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 27e1eaacdfd99..26790bfcde022 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -15,7 +15,7 @@ //! This API is completely unstable and subject to change. #![crate_name = "rustc_driver"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 4a281c413d6fc..61363e5423b66 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -14,7 +14,7 @@ #![allow(dead_code)] #![crate_name = "rustc_llvm"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a1ae96490cad7..65075745ee0d9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -9,7 +9,7 @@ // except according to those terms. #![crate_name = "rustc_resolve"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 5da51697d2fee..97b3dc12f4c4d 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -15,7 +15,7 @@ //! This API is completely unstable and subject to change. #![crate_name = "rustc_trans"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 76ac4b2e8af4c..5824fb776bb85 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -64,7 +64,7 @@ This API is completely unstable and subject to change. */ #![crate_name = "rustc_typeck"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 56f5c23f6f1bb..1bbbcfb3838bd 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -9,7 +9,7 @@ // except according to those terms. #![crate_name = "rustdoc"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 671408acebf0d..77c2315194bb4 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -22,7 +22,7 @@ use string::String; use vec::Vec; /// Extension methods for ASCII-subset only operations on owned strings -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] pub trait OwnedAsciiExt { /// Convert the string to ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', @@ -36,7 +36,7 @@ pub trait OwnedAsciiExt { } /// Extension methods for ASCII-subset only operations on string slices -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] pub trait AsciiExt { /// Check if within the ASCII range. fn is_ascii(&self) -> bool; @@ -57,7 +57,7 @@ pub trait AsciiExt { fn eq_ignore_ascii_case(&self, other: &Self) -> bool; } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl AsciiExt for str { #[inline] fn is_ascii(&self) -> bool { @@ -82,7 +82,7 @@ impl AsciiExt for str { } } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl OwnedAsciiExt for String { #[inline] fn into_ascii_uppercase(self) -> String { @@ -97,7 +97,7 @@ impl OwnedAsciiExt for String { } } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl AsciiExt> for [u8] { #[inline] fn is_ascii(&self) -> bool { @@ -123,7 +123,7 @@ impl AsciiExt> for [u8] { } } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl OwnedAsciiExt for Vec { #[inline] fn into_ascii_uppercase(mut self) -> Vec { @@ -142,7 +142,7 @@ impl OwnedAsciiExt for Vec { } } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl AsciiExt for u8 { #[inline] fn is_ascii(&self) -> bool { @@ -165,7 +165,7 @@ impl AsciiExt for u8 { } } -#[experimental = "would prefer to do this in a more general way"] +#[unstable = "would prefer to do this in a more general way"] impl AsciiExt for char { #[inline] fn is_ascii(&self) -> bool { diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 8dc41368e7f92..3a059766fef8e 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![experimental] +#![unstable] //! A typesafe bitmask flag generator. diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index e43cc053ba079..456f3763b3916 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -632,7 +632,7 @@ impl RawTable { /// Creates a new raw table from a given capacity. All buckets are /// initially empty. - #[allow(experimental)] + #[allow(unstable)] pub fn new(capacity: uint) -> RawTable { unsafe { let ret = RawTable::new_uninitialized(capacity); diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 2d013a8a5b830..3eeb09b79dab2 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -12,7 +12,7 @@ //! //! A simple wrapper over the platform's dynamic library facilities -#![experimental] +#![unstable] #![allow(missing_docs)] use prelude::v1::*; diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index dbc88ddf0a040..54191cf24040e 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![experimental] +#![unstable] use prelude::v1::*; diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 96fff64d2214d..907925e93d399 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -410,7 +410,7 @@ //! them with the same character. For example, the `{` character is escaped with //! `{{` and the `}` character is escaped with `}}`. -#![experimental] +#![unstable] use string; @@ -439,7 +439,7 @@ pub use core::fmt::{argument, argumentuint}; /// let s = fmt::format(format_args!("Hello, {}!", "world")); /// assert_eq!(s, "Hello, world!".to_string()); /// ``` -#[experimental = "this is an implementation detail of format! and should not \ +#[unstable = "this is an implementation detail of format! and should not \ be called directly"] pub fn format(args: Arguments) -> string::String { let mut output = string::String::new(); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 1c48b20c4447f..3968dda2a8202 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -219,7 +219,7 @@ //! concerned with error handling; instead its caller is responsible for //! responding to errors that may occur while attempting to read the numbers. -#![experimental] +#![unstable] #![deny(unused_must_use)] pub use self::SeekStyle::*; diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index 29295b5751cd4..42d9fff6d151d 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -68,7 +68,7 @@ impl UnixStream { /// /// If a `timeout` with zero or negative duration is specified then /// the function returns `Err`, with the error kind set to `TimedOut`. - #[experimental = "the timeout argument is likely to change types"] + #[unstable = "the timeout argument is likely to change types"] pub fn connect_timeout
' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:243 -``` - -Lots of output! Let's break this down: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) -``` - -You can run all of your tests with `cargo test`. This runs both your tests in -`tests`, as well as the tests you put inside of your crate. - -```text -/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default -/home/you/projects/testing/src/main.rs:1 fn main() { -/home/you/projects/testing/src/main.rs:2 println!("Hello, world!") -/home/you/projects/testing/src/main.rs:3 } -``` - -Rust has a **lint** called 'warn on dead code' used by default. A lint is a -bit of code that checks your code, and can tell you things about it. In this -case, Rust is warning us that we've written some code that's never used: our -`main` function. Of course, since we're running tests, we don't use `main`. -We'll turn this lint off for just this function soon. For now, just ignore this -output. - -```text - Running target/lib-654ce120f310a3a5 - -running 1 test -test foo ... FAILED -``` - -Now we're getting somewhere. Remember when we talked about naming our tests -with good names? This is why. Here, it says 'test foo' because we called our -test 'foo'. If we had given it a good name, it'd be more clear which test -failed, especially as we accumulate more tests. - -```text -failures: - ----- foo stdout ---- - thread 'foo' failed at 'assertion failed: false', /home/you/projects/testing/tests/lib.rs:3 - - - -failures: - foo - -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured - -thread '
' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.rs:243 -``` - -After all the tests run, Rust will show us any output from our failed tests. -In this instance, Rust tells us that our assertion failed, with false. This was -what we expected. - -Whew! Let's fix our test: - -```{rust} -#[test] -fn foo() { - assert!(true); -} -``` - -And then try to run our tests again: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running target/lib-654ce120f310a3a5 - -running 1 test -test foo ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-6d7518593c7c3ee5 - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured -``` - -Nice! Our test passes, as we expected. Note how we didn't get the -`main` warning this time? This is because `src/main.rs` didn't -need recompiling, but we'll get that warning again if we -change (and recompile) that file. Let's get rid of that -warning; change your `src/main.rs` to look like this: - -```{rust} -#[cfg(not(test))] -fn main() { - println!("Hello, world!") -} -``` - -This attribute combines two things: `cfg` and `not`. The `cfg` attribute allows -you to conditionally compile code based on something. The following item will -only be compiled if the configuration says it's true. And when Cargo compiles -our tests, it sets things up so that `cfg(test)` is true. But we want to only -include `main` when it's _not_ true. So we use `not` to negate things: -`cfg(not(test))` will only compile our code when the `cfg(test)` is false. - -With this attribute, we won't get the warning (even -though `src/main.rs` gets recompiled this time): - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running target/lib-654ce120f310a3a5 - -running 1 test -test foo ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-6d7518593c7c3ee5 - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured -``` - -Nice. Okay, let's write a real test now. Change your `tests/lib.rs` -to look like this: - -```{rust,ignore} -#[test] -fn math_checks_out() { - let result = add_three_times_four(5); - - assert_eq!(32, result); -} -``` - -And try to run the test: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) -/home/you/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`. -/home/you/projects/testing/tests/lib.rs:3 let result = add_three_times_four(5); - ^~~~~~~~~~~~~~~~~~~~ -error: aborting due to previous error -Build failed, waiting for other jobs to finish... -Could not compile `testing`. - -To learn more, run the command again with `--verbose`. -``` - -Rust can't find this function. That makes sense, as we didn't write it yet! - -In order to share this code with our tests, we'll need to make a library crate. -This is also just good software design: as we mentioned before, it's a good idea -to put most of your functionality into a library crate, and have your executable -crate use that library. This allows for code reuse. - -To do that, we'll need to make a new module. Make a new file, `src/lib.rs`, -and put this in it: - -```{rust} -# fn main() {} -pub fn add_three_times_four(x: i32) -> i32 { - (x + 3) * 4 -} -``` - -We're calling this file `lib.rs`, because Cargo uses that filename as the crate -root by convention. - -We'll then need to use this crate in our `src/main.rs`: - -```{rust,ignore} -extern crate testing; - -#[cfg(not(test))] -fn main() { - println!("Hello, world!") -} -``` - -Finally, let's import this function in our `tests/lib.rs`: - -```{rust,ignore} -extern crate testing; -use testing::add_three_times_four; - -#[test] -fn math_checks_out() { - let result = add_three_times_four(5); - - assert_eq!(32, result); -} -``` - -Let's give it a run: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running target/lib-654ce120f310a3a5 - -running 1 test -test math_checks_out ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-6d7518593c7c3ee5 - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-8a94b31f7fd2e8fe - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured - - Doc-tests testing - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured -``` - -Great! One test passed. We've got an integration test showing that our public -method works, but maybe we want to test some of the internal logic as well. -While this function is simple, if it were more complicated, you can imagine -we'd need more tests. Let's break it up into two helper functions and write -some unit tests to test those. - -Change your `src/lib.rs` to look like this: - -```{rust,ignore} -pub fn add_three_times_four(x: i32) -> i32 { - times_four(add_three(x)) -} - -fn add_three(x: i32) -> i32 { x + 3 } - -fn times_four(x: i32) -> i32 { x * 4 } -``` - -If you run `cargo test`, you should get the same output: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running target/lib-654ce120f310a3a5 - -running 1 test -test math_checks_out ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-6d7518593c7c3ee5 - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-8a94b31f7fd2e8fe - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured - - Doc-tests testing - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured -``` - -If we tried to write a test for these two new functions, it wouldn't -work. For example: - -```{rust,ignore} -extern crate testing; -use testing::add_three_times_four; -use testing::add_three; - -#[test] -fn math_checks_out() { - let result = add_three_times_four(5); - - assert_eq!(32, result); -} - -#[test] -fn test_add_three() { - let result = add_three(5); - - assert_eq!(8, result); -} -``` - -We'd get this error: - -```text - Compiling testing v0.0.1 (file:///home/you/projects/testing) -/home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private -/home/you/projects/testing/tests/lib.rs:3 use testing::add_three; - ^~~~~~~~~~~~~~~~~~~ -``` - -Right. It's private. So external, integration tests won't work. We need a -unit test. Open up your `src/lib.rs` and add this: - -```{rust,ignore} -pub fn add_three_times_four(x: i32) -> i32 { - times_four(add_three(x)) -} - -fn add_three(x: i32) -> i32 { x + 3 } - -fn times_four(x: i32) -> i32 { x * 4 } - -#[cfg(test)] -mod test { - use super::add_three; - use super::times_four; - - #[test] - fn test_add_three() { - let result = add_three(5); - - assert_eq!(8, result); - } - - #[test] - fn test_times_four() { - let result = times_four(5); - - assert_eq!(20, result); - } -} -``` - -Let's give it a shot: - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running target/lib-654ce120f310a3a5 - -running 1 test -test math_checks_out ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-6d7518593c7c3ee5 - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured - - Running target/testing-8a94b31f7fd2e8fe - -running 2 tests -test test::test_times_four ... ok -test test::test_add_three ... ok - -test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured - - Doc-tests testing - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured -``` - -Cool! We now have two tests of our internal functions. You'll note that there -are three sets of output now: one for `src/main.rs`, one for `src/lib.rs`, and -one for `tests/lib.rs`. There's one interesting thing that we haven't talked -about yet, and that's these lines: - -```{rust,ignore} -use super::add_three; -use super::times_four; -``` - -Because we've made a nested module, we can import functions from the parent -module by using `super`. Sub-modules are allowed to 'see' private functions in -the parent. - -We've now covered the basics of testing. Rust's tools are primitive, but they -work well in the simple cases. There are some Rustaceans working on building -more complicated frameworks on top of all of this, but they're just starting -out. - -# Pointers - -In systems programming, pointers are an incredibly important topic. Rust has a -very rich set of pointers, and they operate differently than in many other -languages. They are important enough that we have a specific [Pointer -Guide](guide-pointers.html) that goes into pointers in much detail. In fact, -while you're currently reading this guide, which covers the language in broad -overview, there are a number of other guides that put a specific topic under a -microscope. You can find the list of guides on the [documentation index -page](index.html#guides). - -In this section, we'll assume that you're familiar with pointers as a general -concept. If you aren't, please read the [introduction to -pointers](guide-pointers.html#an-introduction) section of the Pointer Guide, -and then come back here. We'll wait. - -Got the gist? Great. Let's talk about pointers in Rust. - -## References - -The most primitive form of pointer in Rust is called a **reference**. -References are created using the ampersand (`&`). Here's a simple -reference: - -```{rust} -let x = 5; -let y = &x; -``` - -`y` is a reference to `x`. To dereference (get the value being referred to -rather than the reference itself) `y`, we use the asterisk (`*`): - -```{rust} -let x = 5; -let y = &x; - -assert_eq!(5, *y); -``` - -Like any `let` binding, references are immutable by default. - -You can declare that functions take a reference: - -```{rust} -fn add_one(x: &i32) -> i32 { *x + 1 } - -fn main() { - assert_eq!(6, add_one(&5)); -} -``` - -As you can see, we can make a reference from a literal by applying `&` as well. -Of course, in this simple function, there's not a lot of reason to take `x` by -reference. It's just an example of the syntax. - -Because references are immutable, you can have multiple references that -**alias** (point to the same place): - -```{rust} -let x = 5; -let y = &x; -let z = &x; -``` - -We can make a mutable reference by using `&mut` instead of `&`: - -```{rust} -let mut x = 5; -let y = &mut x; -``` - -Note that `x` must also be mutable. If it isn't, like this: - -```{rust,ignore} -let x = 5; -let y = &mut x; -``` - -Rust will complain: - -```text -error: cannot borrow immutable local variable `x` as mutable - let y = &mut x; - ^ -``` - -We don't want a mutable reference to immutable data! This error message uses a -term we haven't talked about yet, 'borrow'. We'll get to that in just a moment. - -This simple example actually illustrates a lot of Rust's power: Rust has -prevented us, at compile time, from breaking our own rules. Because Rust's -references check these kinds of rules entirely at compile time, there's no -runtime overhead for this safety. At runtime, these are the same as a raw -machine pointer, like in C or C++. We've just double-checked ahead of time -that we haven't done anything dangerous. - -Rust will also prevent us from creating two mutable references that alias. -This won't work: - -```{rust,ignore} -let mut x = 5; -let y = &mut x; -let z = &mut x; -``` - -It gives us this error: - -```text -error: cannot borrow `x` as mutable more than once at a time - let z = &mut x; - ^ -note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends - let y = &mut x; - ^ -note: previous borrow ends here - fn main() { - let mut x = 5; - let y = &mut x; - let z = &mut x; - } - ^ -``` - -This is a big error message. Let's dig into it for a moment. There are three -parts: the error and two notes. The error says what we expected, we cannot have -two mutable pointers that point to the same memory. - -The two notes give some extra context. Rust's error messages often contain this -kind of extra information when the error is complex. Rust is telling us two -things: first, that the reason we cannot **borrow** `x` as `z` is that we -previously borrowed `x` as `y`. The second note shows where `y`'s borrowing -ends. - -Wait, borrowing? - -In order to truly understand this error, we have to learn a few new concepts: -**ownership**, **borrowing**, and **lifetimes**. - -## Ownership, borrowing, and lifetimes - -Whenever a resource of some kind is created, something must be responsible -for destroying that resource as well. Given that we're discussing pointers -right now, let's discuss this in the context of memory allocation, though -it applies to other resources as well. - -When you allocate heap memory, you need a mechanism to free that memory. Many -languages use a garbage collector to handle deallocation. This is a valid, -time-tested strategy, but it's not without its drawbacks: it adds overhead, and -can lead to unpredictable pauses in execution. Because the programmer does not -have to think as much about deallocation, allocation becomes something -commonplace, leading to more memory usage. And if you need precise control -over when something is deallocated, leaving it up to your runtime can make this -difficult. - -Rust chooses a different path, and that path is called **ownership**. Any -binding that creates a resource is the **owner** of that resource. - -Being an owner affords you some privileges: - -1. You control when that resource is deallocated. -2. You may lend that resource, immutably, to as many borrowers as you'd like. -3. You may lend that resource, mutably, to a single borrower. - -But it also comes with some restrictions: - -1. If someone is borrowing your resource (either mutably or immutably), you may - not mutate the resource or mutably lend it to someone. -2. If someone is mutably borrowing your resource, you may not lend it out at - all (mutably or immutably) or access it in any way. - -What's up with all this 'lending' and 'borrowing'? When you allocate memory, -you get a pointer to that memory. This pointer allows you to manipulate said -memory. If you are the owner of a pointer, then you may allow another -binding to temporarily borrow that pointer, and then they can manipulate the -memory. The length of time that the borrower is borrowing the pointer -from you is called a **lifetime**. - -If two distinct bindings share a pointer, and the memory that pointer points to -is immutable, then there are no problems. But if it's mutable, the result of -changing it can vary unpredictably depending on who happens to access it first, -which is called a **race condition**. To avoid this, if someone wants to mutate -something that they've borrowed from you, you must not have lent out that -pointer to anyone else. - -Rust has a sophisticated system called the **borrow checker** to make sure that -everyone plays by these rules. At compile time, it verifies that none of these -rules are broken. If our program compiles successfully, Rust can guarantee it -is free of data races and other memory errors, and there is no runtime overhead -for any of this. The borrow checker works only at compile time. If the borrow -checker did find a problem, it will report an error and your program will -refuse to compile. - -That's a lot to take in. It's also one of the _most_ important concepts in -all of Rust. Let's see this syntax in action: - -```{rust} -{ - let x = 5; // x is the owner of this integer, which is memory on the stack. - - // other code here... - -} // privilege 1: when x goes out of scope, this memory is deallocated - -/// this function borrows an integer. It's given back automatically when the -/// function returns. -fn foo(x: &i32) -> &i32 { x } - -{ - // x is the owner of the integer, which is memory on the stack. - let x = 5; - - // privilege 2: you may lend that resource to as many borrowers as you like - let y = &x; - let z = &x; - - foo(&x); // functions can borrow too! - - let a = &x; // we can do this alllllll day! -} - -{ - // x is the owner of this integer, which is memory on the stack. - let mut x = 5; - - // privilege 3: you may lend that resource to a single borrower, mutably - let y = &mut x; -} -``` - -If you are a borrower, you get a few privileges as well, but must also obey a -restriction: - -1. If the borrow is immutable, you may read the data the pointer points to. -2. If the borrow is mutable, you may read and write the data the pointer points to. -3. You may lend the pointer to someone else, **BUT** -4. When you do so, they must return it before you can give your own borrow back. - -This last requirement can seem odd, but it also makes sense. If you have to -return something, and you've lent it to someone, they need to give it back to -you for you to give it back! If we didn't, then the owner could deallocate -the memory, and the person we've loaned it out to would have a pointer to -invalid memory. This is called a 'dangling pointer'. - -Let's re-examine the error that led us to talk about all of this, which was a -violation of the restrictions placed on owners who lend something out mutably. -The code: - -```{rust,ignore} -let mut x = 5; -let y = &mut x; -let z = &mut x; -``` - -The error: - -```text -error: cannot borrow `x` as mutable more than once at a time - let z = &mut x; - ^ -note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends - let y = &mut x; - ^ -note: previous borrow ends here - fn main() { - let mut x = 5; - let y = &mut x; - let z = &mut x; - } - ^ -``` - -This error comes in three parts. Let's go over each in turn. - -```text -error: cannot borrow `x` as mutable more than once at a time - let z = &mut x; - ^ -``` - -This error states the restriction: you cannot lend out something mutable more -than once at the same time. The borrow checker knows the rules! - -```text -note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends - let y = &mut x; - ^ -``` - -Some compiler errors come with notes to help you fix the error. This error comes -with two notes, and this is the first. This note informs us of exactly where -the first mutable borrow occurred. The error showed us the second. So now we -see both parts of the problem. It also alludes to rule #3, by reminding us that -we can't change `x` until the borrow is over. - -```text -note: previous borrow ends here - fn main() { - let mut x = 5; - let y = &mut x; - let z = &mut x; - } - ^ -``` - -Here's the second note, which lets us know where the first borrow would be over. -This is useful, because if we wait to try to borrow `x` after this borrow is -over, then everything will work. - -For more advanced patterns, please consult the [Ownership -Guide](guide-ownership.html). You'll also learn what this type signature with -the `'a` syntax is: - -```{rust,ignore} -pub fn as_maybe_owned(&self) -> MaybeOwned<'a> { ... } -``` - -## Boxes - -Most of the types we've seen so far have a fixed size or number of components. -The compiler needs this fact to lay out values in memory. However, some data -structures, such as a linked list, do not have a fixed size. You might think to -implement a linked list with an enum that's either a `Node` or the end of the -list (`Nil`), like this: - -```{rust,ignore} -enum List { // error: illegal recursive enum type - Node(u32, List), - Nil -} -``` - -But the compiler complains that the type is recursive, that is, it could be -arbitrarily large. To remedy this, Rust provides a fixed-size container called -a **Box** that can hold any type. You can box up any value with the `Box::new` -function. Our boxed List gets the type `Box` (more on the notation when we -get to generics): - -```{rust} -# use std::boxed::Box; -enum List { - Node(u32, Box), - Nil -} - -fn main() { - let list = List::Node(0, Box::new(List::Node(1, Box::new(List::Nil)))); -} -``` - -A box dynamically allocates memory to hold its contents. The great thing about -Rust is that that memory is *automatically*, *efficiently*, and *predictably* -deallocated when you're done with the box. - -A box is a pointer type, and you access what's inside using the `*` operator, -just like regular references. This (rather silly) example dynamically allocates -an integer `5` and makes `x` a pointer to it: - -```{rust} -# use std::boxed::Box; -{ - let x = Box::new(5); - println!("{}", *x); // Prints 5 -} -``` - -The great thing about boxes is that we don't have to manually free this -allocation! Instead, when `x` reaches the end of its lifetime – in this case, -when it goes out of scope at the end of the block – Rust `free`s `x`. This -isn't because Rust has a garbage collector (it doesn't). Instead, by tracking -the ownership and lifetime of a variable (with a little help from you, the -programmer), the compiler knows precisely when it is no longer used. - -The Rust code above will do the same thing as the following C code: - -```{c,ignore} -{ - i32 *x = (i32 *)malloc(sizeof(i32)); - if (!x) abort(); - *x = 5; - printf("%d\n", *x); - free(x); -} -``` - -We get the benefits of manual memory management, while ensuring we don't -introduce any bugs. We can't forget to `free` our memory. - -Boxes are the sole owner of their contents, so you cannot take a mutable -reference to them and then use the original box: - -```{rust,ignore} -# use std::boxed::Box; -let mut x = Box::new(5); -let y = &mut x; - -*x; // you might expect 5, but this is actually an error -``` - -This gives us this error: - -```text -error: cannot use `*x` because it was mutably borrowed - *x; - ^~ -note: borrow of `x` occurs here - let y = &mut x; - ^ -``` - -As long as `y` is borrowing the contents, we cannot use `x`. After `y` is -done borrowing the value, we can use it again. This works fine: - -```{rust} -# use std::boxed::Box; -let mut x = Box::new(5); - -{ - let y = &mut x; -} // y goes out of scope at the end of the block - -*x; -``` - -Boxes are simple and efficient pointers to dynamically allocated values with a -single owner. They are useful for tree-like structures where the lifetime of a -child depends solely on the lifetime of its (single) parent. If you need a -value that must persist as long as any of several referrers, read on. - -## Rc and Arc - -Sometimes you need a variable that is referenced from multiple places -(immutably!), lasting as long as any of those places, and disappearing when it -is no longer referenced. For instance, in a graph-like data structure, a node -might be referenced from all of its neighbors. In this case, it is not possible -for the compiler to determine ahead of time when the value can be freed – it -needs a little run-time support. - -Rust's **Rc** type provides shared ownership of a dynamically allocated value -that is automatically freed at the end of its last owner's lifetime. (`Rc` -stands for 'reference counted', referring to the way these library types are -implemented.) This provides more flexibility than single-owner boxes, but has -some runtime overhead. - -To create an `Rc` value, use `Rc::new()`. To create a second owner, use the -`.clone()` method: - -```{rust} -use std::rc::Rc; - -let x = Rc::new(5); -let y = x.clone(); - -println!("{} {}", *x, *y); // Prints 5 5 -``` - -The `Rc` will live as long as any of its owners are alive. After that, the -memory will be `free`d. - -**Arc** is an 'atomically reference counted' value, identical to `Rc` except -that ownership can be safely shared among multiple threads. Why two types? -`Arc` has more overhead, so if you're not in a multi-threaded scenario, you -don't have to pay the price. - -If you use `Rc` or `Arc`, you have to be careful about introducing cycles. If -you have two `Rc`s that point to each other, they will happily keep each other -alive forever, creating a memory leak. To learn more, check out [the section on -`Rc` and `Arc` in the pointers guide](guide-pointers.html#rc-and-arc). - -# Patterns - -We've made use of patterns a few times in the guide: first with `let` bindings, -then with `match` statements. Let's go on a whirlwind tour of all of the things -patterns can do! - -A quick refresher: you can match against literals directly, and `_` acts as an -'any' case: - -```{rust} -let x = 1; - -match x { - 1 => println!("one"), - 2 => println!("two"), - 3 => println!("three"), - _ => println!("anything"), -} -``` - -You can match multiple patterns with `|`: - -```{rust} -let x = 1; - -match x { - 1 | 2 => println!("one or two"), - 3 => println!("three"), - _ => println!("anything"), -} -``` - -You can match a range of values with `...`: - -```{rust} -let x = 1; - -match x { - 1 ... 5 => println!("one through five"), - _ => println!("anything"), -} -``` - -Ranges are mostly used with integers and single characters. - -If you're matching multiple things, via a `|` or a `...`, you can bind -the value to a name with `@`: - -```{rust} -let x = 1; - -match x { - e @ 1 ... 5 => println!("got a range element {}", e), - _ => println!("anything"), -} -``` - -If you're matching on an enum which has variants, you can use `..` to -ignore the value and type in the variant: - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} - -let x = OptionalInt::Value(5); - -match x { - OptionalInt::Value(..) => println!("Got an i32!"), - OptionalInt::Missing => println!("No such luck."), -} -``` - -You can introduce **match guards** with `if`: - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} - -let x = OptionalInt::Value(5); - -match x { - OptionalInt::Value(i) if i > 5 => println!("Got an i32 bigger than five!"), - OptionalInt::Value(..) => println!("Got an i32!"), - OptionalInt::Missing => println!("No such luck."), -} -``` - -If you're matching on a pointer, you can use the same syntax as you declared it -with. First, `&`: - -```{rust} -let x = &5; - -match x { - &val => println!("Got a value: {}", val), -} -``` - -Here, the `val` inside the `match` has type `i32`. In other words, the left-hand -side of the pattern destructures the value. If we have `&5`, then in `&val`, `val` -would be `5`. - -If you want to get a reference, use the `ref` keyword: - -```{rust} -let x = 5; - -match x { - ref r => println!("Got a reference to {}", r), -} -``` - -Here, the `r` inside the `match` has the type `&i32`. In other words, the `ref` -keyword _creates_ a reference, for use in the pattern. If you need a mutable -reference, `ref mut` will work in the same way: - -```{rust} -let mut x = 5; - -match x { - ref mut mr => println!("Got a mutable reference to {}", mr), -} -``` - -If you have a struct, you can destructure it inside of a pattern: - -```{rust} -# #![allow(non_shorthand_field_patterns)] -struct Point { - x: i32, - y: i32, -} - -let origin = Point { x: 0, y: 0 }; - -match origin { - Point { x: x, y: y } => println!("({},{})", x, y), -} -``` - -If we only care about some of the values, we don't have to give them all names: - -```{rust} -# #![allow(non_shorthand_field_patterns)] -struct Point { - x: i32, - y: i32, -} - -let origin = Point { x: 0, y: 0 }; - -match origin { - Point { x: x, .. } => println!("x is {}", x), -} -``` - -You can do this kind of match on any member, not just the first: - -```{rust} -# #![allow(non_shorthand_field_patterns)] -struct Point { - x: i32, - y: i32, -} - -let origin = Point { x: 0, y: 0 }; - -match origin { - Point { y: y, .. } => println!("y is {}", y), -} -``` - -If you want to match against a slice or array, you can use `[]`: - -```{rust} -fn main() { - let v = vec!["match_this", "1"]; - - match v.as_slice() { - ["match_this", second] => println!("The second element is {}", second), - _ => {}, - } -} -``` - -Whew! That's a lot of different ways to match things, and they can all be -mixed and matched, depending on what you're doing: - -```{rust,ignore} -match x { - Foo { x: Some(ref name), y: None } => ... -} -``` - -Patterns are very powerful. Make good use of them. - -# Method Syntax - -Functions are great, but if you want to call a bunch of them on some data, it -can be awkward. Consider this code: - -```{rust,ignore} -baz(bar(foo(x))); -``` - -We would read this left-to right, and so we see 'baz bar foo.' But this isn't the -order that the functions would get called in, that's inside-out: 'foo bar baz.' -Wouldn't it be nice if we could do this instead? - -```{rust,ignore} -x.foo().bar().baz(); -``` - -Luckily, as you may have guessed with the leading question, you can! Rust provides -the ability to use this **method call syntax** via the `impl` keyword. - -Here's how it works: - -```{rust} -struct Circle { - x: f64, - y: f64, - radius: f64, -} - -impl Circle { - fn area(&self) -> f64 { - std::f64::consts::PI * (self.radius * self.radius) - } -} - -fn main() { - let c = Circle { x: 0.0, y: 0.0, radius: 2.0 }; - println!("{}", c.area()); -} -``` - -This will print `12.566371`. - -We've made a struct that represents a circle. We then write an `impl` block, -and inside it, define a method, `area`. Methods take a special first -parameter, `&self`. There are three variants: `self`, `&self`, and `&mut self`. -You can think of this first parameter as being the `x` in `x.foo()`. The three -variants correspond to the three kinds of things `x` could be: `self` if it's -just a value on the stack, `&self` if it's a reference, and `&mut self` if it's -a mutable reference. We should default to using `&self`, as it's the most -common. - -Finally, as you may remember, the value of the area of a circle is `π*r²`. -Because we took the `&self` parameter to `area`, we can use it just like any -other parameter. Because we know it's a `Circle`, we can access the `radius` -just like we would with any other struct. An import of π and some -multiplications later, and we have our area. - -You can also define methods that do not take a `self` parameter. Here's a -pattern that's very common in Rust code: - -```{rust} -# #![allow(non_shorthand_field_patterns)] -struct Circle { - x: f64, - y: f64, - radius: f64, -} - -impl Circle { - fn new(x: f64, y: f64, radius: f64) -> Circle { - Circle { - x: x, - y: y, - radius: radius, - } - } -} - -fn main() { - let c = Circle::new(0.0, 0.0, 2.0); -} -``` - -This **static method** builds a new `Circle` for us. Note that static methods -are called with the `Struct::method()` syntax, rather than the `ref.method()` -syntax. - -# Closures - -So far, we've made lots of functions in Rust, but we've given them all names. -Rust also allows us to create anonymous functions. Rust's anonymous -functions are called **closure**s. By themselves, closures aren't all that -interesting, but when you combine them with functions that take closures as -arguments, really powerful things are possible. - -Let's make a closure: - -```{rust} -let add_one = |&: x| { 1 + x }; - -println!("The sum of 5 plus 1 is {}.", add_one(5)); -``` - -We create a closure using the `|...| { ... }` syntax, and then we create a -binding so we can use it later. Note that we call the function using the -binding name and two parentheses, just like we would for a named function. - -Let's compare syntax. The two are pretty close: - -```{rust} -let add_one = |&: x: i32| -> i32 { 1 + x }; -fn add_one (x: i32) -> i32 { 1 + x } -``` - -As you may have noticed, closures infer their argument and return types, so you -don't need to declare one. This is different from named functions, which -default to returning unit (`()`). - -There's one big difference between a closure and named functions, and it's in -the name: a closure "closes over its environment." What does that mean? It means -this: - -```{rust} -fn main() { - let x: i32 = 5; - - let printer = |&:| { println!("x is: {}", x); }; - - printer(); // prints "x is: 5" -} -``` - -The `||` syntax means this is an anonymous closure that takes no arguments. -Without it, we'd just have a block of code in `{}`s. - -In other words, a closure has access to variables in the scope where it's -defined. The closure borrows any variables it uses, so this will error: - -```{rust,ignore} -fn main() { - let mut x = 5; - - let printer = |&:| { println!("x is: {}", x); }; - - x = 6; // error: cannot assign to `x` because it is borrowed -} -``` - -## Moving closures - -Rust has a second type of closure, called a **moving closure**. Moving -closures are indicated using the `move` keyword (e.g., `move || x * -x`). The difference between a moving closure and an ordinary closure -is that a moving closure always takes ownership of all variables that -it uses. Ordinary closures, in contrast, just create a reference into -the enclosing stack frame. Moving closures are most useful with Rust's -concurrency features, and so we'll just leave it at this for -now. We'll talk about them more in the "Threads" section of the guide. - -## Accepting closures as arguments - -Closures are most useful as an argument to another function. Here's an example: - -```{rust} -fn twice i32>(x: i32, f: F) -> i32 { - f(x) + f(x) -} - -fn main() { - let square = |&: x: i32| { x * x }; - - twice(5, square); // evaluates to 50 -} -``` - -Let's break the example down, starting with `main`: - -```{rust} -let square = |&: x: i32| { x * x }; -``` - -We've seen this before. We make a closure that takes an integer, and returns -its square. - -```{rust} -# fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } -# let square = |&: x: i32| { x * x }; -twice(5, square); // evaluates to 50 -``` - -This line is more interesting. Here, we call our function, `twice`, and we pass -it two arguments: an integer, `5`, and our closure, `square`. This is just like -passing any other two variable bindings to a function, but if you've never -worked with closures before, it can seem a little complex. Just think: "I'm -passing two variables: one is an i32, and one is a function." - -Next, let's look at how `twice` is defined: - -```{rust,ignore} -fn twice(x: i32, f: |i32| -> i32) -> i32 { -``` - -`twice` takes two arguments, `x` and `f`. That's why we called it with two -arguments. `x` is an `i32`, we've done that a ton of times. `f` is a function, -though, and that function takes an `i32` and returns an `i32`. Notice -how the `|i32| -> i32` syntax looks a lot like our definition of `square` -above, if we added the return type in: - -```{rust} -let square = |&: x: i32| -> i32 { x * x }; -// |i32| -> i32 -``` - -This function takes an `i32` and returns an `i32`. - -This is the most complicated function signature we've seen yet! Give it a read -a few times until you can see how it works. It takes a teeny bit of practice, and -then it's easy. - -Finally, `twice` returns an `i32` as well. - -Okay, let's look at the body of `twice`: - -```{rust} -fn twice i32>(x: i32, f: F) -> i32 { - f(x) + f(x) -} -``` - -Since our closure is named `f`, we can call it just like we called our closures -before, and we pass in our `x` argument to each one, hence the name `twice`. - -If you do the math, `(5 * 5) + (5 * 5) == 50`, so that's the output we get. - -Play around with this concept until you're comfortable with it. Rust's standard -library uses lots of closures where appropriate, so you'll be using -this technique a lot. - -If we didn't want to give `square` a name, we could just define it inline. -This example is the same as the previous one: - -```{rust} -fn twice i32>(x: i32, f: F) -> i32 { - f(x) + f(x) -} - -fn main() { - twice(5, |x: i32| { x * x }); // evaluates to 50 -} -``` - -A named function's name can be used wherever you'd use a closure. Another -way of writing the previous example: - -```{rust} -fn twice i32>(x: i32, f: F) -> i32 { - f(x) + f(x) -} - -fn square(x: i32) -> i32 { x * x } - -fn main() { - twice(5, square); // evaluates to 50 -} -``` - -Doing this is not particularly common, but it's useful every once in a while. - -That's all you need to get the hang of closures! Closures are a little bit -strange at first, but once you're used to them, you'll miss them -in other languages. Passing functions to other functions is -incredibly powerful, as you will see in the following chapter about iterators. - -# Iterators - -Let's talk about loops. - -Remember Rust's `for` loop? Here's an example: - -```{rust} -for x in range(0, 10) { - println!("{}", x); -} -``` - -Now that you know more Rust, we can talk in detail about how this works. The -`range` function returns an **iterator**. An iterator is something that we can -call the `.next()` method on repeatedly, and it gives us a sequence of things. - -Like this: - -```{rust} -let mut range = range(0, 10); - -loop { - match range.next() { - Some(x) => { - println!("{}", x); - }, - None => { break } - } -} -``` - -We make a mutable binding to the return value of `range`, which is our iterator. -We then `loop`, with an inner `match`. This `match` is used on the result of -`range.next()`, which gives us a reference to the next value of the iterator. -`next` returns an `Option`, in this case, which will be `Some(i32)` when -we have a value and `None` once we run out. If we get `Some(i32)`, we print it -out, and if we get `None`, we `break` out of the loop. - -This code sample is basically the same as our `for` loop version. The `for` -loop is just a handy way to write this `loop`/`match`/`break` construct. - -`for` loops aren't the only thing that uses iterators, however. Writing your -own iterator involves implementing the `Iterator` trait. While doing that is -outside of the scope of this guide, Rust provides a number of useful iterators -to accomplish various tasks. Before we talk about those, we should talk about a -Rust anti-pattern. And that's `range`. - -Yes, we just talked about how `range` is cool. But `range` is also very -primitive. For example, if you needed to iterate over the contents of -a vector, you may be tempted to write this: - -```{rust} -let nums = vec![1, 2, 3]; - -for i in range(0u, nums.len()) { - println!("{}", nums[i]); -} -``` - -This is strictly worse than using an actual iterator. The `.iter()` method on -vectors returns an iterator that iterates through a reference to each element -of the vector in turn. So write this: - -```{rust} -let nums = vec![1, 2, 3]; - -for num in nums.iter() { - println!("{}", num); -} -``` - -There are two reasons for this. First, this more directly expresses what we -mean. We iterate through the entire vector, rather than iterating through -indexes, and then indexing the vector. Second, this version is more efficient: -the first version will have extra bounds checking because it used indexing, -`nums[i]`. But since we yield a reference to each element of the vector in turn -with the iterator, there's no bounds checking in the second example. This is -very common with iterators: we can ignore unnecessary bounds checks, but still -know that we're safe. - -There's another detail here that's not 100% clear because of how `println!` -works. `num` is actually of type `&i32`. That is, it's a reference to an `i32`, -not an `i32` itself. `println!` handles the dereferencing for us, so we don't -see it. This code works fine too: - -```{rust} -let nums = vec![1, 2, 3]; - -for num in nums.iter() { - println!("{}", *num); -} -``` - -Now we're explicitly dereferencing `num`. Why does `iter()` give us references? -Well, if it gave us the data itself, we would have to be its owner, which would -involve making a copy of the data and giving us the copy. With references, -we're just borrowing a reference to the data, and so it's just passing -a reference, without needing to do the copy. - -So, now that we've established that `range` is often not what you want, let's -talk about what you do want instead. - -There are three broad classes of things that are relevant here: iterators, -**iterator adapters**, and **consumers**. Here's some definitions: - -* 'iterators' give you a sequence of values. -* 'iterator adapters' operate on an iterator, producing a new iterator with a - different output sequence. -* 'consumers' operate on an iterator, producing some final set of values. - -Let's talk about consumers first, since you've already seen an iterator, -`range`. - -## Consumers - -A 'consumer' operates on an iterator, returning some kind of value or values. -The most common consumer is `collect()`. This code doesn't quite compile, -but it shows the intention: - -```{rust,ignore} -let one_to_one_hundred = range(1, 101).collect(); -``` - -As you can see, we call `collect()` on our iterator. `collect()` takes -as many values as the iterator will give it, and returns a collection -of the results. So why won't this compile? Rust can't determine what -type of things you want to collect, and so you need to let it know. -Here's the version that does compile: - -```{rust} -let one_to_one_hundred = range(1, 101).collect::>(); -``` - -If you remember, the `::<>` syntax allows us to give a type hint, -and so we tell it that we want a vector of integers. - -`collect()` is the most common consumer, but there are others too. `find()` -is one: - -```{rust} -let greater_than_forty_two = range(0, 100) - .find(|x| *x > 42); - -match greater_than_forty_two { - Some(_) => println!("We got some numbers!"), - None => println!("No numbers found :("), -} -``` - -`find` takes a closure, and works on a reference to each element of an -iterator. This closure returns `true` if the element is the element we're -looking for, and `false` otherwise. Because we might not find a matching -element, `find` returns an `Option` rather than the element itself. - -Another important consumer is `fold`. Here's what it looks like: - -```{rust} -let sum = range(1, 4) - .fold(0, |sum, x| sum + x); -``` - -`fold()` is a consumer that looks like this: -`fold(base, |accumulator, element| ...)`. It takes two arguments: the first -is an element called the "base". The second is a closure that itself takes two -arguments: the first is called the "accumulator," and the second is an -"element." Upon each iteration, the closure is called, and the result is the -value of the accumulator on the next iteration. On the first iteration, the -base is the value of the accumulator. - -Okay, that's a bit confusing. Let's examine the values of all of these things -in this iterator: - -| base | accumulator | element | closure result | -|------|-------------|---------|----------------| -| 0 | 0 | 1 | 1 | -| 0 | 1 | 2 | 3 | -| 0 | 3 | 3 | 6 | - -We called `fold()` with these arguments: - -```{rust} -# range(1, 4) -.fold(0, |sum, x| sum + x); -``` - -So, `0` is our base, `sum` is our accumulator, and `x` is our element. On the -first iteration, we set `sum` to `0`, and `x` is the first element of `nums`, -`1`. We then add `sum` and `x`, which gives us `0 + 1 = 1`. On the second -iteration, that value becomes our accumulator, `sum`, and the element is -the second element of the array, `2`. `1 + 2 = 3`, and so that becomes -the value of the accumulator for the last iteration. On that iteration, -`x` is the last element, `3`, and `3 + 3 = 6`, which is our final -result for our sum. `1 + 2 + 3 = 6`, and that's the result we got. - -Whew. `fold` can be a bit strange the first few times you see it, but once it -clicks, you can use it all over the place. Any time you have a list of things, -and you want a single result, `fold` is appropriate. - -Consumers are important due to one additional property of iterators we haven't -talked about yet: laziness. Let's talk some more about iterators, and you'll -see why consumers matter. - -## Iterators - -As we've said before, an iterator is something that we can call the -`.next()` method on repeatedly, and it gives us a sequence of things. -Because you need to call the method, this means that iterators -are **lazy** and don't need to generate all of the values upfront. -This code, for example, does not actually generate the numbers -`1-100`, and just creates a value that represents the sequence: - -```{rust} -let nums = range(1, 100); -``` - -Since we didn't do anything with the range, it didn't generate the sequence. -Let's add the consumer: - -```{rust} -let nums = range(1, 100).collect::>(); -``` - -Now, `collect()` will require that `range()` give it some numbers, and so -it will do the work of generating the sequence. - -`range` is one of two basic iterators that you'll see. The other is `iter()`, -which you've used before. `iter()` can turn a vector into a simple iterator -that gives you each element in turn: - -```{rust} -let nums = [1, 2, 3]; - -for num in nums.iter() { - println!("{}", num); -} -``` - -These two basic iterators should serve you well. There are some more -advanced iterators, including ones that are infinite. Like `count`: - -```{rust} -std::iter::count(1, 5); -``` - -This iterator counts up from one, adding five each time. It will give -you a new integer every time, forever (well, technically, until it reaches the -maximum number representable by an `i32`). But since iterators are lazy, -that's okay! You probably don't want to use `collect()` on it, though... - -That's enough about iterators. Iterator adapters are the last concept -we need to talk about with regards to iterators. Let's get to it! - -## Iterator adapters - -"Iterator adapters" take an iterator and modify it somehow, producing -a new iterator. The simplest one is called `map`: - -```{rust,ignore} -range(1, 100).map(|x| x + 1); -``` - -`map` is called upon another iterator, and produces a new iterator where each -element reference has the closure it's been given as an argument called on it. -So this would give us the numbers from `2-100`. Well, almost! If you -compile the example, you'll get a warning: - -```text -warning: unused result which must be used: iterator adaptors are lazy and - do nothing unless consumed, #[warn(unused_must_use)] on by default - range(1, 100).map(|x| x + 1); - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -``` - -Laziness strikes again! That closure will never execute. This example -doesn't print any numbers: - -```{rust,ignore} -range(1, 100).map(|x| println!("{}", x)); -``` - -If you are trying to execute a closure on an iterator for its side effects, -just use `for` instead. - -There are tons of interesting iterator adapters. `take(n)` will return an -iterator over the next `n` elements of the original iterator, note that this -has no side effect on the original iterator. Let's try it out with our infinite -iterator from before, `count()`: - -```{rust} -for i in std::iter::count(1, 5).take(5) { - println!("{}", i); -} -``` - -This will print - -```text -1 -6 -11 -16 -21 -``` - -`filter()` is an adapter that takes a closure as an argument. This closure -returns `true` or `false`. The new iterator `filter()` produces -only the elements that that closure returns `true` for: - -```{rust} -for i in range(1, 100).filter(|&x| x % 2 == 0) { - println!("{}", i); -} -``` - -This will print all of the even numbers between one and a hundred. -(Note that because `filter` doesn't consume the elements that are -being iterated over, it is passed a reference to each element, and -thus the filter predicate uses the `&x` pattern to extract the integer -itself.) - -You can chain all three things together: start with an iterator, adapt it -a few times, and then consume the result. Check it out: - -```{rust} -range(1, 1000) - .filter(|&x| x % 2 == 0) - .filter(|&x| x % 3 == 0) - .take(5) - .collect::>(); -``` - -This will give you a vector containing `6`, `12`, `18`, `24`, and `30`. - -This is just a small taste of what iterators, iterator adapters, and consumers -can help you with. There are a number of really useful iterators, and you can -write your own as well. Iterators provide a safe, efficient way to manipulate -all kinds of lists. They're a little unusual at first, but if you play with -them, you'll get hooked. For a full list of the different iterators and -consumers, check out the [iterator module documentation](std/iter/index.html). - -# Generics - -Sometimes, when writing a function or data type, we may want it to work for -multiple types of arguments. For example, remember our `OptionalInt` type? - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} -``` - -If we wanted to also have an `OptionalFloat64`, we would need a new enum: - -```{rust} -enum OptionalFloat64 { - Valuef64(f64), - Missingf64, -} -``` - -Such repetition is unfortunate. Luckily, Rust has a feature that gives us a -better way: **generics**. Generics are called **parametric polymorphism** in -type theory, which means that they are types or functions that have multiple -forms over a given parameter ("parametric"). - -Let's see how generics help us escape `OptionalInt`. `Option` is already -provided in Rust's standard library and looks like this: - -```rust -enum Option { - Some(T), - None, -} -``` - -The `` part, which you've seen a few times before, indicates that this is a -generic data type. `T` is called a **type parameter**. When we create instances -of `Option`, we need to provide a concrete type in place of the type -parameter. For example, if we wanted something like our `OptionalInt`, we would -need to instantiate an `Option`. Inside the declaration of our enum, -wherever we see a `T`, we replace it with the type specified (or inferred by the -compiler). - -```{rust} -let x: Option = Some(5); -``` - -In this particular `Option`, `T` has the value of `i32`. On the right-hand side -of the binding, we do make a `Some(T)`, where `T` is `5`. Since that's an -`i32`, the two sides match, and Rust is happy. If they didn't match, we'd get an -error: - -```{rust,ignore} -let x: Option = Some(5); -// error: mismatched types: expected `core::option::Option`, -// found `core::option::Option` (expected f64, found i32) -``` - -That doesn't mean we can't make `Option`s that hold an `f64`! They just have to -match up: - -```{rust} -let x: Option = Some(5); -let y: Option = Some(5.0f64); -``` - -Generics don't have to only be generic over one type. Consider Rust's built-in -`Result` type: - -```{rust} -enum Result { - Ok(T), - Err(E), -} -``` - -This type is generic over _two_ types: `T` and `E`. By the way, the capital letters -can be any letter you'd like. We could define `Result` as: - -```{rust} -enum Result { - Ok(H), - Err(N), -} -``` - -Convention says that the first generic parameter should be `T`, for "type," and -that we use `E` for "error." - -The `Result` type is intended to be used to return the result of a -computation and to have the ability to return an error if it didn't work -out. Here's an example: - -```{rust} -let x: Result = Ok(2.3f64); -let y: Result = Err("There was an error.".to_string()); -``` - -This particular `Result` will return an `f64` upon success and a `String` if -there's a failure. Let's write a function that uses `Result`: - -```{rust} -fn inverse(x: f64) -> Result { - if x == 0.0f64 { return Err("x cannot be zero!".to_string()); } - - Ok(1.0f64 / x) -} -``` - -We want to indicate that `inverse(0.0f64)` is undefined or is an erroneous usage -of the function, so we check to make sure that we weren't passed zero. If we -were, we return an `Err` with a message. If it's okay, we return an `Ok` with -the answer. - -Why does this matter? Well, remember how `match` does exhaustive matches? -Here's how this function gets used: - -```{rust} -# fn inverse(x: f64) -> Result { -# if x == 0.0f64 { return Err("x cannot be zero!".to_string()); } -# Ok(1.0f64 / x) -# } -let x = inverse(25.0f64); - -match x { - Ok(x) => println!("The inverse of 25 is {}", x), - Err(msg) => println!("Error: {}", msg), -} -``` - -The `match` enforces that we handle the `Err` case. In addition, because the -answer is wrapped up in an `Ok`, we can't just use the result without doing -the match: - -```{rust,ignore} -let x = inverse(25.0f64); -println!("{}", x + 2.0f64); // error: binary operation `+` cannot be applied - // to type `core::result::Result` -``` - -This function is great, but there's one other problem: it only works for 64 bit -floating point values. If we wanted to handle 32 bit floating point values we'd -have to write this: - -```{rust} -fn inverse32(x: f32) -> Result { - if x == 0.0f32 { return Err("x cannot be zero!".to_string()); } - - Ok(1.0f32 / x) -} -``` - -What we need is a **generic function**. We can do that with Rust! However, it -won't _quite_ work yet. We need to talk about syntax. A first attempt at a -generic version of `inverse` might look something like this: - -```{rust,ignore} -fn inverse(x: T) -> Result { - if x == 0.0 { return Err("x cannot be zero!".to_string()); } - - Ok(1.0 / x) -} -``` - -Just like how we had `Option`, we use a similar syntax for `inverse`. We -can then use `T` inside the rest of the signature: `x` has type `T`, and half of -the `Result` has type `T`. However, if we try to compile that example, we'll get -some errors: - -```text -error: binary operation `==` cannot be applied to type `T` - if x == 0.0 { return Err("x cannot be zero!".to_string()); } - ^~~~~~~~ -error: mismatched types: expected `_`, found `T` (expected floating-point variable, found type parameter) - Ok(1.0 / x) - ^ -error: mismatched types: expected `core::result::Result`, found `core::result::Result<_, _>` (expected type parameter, found floating-point variable) - Ok(1.0 / x) - ^~~~~~~~~~~ -``` - -The problem is that `T` is unconstrained: it can be _any_ type. It could be a -`String`, and the expression `1.0 / x` has no meaning if `x` is a `String`. It -may be a type that doesn't implement `==`, and the first line would be -wrong. What do we do? - -To fix this example, we need to learn about another Rust feature: **traits**. - -# Traits - -Our discussion of **traits** begins with the `impl` keyword. We used it before -to specify methods. - -```{rust} -struct Circle { - x: f64, - y: f64, - radius: f64, -} - -impl Circle { - fn area(&self) -> f64 { - std::f64::consts::PI * (self.radius * self.radius) - } -} -``` - -We define a trait in terms of its methods. We then `impl` a trait `for` a type -(or many types). - -```{rust} -struct Circle { - x: f64, - y: f64, - radius: f64, -} - -trait HasArea { - fn area(&self) -> f64; -} - -impl HasArea for Circle { - fn area(&self) -> f64 { - std::f64::consts::PI * (self.radius * self.radius) - } -} -``` - -The `trait` block defines only type signatures. When we `impl` a trait, we use -`impl Trait for Item`, rather than just `impl Item`. - -The first of the three errors we got with our generic `inverse` function was -this: - -```text -error: binary operation `==` cannot be applied to type `T` -``` - -We can use traits to constrain generic type parameters. Consider this function, -which does not compile, and gives us a similar error: - -```{rust,ignore} -fn print_area(shape: T) { - println!("This shape has an area of {}", shape.area()); -} -``` - -Rust complains: - -```text -error: type `T` does not implement any method in scope named `area` -``` - -Because `T` can be any type, we can't be sure that it implements the `area` -method. But we can add a **trait constraint** to our generic `T`, ensuring that -we can only compile the function if it's called with types which `impl` the -`HasArea` trait: - -```{rust} -# trait HasArea { -# fn area(&self) -> f64; -# } -fn print_area(shape: T) { - println!("This shape has an area of {}", shape.area()); -} -``` - -The syntax `` means "any type that implements the HasArea trait." -Because traits define method signatures, we can be sure that any type which -implements `HasArea` will have an `area` method. - -Here's an extended example of how this works: - -```{rust} -trait HasArea { - fn area(&self) -> f64; -} - -struct Circle { - x: f64, - y: f64, - radius: f64, -} - -impl HasArea for Circle { - fn area(&self) -> f64 { - std::f64::consts::PI * (self.radius * self.radius) - } -} - -struct Square { - x: f64, - y: f64, - side: f64, -} - -impl HasArea for Square { - fn area(&self) -> f64 { - self.side * self.side - } -} - -fn print_area(shape: T) { - println!("This shape has an area of {}", shape.area()); -} - -fn main() { - let c = Circle { - x: 0.0f64, - y: 0.0f64, - radius: 1.0f64, - }; - - let s = Square { - x: 0.0f64, - y: 0.0f64, - side: 1.0f64, - }; - - print_area(c); - print_area(s); -} -``` - -This program outputs: - -```text -This shape has an area of 3.141593 -This shape has an area of 1 -``` - -As you can see, `print_area` is now generic, but also ensures that we -have passed in the correct types. If we pass in an incorrect type: - -```{rust,ignore} -print_area(5); -``` - -We get a compile-time error: - -```text -error: failed to find an implementation of trait main::HasArea for i32 -``` - -So far, we've only added trait implementations to structs, but you can -implement a trait for any type. So technically, we _could_ implement -`HasArea` for `i32`: - -```{rust} -trait HasArea { - fn area(&self) -> f64; -} - -impl HasArea for i32 { - fn area(&self) -> f64 { - println!("this is silly"); - - *self as f64 - } -} - -5.area(); -``` - -It is considered poor style to implement methods on such primitive types, even -though it is possible. - -## Scoped Method Resolution and Orphan `impl`s - -There are two restrictions for implementing traits that prevent this from -getting out of hand. - -1. **Scope-based Method Resolution**: Traits must be `use`d in any scope where - you wish to use the trait's methods -2. **No Orphan `impl`s**: Either the trait or the type you're writing the `impl` - for must be inside your crate. - -If we organize our crate differently by using modules, we'll need to ensure both -of the conditions are satisfied. Don't worry, you can lean on the compiler since -it won't let you get away with violating them. - -```{rust} -use shapes::HasArea; // satisfies #1 - -mod shapes { - use std::f64::consts; - - pub trait HasArea { - fn area(&self) -> f64; - } - - pub struct Circle { - pub x: f64, - pub y: f64, - pub radius: f64, - } - - impl HasArea for Circle { - fn area(&self) -> f64 { - consts::PI * (self.radius * self.radius) - } - } -} - -fn main() { - // use shapes::HasArea; // This would satisfy #1, too - let c = shapes::Circle { - x: 0.0f64, - y: 0.0f64, - radius: 1.0f64, - }; - - println!("{}", c.area()); -} -``` - -Requiring us to `use` traits whose methods we want means that even if someone -does something bad like add methods to `i32`, it won't affect us, unless you -`use` that trait. - -The second condition allows us to `impl` built-in `trait`s for types we define, -or allows us to `impl` our own `trait`s for built-in types, but restricts us -from mixing and matching third party or built-in `impl`s with third party or -built-in types. - -We could `impl` the `HasArea` trait for `i32`, because `HasArea` is in our -crate. But if we tried to implement `Float`, a standard library `trait`, for -`i32`, we could not, because neither the `trait` nor the `type` are in our -crate. - -## Monomorphization - -One last thing about generics and traits: the compiler performs -**monomorphization** on generic functions so they are statically dispatched. To -see what that means, let's take a look at `print_area` again: - -```{rust,ignore} -fn print_area(shape: T) { - println!("This shape has an area of {}", shape.area()); -} - -fn main() { - let c = Circle { ... }; - - let s = Square { ... }; - - print_area(c); - print_area(s); -} -``` - -Because we have called `print_area` with two different types in place of its -type paramater `T`, Rust will generate two versions of the function with the -appropriate concrete types, replacing the call sites with calls to the concrete -implementations. In other words, the compiler will actually compile something -more like this: - -```{rust,ignore} -fn __print_area_circle(shape: Circle) { - println!("This shape has an area of {}", shape.area()); -} - -fn __print_area_square(shape: Square) { - println!("This shape has an area of {}", shape.area()); -} - -fn main() { - let c = Circle { ... }; - - let s = Square { ... }; - - __print_area_circle(c); - __print_area_square(s); -} -``` - -These names are for illustration; the compiler will generate its own cryptic -names for internal uses. The point is that there is no runtime overhead of -deciding which version to call. The function to be called is determined -statically, at compile time. Thus, generic functions are **statically -dispatched**. The downside is that we have two similar functions, so our binary -is larger. - -# Threads - -Concurrency and parallelism are topics that are of increasing interest to a -broad subsection of software developers. Modern computers are often multi-core, -to the point that even embedded devices like cell phones have more than one -processor. Rust's semantics lend themselves very nicely to solving a number of -issues that programmers have with concurrency. Many concurrency errors that are -runtime errors in other languages are compile-time errors in Rust. - -Rust's concurrency primitive is called a **thread**. It's worth noting that -threads are implemented as a library, and not part of the language. This means -that in the future, other concurrency libraries can be written for Rust to help -in specific scenarios. Here's an example of creating a thread: - -```{rust,ignore} -spawn(move || { - println!("Hello from a thread!"); -}); -``` - -The `spawn` function takes a closure as an argument, and runs that -closure in a new thread. Typically, you will want to use a moving -closure, so that the closure takes ownership of any variables that it -touches. This implies that those variables are not usable from the -parent thread after the child thread is spawned: - -```{rust,ignore} -let mut x = vec![1, 2, 3]; - -spawn(move || { - println!("The value of x[0] is: {}", x[0]); -}); - -println!("The value of x[0] is: {}", x[0]); // error: use of moved value: `x` -``` - -`x` is now owned by the closure, and so we can't use it anymore. Many -other languages would let us do this, but it's not safe to do -so. Rust's borrow checker catches the error. - -If threads were only able to capture these values, they wouldn't be very useful. -Luckily, threads can communicate with each other through **channel**s. Channels -work like this: - -```{rust,ignore} -let (tx, rx) = channel(); - -spawn(move || { - tx.send("Hello from a thread!".to_string()); -}); - -let message = rx.recv(); -println!("{}", message); -``` - -The `channel()` function returns two endpoints: a `Receiver` and a -`Sender`. You can use the `.send()` method on the `Sender` end, and -receive the message on the `Receiver` side with the `recv()` method. This -method blocks until it gets a message. There's a similar method, `.try_recv()`, -which returns an `Result` and does not block. - -If you want to send messages to the thread as well, create two channels! - -```{rust,ignore} -let (tx1, rx1) = channel(); -let (tx2, rx2) = channel(); - -spawn(move || { - tx1.send("Hello from a thread!".to_string()); - let message = rx2.recv(); - println!("{}", message); -}); - -let message = rx1.recv(); -println!("{}", message); - -tx2.send("Goodbye from main!".to_string()); -``` - -The closure has one sending end and one receiving end, and the main thread has -one of each as well. Now they can talk back and forth in whatever way they -wish. - -Notice as well that because `Sender` and `Receiver` are generic, while you can -pass any kind of information through the channel, the ends are strongly typed. -If you try to pass a string, and then an integer, Rust will complain. - -## Futures - -With these basic primitives, many different concurrency patterns can be -developed. Rust includes some of these types in its standard library. For -example, if you wish to compute some value in the background, `Future` is -a useful thing to use: - -```{rust} -# #![allow(deprecated)] -use std::sync::Future; - -let mut delayed_value = Future::spawn(move || { - // just return anything for examples' sake - - 12345 -}); -println!("value = {}", delayed_value.get()); -``` - -Calling `Future::spawn` works just like `spawn()`: it takes a -closure. In this case, though, you don't need to mess with the -channel: just have the closure return the value. - -`Future::spawn` will return a value which we can bind with `let`. It needs -to be mutable, because once the value is computed, it saves a copy of the -value, and if it were immutable, it couldn't update itself. - -The future will go on processing in the background, and when we need -the final value, we can call `get()` on it. This will block until the -result is done, but if it's finished computing in the background, -we'll just get the value immediately. - -## Success and failure - -Threads don't always succeed, they can also panic. A thread that wishes to panic -can call the `panic!` macro, passing a message: - -```{rust,ignore} -spawn(move || { - panic!("Nope."); -}); -``` - -If a thread panics, it is not possible for it to recover. However, it can -notify other thread that it has panicked. We can do this with `thread::try`: - -```{rust,ignore} -use std::thread; -use std::rand; - -let result = thread::try(move || { - if rand::random() { - println!("OK"); - } else { - panic!("oops!"); - } -}); -``` - -This thread will randomly panic or succeed. `thread::try` returns a `Result` -type, so we can handle the response like any other computation that may -fail. - -# Macros - -One of Rust's most advanced features is its system of **macro**s. While -functions allow you to provide abstractions over values and operations, macros -allow you to provide abstractions over syntax. Do you wish Rust had the ability -to do something that it can't currently do? You may be able to write a macro -to extend Rust's capabilities. - -You've already used one macro extensively: `println!`. When we invoke -a Rust macro, we need to use the exclamation mark (`!`). There are two reasons -why this is so: the first is that it makes it clear when you're using a -macro. The second is that macros allow for flexible syntax, and so Rust must -be able to tell where a macro starts and ends. The `!(...)` helps with this. - -Let's talk some more about `println!`. We could have implemented `println!` as -a function, but it would be worse. Why? Well, what macros allow you to do -is write code that generates more code. So when we call `println!` like this: - -```{rust} -let x = 5; -println!("x is: {}", x); -``` - -The `println!` macro does a few things: - -1. It parses the string to find any `{}`s. -2. It checks that the number of `{}`s matches the number of other arguments. -3. It generates a bunch of Rust code, taking this in mind. - -What this means is that you get type checking at compile time, because -Rust will generate code that takes all of the types into account. If -`println!` was a function, it could still do this type checking, but it -would happen at run time rather than compile time. - -We can check this out using a special flag to `rustc`. Put this code in a file -called `print.rs`: - -```{rust} -fn main() { - let x = 5; - println!("x is: {}", x); -} -``` - -You can have the macros expanded like this: `rustc --pretty=expanded print.rs`, which will -give us this huge result: - -```{rust,ignore} -#![feature(phase)] -#![no_std] -#![feature(globs)] -#[phase(plugin, link)] -extern crate "std" as std; -extern crate "native" as rt; -#[prelude_import] -use std::prelude::*; -fn main() { - let x = 5; - match (&x,) { - (__arg0,) => { - #[inline] - #[allow(dead_code)] - static __STATIC_FMTSTR: [&'static str, ..1u] = ["x is: "]; - let __args_vec = - &[::std::fmt::argument(::std::fmt::secret_show, __arg0)]; - let __args = - unsafe { - ::std::fmt::Arguments::new(__STATIC_FMTSTR, __args_vec) - }; - ::std::io::stdio::println_args(&__args) - } - }; -} -``` - -Whew! This isn't too terrible. You can see that we still `let x = 5`, -but then things get a little bit hairy. Three more bindings get set: a -static format string, an argument vector, and the arguments. We then -invoke the `println_args` function with the generated arguments. - -This is the code that Rust actually compiles. You can see all of the extra -information that's here. We get all of the type safety and options that it -provides, but at compile time, and without needing to type all of this out. -This is how macros are powerful: without them you would need to type all of -this by hand to get a type-checked `println`. - -For more on macros, please consult [the Macros Guide](guide-macros.html). -Macros are a very advanced and still slightly experimental feature, but they don't -require a deep understanding to be called, since they look just like functions. The -Guide can help you if you want to write your own. - -# Unsafe - -Finally, there's one more Rust concept that you should be aware of: `unsafe`. -There are two circumstances where Rust's safety provisions don't work well. -The first is when interfacing with C code, and the second is when building -certain kinds of abstractions. - -Rust has support for [FFI](http://en.wikipedia.org/wiki/Foreign_function_interface) -(which you can read about in the [FFI Guide](guide-ffi.html)), but can't guarantee -that the C code will be safe. Therefore, Rust marks such functions with the `unsafe` -keyword, which indicates that the function may not behave properly. - -Second, if you'd like to create some sort of shared-memory data structure, Rust -won't allow it, because memory must be owned by a single owner. However, if -you're planning on making access to that shared memory safe – such as with a -mutex – _you_ know that it's safe, but Rust can't know. Writing an `unsafe` -block allows you to ask the compiler to trust you. In this case, the _internal_ -implementation of the mutex is considered unsafe, but the _external_ interface -we present is safe. This allows it to be effectively used in normal Rust, while -being able to implement functionality that the compiler can't double check for -us. - -Doesn't an escape hatch undermine the safety of the entire system? Well, if -Rust code segfaults, it _must_ be because of unsafe code somewhere. By -annotating exactly where that is, you have a significantly smaller area to -search. - -We haven't even talked about any examples here, and that's because I want to -emphasize that you should not be writing unsafe code unless you know exactly -what you're doing. The vast majority of Rust developers will only interact with -it when doing FFI, and advanced library authors may use it to build certain -kinds of abstraction. - -# Conclusion - -We covered a lot of ground here. When you've mastered everything in this Guide, -you will have a firm grasp of basic Rust development. There's a whole lot more -out there, we've just covered the surface. There's tons of topics that you can -dig deeper into, and we've built specialized guides for many of them. To learn -more, dig into the [full documentation index](index.html). - -Happy hacking! diff --git a/src/doc/index.md b/src/doc/index.md index 7f22c1eeb855f..25dcc10d89363 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -9,10 +9,11 @@ If you haven't seen Rust at all yet, the first thing you should read is the [30 minute intro](intro.html). It will give you an overview of the basic ideas of Rust at a high level. -Once you know you really want to learn Rust, the next step is reading [the -guide](guide.html). It is a lengthy explanation of Rust, its syntax, and its -concepts. Upon completing the guide, you'll be an intermediate Rust developer, -and will have a good grasp of the fundamental ideas behind Rust. +Once you know you really want to learn Rust, the next step is reading [The +Rust Programming Language](book/index.html). It is a lengthy explanation of +Rust, its syntax, and its concepts. Upon completing the book, you'll be an +intermediate Rust developer, and will have a good grasp of the fundamental +ideas behind Rust. # Community & Getting Help @@ -48,24 +49,6 @@ development of Rust itself is discussed. Rust does not have an exact specification, but an effort to describe as much of the language in as much detail as possible is in [the reference](reference.html). -# Guides - -Rust Guides are in-depth looks at a particular topic that's relevant to Rust -development. If you're trying to figure out how to do something, there may be -a guide that can help you out: - -* [Ownership](guide-ownership.html) -* [Strings](guide-strings.html) -* [Pointers](guide-pointers.html) -* [Crates and modules](guide-crates.html) -* [Threads and Communication](guide-tasks.html) -* [Error Handling](guide-error-handling.html) -* [Foreign Function Interface](guide-ffi.html) -* [Writing Unsafe and Low-Level Code](guide-unsafe.html) -* [Macros](guide-macros.html) -* [Testing](guide-testing.html) -* [Compiler Plugins](guide-plugin.html) - # Tools Rust's still a young language, so there isn't a ton of tooling yet, but the diff --git a/src/doc/intro.md b/src/doc/intro.md index ffe33f41bc733..cb28586d103ec 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -7,8 +7,8 @@ This introduction will give you a rough idea of what Rust is like, eliding many details. It does not require prior experience with systems programming, but you may find the syntax easier if you've used a 'curly brace' programming language before, like C or JavaScript. The concepts are more important than the syntax, -so don't worry if you don't get every last detail: you can read [the -Guide](guide.html) to get a more complete explanation. +so don't worry if you don't get every last detail: you can read [The +Rust Programming Language](book/index.html) to get a more complete explanation. Because this is about high-level concepts, you don't need to actually install Rust to follow along. If you'd like to anyway, check out [the @@ -587,5 +587,6 @@ the type system helps you find bugs, how Rust can help you write correct concurrent code, and how you don't have to pay a speed cost for much of this safety. -To continue your Rustic education, read [the guide](guide.html) for a more -in-depth exploration of Rust's syntax and concepts. +To continue your Rustic education, read [The Rust Programming +Language](book/index.html) for a more in-depth exploration of Rust's syntax and +concepts. diff --git a/src/doc/reference.md b/src/doc/reference.md index 804b6b9f63cf0..2486466c8696d 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -14,7 +14,7 @@ provides three kinds of material: influenced the design. This document does not serve as an introduction to the language. Background -familiarity with the language is assumed. A separate [guide] is available to +familiarity with the language is assumed. A separate [book] is available to help acquire such background familiarity. This document also does not serve as a reference to the [standard] library @@ -23,7 +23,7 @@ separately by extracting documentation attributes from their source code. Many of the features that one might expect to be language features are library features in Rust, so what you're looking for may be there, not here. -[guide]: guide.html +[book]: book/index.html [standard]: std/index.html # Notation @@ -647,10 +647,10 @@ All of the above extensions are expressions with values. Users of `rustc` can define new syntax extensions in two ways: -* [Compiler plugins](guide-plugin.html#syntax-extensions) can include arbitrary +* [Compiler plugins](book/syntax-extensions.html) can include arbitrary Rust code that manipulates syntax trees at compile time. -* [Macros](guide-macros.html) define new syntax in a higher-level, +* [Macros](book/macros.html) define new syntax in a higher-level, declarative way. ## Macros @@ -2076,7 +2076,7 @@ On `struct`s: list of names `#[macro_use(foo, bar)]` restricts the import to just those macros named. The `extern crate` must appear at the crate root, not inside `mod`, which ensures proper function of the [`$crate` macro - variable](guide-macros.html#the-variable-$crate). + variable](book/macros.html#the-variable-$crate). - `macro_reexport` on an `extern crate` — re-export the named macros. @@ -2090,8 +2090,9 @@ On `struct`s: - `no_link` on an `extern crate` — even if we load this crate for macros or compiler plugins, don't link it into the output. -See the [macros guide](guide-macros.html#scoping-and-macro-import/export) for -more information on macro scope. +See the [macros section of the +book](book/macros.html#scoping-and-macro-import/export) for more information on +macro scope. ### Miscellaneous attributes @@ -2193,7 +2194,7 @@ For any lint check `C`: The lint checks supported by the compiler can be found via `rustc -W help`, along with their default settings. [Compiler -plugins](guide-plugin.html#lint-plugins) can provide additional lint checks. +plugins](book/plugin.html#lint-plugins) can provide additional lint checks. ```{.ignore} mod m1 { @@ -4227,7 +4228,7 @@ communication facilities. The Rust compiler supports various methods to link crates together both statically and dynamically. This section will explore the various methods to link Rust crates together, and more information about native libraries can be -found in the [ffi guide][ffi]. +found in the [ffi section of the book][ffi]. In one session of compilation, the compiler can generate multiple artifacts through the usage of either command line flags or the `crate_type` attribute. @@ -4359,5 +4360,5 @@ that have since been removed): * [Unicode Annex #31](http://www.unicode.org/reports/tr31/): identifier and pattern syntax -[ffi]: guide-ffi.html -[plugin]: guide-plugin.html +[ffi]: book/ffi.html +[plugin]: book/plugin.html diff --git a/src/doc/trpl/README.md b/src/doc/trpl/README.md new file mode 100644 index 0000000000000..0202e873b3644 --- /dev/null +++ b/src/doc/trpl/README.md @@ -0,0 +1,35 @@ +% The Rust Programming Language + +Welcome! This book will teach you about [the Rust Programming +Language](http://www.rust-lang.org/). Rust is a modern systems programming +language focusing on safety and speed. It accomplishes these goals by being +memory safe without using garbage collection. + +"The Rust Programming Language" is split into three sections, which you can +navigate through the menu on the left. + +## Basics + +This section is a linear introduction to the basic syntax and semantics of +Rust. It has individual sections on each part of Rust's syntax, and cumulates +in a small project: a guessing game. + +After reading "Basics," you will have a good foundation to learn more about +Rust, and can write very simple programs. + +## Intermediate + +This section contains individual chapters, which are self-contained. They focus +on specific topics, and can be read in any order. + +After reading "Intermediate," you will have a solid understanding of Rust, +and will be able to understand most Rust code and write more complex programs. + +## Advanced + +In a similar fashion to "Intermediate," this setion is full of individual, +deep-dive chapters, which stand alone and can be read in any order. These +chapters focus on the most complex features, as well as some things that +are only available in upcoming versions of Rust. + +After reading "Advanced," you'll be a Rust expert! diff --git a/src/doc/trpl/SUMMARY.md b/src/doc/trpl/SUMMARY.md new file mode 100644 index 0000000000000..0f1bce389df9a --- /dev/null +++ b/src/doc/trpl/SUMMARY.md @@ -0,0 +1,35 @@ +# Summary + +* [I: The Basics](src/basic.md) + * [Installing Rust](src/installing-rust.md) + * [Hello, world!](src/hello-world.md) + * [Hello, Cargo!](src/hello-cargo.md) + * [Variable Bindings](src/variable-bindings.md) + * [If](src/if.md) + * [Functions](src/functions.md) + * [Comments](src/comments.md) + * [Compound Data Types](src/compound-data-types.md) + * [Match](src/match.md) + * [Looping](src/looping.md) + * [Strings](src/strings.md) + * [Arrays, Vectors, and Slices](src/arrays-vectors-and-slices.md) + * [Standard Input](src/standard-input.md) + * [Guessing Game](src/guessing-game.md) +* [II: Intermedite Rust](src/intermediate.md) + * [Crates and Modules](src/crates-and-modules.md) + * [Testing](src/testing.md) + * [Pointers](src/pointers.md) + * [Patterns](src/patterns.md) + * [Method Syntax](src/method-syntax.md) + * [Closures](src/closures.md) + * [Iterators](src/iterators.md) + * [Generics](src/generics.md) + * [Traits](src/traits.md) + * [Tasks](src/tasks.md) + * [Error Handling](src/error-handling.md) +* [III: Advanced Topics](src/advanced.md) + * [FFI](src/ffi.md) + * [Unsafe Code](src/unsafe.md) + * [Macros](src/macros.md) + * [Compiler Plugins](src/plugins.md) +* [Conclusion](src/conclusion.md) diff --git a/src/doc/trpl/rust-book.css b/src/doc/trpl/rust-book.css new file mode 100644 index 0000000000000..3d08de40f55aa --- /dev/null +++ b/src/doc/trpl/rust-book.css @@ -0,0 +1,59 @@ + +@import url("//static.rust-lang.org/doc/master/rust.css"); + +body { + max-width:none; +} + +#toc { + position: absolute; + left: 0px; + top: 0px; + bottom: 0px; + width: 250px; + overflow-y: auto; + border-right: 1px solid rgba(0, 0, 0, 0.07); + padding: 10px 10px; + font-size: 16px; + background: none repeat scroll 0% 0% #FFF; + box-sizing: border-box; +} + +#page-wrapper { + position: absolute; + overflow-y: auto; + left: 260px; + right: 0px; + top: 0px; + bottom: 0px; + box-sizing: border-box; + background: none repeat scroll 0% 0% #FFF; +} + +#page { + margin-left: auto; + margin-right:auto; + width: 750px; +} + +.chapter { + list-style: none outside none; + padding-left: 0px; + line-height: 30px; +} + +.section { + list-style: none outside none; + padding-left: 20px; + line-height: 30px; +} + +.section li { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + +.chapter li a { + color: #000000; +} diff --git a/src/doc/trpl/src/advanced.md b/src/doc/trpl/src/advanced.md new file mode 100644 index 0000000000000..138db523b9a21 --- /dev/null +++ b/src/doc/trpl/src/advanced.md @@ -0,0 +1,8 @@ +% Advanced + +In a similar fashion to "Intermediate," this setion is full of individual, +deep-dive chapters, which stand alone and can be read in any order. These +chapters focus on the most complex features, as well as some things that +are only available in upcoming versions of Rust. + +After reading "Advanced," you'll be a Rust expert! diff --git a/src/doc/trpl/src/arrays-vectors-and-slices.md b/src/doc/trpl/src/arrays-vectors-and-slices.md new file mode 100644 index 0000000000000..68fc73222fd2b --- /dev/null +++ b/src/doc/trpl/src/arrays-vectors-and-slices.md @@ -0,0 +1,99 @@ +# Arrays, Vectors, and Slices + +Like many programming languages, Rust has list types to represent a sequence of +things. The most basic is the **array**, a fixed-size list of elements of the +same type. By default, arrays are immutable. + +```{rust} +let a = [1, 2, 3]; // a: [i32; 3] +let mut m = [1, 2, 3]; // mut m: [i32; 3] +``` + +There's a shorthand for initializing each element of an array to the same +value. In this example, each element of `a` will be initialized to `0`: + +```{rust} +let a = [0; 20]; // a: [i32; 20] +``` + +Arrays have type `[T; N]`. We'll talk about this `T` notation later, when we +cover generics. + +You can get the number of elements in an array `a` with `a.len()`, and use +`a.iter()` to iterate over them with a for loop. This code will print each +number in order: + +```{rust} +let a = [1, 2, 3]; + +println!("a has {} elements", a.len()); +for e in a.iter() { + println!("{}", e); +} +``` + +You can access a particular element of an array with **subscript notation**: + +```{rust} +let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3] + +println!("The second name is: {}", names[1]); +``` + +Subscripts start at zero, like in most programming languages, so the first name +is `names[0]` and the second name is `names[1]`. The above example prints +`The second name is: Brian`. If you try to use a subscript that is not in the +array, you will get an error: array access is bounds-checked at run-time. Such +errant access is the source of many bugs in other systems programming +languages. + +A **vector** is a dynamic or "growable" array, implemented as the standard +library type [`Vec`](std/vec/) (we'll talk about what the `` means +later). Vectors are to arrays what `String` is to `&str`. You can create them +with the `vec!` macro: + +```{rust} +let v = vec![1, 2, 3]; // v: Vec +``` + +(Notice that unlike the `println!` macro we've used in the past, we use square +brackets `[]` with `vec!`. Rust allows you to use either in either situation, +this is just convention.) + +You can get the length of, iterate over, and subscript vectors just like +arrays. In addition, (mutable) vectors can grow automatically: + +```{rust} +let mut nums = vec![1, 2, 3]; // mut nums: Vec + +nums.push(4); + +println!("The length of nums is now {}", nums.len()); // Prints 4 +``` + +Vectors have many more useful methods. + +A **slice** is a reference to (or "view" into) an array. They are useful for +allowing safe, efficient access to a portion of an array without copying. For +example, you might want to reference just one line of a file read into memory. +By nature, a slice is not created directly, but from an existing variable. +Slices have a length, can be mutable or not, and in many ways behave like +arrays: + +```{rust} +let a = [0, 1, 2, 3, 4]; +let middle = a.slice(1, 4); // A slice of a: just the elements [1,2,3] + +for e in middle.iter() { + println!("{}", e); // Prints 1, 2, 3 +} +``` + +You can also take a slice of a vector, `String`, or `&str`, because they are +backed by arrays. Slices have type `&[T]`, which we'll talk about when we cover +generics. + +We have now learned all of the most basic Rust concepts. We're ready to start +building our guessing game, we just need to know one last thing: how to get +input from the keyboard. You can't have a guessing game without the ability to +guess! diff --git a/src/doc/trpl/src/basic.md b/src/doc/trpl/src/basic.md new file mode 100644 index 0000000000000..087121d0e7dc3 --- /dev/null +++ b/src/doc/trpl/src/basic.md @@ -0,0 +1,8 @@ +% Basics + +This section is a linear introduction to the basic syntax and semantics of +Rust. It has individual sections on each part of Rust's syntax, and cumulates +in a small project: a guessing game. + +After reading "Basics," you will have a good foundation to learn more about +Rust, and can write very simple programs. diff --git a/src/doc/trpl/src/closures.md b/src/doc/trpl/src/closures.md new file mode 100644 index 0000000000000..79ae28e1b911f --- /dev/null +++ b/src/doc/trpl/src/closures.md @@ -0,0 +1,185 @@ +# Closures + +So far, we've made lots of functions in Rust, but we've given them all names. +Rust also allows us to create anonymous functions. Rust's anonymous +functions are called **closure**s. By themselves, closures aren't all that +interesting, but when you combine them with functions that take closures as +arguments, really powerful things are possible. + +Let's make a closure: + +```{rust} +let add_one = |&: x| { 1 + x }; + +println!("The sum of 5 plus 1 is {}.", add_one(5)); +``` + +We create a closure using the `|...| { ... }` syntax, and then we create a +binding so we can use it later. Note that we call the function using the +binding name and two parentheses, just like we would for a named function. + +Let's compare syntax. The two are pretty close: + +```{rust} +let add_one = |&: x: i32| -> i32 { 1 + x }; +fn add_one (x: i32) -> i32 { 1 + x } +``` + +As you may have noticed, closures infer their argument and return types, so you +don't need to declare one. This is different from named functions, which +default to returning unit (`()`). + +There's one big difference between a closure and named functions, and it's in +the name: a closure "closes over its environment." What does that mean? It means +this: + +```{rust} +fn main() { + let x: i32 = 5; + + let printer = |&:| { println!("x is: {}", x); }; + + printer(); // prints "x is: 5" +} +``` + +The `||` syntax means this is an anonymous closure that takes no arguments. +Without it, we'd just have a block of code in `{}`s. + +In other words, a closure has access to variables in the scope where it's +defined. The closure borrows any variables it uses, so this will error: + +```{rust,ignore} +fn main() { + let mut x = 5; + + let printer = |&:| { println!("x is: {}", x); }; + + x = 6; // error: cannot assign to `x` because it is borrowed +} +``` + +## Moving closures + +Rust has a second type of closure, called a **moving closure**. Moving +closures are indicated using the `move` keyword (e.g., `move || x * +x`). The difference between a moving closure and an ordinary closure +is that a moving closure always takes ownership of all variables that +it uses. Ordinary closures, in contrast, just create a reference into +the enclosing stack frame. Moving closures are most useful with Rust's +concurrency features, and so we'll just leave it at this for +now. We'll talk about them more in the "Threads" section of the guide. + +## Accepting closures as arguments + +Closures are most useful as an argument to another function. Here's an example: + +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { + f(x) + f(x) +} + +fn main() { + let square = |&: x: i32| { x * x }; + + twice(5, square); // evaluates to 50 +} +``` + +Let's break the example down, starting with `main`: + +```{rust} +let square = |&: x: i32| { x * x }; +``` + +We've seen this before. We make a closure that takes an integer, and returns +its square. + +```{rust} +# fn twice i32>(x: i32, f: F) -> i32 { f(x) + f(x) } +# let square = |&: x: i32| { x * x }; +twice(5, square); // evaluates to 50 +``` + +This line is more interesting. Here, we call our function, `twice`, and we pass +it two arguments: an integer, `5`, and our closure, `square`. This is just like +passing any other two variable bindings to a function, but if you've never +worked with closures before, it can seem a little complex. Just think: "I'm +passing two variables: one is an i32, and one is a function." + +Next, let's look at how `twice` is defined: + +```{rust,ignore} +fn twice(x: i32, f: |i32| -> i32) -> i32 { +``` + +`twice` takes two arguments, `x` and `f`. That's why we called it with two +arguments. `x` is an `i32`, we've done that a ton of times. `f` is a function, +though, and that function takes an `i32` and returns an `i32`. Notice +how the `|i32| -> i32` syntax looks a lot like our definition of `square` +above, if we added the return type in: + +```{rust} +let square = |&: x: i32| -> i32 { x * x }; +// |i32| -> i32 +``` + +This function takes an `i32` and returns an `i32`. + +This is the most complicated function signature we've seen yet! Give it a read +a few times until you can see how it works. It takes a teeny bit of practice, and +then it's easy. + +Finally, `twice` returns an `i32` as well. + +Okay, let's look at the body of `twice`: + +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { + f(x) + f(x) +} +``` + +Since our closure is named `f`, we can call it just like we called our closures +before, and we pass in our `x` argument to each one, hence the name `twice`. + +If you do the math, `(5 * 5) + (5 * 5) == 50`, so that's the output we get. + +Play around with this concept until you're comfortable with it. Rust's standard +library uses lots of closures where appropriate, so you'll be using +this technique a lot. + +If we didn't want to give `square` a name, we could just define it inline. +This example is the same as the previous one: + +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { + f(x) + f(x) +} + +fn main() { + twice(5, |x: i32| { x * x }); // evaluates to 50 +} +``` + +A named function's name can be used wherever you'd use a closure. Another +way of writing the previous example: + +```{rust} +fn twice i32>(x: i32, f: F) -> i32 { + f(x) + f(x) +} + +fn square(x: i32) -> i32 { x * x } + +fn main() { + twice(5, square); // evaluates to 50 +} +``` + +Doing this is not particularly common, but it's useful every once in a while. + +That's all you need to get the hang of closures! Closures are a little bit +strange at first, but once you're used to them, you'll miss them +in other languages. Passing functions to other functions is +incredibly powerful, as you will see in the following chapter about iterators. diff --git a/src/doc/trpl/src/comments.md b/src/doc/trpl/src/comments.md new file mode 100644 index 0000000000000..cce6eacea0408 --- /dev/null +++ b/src/doc/trpl/src/comments.md @@ -0,0 +1,46 @@ +# Comments + +Now that we have some functions, it's a good idea to learn about comments. +Comments are notes that you leave to other programmers to help explain things +about your code. The compiler mostly ignores them. + +Rust has two kinds of comments that you should care about: **line comment**s +and **doc comment**s. + +```{rust} +// Line comments are anything after '//' and extend to the end of the line. + +let x = 5; // this is also a line comment. + +// If you have a long explanation for something, you can put line comments next +// to each other. Put a space between the // and your comment so that it's +// more readable. +``` + +The other kind of comment is a doc comment. Doc comments use `///` instead of +`//`, and support Markdown notation inside: + +```{rust} +/// `hello` is a function that prints a greeting that is personalized based on +/// the name given. +/// +/// # Arguments +/// +/// * `name` - The name of the person you'd like to greet. +/// +/// # Example +/// +/// ```rust +/// let name = "Steve"; +/// hello(name); // prints "Hello, Steve!" +/// ``` +fn hello(name: &str) { + println!("Hello, {}!", name); +} +``` + +When writing doc comments, adding sections for any arguments, return values, +and providing some examples of usage is very, very helpful. + +You can use the [`rustdoc`](rustdoc.html) tool to generate HTML documentation +from these doc comments. diff --git a/src/doc/trpl/src/compound-data-types.md b/src/doc/trpl/src/compound-data-types.md new file mode 100644 index 0000000000000..b9bb50973615c --- /dev/null +++ b/src/doc/trpl/src/compound-data-types.md @@ -0,0 +1,353 @@ +# Compound Data Types + +Rust, like many programming languages, has a number of different data types +that are built-in. You've already done some simple work with integers and +strings, but next, let's talk about some more complicated ways of storing data. + +## Tuples + +The first compound data type we're going to talk about are called **tuple**s. +Tuples are an ordered list of a fixed size. Like this: + +```rust +let x = (1, "hello"); +``` + +The parentheses and commas form this two-length tuple. Here's the same code, but +with the type annotated: + +```rust +let x: (i32, &str) = (1, "hello"); +``` + +As you can see, the type of a tuple looks just like the tuple, but with each +position having a type name rather than the value. Careful readers will also +note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple. +You haven't seen `&str` as a type before, and we'll discuss the details of +strings later. In systems programming languages, strings are a bit more complex +than in other languages. For now, just read `&str` as "a string slice," and +we'll learn more soon. + +You can access the fields in a tuple through a **destructuring let**. Here's +an example: + +```rust +let (x, y, z) = (1, 2, 3); + +println!("x is {}", x); +``` + +Remember before when I said the left-hand side of a `let` statement was more +powerful than just assigning a binding? Here we are. We can put a pattern on +the left-hand side of the `let`, and if it matches up to the right-hand side, +we can assign multiple bindings at once. In this case, `let` 'destructures,' +or 'breaks up,' the tuple, and assigns the bits to three bindings. + +This pattern is very powerful, and we'll see it repeated more later. + +There are also a few things you can do with a tuple as a whole, without +destructuring. You can assign one tuple into another, if they have the same +arity and contained types. + +```rust +let mut x = (1, 2); // x: (i32, i32) +let y = (2, 3); // y: (i32, i32) + +x = y; +``` + +You can also check for equality with `==`. Again, this will only compile if the +tuples have the same type. + +```rust +let x = (1, 2, 3); +let y = (2, 2, 4); + +if x == y { + println!("yes"); +} else { + println!("no"); +} +``` + +This will print `no`, because some of the values aren't equal. + +One other use of tuples is to return multiple values from a function: + +```rust +fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) } + +fn main() { + let (x, y) = next_two(5); + println!("x, y = {}, {}", x, y); +} +``` + +Even though Rust functions can only return one value, a tuple _is_ one value, +that happens to be made up of more than one value. You can also see in this example how you +can destructure a pattern returned by a function, as well. + +Tuples are a very simple data structure, and so are not often what you want. +Let's move on to their bigger sibling, structs. + +## Structs + +A struct is another form of a 'record type,' just like a tuple. There's a +difference: structs give each element that they contain a name, called a +'field' or a 'member.' Check it out: + +```rust +struct Point { + x: i32, + y: i32, +} + +fn main() { + let origin = Point { x: 0, y: 0 }; // origin: Point + + println!("The origin is at ({}, {})", origin.x, origin.y); +} +``` + +There's a lot going on here, so let's break it down. We declare a struct with +the `struct` keyword, and then with a name. By convention, structs begin with a +capital letter and are also camel cased: `PointInSpace`, not `Point_In_Space`. + +We can create an instance of our struct via `let`, as usual, but we use a `key: +value` style syntax to set each field. The order doesn't need to be the same as +in the original declaration. + +Finally, because fields have names, we can access the field through dot +notation: `origin.x`. + +The values in structs are immutable by default, like other bindings in Rust. +Use `mut` to make them mutable: + +```{rust} +struct Point { + x: i32, + y: i32, +} + +fn main() { + let mut point = Point { x: 0, y: 0 }; + + point.x = 5; + + println!("The point is at ({}, {})", point.x, point.y); +} +``` + +This will print `The point is at (5, 0)`. + +## Tuple Structs and Newtypes + +Rust has another data type that's like a hybrid between a tuple and a struct, +called a **tuple struct**. Tuple structs do have a name, but their fields +don't: + + +```{rust} +struct Color(i32, i32, i32); +struct Point(i32, i32, i32); +``` + +These two will not be equal, even if they have the same values: + +```{rust} +# struct Color(i32, i32, i32); +# struct Point(i32, i32, i32); +let black = Color(0, 0, 0); +let origin = Point(0, 0, 0); +``` + +It is almost always better to use a struct than a tuple struct. We would write +`Color` and `Point` like this instead: + +```{rust} +struct Color { + red: i32, + blue: i32, + green: i32, +} + +struct Point { + x: i32, + y: i32, + z: i32, +} +``` + +Now, we have actual names, rather than positions. Good names are important, +and with a struct, we have actual names. + +There _is_ one case when a tuple struct is very useful, though, and that's a +tuple struct with only one element. We call this a 'newtype,' because it lets +you create a new type that's a synonym for another one: + +```{rust} +struct Inches(i32); + +let length = Inches(10); + +let Inches(integer_length) = length; +println!("length is {} inches", integer_length); +``` + +As you can see here, you can extract the inner integer type through a +destructuring `let`. + +## Enums + +Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful +feature of Rust, and are used throughout the standard library. This is an enum +that is provided by the Rust standard library: + +```{rust} +enum Ordering { + Less, + Equal, + Greater, +} +``` + +An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given +time. + +Because `Ordering` is provided by the standard library, we can use the `use` +keyword to use it in our code. We'll learn more about `use` later, but it's +used to bring names into scope. + +Here's an example of how to use `Ordering`: + +```{rust} +use std::cmp::Ordering; + +fn cmp(a: i32, b: i32) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} + +fn main() { + let x = 5; + let y = 10; + + let ordering = cmp(x, y); // ordering: Ordering + + if ordering == Ordering::Less { + println!("less"); + } else if ordering == Ordering::Greater { + println!("greater"); + } else if ordering == Ordering::Equal { + println!("equal"); + } +} +``` + +There's a symbol here we haven't seen before: the double colon (`::`). +This is used to indicate a namespace. In this case, `Ordering` lives in +the `cmp` submodule of the `std` module. We'll talk more about modules +later in the guide. For now, all you need to know is that you can `use` +things from the standard library if you need them. + +Okay, let's talk about the actual code in the example. `cmp` is a function that +compares two things, and returns an `Ordering`. We return either +`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on if +the two values are greater, less, or equal. Note that each variant of the +`enum` is namespaced under the `enum` itself: it's `Ordering::Greater` not +`Greater`. + +The `ordering` variable has the type `Ordering`, and so contains one of the +three values. We can then do a bunch of `if`/`else` comparisons to check which +one it is. However, repeated `if`/`else` comparisons get quite tedious. Rust +has a feature that not only makes them nicer to read, but also makes sure that +you never miss a case. Before we get to that, though, let's talk about another +kind of enum: one with values. + +This enum has two variants, one of which has a value: + +```{rust} +enum OptionalInt { + Value(i32), + Missing, +} +``` + +This enum represents an `i32` that we may or may not have. In the `Missing` +case, we have no value, but in the `Value` case, we do. This enum is specific +to `i32`s, though. We can make it usable by any type, but we haven't quite +gotten there yet! + +You can also have any number of values in an enum: + +```{rust} +enum OptionalColor { + Color(i32, i32, i32), + Missing, +} +``` + +And you can also have something like this: + +```{rust} +enum StringResult { + StringOK(String), + ErrorReason(String), +} +``` +Where a `StringResult` is either a `StringResult::StringOK`, with the result of +a computation, or an `StringResult::ErrorReason` with a `String` explaining +what caused the computation to fail. These kinds of `enum`s are actually very +useful and are even part of the standard library. + +Here is an example of using our `StringResult`: + +```rust +enum StringResult { + StringOK(String), + ErrorReason(String), +} + +fn respond(greeting: &str) -> StringResult { + if greeting == "Hello" { + StringResult::StringOK("Good morning!".to_string()) + } else { + StringResult::ErrorReason("I didn't understand you!".to_string()) + } +} +``` + +That's a lot of typing! We can use the `use` keyword to make it shorter: + +```rust +use StringResult::StringOK; +use StringResult::ErrorReason; + +enum StringResult { + StringOK(String), + ErrorReason(String), +} + +# fn main() {} + +fn respond(greeting: &str) -> StringResult { + if greeting == "Hello" { + StringOK("Good morning!".to_string()) + } else { + ErrorReason("I didn't understand you!".to_string()) + } +} +``` + +`use` declarations must come before anything else, which looks a little strange in this example, +since we `use` the variants before we define them. Anyway, in the body of `respond`, we can just +say `StringOK` now, rather than the full `StringResult::StringOK`. Importing variants can be +convenient, but can also cause name conflicts, so do this with caution. It's considered good style +to rarely import variants for this reason. + +As you can see, `enum`s with values are quite a powerful tool for data representation, +and can be even more useful when they're generic across types. Before we get to generics, +though, let's talk about how to use them with pattern matching, a tool that will +let us deconstruct this sum type (the type theory term for enums) in a very elegant +way and avoid all these messy `if`/`else`s. diff --git a/src/doc/trpl/src/conclusion.md b/src/doc/trpl/src/conclusion.md new file mode 100644 index 0000000000000..0472787e948d9 --- /dev/null +++ b/src/doc/trpl/src/conclusion.md @@ -0,0 +1,10 @@ +% Conclusion + +We covered a lot of ground here. When you've mastered everything in this Guide, +you will have a firm grasp of basic Rust development. There's a whole lot more +out there, we've just covered the surface. There's tons of topics that you can +dig deeper into, and we've built specialized guides for many of them. To learn +more, dig into the [full documentation +index](index.html). + +Happy hacking! diff --git a/src/doc/guide-crates.md b/src/doc/trpl/src/crates-and-modules.md similarity index 100% rename from src/doc/guide-crates.md rename to src/doc/trpl/src/crates-and-modules.md diff --git a/src/doc/guide-error-handling.md b/src/doc/trpl/src/error-handling.md similarity index 100% rename from src/doc/guide-error-handling.md rename to src/doc/trpl/src/error-handling.md diff --git a/src/doc/guide-ffi.md b/src/doc/trpl/src/ffi.md similarity index 100% rename from src/doc/guide-ffi.md rename to src/doc/trpl/src/ffi.md diff --git a/src/doc/trpl/src/functions.md b/src/doc/trpl/src/functions.md new file mode 100644 index 0000000000000..0fa3c66af648c --- /dev/null +++ b/src/doc/trpl/src/functions.md @@ -0,0 +1,146 @@ +# Functions + +You've already seen one function so far, the `main` function: + +```{rust} +fn main() { +} +``` + +This is the simplest possible function declaration. As we mentioned before, +`fn` says 'this is a function,' followed by the name, some parentheses because +this function takes no arguments, and then some curly braces to indicate the +body. Here's a function named `foo`: + +```{rust} +fn foo() { +} +``` + +So, what about taking arguments? Here's a function that prints a number: + +```{rust} +fn print_number(x: i32) { + println!("x is: {}", x); +} +``` + +Here's a complete program that uses `print_number`: + +```{rust} +fn main() { + print_number(5); +} + +fn print_number(x: i32) { + println!("x is: {}", x); +} +``` + +As you can see, function arguments work very similar to `let` declarations: +you add a type to the argument name, after a colon. + +Here's a complete program that adds two numbers together and prints them: + +```{rust} +fn main() { + print_sum(5, 6); +} + +fn print_sum(x: i32, y: i32) { + println!("sum is: {}", x + y); +} +``` + +You separate arguments with a comma, both when you call the function, as well +as when you declare it. + +Unlike `let`, you _must_ declare the types of function arguments. This does +not work: + +```{ignore} +fn print_number(x, y) { + println!("x is: {}", x + y); +} +``` + +You get this error: + +```text +hello.rs:5:18: 5:19 error: expected `:` but found `,` +hello.rs:5 fn print_number(x, y) { +``` + +This is a deliberate design decision. While full-program inference is possible, +languages which have it, like Haskell, often suggest that documenting your +types explicitly is a best-practice. We agree that forcing functions to declare +types while allowing for inference inside of function bodies is a wonderful +sweet spot between full inference and no inference. + +What about returning a value? Here's a function that adds one to an integer: + +```{rust} +fn add_one(x: i32) -> i32 { + x + 1 +} +``` + +Rust functions return exactly one value, and you declare the type after an +'arrow', which is a dash (`-`) followed by a greater-than sign (`>`). + +You'll note the lack of a semicolon here. If we added it in: + +```{ignore} +fn add_one(x: i32) -> i32 { + x + 1; +} +``` + +We would get an error: + +```text +error: not all control paths return a value +fn add_one(x: i32) -> i32 { + x + 1; +} + +help: consider removing this semicolon: + x + 1; + ^ +``` + +Remember our earlier discussions about semicolons and `()`? Our function claims +to return an `i32`, but with a semicolon, it would return `()` instead. Rust +realizes this probably isn't what we want, and suggests removing the semicolon. + +This is very much like our `if` statement before: the result of the block +(`{}`) is the value of the expression. Other expression-oriented languages, +such as Ruby, work like this, but it's a bit unusual in the systems programming +world. When people first learn about this, they usually assume that it +introduces bugs. But because Rust's type system is so strong, and because unit +is its own unique type, we have never seen an issue where adding or removing a +semicolon in a return position would cause a bug. + +But what about early returns? Rust does have a keyword for that, `return`: + +```{rust} +fn foo(x: i32) -> i32 { + if x < 5 { return x; } + + x + 1 +} +``` + +Using a `return` as the last line of a function works, but is considered poor +style: + +```{rust} +fn foo(x: i32) -> i32 { + if x < 5 { return x; } + + return x + 1; +} +``` + +There are some additional ways to define functions, but they involve features +that we haven't learned about yet, so let's just leave it at that for now. diff --git a/src/doc/trpl/src/generics.md b/src/doc/trpl/src/generics.md new file mode 100644 index 0000000000000..137b66ea15af0 --- /dev/null +++ b/src/doc/trpl/src/generics.md @@ -0,0 +1,177 @@ +% Generics + +Sometimes, when writing a function or data type, we may want it to work for +multiple types of arguments. For example, remember our `OptionalInt` type? + +```{rust} +enum OptionalInt { + Value(int), + Missing, +} +``` + +If we wanted to also have an `OptionalFloat64`, we would need a new enum: + +```{rust} +enum OptionalFloat64 { + Valuef64(f64), + Missingf64, +} +``` + +This is really unfortunate. Luckily, Rust has a feature that gives us a better +way: generics. Generics are called **parametric polymorphism** in type theory, +which means that they are types or functions that have multiple forms ("poly" +is multiple, "morph" is form) over a given parameter ("parametric"). + +Anyway, enough with type theory declarations, let's check out the generic form +of `OptionalInt`. It is actually provided by Rust itself, and looks like this: + +```rust +enum Option { + Some(T), + None, +} +``` + +The `` part, which you've seen a few times before, indicates that this is +a generic data type. Inside the declaration of our enum, wherever we see a `T`, +we substitute that type for the same type used in the generic. Here's an +example of using `Option`, with some extra type annotations: + +```{rust} +let x: Option = Some(5i); +``` + +In the type declaration, we say `Option`. Note how similar this looks to +`Option`. So, in this particular `Option`, `T` has the value of `int`. On +the right-hand side of the binding, we do make a `Some(T)`, where `T` is `5i`. +Since that's an `int`, the two sides match, and Rust is happy. If they didn't +match, we'd get an error: + +```{rust,ignore} +let x: Option = Some(5i); +// error: mismatched types: expected `core::option::Option` +// but found `core::option::Option` (expected f64 but found int) +``` + +That doesn't mean we can't make `Option`s that hold an `f64`! They just have to +match up: + +```{rust} +let x: Option = Some(5i); +let y: Option = Some(5.0f64); +``` + +This is just fine. One definition, multiple uses. + +Generics don't have to only be generic over one type. Consider Rust's built-in +`Result` type: + +```{rust} +enum Result { + Ok(T), + Err(E), +} +``` + +This type is generic over _two_ types: `T` and `E`. By the way, the capital letters +can be any letter you'd like. We could define `Result` as: + +```{rust} +enum Result { + Ok(H), + Err(N), +} +``` + +if we wanted to. Convention says that the first generic parameter should be +`T`, for 'type,' and that we use `E` for 'error.' Rust doesn't care, however. + +The `Result` type is intended to +be used to return the result of a computation, and to have the ability to +return an error if it didn't work out. Here's an example: + +```{rust} +let x: Result = Ok(2.3f64); +let y: Result = Err("There was an error.".to_string()); +``` + +This particular Result will return an `f64` if there's a success, and a +`String` if there's a failure. Let's write a function that uses `Result`: + +```{rust} +fn inverse(x: f64) -> Result { + if x == 0.0f64 { return Err("x cannot be zero!".to_string()); } + + Ok(1.0f64 / x) +} +``` + +We don't want to take the inverse of zero, so we check to make sure that we +weren't passed zero. If we were, then we return an `Err`, with a message. If +it's okay, we return an `Ok`, with the answer. + +Why does this matter? Well, remember how `match` does exhaustive matches? +Here's how this function gets used: + +```{rust} +# fn inverse(x: f64) -> Result { +# if x == 0.0f64 { return Err("x cannot be zero!".to_string()); } +# Ok(1.0f64 / x) +# } +let x = inverse(25.0f64); + +match x { + Ok(x) => println!("The inverse of 25 is {}", x), + Err(msg) => println!("Error: {}", msg), +} +``` + +The `match` enforces that we handle the `Err` case. In addition, because the +answer is wrapped up in an `Ok`, we can't just use the result without doing +the match: + +```{rust,ignore} +let x = inverse(25.0f64); +println!("{}", x + 2.0f64); // error: binary operation `+` cannot be applied + // to type `core::result::Result` +``` + +This function is great, but there's one other problem: it only works for 64 bit +floating point values. What if we wanted to handle 32 bit floating point as +well? We'd have to write this: + +```{rust} +fn inverse32(x: f32) -> Result { + if x == 0.0f32 { return Err("x cannot be zero!".to_string()); } + + Ok(1.0f32 / x) +} +``` + +Bummer. What we need is a **generic function**. Luckily, we can write one! +However, it won't _quite_ work yet. Before we get into that, let's talk syntax. +A generic version of `inverse` would look something like this: + +```{rust,ignore} +fn inverse(x: T) -> Result { + if x == 0.0 { return Err("x cannot be zero!".to_string()); } + + Ok(1.0 / x) +} +``` + +Just like how we had `Option`, we use a similar syntax for `inverse`. +We can then use `T` inside the rest of the signature: `x` has type `T`, and half +of the `Result` has type `T`. However, if we try to compile that example, we'll get +an error: + +```text +error: binary operation `==` cannot be applied to type `T` +``` + +Because `T` can be _any_ type, it may be a type that doesn't implement `==`, +and therefore, the first line would be wrong. What do we do? + +To fix this example, we need to learn about another Rust feature: traits. diff --git a/src/doc/trpl/src/guessing-game.md b/src/doc/trpl/src/guessing-game.md new file mode 100644 index 0000000000000..1efcd4897609d --- /dev/null +++ b/src/doc/trpl/src/guessing-game.md @@ -0,0 +1,891 @@ +# Guessing Game + +Okay! We've got the basics of Rust down. Let's write a bigger program. + +For our first project, we'll implement a classic beginner programming problem: +the guessing game. Here's how it works: Our program will generate a random +integer between one and a hundred. It will then prompt us to enter a guess. +Upon entering our guess, it will tell us if we're too low or too high. Once we +guess correctly, it will congratulate us. Sound good? + +## Set up + +Let's set up a new project. Go to your projects directory. Remember how we +had to create our directory structure and a `Cargo.toml` for `hello_world`? Cargo +has a command that does that for us. Let's give it a shot: + +```{bash} +$ cd ~/projects +$ cargo new guessing_game --bin +$ cd guessing_game +``` + +We pass the name of our project to `cargo new`, and then the `--bin` flag, +since we're making a binary, rather than a library. + +Check out the generated `Cargo.toml`: + +```toml +[package] + +name = "guessing_game" +version = "0.0.1" +authors = ["Your Name "] +``` + +Cargo gets this information from your environment. If it's not correct, go ahead +and fix that. + +Finally, Cargo generated a "Hello, world!" for us. Check out `src/main.rs`: + +```{rust} +fn main() { + println!("Hello, world!") +} +``` + +Let's try compiling what Cargo gave us: + +```{bash} +$ cargo build + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) +``` + +Excellent! Open up your `src/main.rs` again. We'll be writing all of +our code in this file. We'll talk about multiple-file projects later on in the +guide. + +Before we move on, let me show you one more Cargo command: `run`. `cargo run` +is kind of like `cargo build`, but it also then runs the produced executable. +Try it out: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Hello, world! +``` + +Great! The `run` command comes in handy when you need to rapidly iterate on a project. +Our game is just such a project, we need to quickly test each iteration before moving on to the next one. + +## Processing a Guess + +Let's get to it! The first thing we need to do for our guessing game is +allow our player to input a guess. Put this in your `src/main.rs`: + +```{rust,no_run} +use std::io; + +fn main() { + println!("Guess the number!"); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + println!("You guessed: {}", input); +} +``` + +You've seen this code before, when we talked about standard input. We +import the `std::io` module with `use`, and then our `main` function contains +our program's logic. We print a little message announcing the game, ask the +user to input a guess, get their input, and then print it out. + +Because we talked about this in the section on standard I/O, I won't go into +more details here. If you need a refresher, go re-read that section. + +## Generating a secret number + +Next, we need to generate a secret number. To do that, we need to use Rust's +random number generation, which we haven't talked about yet. Rust includes a +bunch of interesting functions in its standard library. If you need a bit of +code, it's possible that it's already been written for you! In this case, +we do know that Rust has random number generation, but we don't know how to +use it. + +Enter the docs. Rust has a page specifically to document the standard library. +You can find that page [here](std/index.html). There's a lot of information on +that page, but the best part is the search bar. Right up at the top, there's +a box that you can enter in a search term. The search is pretty primitive +right now, but is getting better all the time. If you type 'random' in that +box, the page will update to [this one](std/index.html?search=random). The very +first result is a link to [`std::rand::random`](std/rand/fn.random.html). If we +click on that result, we'll be taken to its documentation page. + +This page shows us a few things: the type signature of the function, some +explanatory text, and then an example. Let's try to modify our code to add in the +`random` function and see what happens: + +```{rust,ignore} +use std::io; +use std::rand; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random() % 100) + 1; // secret_number: i32 + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + + println!("You guessed: {}", input); +} +``` + +The first thing we changed was to `use std::rand`, as the docs +explained. We then added in a `let` expression to create a variable binding +named `secret_number`, and we printed out its result. + +Also, you may wonder why we are using `%` on the result of `rand::random()`. +This operator is called 'modulo', and it returns the remainder of a division. +By taking the modulo of the result of `rand::random()`, we're limiting the +values to be between 0 and 99. Then, we add one to the result, making it from 1 +to 100. Using modulo can give you a very, very small bias in the result, but +for this example, it is not important. + +Let's try to compile this using `cargo build`: + +```bash +$ cargo build + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) +src/main.rs:7:26: 7:34 error: the type of this value must be known in this context +src/main.rs:7 let secret_number = (rand::random() % 100) + 1; + ^~~~~~~~ +error: aborting due to previous error +``` + +It didn't work! Rust says "the type of this value must be known in this +context." What's up with that? Well, as it turns out, `rand::random()` can +generate many kinds of random values, not just integers. And in this case, Rust +isn't sure what kind of value `random()` should generate. So we have to help +it. With number literals, we can just add an `i32` onto the end to tell Rust they're +integers, but that does not work with functions. There's a different syntax, +and it looks like this: + +```{rust,ignore} +rand::random::(); +``` + +This says "please give me a random `i32` value." We can change our code to use +this hint: + +```{rust,no_run} +use std::io; +use std::rand; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100) + 1; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + + println!("You guessed: {}", input); +} +``` + +Try running our new program a few times: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 7 +Please input your guess. +4 +You guessed: 4 +$ ./target/guessing_game +Guess the number! +The secret number is: 83 +Please input your guess. +5 +You guessed: 5 +$ ./target/guessing_game +Guess the number! +The secret number is: -29 +Please input your guess. +42 +You guessed: 42 +``` + +Wait. Negative 29? We wanted a number between one and a hundred! We have two +options here: we can either ask `random()` to generate an unsigned integer, which +can only be positive, or we can use the `abs()` function. Let's go with the +unsigned integer approach. If we want a random positive number, we should ask for +a random positive number. Our code looks like this now: + +```{rust,no_run} +use std::io; +use std::rand; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + + println!("You guessed: {}", input); +} +``` + +And trying it out: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 57 +Please input your guess. +3 +You guessed: 3 +``` + +Great! Next up: let's compare our guess to the secret guess. + +## Comparing guesses + +If you remember, earlier in the guide, we made a `cmp` function that compared +two numbers. Let's add that in, along with a `match` statement to compare our +guess to the secret number: + +```{rust,ignore} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + + println!("You guessed: {}", input); + + match cmp(input, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } +} + +fn cmp(a: i32, b: i32) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +If we try to compile, we'll get some errors: + +```bash +$ cargo build + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) +src/main.rs:20:15: 20:20 error: mismatched types: expected `i32` but found `collections::string::String` (expected i32 but found struct collections::string::String) +src/main.rs:20 match cmp(input, secret_number) { + ^~~~~ +src/main.rs:20:22: 20:35 error: mismatched types: expected `i32` but found `uint` (expected i32 but found uint) +src/main.rs:20 match cmp(input, secret_number) { + ^~~~~~~~~~~~~ +error: aborting due to 2 previous errors +``` + +This often happens when writing Rust programs, and is one of Rust's greatest +strengths. You try out some code, see if it compiles, and Rust tells you that +you've done something wrong. In this case, our `cmp` function works on integers, +but we've given it unsigned integers. In this case, the fix is easy, because +we wrote the `cmp` function! Let's change it to take `uint`s: + +```{rust,ignore} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + + + println!("You guessed: {}", input); + + match cmp(input, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +And try compiling again: + +```bash +$ cargo build + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) +src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String) +src/main.rs:20 match cmp(input, secret_number) { + ^~~~~ +error: aborting due to previous error +``` + +This error is similar to the last one: we expected to get a `uint`, but we got +a `String` instead! That's because our `input` variable is coming from the +standard input, and you can guess anything. Try it: + +```bash +$ ./target/guessing_game +Guess the number! +The secret number is: 73 +Please input your guess. +hello +You guessed: hello +``` + +Oops! Also, you'll note that we just ran our program even though it didn't compile. +This works because the older version we did successfully compile was still lying +around. Gotta be careful! + +Anyway, we have a `String`, but we need a `uint`. What to do? Well, there's +a function for that: + +```{rust,ignore} +let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); +let input_num: Option = input.parse(); +``` + +The `parse` function takes in a `&str` value and converts it into something. +We tell it what kind of something with a type hint. Remember our type hint with +`random()`? It looked like this: + +```{rust,ignore} +rand::random::(); +``` + +There's an alternate way of providing a hint too, and that's declaring the type +in a `let`: + +```{rust,ignore} +let x: uint = rand::random(); +``` + +In this case, we say `x` is a `uint` explicitly, so Rust is able to properly +tell `random()` what to generate. In a similar fashion, both of these work: + +```{rust,ignore} +let input_num = "5".parse::(); // input_num: Option +let input_num: Option = "5".parse(); // input_num: Option +``` + +Anyway, with us now converting our input to a number, our code looks like this: + +```{rust,ignore} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.parse(); + + println!("You guessed: {}", input_num); + + match cmp(input_num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +Let's try it out! + +```bash +$ cargo build + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) +src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option` (expected uint but found enum core::option::Option) +src/main.rs:22 match cmp(input_num, secret_number) { + ^~~~~~~~~ +error: aborting due to previous error +``` + +Oh yeah! Our `input_num` has the type `Option`, rather than `uint`. We +need to unwrap the Option. If you remember from before, `match` is a great way +to do that. Try this code: + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + return; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +We use a `match` to either give us the `uint` inside of the `Option`, or else +print an error message and return. Let's give this a shot: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 17 +Please input your guess. +5 +Please input a number! +``` + +Uh, what? But we did! + +... actually, we didn't. See, when you get a line of input from `stdin()`, +you get all the input. Including the `\n` character from you pressing Enter. +Therefore, `parse()` sees the string `"5\n"` and says "nope, that's not a +number; there's non-number stuff in there!" Luckily for us, `&str`s have an easy +method we can use defined on them: `trim()`. One small modification, and our +code looks like this: + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.trim().parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + return; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +Let's try it! + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 58 +Please input your guess. + 76 +You guessed: 76 +Too big! +``` + +Nice! You can see I even added spaces before my guess, and it still figured +out that I guessed 76. Run the program a few times, and verify that guessing +the number works, as well as guessing a number too small. + +The Rust compiler helped us out quite a bit there! This technique is called +"lean on the compiler", and it's often useful when working on some code. Let +the error messages help guide you towards the correct types. + +Now we've got most of the game working, but we can only make one guess. Let's +change that by adding loops! + +## Looping + +As we already discussed, the `loop` keyword gives us an infinite loop. +Let's add that in: + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + loop { + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.trim().parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + return; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), + } + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +And try it out. But wait, didn't we just add an infinite loop? Yup. Remember +that `return`? If we give a non-number answer, we'll `return` and quit. Observe: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 59 +Please input your guess. +45 +You guessed: 45 +Too small! +Please input your guess. +60 +You guessed: 60 +Too big! +Please input your guess. +59 +You guessed: 59 +You win! +Please input your guess. +quit +Please input a number! +``` + +Ha! `quit` actually quits. As does any other non-number input. Well, this is +suboptimal to say the least. First, let's actually quit when you win the game: + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + loop { + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.trim().parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + return; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { + println!("You win!"); + return; + }, + } + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +By adding the `return` line after the `You win!`, we'll exit the program when +we win. We have just one more tweak to make: when someone inputs a non-number, +we don't want to quit, we just want to ignore it. Change that `return` to +`continue`: + + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + println!("The secret number is: {}", secret_number); + + loop { + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.trim().parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + continue; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { + println!("You win!"); + return; + }, + } + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +Now we should be good! Let's try: + +```bash +$ cargo run + Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) + Running `target/guessing_game` +Guess the number! +The secret number is: 61 +Please input your guess. +10 +You guessed: 10 +Too small! +Please input your guess. +99 +You guessed: 99 +Too big! +Please input your guess. +foo +Please input a number! +Please input your guess. +61 +You guessed: 61 +You win! +``` + +Awesome! With one tiny last tweak, we have finished the guessing game. Can you +think of what it is? That's right, we don't want to print out the secret number. +It was good for testing, but it kind of ruins the game. Here's our final source: + +```{rust,no_run} +use std::io; +use std::rand; +use std::cmp::Ordering; + +fn main() { + println!("Guess the number!"); + + let secret_number = (rand::random::() % 100u) + 1u; + + loop { + + println!("Please input your guess."); + + let input = io::stdin().read_line() + .ok() + .expect("Failed to read line"); + let input_num: Option = input.trim().parse(); + + let num = match input_num { + Some(num) => num, + None => { + println!("Please input a number!"); + continue; + } + }; + + + println!("You guessed: {}", num); + + match cmp(num, secret_number) { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { + println!("You win!"); + return; + }, + } + } +} + +fn cmp(a: uint, b: uint) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} +``` + +## Complete! + +At this point, you have successfully built the Guessing Game! Congratulations! + +You've now learned the basic syntax of Rust. All of this is relatively close to +various other programming languages you have used in the past. These +fundamental syntactical and semantic elements will form the foundation for the +rest of your Rust education. + +Now that you're an expert at the basics, it's time to learn about some of +Rust's more unique features. diff --git a/src/doc/trpl/src/guide-lifetimes.md b/src/doc/trpl/src/guide-lifetimes.md new file mode 100644 index 0000000000000..7a5c535827c25 --- /dev/null +++ b/src/doc/trpl/src/guide-lifetimes.md @@ -0,0 +1,565 @@ +% The Rust References and Lifetimes Guide + +# Introduction + +References are one of the more flexible and powerful tools available in +Rust. They can point anywhere: into the heap, stack, and even into the +interior of another data structure. A reference is as flexible as a C pointer +or C++ reference. + +Unlike C and C++ compilers, the Rust compiler includes special static +checks that ensure that programs use references safely. + +Despite their complete safety, a reference's representation at runtime +is the same as that of an ordinary pointer in a C program. They introduce zero +overhead. The compiler does all safety checks at compile time. + +Although references have rather elaborate theoretical underpinnings +(e.g. region pointers), the core concepts will be familiar to anyone +who has worked with C or C++. The best way to explain how they are +used—and their limitations—is probably just to work through several examples. + +# By example + +References, sometimes known as *borrowed pointers*, are only valid for +a limited duration. References never claim any kind of ownership +over the data that they point to. Instead, they are used for cases +where you would like to use data for a short time. + +Consider a simple struct type `Point`: + +~~~ +struct Point {x: f64, y: f64} +~~~ + +We can use this simple definition to allocate points in many different ways. For +example, in this code, each of these local variables contains a point, +but allocated in a different place: + +~~~ +# struct Point {x: f64, y: f64} +let on_the_stack : Point = Point {x: 3.0, y: 4.0}; +let on_the_heap : Box = box Point {x: 7.0, y: 9.0}; +~~~ + +Suppose we wanted to write a procedure that computed the distance between any +two points, no matter where they were stored. One option is to define a function +that takes two arguments of type `Point`—that is, it takes the points by value. +But if we define it this way, calling the function will cause the points to be +copied. For points, this is probably not so bad, but often copies are +expensive. So we'd like to define a function that takes the points just as +a reference. + +~~~ +# use std::num::Float; +# struct Point {x: f64, y: f64} +# fn sqrt(f: f64) -> f64 { 0.0 } +fn compute_distance(p1: &Point, p2: &Point) -> f64 { + let x_d = p1.x - p2.x; + let y_d = p1.y - p2.y; + (x_d * x_d + y_d * y_d).sqrt() +} +~~~ + +Now we can call `compute_distance()`: + +~~~ +# struct Point {x: f64, y: f64} +# let on_the_stack : Point = Point{x: 3.0, y: 4.0}; +# let on_the_heap : Box = box Point{x: 7.0, y: 9.0}; +# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } +compute_distance(&on_the_stack, &*on_the_heap); +~~~ + +Here, the `&` operator takes the address of the variable +`on_the_stack`; this is because `on_the_stack` has the type `Point` +(that is, a struct value) and we have to take its address to get a +value. We also call this _borrowing_ the local variable +`on_the_stack`, because we have created an alias: that is, another +name for the same data. + +Likewise, in the case of `on_the_heap`, +the `&` operator is used in conjunction with the `*` operator +to take a reference to the contents of the box. + +Whenever a caller lends data to a callee, there are some limitations on what +the caller can do with the original. For example, if the contents of a +variable have been lent out, you cannot send that variable to another task. In +addition, the compiler will reject any code that might cause the borrowed +value to be freed or overwrite its component fields with values of different +types (I'll get into what kinds of actions those are shortly). This rule +should make intuitive sense: you must wait for a borrower to return the value +that you lent it (that is, wait for the reference to go out of scope) +before you can make full use of it again. + +# Other uses for the & operator + +In the previous example, the value `on_the_stack` was defined like so: + +~~~ +# struct Point {x: f64, y: f64} +let on_the_stack: Point = Point {x: 3.0, y: 4.0}; +~~~ + +This declaration means that code can only pass `Point` by value to other +functions. As a consequence, we had to explicitly take the address of +`on_the_stack` to get a reference. Sometimes however it is more +convenient to move the & operator into the definition of `on_the_stack`: + +~~~ +# struct Point {x: f64, y: f64} +let on_the_stack2: &Point = &Point {x: 3.0, y: 4.0}; +~~~ + +Applying `&` to an rvalue (non-assignable location) is just a convenient +shorthand for creating a temporary and taking its address. A more verbose +way to write the same code is: + +~~~ +# struct Point {x: f64, y: f64} +let tmp = Point {x: 3.0, y: 4.0}; +let on_the_stack2 : &Point = &tmp; +~~~ + +# Taking the address of fields + +The `&` operator is not limited to taking the address of +local variables. It can also take the address of fields or +individual array elements. For example, consider this type definition +for `Rectangle`: + +~~~ +struct Point {x: f64, y: f64} // as before +struct Size {w: f64, h: f64} // as before +struct Rectangle {origin: Point, size: Size} +~~~ + +Now, as before, we can define rectangles in a few different ways: + +~~~ +# struct Point {x: f64, y: f64} +# struct Size {w: f64, h: f64} // as before +# struct Rectangle {origin: Point, size: Size} +let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, + size: Size {w: 3.0, h: 4.0}}; +let rect_heap = box Rectangle {origin: Point {x: 5.0, y: 6.0}, + size: Size {w: 3.0, h: 4.0}}; +~~~ + +In each case, we can extract out individual subcomponents with the `&` +operator. For example, I could write: + +~~~ +# struct Point {x: f64, y: f64} // as before +# struct Size {w: f64, h: f64} // as before +# struct Rectangle {origin: Point, size: Size} +# let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, size: Size {w: 3.0, h: 4.0}}; +# let rect_heap = box Rectangle {origin: Point {x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; +# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } +compute_distance(&rect_stack.origin, &rect_heap.origin); +~~~ + +which would borrow the field `origin` from the rectangle on the stack +as well as from the owned box, and then compute the distance between them. + +# Lifetimes + +We’ve seen a few examples of borrowing data. To this point, we’ve glossed +over issues of safety. As stated in the introduction, at runtime a reference +is simply a pointer, nothing more. Therefore, avoiding C's problems with +dangling pointers requires a compile-time safety check. + +The basis for the check is the notion of _lifetimes_. A lifetime is a +static approximation of the span of execution during which the pointer +is valid: it always corresponds to some expression or block within the +program. + +The compiler will only allow a borrow *if it can guarantee that the data will +not be reassigned or moved for the lifetime of the pointer*. This does not +necessarily mean that the data is stored in immutable memory. For example, +the following function is legal: + +~~~ +# fn some_condition() -> bool { true } +# struct Foo { f: int } +fn example3() -> int { + let mut x = box Foo {f: 3}; + if some_condition() { + let y = &x.f; // -+ L + return *y; // | + } // -+ + x = box Foo {f: 4}; + // ... +# return 0; +} +~~~ + +Here, the interior of the variable `x` is being borrowed +and `x` is declared as mutable. However, the compiler can prove that +`x` is not assigned anywhere in the lifetime L of the variable +`y`. Therefore, it accepts the function, even though `x` is mutable +and in fact is mutated later in the function. + +It may not be clear why we are so concerned about mutating a borrowed +variable. The reason is that the runtime system frees any box +_as soon as its owning reference changes or goes out of +scope_. Therefore, a program like this is illegal (and would be +rejected by the compiler): + +~~~ {.ignore} +fn example3() -> int { + let mut x = box X {f: 3}; + let y = &x.f; + x = box X {f: 4}; // Error reported here. + *y +} +~~~ + +To make this clearer, consider this diagram showing the state of +memory immediately before the re-assignment of `x`: + +~~~ {.text} + Stack Exchange Heap + + x +-------------+ + | box {f:int} | ----+ + y +-------------+ | + | &int | ----+ + +-------------+ | +---------+ + +--> | f: 3 | + +---------+ +~~~ + +Once the reassignment occurs, the memory will look like this: + +~~~ {.text} + Stack Exchange Heap + + x +-------------+ +---------+ + | box {f:int} | -------> | f: 4 | + y +-------------+ +---------+ + | &int | ----+ + +-------------+ | +---------+ + +--> | (freed) | + +---------+ +~~~ + +Here you can see that the variable `y` still points at the old `f` +property of Foo, which has been freed. + +In fact, the compiler can apply the same kind of reasoning to any +memory that is (uniquely) owned by the stack frame. So we could +modify the previous example to introduce additional owned pointers +and structs, and the compiler will still be able to detect possible +mutations. This time, we'll use an analogy to illustrate the concept. + +~~~ {.ignore} +fn example3() -> int { + struct House { owner: Box } + struct Person { age: int } + + let mut house = box House { + owner: box Person {age: 30} + }; + + let owner_age = &house.owner.age; + house = box House {owner: box Person {age: 40}}; // Error reported here. + house.owner = box Person {age: 50}; // Error reported here. + *owner_age +} +~~~ + +In this case, two errors are reported, one when the variable `house` is +modified and another when `house.owner` is modified. Either modification would +invalidate the pointer `owner_age`. + +# Borrowing and enums + +The previous example showed that the type system forbids any mutations +of owned boxed values while they are being borrowed. In general, the type +system also forbids borrowing a value as mutable if it is already being +borrowed - either as a mutable reference or an immutable one. This restriction +prevents pointers from pointing into freed memory. There is one other +case where the compiler must be very careful to ensure that pointers +remain valid: pointers into the interior of an `enum`. + +Let’s look at the following `shape` type that can represent both rectangles +and circles: + +~~~ +struct Point {x: f64, y: f64}; // as before +struct Size {w: f64, h: f64}; // as before +enum Shape { + Circle(Point, f64), // origin, radius + Rectangle(Point, Size) // upper-left, dimensions +} +~~~ + +Now we might write a function to compute the area of a shape. This +function takes a reference to a shape, to avoid the need for +copying. + +~~~ +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before +# enum Shape { +# Circle(Point, f64), // origin, radius +# Rectangle(Point, Size) // upper-left, dimensions +# } +fn compute_area(shape: &Shape) -> f64 { + match *shape { + Shape::Circle(_, radius) => std::f64::consts::PI * radius * radius, + Shape::Rectangle(_, ref size) => size.w * size.h + } +} +~~~ + +The first case matches against circles. Here, the pattern extracts the +radius from the shape variant and the action uses it to compute the +area of the circle. + +The second match is more interesting. Here we match against a +rectangle and extract its size: but rather than copy the `size` +struct, we use a by-reference binding to create a pointer to it. In +other words, a pattern binding like `ref size` binds the name `size` +to a pointer of type `&size` into the _interior of the enum_. + +To make this more clear, let's look at a diagram of memory layout in +the case where `shape` points at a rectangle: + +~~~ {.text} +Stack Memory + ++-------+ +---------------+ +| shape | ------> | rectangle( | ++-------+ | {x: f64, | +| size | -+ | y: f64}, | ++-------+ +----> | {w: f64, | + | h: f64}) | + +---------------+ +~~~ + +Here you can see that rectangular shapes are composed of five words of +memory. The first is a tag indicating which variant this enum is +(`rectangle`, in this case). The next two words are the `x` and `y` +fields for the point and the remaining two are the `w` and `h` fields +for the size. The binding `size` is then a pointer into the inside of +the shape. + +Perhaps you can see where the danger lies: if the shape were somehow +to be reassigned, perhaps to a circle, then although the memory used +to store that shape value would still be valid, _it would have a +different type_! The following diagram shows what memory would look +like if code overwrote `shape` with a circle: + +~~~ {.text} +Stack Memory + ++-------+ +---------------+ +| shape | ------> | circle( | ++-------+ | {x: f64, | +| size | -+ | y: f64}, | ++-------+ +----> | f64) | + | | + +---------------+ +~~~ + +As you can see, the `size` pointer would be pointing at a `f64` +instead of a struct. This is not good: dereferencing the second field +of a `f64` as if it were a struct with two fields would be a memory +safety violation. + +So, in fact, for every `ref` binding, the compiler will impose the +same rules as the ones we saw for borrowing the interior of an owned +box: it must be able to guarantee that the `enum` will not be +overwritten for the duration of the borrow. In fact, the compiler +would accept the example we gave earlier. The example is safe because +the shape pointer has type `&Shape`, which means "reference to +immutable memory containing a `shape`". If, however, the type of that +pointer were `&mut Shape`, then the ref binding would be ill-typed. +Just as with owned boxes, the compiler will permit `ref` bindings +into data owned by the stack frame even if the data are mutable, +but otherwise it requires that the data reside in immutable memory. + +# Returning references + +So far, all of the examples we have looked at, use references in a +“downward” direction. That is, a method or code block creates a +reference, then uses it within the same scope. It is also +possible to return references as the result of a function, but +as we'll see, doing so requires some explicit annotation. + +We could write a subroutine like this: + +~~~ +struct Point {x: f64, y: f64} +fn get_x<'r>(p: &'r Point) -> &'r f64 { &p.x } +~~~ + +Here, the function `get_x()` returns a pointer into the structure it +was given. The type of the parameter (`&'r Point`) and return type +(`&'r f64`) both use a new syntactic form that we have not seen so +far. Here the identifier `r` names the lifetime of the pointer +explicitly. So in effect, this function declares that it takes a +pointer with lifetime `r` and returns a pointer with that same +lifetime. + +In general, it is only possible to return references if they +are derived from a parameter to the procedure. In that case, the +pointer result will always have the same lifetime as one of the +parameters; named lifetimes indicate which parameter that +is. + +In the previous code samples, function parameter types did not include a +lifetime name. The compiler simply creates a fresh name for the lifetime +automatically: that is, the lifetime name is guaranteed to refer to a distinct +lifetime from the lifetimes of all other parameters. + +Named lifetimes that appear in function signatures are conceptually +the same as the other lifetimes we have seen before, but they are a bit +abstract: they don’t refer to a specific expression within `get_x()`, +but rather to some expression within the *caller of `get_x()`*. The +lifetime `r` is actually a kind of *lifetime parameter*: it is defined +by the caller to `get_x()`, just as the value for the parameter `p` is +defined by that caller. + +In any case, whatever the lifetime of `r` is, the pointer produced by +`&p.x` always has the same lifetime as `p` itself: a pointer to a +field of a struct is valid as long as the struct is valid. Therefore, +the compiler accepts the function `get_x()`. + +In general, if you borrow a struct or box to create a +reference, it will only be valid within the function +and cannot be returned. This is why the typical way to return references +is to take references as input (the only other case in +which it can be legal to return a reference is if it +points at a static constant). + +# Named lifetimes + +Lifetimes can be named and referenced. For example, the special lifetime +`'static`, which does not go out of scope, can be used to create global +variables and communicate between tasks (see the manual for use cases). + +## Parameter Lifetimes + +Named lifetimes allow for grouping of parameters by lifetime. +For example, consider this function: + +~~~ +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before +# enum Shape { +# Circle(Point, f64), // origin, radius +# Rectangle(Point, Size) // upper-left, dimensions +# } +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, T>(shape: &'r Shape, threshold: f64, + a: &'r T, b: &'r T) -> &'r T { + if compute_area(shape) > threshold {a} else {b} +} +~~~ + +This function takes three references and assigns each the same +lifetime `r`. In practice, this means that, in the caller, the +lifetime `r` will be the *intersection of the lifetime of the three +region parameters*. This may be overly conservative, as in this +example: + +~~~ +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before +# enum Shape { +# Circle(Point, f64), // origin, radius +# Rectangle(Point, Size) // upper-left, dimensions +# } +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +# fn select<'r, T>(shape: &Shape, threshold: f64, +# a: &'r T, b: &'r T) -> &'r T { +# if compute_area(shape) > threshold {a} else {b} +# } + // -+ r +fn select_based_on_unit_circle<'r, T>( // |-+ B + threshold: f64, a: &'r T, b: &'r T) -> &'r T { // | | + // | | + let shape = Shape::Circle(Point {x: 0., y: 0.}, 1.); // | | + select(&shape, threshold, a, b) // | | +} // |-+ + // -+ +~~~ + +In this call to `select()`, the lifetime of the first parameter shape +is B, the function body. Both of the second two parameters `a` and `b` +share the same lifetime, `r`, which is a lifetime parameter of +`select_based_on_unit_circle()`. The caller will infer the +intersection of these two lifetimes as the lifetime of the returned +value, and hence the return value of `select()` will be assigned a +lifetime of B. This will in turn lead to a compilation error, because +`select_based_on_unit_circle()` is supposed to return a value with the +lifetime `r`. + +To address this, we can modify the definition of `select()` to +distinguish the lifetime of the first parameter from the lifetime of +the latter two. After all, the first parameter is not being +returned. Here is how the new `select()` might look: + +~~~ +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before +# enum Shape { +# Circle(Point, f64), // origin, radius +# Rectangle(Point, Size) // upper-left, dimensions +# } +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: f64, + a: &'r T, b: &'r T) -> &'r T { + if compute_area(shape) > threshold {a} else {b} +} +~~~ + +Here you can see that `shape`'s lifetime is now named `tmp`. The +parameters `a`, `b`, and the return value all have the lifetime `r`. +However, since the lifetime `tmp` is not returned, it would be more +concise to just omit the named lifetime for `shape` altogether: + +~~~ +# struct Point {x: f64, y: f64}; // as before +# struct Size {w: f64, h: f64}; // as before +# enum Shape { +# Circle(Point, f64), // origin, radius +# Rectangle(Point, Size) // upper-left, dimensions +# } +# fn compute_area(shape: &Shape) -> f64 { 0.0 } +fn select<'r, T>(shape: &Shape, threshold: f64, + a: &'r T, b: &'r T) -> &'r T { + if compute_area(shape) > threshold {a} else {b} +} +~~~ + +This is equivalent to the previous definition. + +## Labeled Control Structures + +Named lifetime notation can also be used to control the flow of execution: + +~~~ +'h: for i in range(0u, 10) { + 'g: loop { + if i % 2 == 0 { continue 'h; } + if i == 9 { break 'h; } + break 'g; + } +} +~~~ + +> *Note:* Labelled breaks are not currently supported within `while` loops. + +Named labels are hygienic and can be used safely within macros. +See the macros guide section on hygiene for more details. + +# Conclusion + +So there you have it: a (relatively) brief tour of the lifetime +system. For more details, we refer to the (yet to be written) reference +document on references, which will explain the full notation +and give more examples. diff --git a/src/doc/trpl/src/hello-cargo.md b/src/doc/trpl/src/hello-cargo.md new file mode 100644 index 0000000000000..c81cdc465c8fc --- /dev/null +++ b/src/doc/trpl/src/hello-cargo.md @@ -0,0 +1,108 @@ +# Hello, Cargo! + +[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their +Rust projects. Cargo is currently in an alpha state, just like Rust, and so it +is still a work in progress. However, it is already good enough to use for many +Rust projects, and so it is assumed that Rust projects will use Cargo from the +beginning. + +Cargo manages three things: building your code, downloading the dependencies +your code needs, and building the dependencies your code needs. At first, your +program doesn't have any dependencies, so we'll only be using the first part of +its functionality. Eventually, we'll add more. Since we started off by using +Cargo, it'll be easy to add later. + +If you installed Rust via the official installers you will also have +Cargo. If you installed Rust some other way, you may want to [check +the Cargo +README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies) +for specific instructions about installing it. + +Let's convert Hello World to Cargo. + +To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` +configuration file, and put our source file in the right place. Let's +do that part first: + +```{bash} +$ mkdir src +$ mv main.rs src/main.rs +``` + +Cargo expects your source files to live inside a `src` directory. That leaves +the top level for other things, like READMEs, license information, and anything +not related to your code. Cargo helps us keep our projects nice and tidy. A +place for everything, and everything in its place. + +Next, our configuration file: + +```{bash} +$ editor Cargo.toml +``` + +Make sure to get this name right: you need the capital `C`! + +Put this inside: + +```toml +[package] + +name = "hello_world" +version = "0.0.1" +authors = [ "Your name " ] + +[[bin]] + +name = "hello_world" +``` + +This file is in the [TOML](https://github.com/toml-lang/toml) format. Let's let +it explain itself to you: + +> TOML aims to be a minimal configuration file format that's easy to read due +> to obvious semantics. TOML is designed to map unambiguously to a hash table. +> TOML should be easy to parse into data structures in a wide variety of +> languages. + +TOML is very similar to INI, but with some extra goodies. + +Anyway, there are two **table**s in this file: `package` and `bin`. The first +tells Cargo metadata about your package. The second tells Cargo that we're +interested in building a binary, not a library (though we could do both!), as +well as what it is named. + +Once you have this file in place, we should be ready to build! Try this: + +```{bash} +$ cargo build + Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world) +$ ./target/hello_world +Hello, world! +``` + +Bam! We build our project with `cargo build`, and run it with +`./target/hello_world`. This hasn't bought us a whole lot over our simple use +of `rustc`, but think about the future: when our project has more than one +file, we would need to call `rustc` more than once, and pass it a bunch of options to +tell it to build everything together. With Cargo, as our project grows, we can +just `cargo build` and it'll work the right way. + +You'll also notice that Cargo has created a new file: `Cargo.lock`. + +```toml +[root] +name = "hello_world" +version = "0.0.1" +``` + +This file is used by Cargo to keep track of dependencies in your application. +Right now, we don't have any, so it's a bit sparse. You won't ever need +to touch this file yourself, just let Cargo handle it. + +That's it! We've successfully built `hello_world` with Cargo. Even though our +program is simple, it's using much of the real tooling that you'll use for the +rest of your Rust career. + +Now that you've got the tools down, let's actually learn more about the Rust +language itself. These are the basics that will serve you well through the rest +of your time with Rust. diff --git a/src/doc/trpl/src/hello-world.md b/src/doc/trpl/src/hello-world.md new file mode 100644 index 0000000000000..33cb752c36468 --- /dev/null +++ b/src/doc/trpl/src/hello-world.md @@ -0,0 +1,164 @@ +# Hello, world! + +Now that you have Rust installed, let's write your first Rust program. It's +traditional to make your first program in any new language one that prints the +text "Hello, world!" to the screen. The nice thing about starting with such a +simple program is that you can verify that your compiler isn't just installed, +but also working properly. And printing information to the screen is a pretty +common thing to do. + +The first thing that we need to do is make a file to put our code in. I like +to make a `projects` directory in my home directory, and keep all my projects +there. Rust does not care where your code lives. + +This actually leads to one other concern we should address: this guide will +assume that you have basic familiarity with the command line. Rust does not +require that you know a whole ton about the command line, but until the +language is in a more finished state, IDE support is spotty. Rust makes no +specific demands on your editing tooling, or where your code lives. + +With that said, let's make a directory in our projects directory. + +```{bash} +$ mkdir ~/projects +$ cd ~/projects +$ mkdir hello_world +$ cd hello_world +``` + +If you're on Windows and not using PowerShell, the `~` may not work. Consult +the documentation for your shell for more details. + +Let's make a new source file next. I'm going to use the syntax `editor +filename` to represent editing a file in these examples, but you should use +whatever method you want. We'll call our file `main.rs`: + +```{bash} +$ editor main.rs +``` + +Rust files always end in a `.rs` extension. If you're using more than one word +in your filename, use an underscore. `hello_world.rs` rather than +`helloworld.rs`. + +Now that you've got your file open, type this in: + +```{rust} +fn main() { + println!("Hello, world!"); +} +``` + +Save the file, and then type this into your terminal window: + +```{bash} +$ rustc main.rs +$ ./main # or main.exe on Windows +Hello, world! +``` + +You can also run these examples on [play.rust-lang.org](http://play.rust-lang.org/) by clicking on the arrow that appears in the upper right of the example when you mouse over the code. + +Success! Let's go over what just happened in detail. + +```{rust} +fn main() { + +} +``` + +These lines define a **function** in Rust. The `main` function is special: +it's the beginning of every Rust program. The first line says "I'm declaring a +function named `main`, which takes no arguments and returns nothing." If there +were arguments, they would go inside the parentheses (`(` and `)`), and because +we aren't returning anything from this function, we've dropped that notation +entirely. We'll get to it later. + +You'll also note that the function is wrapped in curly braces (`{` and `}`). +Rust requires these around all function bodies. It is also considered good +style to put the opening curly brace on the same line as the function +declaration, with one space in between. + +Next up is this line: + +```{rust} + println!("Hello, world!"); +``` + +This line does all of the work in our little program. There are a number of +details that are important here. The first is that it's indented with four +spaces, not tabs. Please configure your editor of choice to insert four spaces +with the tab key. We provide some [sample configurations for various +editors](https://github.com/rust-lang/rust/tree/master/src/etc). + +The second point is the `println!()` part. This is calling a Rust **macro**, +which is how metaprogramming is done in Rust. If it were a function instead, it +would look like this: `println()`. For our purposes, we don't need to worry +about this difference. Just know that sometimes, you'll see a `!`, and that +means that you're calling a macro instead of a normal function. Rust implements +`println!` as a macro rather than a function for good reasons, but that's a +very advanced topic. You'll learn more when we talk about macros later. One +last thing to mention: Rust's macros are significantly different from C macros, +if you've used those. Don't be scared of using macros. We'll get to the details +eventually, you'll just have to trust us for now. + +Next, `"Hello, world!"` is a **string**. Strings are a surprisingly complicated +topic in a systems programming language, and this is a **statically allocated** +string. We will talk more about different kinds of allocation later. We pass +this string as an argument to `println!`, which prints the string to the +screen. Easy enough! + +Finally, the line ends with a semicolon (`;`). Rust is an **expression +oriented** language, which means that most things are expressions. The `;` is +used to indicate that this expression is over, and the next one is ready to +begin. Most lines of Rust code end with a `;`. We will cover this in-depth +later in the guide. + +Finally, actually **compiling** and **running** our program. We can compile +with our compiler, `rustc`, by passing it the name of our source file: + +```{bash} +$ rustc main.rs +``` + +This is similar to `gcc` or `clang`, if you come from a C or C++ background. Rust +will output a binary executable. You can see it with `ls`: + +```{bash} +$ ls +main main.rs +``` + +Or on Windows: + +```{bash} +$ dir +main.exe main.rs +``` + +There are now two files: our source code, with the `.rs` extension, and the +executable (`main.exe` on Windows, `main` everywhere else) + +```{bash} +$ ./main # or main.exe on Windows +``` + +This prints out our `Hello, world!` text to our terminal. + +If you come from a dynamically typed language like Ruby, Python, or JavaScript, +you may not be used to these two steps being separate. Rust is an +**ahead-of-time compiled language**, which means that you can compile a +program, give it to someone else, and they don't need to have Rust installed. +If you give someone a `.rb` or `.py` or `.js` file, they need to have +Ruby/Python/JavaScript installed, but you just need one command to both compile +and run your program. Everything is a tradeoff in language design, and Rust has +made its choice. + +Congratulations! You have officially written a Rust program. That makes you a +Rust programmer! Welcome. + +Next, I'd like to introduce you to another tool, Cargo, which is used to write +real-world Rust programs. Just using `rustc` is nice for simple things, but as +your project grows, you'll want something to help you manage all of the options +that it has, and to make it easy to share your code with other people and +projects. diff --git a/src/doc/trpl/src/if.md b/src/doc/trpl/src/if.md new file mode 100644 index 0000000000000..bc3d548ce9f05 --- /dev/null +++ b/src/doc/trpl/src/if.md @@ -0,0 +1,141 @@ +# `if` + +Rust's take on `if` is not particularly complex, but it's much more like the +`if` you'll find in a dynamically typed language than in a more traditional +systems language. So let's talk about it, to make sure you grasp the nuances. + +`if` is a specific form of a more general concept, the 'branch.' The name comes +from a branch in a tree: a decision point, where depending on a choice, +multiple paths can be taken. + +In the case of `if`, there is one choice that leads down two paths: + +```rust +let x = 5; + +if x == 5 { + println!("x is five!"); +} +``` + +If we changed the value of `x` to something else, this line would not print. +More specifically, if the expression after the `if` evaluates to `true`, then +the block is executed. If it's `false`, then it is not. + +If you want something to happen in the `false` case, use an `else`: + +```{rust} +let x = 5; + +if x == 5 { + println!("x is five!"); +} else { + println!("x is not five :("); +} +``` + +This is all pretty standard. However, you can also do this: + + +```{rust} +let x = 5; + +let y = if x == 5 { + 10 +} else { + 15 +}; // y: i32 +``` + +Which we can (and probably should) write like this: + +```{rust} +let x = 5; + +let y = if x == 5 { 10 } else { 15 }; // y: i32 +``` + +This reveals two interesting things about Rust: it is an expression-based +language, and semicolons are different from semicolons in other 'curly brace +and semicolon'-based languages. These two things are related. + +## Expressions vs. Statements + +Rust is primarily an expression based language. There are only two kinds of +statements, and everything else is an expression. + +So what's the difference? Expressions return a value, and statements do not. +In many languages, `if` is a statement, and therefore, `let x = if ...` would +make no sense. But in Rust, `if` is an expression, which means that it returns +a value. We can then use this value to initialize the binding. + +Speaking of which, bindings are a kind of the first of Rust's two statements. +The proper name is a **declaration statement**. So far, `let` is the only kind +of declaration statement we've seen. Let's talk about that some more. + +In some languages, variable bindings can be written as expressions, not just +statements. Like Ruby: + +```{ruby} +x = y = 5 +``` + +In Rust, however, using `let` to introduce a binding is _not_ an expression. The +following will produce a compile-time error: + +```{ignore} +let x = (let y = 5); // expected identifier, found keyword `let` +``` + +The compiler is telling us here that it was expecting to see the beginning of +an expression, and a `let` can only begin a statement, not an expression. + +Note that assigning to an already-bound variable (e.g. `y = 5`) is still an +expression, although its value is not particularly useful. Unlike C, where an +assignment evaluates to the assigned value (e.g. `5` in the previous example), +in Rust the value of an assignment is the unit type `()` (which we'll cover later). + +The second kind of statement in Rust is the **expression statement**. Its +purpose is to turn any expression into a statement. In practical terms, Rust's +grammar expects statements to follow other statements. This means that you use +semicolons to separate expressions from each other. This means that Rust +looks a lot like most other languages that require you to use semicolons +at the end of every line, and you will see semicolons at the end of almost +every line of Rust code you see. + +What is this exception that makes us say 'almost?' You saw it already, in this +code: + +```{rust} +let x = 5; + +let y: i32 = if x == 5 { 10 } else { 15 }; +``` + +Note that I've added the type annotation to `y`, to specify explicitly that I +want `y` to be an integer. + +This is not the same as this, which won't compile: + +```{ignore} +let x = 5; + +let y: i32 = if x == 5 { 10; } else { 15; }; +``` + +Note the semicolons after the 10 and 15. Rust will give us the following error: + +```text +error: mismatched types: expected `i32` but found `()` (expected i32 but found ()) +``` + +We expected an integer, but we got `()`. `()` is pronounced 'unit', and is a +special type in Rust's type system. In Rust, `()` is _not_ a valid value for a +variable of type `i32`. It's only a valid value for variables of the type `()`, +which aren't very useful. Remember how we said statements don't return a value? +Well, that's the purpose of unit in this case. The semicolon turns any +expression into a statement by throwing away its value and returning unit +instead. + +There's one more time in which you won't see a semicolon at the end of a line +of Rust code. For that, we'll need our next concept: functions. diff --git a/src/doc/trpl/src/installing-rust.md b/src/doc/trpl/src/installing-rust.md new file mode 100644 index 0000000000000..1705893c397c2 --- /dev/null +++ b/src/doc/trpl/src/installing-rust.md @@ -0,0 +1,89 @@ +# Installing Rust + +The first step to using Rust is to install it! There are a number of ways to +install Rust, but the easiest is to use the `rustup` script. If you're on +Linux or a Mac, all you need to do is this (note that you don't need to type +in the `$`s, they just indicate the start of each command): + +```bash +$ curl -L https://static.rust-lang.org/rustup.sh | sudo sh +``` + +If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`, +please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script: + +```bash +$ curl -L https://static.rust-lang.org/rustup.sh -O +$ sudo sh rustup.sh +``` + +If you're on Windows, please download either the [32-bit +installer](https://static.rust-lang.org/dist/rust-nightly-i686-pc-windows-gnu.exe) +or the [64-bit +installer](https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-gnu.exe) +and run it. + +If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay. +Not every programming language is great for everyone. Just pass an argument to +the script: + +```bash +$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall +``` + +If you used the Windows installer, just re-run the `.exe` and it will give you +an uninstall option. + +You can re-run this script any time you want to update Rust. Which, at this +point, is often. Rust is still pre-1.0, and so people assume that you're using +a very recent Rust. + +This brings me to one other point: some people, and somewhat rightfully so, get +very upset when we tell you to `curl | sudo sh`. And they should be! Basically, +when you do this, you are trusting that the good people who maintain Rust +aren't going to hack your computer and do bad things. That's a good instinct! +If you're one of those people, please check out the documentation on [building +Rust from Source](https://github.com/rust-lang/rust#building-from-source), or +[the official binary downloads](http://www.rust-lang.org/install.html). And we +promise that this method will not be the way to install Rust forever: it's just +the easiest way to keep people updated while Rust is in its alpha state. + +Oh, we should also mention the officially supported platforms: + +* Windows (7, 8, Server 2008 R2) +* Linux (2.6.18 or later, various distributions), x86 and x86-64 +* OSX 10.7 (Lion) or greater, x86 and x86-64 + +We extensively test Rust on these platforms, and a few others, too, like +Android. But these are the ones most likely to work, as they have the most +testing. + +Finally, a comment about Windows. Rust considers Windows to be a first-class +platform upon release, but if we're honest, the Windows experience isn't as +integrated as the Linux/OS X experience is. We're working on it! If anything +does not work, it is a bug. Please let us know if that happens. Each and every +commit is tested against Windows just like any other platform. + +If you've got Rust installed, you can open up a shell, and type this: + +```bash +$ rustc --version +``` + +You should see some output that looks something like this: + +```bash +rustc 1.0.0-nightly (f11f3e7ba 2015-01-04 20:02:14 +0000) +``` + +If you did, Rust has been installed successfully! Congrats! + +If not, there are a number of places where you can get help. The easiest is +[the #rust IRC channel on irc.mozilla.org](irc://irc.mozilla.org/#rust), which +you can access through +[Mibbit](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust). Click +that link, and you'll be chatting with other Rustaceans (a silly nickname we +call ourselves), and we can help you out. Other great resources include [our +forum](http://discuss.rust-lang.org/), [the /r/rust +subreddit](http://www.reddit.com/r/rust), and [Stack +Overflow](http://stackoverflow.com/questions/tagged/rust). diff --git a/src/doc/trpl/src/intermediate.md b/src/doc/trpl/src/intermediate.md new file mode 100644 index 0000000000000..73370a32231eb --- /dev/null +++ b/src/doc/trpl/src/intermediate.md @@ -0,0 +1,7 @@ +% Intermediate + +This section contains individual chapters, which are self-contained. They focus +on specific topics, and can be read in any order. + +After reading "Intermediate," you will have a solid understanding of Rust, +and will be able to understand most Rust code and write more complex programs. diff --git a/src/doc/trpl/src/iterators.md b/src/doc/trpl/src/iterators.md new file mode 100644 index 0000000000000..056e9a9720e13 --- /dev/null +++ b/src/doc/trpl/src/iterators.md @@ -0,0 +1,339 @@ +% Iterators + +Let's talk about loops. + +Remember Rust's `for` loop? Here's an example: + +```{rust} +for x in range(0i, 10i) { + println!("{}", x); +} +``` + +Now that you know more Rust, we can talk in detail about how this works. The +`range` function returns an **iterator**. An iterator is something that we can +call the `.next()` method on repeatedly, and it gives us a sequence of things. + +Like this: + +```{rust} +let mut range = range(0i, 10i); + +loop { + match range.next() { + Some(x) => { + println!("{}", x); + }, + None => { break } + } +} +``` + +We make a mutable binding to the return value of `range`, which is our iterator. +We then `loop`, with an inner `match`. This `match` is used on the result of +`range.next()`, which gives us a reference to the next value of the iterator. +`next` returns an `Option`, in this case, which will be `Some(int)` when +we have a value and `None` once we run out. If we get `Some(int)`, we print it +out, and if we get `None`, we `break` out of the loop. + +This code sample is basically the same as our `for` loop version. The `for` +loop is just a handy way to write this `loop`/`match`/`break` construct. + +`for` loops aren't the only thing that uses iterators, however. Writing your +own iterator involves implementing the `Iterator` trait. While doing that is +outside of the scope of this guide, Rust provides a number of useful iterators +to accomplish various tasks. Before we talk about those, we should talk about a +Rust anti-pattern. And that's `range`. + +Yes, we just talked about how `range` is cool. But `range` is also very +primitive. For example, if you needed to iterate over the contents of +a vector, you may be tempted to write this: + +```{rust} +let nums = vec![1i, 2i, 3i]; + +for i in range(0u, nums.len()) { + println!("{}", nums[i]); +} +``` + +This is strictly worse than using an actual iterator. The `.iter()` method on +vectors returns an iterator which iterates through a reference to each element +of the vector in turn. So write this: + +```{rust} +let nums = vec![1i, 2i, 3i]; + +for num in nums.iter() { + println!("{}", num); +} +``` + +There are two reasons for this. First, this more directly expresses what we +mean. We iterate through the entire vector, rather than iterating through +indexes, and then indexing the vector. Second, this version is more efficient: +the first version will have extra bounds checking because it used indexing, +`nums[i]`. But since we yield a reference to each element of the vector in turn +with the iterator, there's no bounds checking in the second example. This is +very common with iterators: we can ignore unnecessary bounds checks, but still +know that we're safe. + +There's another detail here that's not 100% clear because of how `println!` +works. `num` is actually of type `&int`. That is, it's a reference to an `int`, +not an `int` itself. `println!` handles the dereferencing for us, so we don't +see it. This code works fine too: + +```{rust} +let nums = vec![1i, 2i, 3i]; + +for num in nums.iter() { + println!("{}", *num); +} +``` + +Now we're explicitly dereferencing `num`. Why does `iter()` give us references? +Well, if it gave us the data itself, we would have to be its owner, which would +involve making a copy of the data and giving us the copy. With references, +we're just borrowing a reference to the data, and so it's just passing +a reference, without needing to do the copy. + +So, now that we've established that `range` is often not what you want, let's +talk about what you do want instead. + +There are three broad classes of things that are relevant here: iterators, +**iterator adapters**, and **consumers**. Here's some definitions: + +* 'iterators' give you a sequence of values. +* 'iterator adapters' operate on an iterator, producing a new iterator with a + different output sequence. +* 'consumers' operate on an iterator, producing some final set of values. + +Let's talk about consumers first, since you've already seen an iterator, +`range`. + +## Consumers + +A 'consumer' operates on an iterator, returning some kind of value or values. +The most common consumer is `collect()`. This code doesn't quite compile, +but it shows the intention: + +```{rust,ignore} +let one_to_one_hundred = range(1i, 101i).collect(); +``` + +As you can see, we call `collect()` on our iterator. `collect()` takes +as many values as the iterator will give it, and returns a collection +of the results. So why won't this compile? Rust can't determine what +type of things you want to collect, and so you need to let it know. +Here's the version that does compile: + +```{rust} +let one_to_one_hundred = range(1i, 101i).collect::>(); +``` + +If you remember, the `::<>` syntax allows us to give a type hint, +and so we tell it that we want a vector of integers. + +`collect()` is the most common consumer, but there are others too. `find()` +is one: + +```{rust} +let greater_than_forty_two = range(0i, 100i) + .find(|x| *x > 42); + +match greater_than_forty_two { + Some(_) => println!("We got some numbers!"), + None => println!("No numbers found :("), +} +``` + +`find` takes a closure, and works on a reference to each element of an +iterator. This closure returns `true` if the element is the element we're +looking for, and `false` otherwise. Because we might not find a matching +element, `find` returns an `Option` rather than the element itself. + +Another important consumer is `fold`. Here's what it looks like: + +```{rust} +let sum = range(1i, 4i) + .fold(0i, |sum, x| sum + x); +``` + +`fold()` is a consumer that looks like this: +`fold(base, |accumulator, element| ...)`. It takes two arguments: the first +is an element called the "base". The second is a closure that itself takes two +arguments: the first is called the "accumulator," and the second is an +"element." Upon each iteration, the closure is called, and the result is the +value of the accumulator on the next iteration. On the first iteration, the +base is the value of the accumulator. + +Okay, that's a bit confusing. Let's examine the values of all of these things +in this iterator: + +| base | accumulator | element | closure result | +|------|-------------|---------|----------------| +| 0i | 0i | 1i | 1i | +| 0i | 1i | 2i | 3i | +| 0i | 3i | 3i | 6i | + +We called `fold()` with these arguments: + +```{rust} +# range(1i, 4i) +.fold(0i, |sum, x| sum + x); +``` + +So, `0i` is our base, `sum` is our accumulator, and `x` is our element. On the +first iteration, we set `sum` to `0i`, and `x` is the first element of `nums`, +`1i`. We then add `sum` and `x`, which gives us `0i + 1i = 1i`. On the second +iteration, that value becomes our accumulator, `sum`, and the element is +the second element of the array, `2i`. `1i + 2i = 3i`, and so that becomes +the value of the accumulator for the last iteration. On that iteration, +`x` is the last element, `3i`, and `3i + 3i = 6i`, which is our final +result for our sum. `1 + 2 + 3 = 6`, and that's the result we got. + +Whew. `fold` can be a bit strange the first few times you see it, but once it +clicks, you can use it all over the place. Any time you have a list of things, +and you want a single result, `fold` is appropriate. + +Consumers are important due to one additional property of iterators we haven't +talked about yet: laziness. Let's talk some more about iterators, and you'll +see why consumers matter. + +## Iterators + +As we've said before, an iterator is something that we can call the +`.next()` method on repeatedly, and it gives us a sequence of things. +Because you need to call the method, this means that iterators +are **lazy** and don't need to generate all of the values upfront. +This code, for example, does not actually generate the numbers +`1-100`, and just creates a value that represents the sequence: + +```{rust} +let nums = range(1i, 100i); +``` + +Since we didn't do anything with the range, it didn't generate the sequence. +Let's add the consumer: + +```{rust} +let nums = range(1i, 100i).collect::>(); +``` + +Now, `collect()` will require that `range()` give it some numbers, and so +it will do the work of generating the sequence. + +`range` is one of two basic iterators that you'll see. The other is `iter()`, +which you've used before. `iter()` can turn a vector into a simple iterator +that gives you each element in turn: + +```{rust} +let nums = [1i, 2i, 3i]; + +for num in nums.iter() { + println!("{}", num); +} +``` + +These two basic iterators should serve you well. There are some more +advanced iterators, including ones that are infinite. Like `count`: + +```{rust} +std::iter::count(1i, 5i); +``` + +This iterator counts up from one, adding five each time. It will give +you a new integer every time, forever (well, technically, until it reaches the +maximum number representable by an `int`). But since iterators are lazy, +that's okay! You probably don't want to use `collect()` on it, though... + +That's enough about iterators. Iterator adapters are the last concept +we need to talk about with regards to iterators. Let's get to it! + +## Iterator adapters + +"Iterator adapters" take an iterator and modify it somehow, producing +a new iterator. The simplest one is called `map`: + +```{rust,ignore} +range(1i, 100i).map(|x| x + 1i); +``` + +`map` is called upon another iterator, and produces a new iterator where each +element reference has the closure it's been given as an argument called on it. +So this would give us the numbers from `2-100`. Well, almost! If you +compile the example, you'll get a warning: + +```{notrust,ignore} +warning: unused result which must be used: iterator adaptors are lazy and + do nothing unless consumed, #[warn(unused_must_use)] on by default + range(1i, 100i).map(|x| x + 1i); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +Laziness strikes again! That closure will never execute. This example +doesn't print any numbers: + +```{rust,ignore} +range(1i, 100i).map(|x| println!("{}", x)); +``` + +If you are trying to execute a closure on an iterator for its side effects, +just use `for` instead. + +There are tons of interesting iterator adapters. `take(n)` will return an +iterator over the next `n` elements of the original iterator, note that this +has no side effect on the original iterator. Let's try it out with our infinite +iterator from before, `count()`: + +```{rust} +for i in std::iter::count(1i, 5i).take(5) { + println!("{}", i); +} +``` + +This will print + +```{notrust,ignore} +1 +6 +11 +16 +21 +``` + +`filter()` is an adapter that takes a closure as an argument. This closure +returns `true` or `false`. The new iterator `filter()` produces +only the elements that that closure returns `true` for: + +```{rust} +for i in range(1i, 100i).filter(|&x| x % 2 == 0) { + println!("{}", i); +} +``` + +This will print all of the even numbers between one and a hundred. +(Note that because `filter` doesn't consume the elements that are +being iterated over, it is passed a reference to each element, and +thus the filter predicate uses the `&x` pattern to extract the integer +itself.) + +You can chain all three things together: start with an iterator, adapt it +a few times, and then consume the result. Check it out: + +```{rust} +range(1i, 1000i) + .filter(|&x| x % 2 == 0) + .filter(|&x| x % 3 == 0) + .take(5) + .collect::>(); +``` + +This will give you a vector containing `6`, `12`, `18`, `24`, and `30`. + +This is just a small taste of what iterators, iterator adapters, and consumers +can help you with. There are a number of really useful iterators, and you can +write your own as well. Iterators provide a safe, efficient way to manipulate +all kinds of lists. They're a little unusual at first, but if you play with +them, you'll get hooked. For a full list of the different iterators and +consumers, check out the [iterator module documentation](std/iter/index.html). diff --git a/src/doc/trpl/src/looping.md b/src/doc/trpl/src/looping.md new file mode 100644 index 0000000000000..03384b287030c --- /dev/null +++ b/src/doc/trpl/src/looping.md @@ -0,0 +1,133 @@ +# Looping + +Looping is the last basic construct that we haven't learned yet in Rust. Rust has +two main looping constructs: `for` and `while`. + +## `for` + +The `for` loop is used to loop a particular number of times. Rust's `for` loops +work a bit differently than in other systems languages, however. Rust's `for` +loop doesn't look like this "C-style" `for` loop: + +```{c} +for (x = 0; x < 10; x++) { + printf( "%d\n", x ); +} +``` + +Instead, it looks like this: + +```{rust} +for x in range(0, 10) { + println!("{}", x); // x: i32 +} +``` + +In slightly more abstract terms, + +```{ignore} +for var in expression { + code +} +``` + +The expression is an iterator, which we will discuss in more depth later in the +guide. The iterator gives back a series of elements. Each element is one +iteration of the loop. That value is then bound to the name `var`, which is +valid for the loop body. Once the body is over, the next value is fetched from +the iterator, and we loop another time. When there are no more values, the +`for` loop is over. + +In our example, `range` is a function that takes a start and an end position, +and gives an iterator over those values. The upper bound is exclusive, though, +so our loop will print `0` through `9`, not `10`. + +Rust does not have the "C-style" `for` loop on purpose. Manually controlling +each element of the loop is complicated and error prone, even for experienced C +developers. + +We'll talk more about `for` when we cover **iterator**s, later in the Guide. + +## `while` + +The other kind of looping construct in Rust is the `while` loop. It looks like +this: + +```{rust} +let mut x = 5u; // mut x: uint +let mut done = false; // mut done: bool + +while !done { + x += x - 3; + println!("{}", x); + if x % 5 == 0 { done = true; } +} +``` + +`while` loops are the correct choice when you're not sure how many times +you need to loop. + +If you need an infinite loop, you may be tempted to write this: + +```{rust,ignore} +while true { +``` + +However, Rust has a dedicated keyword, `loop`, to handle this case: + +```{rust,ignore} +loop { +``` + +Rust's control-flow analysis treats this construct differently than a +`while true`, since we know that it will always loop. The details of what +that _means_ aren't super important to understand at this stage, but in +general, the more information we can give to the compiler, the better it +can do with safety and code generation, so you should always prefer +`loop` when you plan to loop infinitely. + +## Ending iteration early + +Let's take a look at that `while` loop we had earlier: + +```{rust} +let mut x = 5u; +let mut done = false; + +while !done { + x += x - 3; + println!("{}", x); + if x % 5 == 0 { done = true; } +} +``` + +We had to keep a dedicated `mut` boolean variable binding, `done`, to know +when we should exit out of the loop. Rust has two keywords to help us with +modifying iteration: `break` and `continue`. + +In this case, we can write the loop in a better way with `break`: + +```{rust} +let mut x = 5u; + +loop { + x += x - 3; + println!("{}", x); + if x % 5 == 0 { break; } +} +``` + +We now loop forever with `loop` and use `break` to break out early. + +`continue` is similar, but instead of ending the loop, goes to the next +iteration. This will only print the odd numbers: + +```{rust} +for x in range(0, 10) { + if x % 2 == 0 { continue; } + + println!("{}", x); +} +``` + +Both `continue` and `break` are valid in both kinds of loops. diff --git a/src/doc/guide-macros.md b/src/doc/trpl/src/macros.md similarity index 100% rename from src/doc/guide-macros.md rename to src/doc/trpl/src/macros.md diff --git a/src/doc/trpl/src/match.md b/src/doc/trpl/src/match.md new file mode 100644 index 0000000000000..0170109def022 --- /dev/null +++ b/src/doc/trpl/src/match.md @@ -0,0 +1,156 @@ +# Match + +Often, a simple `if`/`else` isn't enough, because you have more than two +possible options. Also, `else` conditions can get incredibly complicated, so +what's the solution? + +Rust has a keyword, `match`, that allows you to replace complicated `if`/`else` +groupings with something more powerful. Check it out: + +```{rust} +let x = 5; + +match x { + 1 => println!("one"), + 2 => println!("two"), + 3 => println!("three"), + 4 => println!("four"), + 5 => println!("five"), + _ => println!("something else"), +} +``` + +`match` takes an expression and then branches based on its value. Each 'arm' of +the branch is of the form `val => expression`. When the value matches, that arm's +expression will be evaluated. It's called `match` because of the term 'pattern +matching', which `match` is an implementation of. + +So what's the big advantage here? Well, there are a few. First of all, `match` +enforces 'exhaustiveness checking'. Do you see that last arm, the one with the +underscore (`_`)? If we remove that arm, Rust will give us an error: + +```text +error: non-exhaustive patterns: `_` not covered +``` + +In other words, Rust is trying to tell us we forgot a value. Because `x` is an +integer, Rust knows that it can have a number of different values – for example, +`6`. Without the `_`, however, there is no arm that could match, and so Rust refuses +to compile. `_` acts like a 'catch-all arm'. If none of the other arms match, +the arm with `_` will, and since we have this catch-all arm, we now have an arm +for every possible value of `x`, and so our program will compile successfully. + +`match` statements also destructure enums, as well. Remember this code from the +section on enums? + +```{rust} +use std::cmp::Ordering; + +fn cmp(a: i32, b: i32) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} + +fn main() { + let x = 5; + let y = 10; + + let ordering = cmp(x, y); + + if ordering == Ordering::Less { + println!("less"); + } else if ordering == Ordering::Greater { + println!("greater"); + } else if ordering == Ordering::Equal { + println!("equal"); + } +} +``` + +We can re-write this as a `match`: + +```{rust} +use std::cmp::Ordering; + +fn cmp(a: i32, b: i32) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} + +fn main() { + let x = 5; + let y = 10; + + match cmp(x, y) { + Ordering::Less => println!("less"), + Ordering::Greater => println!("greater"), + Ordering::Equal => println!("equal"), + } +} +``` + +This version has way less noise, and it also checks exhaustively to make sure +that we have covered all possible variants of `Ordering`. With our `if`/`else` +version, if we had forgotten the `Greater` case, for example, our program would +have happily compiled. If we forget in the `match`, it will not. Rust helps us +make sure to cover all of our bases. + +`match` expressions also allow us to get the values contained in an `enum` +(also known as destructuring) as follows: + +```{rust} +enum OptionalInt { + Value(i32), + Missing, +} + +fn main() { + let x = OptionalInt::Value(5); + let y = OptionalInt::Missing; + + match x { + OptionalInt::Value(n) => println!("x is {}", n), + OptionalInt::Missing => println!("x is missing!"), + } + + match y { + OptionalInt::Value(n) => println!("y is {}", n), + OptionalInt::Missing => println!("y is missing!"), + } +} +``` + +That is how you can get and use the values contained in `enum`s. +It can also allow us to handle errors or unexpected computations; for example, a +function that is not guaranteed to be able to compute a result (an `i32` here) +could return an `OptionalInt`, and we would handle that value with a `match`. +As you can see, `enum` and `match` used together are quite useful! + +`match` is also an expression, which means we can use it on the right-hand +side of a `let` binding or directly where an expression is used. We could +also implement the previous example like this: + +```{rust} +use std::cmp::Ordering; + +fn cmp(a: i32, b: i32) -> Ordering { + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } +} + +fn main() { + let x = 5; + let y = 10; + + println!("{}", match cmp(x, y) { + Ordering::Less => "less", + Ordering::Greater => "greater", + Ordering::Equal => "equal", + }); +} +``` + +Sometimes, it's a nice pattern. diff --git a/src/doc/trpl/src/method-syntax.md b/src/doc/trpl/src/method-syntax.md new file mode 100644 index 0000000000000..54e9cdf519115 --- /dev/null +++ b/src/doc/trpl/src/method-syntax.md @@ -0,0 +1,88 @@ +% Method Syntax + +Functions are great, but if you want to call a bunch of them on some data, it +can be awkward. Consider this code: + +```{rust,ignore} +baz(bar(foo(x))); +``` + +We would read this left-to right, and so we see 'baz bar foo.' But this isn't the +order that the functions would get called in, that's inside-out: 'foo bar baz.' +Wouldn't it be nice if we could do this instead? + +```{rust,ignore} +x.foo().bar().baz(); +``` + +Luckily, as you may have guessed with the leading question, you can! Rust provides +the ability to use this **method call syntax** via the `impl` keyword. + +Here's how it works: + +```{rust} +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl Circle { + fn area(&self) -> f64 { + std::f64::consts::PI * (self.radius * self.radius) + } +} + +fn main() { + let c = Circle { x: 0.0, y: 0.0, radius: 2.0 }; + println!("{}", c.area()); +} +``` + +This will print `12.566371`. + +We've made a struct that represents a circle. We then write an `impl` block, +and inside it, define a method, `area`. Methods take a special first +parameter, `&self`. There are three variants: `self`, `&self`, and `&mut self`. +You can think of this first parameter as being the `x` in `x.foo()`. The three +variants correspond to the three kinds of thing `x` could be: `self` if it's +just a value on the stack, `&self` if it's a reference, and `&mut self` if it's +a mutable reference. We should default to using `&self`, as it's the most +common. + +Finally, as you may remember, the value of the area of a circle is `π*r²`. +Because we took the `&self` parameter to `area`, we can use it just like any +other parameter. Because we know it's a `Circle`, we can access the `radius` +just like we would with any other struct. An import of π and some +multiplications later, and we have our area. + +You can also define methods that do not take a `self` parameter. Here's a +pattern that's very common in Rust code: + +```{rust} +# #![allow(non_shorthand_field_patterns)] +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl Circle { + fn new(x: f64, y: f64, radius: f64) -> Circle { + Circle { + x: x, + y: y, + radius: radius, + } + } +} + +fn main() { + let c = Circle::new(0.0, 0.0, 2.0); +} +``` + +This **static method** builds a new `Circle` for us. Note that static methods +are called with the `Struct::method()` syntax, rather than the `ref.method()` +syntax. + diff --git a/src/doc/guide-ownership.md b/src/doc/trpl/src/ownership.md similarity index 100% rename from src/doc/guide-ownership.md rename to src/doc/trpl/src/ownership.md diff --git a/src/doc/trpl/src/patterns.md b/src/doc/trpl/src/patterns.md new file mode 100644 index 0000000000000..282703c43874c --- /dev/null +++ b/src/doc/trpl/src/patterns.md @@ -0,0 +1,199 @@ +% Patterns + +We've made use of patterns a few times in the guide: first with `let` bindings, +then with `match` statements. Let's go on a whirlwind tour of all of the things +patterns can do! + +A quick refresher: you can match against literals directly, and `_` acts as an +'any' case: + +```{rust} +let x = 1i; + +match x { + 1 => println!("one"), + 2 => println!("two"), + 3 => println!("three"), + _ => println!("anything"), +} +``` + +You can match multiple patterns with `|`: + +```{rust} +let x = 1i; + +match x { + 1 | 2 => println!("one or two"), + 3 => println!("three"), + _ => println!("anything"), +} +``` + +You can match a range of values with `...`: + +```{rust} +let x = 1i; + +match x { + 1 ... 5 => println!("one through five"), + _ => println!("anything"), +} +``` + +Ranges are mostly used with integers and single characters. + +If you're matching multiple things, via a `|` or a `...`, you can bind +the value to a name with `@`: + +```{rust} +let x = 1i; + +match x { + e @ 1 ... 5 => println!("got a range element {}", e), + _ => println!("anything"), +} +``` + +If you're matching on an enum which has variants, you can use `..` to +ignore the value and type in the variant: + +```{rust} +enum OptionalInt { + Value(int), + Missing, +} + +let x = OptionalInt::Value(5i); + +match x { + OptionalInt::Value(..) => println!("Got an int!"), + OptionalInt::Missing => println!("No such luck."), +} +``` + +You can introduce **match guards** with `if`: + +```{rust} +enum OptionalInt { + Value(int), + Missing, +} + +let x = OptionalInt::Value(5i); + +match x { + OptionalInt::Value(i) if i > 5 => println!("Got an int bigger than five!"), + OptionalInt::Value(..) => println!("Got an int!"), + OptionalInt::Missing => println!("No such luck."), +} +``` + +If you're matching on a pointer, you can use the same syntax as you declared it +with. First, `&`: + +```{rust} +let x = &5i; + +match x { + &val => println!("Got a value: {}", val), +} +``` + +Here, the `val` inside the `match` has type `int`. In other words, the left-hand +side of the pattern destructures the value. If we have `&5i`, then in `&val`, `val` +would be `5i`. + +If you want to get a reference, use the `ref` keyword: + +```{rust} +let x = 5i; + +match x { + ref r => println!("Got a reference to {}", r), +} +``` + +Here, the `r` inside the `match` has the type `&int`. In other words, the `ref` +keyword _creates_ a reference, for use in the pattern. If you need a mutable +reference, `ref mut` will work in the same way: + +```{rust} +let mut x = 5i; + +match x { + ref mut mr => println!("Got a mutable reference to {}", mr), +} +``` + +If you have a struct, you can destructure it inside of a pattern: + +```{rust} +# #![allow(non_shorthand_field_patterns)] +struct Point { + x: int, + y: int, +} + +let origin = Point { x: 0i, y: 0i }; + +match origin { + Point { x: x, y: y } => println!("({},{})", x, y), +} +``` + +If we only care about some of the values, we don't have to give them all names: + +```{rust} +# #![allow(non_shorthand_field_patterns)] +struct Point { + x: int, + y: int, +} + +let origin = Point { x: 0i, y: 0i }; + +match origin { + Point { x: x, .. } => println!("x is {}", x), +} +``` + +You can do this kind of match on any member, not just the first: + +```{rust} +# #![allow(non_shorthand_field_patterns)] +struct Point { + x: int, + y: int, +} + +let origin = Point { x: 0i, y: 0i }; + +match origin { + Point { y: y, .. } => println!("y is {}", y), +} +``` + +If you want to match against a slice or array, you can use `[]`: + +```{rust} +fn main() { + let v = vec!["match_this", "1"]; + + match v.as_slice() { + ["match_this", second] => println!("The second element is {}", second), + _ => {}, + } +} +``` + +Whew! That's a lot of different ways to match things, and they can all be +mixed and matched, depending on what you're doing: + +```{rust,ignore} +match x { + Foo { x: Some(ref name), y: None } => ... +} +``` + +Patterns are very powerful. Make good use of them. diff --git a/src/doc/guide-plugin.md b/src/doc/trpl/src/plugins.md similarity index 100% rename from src/doc/guide-plugin.md rename to src/doc/trpl/src/plugins.md diff --git a/src/doc/guide-pointers.md b/src/doc/trpl/src/pointers.md similarity index 100% rename from src/doc/guide-pointers.md rename to src/doc/trpl/src/pointers.md diff --git a/src/doc/trpl/src/standard-input.md b/src/doc/trpl/src/standard-input.md new file mode 100644 index 0000000000000..5a150594f0c0b --- /dev/null +++ b/src/doc/trpl/src/standard-input.md @@ -0,0 +1,159 @@ +# Standard Input + +Getting input from the keyboard is pretty easy, but uses some things +we haven't seen before. Here's a simple program that reads some input, +and then prints it back out: + +```{rust,ignore} +fn main() { + println!("Type something!"); + + let input = std::io::stdin().read_line().ok().expect("Failed to read line"); + + println!("{}", input); +} +``` + +Let's go over these chunks, one by one: + +```{rust,ignore} +std::io::stdin(); +``` + +This calls a function, `stdin()`, that lives inside the `std::io` module. As +you can imagine, everything in `std` is provided by Rust, the 'standard +library.' We'll talk more about the module system later. + +Since writing the fully qualified name all the time is annoying, we can use +the `use` statement to import it in: + +```{rust} +use std::io::stdin; + +stdin(); +``` + +However, it's considered better practice to not import individual functions, but +to import the module, and only use one level of qualification: + +```{rust} +use std::io; + +io::stdin(); +``` + +Let's update our example to use this style: + +```{rust,ignore} +use std::io; + +fn main() { + println!("Type something!"); + + let input = io::stdin().read_line().ok().expect("Failed to read line"); + + println!("{}", input); +} +``` + +Next up: + +```{rust,ignore} +.read_line() +``` + +The `read_line()` method can be called on the result of `stdin()` to return +a full line of input. Nice and easy. + +```{rust,ignore} +.ok().expect("Failed to read line"); +``` + +Do you remember this code? + +```{rust} +enum OptionalInt { + Value(i32), + Missing, +} + +fn main() { + let x = OptionalInt::Value(5); + let y = OptionalInt::Missing; + + match x { + OptionalInt::Value(n) => println!("x is {}", n), + OptionalInt::Missing => println!("x is missing!"), + } + + match y { + OptionalInt::Value(n) => println!("y is {}", n), + OptionalInt::Missing => println!("y is missing!"), + } +} +``` + +We had to match each time to see if we had a value or not. In this case, +though, we _know_ that `x` has a `Value`, but `match` forces us to handle +the `missing` case. This is what we want 99% of the time, but sometimes, we +know better than the compiler. + +Likewise, `read_line()` does not return a line of input. It _might_ return a +line of input, though it might also fail to do so. This could happen if our program +isn't running in a terminal, but as part of a cron job, or some other context +where there's no standard input. Because of this, `read_line` returns a type +very similar to our `OptionalInt`: an `IoResult`. We haven't talked about +`IoResult` yet because it is the **generic** form of our `OptionalInt`. +Until then, you can think of it as being the same thing, just for any type – +not just `i32`s. + +Rust provides a method on these `IoResult`s called `ok()`, which does the +same thing as our `match` statement but assumes that we have a valid value. +We then call `expect()` on the result, which will terminate our program if we +don't have a valid value. In this case, if we can't get input, our program +doesn't work, so we're okay with that. In most cases, we would want to handle +the error case explicitly. `expect()` allows us to give an error message if +this crash happens. + +We will cover the exact details of how all of this works later in the Guide. +For now, this gives you enough of a basic understanding to work with. + +Back to the code we were working on! Here's a refresher: + +```{rust,ignore} +use std::io; + +fn main() { + println!("Type something!"); + + let input = io::stdin().read_line().ok().expect("Failed to read line"); + + println!("{}", input); +} +``` + +With long lines like this, Rust gives you some flexibility with the whitespace. +We _could_ write the example like this: + +```{rust,ignore} +use std::io; + +fn main() { + println!("Type something!"); + + // here, we'll show the types at each step + + let input = io::stdin() // std::io::stdio::StdinReader + .read_line() // IoResult + .ok() // Option + .expect("Failed to read line"); // String + + println!("{}", input); +} +``` + +Sometimes, this makes things more readable – sometimes, less. Use your judgement +here. + +That's all you need to get basic input from the standard input! It's not too +complicated, but there are a number of small parts. diff --git a/src/doc/trpl/src/strings.md b/src/doc/trpl/src/strings.md new file mode 100644 index 0000000000000..be1d09f6e9530 --- /dev/null +++ b/src/doc/trpl/src/strings.md @@ -0,0 +1,79 @@ +# Strings + +Strings are an important concept for any programmer to master. Rust's string +handling system is a bit different from other languages, due to its systems +focus. Any time you have a data structure of variable size, things can get +tricky, and strings are a re-sizable data structure. That being said, Rust's +strings also work differently than in some other systems languages, such as C. + +Let's dig into the details. A **string** is a sequence of Unicode scalar values +encoded as a stream of UTF-8 bytes. All strings are guaranteed to be +validly encoded UTF-8 sequences. Additionally, strings are not null-terminated +and can contain null bytes. + +Rust has two main types of strings: `&str` and `String`. + +The first kind is a `&str`. This is pronounced a 'string slice.' String literals +are of the type `&str`: + +```{rust} +let string = "Hello there."; // string: &str +``` + +This string is statically allocated, meaning that it's saved inside our +compiled program, and exists for the entire duration it runs. The `string` +binding is a reference to this statically allocated string. String slices +have a fixed size, and cannot be mutated. + +A `String`, on the other hand, is an in-memory string. This string is +growable, and is also guaranteed to be UTF-8. + +```{rust} +let mut s = "Hello".to_string(); // mut s: String +println!("{}", s); + +s.push_str(", world."); +println!("{}", s); +``` + +You can get a `&str` view into a `String` with the `as_slice()` method: + +```{rust} +fn takes_slice(slice: &str) { + println!("Got: {}", slice); +} + +fn main() { + let s = "Hello".to_string(); + takes_slice(s.as_slice()); +} +``` + +To compare a String to a constant string, prefer `as_slice()`... + +```{rust} +fn compare(string: String) { + if string.as_slice() == "Hello" { + println!("yes"); + } +} +``` + +... over `to_string()`: + +```{rust} +fn compare(string: String) { + if string == "Hello".to_string() { + println!("yes"); + } +} +``` + +Viewing a `String` as a `&str` is cheap, but converting the `&str` to a +`String` involves allocating memory. No reason to do that unless you have to! + +That's the basics of strings in Rust! They're probably a bit more complicated +than you are used to, if you come from a scripting language, but when the +low-level details matter, they really matter. Just remember that `String`s +allocate memory and control their data, while `&str`s are a reference to +another string, and you'll be all set. diff --git a/src/doc/guide-tasks.md b/src/doc/trpl/src/tasks.md similarity index 100% rename from src/doc/guide-tasks.md rename to src/doc/trpl/src/tasks.md diff --git a/src/doc/guide-testing.md b/src/doc/trpl/src/testing.md similarity index 100% rename from src/doc/guide-testing.md rename to src/doc/trpl/src/testing.md diff --git a/src/doc/trpl/src/traits.md b/src/doc/trpl/src/traits.md new file mode 100644 index 0000000000000..04c644da2abbc --- /dev/null +++ b/src/doc/trpl/src/traits.md @@ -0,0 +1,317 @@ +% Traits + +Do you remember the `impl` keyword, used to call a function with method +syntax? + +```{rust} +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl Circle { + fn area(&self) -> f64 { + std::f64::consts::PI * (self.radius * self.radius) + } +} +``` + +Traits are similar, except that we define a trait with just the method +signature, then implement the trait for that struct. Like this: + +```{rust} +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +trait HasArea { + fn area(&self) -> f64; +} + +impl HasArea for Circle { + fn area(&self) -> f64 { + std::f64::consts::PI * (self.radius * self.radius) + } +} +``` + +As you can see, the `trait` block looks very similar to the `impl` block, +but we don't define a body, just a type signature. When we `impl` a trait, +we use `impl Trait for Item`, rather than just `impl Item`. + +So what's the big deal? Remember the error we were getting with our generic +`inverse` function? + +```text +error: binary operation `==` cannot be applied to type `T` +``` + +We can use traits to constrain our generics. Consider this function, which +does not compile, and gives us a similar error: + +```{rust,ignore} +fn print_area(shape: T) { + println!("This shape has an area of {}", shape.area()); +} +``` + +Rust complains: + +```text +error: type `T` does not implement any method in scope named `area` +``` + +Because `T` can be any type, we can't be sure that it implements the `area` +method. But we can add a **trait constraint** to our generic `T`, ensuring +that it does: + +```{rust} +# trait HasArea { +# fn area(&self) -> f64; +# } +fn print_area(shape: T) { + println!("This shape has an area of {}", shape.area()); +} +``` + +The syntax `` means `any type that implements the HasArea trait`. +Because traits define function type signatures, we can be sure that any type +which implements `HasArea` will have an `.area()` method. + +Here's an extended example of how this works: + +```{rust} +trait HasArea { + fn area(&self) -> f64; +} + +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl HasArea for Circle { + fn area(&self) -> f64 { + std::f64::consts::PI * (self.radius * self.radius) + } +} + +struct Square { + x: f64, + y: f64, + side: f64, +} + +impl HasArea for Square { + fn area(&self) -> f64 { + self.side * self.side + } +} + +fn print_area(shape: T) { + println!("This shape has an area of {}", shape.area()); +} + +fn main() { + let c = Circle { + x: 0.0f64, + y: 0.0f64, + radius: 1.0f64, + }; + + let s = Square { + x: 0.0f64, + y: 0.0f64, + side: 1.0f64, + }; + + print_area(c); + print_area(s); +} +``` + +This program outputs: + +```text +This shape has an area of 3.141593 +This shape has an area of 1 +``` + +As you can see, `print_area` is now generic, but also ensures that we +have passed in the correct types. If we pass in an incorrect type: + +```{rust,ignore} +print_area(5i); +``` + +We get a compile-time error: + +```text +error: failed to find an implementation of trait main::HasArea for int +``` + +So far, we've only added trait implementations to structs, but you can +implement a trait for any type. So technically, we _could_ implement +`HasArea` for `int`: + +```{rust} +trait HasArea { + fn area(&self) -> f64; +} + +impl HasArea for int { + fn area(&self) -> f64 { + println!("this is silly"); + + *self as f64 + } +} + +5i.area(); +``` + +It is considered poor style to implement methods on such primitive types, even +though it is possible. + +This may seem like the Wild West, but there are two other restrictions around +implementing traits that prevent this from getting out of hand. First, traits +must be `use`d in any scope where you wish to use the trait's method. So for +example, this does not work: + +```{rust,ignore} +mod shapes { + use std::f64::consts; + + trait HasArea { + fn area(&self) -> f64; + } + + struct Circle { + x: f64, + y: f64, + radius: f64, + } + + impl HasArea for Circle { + fn area(&self) -> f64 { + consts::PI * (self.radius * self.radius) + } + } +} + +fn main() { + let c = shapes::Circle { + x: 0.0f64, + y: 0.0f64, + radius: 1.0f64, + }; + + println!("{}", c.area()); +} +``` + +Now that we've moved the structs and traits into their own module, we get an +error: + +```text +error: type `shapes::Circle` does not implement any method in scope named `area` +``` + +If we add a `use` line right above `main` and make the right things public, +everything is fine: + +```{rust} +use shapes::HasArea; + +mod shapes { + use std::f64::consts; + + pub trait HasArea { + fn area(&self) -> f64; + } + + pub struct Circle { + pub x: f64, + pub y: f64, + pub radius: f64, + } + + impl HasArea for Circle { + fn area(&self) -> f64 { + consts::PI * (self.radius * self.radius) + } + } +} + + +fn main() { + let c = shapes::Circle { + x: 0.0f64, + y: 0.0f64, + radius: 1.0f64, + }; + + println!("{}", c.area()); +} +``` + +This means that even if someone does something bad like add methods to `int`, +it won't affect you, unless you `use` that trait. + +There's one more restriction on implementing traits. Either the trait or the +type you're writing the `impl` for must be inside your crate. So, we could +implement the `HasArea` type for `int`, because `HasArea` is in our crate. But +if we tried to implement `Float`, a trait provided by Rust, for `int`, we could +not, because both the trait and the type aren't in our crate. + +One last thing about traits: generic functions with a trait bound use +**monomorphization** ("mono": one, "morph": form), so they are statically +dispatched. What's that mean? Well, let's take a look at `print_area` again: + +```{rust,ignore} +fn print_area(shape: T) { + println!("This shape has an area of {}", shape.area()); +} + +fn main() { + let c = Circle { ... }; + + let s = Square { ... }; + + print_area(c); + print_area(s); +} +``` + +When we use this trait with `Circle` and `Square`, Rust ends up generating +two different functions with the concrete type, and replacing the call sites with +calls to the concrete implementations. In other words, you get something like +this: + +```{rust,ignore} +fn __print_area_circle(shape: Circle) { + println!("This shape has an area of {}", shape.area()); +} + +fn __print_area_square(shape: Square) { + println!("This shape has an area of {}", shape.area()); +} + +fn main() { + let c = Circle { ... }; + + let s = Square { ... }; + + __print_area_circle(c); + __print_area_square(s); +} +``` + +The names don't actually change to this, it's just for illustration. But +as you can see, there's no overhead of deciding which version to call here, +hence 'statically dispatched.' The downside is that we have two copies of +the same function, so our binary is a little bit larger. diff --git a/src/doc/guide-unsafe.md b/src/doc/trpl/src/unsafe.md similarity index 100% rename from src/doc/guide-unsafe.md rename to src/doc/trpl/src/unsafe.md diff --git a/src/doc/trpl/src/variable-bindings.md b/src/doc/trpl/src/variable-bindings.md new file mode 100644 index 0000000000000..8cf2522b9afec --- /dev/null +++ b/src/doc/trpl/src/variable-bindings.md @@ -0,0 +1,174 @@ +# Variable bindings + +The first thing we'll learn about are 'variable bindings.' They look like this: + +```{rust} +fn main() { + let x = 5; +} +``` + +Putting `fn main() {` in each example is a bit tedious, so we'll leave that out +in the future. If you're following along, make sure to edit your `main()` +function, rather than leaving it off. Otherwise, you'll get an error. + +In many languages, this is called a 'variable.' But Rust's variable bindings +have a few tricks up their sleeves. Rust has a very powerful feature called +'pattern matching' that we'll get into detail with later, but the left +hand side of a `let` expression is a full pattern, not just a variable name. +This means we can do things like: + +```{rust} +let (x, y) = (1, 2); +``` + +After this expression is evaluated, `x` will be one, and `y` will be two. +Patterns are really powerful, but this is about all we can do with them so far. +So let's just keep this in the back of our minds as we go forward. + +Rust is a statically typed language, which means that we specify our types up +front. So why does our first example compile? Well, Rust has this thing called +"type inference." If it can figure out what the type of something is, Rust +doesn't require you to actually type it out. + +We can add the type if we want to, though. Types come after a colon (`:`): + +```{rust} +let x: i32 = 5; +``` + +If I asked you to read this out loud to the rest of the class, you'd say "`x` +is a binding with the type `i32` and the value `five`." + +In future examples, we may annotate the type in a comment. The examples will +look like this: + +```{rust} +fn main() { + let x = 5; // x: i32 +} +``` + +Note the similarities between this annotation and the syntax you use with `let`. +Including these kinds of comments is not idiomatic Rust, but we'll occasionally +include them to help you understand what the types that Rust infers are. + +By default, bindings are **immutable**. This code will not compile: + +```{ignore} +let x = 5; +x = 10; +``` + +It will give you this error: + +```text +error: re-assignment of immutable variable `x` + x = 10; + ^~~~~~~ +``` + +If you want a binding to be mutable, you can use `mut`: + +```{rust} +let mut x = 5; // mut x: i32 +x = 10; +``` + +There is no single reason that bindings are immutable by default, but we can +think about it through one of Rust's primary focuses: safety. If you forget to +say `mut`, the compiler will catch it, and let you know that you have mutated +something you may not have intended to mutate. If bindings were mutable by +default, the compiler would not be able to tell you this. If you _did_ intend +mutation, then the solution is quite easy: add `mut`. + +There are other good reasons to avoid mutable state when possible, but they're +out of the scope of this guide. In general, you can often avoid explicit +mutation, and so it is preferable in Rust. That said, sometimes, mutation is +what you need, so it's not verboten. + +Let's get back to bindings. Rust variable bindings have one more aspect that +differs from other languages: bindings are required to be initialized with a +value before you're allowed to use them. If we try... + +```{ignore} +let x; +``` + +...we'll get an error: + +```text +src/main.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type +src/main.rs:2 let x; + ^ +``` + +Giving it a type will compile, though: + +```{rust} +let x: i32; +``` + +Let's try it out. Change your `src/main.rs` file to look like this: + +```{rust} +fn main() { + let x: i32; + + println!("Hello world!"); +} +``` + +You can use `cargo build` on the command line to build it. You'll get a warning, +but it will still print "Hello, world!": + +```text + Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world) +src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default +src/main.rs:2 let x: i32; + ^ +``` + +Rust warns us that we never use the variable binding, but since we never use it, +no harm, no foul. Things change if we try to actually use this `x`, however. Let's +do that. Change your program to look like this: + +```{rust,ignore} +fn main() { + let x: i32; + + println!("The value of x is: {}", x); +} +``` + +And try to build it. You'll get an error: + +```{bash} +$ cargo build + Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world) +src/main.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` +src/main.rs:4 println!("The value of x is: {}", x); + ^ +note: in expansion of format_args! +:2:23: 2:77 note: expansion site +:1:1: 3:2 note: in expansion of println! +src/main.rs:4:5: 4:42 note: expansion site +error: aborting due to previous error +Could not compile `hello_world`. +``` + +Rust will not let us use a value that has not been initialized. Next, let's +talk about this stuff we've added to `println!`. + +If you include two curly braces (`{}`, some call them moustaches...) in your +string to print, Rust will interpret this as a request to interpolate some sort +of value. **String interpolation** is a computer science term that means "stick +in the middle of a string." We add a comma, and then `x`, to indicate that we +want `x` to be the value we're interpolating. The comma is used to separate +arguments we pass to functions and macros, if you're passing more than one. + +When you just use the curly braces, Rust will attempt to display the +value in a meaningful way by checking out its type. If you want to specify the +format in a more detailed manner, there are a [wide number of options +available](std/fmt/index.html). For now, we'll just stick to the default: +integers aren't very complicated to print. diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs new file mode 100644 index 0000000000000..45a864e337813 --- /dev/null +++ b/src/rustbook/book.rs @@ -0,0 +1,166 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Basic data structures for representing a book. + +use std::io::BufferedReader; +use std::iter; +use std::iter::AdditiveIterator; +use regex::Regex; + +pub struct BookItem { + pub title: String, + pub path: Path, + pub path_to_root: Path, + pub children: Vec, +} + +pub struct Book { + pub chapters: Vec, +} + +/// A depth-first iterator over a book. +pub struct BookItems<'a> { + cur_items: &'a [BookItem], + cur_idx: uint, + stack: Vec<(&'a [BookItem], uint)>, +} + +impl<'a> Iterator for BookItems<'a> { + type Item = (String, &'a BookItem); + + fn next(&mut self) -> Option<(String, &'a BookItem)> { + loop { + if self.cur_idx >= self.cur_items.len() { + match self.stack.pop() { + None => return None, + Some((parent_items, parent_idx)) => { + self.cur_items = parent_items; + self.cur_idx = parent_idx + 1; + } + } + } else { + let cur = self.cur_items.get(self.cur_idx).unwrap(); + + let mut section = "".to_string(); + for &(_, idx) in self.stack.iter() { + section.push_str(&(idx + 1).to_string()[]); + section.push('.'); + } + section.push_str(&(self.cur_idx + 1).to_string()[]); + section.push('.'); + + self.stack.push((self.cur_items, self.cur_idx)); + self.cur_items = &cur.children[]; + self.cur_idx = 0; + return Some((section, cur)) + } + } + } +} + +impl Book { + pub fn iter(&self) -> BookItems { + BookItems { + cur_items: &self.chapters[], + cur_idx: 0, + stack: Vec::new(), + } + } +} + +/// Construct a book by parsing a summary (markdown table of contents). +pub fn parse_summary(input: R, src: &Path) -> Result> { + fn collapse(stack: &mut Vec, + top_items: &mut Vec, + to_level: uint) { + loop { + if stack.len() < to_level { return } + if stack.len() == 1 { + top_items.push(stack.pop().unwrap()); + return; + } + + let tip = stack.pop().unwrap(); + let last = stack.len() - 1; + stack[last].children.push(tip); + } + } + + let regex = r"(?P[\t ]*)\*[:space:]*\[(?P.*)\]\((?P<path>.*)\)"; + let item_re = Regex::new(regex).unwrap(); + let mut top_items = vec!(); + let mut stack = vec!(); + let mut errors = vec!(); + + // always include the introduction + top_items.push(BookItem { + title: "Introduction".to_string(), + path: Path::new("README.md"), + path_to_root: Path::new("."), + children: vec!(), + }); + + for line_result in BufferedReader::new(input).lines() { + let line = match line_result { + Ok(line) => line, + Err(err) => { + errors.push(err.desc.to_string()); // FIXME: include detail + return Err(errors); + } + }; + + item_re.captures(&line[]).map(|cap| { + let given_path = cap.name("path"); + let title = cap.name("title").unwrap().to_string(); + + let path_from_root = match src.join(given_path.unwrap()).path_relative_from(src) { + Some(p) => p, + None => { + errors.push(format!("Paths in SUMMARY.md must be relative, \ + but path '{}' for section '{}' is not.", + given_path.unwrap(), title)); + Path::new("") + } + }; + let path_to_root = Path::new(iter::repeat("../") + .take(path_from_root.components().count() - 1) + .collect::<String>()); + let item = BookItem { + title: title, + path: path_from_root, + path_to_root: path_to_root, + children: vec!(), + }; + let level = cap.name("indent").unwrap().chars().map(|c| { + match c { + ' ' => 1u, + '\t' => 4, + _ => unreachable!() + } + }).sum() / 4 + 1; + + if level > stack.len() + 1 { + // FIXME: better error message + errors.push(format!("Section '{}' is indented too many levels.", item.title)); + } else if level <= stack.len() { + collapse(&mut stack, &mut top_items, level); + } + stack.push(item) + }); + } + + if errors.is_empty() { + collapse(&mut stack, &mut top_items, 1); + Ok(Book { chapters: top_items }) + } else { + Err(errors) + } +} diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs new file mode 100755 index 0000000000000..db79e0b45e00f --- /dev/null +++ b/src/rustbook/build.rs @@ -0,0 +1,191 @@ +// 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. + +//! Implementation of the `build` subcommand, used to compile a book. + +use std::os; +use std::io; +use std::io::{fs, File, BufferedWriter, TempDir, IoResult}; + +use subcommand::Subcommand; +use term::Term; +use error::{Error, CliResult, CommandResult}; +use book; +use book::{Book, BookItem}; +use css; + +use regex::Regex; + +use rustdoc; + +struct Build; + +pub fn parse_cmd(name: &str) -> Option<Box<Subcommand>> { + if name == "build" { + Some(box Build as Box<Subcommand>) + } else { + None + } +} + +fn write_toc(book: &Book, path_to_root: &Path, out: &mut Writer) -> IoResult<()> { + fn walk_items(items: &[BookItem], + section: &str, + path_to_root: &Path, + out: &mut Writer) -> IoResult<()> { + for (i, item) in items.iter().enumerate() { + try!(walk_item(item, &format!("{}{}.", section, i + 1)[], path_to_root, out)); + } + Ok(()) + } + fn walk_item(item: &BookItem, + section: &str, + path_to_root: &Path, + out: &mut Writer) -> IoResult<()> { + try!(writeln!(out, "<li><a href='{}'><b>{}</b> {}</a>", + path_to_root.join(item.path.with_extension("html")).display(), + section, + item.title)); + if !item.children.is_empty() { + try!(writeln!(out, "<ul class='section'>")); + let _ = walk_items(&item.children[], section, path_to_root, out); + try!(writeln!(out, "</ul>")); + } + try!(writeln!(out, "</li>")); + + Ok(()) + } + + try!(writeln!(out, "<div id='toc'>")); + try!(writeln!(out, "<ul class='chapter'>")); + try!(walk_items(&book.chapters[], "", path_to_root, out)); + try!(writeln!(out, "</ul>")); + try!(writeln!(out, "</div>")); + + Ok(()) +} + +fn render(book: &Book, tgt: &Path) -> CliResult<()> { + let tmp = TempDir::new("rust-book") + .ok() + // FIXME: lift to Result instead + .expect("could not create temporary directory"); + + for (section, item) in book.iter() { + println!("{} {}", section, item.title); + + let out_path = tgt.join(item.path.dirname()); + + let regex = r"\[(?P<title>[^]]*)\]\((?P<url_stem>[^)]*)\.(?P<ext>md|markdown)\)"; + let md_urls = Regex::new(regex).unwrap(); + + let src; + if os::args().len() < 3 { + src = os::getcwd().unwrap().clone(); + } else { + src = Path::new(os::args()[2].clone()); + } + // preprocess the markdown, rerouting markdown references to html references + let markdown_data = try!(File::open(&src.join(&item.path)).read_to_string()); + let preprocessed_path = tmp.path().join(item.path.filename().unwrap()); + { + let urls = md_urls.replace_all(&markdown_data[], "[$title]($url_stem.html)"); + try!(File::create(&preprocessed_path) + .write_str(&urls[])); + } + + // write the prelude to a temporary HTML file for rustdoc inclusion + let prelude = tmp.path().join("prelude.html"); + { + let mut toc = BufferedWriter::new(try!(File::create(&prelude))); + let _ = write_toc(book, &item.path_to_root, &mut toc); + try!(writeln!(&mut toc, "<div id='page-wrapper'>")); + try!(writeln!(&mut toc, "<div id='page'>")); + } + + // write the postlude to a temporary HTML file for rustdoc inclusion + let postlude = tmp.path().join("postlude.html"); + { + let mut toc = BufferedWriter::new(try!(File::create(&postlude))); + try!(writeln!(&mut toc, "</div></div>")); + } + + try!(fs::mkdir_recursive(&out_path, io::USER_DIR)); + + let rustdoc_args: &[String] = &[ + "".to_string(), + preprocessed_path.display().to_string(), + format!("-o{}", out_path.display()), + format!("--html-before-content={}", prelude.display()), + format!("--html-after-content={}", postlude.display()), + format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), + "--markdown-no-toc".to_string(), + ]; + let output_result = rustdoc::main_args(rustdoc_args); + if output_result != 0 { + + let message = format!("Could not execute `rustdoc`: {}", output_result); + return Err(box message as Box<Error>); + } + } + + // create index.html from the root README + try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html"))); + Ok(()) +} + +impl Subcommand for Build { + fn parse_args(&mut self, _: &[String]) -> CliResult<()> { + Ok(()) + } + fn usage(&self) {} + fn execute(&mut self, term: &mut Term) -> CommandResult<()> { + let cwd = os::getcwd().unwrap(); + let src; + let tgt; + + if os::args().len() < 3 { + src = cwd.clone(); + } else { + src = Path::new(os::args()[2].clone()); + } + + if os::args().len() < 4 { + tgt = cwd.join("_book"); + } else { + tgt = Path::new(os::args()[3].clone()); + } + + let _ = fs::mkdir(&tgt, io::USER_DIR); // FIXME: handle errors + + // FIXME: handle errors + let _ = File::create(&tgt.join("rust-book.css")).write_str(css::STYLE); + + let summary = File::open(&src.join("SUMMARY.md")); + match book::parse_summary(summary, &src) { + Ok(book) => { + // execute rustdoc on the whole book + let _ = render(&book, &tgt).map_err(|err| { + term.err(&format!("error: {}", err.description())[]); + err.detail().map(|detail| { + term.err(&format!("detail: {}", detail)[]); + }) + }); + } + Err(errors) => { + for err in errors.into_iter() { + term.err(&err[]); + } + } + } + + Ok(()) // lol + } +} diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs new file mode 100644 index 0000000000000..8eb66e71d3ad2 --- /dev/null +++ b/src/rustbook/css.rs @@ -0,0 +1,72 @@ +// 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. + +// The rust-book CSS in string form. + +pub static STYLE: &'static str = r#" +@import url("//static.rust-lang.org/doc/master/rust.css"); + +body { + max-width:none; +} + +#toc { + position: absolute; + left: 0px; + top: 0px; + bottom: 0px; + width: 250px; + overflow-y: auto; + border-right: 1px solid rgba(0, 0, 0, 0.07); + padding: 10px 10px; + font-size: 16px; + background: none repeat scroll 0% 0% #FFF; + box-sizing: border-box; +} + +#page-wrapper { + position: absolute; + overflow-y: auto; + left: 260px; + right: 0px; + top: 0px; + bottom: 0px; + box-sizing: border-box; + background: none repeat scroll 0% 0% #FFF; +} + +#page { + margin-left: auto; + margin-right:auto; + width: 750px; +} + +.chapter { + list-style: none outside none; + padding-left: 0px; + line-height: 30px; +} + +.section { + list-style: none outside none; + padding-left: 20px; + line-height: 30px; +} + +.section li { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + +.chapter li a { + color: #000000; +} +"#; diff --git a/src/rustbook/error.rs b/src/rustbook/error.rs new file mode 100644 index 0000000000000..1d3baef8c1c75 --- /dev/null +++ b/src/rustbook/error.rs @@ -0,0 +1,76 @@ +// 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. + +//! Error handling utilities. WIP. + +use std::fmt; +use std::fmt::{Show, Formatter}; + +use std::io::IoError; + +pub type CliError = Box<Error + 'static>; +pub type CliResult<T> = Result<T, CliError>; + +pub type CommandError = Box<Error + 'static>; +pub type CommandResult<T> = Result<T, CommandError>; + +pub trait Error { + fn description(&self) -> &str; + + fn detail(&self) -> Option<&str> { None } + fn cause(&self) -> Option<&Error> { None } +} + +pub trait FromError<E> { + fn from_err(err: E) -> Self; +} + +impl Show for Box<Error + 'static> { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "{}", self.description()) + } +} + +impl<E: Error + 'static> FromError<E> for Box<Error + 'static> { + fn from_err(err: E) -> Box<Error + 'static> { + box err as Box<Error> + } +} + +impl<'a> Error for &'a str { + fn description<'b>(&'b self) -> &'b str { + *self + } +} + +impl Error for String { + fn description<'a>(&'a self) -> &'a str { + &self[] + } +} + +impl FromError<()> for () { + fn from_err(_: ()) -> () { () } +} + +impl FromError<IoError> for IoError { + fn from_err(error: IoError) -> IoError { error } +} + +impl Error for IoError { + fn description(&self) -> &str { + self.desc + } + fn detail(&self) -> Option<&str> { + self.detail.as_ref().map(|s| &s[]) + } +} + +//fn iter_map_err<T, U, E, I: Iterator<Result<T,E>>>(iter: I, diff --git a/src/rustbook/help.rs b/src/rustbook/help.rs new file mode 100644 index 0000000000000..7fd8214f7311a --- /dev/null +++ b/src/rustbook/help.rs @@ -0,0 +1,46 @@ +// 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. + +//! Implementation of the `help` subcommand. Currently just prints basic usage info. + +use subcommand::Subcommand; +use error::CliResult; +use error::CommandResult; +use term::Term; + +struct Help; + +pub fn parse_cmd(name: &str) -> Option<Box<Subcommand>> { + match name { + "help" | "--help" | "-h" | "-?" => Some(box Help as Box<Subcommand>), + _ => None + } +} + +impl Subcommand for Help { + fn parse_args(&mut self, _: &[String]) -> CliResult<()> { + Ok(()) + } + fn usage(&self) {} + fn execute(&mut self, _: &mut Term) -> CommandResult<()> { + usage(); + Ok(()) + } +} + +pub fn usage() { + println!("Usage: rust-book <command> [<args>]"); + println!(""); + println!("The <command> must be one of:"); + println!(" help Print this message."); + println!(" build Build the book in subdirectory _book"); + println!(" serve --NOT YET IMPLEMENTED--"); + println!(" test --NOT YET IMPLEMENTED--"); +} diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs new file mode 100755 index 0000000000000..acb4edb7a4594 --- /dev/null +++ b/src/rustbook/main.rs @@ -0,0 +1,74 @@ +// 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. + +#![feature(slicing_syntax, box_syntax)] + +extern crate regex; + +extern crate rustdoc; + +use std::os; +use subcommand::Subcommand; +use term::Term; + +macro_rules! try ( + ($expr:expr) => ({ + use error; + match $expr { + Ok(val) => val, + Err(err) => return Err(error::FromError::from_err(err)) + } + }) +); + +mod term; +mod error; +mod book; + +mod subcommand; +mod help; +mod build; +mod serve; +mod test; + +mod css; + +#[cfg(not(test))] // thanks #12327 +fn main() { + let mut term = Term::new(); + let cmd = os::args(); + + if cmd.len() < 1 { + help::usage() + } else { + match subcommand::parse_name(&cmd[1][]) { + Some(mut subcmd) => { + match subcmd.parse_args(cmd.tail()) { + Ok(_) => { + match subcmd.execute(&mut term) { + Ok(_) => (), + Err(_) => os::set_exit_status(-1), + } + } + Err(err) => { + println!("{}", err.description()); + println!(""); + subcmd.usage(); + } + } + } + None => { + println!("Unrecognized command '{}'.", cmd[1]); + println!(""); + help::usage(); + } + } + } +} diff --git a/src/rustbook/serve.rs b/src/rustbook/serve.rs new file mode 100644 index 0000000000000..808527dcef95e --- /dev/null +++ b/src/rustbook/serve.rs @@ -0,0 +1,36 @@ +// 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. + +//! Implementation of the `serve` subcommand. Just a stub for now. + +use subcommand::Subcommand; +use error::CliResult; +use error::CommandResult; +use term::Term; + +struct Serve; + +pub fn parse_cmd(name: &str) -> Option<Box<Subcommand>> { + if name == "serve" { + Some(box Serve as Box<Subcommand>) + } else { + None + } +} + +impl Subcommand for Serve { + fn parse_args(&mut self, _: &[String]) -> CliResult<()> { + Ok(()) + } + fn usage(&self) {} + fn execute(&mut self, _: &mut Term) -> CommandResult<()> { + Ok(()) + } +} diff --git a/src/rustbook/subcommand.rs b/src/rustbook/subcommand.rs new file mode 100644 index 0000000000000..473739c919d64 --- /dev/null +++ b/src/rustbook/subcommand.rs @@ -0,0 +1,44 @@ +// 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. + +//! Common API for all rust-book subcommands. + +use error::CliResult; +use error::CommandResult; +use term::Term; + +use help; +use build; +use serve; +use test; + +pub trait Subcommand { + /// Mutate the subcommand by parsing its arguments. + /// + /// Returns `Err` on a parsing error. + fn parse_args(&mut self, args: &[String]) -> CliResult<()>; + /// Print the CLI usage information. + fn usage(&self); + /// Actually execute the subcommand. + fn execute(&mut self, term: &mut Term) -> CommandResult<()>; +} + +/// Create a Subcommand object based on its name. +pub fn parse_name(name: &str) -> Option<Box<Subcommand>> { + for parser in [ + help::parse_cmd as fn(&str) -> Option<Box<Subcommand>>, + build::parse_cmd as fn(&str) -> Option<Box<Subcommand>>, + serve::parse_cmd as fn(&str) -> Option<Box<Subcommand>>, + test::parse_cmd as fn(&str) -> Option<Box<Subcommand>>].iter() { + let parsed = (*parser)(name); + if parsed.is_some() { return parsed } + } + None +} diff --git a/src/rustbook/term.rs b/src/rustbook/term.rs new file mode 100644 index 0000000000000..18306d6ec20ba --- /dev/null +++ b/src/rustbook/term.rs @@ -0,0 +1,31 @@ +// 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. + +//! An abstraction of the terminal. Eventually, provide color and +//! verbosity support. For now, just a wrapper around stdout/stderr. + +use std::io::stdio; + +pub struct Term { + err: Box<Writer + 'static> +} + +impl Term { + pub fn new() -> Term { + Term { + err: box stdio::stderr() as Box<Writer>, + } + } + + pub fn err(&mut self, msg: &str) { + // swallow any errors + let _ = self.err.write_line(msg); + } +} diff --git a/src/rustbook/test.rs b/src/rustbook/test.rs new file mode 100644 index 0000000000000..f2bf92585f7ea --- /dev/null +++ b/src/rustbook/test.rs @@ -0,0 +1,75 @@ +// 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. + +//! Implementation of the `test` subcommand. Just a stub for now. + +use subcommand::Subcommand; +use error::CliResult; +use error::CommandResult; +use error::Error; +use term::Term; +use book; +use std::io::{Command, File}; +use std::os; + +struct Test; + +pub fn parse_cmd(name: &str) -> Option<Box<Subcommand>> { + if name == "test" { + Some(box Test as Box<Subcommand>) + } else { + None + } +} + +impl Subcommand for Test { + fn parse_args(&mut self, _: &[String]) -> CliResult<()> { + Ok(()) + } + fn usage(&self) {} + fn execute(&mut self, term: &mut Term) -> CommandResult<()> { + let cwd = os::getcwd().unwrap(); + let src = cwd.clone(); + + let summary = File::open(&src.join("SUMMARY.md")); + match book::parse_summary(summary, &src) { + Ok(book) => { + for (_, item) in book.iter() { + let output_result = Command::new("rustdoc") + .arg(&item.path) + .arg("--test") + .output(); + match output_result { + Ok(output) => { + if !output.status.success() { + term.err(&format!("{}\n{}", + String::from_utf8_lossy(&output.output[]), + String::from_utf8_lossy(&output.error[]))[]); + return Err(box "Some tests failed." as Box<Error>); + } + + } + Err(e) => { + let message = format!("Could not execute `rustdoc`: {}", e); + return Err(box message as Box<Error>); + } + } + } + } + Err(errors) => { + for err in errors.into_iter() { + term.err(&err[]); + } + return Err(box "There was an error." as Box<Error>); + } + } + Ok(()) // lol + } +} From 7541f82faba6b2839b5e640605d7caab6cc6ec4f Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Thu, 8 Jan 2015 10:27:03 -0800 Subject: [PATCH 25/25] Fix dead links in the guide and reorganize --- mk/docs.mk | 5 +- mk/tests.mk | 4 +- src/doc/trpl/SUMMARY.md | 67 ++- src/doc/trpl/{src => }/advanced.md | 0 .../{src => }/arrays-vectors-and-slices.md | 4 +- src/doc/trpl/{src => }/basic.md | 0 src/doc/trpl/{src => }/closures.md | 2 +- src/doc/trpl/{src => }/comments.md | 4 +- src/doc/trpl/{src => }/compound-data-types.md | 2 +- src/doc/trpl/{src => }/conclusion.md | 0 src/doc/trpl/{src => }/crates-and-modules.md | 0 src/doc/trpl/{src => }/error-handling.md | 0 src/doc/trpl/{src => }/ffi.md | 0 src/doc/trpl/{src => }/functions.md | 2 +- src/doc/trpl/{src => }/generics.md | 0 src/doc/trpl/{src => }/guessing-game.md | 8 +- src/doc/trpl/{src => }/hello-cargo.md | 2 +- src/doc/trpl/{src => }/hello-world.md | 2 +- src/doc/trpl/{src => }/if.md | 2 +- src/doc/trpl/{src => }/installing-rust.md | 2 +- src/doc/trpl/{src => }/intermediate.md | 0 src/doc/trpl/{src => }/iterators.md | 2 +- src/doc/trpl/{src => }/looping.md | 2 +- src/doc/trpl/{src => }/macros.md | 4 +- src/doc/trpl/{src => }/match.md | 2 +- src/doc/trpl/{src => }/method-syntax.md | 0 src/doc/trpl/{src => }/ownership.md | 0 src/doc/trpl/{src => }/patterns.md | 0 src/doc/trpl/{src => }/plugins.md | 47 +- src/doc/trpl/{src => }/pointers.md | 8 +- src/doc/trpl/src/guide-lifetimes.md | 565 ------------------ src/doc/trpl/{src => }/standard-input.md | 2 +- src/doc/trpl/{src => }/strings.md | 2 +- src/doc/trpl/{src => }/tasks.md | 2 +- src/doc/trpl/{src => }/testing.md | 0 src/doc/trpl/{src => }/traits.md | 0 src/doc/trpl/{src => }/unsafe.md | 8 +- src/doc/trpl/{src => }/variable-bindings.md | 4 +- src/rustbook/book.rs | 8 +- src/rustbook/build.rs | 11 +- src/rustbook/error.rs | 6 + src/rustbook/main.rs | 0 src/rustbook/term.rs | 2 + 43 files changed, 112 insertions(+), 669 deletions(-) rename src/doc/trpl/{src => }/advanced.md (100%) rename src/doc/trpl/{src => }/arrays-vectors-and-slices.md (96%) rename src/doc/trpl/{src => }/basic.md (100%) rename src/doc/trpl/{src => }/closures.md (99%) rename src/doc/trpl/{src => }/comments.md (93%) rename src/doc/trpl/{src => }/compound-data-types.md (99%) rename src/doc/trpl/{src => }/conclusion.md (100%) rename src/doc/trpl/{src => }/crates-and-modules.md (100%) rename src/doc/trpl/{src => }/error-handling.md (100%) rename src/doc/trpl/{src => }/ffi.md (100%) rename src/doc/trpl/{src => }/functions.md (99%) rename src/doc/trpl/{src => }/generics.md (100%) rename src/doc/trpl/{src => }/guessing-game.md (98%) rename src/doc/trpl/{src => }/hello-cargo.md (99%) rename src/doc/trpl/{src => }/hello-world.md (99%) rename src/doc/trpl/{src => }/if.md (99%) rename src/doc/trpl/{src => }/installing-rust.md (99%) rename src/doc/trpl/{src => }/intermediate.md (100%) rename src/doc/trpl/{src => }/iterators.md (99%) rename src/doc/trpl/{src => }/looping.md (99%) rename src/doc/trpl/{src => }/macros.md (99%) rename src/doc/trpl/{src => }/match.md (99%) rename src/doc/trpl/{src => }/method-syntax.md (100%) rename src/doc/trpl/{src => }/ownership.md (100%) rename src/doc/trpl/{src => }/patterns.md (100%) rename src/doc/trpl/{src => }/plugins.md (81%) rename src/doc/trpl/{src => }/pointers.md (98%) delete mode 100644 src/doc/trpl/src/guide-lifetimes.md rename src/doc/trpl/{src => }/standard-input.md (99%) rename src/doc/trpl/{src => }/strings.md (99%) rename src/doc/trpl/{src => }/tasks.md (99%) rename src/doc/trpl/{src => }/testing.md (100%) rename src/doc/trpl/{src => }/traits.md (100%) rename src/doc/trpl/{src => }/unsafe.md (98%) rename src/doc/trpl/{src => }/variable-bindings.md (98%) mode change 100755 => 100644 src/rustbook/build.rs mode change 100755 => 100644 src/rustbook/main.rs diff --git a/mk/docs.mk b/mk/docs.mk index a84977b382b60..1104c3eb6dbb5 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -275,9 +275,8 @@ endif docs: $(DOC_TARGETS) compiler-docs: $(COMPILER_DOC_TARGETS) -trpl: tmp/trpl.ok +trpl: doc/book/index.html -tmp/trpl.ok: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) +doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) $(Q)rm -rf doc/book $(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book - $(Q)touch $@ diff --git a/mk/tests.mk b/mk/tests.mk index 97455e744d4bd..c8c4beb11531b 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -156,8 +156,8 @@ endef $(foreach doc,$(DOCS), \ $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md))) -$(foreach file,$(wildcard $(S)src/doc/trpl/src/*), \ - $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/src/%.md=trpl-%),$(file)))) +$(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \ + $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/%.md=trpl-%),$(file)))) ###################################################################### # Main test targets diff --git a/src/doc/trpl/SUMMARY.md b/src/doc/trpl/SUMMARY.md index 0f1bce389df9a..1a61c6d216b68 100644 --- a/src/doc/trpl/SUMMARY.md +++ b/src/doc/trpl/SUMMARY.md @@ -1,35 +1,36 @@ # Summary -* [I: The Basics](src/basic.md) - * [Installing Rust](src/installing-rust.md) - * [Hello, world!](src/hello-world.md) - * [Hello, Cargo!](src/hello-cargo.md) - * [Variable Bindings](src/variable-bindings.md) - * [If](src/if.md) - * [Functions](src/functions.md) - * [Comments](src/comments.md) - * [Compound Data Types](src/compound-data-types.md) - * [Match](src/match.md) - * [Looping](src/looping.md) - * [Strings](src/strings.md) - * [Arrays, Vectors, and Slices](src/arrays-vectors-and-slices.md) - * [Standard Input](src/standard-input.md) - * [Guessing Game](src/guessing-game.md) -* [II: Intermedite Rust](src/intermediate.md) - * [Crates and Modules](src/crates-and-modules.md) - * [Testing](src/testing.md) - * [Pointers](src/pointers.md) - * [Patterns](src/patterns.md) - * [Method Syntax](src/method-syntax.md) - * [Closures](src/closures.md) - * [Iterators](src/iterators.md) - * [Generics](src/generics.md) - * [Traits](src/traits.md) - * [Tasks](src/tasks.md) - * [Error Handling](src/error-handling.md) -* [III: Advanced Topics](src/advanced.md) - * [FFI](src/ffi.md) - * [Unsafe Code](src/unsafe.md) - * [Macros](src/macros.md) - * [Compiler Plugins](src/plugins.md) -* [Conclusion](src/conclusion.md) +* [I: The Basics](basic.md) + * [Installing Rust](installing-rust.md) + * [Hello, world!](hello-world.md) + * [Hello, Cargo!](hello-cargo.md) + * [Variable Bindings](variable-bindings.md) + * [If](if.md) + * [Functions](functions.md) + * [Comments](comments.md) + * [Compound Data Types](compound-data-types.md) + * [Match](match.md) + * [Looping](looping.md) + * [Strings](strings.md) + * [Arrays, Vectors, and Slices](arrays-vectors-and-slices.md) + * [Standard Input](standard-input.md) + * [Guessing Game](guessing-game.md) +* [II: Intermediate Rust](intermediate.md) + * [Crates and Modules](crates-and-modules.md) + * [Testing](testing.md) + * [Pointers](pointers.md) + * [Ownership](ownership.md) + * [Patterns](patterns.md) + * [Method Syntax](method-syntax.md) + * [Closures](closures.md) + * [Iterators](iterators.md) + * [Generics](generics.md) + * [Traits](traits.md) + * [Tasks](tasks.md) + * [Error Handling](error-handling.md) +* [III: Advanced Topics](advanced.md) + * [FFI](ffi.md) + * [Unsafe Code](unsafe.md) + * [Macros](macros.md) + * [Compiler Plugins](plugins.md) +* [Conclusion](conclusion.md) diff --git a/src/doc/trpl/src/advanced.md b/src/doc/trpl/advanced.md similarity index 100% rename from src/doc/trpl/src/advanced.md rename to src/doc/trpl/advanced.md diff --git a/src/doc/trpl/src/arrays-vectors-and-slices.md b/src/doc/trpl/arrays-vectors-and-slices.md similarity index 96% rename from src/doc/trpl/src/arrays-vectors-and-slices.md rename to src/doc/trpl/arrays-vectors-and-slices.md index 68fc73222fd2b..24d60dd2e4e3c 100644 --- a/src/doc/trpl/src/arrays-vectors-and-slices.md +++ b/src/doc/trpl/arrays-vectors-and-slices.md @@ -1,4 +1,4 @@ -# Arrays, Vectors, and Slices +% Arrays, Vectors, and Slices Like many programming languages, Rust has list types to represent a sequence of things. The most basic is the **array**, a fixed-size list of elements of the @@ -48,7 +48,7 @@ errant access is the source of many bugs in other systems programming languages. A **vector** is a dynamic or "growable" array, implemented as the standard -library type [`Vec<T>`](std/vec/) (we'll talk about what the `<T>` means +library type [`Vec<T>`](../std/vec/) (we'll talk about what the `<T>` means later). Vectors are to arrays what `String` is to `&str`. You can create them with the `vec!` macro: diff --git a/src/doc/trpl/src/basic.md b/src/doc/trpl/basic.md similarity index 100% rename from src/doc/trpl/src/basic.md rename to src/doc/trpl/basic.md diff --git a/src/doc/trpl/src/closures.md b/src/doc/trpl/closures.md similarity index 99% rename from src/doc/trpl/src/closures.md rename to src/doc/trpl/closures.md index 79ae28e1b911f..6413b90ee71e0 100644 --- a/src/doc/trpl/src/closures.md +++ b/src/doc/trpl/closures.md @@ -1,4 +1,4 @@ -# Closures +% Closures So far, we've made lots of functions in Rust, but we've given them all names. Rust also allows us to create anonymous functions. Rust's anonymous diff --git a/src/doc/trpl/src/comments.md b/src/doc/trpl/comments.md similarity index 93% rename from src/doc/trpl/src/comments.md rename to src/doc/trpl/comments.md index cce6eacea0408..f02c1ad9a183e 100644 --- a/src/doc/trpl/src/comments.md +++ b/src/doc/trpl/comments.md @@ -1,4 +1,4 @@ -# Comments +% Comments Now that we have some functions, it's a good idea to learn about comments. Comments are notes that you leave to other programmers to help explain things @@ -42,5 +42,5 @@ fn hello(name: &str) { When writing doc comments, adding sections for any arguments, return values, and providing some examples of usage is very, very helpful. -You can use the [`rustdoc`](rustdoc.html) tool to generate HTML documentation +You can use the [`rustdoc`](../rustdoc.html) tool to generate HTML documentation from these doc comments. diff --git a/src/doc/trpl/src/compound-data-types.md b/src/doc/trpl/compound-data-types.md similarity index 99% rename from src/doc/trpl/src/compound-data-types.md rename to src/doc/trpl/compound-data-types.md index b9bb50973615c..b80d248bc41d1 100644 --- a/src/doc/trpl/src/compound-data-types.md +++ b/src/doc/trpl/compound-data-types.md @@ -1,4 +1,4 @@ -# Compound Data Types +% Compound Data Types Rust, like many programming languages, has a number of different data types that are built-in. You've already done some simple work with integers and diff --git a/src/doc/trpl/src/conclusion.md b/src/doc/trpl/conclusion.md similarity index 100% rename from src/doc/trpl/src/conclusion.md rename to src/doc/trpl/conclusion.md diff --git a/src/doc/trpl/src/crates-and-modules.md b/src/doc/trpl/crates-and-modules.md similarity index 100% rename from src/doc/trpl/src/crates-and-modules.md rename to src/doc/trpl/crates-and-modules.md diff --git a/src/doc/trpl/src/error-handling.md b/src/doc/trpl/error-handling.md similarity index 100% rename from src/doc/trpl/src/error-handling.md rename to src/doc/trpl/error-handling.md diff --git a/src/doc/trpl/src/ffi.md b/src/doc/trpl/ffi.md similarity index 100% rename from src/doc/trpl/src/ffi.md rename to src/doc/trpl/ffi.md diff --git a/src/doc/trpl/src/functions.md b/src/doc/trpl/functions.md similarity index 99% rename from src/doc/trpl/src/functions.md rename to src/doc/trpl/functions.md index 0fa3c66af648c..e3827d962c331 100644 --- a/src/doc/trpl/src/functions.md +++ b/src/doc/trpl/functions.md @@ -1,4 +1,4 @@ -# Functions +% Functions You've already seen one function so far, the `main` function: diff --git a/src/doc/trpl/src/generics.md b/src/doc/trpl/generics.md similarity index 100% rename from src/doc/trpl/src/generics.md rename to src/doc/trpl/generics.md diff --git a/src/doc/trpl/src/guessing-game.md b/src/doc/trpl/guessing-game.md similarity index 98% rename from src/doc/trpl/src/guessing-game.md rename to src/doc/trpl/guessing-game.md index 1efcd4897609d..2847964f15f50 100644 --- a/src/doc/trpl/src/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -1,4 +1,4 @@ -# Guessing Game +% Guessing Game Okay! We've got the basics of Rust down. Let's write a bigger program. @@ -108,12 +108,12 @@ we do know that Rust has random number generation, but we don't know how to use it. Enter the docs. Rust has a page specifically to document the standard library. -You can find that page [here](std/index.html). There's a lot of information on +You can find that page [here](../std/index.html). There's a lot of information on that page, but the best part is the search bar. Right up at the top, there's a box that you can enter in a search term. The search is pretty primitive right now, but is getting better all the time. If you type 'random' in that -box, the page will update to [this one](std/index.html?search=random). The very -first result is a link to [`std::rand::random`](std/rand/fn.random.html). If we +box, the page will update to [this one](../std/index.html?search=random). The very +first result is a link to [`std::rand::random`](../std/rand/fn.random.html). If we click on that result, we'll be taken to its documentation page. This page shows us a few things: the type signature of the function, some diff --git a/src/doc/trpl/src/hello-cargo.md b/src/doc/trpl/hello-cargo.md similarity index 99% rename from src/doc/trpl/src/hello-cargo.md rename to src/doc/trpl/hello-cargo.md index c81cdc465c8fc..d8acd95b59d8f 100644 --- a/src/doc/trpl/src/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -1,4 +1,4 @@ -# Hello, Cargo! +% Hello, Cargo! [Cargo](http://crates.io) is a tool that Rustaceans use to help manage their Rust projects. Cargo is currently in an alpha state, just like Rust, and so it diff --git a/src/doc/trpl/src/hello-world.md b/src/doc/trpl/hello-world.md similarity index 99% rename from src/doc/trpl/src/hello-world.md rename to src/doc/trpl/hello-world.md index 33cb752c36468..f9cc1ebf0bf13 100644 --- a/src/doc/trpl/src/hello-world.md +++ b/src/doc/trpl/hello-world.md @@ -1,4 +1,4 @@ -# Hello, world! +% Hello, world! Now that you have Rust installed, let's write your first Rust program. It's traditional to make your first program in any new language one that prints the diff --git a/src/doc/trpl/src/if.md b/src/doc/trpl/if.md similarity index 99% rename from src/doc/trpl/src/if.md rename to src/doc/trpl/if.md index bc3d548ce9f05..6f81a27b2b7d3 100644 --- a/src/doc/trpl/src/if.md +++ b/src/doc/trpl/if.md @@ -1,4 +1,4 @@ -# `if` +% `if` Rust's take on `if` is not particularly complex, but it's much more like the `if` you'll find in a dynamically typed language than in a more traditional diff --git a/src/doc/trpl/src/installing-rust.md b/src/doc/trpl/installing-rust.md similarity index 99% rename from src/doc/trpl/src/installing-rust.md rename to src/doc/trpl/installing-rust.md index 1705893c397c2..5893b51a4208c 100644 --- a/src/doc/trpl/src/installing-rust.md +++ b/src/doc/trpl/installing-rust.md @@ -1,4 +1,4 @@ -# Installing Rust +% Installing Rust The first step to using Rust is to install it! There are a number of ways to install Rust, but the easiest is to use the `rustup` script. If you're on diff --git a/src/doc/trpl/src/intermediate.md b/src/doc/trpl/intermediate.md similarity index 100% rename from src/doc/trpl/src/intermediate.md rename to src/doc/trpl/intermediate.md diff --git a/src/doc/trpl/src/iterators.md b/src/doc/trpl/iterators.md similarity index 99% rename from src/doc/trpl/src/iterators.md rename to src/doc/trpl/iterators.md index 056e9a9720e13..a773b7329dbaf 100644 --- a/src/doc/trpl/src/iterators.md +++ b/src/doc/trpl/iterators.md @@ -336,4 +336,4 @@ can help you with. There are a number of really useful iterators, and you can write your own as well. Iterators provide a safe, efficient way to manipulate all kinds of lists. They're a little unusual at first, but if you play with them, you'll get hooked. For a full list of the different iterators and -consumers, check out the [iterator module documentation](std/iter/index.html). +consumers, check out the [iterator module documentation](../std/iter/index.html). diff --git a/src/doc/trpl/src/looping.md b/src/doc/trpl/looping.md similarity index 99% rename from src/doc/trpl/src/looping.md rename to src/doc/trpl/looping.md index 03384b287030c..80926c99e872f 100644 --- a/src/doc/trpl/src/looping.md +++ b/src/doc/trpl/looping.md @@ -1,4 +1,4 @@ -# Looping +% Looping Looping is the last basic construct that we haven't learned yet in Rust. Rust has two main looping constructs: `for` and `while`. diff --git a/src/doc/trpl/src/macros.md b/src/doc/trpl/macros.md similarity index 99% rename from src/doc/trpl/src/macros.md rename to src/doc/trpl/macros.md index 95f5305775eed..c694806b4bab9 100644 --- a/src/doc/trpl/src/macros.md +++ b/src/doc/trpl/macros.md @@ -507,7 +507,7 @@ When this library is loaded with `#[use_macros] extern crate`, only `m2` will be imported. The Rust Reference has a [listing of macro-related -attributes](reference.html#macro--and-plugin-related-attributes). +attributes](../reference.html#macro--and-plugin-related-attributes). # The variable `$crate` @@ -567,7 +567,7 @@ intermediate states out, and passing the flag `--pretty expanded` as a command-line argument to the compiler will show the result of expansion. If Rust's macro system can't do what you need, you may want to write a -[compiler plugin](guide-plugin.html) instead. Compared to `macro_rules!` +[compiler plugin](plugin.html) instead. Compared to `macro_rules!` macros, this is significantly more work, the interfaces are much less stable, and the warnings about debugging apply ten-fold. In exchange you get the flexibility of running arbitrary Rust code within the compiler. Syntax diff --git a/src/doc/trpl/src/match.md b/src/doc/trpl/match.md similarity index 99% rename from src/doc/trpl/src/match.md rename to src/doc/trpl/match.md index 0170109def022..c120142cf5c72 100644 --- a/src/doc/trpl/src/match.md +++ b/src/doc/trpl/match.md @@ -1,4 +1,4 @@ -# Match +% Match Often, a simple `if`/`else` isn't enough, because you have more than two possible options. Also, `else` conditions can get incredibly complicated, so diff --git a/src/doc/trpl/src/method-syntax.md b/src/doc/trpl/method-syntax.md similarity index 100% rename from src/doc/trpl/src/method-syntax.md rename to src/doc/trpl/method-syntax.md diff --git a/src/doc/trpl/src/ownership.md b/src/doc/trpl/ownership.md similarity index 100% rename from src/doc/trpl/src/ownership.md rename to src/doc/trpl/ownership.md diff --git a/src/doc/trpl/src/patterns.md b/src/doc/trpl/patterns.md similarity index 100% rename from src/doc/trpl/src/patterns.md rename to src/doc/trpl/patterns.md diff --git a/src/doc/trpl/src/plugins.md b/src/doc/trpl/plugins.md similarity index 81% rename from src/doc/trpl/src/plugins.md rename to src/doc/trpl/plugins.md index 025f0cced63a6..2a0710d018c4e 100644 --- a/src/doc/trpl/src/plugins.md +++ b/src/doc/trpl/plugins.md @@ -5,20 +5,20 @@ <p> <b>Warning:</b> Plugins are an advanced, unstable feature! For many details, the only available documentation is the <a -href="syntax/index.html"><code>libsyntax</code></a> and <a -href="rustc/index.html"><code>librustc</code></a> API docs, or even the source +href="../syntax/index.html"><code>libsyntax</code></a> and <a +href="../rustc/index.html"><code>librustc</code></a> API docs, or even the source code itself. These internal compiler APIs are also subject to change at any time. </p> <p> For defining new syntax it is often much easier to use Rust's <a -href="guide-macros.html">built-in macro system</a>. +href="macros.html">built-in macro system</a>. </p> <p style="margin-bottom: 0"> The code in this document uses language features not covered in the Rust -Guide. See the <a href="reference.html">Reference Manual</a> for more +Guide. See the <a href="../reference.html">Reference Manual</a> for more information. </p> @@ -32,19 +32,19 @@ extend the compiler's behavior with new syntax extensions, lint checks, etc. A plugin is a dynamic library crate with a designated "registrar" function that registers extensions with `rustc`. Other crates can use these extensions by loading the plugin crate with `#[plugin] extern crate`. See the -[`rustc::plugin`](rustc/plugin/index.html) documentation for more about the +[`rustc::plugin`](../rustc/plugin/index.html) documentation for more about the mechanics of defining and loading a plugin. Arguments passed as `#[plugin=...]` or `#[plugin(...)]` are not interpreted by rustc itself. They are provided to the plugin through the `Registry`'s [`args` -method](rustc/plugin/registry/struct.Registry.html#method.args). +method](../rustc/plugin/registry/struct.Registry.html#method.args). # Syntax extensions Plugins can extend Rust's syntax in various ways. One kind of syntax extension is the procedural macro. These are invoked the same way as [ordinary -macros](guide-macros.html), but the expansion is performed by arbitrary Rust -code that manipulates [syntax trees](syntax/ast/index.html) at +macros](macros.html), but the expansion is performed by arbitrary Rust +code that manipulates [syntax trees](../syntax/ast/index.html) at compile time. Let's write a plugin @@ -126,14 +126,13 @@ The advantages over a simple `fn(&str) -> uint` are: a way to define new literal syntax for any data type. In addition to procedural macros, you can define new -[`deriving`](reference.html#deriving)-like attributes and other kinds of +[`deriving`](../reference.html#deriving)-like attributes and other kinds of extensions. See -[`Registry::register_syntax_extension`](rustc/plugin/registry/struct.Registry.html#method.register_syntax_extension) +[`Registry::register_syntax_extension`](../rustc/plugin/registry/struct.Registry.html#method.register_syntax_extension) and the [`SyntaxExtension` enum](http://doc.rust-lang.org/syntax/ext/base/enum.SyntaxExtension.html). For a more involved macro example, see -[`src/libregex_macros/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/libregex_macros/lib.rs) -in the Rust distribution. +[`regex_macros`](https://github.com/rust-lang/regex/blob/master/regex_macros/src/lib.rs). ## Tips and tricks @@ -147,7 +146,7 @@ variables of the same name (but different syntax contexts) are in play in the same scope. In this case `--pretty expanded,hygiene` will tell you about the syntax contexts. -You can use [`syntax::parse`](syntax/parse/index.html) to turn token trees into +You can use [`syntax::parse`](../syntax/parse/index.html) to turn token trees into higher-level syntax elements like expressions: ```ignore @@ -163,23 +162,23 @@ Looking through [`libsyntax` parser code](https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs) will give you a feel for how the parsing infrastructure works. -Keep the [`Span`s](syntax/codemap/struct.Span.html) of +Keep the [`Span`s](../syntax/codemap/struct.Span.html) of everything you parse, for better error reporting. You can wrap -[`Spanned`](syntax/codemap/struct.Spanned.html) around +[`Spanned`](../syntax/codemap/struct.Spanned.html) around your custom data structures. Calling -[`ExtCtxt::span_fatal`](syntax/ext/base/struct.ExtCtxt.html#method.span_fatal) +[`ExtCtxt::span_fatal`](../syntax/ext/base/struct.ExtCtxt.html#method.span_fatal) will immediately abort compilation. It's better to instead call -[`ExtCtxt::span_err`](syntax/ext/base/struct.ExtCtxt.html#method.span_err) +[`ExtCtxt::span_err`](../syntax/ext/base/struct.ExtCtxt.html#method.span_err) and return -[`DummyResult`](syntax/ext/base/struct.DummyResult.html), +[`DummyResult`](../syntax/ext/base/struct.DummyResult.html), so that the compiler can continue and find further errors. The example above produced an integer literal using -[`AstBuilder::expr_uint`](syntax/ext/build/trait.AstBuilder.html#tymethod.expr_uint). +[`AstBuilder::expr_uint`](../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_uint). As an alternative to the `AstBuilder` trait, `libsyntax` provides a set of -[quasiquote macros](syntax/ext/quote/index.html). They are undocumented and +[quasiquote macros](../syntax/ext/quote/index.html). They are undocumented and very rough around the edges. However, the implementation may be a good starting point for an improved quasiquote as an ordinary plugin library. @@ -187,7 +186,7 @@ starting point for an improved quasiquote as an ordinary plugin library. # Lint plugins Plugins can extend [Rust's lint -infrastructure](reference.html#lint-check-attributes) with additional checks for +infrastructure](../reference.html#lint-check-attributes) with additional checks for code style, safety, etc. You can see [`src/test/auxiliary/lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/auxiliary/lint_plugin_test.rs) for a full example, the core of which is reproduced here: @@ -236,11 +235,11 @@ foo.rs:4 fn lintme() { } The components of a lint plugin are: * one or more `declare_lint!` invocations, which define static - [`Lint`](rustc/lint/struct.Lint.html) structs; + [`Lint`](../rustc/lint/struct.Lint.html) structs; * a struct holding any state needed by the lint pass (here, none); -* a [`LintPass`](rustc/lint/trait.LintPass.html) +* a [`LintPass`](../rustc/lint/trait.LintPass.html) implementation defining how to check each syntax element. A single `LintPass` may call `span_lint` for several different `Lint`s, but should register them all through the `get_lints` method. @@ -252,7 +251,7 @@ mostly use the same infrastructure as lint plugins, and provide examples of how to access type information. Lints defined by plugins are controlled by the usual [attributes and compiler -flags](reference.html#lint-check-attributes), e.g. `#[allow(test_lint)]` or +flags](../reference.html#lint-check-attributes), e.g. `#[allow(test_lint)]` or `-A test-lint`. These identifiers are derived from the first argument to `declare_lint!`, with appropriate case and punctuation conversion. diff --git a/src/doc/trpl/src/pointers.md b/src/doc/trpl/pointers.md similarity index 98% rename from src/doc/trpl/src/pointers.md rename to src/doc/trpl/pointers.md index 4c35fae3ecc51..ad80d2812d077 100644 --- a/src/doc/trpl/src/pointers.md +++ b/src/doc/trpl/pointers.md @@ -409,7 +409,7 @@ test.rs:4 let y = &x; As you might guess, this kind of analysis is complex for a human, and therefore hard for a computer, too! There is an entire [guide devoted to references, ownership, -and lifetimes](guide-ownership.html) that goes into this topic in +and lifetimes](ownership.html) that goes into this topic in great detail, so if you want the full details, check that out. ## Best practices @@ -542,7 +542,7 @@ with some improvements: 4. Rust enforces that no other writeable pointers alias to this heap memory, which means writing to an invalid pointer is not possible. -See the section on references or the [ownership guide](guide-ownership.html) +See the section on references or the [ownership guide](ownership.html) for more detail on how lifetimes work. Using boxes and references together is very common. For example: @@ -780,6 +780,6 @@ Here's a quick rundown of Rust's pointer types: # Related resources -* [API documentation for Box](std/boxed/index.html) -* [Ownership guide](guide-ownership.html) +* [API documentation for Box](../std/boxed/index.html) +* [Ownership guide](ownership.html) * [Cyclone paper on regions](http://www.cs.umd.edu/projects/cyclone/papers/cyclone-regions.pdf), which inspired Rust's lifetime system diff --git a/src/doc/trpl/src/guide-lifetimes.md b/src/doc/trpl/src/guide-lifetimes.md deleted file mode 100644 index 7a5c535827c25..0000000000000 --- a/src/doc/trpl/src/guide-lifetimes.md +++ /dev/null @@ -1,565 +0,0 @@ -% The Rust References and Lifetimes Guide - -# Introduction - -References are one of the more flexible and powerful tools available in -Rust. They can point anywhere: into the heap, stack, and even into the -interior of another data structure. A reference is as flexible as a C pointer -or C++ reference. - -Unlike C and C++ compilers, the Rust compiler includes special static -checks that ensure that programs use references safely. - -Despite their complete safety, a reference's representation at runtime -is the same as that of an ordinary pointer in a C program. They introduce zero -overhead. The compiler does all safety checks at compile time. - -Although references have rather elaborate theoretical underpinnings -(e.g. region pointers), the core concepts will be familiar to anyone -who has worked with C or C++. The best way to explain how they are -used—and their limitations—is probably just to work through several examples. - -# By example - -References, sometimes known as *borrowed pointers*, are only valid for -a limited duration. References never claim any kind of ownership -over the data that they point to. Instead, they are used for cases -where you would like to use data for a short time. - -Consider a simple struct type `Point`: - -~~~ -struct Point {x: f64, y: f64} -~~~ - -We can use this simple definition to allocate points in many different ways. For -example, in this code, each of these local variables contains a point, -but allocated in a different place: - -~~~ -# struct Point {x: f64, y: f64} -let on_the_stack : Point = Point {x: 3.0, y: 4.0}; -let on_the_heap : Box<Point> = box Point {x: 7.0, y: 9.0}; -~~~ - -Suppose we wanted to write a procedure that computed the distance between any -two points, no matter where they were stored. One option is to define a function -that takes two arguments of type `Point`—that is, it takes the points by value. -But if we define it this way, calling the function will cause the points to be -copied. For points, this is probably not so bad, but often copies are -expensive. So we'd like to define a function that takes the points just as -a reference. - -~~~ -# use std::num::Float; -# struct Point {x: f64, y: f64} -# fn sqrt(f: f64) -> f64 { 0.0 } -fn compute_distance(p1: &Point, p2: &Point) -> f64 { - let x_d = p1.x - p2.x; - let y_d = p1.y - p2.y; - (x_d * x_d + y_d * y_d).sqrt() -} -~~~ - -Now we can call `compute_distance()`: - -~~~ -# struct Point {x: f64, y: f64} -# let on_the_stack : Point = Point{x: 3.0, y: 4.0}; -# let on_the_heap : Box<Point> = box Point{x: 7.0, y: 9.0}; -# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } -compute_distance(&on_the_stack, &*on_the_heap); -~~~ - -Here, the `&` operator takes the address of the variable -`on_the_stack`; this is because `on_the_stack` has the type `Point` -(that is, a struct value) and we have to take its address to get a -value. We also call this _borrowing_ the local variable -`on_the_stack`, because we have created an alias: that is, another -name for the same data. - -Likewise, in the case of `on_the_heap`, -the `&` operator is used in conjunction with the `*` operator -to take a reference to the contents of the box. - -Whenever a caller lends data to a callee, there are some limitations on what -the caller can do with the original. For example, if the contents of a -variable have been lent out, you cannot send that variable to another task. In -addition, the compiler will reject any code that might cause the borrowed -value to be freed or overwrite its component fields with values of different -types (I'll get into what kinds of actions those are shortly). This rule -should make intuitive sense: you must wait for a borrower to return the value -that you lent it (that is, wait for the reference to go out of scope) -before you can make full use of it again. - -# Other uses for the & operator - -In the previous example, the value `on_the_stack` was defined like so: - -~~~ -# struct Point {x: f64, y: f64} -let on_the_stack: Point = Point {x: 3.0, y: 4.0}; -~~~ - -This declaration means that code can only pass `Point` by value to other -functions. As a consequence, we had to explicitly take the address of -`on_the_stack` to get a reference. Sometimes however it is more -convenient to move the & operator into the definition of `on_the_stack`: - -~~~ -# struct Point {x: f64, y: f64} -let on_the_stack2: &Point = &Point {x: 3.0, y: 4.0}; -~~~ - -Applying `&` to an rvalue (non-assignable location) is just a convenient -shorthand for creating a temporary and taking its address. A more verbose -way to write the same code is: - -~~~ -# struct Point {x: f64, y: f64} -let tmp = Point {x: 3.0, y: 4.0}; -let on_the_stack2 : &Point = &tmp; -~~~ - -# Taking the address of fields - -The `&` operator is not limited to taking the address of -local variables. It can also take the address of fields or -individual array elements. For example, consider this type definition -for `Rectangle`: - -~~~ -struct Point {x: f64, y: f64} // as before -struct Size {w: f64, h: f64} // as before -struct Rectangle {origin: Point, size: Size} -~~~ - -Now, as before, we can define rectangles in a few different ways: - -~~~ -# struct Point {x: f64, y: f64} -# struct Size {w: f64, h: f64} // as before -# struct Rectangle {origin: Point, size: Size} -let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, - size: Size {w: 3.0, h: 4.0}}; -let rect_heap = box Rectangle {origin: Point {x: 5.0, y: 6.0}, - size: Size {w: 3.0, h: 4.0}}; -~~~ - -In each case, we can extract out individual subcomponents with the `&` -operator. For example, I could write: - -~~~ -# struct Point {x: f64, y: f64} // as before -# struct Size {w: f64, h: f64} // as before -# struct Rectangle {origin: Point, size: Size} -# let rect_stack = &Rectangle {origin: Point {x: 1.0, y: 2.0}, size: Size {w: 3.0, h: 4.0}}; -# let rect_heap = box Rectangle {origin: Point {x: 5.0, y: 6.0}, size: Size {w: 3.0, h: 4.0}}; -# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 } -compute_distance(&rect_stack.origin, &rect_heap.origin); -~~~ - -which would borrow the field `origin` from the rectangle on the stack -as well as from the owned box, and then compute the distance between them. - -# Lifetimes - -We’ve seen a few examples of borrowing data. To this point, we’ve glossed -over issues of safety. As stated in the introduction, at runtime a reference -is simply a pointer, nothing more. Therefore, avoiding C's problems with -dangling pointers requires a compile-time safety check. - -The basis for the check is the notion of _lifetimes_. A lifetime is a -static approximation of the span of execution during which the pointer -is valid: it always corresponds to some expression or block within the -program. - -The compiler will only allow a borrow *if it can guarantee that the data will -not be reassigned or moved for the lifetime of the pointer*. This does not -necessarily mean that the data is stored in immutable memory. For example, -the following function is legal: - -~~~ -# fn some_condition() -> bool { true } -# struct Foo { f: int } -fn example3() -> int { - let mut x = box Foo {f: 3}; - if some_condition() { - let y = &x.f; // -+ L - return *y; // | - } // -+ - x = box Foo {f: 4}; - // ... -# return 0; -} -~~~ - -Here, the interior of the variable `x` is being borrowed -and `x` is declared as mutable. However, the compiler can prove that -`x` is not assigned anywhere in the lifetime L of the variable -`y`. Therefore, it accepts the function, even though `x` is mutable -and in fact is mutated later in the function. - -It may not be clear why we are so concerned about mutating a borrowed -variable. The reason is that the runtime system frees any box -_as soon as its owning reference changes or goes out of -scope_. Therefore, a program like this is illegal (and would be -rejected by the compiler): - -~~~ {.ignore} -fn example3() -> int { - let mut x = box X {f: 3}; - let y = &x.f; - x = box X {f: 4}; // Error reported here. - *y -} -~~~ - -To make this clearer, consider this diagram showing the state of -memory immediately before the re-assignment of `x`: - -~~~ {.text} - Stack Exchange Heap - - x +-------------+ - | box {f:int} | ----+ - y +-------------+ | - | &int | ----+ - +-------------+ | +---------+ - +--> | f: 3 | - +---------+ -~~~ - -Once the reassignment occurs, the memory will look like this: - -~~~ {.text} - Stack Exchange Heap - - x +-------------+ +---------+ - | box {f:int} | -------> | f: 4 | - y +-------------+ +---------+ - | &int | ----+ - +-------------+ | +---------+ - +--> | (freed) | - +---------+ -~~~ - -Here you can see that the variable `y` still points at the old `f` -property of Foo, which has been freed. - -In fact, the compiler can apply the same kind of reasoning to any -memory that is (uniquely) owned by the stack frame. So we could -modify the previous example to introduce additional owned pointers -and structs, and the compiler will still be able to detect possible -mutations. This time, we'll use an analogy to illustrate the concept. - -~~~ {.ignore} -fn example3() -> int { - struct House { owner: Box<Person> } - struct Person { age: int } - - let mut house = box House { - owner: box Person {age: 30} - }; - - let owner_age = &house.owner.age; - house = box House {owner: box Person {age: 40}}; // Error reported here. - house.owner = box Person {age: 50}; // Error reported here. - *owner_age -} -~~~ - -In this case, two errors are reported, one when the variable `house` is -modified and another when `house.owner` is modified. Either modification would -invalidate the pointer `owner_age`. - -# Borrowing and enums - -The previous example showed that the type system forbids any mutations -of owned boxed values while they are being borrowed. In general, the type -system also forbids borrowing a value as mutable if it is already being -borrowed - either as a mutable reference or an immutable one. This restriction -prevents pointers from pointing into freed memory. There is one other -case where the compiler must be very careful to ensure that pointers -remain valid: pointers into the interior of an `enum`. - -Let’s look at the following `shape` type that can represent both rectangles -and circles: - -~~~ -struct Point {x: f64, y: f64}; // as before -struct Size {w: f64, h: f64}; // as before -enum Shape { - Circle(Point, f64), // origin, radius - Rectangle(Point, Size) // upper-left, dimensions -} -~~~ - -Now we might write a function to compute the area of a shape. This -function takes a reference to a shape, to avoid the need for -copying. - -~~~ -# struct Point {x: f64, y: f64}; // as before -# struct Size {w: f64, h: f64}; // as before -# enum Shape { -# Circle(Point, f64), // origin, radius -# Rectangle(Point, Size) // upper-left, dimensions -# } -fn compute_area(shape: &Shape) -> f64 { - match *shape { - Shape::Circle(_, radius) => std::f64::consts::PI * radius * radius, - Shape::Rectangle(_, ref size) => size.w * size.h - } -} -~~~ - -The first case matches against circles. Here, the pattern extracts the -radius from the shape variant and the action uses it to compute the -area of the circle. - -The second match is more interesting. Here we match against a -rectangle and extract its size: but rather than copy the `size` -struct, we use a by-reference binding to create a pointer to it. In -other words, a pattern binding like `ref size` binds the name `size` -to a pointer of type `&size` into the _interior of the enum_. - -To make this more clear, let's look at a diagram of memory layout in -the case where `shape` points at a rectangle: - -~~~ {.text} -Stack Memory - -+-------+ +---------------+ -| shape | ------> | rectangle( | -+-------+ | {x: f64, | -| size | -+ | y: f64}, | -+-------+ +----> | {w: f64, | - | h: f64}) | - +---------------+ -~~~ - -Here you can see that rectangular shapes are composed of five words of -memory. The first is a tag indicating which variant this enum is -(`rectangle`, in this case). The next two words are the `x` and `y` -fields for the point and the remaining two are the `w` and `h` fields -for the size. The binding `size` is then a pointer into the inside of -the shape. - -Perhaps you can see where the danger lies: if the shape were somehow -to be reassigned, perhaps to a circle, then although the memory used -to store that shape value would still be valid, _it would have a -different type_! The following diagram shows what memory would look -like if code overwrote `shape` with a circle: - -~~~ {.text} -Stack Memory - -+-------+ +---------------+ -| shape | ------> | circle( | -+-------+ | {x: f64, | -| size | -+ | y: f64}, | -+-------+ +----> | f64) | - | | - +---------------+ -~~~ - -As you can see, the `size` pointer would be pointing at a `f64` -instead of a struct. This is not good: dereferencing the second field -of a `f64` as if it were a struct with two fields would be a memory -safety violation. - -So, in fact, for every `ref` binding, the compiler will impose the -same rules as the ones we saw for borrowing the interior of an owned -box: it must be able to guarantee that the `enum` will not be -overwritten for the duration of the borrow. In fact, the compiler -would accept the example we gave earlier. The example is safe because -the shape pointer has type `&Shape`, which means "reference to -immutable memory containing a `shape`". If, however, the type of that -pointer were `&mut Shape`, then the ref binding would be ill-typed. -Just as with owned boxes, the compiler will permit `ref` bindings -into data owned by the stack frame even if the data are mutable, -but otherwise it requires that the data reside in immutable memory. - -# Returning references - -So far, all of the examples we have looked at, use references in a -“downward” direction. That is, a method or code block creates a -reference, then uses it within the same scope. It is also -possible to return references as the result of a function, but -as we'll see, doing so requires some explicit annotation. - -We could write a subroutine like this: - -~~~ -struct Point {x: f64, y: f64} -fn get_x<'r>(p: &'r Point) -> &'r f64 { &p.x } -~~~ - -Here, the function `get_x()` returns a pointer into the structure it -was given. The type of the parameter (`&'r Point`) and return type -(`&'r f64`) both use a new syntactic form that we have not seen so -far. Here the identifier `r` names the lifetime of the pointer -explicitly. So in effect, this function declares that it takes a -pointer with lifetime `r` and returns a pointer with that same -lifetime. - -In general, it is only possible to return references if they -are derived from a parameter to the procedure. In that case, the -pointer result will always have the same lifetime as one of the -parameters; named lifetimes indicate which parameter that -is. - -In the previous code samples, function parameter types did not include a -lifetime name. The compiler simply creates a fresh name for the lifetime -automatically: that is, the lifetime name is guaranteed to refer to a distinct -lifetime from the lifetimes of all other parameters. - -Named lifetimes that appear in function signatures are conceptually -the same as the other lifetimes we have seen before, but they are a bit -abstract: they don’t refer to a specific expression within `get_x()`, -but rather to some expression within the *caller of `get_x()`*. The -lifetime `r` is actually a kind of *lifetime parameter*: it is defined -by the caller to `get_x()`, just as the value for the parameter `p` is -defined by that caller. - -In any case, whatever the lifetime of `r` is, the pointer produced by -`&p.x` always has the same lifetime as `p` itself: a pointer to a -field of a struct is valid as long as the struct is valid. Therefore, -the compiler accepts the function `get_x()`. - -In general, if you borrow a struct or box to create a -reference, it will only be valid within the function -and cannot be returned. This is why the typical way to return references -is to take references as input (the only other case in -which it can be legal to return a reference is if it -points at a static constant). - -# Named lifetimes - -Lifetimes can be named and referenced. For example, the special lifetime -`'static`, which does not go out of scope, can be used to create global -variables and communicate between tasks (see the manual for use cases). - -## Parameter Lifetimes - -Named lifetimes allow for grouping of parameters by lifetime. -For example, consider this function: - -~~~ -# struct Point {x: f64, y: f64}; // as before -# struct Size {w: f64, h: f64}; // as before -# enum Shape { -# Circle(Point, f64), // origin, radius -# Rectangle(Point, Size) // upper-left, dimensions -# } -# fn compute_area(shape: &Shape) -> f64 { 0.0 } -fn select<'r, T>(shape: &'r Shape, threshold: f64, - a: &'r T, b: &'r T) -> &'r T { - if compute_area(shape) > threshold {a} else {b} -} -~~~ - -This function takes three references and assigns each the same -lifetime `r`. In practice, this means that, in the caller, the -lifetime `r` will be the *intersection of the lifetime of the three -region parameters*. This may be overly conservative, as in this -example: - -~~~ -# struct Point {x: f64, y: f64}; // as before -# struct Size {w: f64, h: f64}; // as before -# enum Shape { -# Circle(Point, f64), // origin, radius -# Rectangle(Point, Size) // upper-left, dimensions -# } -# fn compute_area(shape: &Shape) -> f64 { 0.0 } -# fn select<'r, T>(shape: &Shape, threshold: f64, -# a: &'r T, b: &'r T) -> &'r T { -# if compute_area(shape) > threshold {a} else {b} -# } - // -+ r -fn select_based_on_unit_circle<'r, T>( // |-+ B - threshold: f64, a: &'r T, b: &'r T) -> &'r T { // | | - // | | - let shape = Shape::Circle(Point {x: 0., y: 0.}, 1.); // | | - select(&shape, threshold, a, b) // | | -} // |-+ - // -+ -~~~ - -In this call to `select()`, the lifetime of the first parameter shape -is B, the function body. Both of the second two parameters `a` and `b` -share the same lifetime, `r`, which is a lifetime parameter of -`select_based_on_unit_circle()`. The caller will infer the -intersection of these two lifetimes as the lifetime of the returned -value, and hence the return value of `select()` will be assigned a -lifetime of B. This will in turn lead to a compilation error, because -`select_based_on_unit_circle()` is supposed to return a value with the -lifetime `r`. - -To address this, we can modify the definition of `select()` to -distinguish the lifetime of the first parameter from the lifetime of -the latter two. After all, the first parameter is not being -returned. Here is how the new `select()` might look: - -~~~ -# struct Point {x: f64, y: f64}; // as before -# struct Size {w: f64, h: f64}; // as before -# enum Shape { -# Circle(Point, f64), // origin, radius -# Rectangle(Point, Size) // upper-left, dimensions -# } -# fn compute_area(shape: &Shape) -> f64 { 0.0 } -fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: f64, - a: &'r T, b: &'r T) -> &'r T { - if compute_area(shape) > threshold {a} else {b} -} -~~~ - -Here you can see that `shape`'s lifetime is now named `tmp`. The -parameters `a`, `b`, and the return value all have the lifetime `r`. -However, since the lifetime `tmp` is not returned, it would be more -concise to just omit the named lifetime for `shape` altogether: - -~~~ -# struct Point {x: f64, y: f64}; // as before -# struct Size {w: f64, h: f64}; // as before -# enum Shape { -# Circle(Point, f64), // origin, radius -# Rectangle(Point, Size) // upper-left, dimensions -# } -# fn compute_area(shape: &Shape) -> f64 { 0.0 } -fn select<'r, T>(shape: &Shape, threshold: f64, - a: &'r T, b: &'r T) -> &'r T { - if compute_area(shape) > threshold {a} else {b} -} -~~~ - -This is equivalent to the previous definition. - -## Labeled Control Structures - -Named lifetime notation can also be used to control the flow of execution: - -~~~ -'h: for i in range(0u, 10) { - 'g: loop { - if i % 2 == 0 { continue 'h; } - if i == 9 { break 'h; } - break 'g; - } -} -~~~ - -> *Note:* Labelled breaks are not currently supported within `while` loops. - -Named labels are hygienic and can be used safely within macros. -See the macros guide section on hygiene for more details. - -# Conclusion - -So there you have it: a (relatively) brief tour of the lifetime -system. For more details, we refer to the (yet to be written) reference -document on references, which will explain the full notation -and give more examples. diff --git a/src/doc/trpl/src/standard-input.md b/src/doc/trpl/standard-input.md similarity index 99% rename from src/doc/trpl/src/standard-input.md rename to src/doc/trpl/standard-input.md index 5a150594f0c0b..2d31f06ebaae1 100644 --- a/src/doc/trpl/src/standard-input.md +++ b/src/doc/trpl/standard-input.md @@ -1,4 +1,4 @@ -# Standard Input +% Standard Input Getting input from the keyboard is pretty easy, but uses some things we haven't seen before. Here's a simple program that reads some input, diff --git a/src/doc/trpl/src/strings.md b/src/doc/trpl/strings.md similarity index 99% rename from src/doc/trpl/src/strings.md rename to src/doc/trpl/strings.md index be1d09f6e9530..a40e748dae7b0 100644 --- a/src/doc/trpl/src/strings.md +++ b/src/doc/trpl/strings.md @@ -1,4 +1,4 @@ -# Strings +% Strings Strings are an important concept for any programmer to master. Rust's string handling system is a bit different from other languages, due to its systems diff --git a/src/doc/trpl/src/tasks.md b/src/doc/trpl/tasks.md similarity index 99% rename from src/doc/trpl/src/tasks.md rename to src/doc/trpl/tasks.md index 8eb13187e5841..8e9f40b0f4ec2 100644 --- a/src/doc/trpl/src/tasks.md +++ b/src/doc/trpl/tasks.md @@ -369,7 +369,7 @@ Unlike `spawn`, the function spawned using `try` may return a value, which child thread terminates successfully, `try` will return an `Ok` result; if the child thread panics, `try` will return an `Error` result. -[`Result`]: std/result/index.html +[`Result`]: ../std/result/index.html > *Note:* A panicked thread does not currently produce a useful error > value (`try` always returns `Err(())`). In the diff --git a/src/doc/trpl/src/testing.md b/src/doc/trpl/testing.md similarity index 100% rename from src/doc/trpl/src/testing.md rename to src/doc/trpl/testing.md diff --git a/src/doc/trpl/src/traits.md b/src/doc/trpl/traits.md similarity index 100% rename from src/doc/trpl/src/traits.md rename to src/doc/trpl/traits.md diff --git a/src/doc/trpl/src/unsafe.md b/src/doc/trpl/unsafe.md similarity index 98% rename from src/doc/trpl/src/unsafe.md rename to src/doc/trpl/unsafe.md index 25ca07ad74fe8..3e0a1ef13454a 100644 --- a/src/doc/trpl/src/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -12,7 +12,7 @@ block which allows the programmer to dodge some of the compiler's checks and do a wide range of operations, such as: - dereferencing [raw pointers](#raw-pointers) -- calling a function via FFI ([covered by the FFI guide](guide-ffi.html)) +- calling a function via FFI ([covered by the FFI guide](ffi.html)) - casting between types bitwise (`transmute`, aka "reinterpret cast") - [inline assembly](#inline-assembly) @@ -37,7 +37,7 @@ build safe interfaces. ## References One of Rust's biggest features is memory safety. This is achieved in -part via [the ownership system](guide-ownership.html), which is how the +part via [the ownership system](ownership.html), which is how the compiler can guarantee that every `&` reference is always valid, and, for example, never pointing to freed memory. @@ -504,7 +504,7 @@ shouldn't get triggered. The second of these three functions, `eh_personality`, is used by the failure mechanisms of the compiler. This is often mapped to GCC's personality function (see the -[libstd implementation](std/rt/unwind/index.html) for more +[libstd implementation](../std/rt/unwind/index.html) for more information), but crates which do not trigger a panic can be assured that this function is never called. The final function, `panic_fmt`, is also used by the failure mechanisms of the compiler. @@ -517,7 +517,7 @@ also used by the failure mechanisms of the compiler. With the above techniques, we've got a bare-metal executable running some Rust code. There is a good deal of functionality provided by the standard library, however, that is necessary to be productive in Rust. If the standard library is -not sufficient, then [libcore](core/index.html) is designed to be used +not sufficient, then [libcore](../core/index.html) is designed to be used instead. The core library has very few dependencies and is much more portable than the diff --git a/src/doc/trpl/src/variable-bindings.md b/src/doc/trpl/variable-bindings.md similarity index 98% rename from src/doc/trpl/src/variable-bindings.md rename to src/doc/trpl/variable-bindings.md index 8cf2522b9afec..4e2e7bd2fe2f4 100644 --- a/src/doc/trpl/src/variable-bindings.md +++ b/src/doc/trpl/variable-bindings.md @@ -1,4 +1,4 @@ -# Variable bindings +% Variable bindings The first thing we'll learn about are 'variable bindings.' They look like this: @@ -170,5 +170,5 @@ arguments we pass to functions and macros, if you're passing more than one. When you just use the curly braces, Rust will attempt to display the value in a meaningful way by checking out its type. If you want to specify the format in a more detailed manner, there are a [wide number of options -available](std/fmt/index.html). For now, we'll just stick to the default: +available](../std/fmt/index.html). For now, we'll just stick to the default: integers aren't very complicated to print. diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs index 45a864e337813..1d16de2a2febc 100644 --- a/src/rustbook/book.rs +++ b/src/rustbook/book.rs @@ -29,8 +29,8 @@ pub struct Book { /// A depth-first iterator over a book. pub struct BookItems<'a> { cur_items: &'a [BookItem], - cur_idx: uint, - stack: Vec<(&'a [BookItem], uint)>, + cur_idx: usize, + stack: Vec<(&'a [BookItem], usize)>, } impl<'a> Iterator for BookItems<'a> { @@ -80,7 +80,7 @@ impl Book { pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String>> { fn collapse(stack: &mut Vec<BookItem>, top_items: &mut Vec<BookItem>, - to_level: uint) { + to_level: usize) { loop { if stack.len() < to_level { return } if stack.len() == 1 { @@ -141,7 +141,7 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String }; let level = cap.name("indent").unwrap().chars().map(|c| { match c { - ' ' => 1u, + ' ' => 1us, '\t' => 4, _ => unreachable!() } diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs old mode 100755 new mode 100644 index db79e0b45e00f..1cb5e38e19076 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -130,8 +130,8 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { ]; let output_result = rustdoc::main_args(rustdoc_args); if output_result != 0 { - - let message = format!("Could not execute `rustdoc`: {}", output_result); + let message = format!("Could not execute `rustdoc` with {:?}: {}", + rustdoc_args, output_result); return Err(box message as Box<Error>); } } @@ -172,12 +172,13 @@ impl Subcommand for Build { match book::parse_summary(summary, &src) { Ok(book) => { // execute rustdoc on the whole book - let _ = render(&book, &tgt).map_err(|err| { + try!(render(&book, &tgt).map_err(|err| { term.err(&format!("error: {}", err.description())[]); err.detail().map(|detail| { term.err(&format!("detail: {}", detail)[]); - }) - }); + }); + err + })) } Err(errors) => { for err in errors.into_iter() { diff --git a/src/rustbook/error.rs b/src/rustbook/error.rs index 1d3baef8c1c75..a5915ed4d7370 100644 --- a/src/rustbook/error.rs +++ b/src/rustbook/error.rs @@ -56,6 +56,12 @@ impl Error for String { } } +impl<'a> Error for Box<Error + 'a> { + fn description(&self) -> &str { (**self).description() } + fn detail(&self) -> Option<&str> { (**self).detail() } + fn cause(&self) -> Option<&Error> { (**self).cause() } +} + impl FromError<()> for () { fn from_err(_: ()) -> () { () } } diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs old mode 100755 new mode 100644 diff --git a/src/rustbook/term.rs b/src/rustbook/term.rs index 18306d6ec20ba..471e22ce7c1f1 100644 --- a/src/rustbook/term.rs +++ b/src/rustbook/term.rs @@ -11,6 +11,7 @@ //! An abstraction of the terminal. Eventually, provide color and //! verbosity support. For now, just a wrapper around stdout/stderr. +use std::os; use std::io::stdio; pub struct Term { @@ -27,5 +28,6 @@ impl Term { pub fn err(&mut self, msg: &str) { // swallow any errors let _ = self.err.write_line(msg); + os::set_exit_status(101); } }

(path: P, timeout: Duration) -> IoResult where P: BytesContainer { @@ -107,7 +107,7 @@ impl UnixStream { /// Sets the read/write timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_timeout(&mut self, timeout_ms: Option) { self.inner.set_timeout(timeout_ms) } @@ -115,7 +115,7 @@ impl UnixStream { /// Sets the read timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_read_timeout(&mut self, timeout_ms: Option) { self.inner.set_read_timeout(timeout_ms) } @@ -123,7 +123,7 @@ impl UnixStream { /// Sets the write timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_write_timeout(&mut self, timeout_ms: Option) { self.inner.set_write_timeout(timeout_ms) } @@ -219,7 +219,7 @@ impl UnixAcceptor { /// When using this method, it is likely necessary to reset the timeout as /// appropriate, the timeout specified is specific to this object, not /// specific to the next request. - #[experimental = "the name and arguments to this function are likely \ + #[unstable = "the name and arguments to this function are likely \ to change"] pub fn set_timeout(&mut self, timeout_ms: Option) { self.inner.set_timeout(timeout_ms) @@ -229,7 +229,7 @@ impl UnixAcceptor { /// /// This function has the same semantics as `TcpAcceptor::close_accept`, and /// more information can be found in that documentation. - #[experimental] + #[unstable] pub fn close_accept(&mut self) -> IoResult<()> { self.inner.close_accept() } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 7a376b50cd7dd..6a3f5fcb2c699 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -85,7 +85,7 @@ impl TcpStream { /// /// If a `timeout` with zero or negative duration is specified then /// the function returns `Err`, with the error kind set to `TimedOut`. - #[experimental = "the timeout argument may eventually change types"] + #[unstable = "the timeout argument may eventually change types"] pub fn connect_timeout(addr: A, timeout: Duration) -> IoResult { if timeout <= Duration::milliseconds(0) { @@ -109,7 +109,7 @@ impl TcpStream { } /// Sets the nodelay flag on this connection to the boolean specified - #[experimental] + #[unstable] pub fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { self.inner.set_nodelay(nodelay) } @@ -119,7 +119,7 @@ impl TcpStream { /// If the value specified is `None`, then the keepalive flag is cleared on /// this connection. Otherwise, the keepalive timeout will be set to the /// specified time, in seconds. - #[experimental] + #[unstable] pub fn set_keepalive(&mut self, delay_in_seconds: Option) -> IoResult<()> { self.inner.set_keepalive(delay_in_seconds) } @@ -187,7 +187,7 @@ impl TcpStream { /// /// For clarification on the semantics of interrupting a read and a write, /// take a look at `set_read_timeout` and `set_write_timeout`. - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_timeout(&mut self, timeout_ms: Option) { self.inner.set_timeout(timeout_ms) } @@ -204,7 +204,7 @@ impl TcpStream { /// action is taken. Otherwise, the read operation will be scheduled to /// promptly return. If a timeout error is returned, then no data was read /// during the timeout period. - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_read_timeout(&mut self, timeout_ms: Option) { self.inner.set_read_timeout(timeout_ms) } @@ -231,7 +231,7 @@ impl TcpStream { /// does not know how many bytes were written as part of the timeout /// operation. It may be the case that bytes continue to be written in an /// asynchronous fashion after the call to write returns. - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_write_timeout(&mut self, timeout_ms: Option) { self.inner.set_write_timeout(timeout_ms) } @@ -374,7 +374,7 @@ impl TcpAcceptor { /// # Example /// /// ```no_run - /// # #![allow(experimental)] + /// # #![allow(unstable)] /// use std::io::TcpListener; /// use std::io::{Listener, Acceptor, TimedOut}; /// @@ -397,7 +397,7 @@ impl TcpAcceptor { /// a.set_timeout(None); /// let socket = a.accept(); /// ``` - #[experimental = "the type of the argument and name of this function are \ + #[unstable = "the type of the argument and name of this function are \ subject to change"] pub fn set_timeout(&mut self, ms: Option) { self.inner.set_timeout(ms); } @@ -418,7 +418,7 @@ impl TcpAcceptor { /// # Example /// /// ``` - /// # #![allow(experimental)] + /// # #![allow(unstable)] /// use std::io::{TcpListener, Listener, Acceptor, EndOfFile}; /// use std::thread::Thread; /// @@ -444,7 +444,7 @@ impl TcpAcceptor { /// // Signal our accept loop to exit /// assert!(a.close_accept().is_ok()); /// ``` - #[experimental] + #[unstable] pub fn close_accept(&mut self) -> IoResult<()> { self.inner.close_accept() } @@ -482,7 +482,7 @@ impl sys_common::AsInner for TcpAcceptor { } #[cfg(test)] -#[allow(experimental)] +#[allow(unstable)] mod test { use prelude::v1::*; diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index a4db0d4f5de77..8cdad3f528a48 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -92,13 +92,13 @@ impl UdpSocket { } /// Joins a multicast IP address (becomes a member of it) - #[experimental] + #[unstable] pub fn join_multicast(&mut self, multi: IpAddr) -> IoResult<()> { self.inner.join_multicast(multi) } /// Leaves a multicast IP address (drops membership from it) - #[experimental] + #[unstable] pub fn leave_multicast(&mut self, multi: IpAddr) -> IoResult<()> { self.inner.leave_multicast(multi) } @@ -106,25 +106,25 @@ impl UdpSocket { /// Set the multicast loop flag to the specified value /// /// This lets multicast packets loop back to local sockets (if enabled) - #[experimental] + #[unstable] pub fn set_multicast_loop(&mut self, on: bool) -> IoResult<()> { self.inner.set_multicast_loop(on) } /// Sets the multicast TTL - #[experimental] + #[unstable] pub fn set_multicast_ttl(&mut self, ttl: int) -> IoResult<()> { self.inner.multicast_time_to_live(ttl) } /// Sets this socket's TTL - #[experimental] + #[unstable] pub fn set_ttl(&mut self, ttl: int) -> IoResult<()> { self.inner.time_to_live(ttl) } /// Sets the broadcast flag on or off - #[experimental] + #[unstable] pub fn set_broadcast(&mut self, broadcast: bool) -> IoResult<()> { self.inner.set_broadcast(broadcast) } @@ -132,7 +132,7 @@ impl UdpSocket { /// Sets the read/write timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_timeout(&mut self, timeout_ms: Option) { self.inner.set_timeout(timeout_ms) } @@ -140,7 +140,7 @@ impl UdpSocket { /// Sets the read timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_read_timeout(&mut self, timeout_ms: Option) { self.inner.set_read_timeout(timeout_ms) } @@ -148,7 +148,7 @@ impl UdpSocket { /// Sets the write timeout for this socket. /// /// For more information, see `TcpStream::set_timeout` - #[experimental = "the timeout argument may change in type and value"] + #[unstable = "the timeout argument may change in type and value"] pub fn set_write_timeout(&mut self, timeout_ms: Option) { self.inner.set_write_timeout(timeout_ms) } @@ -176,7 +176,7 @@ impl sys_common::AsInner for UdpSocket { } #[cfg(test)] -#[allow(experimental)] +#[allow(unstable)] mod test { use prelude::v1::*; diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index f824d82160125..a093e748d5736 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -10,7 +10,7 @@ //! Bindings for executing child processes -#![allow(experimental)] +#![allow(unstable)] #![allow(non_upper_case_globals)] pub use self::StdioContainer::*; @@ -661,7 +661,7 @@ impl Process { /// # Example /// /// ```no_run - /// # #![allow(experimental)] + /// # #![allow(unstable)] /// use std::io::{Command, IoResult}; /// use std::io::process::ProcessExit; /// @@ -689,7 +689,7 @@ impl Process { /// p.wait() /// } /// ``` - #[experimental = "the type of the timeout is likely to change"] + #[unstable = "the type of the timeout is likely to change"] pub fn set_timeout(&mut self, timeout_ms: Option) { self.deadline = timeout_ms.map(|i| i + sys::timer::now()).unwrap_or(0); } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 0594b711ad62e..0f293d789ab0a 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -14,7 +14,7 @@ //! library. Each macro is available for use when linking against the standard //! library. -#![experimental] +#![unstable] /// The entry point for panic of Rust tasks. /// @@ -324,7 +324,7 @@ macro_rules! try { /// /// For more information about select, see the `std::sync::mpsc::Select` structure. #[macro_export] -#[experimental] +#[unstable] macro_rules! select { ( $($name:pat = $rx:ident.$meth:ident() => $code:expr),+ diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 0a1c17fab471e..adbce89388770 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -366,7 +366,7 @@ impl Float for f32 { /// /// * num - The float value #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_string(num: f32) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigAll, ExpNone, false); @@ -379,7 +379,7 @@ pub fn to_string(num: f32) -> String { /// /// * num - The float value #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_hex(num: f32) -> String { let (r, _) = strconv::float_to_str_common( num, 16u, true, SignNeg, DigAll, ExpNone, false); @@ -394,7 +394,7 @@ pub fn to_str_hex(num: f32) -> String { /// * num - The float value /// * radix - The base to use #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_radix_special(num: f32, rdx: uint) -> (String, bool) { strconv::float_to_str_common(num, rdx, true, SignNeg, DigAll, ExpNone, false) } @@ -407,7 +407,7 @@ pub fn to_str_radix_special(num: f32, rdx: uint) -> (String, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exact(num: f32, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigExact(dig), ExpNone, false); @@ -422,7 +422,7 @@ pub fn to_str_exact(num: f32, dig: uint) -> String { /// * num - The float value /// * digits - The number of significant digits #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_digits(num: f32, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigMax(dig), ExpNone, false); @@ -438,7 +438,7 @@ pub fn to_str_digits(num: f32, dig: uint) -> String { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigExact(dig), ExpDec, upper); @@ -454,7 +454,7 @@ pub fn to_str_exp_exact(num: f32, dig: uint, upper: bool) -> String { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigMax(dig), ExpDec, upper); diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 2806154a01681..baff14125ee17 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -375,7 +375,7 @@ impl Float for f64 { /// /// * num - The float value #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_string(num: f64) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigAll, ExpNone, false); @@ -388,7 +388,7 @@ pub fn to_string(num: f64) -> String { /// /// * num - The float value #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_hex(num: f64) -> String { let (r, _) = strconv::float_to_str_common( num, 16u, true, SignNeg, DigAll, ExpNone, false); @@ -403,7 +403,7 @@ pub fn to_str_hex(num: f64) -> String { /// * num - The float value /// * radix - The base to use #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_radix_special(num: f64, rdx: uint) -> (String, bool) { strconv::float_to_str_common(num, rdx, true, SignNeg, DigAll, ExpNone, false) } @@ -416,7 +416,7 @@ pub fn to_str_radix_special(num: f64, rdx: uint) -> (String, bool) { /// * num - The float value /// * digits - The number of significant digits #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exact(num: f64, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigExact(dig), ExpNone, false); @@ -431,7 +431,7 @@ pub fn to_str_exact(num: f64, dig: uint) -> String { /// * num - The float value /// * digits - The number of significant digits #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_digits(num: f64, dig: uint) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigMax(dig), ExpNone, false); @@ -447,7 +447,7 @@ pub fn to_str_digits(num: f64, dig: uint) -> String { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigExact(dig), ExpDec, upper); @@ -463,7 +463,7 @@ pub fn to_str_exp_exact(num: f64, dig: uint, upper: bool) -> String { /// * digits - The number of digits after the decimal point /// * upper - Use `E` instead of `e` for the exponent sign #[inline] -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String { let (r, _) = strconv::float_to_str_common( num, 10u, true, SignNeg, DigMax(dig), ExpDec, upper); diff --git a/src/libstd/num/float_macros.rs b/src/libstd/num/float_macros.rs index 4c52f29b12d76..ec168eaaa9de6 100644 --- a/src/libstd/num/float_macros.rs +++ b/src/libstd/num/float_macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![experimental] +#![unstable] #![doc(hidden)] macro_rules! assert_approx_eq { diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index ebcb20861879c..5bc5415287497 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![experimental] +#![unstable] #![doc(hidden)] macro_rules! int_module { ($T:ty) => ( diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 9c6911cf4d14a..e804408b4d0e2 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -33,7 +33,7 @@ pub use core::num::{FpCategory}; use option::Option; -#[experimental = "may be removed or relocated"] +#[unstable = "may be removed or relocated"] pub mod strconv; /// Mathematical operations on primitive floating point numbers. diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 4ce15491a0e53..f480a3b420f54 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![experimental] +#![unstable] #![doc(hidden)] #![allow(unsigned_negation)] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index cef85c260a7e5..6e3949b9e22d0 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -22,7 +22,7 @@ //! so we will not _hide_ the facts of which OS the user is on -- they should be given the //! opportunity to write OS-ignorant code by default. -#![experimental] +#![unstable] #![allow(missing_docs)] #![allow(non_snake_case)] diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index b474ae4e37195..1ec7b6b3edcbb 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -59,7 +59,7 @@ //! println!("path exists: {}", path.exists()); //! ``` -#![experimental] +#![unstable] use core::marker::Sized; use ffi::CString; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 3fa1efe1ccdfe..60d490982db7e 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -219,7 +219,7 @@ //! } //! ``` -#![experimental] +#![unstable] use cell::RefCell; use clone::Clone; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 5ef55f5b487d0..e3e4e132b8172 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -16,7 +16,7 @@ //! and should be considered as private implementation details for the //! time being. -#![experimental] +#![unstable] // FIXME: this should not be here. #![allow(missing_docs)] diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 03876189da9cc..4cd0b29688a70 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -582,7 +582,7 @@ fn begin_unwind_inner(msg: Box, file_line: &(&'static str, uint)) -> /// Only a limited number of callbacks can be registered, and this function /// returns whether the callback was successfully registered or not. It is not /// currently possible to unregister a callback once it has been registered. -#[experimental] +#[unstable] pub unsafe fn register(f: Callback) -> bool { match CALLBACK_CNT.fetch_add(1, Ordering::SeqCst) { // The invocation code has knowledge of this window where the count has diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index 862808a9e3d90..f4fbd378899e0 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -12,7 +12,7 @@ //! the standard library This varies per-platform, but these libraries are //! necessary for running libstd. -#![experimental] +#![unstable] // All platforms need to link to rustrt #[cfg(not(test))] diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index f8eae1322bf1f..83de98fdbffee 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -35,7 +35,7 @@ //! method, and see the method for more information about it. Due to this //! caveat, this queue may not be appropriate for all use-cases. -#![experimental] +#![unstable] // http://www.1024cores.net/home/lock-free-algorithms // /queues/non-intrusive-mpsc-node-based-queue diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index b7bb22b3ef314..0da458a51f108 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -46,7 +46,7 @@ //! ``` #![allow(dead_code)] -#![experimental = "This implementation, while likely sufficient, is unsafe and \ +#![unstable = "This implementation, while likely sufficient, is unsafe and \ likely to be error prone. At some point in the future this \ module will likely be replaced, and it is currently \ unknown how much API breakage that will cause. The ability \ diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index e8d6e380be5de..46c69f6f54789 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -33,7 +33,7 @@ //! concurrently between two tasks. This data structure is safe to use and //! enforces the semantics that there is one pusher and one popper. -#![experimental] +#![unstable] use core::prelude::*; diff --git a/src/libstd/sys/unix/ext.rs b/src/libstd/sys/unix/ext.rs index ae3c939bf78bd..0e4a9d1b307f7 100644 --- a/src/libstd/sys/unix/ext.rs +++ b/src/libstd/sys/unix/ext.rs @@ -29,7 +29,7 @@ //! } //! ``` -#![experimental] +#![unstable] use sys_common::AsInner; use libc; diff --git a/src/libstd/sys/windows/ext.rs b/src/libstd/sys/windows/ext.rs index 049aca3f59064..87ff31ab73cda 100644 --- a/src/libstd/sys/windows/ext.rs +++ b/src/libstd/sys/windows/ext.rs @@ -14,7 +14,7 @@ //! descriptors, and sockets, but its functionality will grow over //! time. -#![experimental] +#![unstable] use sys_common::AsInner; use libc; diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index c103365745cd6..932556fe1a65d 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -207,14 +207,14 @@ impl Builder { } /// Redirect thread-local stdout. - #[experimental = "Will likely go away after proc removal"] + #[unstable = "Will likely go away after proc removal"] pub fn stdout(mut self, stdout: Box) -> Builder { self.stdout = Some(stdout); self } /// Redirect thread-local stderr. - #[experimental = "Will likely go away after proc removal"] + #[unstable = "Will likely go away after proc removal"] pub fn stderr(mut self, stderr: Box) -> Builder { self.stderr = Some(stderr); self @@ -483,7 +483,7 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { impl JoinGuard<'static, T> { /// Detaches the child thread, allowing it to outlive its parent. - #[experimental = "unsure whether this API imposes limitations elsewhere"] + #[unstable = "unsure whether this API imposes limitations elsewhere"] pub fn detach(mut self) { unsafe { imp::detach(self.native) }; self.joined = true; // avoid joining in the destructor diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index a651d927c1431..162c3677168f8 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -10,7 +10,7 @@ //! Temporal quantification -#![experimental] +#![unstable] use {fmt, i64}; use ops::{Add, Sub, Mul, Div, Neg, FnOnce}; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 1efd6a87f863f..eb6a2a43d431f 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -15,7 +15,7 @@ //! This API is completely unstable and subject to change. #![crate_name = "syntax"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index b4f224cb4a7ce..7a161241ed682 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -39,7 +39,7 @@ //! [ti]: https://en.wikipedia.org/wiki/Terminfo #![crate_name = "term"] -#![experimental = "use the crates.io `term` library instead"] +#![unstable = "use the crates.io `term` library instead"] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index d04308814f85b..cb6405be7ee2f 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -24,7 +24,7 @@ // build off of. #![crate_name = "test"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index 27255cc33ee6a..ee508572adbd8 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -21,7 +21,7 @@ //! (yet) aim to provide a full set of Unicode tables. #![crate_name = "unicode"] -#![experimental] +#![unstable] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libunicode/u_char.rs b/src/libunicode/u_char.rs index 5693c222de123..4142a62ba6664 100644 --- a/src/libunicode/u_char.rs +++ b/src/libunicode/u_char.rs @@ -112,7 +112,7 @@ pub trait CharExt { /// 'XID_Start' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. - #[experimental = "mainly needed for compiler internals"] + #[unstable = "mainly needed for compiler internals"] fn is_xid_start(self) -> bool; /// Returns whether the specified `char` satisfies the 'XID_Continue' @@ -121,7 +121,7 @@ pub trait CharExt { /// 'XID_Continue' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. - #[experimental = "mainly needed for compiler internals"] + #[unstable = "mainly needed for compiler internals"] fn is_xid_continue(self) -> bool; /// Indicates whether a character is in lowercase. @@ -171,7 +171,7 @@ pub trait CharExt { /// /// Returns the lowercase equivalent of the character, or the character /// itself if no conversion is possible. - #[experimental = "pending case transformation decisions"] + #[unstable = "pending case transformation decisions"] fn to_lowercase(self) -> char; /// Converts a character to its uppercase equivalent. @@ -194,7 +194,7 @@ pub trait CharExt { /// [`SpecialCasing`.txt`]: ftp://ftp.unicode.org/Public/UNIDATA/SpecialCasing.txt /// /// [2]: http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf#G33992 - #[experimental = "pending case transformation decisions"] + #[unstable = "pending case transformation decisions"] fn to_uppercase(self) -> char; /// Returns this character's displayed width in columns, or `None` if it is a @@ -206,7 +206,7 @@ pub trait CharExt { /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) /// recommends that these characters be treated as 1 column (i.e., /// `is_cjk` = `false`) if the context cannot be reliably determined. - #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"] + #[unstable = "needs expert opinion. is_cjk flag stands out as ugly"] fn width(self, is_cjk: bool) -> Option; } @@ -238,10 +238,10 @@ impl CharExt for char { } } - #[experimental = "mainly needed for compiler internals"] + #[unstable = "mainly needed for compiler internals"] fn is_xid_start(self) -> bool { derived_property::XID_Start(self) } - #[experimental = "mainly needed for compiler internals"] + #[unstable = "mainly needed for compiler internals"] fn is_xid_continue(self) -> bool { derived_property::XID_Continue(self) } #[stable] @@ -288,12 +288,12 @@ impl CharExt for char { } } - #[experimental = "pending case transformation decisions"] + #[unstable = "pending case transformation decisions"] fn to_lowercase(self) -> char { conversions::to_lower(self) } - #[experimental = "pending case transformation decisions"] + #[unstable = "pending case transformation decisions"] fn to_uppercase(self) -> char { conversions::to_upper(self) } - #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"] + #[unstable = "needs expert opinion. is_cjk flag stands out as ugly"] fn width(self, is_cjk: bool) -> Option { charwidth::width(self, is_cjk) } } diff --git a/src/test/auxiliary/inherited_stability.rs b/src/test/auxiliary/inherited_stability.rs index 5691ce3bfa740..7a01ce3de0bcf 100644 --- a/src/test/auxiliary/inherited_stability.rs +++ b/src/test/auxiliary/inherited_stability.rs @@ -9,7 +9,8 @@ // except according to those terms. #![crate_name="inherited_stability"] #![crate_type = "lib"] -#![experimental] +#![unstable] +#![staged_api] pub fn experimental() {} @@ -26,7 +27,7 @@ pub mod stable_mod { #[unstable] pub mod unstable_mod { - #[experimental] + #[unstable] pub fn experimental() {} pub fn unstable() {} diff --git a/src/test/auxiliary/lint_output_format.rs b/src/test/auxiliary/lint_output_format.rs index 181b651ef521c..adbb90fe6c824 100755 --- a/src/test/auxiliary/lint_output_format.rs +++ b/src/test/auxiliary/lint_output_format.rs @@ -10,13 +10,14 @@ #![crate_name="lint_output_format"] #![crate_type = "lib"] +#![staged_api] #[deprecated] pub fn foo() -> uint { 20 } -#[experimental] +#[unstable] pub fn bar() -> uint { 40 } diff --git a/src/test/auxiliary/lint_stability.rs b/src/test/auxiliary/lint_stability.rs index 708830d025986..73724713b21c4 100644 --- a/src/test/auxiliary/lint_stability.rs +++ b/src/test/auxiliary/lint_stability.rs @@ -9,15 +9,16 @@ // except according to those terms. #![crate_name="lint_stability"] #![crate_type = "lib"] +#![staged_api] #[deprecated] pub fn deprecated() {} #[deprecated="text"] pub fn deprecated_text() {} -#[experimental] +#[unstable] pub fn experimental() {} -#[experimental="text"] +#[unstable="text"] pub fn experimental_text() {} #[unstable] @@ -51,9 +52,9 @@ impl MethodTester { #[deprecated="text"] pub fn method_deprecated_text(&self) {} - #[experimental] + #[unstable] pub fn method_experimental(&self) {} - #[experimental="text"] + #[unstable="text"] pub fn method_experimental_text(&self) {} #[unstable] @@ -85,9 +86,9 @@ pub trait Trait { #[deprecated="text"] fn trait_deprecated_text(&self) {} - #[experimental] + #[unstable] fn trait_experimental(&self) {} - #[experimental="text"] + #[unstable="text"] fn trait_experimental_text(&self) {} #[unstable] @@ -115,12 +116,12 @@ pub trait Trait { impl Trait for MethodTester {} -#[experimental] +#[unstable] pub trait ExperimentalTrait {} #[deprecated] pub struct DeprecatedStruct { pub i: int } -#[experimental] +#[unstable] pub struct ExperimentalStruct { pub i: int } #[unstable] pub struct UnstableStruct { pub i: int } @@ -134,7 +135,7 @@ pub struct LockedStruct { pub i: int } #[deprecated] pub struct DeprecatedUnitStruct; -#[experimental] +#[unstable] pub struct ExperimentalUnitStruct; #[unstable] pub struct UnstableUnitStruct; @@ -149,7 +150,7 @@ pub struct LockedUnitStruct; pub enum Enum { #[deprecated] DeprecatedVariant, - #[experimental] + #[unstable] ExperimentalVariant, #[unstable] UnstableVariant, @@ -165,7 +166,7 @@ pub enum Enum { #[deprecated] pub struct DeprecatedTupleStruct(pub int); -#[experimental] +#[unstable] pub struct ExperimentalTupleStruct(pub int); #[unstable] pub struct UnstableTupleStruct(pub int); diff --git a/src/test/auxiliary/stability_cfg1.rs b/src/test/auxiliary/stability_cfg1.rs index 6b2e8e7758f1a..de806c65bebc2 100644 --- a/src/test/auxiliary/stability_cfg1.rs +++ b/src/test/auxiliary/stability_cfg1.rs @@ -10,3 +10,4 @@ #![cfg_attr(foo, experimental)] #![cfg_attr(not(foo), stable)] +#![staged_api] diff --git a/src/test/auxiliary/stability_cfg2.rs b/src/test/auxiliary/stability_cfg2.rs index 3387b319abfd5..842f35b08aec3 100644 --- a/src/test/auxiliary/stability_cfg2.rs +++ b/src/test/auxiliary/stability_cfg2.rs @@ -10,6 +10,6 @@ // compile-flags:--cfg foo -#![cfg_attr(foo, experimental)] +#![cfg_attr(foo, unstable)] #![cfg_attr(not(foo), stable)] - +#![staged_api] diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index f6124c1271f05..cf1264ff5d675 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -39,7 +39,7 @@ // OF THE POSSIBILITY OF SUCH DAMAGE. #![feature(simd)] -#![allow(experimental)] +#![allow(unstable)] // ignore-pretty very bad with line comments diff --git a/src/test/compile-fail/issue-17337.rs b/src/test/compile-fail/issue-17337.rs index e0f655084ff70..24425e5eeecb5 100644 --- a/src/test/compile-fail/issue-17337.rs +++ b/src/test/compile-fail/issue-17337.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![staged_api] #![deny(deprecated)] struct Foo; diff --git a/src/test/compile-fail/lint-forbid-attr.rs b/src/test/compile-fail/lint-forbid-attr.rs index 92fabd6050bc1..d1fcf62115b20 100644 --- a/src/test/compile-fail/lint-forbid-attr.rs +++ b/src/test/compile-fail/lint-forbid-attr.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![forbid(experimental)] +#![forbid(unstable)] -#[allow(experimental)] //~ ERROR allow(experimental) overruled by outer forbid(experimental) +#[allow(unstable)] //~ ERROR allow(unstable) overruled by outer forbid(unstable) fn main() { } diff --git a/src/test/compile-fail/lint-forbid-cmdline.rs b/src/test/compile-fail/lint-forbid-cmdline.rs index 4de84825ada9e..e3be0d06a350f 100644 --- a/src/test/compile-fail/lint-forbid-cmdline.rs +++ b/src/test/compile-fail/lint-forbid-cmdline.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -F experimental +// compile-flags: -F unstable -#[allow(experimental)] //~ ERROR allow(experimental) overruled by outer forbid(experimental) +#![staged_api] +#[allow(unstable)] //~ ERROR allow(unstable) overruled by outer forbid(unstable) fn main() { } diff --git a/src/test/compile-fail/lint-output-format.rs b/src/test/compile-fail/lint-output-format.rs index 35721ee5b148f..10217481bf38a 100644 --- a/src/test/compile-fail/lint-output-format.rs +++ b/src/test/compile-fail/lint-output-format.rs @@ -8,14 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags:-F experimental -D unstable +// compile-flags:-F unstable // aux-build:lint_output_format.rs extern crate lint_output_format; //~ ERROR: use of unmarked item -use lint_output_format::{foo, bar, baz}; +use lint_output_format::{foo, bar}; fn main() { let _x = foo(); //~ WARNING #[warn(deprecated)] on by default - let _y = bar(); //~ ERROR [-F experimental] - let _z = baz(); //~ ERROR [-D unstable] + let _y = bar(); //~ ERROR [-F unstable] } diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 0e24269ec4449..1762285c28103 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -15,15 +15,16 @@ #![deny(unstable)] #![deny(deprecated)] -#![deny(experimental)] +#![deny(unstable)] #![allow(dead_code)] +#![staged_api] #[macro_use] extern crate lint_stability; //~ ERROR: use of unmarked item mod cross_crate { extern crate stability_cfg1; - extern crate stability_cfg2; //~ ERROR: use of experimental item + extern crate stability_cfg2; //~ ERROR: use of unstable item use lint_stability::*; @@ -38,13 +39,13 @@ mod cross_crate { foo.method_deprecated_text(); //~ ERROR use of deprecated item: text foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text - experimental(); //~ ERROR use of experimental item - foo.method_experimental(); //~ ERROR use of experimental item - foo.trait_experimental(); //~ ERROR use of experimental item + experimental(); //~ ERROR use of unstable item + foo.method_experimental(); //~ ERROR use of unstable item + foo.trait_experimental(); //~ ERROR use of unstable item - experimental_text(); //~ ERROR use of experimental item: text - foo.method_experimental_text(); //~ ERROR use of experimental item: text - foo.trait_experimental_text(); //~ ERROR use of experimental item: text + experimental_text(); //~ ERROR use of unstable item: text + foo.method_experimental_text(); //~ ERROR use of unstable item: text + foo.trait_experimental_text(); //~ ERROR use of unstable item: text unstable(); //~ ERROR use of unstable item foo.method_unstable(); //~ ERROR use of unstable item @@ -83,7 +84,7 @@ mod cross_crate { foo.trait_locked_text(); let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item - let _ = ExperimentalStruct { i: 0 }; //~ ERROR use of experimental item + let _ = ExperimentalStruct { i: 0 }; //~ ERROR use of unstable item let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable item let _ = UnmarkedStruct { i: 0 }; //~ ERROR use of unmarked item let _ = StableStruct { i: 0 }; @@ -91,7 +92,7 @@ mod cross_crate { let _ = LockedStruct { i: 0 }; let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item - let _ = ExperimentalUnitStruct; //~ ERROR use of experimental item + let _ = ExperimentalUnitStruct; //~ ERROR use of unstable item let _ = UnstableUnitStruct; //~ ERROR use of unstable item let _ = UnmarkedUnitStruct; //~ ERROR use of unmarked item let _ = StableUnitStruct; @@ -99,7 +100,7 @@ mod cross_crate { let _ = LockedUnitStruct; let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item - let _ = Enum::ExperimentalVariant; //~ ERROR use of experimental item + let _ = Enum::ExperimentalVariant; //~ ERROR use of unstable item let _ = Enum::UnstableVariant; //~ ERROR use of unstable item let _ = Enum::UnmarkedVariant; //~ ERROR use of unmarked item let _ = Enum::StableVariant; @@ -107,7 +108,7 @@ mod cross_crate { let _ = Enum::LockedVariant; let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item - let _ = ExperimentalTupleStruct (1); //~ ERROR use of experimental item + let _ = ExperimentalTupleStruct (1); //~ ERROR use of unstable item let _ = UnstableTupleStruct (1); //~ ERROR use of unstable item let _ = UnmarkedTupleStruct (1); //~ ERROR use of unmarked item let _ = StableTupleStruct (1); @@ -128,8 +129,8 @@ mod cross_crate { fn test_method_param(foo: F) { foo.trait_deprecated(); //~ ERROR use of deprecated item foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text - foo.trait_experimental(); //~ ERROR use of experimental item - foo.trait_experimental_text(); //~ ERROR use of experimental item: text + foo.trait_experimental(); //~ ERROR use of unstable item + foo.trait_experimental_text(); //~ ERROR use of unstable item: text foo.trait_unstable(); //~ ERROR use of unstable item foo.trait_unstable_text(); //~ ERROR use of unstable item: text foo.trait_unmarked(); //~ ERROR use of unmarked item @@ -139,8 +140,8 @@ mod cross_crate { fn test_method_object(foo: &Trait) { foo.trait_deprecated(); //~ ERROR use of deprecated item foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text - foo.trait_experimental(); //~ ERROR use of experimental item - foo.trait_experimental_text(); //~ ERROR use of experimental item: text + foo.trait_experimental(); //~ ERROR use of unstable item + foo.trait_experimental_text(); //~ ERROR use of unstable item: text foo.trait_unstable(); //~ ERROR use of unstable item foo.trait_unstable_text(); //~ ERROR use of unstable item: text foo.trait_unmarked(); //~ ERROR use of unmarked item @@ -149,33 +150,33 @@ mod cross_crate { struct S; - impl ExperimentalTrait for S { } //~ ERROR use of experimental item + impl ExperimentalTrait for S { } //~ ERROR use of unstable item - trait LocalTrait : ExperimentalTrait { } //~ ERROR use of experimental item + trait LocalTrait : ExperimentalTrait { } //~ ERROR use of unstable item } mod inheritance { - extern crate inherited_stability; //~ ERROR: use of experimental item + extern crate inherited_stability; //~ ERROR: use of unstable item use self::inherited_stability::*; fn test_inheritance() { - experimental(); //~ ERROR use of experimental item + experimental(); //~ ERROR use of unstable item stable(); - stable_mod::experimental(); //~ ERROR use of experimental item + stable_mod::experimental(); //~ ERROR use of unstable item stable_mod::stable(); - unstable_mod::experimental(); //~ ERROR use of experimental item + unstable_mod::experimental(); //~ ERROR use of unstable item unstable_mod::unstable(); //~ ERROR use of unstable item - experimental_mod::experimental(); //~ ERROR use of experimental item + experimental_mod::experimental(); //~ ERROR use of unstable item experimental_mod::stable(); - let _ = Experimental::ExperimentalVariant; //~ ERROR use of experimental item + let _ = Experimental::ExperimentalVariant; //~ ERROR use of unstable item let _ = Experimental::StableVariant; let x: uint = 0; - x.experimental(); //~ ERROR use of experimental item + x.experimental(); //~ ERROR use of unstable item x.stable(); } } @@ -186,9 +187,9 @@ mod this_crate { #[deprecated="text"] pub fn deprecated_text() {} - #[experimental] + #[unstable] pub fn experimental() {} - #[experimental="text"] + #[unstable="text"] pub fn experimental_text() {} #[unstable] @@ -222,9 +223,9 @@ mod this_crate { #[deprecated="text"] pub fn method_deprecated_text(&self) {} - #[experimental] + #[unstable] pub fn method_experimental(&self) {} - #[experimental="text"] + #[unstable="text"] pub fn method_experimental_text(&self) {} #[unstable] @@ -256,9 +257,9 @@ mod this_crate { #[deprecated="text"] fn trait_deprecated_text(&self) {} - #[experimental] + #[unstable] fn trait_experimental(&self) {} - #[experimental="text"] + #[unstable="text"] fn trait_experimental_text(&self) {} #[unstable] @@ -288,7 +289,7 @@ mod this_crate { #[deprecated] pub struct DeprecatedStruct { i: int } - #[experimental] + #[unstable] pub struct ExperimentalStruct { i: int } #[unstable] pub struct UnstableStruct { i: int } @@ -302,7 +303,7 @@ mod this_crate { #[deprecated] pub struct DeprecatedUnitStruct; - #[experimental] + #[unstable] pub struct ExperimentalUnitStruct; #[unstable] pub struct UnstableUnitStruct; @@ -317,7 +318,7 @@ mod this_crate { pub enum Enum { #[deprecated] DeprecatedVariant, - #[experimental] + #[unstable] ExperimentalVariant, #[unstable] UnstableVariant, @@ -333,7 +334,7 @@ mod this_crate { #[deprecated] pub struct DeprecatedTupleStruct(int); - #[experimental] + #[unstable] pub struct ExperimentalTupleStruct(int); #[unstable] pub struct UnstableTupleStruct(int); diff --git a/src/test/compile-fail/simd-binop.rs b/src/test/compile-fail/simd-binop.rs index 9fbb7364054d5..0c2d8972ce7ae 100644 --- a/src/test/compile-fail/simd-binop.rs +++ b/src/test/compile-fail/simd-binop.rs @@ -10,7 +10,7 @@ // ignore-tidy-linelength -#![allow(experimental)] +#![allow(unstable)] use std::simd::f32x4; diff --git a/src/test/compile-fail/simd-experimental.rs b/src/test/compile-fail/simd-experimental.rs index 5f9f56bf3c0f4..aea970f90b2c3 100644 --- a/src/test/compile-fail/simd-experimental.rs +++ b/src/test/compile-fail/simd-experimental.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(experimental)] +#![deny(unstable)] use std::simd; diff --git a/src/test/debuginfo/simd.rs b/src/test/debuginfo/simd.rs index 288e7461dd5a0..4aaa3e0b75f31 100644 --- a/src/test/debuginfo/simd.rs +++ b/src/test/debuginfo/simd.rs @@ -41,7 +41,7 @@ // gdb-command:continue -#![allow(experimental)] +#![allow(unstable)] #![allow(unused_variables)] #![omit_gdb_pretty_printer_section] diff --git a/src/test/run-pass/simd-binop.rs b/src/test/run-pass/simd-binop.rs index 7f9be78d5832d..690ad35124709 100644 --- a/src/test/run-pass/simd-binop.rs +++ b/src/test/run-pass/simd-binop.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(experimental)] +#![allow(unstable)] use std::simd::{i32x4, f32x4, u32x4}; diff --git a/src/test/run-pass/simd-issue-10604.rs b/src/test/run-pass/simd-issue-10604.rs index 966db25a128a7..6f0db23e2a621 100644 --- a/src/test/run-pass/simd-issue-10604.rs +++ b/src/test/run-pass/simd-issue-10604.rs @@ -9,7 +9,7 @@ // except according to those terms. -#![allow(experimental)] +#![allow(unstable)] #![feature(simd)] pub fn main() { diff --git a/src/test/run-pass/tcp-connect-timeouts.rs b/src/test/run-pass/tcp-connect-timeouts.rs index 4ab089b6eaa1c..56044289fba3a 100644 --- a/src/test/run-pass/tcp-connect-timeouts.rs +++ b/src/test/run-pass/tcp-connect-timeouts.rs @@ -16,7 +16,7 @@ // one test task to ensure that errors are timeouts, not file descriptor // exhaustion. -#![allow(experimental)] +#![allow(unstable)] #![reexport_test_harness_main = "test_main"] #![allow(unused_imports)] From 114d2bdad16ed6fe106542492e744255f33e8628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 8 Jan 2015 13:14:07 +0100 Subject: [PATCH 03/25] Restore indentation in common.rs Most of the file lost one level of indentation in a recent rollup. Most likely an accident during merge conflict resolution. --- src/librustc_trans/trans/common.rs | 1348 ++++++++++++++-------------- 1 file changed, 674 insertions(+), 674 deletions(-) diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index ab5b563b99c72..3afd33d324dd1 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -124,144 +124,144 @@ pub fn type_is_sized<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { } pub fn lltype_is_sized<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { -match ty.sty { - ty::ty_open(_) => true, - _ => type_is_sized(cx, ty), -} + match ty.sty { + ty::ty_open(_) => true, + _ => type_is_sized(cx, ty), + } } pub fn type_is_fat_ptr<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { -match ty.sty { - ty::ty_ptr(ty::mt{ty, ..}) | - ty::ty_rptr(_, ty::mt{ty, ..}) | - ty::ty_uniq(ty) => { - !type_is_sized(cx, ty) - } - _ => { - false + match ty.sty { + ty::ty_ptr(ty::mt{ty, ..}) | + ty::ty_rptr(_, ty::mt{ty, ..}) | + ty::ty_uniq(ty) => { + !type_is_sized(cx, ty) + } + _ => { + false + } } } -} // Return the smallest part of `ty` which is unsized. Fails if `ty` is sized. // 'Smallest' here means component of the static representation of the type; not // the size of an object at runtime. pub fn unsized_part_of_type<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { -match ty.sty { - ty::ty_str | ty::ty_trait(..) | ty::ty_vec(..) => ty, - ty::ty_struct(def_id, substs) => { - let unsized_fields: Vec<_> = - ty::struct_fields(cx, def_id, substs) - .iter() - .map(|f| f.mt.ty) - .filter(|ty| !type_is_sized(cx, *ty)) - .collect(); - - // Exactly one of the fields must be unsized. - assert!(unsized_fields.len() == 1); - - unsized_part_of_type(cx, unsized_fields[0]) - } - _ => { - assert!(type_is_sized(cx, ty), - "unsized_part_of_type failed even though ty is unsized"); - panic!("called unsized_part_of_type with sized ty"); + match ty.sty { + ty::ty_str | ty::ty_trait(..) | ty::ty_vec(..) => ty, + ty::ty_struct(def_id, substs) => { + let unsized_fields: Vec<_> = + ty::struct_fields(cx, def_id, substs) + .iter() + .map(|f| f.mt.ty) + .filter(|ty| !type_is_sized(cx, *ty)) + .collect(); + + // Exactly one of the fields must be unsized. + assert!(unsized_fields.len() == 1); + + unsized_part_of_type(cx, unsized_fields[0]) + } + _ => { + assert!(type_is_sized(cx, ty), + "unsized_part_of_type failed even though ty is unsized"); + panic!("called unsized_part_of_type with sized ty"); + } } } -} // Some things don't need cleanups during unwinding because the // task can free them all at once later. Currently only things // that only contain scalars and shared boxes can avoid unwind // cleanups. pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { -return memoized(ccx.needs_unwind_cleanup_cache(), ty, |ty| { - type_needs_unwind_cleanup_(ccx.tcx(), ty, &mut FnvHashSet::new()) -}); - -fn type_needs_unwind_cleanup_<'tcx>(tcx: &ty::ctxt<'tcx>, - ty: Ty<'tcx>, - tycache: &mut FnvHashSet>) - -> bool -{ - // Prevent infinite recursion - if !tycache.insert(ty) { - return false; - } - - let mut needs_unwind_cleanup = false; - ty::maybe_walk_ty(ty, |ty| { - needs_unwind_cleanup |= match ty.sty { - ty::ty_bool | ty::ty_int(_) | ty::ty_uint(_) | - ty::ty_float(_) | ty::ty_tup(_) | ty::ty_ptr(_) => false, + return memoized(ccx.needs_unwind_cleanup_cache(), ty, |ty| { + type_needs_unwind_cleanup_(ccx.tcx(), ty, &mut FnvHashSet::new()) + }); - ty::ty_enum(did, substs) => - ty::enum_variants(tcx, did).iter().any(|v| - v.args.iter().any(|&aty| { - let t = aty.subst(tcx, substs); - type_needs_unwind_cleanup_(tcx, t, tycache) - }) - ), + fn type_needs_unwind_cleanup_<'tcx>(tcx: &ty::ctxt<'tcx>, + ty: Ty<'tcx>, + tycache: &mut FnvHashSet>) + -> bool + { + // Prevent infinite recursion + if !tycache.insert(ty) { + return false; + } - _ => true - }; - !needs_unwind_cleanup - }); - needs_unwind_cleanup -} + let mut needs_unwind_cleanup = false; + ty::maybe_walk_ty(ty, |ty| { + needs_unwind_cleanup |= match ty.sty { + ty::ty_bool | ty::ty_int(_) | ty::ty_uint(_) | + ty::ty_float(_) | ty::ty_tup(_) | ty::ty_ptr(_) => false, + + ty::ty_enum(did, substs) => + ty::enum_variants(tcx, did).iter().any(|v| + v.args.iter().any(|&aty| { + let t = aty.subst(tcx, substs); + type_needs_unwind_cleanup_(tcx, t, tycache) + }) + ), + + _ => true + }; + !needs_unwind_cleanup + }); + needs_unwind_cleanup + } } pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { -ty::type_contents(cx, ty).needs_drop(cx) + ty::type_contents(cx, ty).needs_drop(cx) } fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { -match ty.sty { - ty::ty_struct(def_id, substs) => { - let fields = ty::struct_fields(ccx.tcx(), def_id, substs); - fields.len() == 1 && - fields[0].name == - token::special_idents::unnamed_field.name && - type_is_immediate(ccx, fields[0].mt.ty) + match ty.sty { + ty::ty_struct(def_id, substs) => { + let fields = ty::struct_fields(ccx.tcx(), def_id, substs); + fields.len() == 1 && + fields[0].name == + token::special_idents::unnamed_field.name && + type_is_immediate(ccx, fields[0].mt.ty) + } + _ => false } - _ => false -} } pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { -use trans::machine::llsize_of_alloc; -use trans::type_of::sizing_type_of; - -let tcx = ccx.tcx(); -let simple = ty::type_is_scalar(ty) || - ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) || - type_is_newtype_immediate(ccx, ty) || - ty::type_is_simd(tcx, ty); -if simple && !type_is_fat_ptr(tcx, ty) { - return true; -} -if !type_is_sized(tcx, ty) { - return false; -} -match ty.sty { - ty::ty_struct(..) | ty::ty_enum(..) | ty::ty_tup(..) | - ty::ty_unboxed_closure(..) => { - let llty = sizing_type_of(ccx, ty); - llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type()) + use trans::machine::llsize_of_alloc; + use trans::type_of::sizing_type_of; + + let tcx = ccx.tcx(); + let simple = ty::type_is_scalar(ty) || + ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) || + type_is_newtype_immediate(ccx, ty) || + ty::type_is_simd(tcx, ty); + if simple && !type_is_fat_ptr(tcx, ty) { + return true; + } + if !type_is_sized(tcx, ty) { + return false; + } + match ty.sty { + ty::ty_struct(..) | ty::ty_enum(..) | ty::ty_tup(..) | + ty::ty_unboxed_closure(..) => { + let llty = sizing_type_of(ccx, ty); + llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type()) + } + _ => type_is_zero_size(ccx, ty) } - _ => type_is_zero_size(ccx, ty) -} } /// Identify types which have size zero at runtime. pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { -use trans::machine::llsize_of_alloc; -use trans::type_of::sizing_type_of; -let llty = sizing_type_of(ccx, ty); -llsize_of_alloc(ccx, llty) == 0 + use trans::machine::llsize_of_alloc; + use trans::type_of::sizing_type_of; + let llty = sizing_type_of(ccx, ty); + llsize_of_alloc(ccx, llty) == 0 } /// Identifies types which we declare to be equivalent to `void` in C for the purpose of function @@ -269,25 +269,25 @@ llsize_of_alloc(ccx, llty) == 0 /// zero-size, but not all zero-size types use a `void` return type (in order to aid with C ABI /// compatibility). pub fn return_type_is_void(ccx: &CrateContext, ty: Ty) -> bool { -ty::type_is_nil(ty) || ty::type_is_empty(ccx.tcx(), ty) + ty::type_is_nil(ty) || ty::type_is_empty(ccx.tcx(), ty) } /// Generates a unique symbol based off the name given. This is used to create /// unique symbols for things like closures. pub fn gensym_name(name: &str) -> PathElem { -let num = token::gensym(name).uint(); -// use one colon which will get translated to a period by the mangler, and -// we're guaranteed that `num` is globally unique for this crate. -PathName(token::gensym(&format!("{}:{}", name, num)[])) + let num = token::gensym(name).uint(); + // use one colon which will get translated to a period by the mangler, and + // we're guaranteed that `num` is globally unique for this crate. + PathName(token::gensym(&format!("{}:{}", name, num)[])) } #[derive(Copy)] pub struct tydesc_info<'tcx> { -pub ty: Ty<'tcx>, -pub tydesc: ValueRef, -pub size: ValueRef, -pub align: ValueRef, -pub name: ValueRef, + pub ty: Ty<'tcx>, + pub tydesc: ValueRef, + pub size: ValueRef, + pub align: ValueRef, + pub name: ValueRef, } /* @@ -318,36 +318,36 @@ pub name: ValueRef, #[derive(Copy)] pub struct NodeInfo { -pub id: ast::NodeId, -pub span: Span, + pub id: ast::NodeId, + pub span: Span, } pub fn expr_info(expr: &ast::Expr) -> NodeInfo { -NodeInfo { id: expr.id, span: expr.span } + NodeInfo { id: expr.id, span: expr.span } } pub struct BuilderRef_res { -pub b: BuilderRef, + pub b: BuilderRef, } impl Drop for BuilderRef_res { -fn drop(&mut self) { - unsafe { - llvm::LLVMDisposeBuilder(self.b); + fn drop(&mut self) { + unsafe { + llvm::LLVMDisposeBuilder(self.b); + } } } -} pub fn BuilderRef_res(b: BuilderRef) -> BuilderRef_res { -BuilderRef_res { - b: b -} + BuilderRef_res { + b: b + } } pub type ExternMap = FnvHashMap; pub fn validate_substs(substs: &Substs) { -assert!(substs.types.all(|t| !ty::type_needs_infer(*t))); + assert!(substs.types.all(|t| !ty::type_needs_infer(*t))); } // work around bizarre resolve errors @@ -357,183 +357,183 @@ type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>; // Function context. Every LLVM function we create will have one of // these. pub struct FunctionContext<'a, 'tcx: 'a> { -// The ValueRef returned from a call to llvm::LLVMAddFunction; the -// address of the first instruction in the sequence of -// instructions for this function that will go in the .text -// section of the executable we're generating. -pub llfn: ValueRef, + // The ValueRef returned from a call to llvm::LLVMAddFunction; the + // address of the first instruction in the sequence of + // instructions for this function that will go in the .text + // section of the executable we're generating. + pub llfn: ValueRef, -// always an empty parameter-environment -pub param_env: ty::ParameterEnvironment<'a, 'tcx>, + // always an empty parameter-environment + pub param_env: ty::ParameterEnvironment<'a, 'tcx>, -// The environment argument in a closure. -pub llenv: Option, + // The environment argument in a closure. + pub llenv: Option, -// A pointer to where to store the return value. If the return type is -// immediate, this points to an alloca in the function. Otherwise, it's a -// pointer to the hidden first parameter of the function. After function -// construction, this should always be Some. -pub llretslotptr: Cell>, + // A pointer to where to store the return value. If the return type is + // immediate, this points to an alloca in the function. Otherwise, it's a + // pointer to the hidden first parameter of the function. After function + // construction, this should always be Some. + pub llretslotptr: Cell>, -// These pub elements: "hoisted basic blocks" containing -// administrative activities that have to happen in only one place in -// the function, due to LLVM's quirks. -// A marker for the place where we want to insert the function's static -// allocas, so that LLVM will coalesce them into a single alloca call. -pub alloca_insert_pt: Cell>, -pub llreturn: Cell>, + // These pub elements: "hoisted basic blocks" containing + // administrative activities that have to happen in only one place in + // the function, due to LLVM's quirks. + // A marker for the place where we want to insert the function's static + // allocas, so that LLVM will coalesce them into a single alloca call. + pub alloca_insert_pt: Cell>, + pub llreturn: Cell>, -// If the function has any nested return's, including something like: -// fn foo() -> Option { Some(Foo { x: return None }) }, then -// we use a separate alloca for each return -pub needs_ret_allocas: bool, + // If the function has any nested return's, including something like: + // fn foo() -> Option { Some(Foo { x: return None }) }, then + // we use a separate alloca for each return + pub needs_ret_allocas: bool, -// The a value alloca'd for calls to upcalls.rust_personality. Used when -// outputting the resume instruction. -pub personality: Cell>, + // The a value alloca'd for calls to upcalls.rust_personality. Used when + // outputting the resume instruction. + pub personality: Cell>, -// True if the caller expects this fn to use the out pointer to -// return. Either way, your code should write into the slot llretslotptr -// points to, but if this value is false, that slot will be a local alloca. -pub caller_expects_out_pointer: bool, + // True if the caller expects this fn to use the out pointer to + // return. Either way, your code should write into the slot llretslotptr + // points to, but if this value is false, that slot will be a local alloca. + pub caller_expects_out_pointer: bool, -// Maps the DefId's for local variables to the allocas created for -// them in llallocas. -pub lllocals: RefCell>>, + // Maps the DefId's for local variables to the allocas created for + // them in llallocas. + pub lllocals: RefCell>>, -// Same as above, but for closure upvars -pub llupvars: RefCell>, + // Same as above, but for closure upvars + pub llupvars: RefCell>, -// The NodeId of the function, or -1 if it doesn't correspond to -// a user-defined function. -pub id: ast::NodeId, + // The NodeId of the function, or -1 if it doesn't correspond to + // a user-defined function. + pub id: ast::NodeId, -// If this function is being monomorphized, this contains the type -// substitutions used. -pub param_substs: &'a Substs<'tcx>, + // If this function is being monomorphized, this contains the type + // substitutions used. + pub param_substs: &'a Substs<'tcx>, -// The source span and nesting context where this function comes from, for -// error reporting and symbol generation. -pub span: Option, + // The source span and nesting context where this function comes from, for + // error reporting and symbol generation. + pub span: Option, -// The arena that blocks are allocated from. -pub block_arena: &'a TypedArena>, + // The arena that blocks are allocated from. + pub block_arena: &'a TypedArena>, -// This function's enclosing crate context. -pub ccx: &'a CrateContext<'a, 'tcx>, + // This function's enclosing crate context. + pub ccx: &'a CrateContext<'a, 'tcx>, -// Used and maintained by the debuginfo module. -pub debug_context: debuginfo::FunctionDebugContext, + // Used and maintained by the debuginfo module. + pub debug_context: debuginfo::FunctionDebugContext, -// Cleanup scopes. -pub scopes: RefCell>>, + // Cleanup scopes. + pub scopes: RefCell>>, -pub cfg: Option, + pub cfg: Option, } impl<'a, 'tcx> FunctionContext<'a, 'tcx> { -pub fn arg_pos(&self, arg: uint) -> uint { - let arg = self.env_arg_pos() + arg; - if self.llenv.is_some() { - arg + 1 - } else { - arg + pub fn arg_pos(&self, arg: uint) -> uint { + let arg = self.env_arg_pos() + arg; + if self.llenv.is_some() { + arg + 1 + } else { + arg + } } -} -pub fn env_arg_pos(&self) -> uint { - if self.caller_expects_out_pointer { - 1u - } else { - 0u + pub fn env_arg_pos(&self) -> uint { + if self.caller_expects_out_pointer { + 1u + } else { + 0u + } } -} -pub fn cleanup(&self) { - unsafe { - llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt - .get() - .unwrap()); + pub fn cleanup(&self) { + unsafe { + llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt + .get() + .unwrap()); + } } -} -pub fn get_llreturn(&self) -> BasicBlockRef { - if self.llreturn.get().is_none() { + pub fn get_llreturn(&self) -> BasicBlockRef { + if self.llreturn.get().is_none() { - self.llreturn.set(Some(unsafe { - llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), self.llfn, - "return\0".as_ptr() as *const _) - })) - } + self.llreturn.set(Some(unsafe { + llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), self.llfn, + "return\0".as_ptr() as *const _) + })) + } - self.llreturn.get().unwrap() -} + self.llreturn.get().unwrap() + } -pub fn get_ret_slot(&self, bcx: Block<'a, 'tcx>, - output: ty::FnOutput<'tcx>, - name: &str) -> ValueRef { - if self.needs_ret_allocas { - base::alloca_no_lifetime(bcx, match output { - ty::FnConverging(output_type) => type_of::type_of(bcx.ccx(), output_type), - ty::FnDiverging => Type::void(bcx.ccx()) - }, name) - } else { - self.llretslotptr.get().unwrap() + pub fn get_ret_slot(&self, bcx: Block<'a, 'tcx>, + output: ty::FnOutput<'tcx>, + name: &str) -> ValueRef { + if self.needs_ret_allocas { + base::alloca_no_lifetime(bcx, match output { + ty::FnConverging(output_type) => type_of::type_of(bcx.ccx(), output_type), + ty::FnDiverging => Type::void(bcx.ccx()) + }, name) + } else { + self.llretslotptr.get().unwrap() + } } -} -pub fn new_block(&'a self, - is_lpad: bool, - name: &str, - opt_node_id: Option) - -> Block<'a, 'tcx> { - unsafe { - let name = CString::from_slice(name.as_bytes()); - let llbb = llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), - self.llfn, - name.as_ptr()); - BlockS::new(llbb, is_lpad, opt_node_id, self) + pub fn new_block(&'a self, + is_lpad: bool, + name: &str, + opt_node_id: Option) + -> Block<'a, 'tcx> { + unsafe { + let name = CString::from_slice(name.as_bytes()); + let llbb = llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), + self.llfn, + name.as_ptr()); + BlockS::new(llbb, is_lpad, opt_node_id, self) + } } -} -pub fn new_id_block(&'a self, - name: &str, - node_id: ast::NodeId) - -> Block<'a, 'tcx> { - self.new_block(false, name, Some(node_id)) -} + pub fn new_id_block(&'a self, + name: &str, + node_id: ast::NodeId) + -> Block<'a, 'tcx> { + self.new_block(false, name, Some(node_id)) + } -pub fn new_temp_block(&'a self, - name: &str) - -> Block<'a, 'tcx> { - self.new_block(false, name, None) -} + pub fn new_temp_block(&'a self, + name: &str) + -> Block<'a, 'tcx> { + self.new_block(false, name, None) + } -pub fn join_blocks(&'a self, - id: ast::NodeId, - in_cxs: &[Block<'a, 'tcx>]) - -> Block<'a, 'tcx> { - let out = self.new_id_block("join", id); - let mut reachable = false; - for bcx in in_cxs.iter() { - if !bcx.unreachable.get() { - build::Br(*bcx, out.llbb); - reachable = true; + pub fn join_blocks(&'a self, + id: ast::NodeId, + in_cxs: &[Block<'a, 'tcx>]) + -> Block<'a, 'tcx> { + let out = self.new_id_block("join", id); + let mut reachable = false; + for bcx in in_cxs.iter() { + if !bcx.unreachable.get() { + build::Br(*bcx, out.llbb); + reachable = true; + } } + if !reachable { + build::Unreachable(out); + } + return out; } - if !reachable { - build::Unreachable(out); - } - return out; -} -pub fn monomorphize(&self, value: &T) -> T - where T : TypeFoldable<'tcx> + Repr<'tcx> + HasProjectionTypes + Clone -{ - monomorphize::apply_param_substs(self.ccx.tcx(), - self.param_substs, - value) -} + pub fn monomorphize(&self, value: &T) -> T + where T : TypeFoldable<'tcx> + Repr<'tcx> + HasProjectionTypes + Clone + { + monomorphize::apply_param_substs(self.ccx.tcx(), + self.param_substs, + value) + } } // Basic block context. We create a block context for each basic block @@ -542,277 +542,277 @@ pub fn monomorphize(&self, value: &T) -> T // with many basic blocks per function. All the basic blocks attached to a // function are organized as a directed graph. pub struct BlockS<'blk, 'tcx: 'blk> { -// The BasicBlockRef returned from a call to -// llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic -// block to the function pointed to by llfn. We insert -// instructions into that block by way of this block context. -// The block pointing to this one in the function's digraph. -pub llbb: BasicBlockRef, -pub terminated: Cell, -pub unreachable: Cell, + // The BasicBlockRef returned from a call to + // llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic + // block to the function pointed to by llfn. We insert + // instructions into that block by way of this block context. + // The block pointing to this one in the function's digraph. + pub llbb: BasicBlockRef, + pub terminated: Cell, + pub unreachable: Cell, -// Is this block part of a landing pad? -pub is_lpad: bool, + // Is this block part of a landing pad? + pub is_lpad: bool, -// AST node-id associated with this block, if any. Used for -// debugging purposes only. -pub opt_node_id: Option, + // AST node-id associated with this block, if any. Used for + // debugging purposes only. + pub opt_node_id: Option, -// The function context for the function to which this block is -// attached. -pub fcx: &'blk FunctionContext<'blk, 'tcx>, + // The function context for the function to which this block is + // attached. + pub fcx: &'blk FunctionContext<'blk, 'tcx>, } pub type Block<'blk, 'tcx> = &'blk BlockS<'blk, 'tcx>; impl<'blk, 'tcx> BlockS<'blk, 'tcx> { -pub fn new(llbb: BasicBlockRef, - is_lpad: bool, - opt_node_id: Option, - fcx: &'blk FunctionContext<'blk, 'tcx>) - -> Block<'blk, 'tcx> { - fcx.block_arena.alloc(BlockS { - llbb: llbb, - terminated: Cell::new(false), - unreachable: Cell::new(false), - is_lpad: is_lpad, - opt_node_id: opt_node_id, - fcx: fcx - }) -} + pub fn new(llbb: BasicBlockRef, + is_lpad: bool, + opt_node_id: Option, + fcx: &'blk FunctionContext<'blk, 'tcx>) + -> Block<'blk, 'tcx> { + fcx.block_arena.alloc(BlockS { + llbb: llbb, + terminated: Cell::new(false), + unreachable: Cell::new(false), + is_lpad: is_lpad, + opt_node_id: opt_node_id, + fcx: fcx + }) + } -pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> { - self.fcx.ccx -} -pub fn tcx(&self) -> &'blk ty::ctxt<'tcx> { - self.fcx.ccx.tcx() -} -pub fn sess(&self) -> &'blk Session { self.fcx.ccx.sess() } + pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> { + self.fcx.ccx + } + pub fn tcx(&self) -> &'blk ty::ctxt<'tcx> { + self.fcx.ccx.tcx() + } + pub fn sess(&self) -> &'blk Session { self.fcx.ccx.sess() } -pub fn ident(&self, ident: Ident) -> String { - token::get_ident(ident).get().to_string() -} + pub fn ident(&self, ident: Ident) -> String { + token::get_ident(ident).get().to_string() + } -pub fn node_id_to_string(&self, id: ast::NodeId) -> String { - self.tcx().map.node_to_string(id).to_string() -} + pub fn node_id_to_string(&self, id: ast::NodeId) -> String { + self.tcx().map.node_to_string(id).to_string() + } -pub fn expr_to_string(&self, e: &ast::Expr) -> String { - e.repr(self.tcx()) -} + pub fn expr_to_string(&self, e: &ast::Expr) -> String { + e.repr(self.tcx()) + } -pub fn def(&self, nid: ast::NodeId) -> def::Def { - match self.tcx().def_map.borrow().get(&nid) { - Some(v) => v.clone(), - None => { - self.tcx().sess.bug(&format!( - "no def associated with node id {}", nid)[]); + pub fn def(&self, nid: ast::NodeId) -> def::Def { + match self.tcx().def_map.borrow().get(&nid) { + Some(v) => v.clone(), + None => { + self.tcx().sess.bug(&format!( + "no def associated with node id {}", nid)[]); + } } } -} -pub fn val_to_string(&self, val: ValueRef) -> String { - self.ccx().tn().val_to_string(val) -} + pub fn val_to_string(&self, val: ValueRef) -> String { + self.ccx().tn().val_to_string(val) + } -pub fn llty_str(&self, ty: Type) -> String { - self.ccx().tn().type_to_string(ty) -} + pub fn llty_str(&self, ty: Type) -> String { + self.ccx().tn().type_to_string(ty) + } -pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { - t.repr(self.tcx()) -} + pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { + t.repr(self.tcx()) + } -pub fn to_str(&self) -> String { - format!("[block {:p}]", self) -} + pub fn to_str(&self) -> String { + format!("[block {:p}]", self) + } -pub fn monomorphize(&self, value: &T) -> T - where T : TypeFoldable<'tcx> + Repr<'tcx> + HasProjectionTypes + Clone -{ - monomorphize::apply_param_substs(self.tcx(), - self.fcx.param_substs, - value) -} + pub fn monomorphize(&self, value: &T) -> T + where T : TypeFoldable<'tcx> + Repr<'tcx> + HasProjectionTypes + Clone + { + monomorphize::apply_param_substs(self.tcx(), + self.fcx.param_substs, + value) + } } impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { -fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { - self.tcx() -} + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { + self.tcx() + } -fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { - Ok(node_id_type(self, id)) -} + fn node_ty(&self, id: ast::NodeId) -> mc::McResult> { + Ok(node_id_type(self, id)) + } -fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult> { - Ok(expr_ty_adjusted(self, expr)) -} + fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult> { + Ok(expr_ty_adjusted(self, expr)) + } -fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { - self.tcx() - .method_map - .borrow() - .get(&method_call) - .map(|method| monomorphize_type(self, method.ty)) -} + fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { + self.tcx() + .method_map + .borrow() + .get(&method_call) + .map(|method| monomorphize_type(self, method.ty)) + } -fn node_method_origin(&self, method_call: ty::MethodCall) - -> Option> -{ - self.tcx() - .method_map - .borrow() - .get(&method_call) - .map(|method| method.origin.clone()) -} + fn node_method_origin(&self, method_call: ty::MethodCall) + -> Option> + { + self.tcx() + .method_map + .borrow() + .get(&method_call) + .map(|method| method.origin.clone()) + } -fn adjustments<'a>(&'a self) -> &'a RefCell>> { - &self.tcx().adjustments -} + fn adjustments<'a>(&'a self) -> &'a RefCell>> { + &self.tcx().adjustments + } -fn is_method_call(&self, id: ast::NodeId) -> bool { - self.tcx().method_map.borrow().contains_key(&ty::MethodCall::expr(id)) -} + fn is_method_call(&self, id: ast::NodeId) -> bool { + self.tcx().method_map.borrow().contains_key(&ty::MethodCall::expr(id)) + } -fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { - self.tcx().region_maps.temporary_scope(rvalue_id) -} + fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { + self.tcx().region_maps.temporary_scope(rvalue_id) + } -fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> Option { - Some(self.tcx().upvar_borrow_map.borrow()[upvar_id].clone()) -} + fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> Option { + Some(self.tcx().upvar_borrow_map.borrow()[upvar_id].clone()) + } -fn capture_mode(&self, closure_expr_id: ast::NodeId) - -> ast::CaptureClause { - self.tcx().capture_modes.borrow()[closure_expr_id].clone() -} + fn capture_mode(&self, closure_expr_id: ast::NodeId) + -> ast::CaptureClause { + self.tcx().capture_modes.borrow()[closure_expr_id].clone() + } -fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool { - self.fcx.param_env.type_moves_by_default(span, ty) -} + fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool { + self.fcx.param_env.type_moves_by_default(span, ty) + } } impl<'blk, 'tcx> ty::UnboxedClosureTyper<'tcx> for BlockS<'blk, 'tcx> { -fn param_env<'a>(&'a self) -> &'a ty::ParameterEnvironment<'a, 'tcx> { - &self.fcx.param_env -} + fn param_env<'a>(&'a self) -> &'a ty::ParameterEnvironment<'a, 'tcx> { + &self.fcx.param_env + } -fn unboxed_closure_kind(&self, - def_id: ast::DefId) - -> ty::UnboxedClosureKind -{ - let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); - typer.unboxed_closure_kind(def_id) -} + fn unboxed_closure_kind(&self, + def_id: ast::DefId) + -> ty::UnboxedClosureKind + { + let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); + typer.unboxed_closure_kind(def_id) + } -fn unboxed_closure_type(&self, - def_id: ast::DefId, - substs: &subst::Substs<'tcx>) - -> ty::ClosureTy<'tcx> -{ - let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); - typer.unboxed_closure_type(def_id, substs) -} + fn unboxed_closure_type(&self, + def_id: ast::DefId, + substs: &subst::Substs<'tcx>) + -> ty::ClosureTy<'tcx> + { + let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); + typer.unboxed_closure_type(def_id, substs) + } -fn unboxed_closure_upvars(&self, - def_id: ast::DefId, - substs: &Substs<'tcx>) - -> Option>> -{ - let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); - typer.unboxed_closure_upvars(def_id, substs) -} + fn unboxed_closure_upvars(&self, + def_id: ast::DefId, + substs: &Substs<'tcx>) + -> Option>> + { + let typer = NormalizingUnboxedClosureTyper::new(self.tcx()); + typer.unboxed_closure_upvars(def_id, substs) + } } pub struct Result<'blk, 'tcx: 'blk> { -pub bcx: Block<'blk, 'tcx>, -pub val: ValueRef + pub bcx: Block<'blk, 'tcx>, + pub val: ValueRef } impl<'b, 'tcx> Result<'b, 'tcx> { -pub fn new(bcx: Block<'b, 'tcx>, val: ValueRef) -> Result<'b, 'tcx> { - Result { - bcx: bcx, - val: val, + pub fn new(bcx: Block<'b, 'tcx>, val: ValueRef) -> Result<'b, 'tcx> { + Result { + bcx: bcx, + val: val, + } } } -} pub fn val_ty(v: ValueRef) -> Type { -unsafe { - Type::from_ref(llvm::LLVMTypeOf(v)) -} + unsafe { + Type::from_ref(llvm::LLVMTypeOf(v)) + } } // LLVM constant constructors. pub fn C_null(t: Type) -> ValueRef { -unsafe { - llvm::LLVMConstNull(t.to_ref()) -} + unsafe { + llvm::LLVMConstNull(t.to_ref()) + } } pub fn C_undef(t: Type) -> ValueRef { -unsafe { - llvm::LLVMGetUndef(t.to_ref()) -} + unsafe { + llvm::LLVMGetUndef(t.to_ref()) + } } pub fn C_integral(t: Type, u: u64, sign_extend: bool) -> ValueRef { -unsafe { - llvm::LLVMConstInt(t.to_ref(), u, sign_extend as Bool) -} + unsafe { + llvm::LLVMConstInt(t.to_ref(), u, sign_extend as Bool) + } } pub fn C_floating(s: &str, t: Type) -> ValueRef { -unsafe { - let s = CString::from_slice(s.as_bytes()); - llvm::LLVMConstRealOfString(t.to_ref(), s.as_ptr()) -} + unsafe { + let s = CString::from_slice(s.as_bytes()); + llvm::LLVMConstRealOfString(t.to_ref(), s.as_ptr()) + } } pub fn C_nil(ccx: &CrateContext) -> ValueRef { -C_struct(ccx, &[], false) + C_struct(ccx, &[], false) } pub fn C_bool(ccx: &CrateContext, val: bool) -> ValueRef { -C_integral(Type::i1(ccx), val as u64, false) + C_integral(Type::i1(ccx), val as u64, false) } pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef { -C_integral(Type::i32(ccx), i as u64, true) + C_integral(Type::i32(ccx), i as u64, true) } pub fn C_i64(ccx: &CrateContext, i: i64) -> ValueRef { -C_integral(Type::i64(ccx), i as u64, true) + C_integral(Type::i64(ccx), i as u64, true) } pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef { -C_integral(Type::i64(ccx), i, false) + C_integral(Type::i64(ccx), i, false) } pub fn C_int(ccx: &CrateContext, i: I) -> ValueRef { -let v = i.as_i64(); + let v = i.as_i64(); -match machine::llbitsize_of_real(ccx, ccx.int_type()) { - 32 => assert!(v < (1<<31) && v >= -(1<<31)), - 64 => {}, - n => panic!("unsupported target size: {}", n) -} + match machine::llbitsize_of_real(ccx, ccx.int_type()) { + 32 => assert!(v < (1<<31) && v >= -(1<<31)), + 64 => {}, + n => panic!("unsupported target size: {}", n) + } -C_integral(ccx.int_type(), v as u64, true) + C_integral(ccx.int_type(), v as u64, true) } pub fn C_uint(ccx: &CrateContext, i: I) -> ValueRef { -let v = i.as_u64(); + let v = i.as_u64(); -match machine::llbitsize_of_real(ccx, ccx.int_type()) { - 32 => assert!(v < (1<<32)), - 64 => {}, - n => panic!("unsupported target size: {}", n) -} + match machine::llbitsize_of_real(ccx, ccx.int_type()) { + 32 => assert!(v < (1<<32)), + 64 => {}, + n => panic!("unsupported target size: {}", n) + } -C_integral(ccx.int_type(), v, false) + C_integral(ccx.int_type(), v, false) } pub trait AsI64 { fn as_i64(self) -> i64; } @@ -829,157 +829,157 @@ impl AsU64 for u32 { fn as_u64(self) -> u64 { self as u64 }} impl AsU64 for uint { fn as_u64(self) -> u64 { self as u64 }} pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef { -C_integral(Type::i8(ccx), i as u64, false) + C_integral(Type::i8(ccx), i as u64, false) } // This is a 'c-like' raw string, which differs from // our boxed-and-length-annotated strings. pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef { -unsafe { - match cx.const_cstr_cache().borrow().get(&s) { - Some(&llval) => return llval, - None => () - } + unsafe { + match cx.const_cstr_cache().borrow().get(&s) { + Some(&llval) => return llval, + None => () + } - let sc = llvm::LLVMConstStringInContext(cx.llcx(), - s.get().as_ptr() as *const c_char, - s.get().len() as c_uint, - !null_terminated as Bool); + let sc = llvm::LLVMConstStringInContext(cx.llcx(), + s.get().as_ptr() as *const c_char, + s.get().len() as c_uint, + !null_terminated as Bool); - let gsym = token::gensym("str"); - let buf = CString::from_vec(format!("str{}", gsym.uint()).into_bytes()); - let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(sc).to_ref(), buf.as_ptr()); - llvm::LLVMSetInitializer(g, sc); - llvm::LLVMSetGlobalConstant(g, True); - llvm::SetLinkage(g, llvm::InternalLinkage); + let gsym = token::gensym("str"); + let buf = CString::from_vec(format!("str{}", gsym.uint()).into_bytes()); + let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(sc).to_ref(), buf.as_ptr()); + llvm::LLVMSetInitializer(g, sc); + llvm::LLVMSetGlobalConstant(g, True); + llvm::SetLinkage(g, llvm::InternalLinkage); - cx.const_cstr_cache().borrow_mut().insert(s, g); - g -} + cx.const_cstr_cache().borrow_mut().insert(s, g); + g + } } // NB: Do not use `do_spill_noroot` to make this into a constant string, or // you will be kicked off fast isel. See issue #4352 for an example of this. pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef { -let len = s.get().len(); -let cs = consts::ptrcast(C_cstr(cx, s, false), Type::i8p(cx)); -C_named_struct(cx.tn().find_type("str_slice").unwrap(), &[cs, C_uint(cx, len)]) + let len = s.get().len(); + let cs = consts::ptrcast(C_cstr(cx, s, false), Type::i8p(cx)); + C_named_struct(cx.tn().find_type("str_slice").unwrap(), &[cs, C_uint(cx, len)]) } pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef { -unsafe { - let len = data.len(); - let lldata = C_bytes(cx, data); - - let gsym = token::gensym("binary"); - let name = format!("binary{}", gsym.uint()); - let name = CString::from_vec(name.into_bytes()); - let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(lldata).to_ref(), - name.as_ptr()); - llvm::LLVMSetInitializer(g, lldata); - llvm::LLVMSetGlobalConstant(g, True); - llvm::SetLinkage(g, llvm::InternalLinkage); - - let cs = consts::ptrcast(g, Type::i8p(cx)); - C_struct(cx, &[cs, C_uint(cx, len)], false) -} + unsafe { + let len = data.len(); + let lldata = C_bytes(cx, data); + + let gsym = token::gensym("binary"); + let name = format!("binary{}", gsym.uint()); + let name = CString::from_vec(name.into_bytes()); + let g = llvm::LLVMAddGlobal(cx.llmod(), val_ty(lldata).to_ref(), + name.as_ptr()); + llvm::LLVMSetInitializer(g, lldata); + llvm::LLVMSetGlobalConstant(g, True); + llvm::SetLinkage(g, llvm::InternalLinkage); + + let cs = consts::ptrcast(g, Type::i8p(cx)); + C_struct(cx, &[cs, C_uint(cx, len)], false) + } } pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef { -C_struct_in_context(cx.llcx(), elts, packed) + C_struct_in_context(cx.llcx(), elts, packed) } pub fn C_struct_in_context(llcx: ContextRef, elts: &[ValueRef], packed: bool) -> ValueRef { -unsafe { - llvm::LLVMConstStructInContext(llcx, - elts.as_ptr(), elts.len() as c_uint, - packed as Bool) -} + unsafe { + llvm::LLVMConstStructInContext(llcx, + elts.as_ptr(), elts.len() as c_uint, + packed as Bool) + } } pub fn C_named_struct(t: Type, elts: &[ValueRef]) -> ValueRef { -unsafe { - llvm::LLVMConstNamedStruct(t.to_ref(), elts.as_ptr(), elts.len() as c_uint) -} + unsafe { + llvm::LLVMConstNamedStruct(t.to_ref(), elts.as_ptr(), elts.len() as c_uint) + } } pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef { -unsafe { - return llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr(), elts.len() as c_uint); -} + unsafe { + return llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr(), elts.len() as c_uint); + } } pub fn C_bytes(cx: &CrateContext, bytes: &[u8]) -> ValueRef { -C_bytes_in_context(cx.llcx(), bytes) + C_bytes_in_context(cx.llcx(), bytes) } pub fn C_bytes_in_context(llcx: ContextRef, bytes: &[u8]) -> ValueRef { -unsafe { - let ptr = bytes.as_ptr() as *const c_char; - return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True); -} + unsafe { + let ptr = bytes.as_ptr() as *const c_char; + return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True); + } } pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint]) -> ValueRef { -unsafe { - let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint); + unsafe { + let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint); - debug!("const_get_elt(v={}, us={:?}, r={})", - cx.tn().val_to_string(v), us, cx.tn().val_to_string(r)); + debug!("const_get_elt(v={}, us={:?}, r={})", + cx.tn().val_to_string(v), us, cx.tn().val_to_string(r)); - return r; -} + return r; + } } pub fn is_const(v: ValueRef) -> bool { -unsafe { - llvm::LLVMIsConstant(v) == True -} + unsafe { + llvm::LLVMIsConstant(v) == True + } } pub fn const_to_int(v: ValueRef) -> i64 { -unsafe { - llvm::LLVMConstIntGetSExtValue(v) -} + unsafe { + llvm::LLVMConstIntGetSExtValue(v) + } } pub fn const_to_uint(v: ValueRef) -> u64 { -unsafe { - llvm::LLVMConstIntGetZExtValue(v) -} + unsafe { + llvm::LLVMConstIntGetZExtValue(v) + } } pub fn is_undef(val: ValueRef) -> bool { -unsafe { - llvm::LLVMIsUndef(val) != False -} + unsafe { + llvm::LLVMIsUndef(val) != False + } } #[allow(dead_code)] // potentially useful pub fn is_null(val: ValueRef) -> bool { -unsafe { - llvm::LLVMIsNull(val) != False -} + unsafe { + llvm::LLVMIsNull(val) != False + } } pub fn monomorphize_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> { -bcx.fcx.monomorphize(&t) + bcx.fcx.monomorphize(&t) } pub fn node_id_type<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, id: ast::NodeId) -> Ty<'tcx> { -let tcx = bcx.tcx(); -let t = ty::node_id_to_type(tcx, id); -monomorphize_type(bcx, t) + let tcx = bcx.tcx(); + let t = ty::node_id_to_type(tcx, id); + monomorphize_type(bcx, t) } pub fn expr_ty<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> { -node_id_type(bcx, ex.id) + node_id_type(bcx, ex.id) } pub fn expr_ty_adjusted<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, ex: &ast::Expr) -> Ty<'tcx> { -monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex)) + monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex)) } /// Attempts to resolve an obligation. The result is a shallow vtable resolution -- meaning that we @@ -990,117 +990,117 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> { -let tcx = ccx.tcx(); - -// Remove any references to regions; this helps improve caching. -let trait_ref = erase_regions(tcx, &trait_ref); - -// First check the cache. -match ccx.trait_cache().borrow().get(&trait_ref) { - Some(vtable) => { - info!("Cache hit: {}", trait_ref.repr(ccx.tcx())); - return (*vtable).clone(); - } - None => { } -} - -debug!("trans fulfill_obligation: trait_ref={}", trait_ref.repr(ccx.tcx())); - -ty::populate_implementations_for_trait_if_necessary(tcx, trait_ref.def_id()); -let infcx = infer::new_infer_ctxt(tcx); - -// Do the initial selection for the obligation. This yields the -// shallow result we are looking for -- that is, what specific impl. -let typer = NormalizingUnboxedClosureTyper::new(tcx); -let mut selcx = traits::SelectionContext::new(&infcx, &typer); -let obligation = traits::Obligation::new(traits::ObligationCause::dummy(), - trait_ref.to_poly_trait_predicate()); -let selection = match selcx.select(&obligation) { - Ok(Some(selection)) => selection, - Ok(None) => { - // Ambiguity can happen when monomorphizing during trans - // expands to some humongo type that never occurred - // statically -- this humongo type can then overflow, - // leading to an ambiguous result. So report this as an - // overflow bug, since I believe this is the only case - // where ambiguity can result. - debug!("Encountered ambiguity selecting `{}` during trans, \ - presuming due to overflow", - trait_ref.repr(tcx)); - ccx.sess().span_fatal( - span, - "reached the recursion limit during monomorphization"); - } - Err(e) => { - tcx.sess.span_bug( - span, - &format!("Encountered error `{}` selecting `{}` during trans", - e.repr(tcx), - trait_ref.repr(tcx))[]) - } -}; - -// Currently, we use a fulfillment context to completely resolve -// all nested obligations. This is because they can inform the -// inference of the impl's type parameters. -let mut fulfill_cx = traits::FulfillmentContext::new(); -let vtable = selection.map_move_nested(|predicate| { - fulfill_cx.register_predicate_obligation(&infcx, predicate); -}); -let vtable = drain_fulfillment_cx(span, &infcx, &mut fulfill_cx, &vtable); - -info!("Cache miss: {}", trait_ref.repr(ccx.tcx())); -ccx.trait_cache().borrow_mut().insert(trait_ref, - vtable.clone()); - -vtable + let tcx = ccx.tcx(); + + // Remove any references to regions; this helps improve caching. + let trait_ref = erase_regions(tcx, &trait_ref); + + // First check the cache. + match ccx.trait_cache().borrow().get(&trait_ref) { + Some(vtable) => { + info!("Cache hit: {}", trait_ref.repr(ccx.tcx())); + return (*vtable).clone(); + } + None => { } + } + + debug!("trans fulfill_obligation: trait_ref={}", trait_ref.repr(ccx.tcx())); + + ty::populate_implementations_for_trait_if_necessary(tcx, trait_ref.def_id()); + let infcx = infer::new_infer_ctxt(tcx); + + // Do the initial selection for the obligation. This yields the + // shallow result we are looking for -- that is, what specific impl. + let typer = NormalizingUnboxedClosureTyper::new(tcx); + let mut selcx = traits::SelectionContext::new(&infcx, &typer); + let obligation = traits::Obligation::new(traits::ObligationCause::dummy(), + trait_ref.to_poly_trait_predicate()); + let selection = match selcx.select(&obligation) { + Ok(Some(selection)) => selection, + Ok(None) => { + // Ambiguity can happen when monomorphizing during trans + // expands to some humongo type that never occurred + // statically -- this humongo type can then overflow, + // leading to an ambiguous result. So report this as an + // overflow bug, since I believe this is the only case + // where ambiguity can result. + debug!("Encountered ambiguity selecting `{}` during trans, \ + presuming due to overflow", + trait_ref.repr(tcx)); + ccx.sess().span_fatal( + span, + "reached the recursion limit during monomorphization"); + } + Err(e) => { + tcx.sess.span_bug( + span, + &format!("Encountered error `{}` selecting `{}` during trans", + e.repr(tcx), + trait_ref.repr(tcx))[]) + } + }; + + // Currently, we use a fulfillment context to completely resolve + // all nested obligations. This is because they can inform the + // inference of the impl's type parameters. + let mut fulfill_cx = traits::FulfillmentContext::new(); + let vtable = selection.map_move_nested(|predicate| { + fulfill_cx.register_predicate_obligation(&infcx, predicate); + }); + let vtable = drain_fulfillment_cx(span, &infcx, &mut fulfill_cx, &vtable); + + info!("Cache miss: {}", trait_ref.repr(ccx.tcx())); + ccx.trait_cache().borrow_mut().insert(trait_ref, + vtable.clone()); + + vtable } pub struct NormalizingUnboxedClosureTyper<'a,'tcx:'a> { -param_env: ty::ParameterEnvironment<'a, 'tcx> + param_env: ty::ParameterEnvironment<'a, 'tcx> } impl<'a,'tcx> NormalizingUnboxedClosureTyper<'a,'tcx> { -pub fn new(tcx: &'a ty::ctxt<'tcx>) -> NormalizingUnboxedClosureTyper<'a,'tcx> { - // Parameter environment is used to give details about type parameters, - // but since we are in trans, everything is fully monomorphized. - NormalizingUnboxedClosureTyper { param_env: ty::empty_parameter_environment(tcx) } -} + pub fn new(tcx: &'a ty::ctxt<'tcx>) -> NormalizingUnboxedClosureTyper<'a,'tcx> { + // Parameter environment is used to give details about type parameters, + // but since we are in trans, everything is fully monomorphized. + NormalizingUnboxedClosureTyper { param_env: ty::empty_parameter_environment(tcx) } + } } impl<'a,'tcx> ty::UnboxedClosureTyper<'tcx> for NormalizingUnboxedClosureTyper<'a,'tcx> { -fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> { - &self.param_env -} + fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> { + &self.param_env + } -fn unboxed_closure_kind(&self, - def_id: ast::DefId) - -> ty::UnboxedClosureKind -{ - self.param_env.tcx.unboxed_closure_kind(def_id) -} + fn unboxed_closure_kind(&self, + def_id: ast::DefId) + -> ty::UnboxedClosureKind + { + self.param_env.tcx.unboxed_closure_kind(def_id) + } -fn unboxed_closure_type(&self, - def_id: ast::DefId, - substs: &subst::Substs<'tcx>) - -> ty::ClosureTy<'tcx> -{ - // the substitutions in `substs` are already monomorphized, - // but we still must normalize associated types - let closure_ty = self.param_env.tcx.unboxed_closure_type(def_id, substs); - monomorphize::normalize_associated_type(self.param_env.tcx, &closure_ty) -} + fn unboxed_closure_type(&self, + def_id: ast::DefId, + substs: &subst::Substs<'tcx>) + -> ty::ClosureTy<'tcx> + { + // the substitutions in `substs` are already monomorphized, + // but we still must normalize associated types + let closure_ty = self.param_env.tcx.unboxed_closure_type(def_id, substs); + monomorphize::normalize_associated_type(self.param_env.tcx, &closure_ty) + } -fn unboxed_closure_upvars(&self, - def_id: ast::DefId, - substs: &Substs<'tcx>) - -> Option>> -{ - // the substitutions in `substs` are already monomorphized, - // but we still must normalize associated types - let result = ty::unboxed_closure_upvars(&self.param_env, def_id, substs); - monomorphize::normalize_associated_type(self.param_env.tcx, &result) -} + fn unboxed_closure_upvars(&self, + def_id: ast::DefId, + substs: &Substs<'tcx>) + -> Option>> + { + // the substitutions in `substs` are already monomorphized, + // but we still must normalize associated types + let result = ty::unboxed_closure_upvars(&self.param_env, def_id, substs); + monomorphize::normalize_associated_type(self.param_env.tcx, &result) + } } pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span, @@ -1108,73 +1108,73 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span, fulfill_cx: &mut traits::FulfillmentContext<'tcx>, result: &T) -> T -where T : TypeFoldable<'tcx> + Repr<'tcx> + where T : TypeFoldable<'tcx> + Repr<'tcx> { -debug!("drain_fulfillment_cx(result={})", - result.repr(infcx.tcx)); - -// In principle, we only need to do this so long as `result` -// contains unbound type parameters. It could be a slight -// optimization to stop iterating early. -let typer = NormalizingUnboxedClosureTyper::new(infcx.tcx); -match fulfill_cx.select_all_or_error(infcx, &typer) { - Ok(()) => { } - Err(errors) => { - if errors.iter().all(|e| e.is_overflow()) { - // See Ok(None) case above. - infcx.tcx.sess.span_fatal( - span, - "reached the recursion limit during monomorphization"); - } else { - infcx.tcx.sess.span_bug( - span, - &format!("Encountered errors `{}` fulfilling during trans", - errors.repr(infcx.tcx))[]); + debug!("drain_fulfillment_cx(result={})", + result.repr(infcx.tcx)); + + // In principle, we only need to do this so long as `result` + // contains unbound type parameters. It could be a slight + // optimization to stop iterating early. + let typer = NormalizingUnboxedClosureTyper::new(infcx.tcx); + match fulfill_cx.select_all_or_error(infcx, &typer) { + Ok(()) => { } + Err(errors) => { + if errors.iter().all(|e| e.is_overflow()) { + // See Ok(None) case above. + infcx.tcx.sess.span_fatal( + span, + "reached the recursion limit during monomorphization"); + } else { + infcx.tcx.sess.span_bug( + span, + &format!("Encountered errors `{}` fulfilling during trans", + errors.repr(infcx.tcx))[]); + } } } -} -// Use freshen to simultaneously replace all type variables with -// their bindings and replace all regions with 'static. This is -// sort of overkill because we do not expect there to be any -// unbound type variables, hence no `TyFresh` types should ever be -// inserted. -result.fold_with(&mut infcx.freshener()) + // Use freshen to simultaneously replace all type variables with + // their bindings and replace all regions with 'static. This is + // sort of overkill because we do not expect there to be any + // unbound type variables, hence no `TyFresh` types should ever be + // inserted. + result.fold_with(&mut infcx.freshener()) } // Key used to lookup values supplied for type parameters in an expr. #[derive(Copy, PartialEq, Show)] pub enum ExprOrMethodCall { -// Type parameters for a path like `None::` -ExprId(ast::NodeId), + // Type parameters for a path like `None::` + ExprId(ast::NodeId), -// Type parameters for a method call like `a.foo::()` -MethodCallKey(ty::MethodCall) + // Type parameters for a method call like `a.foo::()` + MethodCallKey(ty::MethodCall) } pub fn node_id_substs<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, node: ExprOrMethodCall, param_substs: &subst::Substs<'tcx>) -> subst::Substs<'tcx> { -let tcx = ccx.tcx(); + let tcx = ccx.tcx(); -let substs = match node { - ExprId(id) => { - ty::node_id_item_substs(tcx, id).substs - } - MethodCallKey(method_call) => { - (*tcx.method_map.borrow())[method_call].substs.clone() - } -}; + let substs = match node { + ExprId(id) => { + ty::node_id_item_substs(tcx, id).substs + } + MethodCallKey(method_call) => { + (*tcx.method_map.borrow())[method_call].substs.clone() + } + }; -if substs.types.any(|t| ty::type_needs_infer(*t)) { - tcx.sess.bug(&format!("type parameters for node {:?} include inference types: {:?}", - node, substs.repr(tcx))[]); - } + if substs.types.any(|t| ty::type_needs_infer(*t)) { + tcx.sess.bug(&format!("type parameters for node {:?} include inference types: {:?}", + node, substs.repr(tcx))[]); + } - monomorphize::apply_param_substs(tcx, - param_substs, - &substs.erase_regions()) + monomorphize::apply_param_substs(tcx, + param_substs, + &substs.erase_regions()) } pub fn langcall(bcx: Block, From 0d0869ad738c1961ebbe75412303d360c7e951ba Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Thu, 8 Jan 2015 12:01:48 +0100 Subject: [PATCH 04/25] Remove the deprecated opt_out_copy feature --- src/librustc/middle/traits/select.rs | 23 +----------- src/libsyntax/feature_gate.rs | 5 +-- src/test/compile-fail/opt-out-copy-bad.rs | 44 ---------------------- src/test/run-pass/opt-out-copy.rs | 46 ----------------------- 4 files changed, 3 insertions(+), 115 deletions(-) delete mode 100644 src/test/compile-fail/opt-out-copy-bad.rs delete mode 100644 src/test/run-pass/opt-out-copy.rs diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index f42f43d25764d..dad7461236970 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -713,12 +713,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!("obligation self ty is {}", obligation.predicate.0.self_ty().repr(self.tcx())); - // If the user has asked for the older, compatibility - // behavior, ignore user-defined impls here. This will - // go away by the time 1.0 is released. - if !self.tcx().sess.features.borrow().opt_out_copy { - try!(self.assemble_candidates_from_impls(obligation, &mut candidates.vec)); - } + try!(self.assemble_candidates_from_impls(obligation, &mut candidates.vec)); try!(self.assemble_builtin_bound_candidates(ty::BoundCopy, stack, @@ -1505,21 +1500,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::BoundCopy => { - // This is an Opt-In Built-In Trait. So, unless - // the user is asking for the old behavior, we - // don't supply any form of builtin impl. - if !this.tcx().sess.features.borrow().opt_out_copy { - return Ok(ParameterBuiltin) - } else { - // Older, backwards compatibility behavior: - if - Some(def_id) == tcx.lang_items.no_copy_bound() || - Some(def_id) == tcx.lang_items.managed_bound() || - ty::has_dtor(tcx, def_id) - { - return Err(Unimplemented); - } - } + return Ok(ParameterBuiltin) } ty::BoundSync => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2cfcd38d48fca..9f023be4a534b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -82,7 +82,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ ("issue_5723_bootstrap", Accepted), // A way to temporarily opt out of opt in copy. This will *never* be accepted. - ("opt_out_copy", Deprecated), + ("opt_out_copy", Removed), // A way to temporarily opt out of the new orphan rules. This will *never* be accepted. ("old_orphan_check", Deprecated), @@ -123,7 +123,6 @@ pub struct Features { pub import_shadowing: bool, pub visible_private_types: bool, pub quote: bool, - pub opt_out_copy: bool, pub old_orphan_check: bool, } @@ -135,7 +134,6 @@ impl Features { import_shadowing: false, visible_private_types: false, quote: false, - opt_out_copy: false, old_orphan_check: false, } } @@ -465,7 +463,6 @@ fn check_crate_inner(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C import_shadowing: cx.has_feature("import_shadowing"), visible_private_types: cx.has_feature("visible_private_types"), quote: cx.has_feature("quote"), - opt_out_copy: cx.has_feature("opt_out_copy"), old_orphan_check: cx.has_feature("old_orphan_check"), }, unknown_features) diff --git a/src/test/compile-fail/opt-out-copy-bad.rs b/src/test/compile-fail/opt-out-copy-bad.rs deleted file mode 100644 index 9e425fa8f2e7d..0000000000000 --- a/src/test/compile-fail/opt-out-copy-bad.rs +++ /dev/null @@ -1,44 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(opt_out_copy)] -//~^ WARNING feature is deprecated -//~| WARNING feature is deprecated - -// Test that when using the `opt-out-copy` feature we still consider -// destructors to be non-movable - -struct CantCopyThis; - -impl Drop for CantCopyThis { - fn drop(&mut self) { } -} - -struct IWantToCopyThis { - but_i_cant: CantCopyThis, -} - -impl Copy for IWantToCopyThis {} -//~^ ERROR the trait `Copy` may not be implemented for this type - -enum CantCopyThisEither { - A, - B(::std::marker::NoCopy), -} - -enum IWantToCopyThisToo { - ButICant(CantCopyThisEither), -} - -impl Copy for IWantToCopyThisToo {} -//~^ ERROR the trait `Copy` may not be implemented for this type - -fn main() {} - diff --git a/src/test/run-pass/opt-out-copy.rs b/src/test/run-pass/opt-out-copy.rs deleted file mode 100644 index 8c7072cfdf545..0000000000000 --- a/src/test/run-pass/opt-out-copy.rs +++ /dev/null @@ -1,46 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(opt_out_copy)] - -// Test the opt-out-copy feature guard. This is the same as the -// "opt-in-copy.rs" test from compile-fail, except that it is using -// the feature guard, and hence the structureds in this file are -// implicitly copyable, and hence we get no errors. This test can be -// safely removed once the opt-out-copy "feature" is rejected. - -struct CantCopyThis; - -struct IWantToCopyThis { - but_i_cant: CantCopyThis, -} - -impl Copy for IWantToCopyThis {} - -enum CantCopyThisEither { - A, - B, -} - -enum IWantToCopyThisToo { - ButICant(CantCopyThisEither), -} - -impl Copy for IWantToCopyThisToo {} - -fn is_copy() { } - -fn main() { - is_copy::(); - is_copy::(); - is_copy::(); - is_copy::(); -} - From 0a32010e430006d3850b74976d7d7bf0dda699b4 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 7 Jan 2015 10:53:09 -0500 Subject: [PATCH 05/25] Add comments to autoderef() helper and refactor it to take an `Option<&Expr>` like everything else. --- src/librustc_typeck/check/method/confirm.rs | 12 ++--- src/librustc_typeck/check/method/mod.rs | 8 ++-- src/librustc_typeck/check/mod.rs | 49 +++++++++++++++++---- src/librustc_typeck/check/regionck.rs | 10 ++++- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 7e72f300f4178..7946077485976 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -143,7 +143,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { // time writing the results into the various tables. let (autoderefd_ty, n, result) = check::autoderef( - self.fcx, self.span, unadjusted_self_ty, Some(self.self_expr.id), NoPreference, + self.fcx, self.span, unadjusted_self_ty, Some(self.self_expr), NoPreference, |_, n| if n == auto_deref_ref.autoderefs { Some(()) } else { None }); assert_eq!(n, auto_deref_ref.autoderefs); assert_eq!(result, Some(())); @@ -492,7 +492,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { exprs.repr(self.tcx())); // Fix up autoderefs and derefs. - for (i, expr) in exprs.iter().rev().enumerate() { + for (i, &expr) in exprs.iter().rev().enumerate() { // Count autoderefs. let autoderef_count = match self.fcx .inh @@ -512,8 +512,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { if autoderef_count > 0 { check::autoderef(self.fcx, expr.span, - self.fcx.expr_ty(*expr), - Some(expr.id), + self.fcx.expr_ty(expr), + Some(expr), PreferMutLvalue, |_, autoderefs| { if autoderefs == autoderef_count + 1 { @@ -567,7 +567,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { let result = check::try_index_step( self.fcx, MethodCall::expr(expr.id), - *expr, + expr, &**base_expr, adjusted_base_ty, base_adjustment, @@ -577,7 +577,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { if let Some((input_ty, return_ty)) = result { demand::suptype(self.fcx, index_expr.span, input_ty, index_expr_ty); - let expr_ty = self.fcx.expr_ty(&**expr); + let expr_ty = self.fcx.expr_ty(&*expr); demand::suptype(self.fcx, expr.span, expr_ty, return_ty); } } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index bb000742def92..0c53a16a8118b 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -102,9 +102,9 @@ pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, Ok(confirm::confirm(fcx, span, self_expr, call_expr, self_ty, pick, supplied_method_types)) } -pub fn lookup_in_trait<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, +pub fn lookup_in_trait<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span: Span, - self_expr: Option<&'a ast::Expr>, + self_expr: Option<&ast::Expr>, m_name: ast::Name, trait_def_id: DefId, self_ty: Ty<'tcx>, @@ -125,9 +125,9 @@ pub fn lookup_in_trait<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, /// method-lookup code. In particular, autoderef on index is basically identical to autoderef with /// normal probes, except that the test also looks for built-in indexing. Also, the second half of /// this method is basically the same as confirmation. -pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, +pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span: Span, - self_expr: Option<&'a ast::Expr>, + self_expr: Option<&ast::Expr>, m_name: ast::Name, trait_def_id: DefId, autoderefref: ty::AutoDerefRef<'tcx>, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b98b327100cdb..4ade11a9a83b4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2263,17 +2263,36 @@ pub enum LvaluePreference { /// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide /// whether to terminate the loop. Returns the final type and number of derefs that it performed. /// +<<<<<<< HEAD /// Note: this method does not modify the adjustments table. The caller is responsible for /// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods. pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, +||||||| merged common ancestors +/// Note: this method does not modify the adjustments table. The caller is responsible for +/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods. +pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, +======= +/// Note: this method does not modify the adjustments table. The +/// caller is responsible for inserting an AutoAdjustment record into +/// the `fcx` using one of the suitable methods. However, if +/// `opt_expr` is not `None`, it *will* insert the appropriate method +/// entries for the overloaded deref call. +pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, +>>>>>>> Add comments to autoderef() helper and refactor it to take base_ty: Ty<'tcx>, - expr_id: Option, + opt_expr: Option<&ast::Expr>, mut lvalue_pref: LvaluePreference, mut should_stop: F) - -> (Ty<'tcx>, uint, Option) where - F: FnMut(Ty<'tcx>, uint) -> Option, + -> (Ty<'tcx>, uint, Option) + where F: FnMut(Ty<'tcx>, uint) -> Option, { + debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={})", + base_ty.repr(fcx.tcx()), + opt_expr, + lvalue_pref); + let mut t = base_ty; for autoderefs in range(0, fcx.tcx().sess.recursion_limit.get()) { let resolved_t = structurally_resolved_type(fcx, sp, t); @@ -2291,7 +2310,19 @@ pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, let mt = match ty::deref(resolved_t, false) { Some(mt) => Some(mt), None => { - let method_call = expr_id.map(|id| MethodCall::autoderef(id, autoderefs)); + let method_call = opt_expr.map(|expr| MethodCall::autoderef(expr.id, autoderefs)); + + // Super subtle: it might seem as though we should + // pass `opt_expr` to `try_overloaded_deref`, so that + // the (implicit) autoref of using an overloaded deref + // would get added to the adjustment table. However we + // do not do that, because it's kind of a + // "meta-adjustment" -- instead, we just leave it + // unrecorded and know that there "will be" an + // autoref. regionck and other bits of the code base, + // when they encounter an overloaded autoderef, have + // to do some reconstructive surgery. This is a pretty + // complex mess that is begging for a proper MIR. try_overloaded_deref(fcx, sp, method_call, None, resolved_t, lvalue_pref) } }; @@ -2324,7 +2355,7 @@ fn try_overloaded_deref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // Try DerefMut first, if preferred. let method = match (lvalue_pref, fcx.tcx().lang_items.deref_mut_trait()) { (PreferMutLvalue, Some(trait_did)) => { - method::lookup_in_trait(fcx, span, base_expr.map(|x| &*x), + method::lookup_in_trait(fcx, span, base_expr, token::intern("deref_mut"), trait_did, base_ty, None) } @@ -2334,7 +2365,7 @@ fn try_overloaded_deref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // Otherwise, fall back to Deref. let method = match (method, fcx.tcx().lang_items.deref_trait()) { (None, Some(trait_did)) => { - method::lookup_in_trait(fcx, span, base_expr.map(|x| &*x), + method::lookup_in_trait(fcx, span, base_expr, token::intern("deref"), trait_did, base_ty, None) } @@ -2390,7 +2421,7 @@ fn autoderef_for_index<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, // consolidated. let (ty, autoderefs, final_mt) = - autoderef(fcx, base_expr.span, base_ty, Some(base_expr.id), lvalue_pref, |adj_ty, idx| { + autoderef(fcx, base_expr.span, base_ty, Some(base_expr), lvalue_pref, |adj_ty, idx| { let autoderefref = ty::AutoDerefRef { autoderefs: idx, autoref: None }; step(adj_ty, autoderefref) }); @@ -3360,7 +3391,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, fcx.expr_ty(base)); // FIXME(eddyb) #12808 Integrate privacy into this auto-deref loop. let (_, autoderefs, field_ty) = - autoderef(fcx, expr.span, expr_t, Some(base.id), lvalue_pref, |base_t, _| { + autoderef(fcx, expr.span, expr_t, Some(base), lvalue_pref, |base_t, _| { match base_t.sty { ty::ty_struct(base_id, substs) => { debug!("struct named {}", ppaux::ty_to_string(tcx, base_t)); @@ -3421,7 +3452,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, let mut tuple_like = false; // FIXME(eddyb) #12808 Integrate privacy into this auto-deref loop. let (_, autoderefs, field_ty) = - autoderef(fcx, expr.span, expr_t, Some(base.id), lvalue_pref, |base_t, _| { + autoderef(fcx, expr.span, expr_t, Some(base), lvalue_pref, |base_t, _| { match base_t.sty { ty::ty_struct(base_id, substs) => { tuple_like = ty::is_tuple_struct(tcx, base_id); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 112e00536422c..c74612d3aa836 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1049,13 +1049,16 @@ fn type_of_node_must_outlive<'a, 'tcx>( /// Computes the guarantor for an expression `&base` and then ensures that the lifetime of the /// resulting pointer is linked to the lifetime of its guarantor (if any). fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr, - mutability: ast::Mutability, base: &ast::Expr) { - debug!("link_addr_of(base=?)"); + mutability: ast::Mutability, base: &ast::Expr) { + debug!("link_addr_of(expr={}, base={})", expr.repr(rcx.tcx()), base.repr(rcx.tcx())); let cmt = { let mc = mc::MemCategorizationContext::new(rcx.fcx); ignore_err!(mc.cat_expr(base)) }; + + debug!("link_addr_of: cmt={}", cmt.repr(rcx.tcx())); + link_region_from_node_type(rcx, expr.span, expr.id, mutability, cmt); } @@ -1182,6 +1185,9 @@ fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, id: ast::NodeId, mutbl: ast::Mutability, cmt_borrowed: mc::cmt<'tcx>) { + debug!("link_region_from_node_type(id={}, mutbl={}, cmt_borrowed={})", + id, mutbl, cmt_borrowed.repr(rcx.tcx())); + let rptr_ty = rcx.resolve_node_type(id); if !ty::type_is_error(rptr_ty) { let tcx = rcx.fcx.ccx.tcx; From 2387651f7d5e57ce73d5193f6dbfe75ae1e288c8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 09:12:06 -0500 Subject: [PATCH 06/25] Update the "English-language" to-string function of a `cmt` to use more modern terminology and update tests accordingly. --- src/librustc/middle/mem_categorization.rs | 103 +++++++++++++----- .../borrowck/gather_loans/move_error.rs | 20 ++-- src/librustc_borrowck/borrowck/mod.rs | 4 + src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/mod.rs | 18 +-- src/test/compile-fail/binop-move-semantics.rs | 4 +- ...rrowck-borrow-immut-deref-of-box-as-mut.rs | 2 +- .../borrowck-call-is-borrow-issue-12224.rs | 4 +- .../borrowck-move-in-irrefut-pat.rs | 6 +- ...rowck-move-out-of-overloaded-auto-deref.rs | 2 +- .../borrowck-move-out-of-overloaded-deref.rs | 2 +- .../borrowck-move-out-of-vec-tail.rs | 2 +- .../borrowck-overloaded-index-2.rs | 2 +- .../compile-fail/borrowck-overloaded-index.rs | 2 +- src/test/compile-fail/dst-index.rs | 4 +- src/test/compile-fail/dst-rvalue.rs | 4 +- src/test/compile-fail/issue-12567.rs | 8 +- src/test/compile-fail/issue-17651.rs | 2 +- src/test/compile-fail/issue-2590.rs | 2 +- src/test/compile-fail/method-self-arg-2.rs | 2 +- src/test/compile-fail/slice-mut-2.rs | 2 +- src/test/compile-fail/slice-mut.rs | 2 +- .../compile-fail/std-uncopyable-atomics.rs | 8 +- src/test/compile-fail/unop-move-semantics.rs | 4 +- 24 files changed, 124 insertions(+), 87 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index fb9a16f86e5bc..0cc7f15a0b107 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -75,7 +75,7 @@ use middle::def; use middle::region; use middle::ty::{self, Ty}; use util::nodemap::{NodeMap}; -use util::ppaux::{Repr}; +use util::ppaux::{Repr, UserString}; use syntax::ast::{MutImmutable, MutMutable}; use syntax::ast; @@ -113,10 +113,17 @@ pub struct Upvar { // different kinds of pointers: #[derive(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum PointerKind { + /// `Box` Unique, + + /// `&T` BorrowedPtr(ty::BorrowKind, ty::Region), - Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr. - UnsafePtr(ast::Mutability) + + /// `*T` + UnsafePtr(ast::Mutability), + + /// Implicit deref of the `&T` that results from an overloaded index `[]`. + Implicit(ty::BorrowKind, ty::Region), } // We use the term "interior" to mean "something reachable from the @@ -1392,22 +1399,6 @@ impl<'tcx> cmt_<'tcx> { pub fn descriptive_string(&self, tcx: &ty::ctxt) -> String { - fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String { - if upvar.is_unboxed { - let kind = match upvar.kind { - ty::FnUnboxedClosureKind => "Fn", - ty::FnMutUnboxedClosureKind => "FnMut", - ty::FnOnceUnboxedClosureKind => "FnOnce" - }; - format!("captured outer variable in an `{}` closure", kind) - } else { - (match (upvar.kind, is_copy) { - (ty::FnOnceUnboxedClosureKind, true) => "captured outer variable in a proc", - _ => "captured outer variable" - }).to_string() - } - } - match self.cat { cat_static_item => { "static item".to_string() @@ -1427,16 +1418,23 @@ impl<'tcx> cmt_<'tcx> { let upvar = self.upvar(); match upvar.as_ref().map(|i| &i.cat) { Some(&cat_upvar(ref var)) => { - upvar_to_string(var, false) + var.user_string(tcx) } Some(_) => unreachable!(), None => { match pk { Implicit(..) => { - "dereference (dereference is implicit, due to indexing)".to_string() + format!("indexed content") + } + Unique => { + format!("`Box` content") + } + UnsafePtr(..) => { + format!("dereference of unsafe pointer") + } + BorrowedPtr(..) => { + format!("borrowed content") } - Unique => format!("dereference of `{}`", ptr_sigil(pk)), - _ => format!("dereference of `{}`-pointer", ptr_sigil(pk)) } } } @@ -1447,14 +1445,12 @@ impl<'tcx> cmt_<'tcx> { cat_interior(_, InteriorField(PositionalField(_))) => { "anonymous field".to_string() } - cat_interior(_, InteriorElement(VecElement)) => { - "vec content".to_string() - } + cat_interior(_, InteriorElement(VecElement)) | cat_interior(_, InteriorElement(OtherElement)) => { "indexed content".to_string() } cat_upvar(ref var) => { - upvar_to_string(var, true) + var.user_string(tcx) } cat_downcast(ref cmt, _) => { cmt.descriptive_string(tcx) @@ -1483,7 +1479,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> { format!("{:?}", *self) } cat_deref(ref cmt, derefs, ptr) => { - format!("{}-{}{}->", cmt.cat.repr(tcx), ptr_sigil(ptr), derefs) + format!("{}-{}{}->", cmt.cat.repr(tcx), ptr.repr(tcx), derefs) } cat_interior(ref cmt, interior) => { format!("{}.{}", cmt.cat.repr(tcx), interior.repr(tcx)) @@ -1504,7 +1500,32 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str { Implicit(ty::MutBorrow, _) => "&mut", BorrowedPtr(ty::UniqueImmBorrow, _) | Implicit(ty::UniqueImmBorrow, _) => "&unique", - UnsafePtr(_) => "*" + UnsafePtr(_) => "*", + } +} + +impl<'tcx> Repr<'tcx> for PointerKind { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { + match *self { + Unique => { + format!("Box") + } + BorrowedPtr(ty::ImmBorrow, ref r) | + Implicit(ty::ImmBorrow, ref r) => { + format!("&{}", r.repr(tcx)) + } + BorrowedPtr(ty::MutBorrow, ref r) | + Implicit(ty::MutBorrow, ref r) => { + format!("&{} mut", r.repr(tcx)) + } + BorrowedPtr(ty::UniqueImmBorrow, ref r) | + Implicit(ty::UniqueImmBorrow, ref r) => { + format!("&{} uniq", r.repr(tcx)) + } + UnsafePtr(_) => { + format!("*") + } + } } } @@ -1531,3 +1552,27 @@ fn element_kind(t: Ty) -> ElementKind { _ => OtherElement } } + +impl<'tcx> Repr<'tcx> for ty::UnboxedClosureKind { + fn repr(&self, _: &ty::ctxt) -> String { + format!("Upvar({:?})", self) + } +} + +impl<'tcx> Repr<'tcx> for Upvar { + fn repr(&self, tcx: &ty::ctxt) -> String { + format!("Upvar({})", self.kind.repr(tcx)) + } +} + +impl<'tcx> UserString<'tcx> for Upvar { + fn user_string(&self, _: &ty::ctxt) -> String { + let kind = match self.kind { + ty::FnUnboxedClosureKind => "Fn", + ty::FnMutUnboxedClosureKind => "FnMut", + ty::FnOnceUnboxedClosureKind => "FnOnce", + }; + format!("captured outer variable in an `{}` closure", kind) + } +} + diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index a7771fefec412..28d02161eebd7 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -115,29 +115,31 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, match move_from.cat { mc::cat_deref(_, _, mc::BorrowedPtr(..)) | mc::cat_deref(_, _, mc::Implicit(..)) | - mc::cat_deref(_, _, mc::UnsafePtr(..)) | mc::cat_static_item => { - bccx.span_err( - move_from.span, - &format!("cannot move out of {}", - bccx.cmt_to_string(&*move_from))[]); + bccx.span_err(move_from.span, + &format!("cannot move out of {}", + move_from.descriptive_string(bccx.tcx))[]); } mc::cat_downcast(ref b, _) | mc::cat_interior(ref b, _) => { match b.ty.sty { - ty::ty_struct(did, _) - | ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => { + ty::ty_struct(did, _) | + ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => { bccx.span_err( move_from.span, &format!("cannot move out of type `{}`, \ which defines the `Drop` trait", b.ty.user_string(bccx.tcx))[]); }, - _ => panic!("this path should not cause illegal move") + _ => { + bccx.span_bug(move_from.span, "this path should not cause illegal move") + } } } - _ => panic!("this path should not cause illegal move") + _ => { + bccx.span_bug(move_from.span, "this path should not cause illegal move") + } } } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index e734e8fb6ffb7..b87fed1601c51 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -681,6 +681,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx.sess.span_err(s, m); } + pub fn span_bug(&self, s: Span, m: &str) { + self.tcx.sess.span_bug(s, m); + } + pub fn span_note(&self, s: Span, m: &str) { self.tcx.sess.span_note(s, m); } diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index dff216ac2935f..19a88dfc553b6 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -73,7 +73,7 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, autoderef(fcx, callee_expr.span, original_callee_ty, - Some(callee_expr.id), + Some(callee_expr), LvaluePreference::NoPreference, |adj_ty, idx| { let autoderefref = ty::AutoDerefRef { autoderefs: idx, autoref: None }; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4ade11a9a83b4..084a457909c5c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2263,24 +2263,10 @@ pub enum LvaluePreference { /// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide /// whether to terminate the loop. Returns the final type and number of derefs that it performed. /// -<<<<<<< HEAD /// Note: this method does not modify the adjustments table. The caller is responsible for /// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods. pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, -||||||| merged common ancestors -/// Note: this method does not modify the adjustments table. The caller is responsible for -/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods. -pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, -======= -/// Note: this method does not modify the adjustments table. The -/// caller is responsible for inserting an AutoAdjustment record into -/// the `fcx` using one of the suitable methods. However, if -/// `opt_expr` is not `None`, it *will* insert the appropriate method -/// entries for the overloaded deref call. -pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, - sp: Span, ->>>>>>> Add comments to autoderef() helper and refactor it to take base_ty: Ty<'tcx>, opt_expr: Option<&ast::Expr>, mut lvalue_pref: LvaluePreference, @@ -2288,9 +2274,9 @@ pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, -> (Ty<'tcx>, uint, Option) where F: FnMut(Ty<'tcx>, uint) -> Option, { - debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={})", + debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={:?})", base_ty.repr(fcx.tcx()), - opt_expr, + opt_expr.repr(fcx.tcx()), lvalue_pref); let mut t = base_ty; diff --git a/src/test/compile-fail/binop-move-semantics.rs b/src/test/compile-fail/binop-move-semantics.rs index ffc38cc0a6005..cff0064497aff 100644 --- a/src/test/compile-fail/binop-move-semantics.rs +++ b/src/test/compile-fail/binop-move-semantics.rs @@ -37,9 +37,9 @@ fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; - *m //~ ERROR: cannot move out of dereference of `&mut`-pointer + *m //~ ERROR: cannot move out of borrowed content + - *n; //~ ERROR: cannot move out of dereference of `&`-pointer + *n; //~ ERROR: cannot move out of borrowed content } struct Foo; diff --git a/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs b/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs index 84f4e4f8817ca..794e0fc6e3aba 100644 --- a/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs +++ b/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs @@ -20,5 +20,5 @@ impl A { pub fn main() { let a = box A; a.foo(); - //~^ ERROR cannot borrow immutable dereference of `Box` `*a` as mutable + //~^ ERROR cannot borrow immutable `Box` content `*a` as mutable } diff --git a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs index 9aec8de46b6d9..d5df125134656 100644 --- a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs +++ b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs @@ -33,7 +33,7 @@ fn test1() { } fn test2(f: &F) where F: FnMut() { - (*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable + (*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable } fn test3(f: &mut F) where F: FnMut() { @@ -41,7 +41,7 @@ fn test3(f: &mut F) where F: FnMut() { } fn test4(f: &Test) { - f.f.call_mut(()) //~ ERROR: cannot borrow immutable dereference of `Box` `*f.f` as mutable + f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable } fn test5(f: &mut Test) { diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index c5d23925a89b1..ec505faf88502 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -11,16 +11,16 @@ fn with(f: F) where F: FnOnce(&String) {} fn arg_item(&_x: &String) {} - //~^ ERROR cannot move out of dereference of `&`-pointer + //~^ ERROR cannot move out of borrowed content fn arg_closure() { with(|&_x| ()) - //~^ ERROR cannot move out of dereference of `&`-pointer + //~^ ERROR cannot move out of borrowed content } fn let_pat() { let &_x = &"hi".to_string(); - //~^ ERROR cannot move out of dereference of `&`-pointer + //~^ ERROR cannot move out of borrowed content } pub fn main() {} diff --git a/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs index a6723a04611af..a13efdea5621e 100644 --- a/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs +++ b/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs @@ -12,5 +12,5 @@ use std::rc::Rc; pub fn main() { let _x = Rc::new(vec!(1i, 2)).into_iter(); - //~^ ERROR cannot move out of dereference of `&`-pointer + //~^ ERROR cannot move out of borrowed content } diff --git a/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs b/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs index 8a93790d5a298..fffcf575ab08e 100644 --- a/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs +++ b/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs @@ -12,5 +12,5 @@ use std::rc::Rc; pub fn main() { let _x = *Rc::new("hi".to_string()); - //~^ ERROR cannot move out of dereference of `&`-pointer + //~^ ERROR cannot move out of borrowed content } diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index 23ef5331b495f..75596af10d70e 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -25,7 +25,7 @@ pub fn main() { match x { [_, tail..] => { match tail { - [Foo { string: a }, //~ ERROR cannot move out of dereference of `&`-pointer + [Foo { string: a }, //~ ERROR cannot move out of borrowed content Foo { string: b }] => { //~^^ NOTE attempting to move value to here //~^^ NOTE and here diff --git a/src/test/compile-fail/borrowck-overloaded-index-2.rs b/src/test/compile-fail/borrowck-overloaded-index-2.rs index 5e6d235574e69..334f14349d723 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-2.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-2.rs @@ -28,5 +28,5 @@ fn main() { let v = MyVec { data: vec!(box 1i, box 2, box 3) }; let good = &v[0]; // Shouldn't fail here let bad = v[0]; - //~^ ERROR cannot move out of dereference (dereference is implicit, due to indexing) + //~^ ERROR cannot move out of indexed content } diff --git a/src/test/compile-fail/borrowck-overloaded-index.rs b/src/test/compile-fail/borrowck-overloaded-index.rs index 80b68dbf519ee..f4f4d983e009b 100644 --- a/src/test/compile-fail/borrowck-overloaded-index.rs +++ b/src/test/compile-fail/borrowck-overloaded-index.rs @@ -66,5 +66,5 @@ fn main() { x: 1, }; s[2] = 20; - //~^ ERROR cannot assign to immutable dereference (dereference is implicit, due to indexing) + //~^ ERROR cannot assign to immutable indexed content } diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index e297ecaac233e..c64cc13bbe2ea 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -41,9 +41,9 @@ impl Index for T { fn main() { S[0]; - //~^ ERROR cannot move out of dereference + //~^ ERROR cannot move out of indexed content //~^^ ERROR E0161 T[0]; - //~^ ERROR cannot move out of dereference + //~^ ERROR cannot move out of indexed content //~^^ ERROR E0161 } diff --git a/src/test/compile-fail/dst-rvalue.rs b/src/test/compile-fail/dst-rvalue.rs index 74e952364cd45..faae0009a934c 100644 --- a/src/test/compile-fail/dst-rvalue.rs +++ b/src/test/compile-fail/dst-rvalue.rs @@ -15,10 +15,10 @@ pub fn main() { let _x: Box = box *"hello world"; //~^ ERROR E0161 - //~^^ ERROR cannot move out of dereference + //~^^ ERROR cannot move out of borrowed content let array: &[int] = &[1, 2, 3]; let _x: Box<[int]> = box *array; //~^ ERROR E0161 - //~^^ ERROR cannot move out of dereference + //~^^ ERROR cannot move out of borrowed content } diff --git a/src/test/compile-fail/issue-12567.rs b/src/test/compile-fail/issue-12567.rs index 26866cbbc6033..d186a83676a80 100644 --- a/src/test/compile-fail/issue-12567.rs +++ b/src/test/compile-fail/issue-12567.rs @@ -12,11 +12,11 @@ fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) { match (l1, l2) { ([], []) => println!("both empty"), ([], [hd, tl..]) | ([hd, tl..], []) => println!("one empty"), - //~^ ERROR: cannot move out of dereference - //~^^ ERROR: cannot move out of dereference + //~^ ERROR: cannot move out of borrowed content + //~^^ ERROR: cannot move out of borrowed content ([hd1, tl1..], [hd2, tl2..]) => println!("both nonempty"), - //~^ ERROR: cannot move out of dereference - //~^^ ERROR: cannot move out of dereference + //~^ ERROR: cannot move out of borrowed content + //~^^ ERROR: cannot move out of borrowed content } } diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs index d3678f7d87fdb..fbecd0487bf6f 100644 --- a/src/test/compile-fail/issue-17651.rs +++ b/src/test/compile-fail/issue-17651.rs @@ -15,6 +15,6 @@ fn main() { (|&:| box *[0us].as_slice())(); - //~^ ERROR cannot move out of dereference + //~^ ERROR cannot move out of borrowed content //~^^ ERROR cannot move a value of type [usize] } diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs index 79a66e30fdb91..07aea4fd633b4 100644 --- a/src/test/compile-fail/issue-2590.rs +++ b/src/test/compile-fail/issue-2590.rs @@ -19,7 +19,7 @@ trait parse { impl parse for parser { fn parse(&self) -> Vec { - self.tokens //~ ERROR cannot move out of dereference of `&`-pointer + self.tokens //~ ERROR cannot move out of borrowed content } } diff --git a/src/test/compile-fail/method-self-arg-2.rs b/src/test/compile-fail/method-self-arg-2.rs index 0ac0851619c59..ad255ecd9c064 100644 --- a/src/test/compile-fail/method-self-arg-2.rs +++ b/src/test/compile-fail/method-self-arg-2.rs @@ -23,5 +23,5 @@ fn main() { Foo::bar(&x); //~ERROR cannot borrow `x` let x = Foo; - Foo::baz(&x); //~ERROR cannot borrow immutable dereference of `&`-pointer as mutable + Foo::baz(&x); //~ERROR cannot borrow immutable borrowed content as mutable } diff --git a/src/test/compile-fail/slice-mut-2.rs b/src/test/compile-fail/slice-mut-2.rs index 12f184d410c90..09357d328cd18 100644 --- a/src/test/compile-fail/slice-mut-2.rs +++ b/src/test/compile-fail/slice-mut-2.rs @@ -14,5 +14,5 @@ fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; // Can't mutably slice an immutable slice let slice: &mut [int] = &mut [0, 1]; - let _ = &mut x[2..4]; //~ERROR cannot borrow immutable dereference of `&`-pointer `*x` as mutabl + let _ = &mut x[2..4]; //~ERROR cannot borrow immutable borrowed content `*x` as mutable } diff --git a/src/test/compile-fail/slice-mut.rs b/src/test/compile-fail/slice-mut.rs index 9bd9a752e4e89..f68554b9ec79e 100644 --- a/src/test/compile-fail/slice-mut.rs +++ b/src/test/compile-fail/slice-mut.rs @@ -13,5 +13,5 @@ fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; // Immutable slices are not mutable. - let y: &mut[_] = &x[2..4]; //~ ERROR cannot borrow immutable dereference of `&`-pointer as mutab + let y: &mut[_] = &x[2..4]; //~ ERROR cannot borrow immutable borrowed content as mutable } diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 5ebabc2e3548c..81cf9c1bdcf1a 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -16,11 +16,11 @@ use std::ptr; fn main() { let x = ATOMIC_BOOL_INIT; - let x = *&x; //~ ERROR: cannot move out of dereference + let x = *&x; //~ ERROR: cannot move out of borrowed content let x = ATOMIC_INT_INIT; - let x = *&x; //~ ERROR: cannot move out of dereference + let x = *&x; //~ ERROR: cannot move out of borrowed content let x = ATOMIC_UINT_INIT; - let x = *&x; //~ ERROR: cannot move out of dereference + let x = *&x; //~ ERROR: cannot move out of borrowed content let x: AtomicPtr = AtomicPtr::new(ptr::null_mut()); - let x = *&x; //~ ERROR: cannot move out of dereference + let x = *&x; //~ ERROR: cannot move out of borrowed content } diff --git a/src/test/compile-fail/unop-move-semantics.rs b/src/test/compile-fail/unop-move-semantics.rs index f8cbdb4e160bf..946566675981e 100644 --- a/src/test/compile-fail/unop-move-semantics.rs +++ b/src/test/compile-fail/unop-move-semantics.rs @@ -31,9 +31,9 @@ fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; - !*m; //~ ERROR: cannot move out of dereference of `&mut`-pointer + !*m; //~ ERROR: cannot move out of borrowed content - !*n; //~ ERROR: cannot move out of dereference of `&`-pointer + !*n; //~ ERROR: cannot move out of borrowed content } fn main() {} From 92425496e525855fd772f771a35456a4b66c071f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 09:13:08 -0500 Subject: [PATCH 07/25] Fix the actual bug for #20232: when creating the cmt for the implicit deref that is associated with an overloaded index, we should not consult the method lookup table. This deref is *always* a deref of an `&T` and hence is never overloaded (and is also not present in the tables; it has no "id" or other associated key). --- src/librustc/middle/mem_categorization.rs | 33 ++++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 0cc7f15a0b107..51ec75284326c 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -460,7 +460,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { autoderefs, cmt.repr(self.tcx())); for deref in range(1u, autoderefs + 1) { - cmt = try!(self.cat_deref(expr, cmt, deref, false)); + cmt = try!(self.cat_deref(expr, cmt, deref)); } return Ok(cmt); } @@ -472,7 +472,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { match expr.node { ast::ExprUnary(ast::UnDeref, ref e_base) => { let base_cmt = try!(self.cat_expr(&**e_base)); - self.cat_deref(expr, base_cmt, 0, false) + self.cat_deref(expr, base_cmt, 0) } ast::ExprField(ref base, f_name) => { @@ -496,10 +496,23 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { // If this is an index implemented by a method call, then it // will include an implicit deref of the result. let ret_ty = self.overloaded_method_return_ty(method_ty); - self.cat_deref(expr, - self.cat_rvalue_node(expr.id(), - expr.span(), - ret_ty), 1, true) + + // The index method always returns an `&T`, so + // dereference it to find the result type. + let elem_ty = match ret_ty.sty { + ty::ty_rptr(_, mt) => mt.ty, + _ => { + debug!("cat_expr_unadjusted: return type of overloaded index is {}?", + ret_ty.repr(self.tcx())); + return Err(()); + } + }; + + // The call to index() returns a `&T` value, which + // is an rvalue. That is what we will be + // dereferencing. + let base_cmt = self.cat_rvalue_node(expr.id(), expr.span(), ret_ty); + self.cat_deref_common(expr, base_cmt, 1, elem_ty, true) } None => { self.cat_index(expr, try!(self.cat_expr(&**base))) @@ -844,8 +857,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { fn cat_deref(&self, node: &N, base_cmt: cmt<'tcx>, - deref_cnt: uint, - implicit: bool) + deref_cnt: uint) -> McResult> { let adjustment = match self.typer.adjustments().borrow().get(&node.id()) { Some(adj) if ty::adjust_is_object(adj) => ty::AutoObject, @@ -873,7 +885,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { }; let base_cmt_ty = base_cmt.ty; match ty::deref(base_cmt_ty, true) { - Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty, implicit), + Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty, + /* implicit: */ false), None => { debug!("Explicit deref of non-derefable type: {}", base_cmt_ty.repr(self.tcx())); @@ -1243,7 +1256,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { // box p1, &p1, &mut p1. we can ignore the mutability of // PatRegion since that information is already contained // in the type. - let subcmt = try!(self.cat_deref(pat, cmt, 0, false)); + let subcmt = try!(self.cat_deref(pat, cmt, 0)); try!(self.cat_pattern_(subcmt, &**subpat, op)); } From 9b5fb6091a99dc7675c79bfc758ae2ecb3a8cc96 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 09:13:40 -0500 Subject: [PATCH 08/25] Update regionck to discharge the binder safely (using `assert_no_late_bound_regions`) and to give more helpful debug output. --- src/librustc_typeck/check/regionck.rs | 38 ++++++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index c74612d3aa836..3b5027dbb9e69 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -936,29 +936,47 @@ fn constrain_call<'a, I: Iterator>(rcx: &mut Rcx, fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, deref_expr: &ast::Expr, derefs: uint, - mut derefd_ty: Ty<'tcx>) { + mut derefd_ty: Ty<'tcx>) +{ + debug!("constrain_autoderefs(deref_expr={}, derefs={}, derefd_ty={})", + deref_expr.repr(rcx.tcx()), + derefs, + derefd_ty.repr(rcx.tcx())); + let r_deref_expr = ty::ReScope(CodeExtent::from_node_id(deref_expr.id)); for i in range(0u, derefs) { - debug!("constrain_autoderefs(deref_expr=?, derefd_ty={}, derefs={}/{}", - rcx.fcx.infcx().ty_to_string(derefd_ty), - i, derefs); - let method_call = MethodCall::autoderef(deref_expr.id, i); + debug!("constrain_autoderefs: method_call={:?} (of {:?} total)", method_call, derefs); + derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) { Some(method) => { + debug!("constrain_autoderefs: #{} is overloaded, method={}", + i, method.repr(rcx.tcx())); + // Treat overloaded autoderefs as if an AutoRef adjustment // was applied on the base type, as that is always the case. let fn_sig = ty::ty_fn_sig(method.ty); - let self_ty = fn_sig.0.inputs[0]; + let fn_sig = // late-bound regions should have been instantiated + ty::assert_no_late_bound_regions(rcx.tcx(), fn_sig); + let self_ty = fn_sig.inputs[0]; let (m, r) = match self_ty.sty { ty::ty_rptr(r, ref m) => (m.mutbl, r), - _ => rcx.tcx().sess.span_bug(deref_expr.span, + _ => { + rcx.tcx().sess.span_bug( + deref_expr.span, &format!("bad overloaded deref type {}", - method.ty.repr(rcx.tcx()))[]) + method.ty.repr(rcx.tcx()))[]) + } }; + + debug!("constrain_autoderefs: receiver r={:?} m={:?}", + r.repr(rcx.tcx()), m); + { let mc = mc::MemCategorizationContext::new(rcx.fcx); let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i)); + debug!("constrain_autoderefs: self_cmt={:?}", + self_cmt.repr(rcx.tcx())); link_region(rcx, deref_expr.span, *r, ty::BorrowKind::from_mutbl(m), self_cmt); } @@ -966,7 +984,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, // Specialized version of constrain_call. type_must_outlive(rcx, infer::CallRcvr(deref_expr.span), self_ty, r_deref_expr); - match fn_sig.0.output { + match fn_sig.output { ty::FnConverging(return_type) => { type_must_outlive(rcx, infer::CallReturn(deref_expr.span), return_type, r_deref_expr); @@ -1185,7 +1203,7 @@ fn link_region_from_node_type<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, id: ast::NodeId, mutbl: ast::Mutability, cmt_borrowed: mc::cmt<'tcx>) { - debug!("link_region_from_node_type(id={}, mutbl={}, cmt_borrowed={})", + debug!("link_region_from_node_type(id={:?}, mutbl={:?}, cmt_borrowed={})", id, mutbl, cmt_borrowed.repr(rcx.tcx())); let rptr_ty = rcx.resolve_node_type(id); From ba87b540a4521282aa26fee4d3394befee978351 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 09:18:55 -0500 Subject: [PATCH 09/25] Add new test for #20232. --- ...k-overloaded-index-and-overloaded-deref.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs diff --git a/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs b/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs new file mode 100644 index 0000000000000..4188cf001423e --- /dev/null +++ b/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs @@ -0,0 +1,47 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we properly record borrows when we are doing an +// overloaded, autoderef of a value obtained via an overloaded index +// operator. The accounting of the all the implicit things going on +// here is rather subtle. Issue #20232. + +use std::ops::{Deref, Index}; + +struct MyVec { x: T } + +impl Index for MyVec { + type Output = T; + fn index(&self, _: &usize) -> &T { + &self.x + } +} + +struct MyPtr { x: T } + +impl Deref for MyPtr { + type Target = T; + fn deref(&self) -> &T { + &self.x + } +} + +struct Foo { f: usize } + +fn main() { + let mut v = MyVec { x: MyPtr { x: Foo { f: 22 } } }; + let i = &v[0].f; + v = MyVec { x: MyPtr { x: Foo { f: 23 } } }; + //~^ ERROR cannot assign to `v` + read(*i); +} + +fn read(_: usize) { } + From e95779554e9d6fc111102df7af80b40f8e22cfae Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 20:13:14 +1100 Subject: [PATCH 10/25] Store deprecated status of i/u-suffixed literals. --- src/librustc/lint/builtin.rs | 16 ++++----- src/librustc/metadata/tyencode.rs | 4 +-- src/librustc/middle/const_eval.rs | 4 +-- src/librustc/middle/ty.rs | 14 ++++---- src/librustc_resolve/lib.rs | 8 ++--- src/librustc_trans/trans/base.rs | 4 +-- src/librustc_trans/trans/debuginfo.rs | 8 ++--- src/librustc_trans/trans/type_.rs | 4 +-- src/librustc_trans/trans/type_of.rs | 2 +- src/librustc_typeck/check/mod.rs | 6 ++-- src/librustdoc/clean/mod.rs | 8 ++--- src/libsyntax/ast.rs | 44 ++++++++++++++++++----- src/libsyntax/ast_util.rs | 16 +++++---- src/libsyntax/attr.rs | 10 +++--- src/libsyntax/ext/build.rs | 5 +-- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/ext/quote.rs | 28 +++++++-------- src/libsyntax/parse/mod.rs | 8 ++--- 18 files changed, 112 insertions(+), 79 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 7d893f3a106cc..9795947ac811d 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -216,7 +216,7 @@ impl LintPass for TypeLimits { match lit.node { ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => { - let int_type = if t == ast::TyIs { + let int_type = if let ast::TyIs(_) = t { cx.sess().target.int_type } else { t }; let (min, max) = int_ty_range(int_type); @@ -233,7 +233,7 @@ impl LintPass for TypeLimits { }; }, ty::ty_uint(t) => { - let uint_type = if t == ast::TyUs { + let uint_type = if let ast::TyUs(_) = t { cx.sess().target.uint_type } else { t }; let (min, max) = uint_ty_range(uint_type); @@ -296,7 +296,7 @@ impl LintPass for TypeLimits { // warnings are consistent between 32- and 64-bit platforms fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) { match int_ty { - ast::TyIs=> (i64::MIN, i64::MAX), + ast::TyIs(_) => (i64::MIN, i64::MAX), ast::TyI8 => (i8::MIN as i64, i8::MAX as i64), ast::TyI16 => (i16::MIN as i64, i16::MAX as i64), ast::TyI32 => (i32::MIN as i64, i32::MAX as i64), @@ -306,7 +306,7 @@ impl LintPass for TypeLimits { fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) { match uint_ty { - ast::TyUs=> (u64::MIN, u64::MAX), + ast::TyUs(_) => (u64::MIN, u64::MAX), ast::TyU8 => (u8::MIN as u64, u8::MAX as u64), ast::TyU16 => (u16::MIN as u64, u16::MAX as u64), ast::TyU32 => (u32::MIN as u64, u32::MAX as u64), @@ -323,7 +323,7 @@ impl LintPass for TypeLimits { fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 { match int_ty { - ast::TyIs=> int_ty_bits(target_int_ty, target_int_ty), + ast::TyIs(_) => int_ty_bits(target_int_ty, target_int_ty), ast::TyI8 => i8::BITS as u64, ast::TyI16 => i16::BITS as u64, ast::TyI32 => i32::BITS as u64, @@ -333,7 +333,7 @@ impl LintPass for TypeLimits { fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 { match uint_ty { - ast::TyUs=> uint_ty_bits(target_uint_ty, target_uint_ty), + ast::TyUs(_) => uint_ty_bits(target_uint_ty, target_uint_ty), ast::TyU8 => u8::BITS as u64, ast::TyU16 => u16::BITS as u64, ast::TyU32 => u32::BITS as u64, @@ -404,12 +404,12 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) { match self.cx.tcx.def_map.borrow()[path_id].clone() { - def::DefPrimTy(ast::TyInt(ast::TyIs)) => { + def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => { self.cx.span_lint(IMPROPER_CTYPES, sp, "found rust type `isize` in foreign module, while \ libc::c_int or libc::c_long should be used"); } - def::DefPrimTy(ast::TyUint(ast::TyUs)) => { + def::DefPrimTy(ast::TyUint(ast::TyUs(_))) => { self.cx.span_lint(IMPROPER_CTYPES, sp, "found rust type `usize` in foreign module, while \ libc::c_uint or libc::c_ulong should be used"); diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index c019d129218b6..bdd08ad6c4952 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -61,7 +61,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t ty::ty_char => mywrite!(w, "c"), ty::ty_int(t) => { match t { - ast::TyIs => mywrite!(w, "is"), + ast::TyIs(_) => mywrite!(w, "is"), ast::TyI8 => mywrite!(w, "MB"), ast::TyI16 => mywrite!(w, "MW"), ast::TyI32 => mywrite!(w, "ML"), @@ -70,7 +70,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t } ty::ty_uint(t) => { match t { - ast::TyUs => mywrite!(w, "us"), + ast::TyUs(_) => mywrite!(w, "us"), ast::TyU8 => mywrite!(w, "Mb"), ast::TyU16 => mywrite!(w, "Mw"), ast::TyU32 => mywrite!(w, "Ml"), diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 04d4b41b21aa4..52352e920ce36 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -528,12 +528,12 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result (int, const_int, i64), + ty::ty_int(ast::TyIs(_)) => (int, const_int, i64), ty::ty_int(ast::TyI8) => (i8, const_int, i64), ty::ty_int(ast::TyI16) => (i16, const_int, i64), ty::ty_int(ast::TyI32) => (i32, const_int, i64), ty::ty_int(ast::TyI64) => (i64, const_int, i64), - ty::ty_uint(ast::TyUs) => (uint, const_uint, u64), + ty::ty_uint(ast::TyUs(_)) => (uint, const_uint, u64), ty::ty_uint(ast::TyU8) => (u8, const_uint, u64), ty::ty_uint(ast::TyU16) => (u16, const_uint, u64), ty::ty_uint(ast::TyU32) => (u32, const_uint, u64), diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 64f0bcb1c88db..2534232960fad 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2341,12 +2341,12 @@ impl<'tcx> CommonTypes<'tcx> { bool: intern_ty(arena, interner, ty_bool), char: intern_ty(arena, interner, ty_char), err: intern_ty(arena, interner, ty_err), - int: intern_ty(arena, interner, ty_int(ast::TyIs)), + int: intern_ty(arena, interner, ty_int(ast::TyIs(_))), i8: intern_ty(arena, interner, ty_int(ast::TyI8)), i16: intern_ty(arena, interner, ty_int(ast::TyI16)), i32: intern_ty(arena, interner, ty_int(ast::TyI32)), i64: intern_ty(arena, interner, ty_int(ast::TyI64)), - uint: intern_ty(arena, interner, ty_uint(ast::TyUs)), + uint: intern_ty(arena, interner, ty_uint(ast::TyUs(_))), u8: intern_ty(arena, interner, ty_uint(ast::TyU8)), u16: intern_ty(arena, interner, ty_uint(ast::TyU16)), u32: intern_ty(arena, interner, ty_uint(ast::TyU32)), @@ -2692,7 +2692,7 @@ impl FlagComputation { pub fn mk_mach_int<'tcx>(tcx: &ctxt<'tcx>, tm: ast::IntTy) -> Ty<'tcx> { match tm { - ast::TyIs => tcx.types.int, + ast::TyIs(_) => tcx.types.int, ast::TyI8 => tcx.types.i8, ast::TyI16 => tcx.types.i16, ast::TyI32 => tcx.types.i32, @@ -2702,7 +2702,7 @@ pub fn mk_mach_int<'tcx>(tcx: &ctxt<'tcx>, tm: ast::IntTy) -> Ty<'tcx> { pub fn mk_mach_uint<'tcx>(tcx: &ctxt<'tcx>, tm: ast::UintTy) -> Ty<'tcx> { match tm { - ast::TyUs => tcx.types.uint, + ast::TyUs(_) => tcx.types.uint, ast::TyU8 => tcx.types.u8, ast::TyU16 => tcx.types.u16, ast::TyU32 => tcx.types.u32, @@ -3363,7 +3363,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { let result = match ty.sty { // uint and int are ffi-unsafe - ty_uint(ast::TyUs) | ty_int(ast::TyIs) => { + ty_uint(ast::TyUs(_)) | ty_int(ast::TyIs(_)) => { TC::ReachesFfiUnsafe } @@ -3937,7 +3937,7 @@ pub fn type_is_fresh(ty: Ty) -> bool { pub fn type_is_uint(ty: Ty) -> bool { match ty.sty { - ty_infer(IntVar(_)) | ty_uint(ast::TyUs) => true, + ty_infer(IntVar(_)) | ty_uint(ast::TyUs(_)) => true, _ => false } } @@ -3983,7 +3983,7 @@ pub fn type_is_signed(ty: Ty) -> bool { pub fn type_is_machine(ty: Ty) -> bool { match ty.sty { - ty_int(ast::TyIs) | ty_uint(ast::TyUs) => false, + ty_int(ast::TyIs(_)) | ty_uint(ast::TyUs(_)) => false, ty_int(..) | ty_uint(..) | ty_float(..) => true, _ => false } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a1ae96490cad7..88f0abf3ca761 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -819,15 +819,15 @@ impl PrimitiveTypeTable { table.intern("char", TyChar); table.intern("f32", TyFloat(TyF32)); table.intern("f64", TyFloat(TyF64)); - table.intern("int", TyInt(TyIs)); - table.intern("isize", TyInt(TyIs)); + table.intern("int", TyInt(TyIs(true))); + table.intern("isize", TyInt(TyIs(false))); table.intern("i8", TyInt(TyI8)); table.intern("i16", TyInt(TyI16)); table.intern("i32", TyInt(TyI32)); table.intern("i64", TyInt(TyI64)); table.intern("str", TyStr); - table.intern("uint", TyUint(TyUs)); - table.intern("usize", TyUint(TyUs)); + table.intern("uint", TyUint(TyUs(true))); + table.intern("usize", TyUint(TyUs(false))); table.intern("u8", TyUint(TyU8)); table.intern("u16", TyUint(TyU16)); table.intern("u32", TyUint(TyU32)); diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 74071a1de4c3d..88ce36a710a0c 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -917,8 +917,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>( ty::ty_int(t) => { let llty = Type::int_from_ty(cx.ccx(), t); let min = match t { - ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64, - ast::TyIs => i64::MIN as u64, + ast::TyIs(_) if llty == Type::i32(cx.ccx()) => i32::MIN as u64, + ast::TyIs(_) => i64::MIN as u64, ast::TyI8 => i8::MIN as u64, ast::TyI16 => i16::MIN as u64, ast::TyI32 => i32::MIN as u64, diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 3a6f4b47e4e1e..2f58baab7fca9 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -1804,14 +1804,14 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::ty_bool => ("bool".to_string(), DW_ATE_boolean), ty::ty_char => ("char".to_string(), DW_ATE_unsigned_char), ty::ty_int(int_ty) => match int_ty { - ast::TyIs => ("isize".to_string(), DW_ATE_signed), + ast::TyIs(_) => ("isize".to_string(), DW_ATE_signed), ast::TyI8 => ("i8".to_string(), DW_ATE_signed), ast::TyI16 => ("i16".to_string(), DW_ATE_signed), ast::TyI32 => ("i32".to_string(), DW_ATE_signed), ast::TyI64 => ("i64".to_string(), DW_ATE_signed) }, ty::ty_uint(uint_ty) => match uint_ty { - ast::TyUs => ("usize".to_string(), DW_ATE_unsigned), + ast::TyUs(_) => ("usize".to_string(), DW_ATE_unsigned), ast::TyU8 => ("u8".to_string(), DW_ATE_unsigned), ast::TyU16 => ("u16".to_string(), DW_ATE_unsigned), ast::TyU32 => ("u32".to_string(), DW_ATE_unsigned), @@ -3739,12 +3739,12 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::ty_bool => output.push_str("bool"), ty::ty_char => output.push_str("char"), ty::ty_str => output.push_str("str"), - ty::ty_int(ast::TyIs) => output.push_str("isize"), + ty::ty_int(ast::TyIs(_)) => output.push_str("isize"), ty::ty_int(ast::TyI8) => output.push_str("i8"), ty::ty_int(ast::TyI16) => output.push_str("i16"), ty::ty_int(ast::TyI32) => output.push_str("i32"), ty::ty_int(ast::TyI64) => output.push_str("i64"), - ty::ty_uint(ast::TyUs) => output.push_str("usize"), + ty::ty_uint(ast::TyUs(_)) => output.push_str("usize"), ty::ty_uint(ast::TyU8) => output.push_str("u8"), ty::ty_uint(ast::TyU16) => output.push_str("u16"), ty::ty_uint(ast::TyU32) => output.push_str("u32"), diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index e2ed275d4c0cc..71a7789eb3932 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -112,7 +112,7 @@ impl Type { pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type { match t { - ast::TyIs => ccx.int_type(), + ast::TyIs(_) => ccx.int_type(), ast::TyI8 => Type::i8(ccx), ast::TyI16 => Type::i16(ccx), ast::TyI32 => Type::i32(ccx), @@ -122,7 +122,7 @@ impl Type { pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type { match t { - ast::TyUs => ccx.int_type(), + ast::TyUs(_) => ccx.int_type(), ast::TyU8 => Type::i8(ccx), ast::TyU16 => Type::i16(ccx), ast::TyU32 => Type::i32(ccx), diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 034a1ee8be592..416dfb420ffae 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -263,7 +263,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { } match unsized_part_of_type(cx.tcx(), t).sty { - ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs), + ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs(_)), ty::ty_trait(_) => Type::vtable_ptr(cx), _ => panic!("Unexpected type returned from unsized_part_of_type : {}", t.repr(cx.tcx())) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b98b327100cdb..f3778eb054037 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2442,7 +2442,7 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // First, try built-in indexing. match (ty::index(adjusted_ty), &index_ty.sty) { - (Some(ty), &ty::ty_uint(ast::TyUs)) | (Some(ty), &ty::ty_infer(ty::IntVar(_))) => { + (Some(ty), &ty::ty_uint(ast::TyUs(_))) | (Some(ty), &ty::ty_infer(ty::IntVar(_))) => { debug!("try_index_step: success, using built-in indexing"); fcx.write_adjustment(base_expr.id, base_expr.span, ty::AdjustDerefRef(adjustment)); return Some((tcx.types.uint, ty)); @@ -4770,7 +4770,7 @@ pub fn check_enum_variants(ccx: &CrateCtxt, ast::TyU16 => disr as u16 as Disr == disr, ast::TyU32 => disr as u32 as Disr == disr, ast::TyU64 => disr as u64 as Disr == disr, - ast::TyUs => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr) + ast::TyUs(_) => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr) } } fn int_in_range(ccx: &CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool { @@ -4779,7 +4779,7 @@ pub fn check_enum_variants(ccx: &CrateCtxt, ast::TyI16 => disr as i16 as Disr == disr, ast::TyI32 => disr as i32 as Disr == disr, ast::TyI64 => disr as i64 as Disr == disr, - ast::TyIs => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr) + ast::TyIs(_) => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr) } } match ty { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index fbb3c40ee99f6..a44c73e8c4120 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1389,12 +1389,12 @@ impl<'tcx> Clean for ty::Ty<'tcx> { match self.sty { ty::ty_bool => Primitive(Bool), ty::ty_char => Primitive(Char), - ty::ty_int(ast::TyIs) => Primitive(Isize), + ty::ty_int(ast::TyIs(_)) => Primitive(Isize), ty::ty_int(ast::TyI8) => Primitive(I8), ty::ty_int(ast::TyI16) => Primitive(I16), ty::ty_int(ast::TyI32) => Primitive(I32), ty::ty_int(ast::TyI64) => Primitive(I64), - ty::ty_uint(ast::TyUs) => Primitive(Usize), + ty::ty_uint(ast::TyUs(_)) => Primitive(Usize), ty::ty_uint(ast::TyU8) => Primitive(U8), ty::ty_uint(ast::TyU16) => Primitive(U16), ty::ty_uint(ast::TyU32) => Primitive(U32), @@ -2269,12 +2269,12 @@ fn resolve_type(cx: &DocContext, ast::TyStr => return Primitive(Str), ast::TyBool => return Primitive(Bool), ast::TyChar => return Primitive(Char), - ast::TyInt(ast::TyIs) => return Primitive(Isize), + ast::TyInt(ast::TyIs(_)) => return Primitive(Isize), ast::TyInt(ast::TyI8) => return Primitive(I8), ast::TyInt(ast::TyI16) => return Primitive(I16), ast::TyInt(ast::TyI32) => return Primitive(I32), ast::TyInt(ast::TyI64) => return Primitive(I64), - ast::TyUint(ast::TyUs) => return Primitive(Usize), + ast::TyUint(ast::TyUs(_)) => return Primitive(Usize), ast::TyUint(ast::TyU8) => return Primitive(U8), ast::TyUint(ast::TyU16) => return Primitive(U16), ast::TyUint(ast::TyU32) => return Primitive(U32), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0a9e0aedd3da8..630f7768885de 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1075,15 +1075,29 @@ pub struct Typedef { pub typ: P, } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum IntTy { - TyIs, + TyIs(bool /* is this deprecated `int`? */), TyI8, TyI16, TyI32, TyI64, } +impl PartialEq for IntTy { + fn eq(&self, other: &IntTy) -> bool { + match (*self, *other) { + // true/false need to compare the same, so this can't be derived + (TyIs(_), TyIs(_)) | + (TyI8, TyI8) | + (TyI16, TyI16) | + (TyI32, TyI32) | + (TyI64, TyI64) => true, + _ => false + } + } +} + impl fmt::Show for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::String::fmt(self, f) @@ -1099,27 +1113,41 @@ impl fmt::String for IntTy { impl IntTy { pub fn suffix_len(&self) -> uint { match *self { - TyIs => 1, - TyI8 => 2, + TyIs(true) /* i */ => 1, + TyIs(false) /* is */ | TyI8 => 2, TyI16 | TyI32 | TyI64 => 3, } } } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum UintTy { - TyUs, + TyUs(bool /* is this deprecated uint? */), TyU8, TyU16, TyU32, TyU64, } +impl PartialEq for UintTy { + fn eq(&self, other: &UintTy) -> bool { + match (*self, *other) { + // true/false need to compare the same, so this can't be derived + (TyUs(_), TyUs(_)) | + (TyU8, TyU8) | + (TyU16, TyU16) | + (TyU32, TyU32) | + (TyU64, TyU64) => true, + _ => false + } + } +} + impl UintTy { pub fn suffix_len(&self) -> uint { match *self { - TyUs => 1, - TyU8 => 2, + TyUs(true) /* u */ => 1, + TyUs(false) /* us */ | TyU8 => 2, TyU16 | TyU32 | TyU64 => 3, } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index b4e917e28cb24..bc7fbd46fd8ba 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -127,8 +127,10 @@ pub fn is_path(e: P) -> bool { /// We want to avoid "45int" and "-3int" in favor of "45" and "-3" pub fn int_ty_to_string(t: IntTy, val: Option) -> String { let s = match t { - TyIs if val.is_some() => "is", - TyIs => "isize", + TyIs(true) if val.is_some() => "i", + TyIs(true) => "int", + TyIs(false) if val.is_some() => "is", + TyIs(false) => "isize", TyI8 => "i8", TyI16 => "i16", TyI32 => "i32", @@ -148,7 +150,7 @@ pub fn int_ty_max(t: IntTy) -> u64 { match t { TyI8 => 0x80u64, TyI16 => 0x8000u64, - TyIs | TyI32 => 0x80000000u64, // actually ni about TyIs + TyIs(_) | TyI32 => 0x80000000u64, // actually ni about TyIs TyI64 => 0x8000000000000000u64 } } @@ -157,8 +159,10 @@ pub fn int_ty_max(t: IntTy) -> u64 { /// We want to avoid "42uint" in favor of "42u" pub fn uint_ty_to_string(t: UintTy, val: Option) -> String { let s = match t { - TyUs if val.is_some() => "us", - TyUs => "usize", + TyUs(true) if val.is_some() => "u", + TyUs(true) => "uint", + TyUs(false) if val.is_some() => "us", + TyUs(false) => "usize", TyU8 => "u8", TyU16 => "u16", TyU32 => "u32", @@ -175,7 +179,7 @@ pub fn uint_ty_max(t: UintTy) -> u64 { match t { TyU8 => 0xffu64, TyU16 => 0xffffu64, - TyUs | TyU32 => 0xffffffffu64, // actually ni about TyUs + TyUs(_) | TyU32 => 0xffffffffu64, // actually ni about TyUs TyU64 => 0xffffffffffffffffu64 } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 2cea55dfc55ef..6f57c06d33e88 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -464,10 +464,10 @@ fn int_type_of_word(s: &str) -> Option { "u32" => Some(UnsignedInt(ast::TyU32)), "i64" => Some(SignedInt(ast::TyI64)), "u64" => Some(UnsignedInt(ast::TyU64)), - "int" => Some(SignedInt(ast::TyIs)), - "uint" => Some(UnsignedInt(ast::TyUs)), - "isize" => Some(SignedInt(ast::TyIs)), - "usize" => Some(UnsignedInt(ast::TyUs)), + "int" => Some(SignedInt(ast::TyIs(true))), + "uint" => Some(UnsignedInt(ast::TyUs(true))), + "isize" => Some(SignedInt(ast::TyIs(false))), + "usize" => Some(UnsignedInt(ast::TyUs(false))), _ => None } } @@ -511,7 +511,7 @@ impl IntType { SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) | SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) | SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true, - SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false + SignedInt(ast::TyIs(_)) | UnsignedInt(ast::TyUs(_)) => false } } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 27523ea453585..c34142aec39c8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -642,10 +642,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprLit(P(respan(sp, lit)))) } fn expr_uint(&self, span: Span, i: uint) -> P { - self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs))) + self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs(false)))) } fn expr_int(&self, sp: Span, i: int) -> P { - self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs, ast::Sign::new(i)))) + self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false), + ast::Sign::new(i)))) } fn expr_u8(&self, sp: Span, u: u8) -> P { self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8))) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 47b29a4db3e27..e6b6f7bbd49c3 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1031,7 +1031,7 @@ impl<'a> MethodDef<'a> { let arms: Vec = variants.iter().enumerate() .map(|(index, variant)| { let pat = variant_to_pat(cx, sp, type_ident, &**variant); - let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs)); + let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs(false))); cx.arm(sp, vec![pat], cx.expr_lit(sp, lit)) }).collect(); diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 2dbf29c145c8a..c42b188302cc3 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -244,10 +244,10 @@ pub mod rt { } macro_rules! impl_to_source_int { - (signed, $t:ty, $tag:ident) => ( + (signed, $t:ty, $tag:expr) => ( impl ToSource for $t { fn to_source(&self) -> String { - let lit = ast::LitInt(*self as u64, ast::SignedIntLit(ast::$tag, + let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag, ast::Sign::new(*self))); pprust::lit_to_string(&dummy_spanned(lit)) } @@ -258,10 +258,10 @@ pub mod rt { } } ); - (unsigned, $t:ty, $tag:ident) => ( + (unsigned, $t:ty, $tag:expr) => ( impl ToSource for $t { fn to_source(&self) -> String { - let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit(ast::$tag)); + let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag)); pprust::lit_to_string(&dummy_spanned(lit)) } } @@ -273,17 +273,17 @@ pub mod rt { ); } - impl_to_source_int! { signed, int, TyIs } - impl_to_source_int! { signed, i8, TyI8 } - impl_to_source_int! { signed, i16, TyI16 } - impl_to_source_int! { signed, i32, TyI32 } - impl_to_source_int! { signed, i64, TyI64 } + impl_to_source_int! { signed, int, ast::TyIs(false) } + impl_to_source_int! { signed, i8, ast::TyI8 } + impl_to_source_int! { signed, i16, ast::TyI16 } + impl_to_source_int! { signed, i32, ast::TyI32 } + impl_to_source_int! { signed, i64, ast::TyI64 } - impl_to_source_int! { unsigned, uint, TyUs } - impl_to_source_int! { unsigned, u8, TyU8 } - impl_to_source_int! { unsigned, u16, TyU16 } - impl_to_source_int! { unsigned, u32, TyU32 } - impl_to_source_int! { unsigned, u64, TyU64 } + impl_to_source_int! { unsigned, uint, ast::TyUs(false) } + impl_to_source_int! { unsigned, u8, ast::TyU8 } + impl_to_source_int! { unsigned, u16, ast::TyU16 } + impl_to_source_int! { unsigned, u32, ast::TyU32 } + impl_to_source_int! { unsigned, u64, ast::TyU64 } // Alas ... we write these out instead. All redundant. diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c42a6beea2d44..f1f547ba0c7dd 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -702,14 +702,14 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> if let Some(suf) = suffix { if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")} ty = match suf { - "i" => ast::SignedIntLit(ast::TyIs, ast::Plus), - "is" => ast::SignedIntLit(ast::TyIs, ast::Plus), + "i" => ast::SignedIntLit(ast::TyIs(true), ast::Plus), + "is" => ast::SignedIntLit(ast::TyIs(false), ast::Plus), "i8" => ast::SignedIntLit(ast::TyI8, ast::Plus), "i16" => ast::SignedIntLit(ast::TyI16, ast::Plus), "i32" => ast::SignedIntLit(ast::TyI32, ast::Plus), "i64" => ast::SignedIntLit(ast::TyI64, ast::Plus), - "u" => ast::UnsignedIntLit(ast::TyUs), - "us" => ast::UnsignedIntLit(ast::TyUs), + "u" => ast::UnsignedIntLit(ast::TyUs(true)), + "us" => ast::UnsignedIntLit(ast::TyUs(false)), "u8" => ast::UnsignedIntLit(ast::TyU8), "u16" => ast::UnsignedIntLit(ast::TyU16), "u32" => ast::UnsignedIntLit(ast::TyU32), From d12514bc589c1955108d517acd6d5952929b1650 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 21:16:35 +1100 Subject: [PATCH 11/25] Add a warning feature gate for int/uint in types and i/u suffixes. --- src/librustc/middle/ty.rs | 4 +- src/librustc_trans/trans/type_of.rs | 2 +- src/libsyntax/feature_gate.rs | 55 +++++++++++++++++++ .../compile-fail/feature-gate-int-uint.rs | 35 ++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/feature-gate-int-uint.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2534232960fad..ef86e67de1606 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2341,12 +2341,12 @@ impl<'tcx> CommonTypes<'tcx> { bool: intern_ty(arena, interner, ty_bool), char: intern_ty(arena, interner, ty_char), err: intern_ty(arena, interner, ty_err), - int: intern_ty(arena, interner, ty_int(ast::TyIs(_))), + int: intern_ty(arena, interner, ty_int(ast::TyIs(false))), i8: intern_ty(arena, interner, ty_int(ast::TyI8)), i16: intern_ty(arena, interner, ty_int(ast::TyI16)), i32: intern_ty(arena, interner, ty_int(ast::TyI32)), i64: intern_ty(arena, interner, ty_int(ast::TyI64)), - uint: intern_ty(arena, interner, ty_uint(ast::TyUs(_))), + uint: intern_ty(arena, interner, ty_uint(ast::TyUs(false))), u8: intern_ty(arena, interner, ty_uint(ast::TyU8)), u16: intern_ty(arena, interner, ty_uint(ast::TyU16)), u32: intern_ty(arena, interner, ty_uint(ast::TyU32)), diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 416dfb420ffae..9933079742229 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -263,7 +263,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { } match unsized_part_of_type(cx.tcx(), t).sty { - ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs(_)), + ty::ty_str | ty::ty_vec(..) => Type::uint_from_ty(cx, ast::TyUs(false)), ty::ty_trait(_) => Type::vtable_ptr(cx), _ => panic!("Unexpected type returned from unsized_part_of_type : {}", t.repr(cx.tcx())) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2cfcd38d48fca..6deffa804b2df 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -93,6 +93,9 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ // OIBIT specific features ("optin_builtin_traits", Active), + // int and uint are now deprecated + ("int_uint", Active), + // These are used to test this portion of the compiler, they don't actually // mean anything ("test_accepted_feature", Accepted), @@ -157,6 +160,14 @@ impl<'a> Context<'a> { } } + fn warn_feature(&self, feature: &str, span: Span, explain: &str) { + if !self.has_feature(feature) { + self.span_handler.span_warn(span, explain); + self.span_handler.span_help(span, &format!("add #![feature({})] to the \ + crate attributes to silence this warning", + feature)[]); + } + } fn has_feature(&self, feature: &str) -> bool { self.features.iter().any(|&n| n == feature) } @@ -334,6 +345,31 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_ty(&mut self, t: &ast::Ty) { + match t.node { + ast::TyPath(ref p, _) => { + match &*p.segments { + + [ast::PathSegment { identifier, .. }] => { + let name = token::get_ident(identifier); + let msg = if name == "int" { + Some("the `int` type is deprecated; \ + use `isize` or a fixed-sized integer") + } else if name == "uint" { + Some("the `unt` type is deprecated; \ + use `usize` or a fixed-sized integer") + } else { + None + }; + + if let Some(msg) = msg { + self.context.warn_feature("int_uint", t.span, msg) + } + } + _ => {} + } + } + _ => {} + } visit::walk_ty(self, t); } @@ -345,6 +381,25 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { "box expression syntax is experimental in alpha release; \ you can call `Box::new` instead."); } + ast::ExprLit(ref lit) => { + match lit.node { + ast::LitInt(_, ty) => { + let msg = if let ast::SignedIntLit(ast::TyIs(true), _) = ty { + Some("the `i` suffix on integers is deprecated; use `is` \ + or one of the fixed-sized suffixes") + } else if let ast::UnsignedIntLit(ast::TyUs(true)) = ty { + Some("the `u` suffix on integers is deprecated; use `us` \ + or one of the fixed-sized suffixes") + } else { + None + }; + if let Some(msg) = msg { + self.context.warn_feature("int_uint", e.span, msg); + } + } + _ => {} + } + } _ => {} } visit::walk_expr(self, e); diff --git a/src/test/compile-fail/feature-gate-int-uint.rs b/src/test/compile-fail/feature-gate-int-uint.rs new file mode 100644 index 0000000000000..78b931b383f90 --- /dev/null +++ b/src/test/compile-fail/feature-gate-int-uint.rs @@ -0,0 +1,35 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(dead_code)] + +mod u { + type X = uint; //~ WARN the `uint` type is deprecated + struct Foo { + x: uint //~ WARN the `uint` type is deprecated + } + fn bar(x: uint) { //~ WARN the `uint` type is deprecated + 1u; //~ WARN the `u` suffix on integers is deprecated + } +} +mod i { + type X = int; //~ WARN the `int` type is deprecated + struct Foo { + x: int //~ WARN the `int` type is deprecated + } + fn bar(x: int) { //~ WARN the `int` type is deprecated + 1i; //~ WARN the `u` suffix on integers is deprecated + } +} + +fn main() { + // make compilation fail, after feature gating + let () = 1u8; //~ ERROR +} From 4f5a57e80ef6c029278f1e8ef59e13dcea9b255b Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 21:45:49 +1100 Subject: [PATCH 12/25] Remove warning from the libraries. This adds the int_uint feature to *every* library, whether or not it needs it. --- src/compiletest/compiletest.rs | 1 + src/liballoc/lib.rs | 1 + src/libarena/lib.rs | 1 + src/libcollections/lib.rs | 1 + src/libcore/lib.rs | 3 ++- src/libcore/macros.rs | 4 ++-- src/libcoretest/lib.rs | 1 + src/libflate/lib.rs | 1 + src/libfmt_macros/lib.rs | 1 + src/libgetopts/lib.rs | 1 + src/libgraphviz/lib.rs | 1 + src/liblibc/lib.rs | 1 + src/liblog/lib.rs | 1 + src/librand/lib.rs | 2 +- src/librbml/lib.rs | 1 + src/libregex/lib.rs | 1 + src/librustc/lib.rs | 1 + src/librustc_back/lib.rs | 1 + src/librustc_borrowck/lib.rs | 1 + src/librustc_driver/lib.rs | 1 + src/librustc_llvm/lib.rs | 1 + src/librustc_resolve/lib.rs | 1 + src/librustc_trans/lib.rs | 1 + src/librustc_typeck/lib.rs | 1 + src/librustdoc/lib.rs | 1 + src/libserialize/lib.rs | 1 + src/libstd/lib.rs | 1 + src/libstd/macros.rs | 8 ++++---- src/libsyntax/lib.rs | 1 + src/libterm/lib.rs | 1 + src/libtest/lib.rs | 1 + src/libunicode/lib.rs | 1 + 32 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 9a5665e683934..802fb05796d66 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -12,6 +12,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax, unboxed_closures)] #![feature(box_syntax)] +#![feature(int_uint)] #![deny(warnings)] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0bb8ba669ec25..3fbb063b340b1 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -68,6 +68,7 @@ #![allow(unknown_features)] #![feature(lang_items, unsafe_destructor)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #[macro_use] extern crate core; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index f208ff9dc0517..e6ceab4c4d431 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -32,6 +32,7 @@ #![feature(unsafe_destructor)] #![feature(unboxed_closures)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![allow(missing_docs)] extern crate alloc; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 7692c1558a70f..a651d8a9d76d1 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -27,6 +27,7 @@ #![feature(box_syntax)] #![feature(unboxed_closures)] #![feature(old_impl_check)] +#![allow(unknown_features)] #![feature(int_uint)] #![no_std] #[macro_use] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index af5aba53bf478..39aaca93f1b3a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -59,9 +59,10 @@ #![no_std] #![allow(unknown_features, raw_pointer_derive)] #![cfg_attr(stage0, allow(unused_attributes))] -#![feature(intrinsics, lang_items)] +#![allow(unknown_features)] #![feature(intrinsics, lang_items)] #![feature(simd, unsafe_destructor, slicing_syntax)] #![feature(unboxed_closures)] +#![allow(unknown_features)] #![feature(int_uint)] #![deny(missing_docs)] #[macro_use] diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index bfe88fff22fb1..f6415518864bf 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -15,7 +15,7 @@ macro_rules! panic { panic!("explicit panic") ); ($msg:expr) => ({ - static _MSG_FILE_LINE: (&'static str, &'static str, uint) = ($msg, file!(), line!()); + static _MSG_FILE_LINE: (&'static str, &'static str, usize) = ($msg, file!(), line!()); ::core::panicking::panic(&_MSG_FILE_LINE) }); ($fmt:expr, $($arg:tt)*) => ({ @@ -23,7 +23,7 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, uint) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!()); ::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE) }); } diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index c12981b7d2484..0d371dbe15375 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -11,6 +11,7 @@ #![feature(unsafe_destructor, slicing_syntax)] #![feature(unboxed_closures)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate core; extern crate test; diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 1896bdd182ae0..fda52cebf75cb 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -17,6 +17,7 @@ #![crate_name = "flate"] #![experimental] #![staged_api] +#![allow(unknown_features)] #![feature(int_uint)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 02eea5d024c7a..4ec5969a6d769 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -25,6 +25,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] pub use self::Piece::*; pub use self::Position::*; diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 1d6c99542b58e..10d514fee8c44 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -87,6 +87,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![deny(missing_docs)] #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 9d2318e253e72..268dfdc00f9a4 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -273,6 +273,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] use self::LabelText::*; diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index c39fd074387f5..dfa7f5cc754f9 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -12,6 +12,7 @@ #![crate_type = "rlib"] #![cfg_attr(not(feature = "cargo-build"), experimental)] #![cfg_attr(not(feature = "cargo-build"), staged_api)] +#![allow(unknown_features)] #![feature(int_uint)] #![no_std] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 0d5f6b65827a4..ef7c6f5f311e2 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -168,6 +168,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![deny(missing_docs)] extern crate regex; diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 497e339b316c1..d7caa4158ddc5 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -22,7 +22,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] - +#![allow(unknown_features)] #![feature(int_uint)] #![no_std] #![experimental] #![staged_api] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index da803aa50119c..4a28316fbea2f 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -26,6 +26,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![allow(unknown_features)] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate serialize; #[macro_use] extern crate log; diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index d19ce3b460ae5..4fd4531a92b39 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -26,6 +26,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![deny(missing_docs)] #[cfg(test)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index e0143917a7cff..283e32e8802b8 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -27,6 +27,7 @@ #![feature(quote)] #![feature(slicing_syntax, unsafe_destructor)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![feature(rustc_diagnostic_macros)] #![feature(old_impl_check)] diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index fcd20158c0a29..d07a11b8a6a32 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -31,6 +31,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![allow(unknown_features)] #![feature(slicing_syntax, box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate syntax; extern crate serialize; diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 452eaaaa52dab..0b96171548ab9 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -21,6 +21,7 @@ #![feature(quote)] #![feature(slicing_syntax, unsafe_destructor)] #![feature(rustc_diagnostic_macros)] +#![allow(unknown_features)] #![feature(int_uint)] #![allow(non_camel_case_types)] #[macro_use] extern crate log; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 27e1eaacdfd99..7617027dfd195 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -28,6 +28,7 @@ #![feature(slicing_syntax, unsafe_destructor)] #![feature(box_syntax)] #![feature(rustc_diagnostic_macros)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate arena; extern crate flate; diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 4a281c413d6fc..2895defdd6f60 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -25,6 +25,7 @@ #![allow(unknown_features)] #![feature(link_args)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate libc; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 88f0abf3ca761..edd67590e0cb5 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -19,6 +19,7 @@ #![feature(slicing_syntax)] #![feature(rustc_diagnostic_macros)] +#![allow(unknown_features)] #![feature(int_uint)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 5da51697d2fee..b317cdc4dca38 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -28,6 +28,7 @@ #![feature(slicing_syntax, unsafe_destructor)] #![feature(box_syntax)] #![feature(rustc_diagnostic_macros)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate arena; extern crate flate; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 76ac4b2e8af4c..e39d7186fa187 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -77,6 +77,7 @@ This API is completely unstable and subject to change. #![feature(slicing_syntax, unsafe_destructor)] #![feature(box_syntax)] #![feature(rustc_diagnostic_macros)] +#![allow(unknown_features)] #![feature(int_uint)] #![allow(non_camel_case_types)] #[macro_use] extern crate log; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 56f5c23f6f1bb..e0b0274b7c4eb 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -19,6 +19,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![feature(slicing_syntax)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate arena; extern crate getopts; diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index b3c4cec2ef13f..942a8cfa2c5b9 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -28,6 +28,7 @@ Core encoding and decoding interfaces. #![feature(box_syntax)] #![feature(old_impl_check)] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] // test harness access #[cfg(test)] extern crate test; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 71221a654e8c1..dc157c7d67660 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -110,6 +110,7 @@ #![feature(slicing_syntax, unboxed_closures)] #![feature(box_syntax)] #![feature(old_impl_check)] +#![allow(unknown_features)] #![feature(int_uint)] // Don't link to std. We are std. #![no_std] diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 0594b711ad62e..6e7599b7b8f72 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -44,7 +44,7 @@ macro_rules! panic { ($msg:expr) => ({ $crate::rt::begin_unwind($msg, { // static requires less code at runtime, more constant data - static _FILE_LINE: (&'static str, uint) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!()); &_FILE_LINE }) }); @@ -54,7 +54,7 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, uint) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!()); &_FILE_LINE }) }); @@ -466,7 +466,7 @@ pub mod builtin { /// A macro which expands to the line number on which it was invoked. /// - /// The expanded expression has type `uint`, and the returned line is not + /// The expanded expression has type `usize`, and the returned line is not /// the invocation of the `line!()` macro itself, but rather the first macro /// invocation leading up to the invocation of the `line!()` macro. /// @@ -481,7 +481,7 @@ pub mod builtin { /// A macro which expands to the column number on which it was invoked. /// - /// The expanded expression has type `uint`, and the returned column is not + /// The expanded expression has type `usize`, and the returned column is not /// the invocation of the `column!()` macro itself, but rather the first macro /// invocation leading up to the invocation of the `column!()` macro. /// diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 1efd6a87f863f..4bbc8a40a9e60 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -27,6 +27,7 @@ #![feature(slicing_syntax)] #![feature(box_syntax)] #![feature(quote, unsafe_destructor)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate arena; extern crate fmt_macros; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index b4f224cb4a7ce..6db07b9c87cf0 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -51,6 +51,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] #![deny(missing_docs)] #[macro_use] extern crate log; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index d04308814f85b..ec01b535bfdf3 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -34,6 +34,7 @@ #![allow(unknown_features)] #![feature(asm, slicing_syntax)] #![feature(box_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate getopts; extern crate regex; diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index 27255cc33ee6a..6c95d6ef2a6dd 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -30,6 +30,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] #![feature(slicing_syntax)] +#![allow(unknown_features)] #![feature(int_uint)] extern crate core; From 0c70ce1424f380360dcc8d857c68d2df1a27b6fd Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 21:54:35 +1100 Subject: [PATCH 13/25] Update compile fail tests to use isize. --- .../compile-fail/access-mode-in-closures.rs | 4 +- src/test/compile-fail/arg-count-mismatch.rs | 2 +- src/test/compile-fail/arg-type-mismatch.rs | 2 +- src/test/compile-fail/array-old-syntax-1.rs | 2 +- src/test/compile-fail/asm-in-bad-modifier.rs | 6 +- src/test/compile-fail/asm-misplaced-option.rs | 2 +- src/test/compile-fail/asm-out-assign-imm.rs | 4 +- src/test/compile-fail/asm-out-no-modifier.rs | 4 +- src/test/compile-fail/asm-out-read-uninit.rs | 4 +- .../compile-fail/assign-imm-local-twice.rs | 2 +- src/test/compile-fail/assign-to-method.rs | 4 +- src/test/compile-fail/assoc-inherent.rs | 2 +- .../associated-types-bound-failure.rs | 6 +- .../compile-fail/associated-types-eq-2.rs | 2 +- .../compile-fail/associated-types-eq-3.rs | 2 +- .../associated-types-eq-expr-path.rs | 8 +- .../compile-fail/associated-types-eq-hr.rs | 20 ++-- .../associated-types-incomplete-object.rs | 2 +- ...ted-types-invalid-trait-ref-issue-18865.rs | 2 +- .../associated-types-issue-17359.rs | 2 +- .../associated-types-no-suitable-bound.rs | 2 +- .../compile-fail/associated-types-path-2.rs | 4 +- ...ciated-types-project-from-hrtb-explicit.rs | 2 +- ...ated-types-project-from-hrtb-in-fn-body.rs | 10 +- ...ssociated-types-project-from-hrtb-in-fn.rs | 10 +- ...iated-types-project-from-hrtb-in-struct.rs | 10 +- ...types-project-from-hrtb-in-trait-method.rs | 10 +- .../associated-types-unconstrained.rs | 8 +- .../compile-fail/auto-ref-slice-plus-ref.rs | 2 +- src/test/compile-fail/autoderef-full-lval.rs | 2 +- src/test/compile-fail/bad-env-capture.rs | 2 +- src/test/compile-fail/bad-env-capture2.rs | 2 +- src/test/compile-fail/bad-env-capture3.rs | 2 +- src/test/compile-fail/bad-main.rs | 2 +- src/test/compile-fail/bad-match.rs | 2 +- .../compile-fail/bad-mid-path-type-params.rs | 14 +-- src/test/compile-fail/bad-name.rs | 2 +- src/test/compile-fail/better-expected.rs | 2 +- .../bind-struct-early-modifiers.rs | 2 +- src/test/compile-fail/bogus-tag.rs | 2 +- src/test/compile-fail/borrow-tuple-fields.rs | 4 +- src/test/compile-fail/borrowck-and-init.rs | 2 +- .../compile-fail/borrowck-assign-comp-idx.rs | 8 +- src/test/compile-fail/borrowck-assign-comp.rs | 4 +- ...rowck-assign-to-andmut-in-aliasable-loc.rs | 2 +- ...rrowck-assign-to-andmut-in-borrowed-loc.rs | 2 +- .../borrowck-assign-to-constants.rs | 2 +- .../borrowck-auto-mut-ref-to-immut-var.rs | 2 +- src/test/compile-fail/borrowck-block-unint.rs | 2 +- .../borrowck-borrow-from-owned-ptr.rs | 4 +- .../borrowck-borrow-from-stack-variable.rs | 4 +- .../borrowck-borrow-from-temporary.rs | 4 +- ...ck-borrow-mut-base-ptr-in-aliasable-loc.rs | 12 +- ...rrowck-borrow-overloaded-auto-deref-mut.rs | 24 ++-- .../borrowck-borrow-overloaded-auto-deref.rs | 24 ++-- .../borrowck-borrow-overloaded-deref-mut.rs | 18 +-- .../borrowck-borrow-overloaded-deref.rs | 18 +-- .../borrowck-box-insensitivity.rs | 12 +- .../compile-fail/borrowck-break-uninit-2.rs | 4 +- .../compile-fail/borrowck-break-uninit.rs | 4 +- .../borrowck-call-is-borrow-issue-12224.rs | 4 +- ...borrowck-call-method-from-mut-aliasable.rs | 2 +- .../borrowck-closures-mut-and-imm.rs | 8 +- .../borrowck-closures-mut-of-imm.rs | 6 +- .../compile-fail/borrowck-closures-two-mut.rs | 4 +- .../borrowck-closures-unique-imm.rs | 2 +- .../compile-fail/borrowck-closures-unique.rs | 14 +-- .../borrowck-closures-use-after-free.rs | 2 +- .../borrowck-field-sensitivity.rs | 2 +- ...rrowck-for-loop-correct-cmt-for-pattern.rs | 2 +- src/test/compile-fail/borrowck-if-no-else.rs | 4 +- .../compile-fail/borrowck-if-with-else.rs | 4 +- .../borrowck-init-in-called-fn-expr.rs | 4 +- .../compile-fail/borrowck-init-in-fn-expr.rs | 4 +- src/test/compile-fail/borrowck-init-in-fru.rs | 4 +- .../compile-fail/borrowck-init-op-equal.rs | 2 +- .../compile-fail/borrowck-init-plus-equal.rs | 2 +- .../borrowck-insert-during-each.rs | 4 +- src/test/compile-fail/borrowck-issue-14498.rs | 8 +- .../compile-fail/borrowck-lend-flow-if.rs | 6 +- .../compile-fail/borrowck-lend-flow-loop.rs | 6 +- src/test/compile-fail/borrowck-lend-flow.rs | 6 +- .../borrowck-loan-blocks-move-cc.rs | 2 +- .../compile-fail/borrowck-loan-blocks-move.rs | 2 +- .../borrowck-loan-blocks-mut-uniq.rs | 2 +- .../borrowck-loan-rcvr-overloaded-op.rs | 12 +- src/test/compile-fail/borrowck-loan-rcvr.rs | 2 +- .../compile-fail/borrowck-loan-vec-content.rs | 6 +- .../borrowck-match-binding-is-assignment.rs | 4 +- .../compile-fail/borrowck-move-by-capture.rs | 2 +- .../borrowck-move-error-with-note.rs | 2 +- .../borrowck-move-from-unsafe-ptr.rs | 2 +- .../borrowck-move-moved-value-into-closure.rs | 2 +- .../borrowck-move-mut-base-ptr.rs | 4 +- .../borrowck-move-out-of-static-item.rs | 2 +- .../borrowck-move-subcomponent.rs | 2 +- .../borrowck-mut-addr-of-imm-var.rs | 4 +- .../borrowck-mut-borrow-of-mut-base-ptr.rs | 12 +- .../borrowck-mut-slice-of-imm-vec.rs | 2 +- .../compile-fail/borrowck-mutate-in-guard.rs | 4 +- src/test/compile-fail/borrowck-or-init.rs | 2 +- .../compile-fail/borrowck-overloaded-call.rs | 16 +-- .../borrowck-overloaded-index-autoderef.rs | 12 +- .../compile-fail/borrowck-overloaded-index.rs | 20 ++-- .../borrowck-pat-reassign-binding.rs | 2 +- .../borrowck-reborrow-from-mut.rs | 4 +- ...owck-reborrow-from-shorter-lived-andmut.rs | 2 +- .../compile-fail/borrowck-ref-mut-of-imm.rs | 2 +- src/test/compile-fail/borrowck-return.rs | 4 +- .../borrowck-struct-update-with-dtor.rs | 4 +- .../borrowck-swap-mut-base-ptr.rs | 6 +- src/test/compile-fail/borrowck-unary-move.rs | 4 +- .../compile-fail/borrowck-unboxed-closures.rs | 6 +- .../borrowck-uninit-after-item.rs | 2 +- .../borrowck-uninit-in-assignop.rs | 20 ++-- src/test/compile-fail/borrowck-uninit.rs | 4 +- .../compile-fail/borrowck-uniq-via-lend.rs | 6 +- .../borrowck-use-in-index-lvalue.rs | 4 +- .../compile-fail/borrowck-use-mut-borrow.rs | 8 +- .../borrowck-vec-pattern-element-loan.rs | 12 +- .../borrowck-vec-pattern-loan-from-mut.rs | 2 +- .../borrowck-vec-pattern-nesting.rs | 8 +- .../borrowck-vec-pattern-tail-element-loan.rs | 4 +- src/test/compile-fail/borrowck-while.rs | 4 +- src/test/compile-fail/capture1.rs | 4 +- src/test/compile-fail/cast-to-bare-fn.rs | 6 +- .../check-static-immutable-mut-slices.rs | 2 +- .../check-static-values-constraints.rs | 8 +- src/test/compile-fail/class-cast-to-trait.rs | 4 +- src/test/compile-fail/coherence-all-remote.rs | 2 +- src/test/compile-fail/coherence-bigint-int.rs | 2 +- .../compile-fail/coherence-bigint-vecint.rs | 2 +- ...nket-conflicts-with-blanket-implemented.rs | 2 +- ...ket-conflicts-with-specific-cross-crate.rs | 4 +- src/test/compile-fail/coherence-orphan.rs | 6 +- .../compile-fail/comm-not-freeze-receiver.rs | 2 +- src/test/compile-fail/comm-not-freeze.rs | 2 +- src/test/compile-fail/const-recursive.rs | 4 +- src/test/compile-fail/copy-a-resource.rs | 4 +- src/test/compile-fail/deriving-primitive.rs | 10 +- .../compile-fail/destructure-trait-ref.rs | 2 +- src/test/compile-fail/drop-on-non-struct.rs | 2 +- src/test/compile-fail/dst-bad-assign-2.rs | 8 +- src/test/compile-fail/dst-bad-assign.rs | 8 +- src/test/compile-fail/dst-bad-coerce2.rs | 4 +- src/test/compile-fail/dst-bad-coerce3.rs | 4 +- src/test/compile-fail/dst-bad-deep.rs | 6 +- src/test/compile-fail/dst-rvalue.rs | 4 +- src/test/compile-fail/duplicate-parameter.rs | 2 +- .../enum-and-module-in-same-scope.rs | 2 +- .../compile-fail/enum-discrim-too-small.rs | 2 +- src/test/compile-fail/enum-in-scope.rs | 2 +- .../compile-fail/explicit-call-to-dtor.rs | 2 +- .../explicit-call-to-supertrait-dtor.rs | 2 +- .../explicit-self-lifetime-mismatch.rs | 4 +- src/test/compile-fail/export.rs | 4 +- .../compile-fail/feature-gate-int-uint.rs | 6 +- src/test/compile-fail/fn-bad-block-type.rs | 2 +- src/test/compile-fail/fn-item-type.rs | 4 +- src/test/compile-fail/fn-variance-1.rs | 4 +- src/test/compile-fail/for-loop-bogosity.rs | 6 +- src/test/compile-fail/forget-init-unsafe.rs | 2 +- .../fully-qualified-type-name3.rs | 2 +- .../functional-struct-update-noncopyable.rs | 2 +- .../compile-fail/gated-non-ascii-idents.rs | 8 +- .../generic-impl-less-params-with-defaults.rs | 2 +- .../generic-impl-more-params-with-defaults.rs | 2 +- .../generic-type-more-params-with-defaults.rs | 2 +- src/test/compile-fail/glob-resolve1.rs | 2 +- .../compile-fail/hrtb-conflate-regions.rs | 6 +- ...tb-higher-ranker-supertraits-transitive.rs | 4 +- .../hrtb-higher-ranker-supertraits.rs | 4 +- .../compile-fail/hrtb-identity-fn-borrows.rs | 2 +- .../compile-fail/immut-function-arguments.rs | 4 +- src/test/compile-fail/impl-bounds-checking.rs | 4 +- .../compile-fail/impl-not-adjacent-to-type.rs | 4 +- src/test/compile-fail/impl-unused-tps.rs | 8 +- src/test/compile-fail/import-shadow-1.rs | 4 +- src/test/compile-fail/import-shadow-2.rs | 4 +- src/test/compile-fail/import-shadow-3.rs | 4 +- src/test/compile-fail/import-shadow-4.rs | 4 +- src/test/compile-fail/import-shadow-5.rs | 4 +- src/test/compile-fail/import-shadow-6.rs | 4 +- src/test/compile-fail/import-shadow-7.rs | 4 +- .../compile-fail/indexing-requires-a-uint.rs | 2 +- .../infinite-tag-type-recursion.rs | 2 +- .../int-literal-too-large-span.rs | 2 +- src/test/compile-fail/integral-indexing.rs | 2 +- .../compile-fail/intrinsic-return-address.rs | 2 +- src/test/compile-fail/issue-10291.rs | 4 +- src/test/compile-fail/issue-10392-2.rs | 2 +- src/test/compile-fail/issue-10392.rs | 2 +- src/test/compile-fail/issue-10636-2.rs | 2 +- src/test/compile-fail/issue-10877.rs | 6 +- src/test/compile-fail/issue-11192.rs | 2 +- src/test/compile-fail/issue-11714.rs | 2 +- src/test/compile-fail/issue-12116.rs | 2 +- src/test/compile-fail/issue-12127.rs | 2 +- src/test/compile-fail/issue-12369.rs | 2 +- src/test/compile-fail/issue-12470.rs | 6 +- src/test/compile-fail/issue-12997-1.rs | 2 +- src/test/compile-fail/issue-13359.rs | 2 +- src/test/compile-fail/issue-13853-4.rs | 2 +- src/test/compile-fail/issue-14182.rs | 4 +- src/test/compile-fail/issue-14254.rs | 10 +- src/test/compile-fail/issue-14303-impl.rs | 2 +- src/test/compile-fail/issue-15129.rs | 2 +- src/test/compile-fail/issue-15524.rs | 2 +- src/test/compile-fail/issue-16149.rs | 2 +- src/test/compile-fail/issue-16465.rs | 2 +- src/test/compile-fail/issue-17263.rs | 2 +- src/test/compile-fail/issue-17383.rs | 2 +- src/test/compile-fail/issue-17385.rs | 2 +- src/test/compile-fail/issue-17405.rs | 2 +- src/test/compile-fail/issue-17450.rs | 4 +- .../compile-fail/issue-17718-const-naming.rs | 2 +- src/test/compile-fail/issue-18118.rs | 2 +- src/test/compile-fail/issue-18423.rs | 2 +- src/test/compile-fail/issue-19096.rs | 2 +- src/test/compile-fail/issue-19244-1.rs | 2 +- src/test/compile-fail/issue-19244-2.rs | 2 +- src/test/compile-fail/issue-2150.rs | 2 +- src/test/compile-fail/issue-2330.rs | 4 +- src/test/compile-fail/issue-2354-1.rs | 2 +- src/test/compile-fail/issue-2356.rs | 2 +- src/test/compile-fail/issue-2478.rs | 4 +- src/test/compile-fail/issue-2590.rs | 6 +- src/test/compile-fail/issue-2611-4.rs | 2 +- src/test/compile-fail/issue-2611-5.rs | 2 +- src/test/compile-fail/issue-2823.rs | 2 +- src/test/compile-fail/issue-2849.rs | 2 +- src/test/compile-fail/issue-2995.rs | 4 +- src/test/compile-fail/issue-3038.rs | 6 +- src/test/compile-fail/issue-3521-2.rs | 2 +- src/test/compile-fail/issue-3668-2.rs | 4 +- src/test/compile-fail/issue-3702-2.rs | 10 +- src/test/compile-fail/issue-3763.rs | 2 +- src/test/compile-fail/issue-3820.rs | 4 +- src/test/compile-fail/issue-3907-2.rs | 2 +- src/test/compile-fail/issue-3907.rs | 2 +- src/test/compile-fail/issue-3953.rs | 2 +- src/test/compile-fail/issue-4366-2.rs | 2 +- src/test/compile-fail/issue-4366.rs | 4 +- src/test/compile-fail/issue-5035.rs | 2 +- src/test/compile-fail/issue-5153.rs | 4 +- src/test/compile-fail/issue-5439.rs | 6 +- src/test/compile-fail/issue-5544-a.rs | 2 +- src/test/compile-fail/issue-5544-b.rs | 2 +- src/test/compile-fail/issue-5997-enum.rs | 2 +- src/test/compile-fail/issue-5997-struct.rs | 2 +- src/test/compile-fail/issue-6702.rs | 2 +- src/test/compile-fail/issue-7044.rs | 2 +- src/test/compile-fail/issue-7364.rs | 2 +- src/test/compile-fail/issue-7607-1.rs | 2 +- src/test/compile-fail/issue-8153.rs | 6 +- src/test/compile-fail/issue-9243.rs | 2 +- src/test/compile-fail/issue-9725.rs | 2 +- src/test/compile-fail/issue-9814.rs | 2 +- src/test/compile-fail/keyword-super.rs | 2 +- src/test/compile-fail/kindck-copy.rs | 32 +++--- .../compile-fail/kindck-destructor-owned.rs | 4 +- .../compile-fail/kindck-impl-type-params.rs | 4 +- src/test/compile-fail/kindck-send-owned.rs | 8 +- .../kindck-send-region-pointers.rs | 16 +-- src/test/compile-fail/kindck-send-unsafe.rs | 2 +- src/test/compile-fail/lang-item-missing.rs | 2 +- .../compile-fail/lex-bad-numeric-literals.rs | 4 +- ...-return-type-requires-explicit-lifetime.rs | 10 +- ...me-inference-give-expl-lifetime-param-3.rs | 10 +- ...time-inference-give-expl-lifetime-param.rs | 30 ++--- src/test/compile-fail/lifetime-no-keyword.rs | 6 +- .../compile-fail/lifetime-obsoleted-self.rs | 2 +- src/test/compile-fail/linkage1.rs | 2 +- src/test/compile-fail/linkage4.rs | 2 +- src/test/compile-fail/lint-ctypes.rs | 4 +- src/test/compile-fail/lint-dead-code-1.rs | 30 ++--- src/test/compile-fail/lint-dead-code-2.rs | 2 +- src/test/compile-fail/lint-dead-code-3.rs | 2 +- src/test/compile-fail/lint-dead-code-4.rs | 2 +- src/test/compile-fail/lint-dead-code-5.rs | 8 +- ...int-directives-on-use-items-issue-10534.rs | 2 +- .../compile-fail/lint-exceeding-bitshifts.rs | 2 +- src/test/compile-fail/lint-group-style.rs | 2 +- src/test/compile-fail/lint-impl-fn.rs | 4 +- src/test/compile-fail/lint-missing-doc.rs | 22 ++-- .../compile-fail/lint-non-camel-case-types.rs | 10 +- .../lint-non-uppercase-statics.rs | 2 +- .../compile-fail/lint-owned-heap-memory.rs | 2 +- src/test/compile-fail/lint-raw-ptr-derive.rs | 10 +- src/test/compile-fail/lint-shorthand-field.rs | 6 +- src/test/compile-fail/lint-stability.rs | 28 ++--- src/test/compile-fail/lint-type-limits.rs | 4 +- .../compile-fail/lint-unnecessary-parens.rs | 2 +- src/test/compile-fail/lint-unused-imports.rs | 4 +- .../compile-fail/lint-unused-mut-variables.rs | 10 +- .../lint-visible-private-types.rs | 104 +++++++++--------- .../liveness-assign-imm-local-in-loop.rs | 2 +- .../liveness-assign-imm-local-in-op-eq.rs | 2 +- .../liveness-assign-imm-local-with-init.rs | 2 +- .../liveness-closure-require-ret.rs | 2 +- src/test/compile-fail/liveness-dead.rs | 6 +- src/test/compile-fail/liveness-forgot-ret.rs | 4 +- src/test/compile-fail/liveness-issue-2163.rs | 2 +- .../compile-fail/liveness-missing-ret2.rs | 2 +- .../compile-fail/liveness-move-call-arg.rs | 4 +- .../compile-fail/liveness-move-in-loop.rs | 4 +- .../compile-fail/liveness-move-in-while.rs | 4 +- .../liveness-return-last-stmt-semi.rs | 4 +- src/test/compile-fail/liveness-unused.rs | 12 +- .../compile-fail/liveness-use-after-send.rs | 4 +- src/test/compile-fail/main-wrong-type.rs | 4 +- src/test/compile-fail/match-join.rs | 2 +- .../compile-fail/match-static-const-lc.rs | 6 +- src/test/compile-fail/match-struct.rs | 4 +- src/test/compile-fail/match-tag-unary.rs | 4 +- .../compile-fail/match-vec-unreachable.rs | 4 +- .../method-ambig-one-trait-coerce.rs | 6 +- ...method-ambig-one-trait-unknown-int-type.rs | 8 +- src/test/compile-fail/method-call-err-msg.rs | 4 +- src/test/compile-fail/method-missing-call.rs | 8 +- .../compile-fail/missing-derivable-attr.rs | 6 +- src/test/compile-fail/missing-return.rs | 2 +- src/test/compile-fail/mod_file_aux.rs | 2 +- src/test/compile-fail/move-fragments-1.rs | 2 +- src/test/compile-fail/move-fragments-2.rs | 2 +- src/test/compile-fail/move-fragments-3.rs | 2 +- src/test/compile-fail/move-fragments-4.rs | 2 +- src/test/compile-fail/move-fragments-5.rs | 2 +- src/test/compile-fail/move-fragments-7.rs | 2 +- src/test/compile-fail/move-fragments-8.rs | 2 +- src/test/compile-fail/move-fragments-9.rs | 2 +- .../compile-fail/move-out-of-tuple-field.rs | 2 +- .../moves-based-on-type-access-to-field.rs | 2 +- .../moves-based-on-type-block-bad.rs | 2 +- ...s-based-on-type-cyclic-types-issue-4821.rs | 6 +- .../compile-fail/moves-based-on-type-tuple.rs | 2 +- .../compile-fail/moves-sru-moved-field.rs | 6 +- src/test/compile-fail/multitrait.rs | 2 +- src/test/compile-fail/mut-cross-borrowing.rs | 2 +- src/test/compile-fail/mut-patterns.rs | 2 +- .../compile-fail/mutable-class-fields-2.rs | 4 +- src/test/compile-fail/mutable-class-fields.rs | 4 +- src/test/compile-fail/name-clash-nullary.rs | 2 +- .../namespaced-enum-glob-import-no-impls.rs | 4 +- src/test/compile-fail/no_send-struct.rs | 2 +- src/test/compile-fail/no_share-struct.rs | 2 +- src/test/compile-fail/noexporttypeexe.rs | 2 +- .../non-constant-expr-for-fixed-len-vec.rs | 4 +- src/test/compile-fail/non-copyable-void.rs | 2 +- src/test/compile-fail/non-exhaustive-match.rs | 6 +- src/test/compile-fail/noncopyable-class.rs | 8 +- src/test/compile-fail/nonscalar-cast.rs | 4 +- src/test/compile-fail/not-a-pred.rs | 6 +- src/test/compile-fail/not-enough-arguments.rs | 2 +- src/test/compile-fail/obsolete-tilde.rs | 4 +- .../obsolete-tuple-struct-deref.rs | 2 +- src/test/compile-fail/occurs-check-3.rs | 2 +- src/test/compile-fail/or-patter-mismatch.rs | 2 +- src/test/compile-fail/output-type-mismatch.rs | 2 +- src/test/compile-fail/overloaded-calls-bad.rs | 8 +- .../compile-fail/overloaded-calls-nontuple.rs | 8 +- src/test/compile-fail/oversized-literal.rs | 2 +- src/test/compile-fail/pat-ref-enum.rs | 2 +- .../compile-fail/pattern-error-continue.rs | 6 +- .../pattern-ident-path-generics.rs | 2 +- src/test/compile-fail/pattern-tyvar-2.rs | 4 +- src/test/compile-fail/pattern-tyvar.rs | 4 +- src/test/compile-fail/prim-with-args.rs | 24 ++-- src/test/compile-fail/privacy1.rs | 6 +- src/test/compile-fail/privacy2.rs | 2 +- src/test/compile-fail/privacy3.rs | 2 +- src/test/compile-fail/privacy4.rs | 2 +- src/test/compile-fail/privacy5.rs | 6 +- src/test/compile-fail/private-impl-method.rs | 2 +- src/test/compile-fail/private-method.rs | 4 +- .../compile-fail/private-struct-field-ctor.rs | 2 +- .../private-struct-field-pattern.rs | 2 +- src/test/compile-fail/ptr-coercion.rs | 10 +- src/test/compile-fail/qquote-2.rs | 2 +- src/test/compile-fail/recursion.rs | 10 +- .../compile-fail/refutable-pattern-errors.rs | 2 +- .../refutable-pattern-in-fn-arg.rs | 2 +- ...ion-lifetime-bounds-on-fns-where-clause.rs | 10 +- ...ple-lifetime-bounds-on-fns-where-clause.rs | 10 +- .../regionck-unboxed-closure-lifetimes.rs | 2 +- src/test/compile-fail/regions-addr-of-arg.rs | 10 +- .../regions-bound-missing-bound-in-impl.rs | 4 +- .../compile-fail/regions-bounded-by-send.rs | 28 ++--- ...gions-bounded-by-trait-requiring-static.rs | 38 +++---- ...nded-method-type-parameters-trait-bound.rs | 2 +- .../regions-bounded-method-type-parameters.rs | 4 +- src/test/compile-fail/regions-bounds.rs | 4 +- .../regions-close-over-borrowed-ref-in-obj.rs | 4 +- .../regions-close-over-type-parameter-1.rs | 2 +- .../regions-close-over-type-parameter-2.rs | 2 +- ...ions-close-over-type-parameter-multiple.rs | 2 +- .../regions-early-bound-error-method.rs | 8 +- .../compile-fail/regions-early-bound-error.rs | 2 +- src/test/compile-fail/regions-enum-not-wf.rs | 4 +- .../compile-fail/regions-escape-bound-fn-2.rs | 2 +- .../compile-fail/regions-escape-bound-fn.rs | 4 +- .../regions-escape-unboxed-closure.rs | 4 +- .../regions-escape-via-trait-or-not.rs | 10 +- src/test/compile-fail/regions-in-consts.rs | 4 +- .../compile-fail/regions-in-enums-anon.rs | 2 +- .../compile-fail/regions-in-structs-anon.rs | 2 +- src/test/compile-fail/regions-in-structs.rs | 4 +- .../regions-infer-borrow-scope-too-big.rs | 8 +- .../regions-infer-borrow-scope-within-loop.rs | 4 +- .../regions-infer-bound-from-trait-self.rs | 2 +- .../regions-infer-bound-from-trait.rs | 2 +- src/test/compile-fail/regions-infer-call-3.rs | 6 +- ...egions-infer-contravariance-due-to-decl.rs | 4 +- .../regions-infer-covariance-due-to-decl.rs | 4 +- ...ns-infer-invariance-due-to-mutability-3.rs | 2 +- ...ns-infer-invariance-due-to-mutability-4.rs | 2 +- .../compile-fail/regions-infer-not-param.rs | 2 +- .../regions-infer-paramd-method.rs | 6 +- .../regions-infer-proc-static-upvar.rs | 2 +- .../regions-lifetime-bounds-on-fns.rs | 10 +- .../compile-fail/regions-name-duplicated.rs | 2 +- src/test/compile-fail/regions-name-static.rs | 2 +- .../compile-fail/regions-name-undeclared.rs | 36 +++--- src/test/compile-fail/regions-nested-fns-2.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 6 +- .../regions-proc-bound-capture.rs | 4 +- ...s-reborrow-from-shorter-mut-ref-mut-ref.rs | 2 +- .../regions-reborrow-from-shorter-mut-ref.rs | 2 +- .../compile-fail/regions-ref-in-fn-arg.rs | 6 +- .../compile-fail/regions-ret-borrowed-1.rs | 4 +- src/test/compile-fail/regions-ret-borrowed.rs | 8 +- src/test/compile-fail/regions-ret.rs | 2 +- .../regions-return-stack-allocated-vec.rs | 2 +- .../compile-fail/regions-trait-variance.rs | 6 +- src/test/compile-fail/regions-undeclared.rs | 10 +- ...ariant-use-covariant-in-second-position.rs | 8 +- ...ns-variance-contravariant-use-covariant.rs | 6 +- ...ns-variance-covariant-use-contravariant.rs | 6 +- ...ns-variance-invariant-use-contravariant.rs | 6 +- ...egions-variance-invariant-use-covariant.rs | 2 +- .../removed-syntax-enum-newtype.rs | 2 +- .../removed-syntax-extern-const.rs | 2 +- .../compile-fail/removed-syntax-fixed-vec.rs | 2 +- src/test/compile-fail/removed-syntax-mode.rs | 2 +- .../compile-fail/removed-syntax-mut-vec-ty.rs | 4 +- .../removed-syntax-ptr-lifetime.rs | 2 +- .../removed-syntax-uniq-mut-ty.rs | 4 +- .../compile-fail/repeat-to-run-dtor-twice.rs | 2 +- .../resolve-inconsistent-binding-mode.rs | 2 +- .../compile-fail/resolve-unknown-trait.rs | 2 +- src/test/compile-fail/ret-non-nil.rs | 2 +- src/test/compile-fail/shadowed-lifetime.rs | 14 +-- .../shadowing-in-the-same-pattern.rs | 2 +- src/test/compile-fail/simd-type.rs | 2 +- src/test/compile-fail/slice-borrow.rs | 2 +- src/test/compile-fail/slice-mut-2.rs | 4 +- src/test/compile-fail/slice-mut.rs | 2 +- .../compile-fail/static-items-cant-move.rs | 2 +- src/test/compile-fail/static-mut-bad-types.rs | 2 +- .../compile-fail/static-mut-not-constant.rs | 2 +- src/test/compile-fail/static-mut-not-pat.rs | 2 +- .../static-mut-requires-unsafe.rs | 2 +- .../compile-fail/static-priv-by-default.rs | 6 +- .../compile-fail/static-priv-by-default2.rs | 4 +- .../compile-fail/static-reference-to-fn-1.rs | 6 +- .../static-vec-repeat-not-constant.rs | 4 +- src/test/compile-fail/staticness-mismatch.rs | 2 +- .../compile-fail/struct-base-wrong-type.rs | 4 +- .../struct-field-assignability.rs | 2 +- src/test/compile-fail/struct-field-privacy.rs | 10 +- .../compile-fail/struct-fields-decl-dupe.rs | 4 +- src/test/compile-fail/struct-fields-dupe.rs | 2 +- .../compile-fail/struct-fields-missing.rs | 4 +- .../compile-fail/struct-fields-too-many.rs | 2 +- .../struct-like-enum-nonexhaustive.rs | 2 +- .../compile-fail/struct-literal-in-for.rs | 2 +- src/test/compile-fail/struct-literal-in-if.rs | 2 +- .../struct-literal-in-match-discriminant.rs | 2 +- .../compile-fail/struct-literal-in-while.rs | 2 +- .../struct-pattern-match-useless.rs | 4 +- .../compile-fail/struct-variant-no-pub.rs | 2 +- .../compile-fail/struct-variant-privacy.rs | 2 +- .../tag-variant-cast-non-nullary.rs | 4 +- src/test/compile-fail/tail-typeck.rs | 2 +- src/test/compile-fail/terr-in-field.rs | 6 +- src/test/compile-fail/terr-sorts.rs | 4 +- .../trait-bounds-on-structs-and-enums.rs | 4 +- src/test/compile-fail/trait-impl-1.rs | 2 +- ...it-impl-can-not-have-untraitful-methods.rs | 2 +- .../trait-impl-different-num-params.rs | 4 +- ...upertrait-has-wrong-lifetime-parameters.rs | 12 +- .../compile-fail/trait-matching-lifetimes.rs | 4 +- src/test/compile-fail/trait-safety-fn-body.rs | 2 +- .../trait-safety-trait-impl-cc.rs | 4 +- src/test/compile-fail/trait-test-2.rs | 6 +- src/test/compile-fail/trait-test.rs | 2 +- .../compile-fail/traits-multidispatch-bad.rs | 2 +- src/test/compile-fail/transmute-impl.rs | 4 +- .../compile-fail/transmute-type-parameters.rs | 14 +-- .../compile-fail/tuple-index-not-tuple.rs | 2 +- .../tuple-struct-nonexhaustive.rs | 2 +- .../tutorial-suffix-inference-test.rs | 2 +- .../type-parameters-in-field-exprs.rs | 6 +- src/test/compile-fail/type-recursive.rs | 2 +- src/test/compile-fail/type-shadow.rs | 2 +- .../compile-fail/ufcs-explicit-self-bad.rs | 8 +- .../unboxed-closure-feature-gate.rs | 8 +- .../unboxed-closure-sugar-default.rs | 6 +- .../unboxed-closure-sugar-equiv.rs | 28 ++--- .../unboxed-closure-sugar-lifetime-elision.rs | 10 +- ...unboxed-closure-sugar-nonexistent-trait.rs | 6 +- .../unboxed-closure-sugar-region.rs | 6 +- .../unboxed-closure-sugar-used-on-struct-3.rs | 2 +- .../unboxed-closure-sugar-wrong-trait.rs | 2 +- .../unboxed-closures-fnmut-as-fn.rs | 6 +- .../unboxed-closures-type-mismatch.rs | 2 +- .../unboxed-closures-unsafe-extern-fn.rs | 8 +- .../unboxed-closures-vtable-mismatch.rs | 4 +- .../unboxed-closures-wrong-abi.rs | 8 +- ...boxed-closures-wrong-arg-type-extern-fn.rs | 10 +- .../unboxed-closures-wrong-trait.rs | 6 +- .../compile-fail/uninhabited-enum-cast.rs | 2 +- .../compile-fail/unique-object-noncopyable.rs | 2 +- src/test/compile-fail/unique-vec-res.rs | 2 +- src/test/compile-fail/unnecessary-private.rs | 2 +- src/test/compile-fail/unreachable-arm.rs | 2 +- src/test/compile-fail/unsafe-fn-autoderef.rs | 4 +- src/test/compile-fail/unsendable-class.rs | 4 +- src/test/compile-fail/unsized5.rs | 10 +- src/test/compile-fail/unsized6.rs | 6 +- src/test/compile-fail/unused-attr.rs | 2 +- src/test/compile-fail/unused-result.rs | 10 +- .../use-after-move-self-based-on-type.rs | 4 +- src/test/compile-fail/use-after-move-self.rs | 4 +- src/test/compile-fail/use-mod-3.rs | 2 +- src/test/compile-fail/useless-priv.rs | 2 +- src/test/compile-fail/variadic-ffi-1.rs | 2 +- src/test/compile-fail/variadic-ffi-3.rs | 2 +- src/test/compile-fail/variadic-ffi-4.rs | 2 +- .../variance-cell-is-invariant.rs | 6 +- .../compile-fail/variance-regions-direct.rs | 22 ++-- .../compile-fail/variance-regions-indirect.rs | 4 +- .../compile-fail/variance-trait-matching.rs | 10 +- src/test/compile-fail/vec-mut-iter-borrow.rs | 2 +- src/test/compile-fail/vec-res-add.rs | 4 +- src/test/compile-fail/virtual-structs.rs | 2 +- .../compile-fail/vtable-res-trait-param.rs | 10 +- .../compile-fail/walk-struct-literal-with.rs | 2 +- .../where-clause-method-substituion.rs | 2 +- .../where-clauses-not-parameter.rs | 2 +- .../compile-fail/writing-to-immutable-vec.rs | 2 +- src/test/compile-fail/wrong-ret-type.rs | 2 +- 552 files changed, 1324 insertions(+), 1324 deletions(-) diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index f15157d126ed7..bad192fc2cfea 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -9,9 +9,9 @@ // except according to those terms. -struct sty(Vec ); +struct sty(Vec ); -fn unpack(_unpack: F) where F: FnOnce(&sty) -> Vec {} +fn unpack(_unpack: F) where F: FnOnce(&sty) -> Vec {} fn main() { let _foo = unpack(|s| { diff --git a/src/test/compile-fail/arg-count-mismatch.rs b/src/test/compile-fail/arg-count-mismatch.rs index 472c66d9aadbf..673314ec4c997 100644 --- a/src/test/compile-fail/arg-count-mismatch.rs +++ b/src/test/compile-fail/arg-count-mismatch.rs @@ -10,6 +10,6 @@ // error-pattern: parameters were supplied -fn f(x: int) { } +fn f(x: isize) { } fn main() { let i: (); i = f(); } diff --git a/src/test/compile-fail/arg-type-mismatch.rs b/src/test/compile-fail/arg-type-mismatch.rs index 06fcc40f2e493..1f657ca58326e 100644 --- a/src/test/compile-fail/arg-type-mismatch.rs +++ b/src/test/compile-fail/arg-type-mismatch.rs @@ -11,6 +11,6 @@ // error-pattern: mismatched types -fn f(x: int) { } +fn f(x: isize) { } fn main() { let i: (); i = f(()); } diff --git a/src/test/compile-fail/array-old-syntax-1.rs b/src/test/compile-fail/array-old-syntax-1.rs index 3c01a7756a6b9..2dbc9e3da2181 100644 --- a/src/test/compile-fail/array-old-syntax-1.rs +++ b/src/test/compile-fail/array-old-syntax-1.rs @@ -11,5 +11,5 @@ // Test that the old fixed length array syntax is a parsing error. fn main() { - let _x: [int, ..3] = [0i, 1, 2]; //~ ERROR + let _x: [isize, ..3] = [0i, 1, 2]; //~ ERROR } diff --git a/src/test/compile-fail/asm-in-bad-modifier.rs b/src/test/compile-fail/asm-in-bad-modifier.rs index bc240df9b3b1c..deff677ad0383 100644 --- a/src/test/compile-fail/asm-in-bad-modifier.rs +++ b/src/test/compile-fail/asm-in-bad-modifier.rs @@ -10,15 +10,15 @@ #![feature(asm)] -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } #[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))] pub fn main() { - let x: int; - let y: int; + let x: isize; + let y: isize; unsafe { asm!("mov $1, $0" : "=r"(x) : "=r"(5u)); //~ ERROR input operand constraint contains '=' asm!("mov $1, $0" : "=r"(y) : "+r"(5u)); //~ ERROR input operand constraint contains '+' diff --git a/src/test/compile-fail/asm-misplaced-option.rs b/src/test/compile-fail/asm-misplaced-option.rs index b29899e1940e2..42f3c1692c198 100644 --- a/src/test/compile-fail/asm-misplaced-option.rs +++ b/src/test/compile-fail/asm-misplaced-option.rs @@ -18,7 +18,7 @@ target_arch = "x86_64"))] pub fn main() { // assignment not dead - let mut x: int = 0; + let mut x: isize = 0; unsafe { // extra colon asm!("mov $1, $0" : "=r"(x) : "r"(5u), "0"(x) : : "cc"); diff --git a/src/test/compile-fail/asm-out-assign-imm.rs b/src/test/compile-fail/asm-out-assign-imm.rs index 387b4bec47eaa..031b1de91f26e 100644 --- a/src/test/compile-fail/asm-out-assign-imm.rs +++ b/src/test/compile-fail/asm-out-assign-imm.rs @@ -10,14 +10,14 @@ #![feature(asm)] -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } #[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))] pub fn main() { - let x: int; + let x: isize; x = 1; //~ NOTE prior assignment occurs here foo(x); unsafe { diff --git a/src/test/compile-fail/asm-out-no-modifier.rs b/src/test/compile-fail/asm-out-no-modifier.rs index 4690bdc40cbc0..76f60a34f3c01 100644 --- a/src/test/compile-fail/asm-out-no-modifier.rs +++ b/src/test/compile-fail/asm-out-no-modifier.rs @@ -10,14 +10,14 @@ #![feature(asm)] -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } #[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))] pub fn main() { - let x: int; + let x: isize; unsafe { asm!("mov $1, $0" : "r"(x) : "r"(5u)); //~ ERROR output operand constraint lacks '=' } diff --git a/src/test/compile-fail/asm-out-read-uninit.rs b/src/test/compile-fail/asm-out-read-uninit.rs index 2577dcc3f9954..5e71a2c731dd2 100644 --- a/src/test/compile-fail/asm-out-read-uninit.rs +++ b/src/test/compile-fail/asm-out-read-uninit.rs @@ -10,14 +10,14 @@ #![feature(asm)] -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } #[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))] pub fn main() { - let x: int; + let x: isize; unsafe { asm!("mov $1, $0" : "=r"(x) : "r"(x)); //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/assign-imm-local-twice.rs b/src/test/compile-fail/assign-imm-local-twice.rs index 77f47a028d698..540272a8e2c58 100644 --- a/src/test/compile-fail/assign-imm-local-twice.rs +++ b/src/test/compile-fail/assign-imm-local-twice.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test() { - let v: int; + let v: isize; v = 1; //~ NOTE prior assignment occurs here println!("v={}", v); v = 2; //~ ERROR re-assignment of immutable variable diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index f14668192f850..f810851949232 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -11,14 +11,14 @@ struct cat { meows : uint, - how_hungry : int, + how_hungry : isize, } impl cat { pub fn speak(&self) { self.meows += 1u; } } -fn cat(in_x : uint, in_y : int) -> cat { +fn cat(in_x : uint, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/assoc-inherent.rs b/src/test/compile-fail/assoc-inherent.rs index 8025011bfa781..ba8e4a652d337 100644 --- a/src/test/compile-fail/assoc-inherent.rs +++ b/src/test/compile-fail/assoc-inherent.rs @@ -13,7 +13,7 @@ struct Foo; impl Foo { - type Bar = int; //~ERROR associated items are not allowed in inherent impls + type Bar = isize; //~ERROR associated items are not allowed in inherent impls } fn main() {} diff --git a/src/test/compile-fail/associated-types-bound-failure.rs b/src/test/compile-fail/associated-types-bound-failure.rs index 918826bb390cb..adccd73beae2d 100644 --- a/src/test/compile-fail/associated-types-bound-failure.rs +++ b/src/test/compile-fail/associated-types-bound-failure.rs @@ -11,7 +11,7 @@ // Test equality constraints on associated types in a where clause. pub trait ToInt { - fn to_int(&self) -> int; + fn to_int(&self) -> isize; } pub trait GetToInt @@ -21,13 +21,13 @@ pub trait GetToInt fn get(&self) -> ::R; } -fn foo(g: G) -> int +fn foo(g: G) -> isize where G : GetToInt { ToInt::to_int(&g.get()) //~ ERROR not implemented } -fn bar(g: G) -> int +fn bar(g: G) -> isize where G::R : ToInt { ToInt::to_int(&g.get()) // OK diff --git a/src/test/compile-fail/associated-types-eq-2.rs b/src/test/compile-fail/associated-types-eq-2.rs index e298d05d11dad..34c7a6eaa6c47 100644 --- a/src/test/compile-fail/associated-types-eq-2.rs +++ b/src/test/compile-fail/associated-types-eq-2.rs @@ -18,7 +18,7 @@ pub trait Foo { struct Bar; -impl Foo for int { +impl Foo for isize { type A = uint; fn boo(&self) -> uint { 42 } } diff --git a/src/test/compile-fail/associated-types-eq-3.rs b/src/test/compile-fail/associated-types-eq-3.rs index b56f971db7449..f04698100fc88 100644 --- a/src/test/compile-fail/associated-types-eq-3.rs +++ b/src/test/compile-fail/associated-types-eq-3.rs @@ -18,7 +18,7 @@ pub trait Foo { struct Bar; -impl Foo for int { +impl Foo for isize { type A = uint; fn boo(&self) -> uint { 42 diff --git a/src/test/compile-fail/associated-types-eq-expr-path.rs b/src/test/compile-fail/associated-types-eq-expr-path.rs index ef56fdeb05183..90c4c97b5bdfd 100644 --- a/src/test/compile-fail/associated-types-eq-expr-path.rs +++ b/src/test/compile-fail/associated-types-eq-expr-path.rs @@ -12,15 +12,15 @@ trait Foo { type A; - fn bar() -> int; + fn bar() -> isize; } -impl Foo for int { +impl Foo for isize { type A = uint; - fn bar() -> int { 42 } + fn bar() -> isize { 42 } } pub fn main() { - let x: int = Foo::::bar(); + let x: isize = Foo::::bar(); //~^ERROR unexpected binding of associated item in expression path } diff --git a/src/test/compile-fail/associated-types-eq-hr.rs b/src/test/compile-fail/associated-types-eq-hr.rs index 2532977b1ca24..c180e2f61122f 100644 --- a/src/test/compile-fail/associated-types-eq-hr.rs +++ b/src/test/compile-fail/associated-types-eq-hr.rs @@ -17,43 +17,43 @@ pub trait TheTrait { } struct IntStruct { - x: int + x: isize } -impl<'a> TheTrait<&'a int> for IntStruct { - type A = &'a int; +impl<'a> TheTrait<&'a isize> for IntStruct { + type A = &'a isize; - fn get(&self, t: &'a int) -> &'a int { + fn get(&self, t: &'a isize) -> &'a isize { t } } struct UintStruct { - x: int + x: isize } -impl<'a> TheTrait<&'a int> for UintStruct { +impl<'a> TheTrait<&'a isize> for UintStruct { type A = &'a uint; - fn get(&self, t: &'a int) -> &'a uint { + fn get(&self, t: &'a isize) -> &'a uint { panic!() } } fn foo() - where T : for<'x> TheTrait<&'x int, A = &'x int> + where T : for<'x> TheTrait<&'x isize, A = &'x isize> { // ok for IntStruct, but not UintStruct } fn bar() - where T : for<'x> TheTrait<&'x int, A = &'x uint> + where T : for<'x> TheTrait<&'x isize, A = &'x uint> { // ok for UintStruct, but not IntStruct } fn baz() - where T : for<'x,'y> TheTrait<&'x int, A = &'y int> + where T : for<'x,'y> TheTrait<&'x isize, A = &'y isize> { // not ok for either struct, due to the use of two lifetimes } diff --git a/src/test/compile-fail/associated-types-incomplete-object.rs b/src/test/compile-fail/associated-types-incomplete-object.rs index 371f97e867a29..898403f1d6144 100644 --- a/src/test/compile-fail/associated-types-incomplete-object.rs +++ b/src/test/compile-fail/associated-types-incomplete-object.rs @@ -19,7 +19,7 @@ pub trait Foo { struct Bar; -impl Foo for int { +impl Foo for isize { type A = uint; type B = char; fn boo(&self) -> uint { diff --git a/src/test/compile-fail/associated-types-invalid-trait-ref-issue-18865.rs b/src/test/compile-fail/associated-types-invalid-trait-ref-issue-18865.rs index 13f6dcc9fdee4..b6c4d59c84882 100644 --- a/src/test/compile-fail/associated-types-invalid-trait-ref-issue-18865.rs +++ b/src/test/compile-fail/associated-types-invalid-trait-ref-issue-18865.rs @@ -16,7 +16,7 @@ trait Foo { fn get_bar(&self) -> Self::Bar; } -fn f>(t: &T) { +fn f>(t: &T) { let u: >::Bar = t.get_bar(); //~^ ERROR the trait `Foo` is not implemented for the type `T` } diff --git a/src/test/compile-fail/associated-types-issue-17359.rs b/src/test/compile-fail/associated-types-issue-17359.rs index 6c79105abee8f..fa09ae793bf63 100644 --- a/src/test/compile-fail/associated-types-issue-17359.rs +++ b/src/test/compile-fail/associated-types-issue-17359.rs @@ -15,7 +15,7 @@ trait Trait { type Type; } -impl Trait for int {} //~ ERROR missing: `Type` +impl Trait for isize {} //~ ERROR missing: `Type` fn main() {} diff --git a/src/test/compile-fail/associated-types-no-suitable-bound.rs b/src/test/compile-fail/associated-types-no-suitable-bound.rs index 98f2355f9be1a..fd60896c29885 100644 --- a/src/test/compile-fail/associated-types-no-suitable-bound.rs +++ b/src/test/compile-fail/associated-types-no-suitable-bound.rs @@ -14,7 +14,7 @@ trait Get { } struct Struct { - x: int, + x: isize, } impl Struct { diff --git a/src/test/compile-fail/associated-types-path-2.rs b/src/test/compile-fail/associated-types-path-2.rs index 9994a0c465f79..4a9e077769788 100644 --- a/src/test/compile-fail/associated-types-path-2.rs +++ b/src/test/compile-fail/associated-types-path-2.rs @@ -14,7 +14,7 @@ pub trait Foo { type A; } -impl Foo for int { +impl Foo for isize { type A = uint; } @@ -45,7 +45,7 @@ pub fn f1_uint_int() { } pub fn f2_int() { - let _: int = f2(2is); + let _: isize = f2(2is); //~^ ERROR expected `isize`, found `usize` } diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs b/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs index c5245840c4285..917c03fbf4b1c 100644 --- a/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs +++ b/src/test/compile-fail/associated-types-project-from-hrtb-explicit.rs @@ -17,7 +17,7 @@ pub trait Foo { fn get(&self, t: T) -> Self::A; } -fn foo2(x: Foo<&'x int>>::A) +fn foo2(x: Foo<&'x isize>>::A) //~^ ERROR expected identifier, found keyword `for` //~| ERROR expected one of `::` or `>` { diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs index 1f1ab4ca4b6d8..285a77d6b657a 100644 --- a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs @@ -17,15 +17,15 @@ pub trait Foo { fn get(&self, t: T) -> Self::A; } -fn foo<'a, I : for<'x> Foo<&'x int>>( - x: >::A) +fn foo<'a, I : for<'x> Foo<&'x isize>>( + x: >::A) { let y: I::A = x; } -fn bar<'a, 'b, I : for<'x> Foo<&'x int>>( - x: >::A, - y: >::A, +fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>( + x: >::A, + y: >::A, cond: bool) { // x and y here have two distinct lifetimes: diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs index 0920bfab32b97..a79d5c4649a49 100644 --- a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn.rs @@ -17,7 +17,7 @@ pub trait Foo { fn get(&self, t: T) -> Self::A; } -fn foo2 Foo<&'x int>>( +fn foo2 Foo<&'x isize>>( x: I::A) //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context { @@ -28,15 +28,15 @@ fn foo2 Foo<&'x int>>( // specifically for fn signatures. } -fn foo3 Foo<&'x int>>( - x: >::A) +fn foo3 Foo<&'x isize>>( + x: >::A) { // OK, in this case we spelled out the precise regions involved, though we left one of // them anonymous. } -fn foo4<'a, I : for<'x> Foo<&'x int>>( - x: >::A) +fn foo4<'a, I : for<'x> Foo<&'x isize>>( + x: >::A) { // OK, in this case we spelled out the precise regions involved. } diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs index 0acb0f4853bc2..44ad0bb01138f 100644 --- a/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-struct.rs @@ -17,18 +17,18 @@ pub trait Foo { fn get(&self, t: T) -> Self::A; } -struct SomeStruct Foo<&'x int>> { +struct SomeStruct Foo<&'x isize>> { field: I::A //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context } -struct AnotherStruct Foo<&'x int>> { - field: >::A +struct AnotherStruct Foo<&'x isize>> { + field: >::A //~^ ERROR missing lifetime specifier } -struct YetAnotherStruct<'a, I : for<'x> Foo<&'x int>> { - field: >::A +struct YetAnotherStruct<'a, I : for<'x> Foo<&'x isize>> { + field: >::A } pub fn main() {} diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs b/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs index 21e92c53058d6..af46a1b42d078 100644 --- a/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs +++ b/src/test/compile-fail/associated-types-project-from-hrtb-in-trait-method.rs @@ -17,17 +17,17 @@ pub trait Foo { fn get(&self, t: T) -> Self::A; } -trait SomeTrait Foo<&'x int>> { +trait SomeTrait Foo<&'x isize>> { fn some_method(&self, arg: I::A); //~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context } -trait AnotherTrait Foo<&'x int>> { - fn some_method(&self, arg: >::A); +trait AnotherTrait Foo<&'x isize>> { + fn some_method(&self, arg: >::A); } -trait YetAnotherTrait Foo<&'x int>> { - fn some_method<'a>(&self, arg: >::A); +trait YetAnotherTrait Foo<&'x isize>> { + fn some_method<'a>(&self, arg: >::A); } pub fn main() {} diff --git a/src/test/compile-fail/associated-types-unconstrained.rs b/src/test/compile-fail/associated-types-unconstrained.rs index 968634669446a..8b80ab92e0797 100644 --- a/src/test/compile-fail/associated-types-unconstrained.rs +++ b/src/test/compile-fail/associated-types-unconstrained.rs @@ -12,15 +12,15 @@ trait Foo { type A; - fn bar() -> int; + fn bar() -> isize; } -impl Foo for int { +impl Foo for isize { type A = uint; - fn bar() -> int { 42 } + fn bar() -> isize { 42 } } pub fn main() { - let x: int = Foo::bar(); + let x: isize = Foo::bar(); //~^ ERROR type annotations required } diff --git a/src/test/compile-fail/auto-ref-slice-plus-ref.rs b/src/test/compile-fail/auto-ref-slice-plus-ref.rs index fb935cf103096..ad3f467a45471 100644 --- a/src/test/compile-fail/auto-ref-slice-plus-ref.rs +++ b/src/test/compile-fail/auto-ref-slice-plus-ref.rs @@ -27,7 +27,7 @@ trait MyIter { fn test(&self); } -impl<'a> MyIter for &'a [int] { +impl<'a> MyIter for &'a [isize] { fn test_mut(&mut self) { } fn test(&self) { } } diff --git a/src/test/compile-fail/autoderef-full-lval.rs b/src/test/compile-fail/autoderef-full-lval.rs index fb58028658e1b..2c5749e0d5d39 100644 --- a/src/test/compile-fail/autoderef-full-lval.rs +++ b/src/test/compile-fail/autoderef-full-lval.rs @@ -28,7 +28,7 @@ fn main() { assert_eq!(z, 21); let forty: fish = fish{a: box 40}; let two: fish = fish{a: box 2}; - let answer: int = forty.a + two.a; + let answer: isize = forty.a + two.a; //~^ ERROR binary operation `+` cannot be applied to type `Box` println!("{}", answer); assert_eq!(answer, 42); diff --git a/src/test/compile-fail/bad-env-capture.rs b/src/test/compile-fail/bad-env-capture.rs index ac5a4c220a4a6..938664887327b 100644 --- a/src/test/compile-fail/bad-env-capture.rs +++ b/src/test/compile-fail/bad-env-capture.rs @@ -10,7 +10,7 @@ // error-pattern: can't capture dynamic environment in a fn item; fn foo() { - let x: int; + let x: isize; fn bar() { log(debug, x); } } fn main() { foo(); } diff --git a/src/test/compile-fail/bad-env-capture2.rs b/src/test/compile-fail/bad-env-capture2.rs index c97069acd9aee..39a6922cfd0b6 100644 --- a/src/test/compile-fail/bad-env-capture2.rs +++ b/src/test/compile-fail/bad-env-capture2.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern: can't capture dynamic environment in a fn item; -fn foo(x: int) { +fn foo(x: isize) { fn bar() { log(debug, x); } } fn main() { foo(2); } diff --git a/src/test/compile-fail/bad-env-capture3.rs b/src/test/compile-fail/bad-env-capture3.rs index e3a6ac2cdfc4f..8857b94ddce0c 100644 --- a/src/test/compile-fail/bad-env-capture3.rs +++ b/src/test/compile-fail/bad-env-capture3.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern: can't capture dynamic environment in a fn item; -fn foo(x: int) { +fn foo(x: isize) { fn mth() { fn bar() { log(debug, x); } } diff --git a/src/test/compile-fail/bad-main.rs b/src/test/compile-fail/bad-main.rs index da8596fa25b47..321dca8989134 100644 --- a/src/test/compile-fail/bad-main.rs +++ b/src/test/compile-fail/bad-main.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main(x: int) { } //~ ERROR: main function expects type +fn main(x: isize) { } //~ ERROR: main function expects type diff --git a/src/test/compile-fail/bad-match.rs b/src/test/compile-fail/bad-match.rs index 728b577df1dd4..33043ff5524a4 100644 --- a/src/test/compile-fail/bad-match.rs +++ b/src/test/compile-fail/bad-match.rs @@ -11,7 +11,7 @@ // error-pattern: expected fn main() { - let int x = 5; + let isize x = 5; match x; } diff --git a/src/test/compile-fail/bad-mid-path-type-params.rs b/src/test/compile-fail/bad-mid-path-type-params.rs index 3a2a75586576e..79fe4e7165ec3 100644 --- a/src/test/compile-fail/bad-mid-path-type-params.rs +++ b/src/test/compile-fail/bad-mid-path-type-params.rs @@ -33,11 +33,11 @@ trait Trait { } struct S2 { - contents: int, + contents: isize, } -impl Trait for S2 { - fn new(x: int, _: U) -> S2 { +impl Trait for S2 { + fn new(x: isize, _: U) -> S2 { S2 { contents: x, } @@ -45,16 +45,16 @@ impl Trait for S2 { } fn foo<'a>() { - let _ = S::new::(1, 1.0); + let _ = S::new::(1, 1.0); //~^ ERROR too many type parameters provided - let _ = S::<'a,int>::new::(1, 1.0); + let _ = S::<'a,isize>::new::(1, 1.0); //~^ ERROR too many lifetime parameters provided - let _: S2 = Trait::new::(1, 1.0); + let _: S2 = Trait::new::(1, 1.0); //~^ ERROR too many type parameters provided - let _: S2 = Trait::<'a,int>::new::(1, 1.0); + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); //~^ ERROR too many lifetime parameters provided } diff --git a/src/test/compile-fail/bad-name.rs b/src/test/compile-fail/bad-name.rs index e320d5918b6b5..b208c6f4244ef 100644 --- a/src/test/compile-fail/bad-name.rs +++ b/src/test/compile-fail/bad-name.rs @@ -11,5 +11,5 @@ // error-pattern: expected fn main() { - let x.y::.z foo; + let x.y::.z foo; } diff --git a/src/test/compile-fail/better-expected.rs b/src/test/compile-fail/better-expected.rs index 672d8a30fc56c..0d84a5e7d0280 100644 --- a/src/test/compile-fail/better-expected.rs +++ b/src/test/compile-fail/better-expected.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - let x: [int 3]; //~ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `3` + let x: [isize 3]; //~ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `3` } diff --git a/src/test/compile-fail/bind-struct-early-modifiers.rs b/src/test/compile-fail/bind-struct-early-modifiers.rs index 3671cf110d81e..375f6c5d0475e 100644 --- a/src/test/compile-fail/bind-struct-early-modifiers.rs +++ b/src/test/compile-fail/bind-struct-early-modifiers.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - struct Foo { x: int } + struct Foo { x: isize } match (Foo { x: 10 }) { Foo { ref x: ref x } => {}, //~ ERROR unexpected `:` _ => {} diff --git a/src/test/compile-fail/bogus-tag.rs b/src/test/compile-fail/bogus-tag.rs index cc0ed21410323..704d856f106b2 100644 --- a/src/test/compile-fail/bogus-tag.rs +++ b/src/test/compile-fail/bogus-tag.rs @@ -11,7 +11,7 @@ // error-pattern: unresolved -enum color { rgb(int, int, int), rgba(int, int, int, int), } +enum color { rgb(isize, isize, isize), rgba(isize, isize, isize, isize), } fn main() { let red: color = rgb(255, 0, 0); diff --git a/src/test/compile-fail/borrow-tuple-fields.rs b/src/test/compile-fail/borrow-tuple-fields.rs index 59ed0e5fa0630..63fd3c60e8c9d 100644 --- a/src/test/compile-fail/borrow-tuple-fields.rs +++ b/src/test/compile-fail/borrow-tuple-fields.rs @@ -11,9 +11,9 @@ #![allow(unknown_features)] #![feature(box_syntax)] -struct Foo(Box, int); +struct Foo(Box, isize); -struct Bar(int, int); +struct Bar(isize, isize); fn main() { let x = (box 1i, 2i); diff --git a/src/test/compile-fail/borrowck-and-init.rs b/src/test/compile-fail/borrowck-and-init.rs index 0f07cab3acc1b..92f16d8ffcedb 100644 --- a/src/test/compile-fail/borrowck-and-init.rs +++ b/src/test/compile-fail/borrowck-and-init.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let i: int; + let i: isize; println!("{}", false && { i = 5; true }); println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i` diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index a6801a6a51a52..3a2c6f0385107 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -9,22 +9,22 @@ // except according to those terms. struct Point { - x: int, - y: int, + x: isize, + y: isize, } fn a() { let mut p = vec!(1); // Create an immutable pointer into p's contents: - let q: &int = &p[0]; + let q: &isize = &p[0]; p[0] = 5; //~ ERROR cannot borrow println!("{}", *q); } -fn borrow(_x: &[int], _f: F) where F: FnOnce() {} +fn borrow(_x: &[isize], _f: F) where F: FnOnce() {} fn b() { // here we alias the mutable vector into an imm slice and try to diff --git a/src/test/compile-fail/borrowck-assign-comp.rs b/src/test/compile-fail/borrowck-assign-comp.rs index ccd0542ca7f59..802b83119b7c3 100644 --- a/src/test/compile-fail/borrowck-assign-comp.rs +++ b/src/test/compile-fail/borrowck-assign-comp.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct point { x: int, y: int } +struct point { x: isize, y: isize } fn a() { let mut p = point {x: 3, y: 4}; @@ -16,7 +16,7 @@ fn a() { // This assignment is illegal because the field x is not // inherently mutable; since `p` was made immutable, `p.x` is now - // immutable. Otherwise the type of &_q.x (&int) would be wrong. + // immutable. Otherwise the type of &_q.x (&isize) would be wrong. p.x = 5; //~ ERROR cannot assign to `p.x` q.x; } diff --git a/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs index 3fa840f6a4efb..d66cdb99a7463 100644 --- a/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs +++ b/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs @@ -12,7 +12,7 @@ // borrowed (but otherwise non-aliasable) location is illegal. struct S<'a> { - pointer: &'a mut int + pointer: &'a mut isize } fn a(s: &S) { diff --git a/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs b/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs index ccbbc2ea6c3a0..77aa57ef1b5ba 100644 --- a/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs +++ b/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs @@ -12,7 +12,7 @@ // borrowed (but otherwise non-aliasable) location is illegal. struct S<'a> { - pointer: &'a mut int + pointer: &'a mut isize } fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> { diff --git a/src/test/compile-fail/borrowck-assign-to-constants.rs b/src/test/compile-fail/borrowck-assign-to-constants.rs index c0fb24c83e37a..1b5b1899e0d9d 100644 --- a/src/test/compile-fail/borrowck-assign-to-constants.rs +++ b/src/test/compile-fail/borrowck-assign-to-constants.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static foo: int = 5; +static foo: isize = 5; fn main() { // assigning to various global constants diff --git a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs index dcfef4e1d9c85..ea020dc068521 100644 --- a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs +++ b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs @@ -11,7 +11,7 @@ // Tests that auto-ref can't create mutable aliases to immutable memory. struct Foo { - x: int + x: isize } impl Foo { diff --git a/src/test/compile-fail/borrowck-block-unint.rs b/src/test/compile-fail/borrowck-block-unint.rs index e519e57d178c8..a09ee43924543 100644 --- a/src/test/compile-fail/borrowck-block-unint.rs +++ b/src/test/compile-fail/borrowck-block-unint.rs @@ -10,7 +10,7 @@ fn force(f: F) where F: FnOnce() { f(); } fn main() { - let x: int; + let x: isize; force(|| { //~ ERROR capture of possibly uninitialized variable: `x` println!("{}", x); }); diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs index d5998c8ca9935..397c55a502afd 100644 --- a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs +++ b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs @@ -17,8 +17,8 @@ struct Foo { impl Copy for Foo {} struct Bar { - int1: int, - int2: int, + int1: isize, + int2: isize, } impl Copy for Bar {} diff --git a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs index d252d44229792..ae4c09c59d720 100644 --- a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs +++ b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs @@ -16,8 +16,8 @@ struct Foo { impl Copy for Foo {} struct Bar { - int1: int, - int2: int, + int1: isize, + int2: isize, } impl Copy for Bar {} diff --git a/src/test/compile-fail/borrowck-borrow-from-temporary.rs b/src/test/compile-fail/borrowck-borrow-from-temporary.rs index 784bd1e8ae45d..fbb3824cd4060 100644 --- a/src/test/compile-fail/borrowck-borrow-from-temporary.rs +++ b/src/test/compile-fail/borrowck-borrow-from-temporary.rs @@ -11,9 +11,9 @@ // Test lifetimes are linked properly when we take reference // to interior. -struct Foo(int); +struct Foo(isize); -fn foo<'a>() -> &'a int { +fn foo<'a>() -> &'a isize { let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough x } diff --git a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs index 7bee06b7804b9..9126058a4e6f4 100644 --- a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs +++ b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs @@ -13,20 +13,20 @@ // // Example from src/middle/borrowck/doc.rs -fn foo(t0: & &mut int) { +fn foo(t0: & &mut isize) { let t1 = t0; - let p: &int = &**t0; + let p: &isize = &**t0; **t1 = 22; //~ ERROR cannot assign } -fn foo3(t0: &mut &mut int) { +fn foo3(t0: &mut &mut isize) { let t1 = &mut *t0; - let p: &int = &**t0; //~ ERROR cannot borrow + let p: &isize = &**t0; //~ ERROR cannot borrow **t1 = 22; } -fn foo4(t0: & &mut int) { - let x: &mut int = &mut **t0; //~ ERROR cannot borrow +fn foo4(t0: & &mut isize) { + let x: &mut isize = &mut **t0; //~ ERROR cannot borrow *x += 1; } diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs index 66bcfc2380835..5db9ad2e3a4a9 100644 --- a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs +++ b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs @@ -32,25 +32,25 @@ impl DerefMut for Own { } struct Point { - x: int, - y: int + x: isize, + y: isize } impl Point { - fn get(&self) -> (int, int) { + fn get(&self) -> (isize, isize) { (self.x, self.y) } - fn set(&mut self, x: int, y: int) { + fn set(&mut self, x: isize, y: isize) { self.x = x; self.y = y; } - fn x_ref(&self) -> &int { + fn x_ref(&self) -> &isize { &self.x } - fn y_mut(&mut self) -> &mut int { + fn y_mut(&mut self) -> &mut isize { &mut self.y } } @@ -67,15 +67,15 @@ fn deref_mut_field2(mut x: Own) { let _i = &mut x.y; } -fn deref_extend_field(x: &Own) -> &int { +fn deref_extend_field(x: &Own) -> &isize { &x.y } -fn deref_extend_mut_field1(x: &Own) -> &mut int { +fn deref_extend_mut_field1(x: &Own) -> &mut isize { &mut x.y //~ ERROR cannot borrow } -fn deref_extend_mut_field2(x: &mut Own) -> &mut int { +fn deref_extend_mut_field2(x: &mut Own) -> &mut isize { &mut x.y } @@ -126,15 +126,15 @@ fn deref_mut_method2(mut x: Own) { x.set(0, 0); } -fn deref_extend_method(x: &Own) -> &int { +fn deref_extend_method(x: &Own) -> &isize { x.x_ref() } -fn deref_extend_mut_method1(x: &Own) -> &mut int { +fn deref_extend_mut_method1(x: &Own) -> &mut isize { x.y_mut() //~ ERROR cannot borrow } -fn deref_extend_mut_method2(x: &mut Own) -> &mut int { +fn deref_extend_mut_method2(x: &mut Own) -> &mut isize { x.y_mut() } diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs index abab9e57ffe34..75680de9c9eff 100644 --- a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs +++ b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs @@ -26,25 +26,25 @@ impl Deref for Rc { } struct Point { - x: int, - y: int + x: isize, + y: isize } impl Point { - fn get(&self) -> (int, int) { + fn get(&self) -> (isize, isize) { (self.x, self.y) } - fn set(&mut self, x: int, y: int) { + fn set(&mut self, x: isize, y: isize) { self.x = x; self.y = y; } - fn x_ref(&self) -> &int { + fn x_ref(&self) -> &isize { &self.x } - fn y_mut(&mut self) -> &mut int { + fn y_mut(&mut self) -> &mut isize { &mut self.y } } @@ -61,15 +61,15 @@ fn deref_mut_field2(mut x: Rc) { let _i = &mut x.y; //~ ERROR cannot borrow } -fn deref_extend_field(x: &Rc) -> &int { +fn deref_extend_field(x: &Rc) -> &isize { &x.y } -fn deref_extend_mut_field1(x: &Rc) -> &mut int { +fn deref_extend_mut_field1(x: &Rc) -> &mut isize { &mut x.y //~ ERROR cannot borrow } -fn deref_extend_mut_field2(x: &mut Rc) -> &mut int { +fn deref_extend_mut_field2(x: &mut Rc) -> &mut isize { &mut x.y //~ ERROR cannot borrow } @@ -97,15 +97,15 @@ fn deref_mut_method2(mut x: Rc) { x.set(0, 0); //~ ERROR cannot borrow } -fn deref_extend_method(x: &Rc) -> &int { +fn deref_extend_method(x: &Rc) -> &isize { x.x_ref() } -fn deref_extend_mut_method1(x: &Rc) -> &mut int { +fn deref_extend_mut_method1(x: &Rc) -> &mut isize { x.y_mut() //~ ERROR cannot borrow } -fn deref_extend_mut_method2(x: &mut Rc) -> &mut int { +fn deref_extend_mut_method2(x: &mut Rc) -> &mut isize { x.y_mut() //~ ERROR cannot borrow } diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs index dda7e4d10474b..bfe53b739f4a8 100644 --- a/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs +++ b/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs @@ -31,39 +31,39 @@ impl DerefMut for Own { } } -fn deref_imm(x: Own) { +fn deref_imm(x: Own) { let _i = &*x; } -fn deref_mut1(x: Own) { +fn deref_mut1(x: Own) { let _i = &mut *x; //~ ERROR cannot borrow } -fn deref_mut2(mut x: Own) { +fn deref_mut2(mut x: Own) { let _i = &mut *x; } -fn deref_extend<'a>(x: &'a Own) -> &'a int { +fn deref_extend<'a>(x: &'a Own) -> &'a isize { &**x } -fn deref_extend_mut1<'a>(x: &'a Own) -> &'a mut int { +fn deref_extend_mut1<'a>(x: &'a Own) -> &'a mut isize { &mut **x //~ ERROR cannot borrow } -fn deref_extend_mut2<'a>(x: &'a mut Own) -> &'a mut int { +fn deref_extend_mut2<'a>(x: &'a mut Own) -> &'a mut isize { &mut **x } -fn assign1<'a>(x: Own) { +fn assign1<'a>(x: Own) { *x = 3; //~ ERROR cannot borrow } -fn assign2<'a>(x: &'a Own) { +fn assign2<'a>(x: &'a Own) { **x = 3; //~ ERROR cannot borrow } -fn assign3<'a>(x: &'a mut Own) { +fn assign3<'a>(x: &'a mut Own) { **x = 3; } diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs b/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs index 001a5232b127f..153368f4894a4 100644 --- a/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs +++ b/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs @@ -25,39 +25,39 @@ impl Deref for Rc { } } -fn deref_imm(x: Rc) { +fn deref_imm(x: Rc) { let _i = &*x; } -fn deref_mut1(x: Rc) { +fn deref_mut1(x: Rc) { let _i = &mut *x; //~ ERROR cannot borrow } -fn deref_mut2(mut x: Rc) { +fn deref_mut2(mut x: Rc) { let _i = &mut *x; //~ ERROR cannot borrow } -fn deref_extend<'a>(x: &'a Rc) -> &'a int { +fn deref_extend<'a>(x: &'a Rc) -> &'a isize { &**x } -fn deref_extend_mut1<'a>(x: &'a Rc) -> &'a mut int { +fn deref_extend_mut1<'a>(x: &'a Rc) -> &'a mut isize { &mut **x //~ ERROR cannot borrow } -fn deref_extend_mut2<'a>(x: &'a mut Rc) -> &'a mut int { +fn deref_extend_mut2<'a>(x: &'a mut Rc) -> &'a mut isize { &mut **x //~ ERROR cannot borrow } -fn assign1<'a>(x: Rc) { +fn assign1<'a>(x: Rc) { *x = 3; //~ ERROR cannot assign } -fn assign2<'a>(x: &'a Rc) { +fn assign2<'a>(x: &'a Rc) { **x = 3; //~ ERROR cannot assign } -fn assign3<'a>(x: &'a mut Rc) { +fn assign3<'a>(x: &'a mut Rc) { **x = 3; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/borrowck-box-insensitivity.rs b/src/test/compile-fail/borrowck-box-insensitivity.rs index bd22b61fe3b60..648d0d81ffbc0 100644 --- a/src/test/compile-fail/borrowck-box-insensitivity.rs +++ b/src/test/compile-fail/borrowck-box-insensitivity.rs @@ -11,23 +11,23 @@ #![feature(box_syntax)] struct A { - x: Box, - y: int, + x: Box, + y: isize, } struct B { - x: Box, - y: Box, + x: Box, + y: Box, } struct C { x: Box, - y: int, + y: isize, } struct D { x: Box, - y: Box, + y: Box, } fn copy_after_move() { diff --git a/src/test/compile-fail/borrowck-break-uninit-2.rs b/src/test/compile-fail/borrowck-break-uninit-2.rs index 0b10ccfdca193..1ecf9f999b7c5 100644 --- a/src/test/compile-fail/borrowck-break-uninit-2.rs +++ b/src/test/compile-fail/borrowck-break-uninit-2.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() -> int { - let x: int; +fn foo() -> isize { + let x: isize; while 1i != 2 { break; diff --git a/src/test/compile-fail/borrowck-break-uninit.rs b/src/test/compile-fail/borrowck-break-uninit.rs index aa7ce4fa34788..8a6a036945b78 100644 --- a/src/test/compile-fail/borrowck-break-uninit.rs +++ b/src/test/compile-fail/borrowck-break-uninit.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() -> int { - let x: int; +fn foo() -> isize { + let x: isize; loop { break; diff --git a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs index 9aec8de46b6d9..6a77b35f91de4 100644 --- a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs +++ b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs @@ -56,8 +56,8 @@ fn test6() { } fn test7() { - fn foo(_: F) where F: FnMut(Box, int) {} - let mut f = |&mut: g: Box, b: int| {}; + fn foo(_: F) where F: FnMut(Box, isize) {} + let mut f = |&mut: g: Box, b: isize| {}; f(box |a| { //~ ERROR: cannot borrow `f` as immutable because it is also borrowed as mutable foo(f); //~ ERROR: cannot move out of captured outer variable }, 3); diff --git a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs index 537e52120d9f1..bc0b667e895d0 100644 --- a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs +++ b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } impl Foo { diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs index 126003b5d824d..14d57062660b9 100644 --- a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs @@ -13,11 +13,11 @@ #![feature(box_syntax)] -fn get(x: &int) -> int { +fn get(x: &isize) -> isize { *x } -fn set(x: &mut int) { +fn set(x: &mut isize) { *x = 4; } @@ -59,7 +59,7 @@ fn f() { fn g() { struct Foo { - f: Box + f: Box } let mut x = box Foo { f: box 3 }; @@ -69,7 +69,7 @@ fn g() { fn h() { struct Foo { - f: Box + f: Box } let mut x = box Foo { f: box 3 }; diff --git a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs index 30e1421ba2660..8260774190967 100644 --- a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs @@ -11,15 +11,15 @@ // Tests that two closures cannot simultaneously have mutable // and immutable access to the variable. Issue #6801. -fn get(x: &int) -> int { +fn get(x: &isize) -> isize { *x } -fn set(x: &mut int) { +fn set(x: &mut isize) { *x = 4; } -fn a(x: &int) { +fn a(x: &isize) { let c1 = |&mut:| set(&mut *x); //~^ ERROR cannot borrow let c2 = |&mut:| set(&mut *x); diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs index e1f557cfab2d7..d442e3ac3f80c 100644 --- a/src/test/compile-fail/borrowck-closures-two-mut.rs +++ b/src/test/compile-fail/borrowck-closures-two-mut.rs @@ -20,7 +20,7 @@ fn a() { let c2 = |&mut:| x = 5; //~ ERROR cannot borrow `x` as mutable more than once } -fn set(x: &mut int) { +fn set(x: &mut isize) { *x = 4; } @@ -45,7 +45,7 @@ fn d() { fn g() { struct Foo { - f: Box + f: Box } let mut x = box Foo { f: box 3 }; diff --git a/src/test/compile-fail/borrowck-closures-unique-imm.rs b/src/test/compile-fail/borrowck-closures-unique-imm.rs index a9cc9e967f6ff..cf86602af0be2 100644 --- a/src/test/compile-fail/borrowck-closures-unique-imm.rs +++ b/src/test/compile-fail/borrowck-closures-unique-imm.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } pub fn main() { diff --git a/src/test/compile-fail/borrowck-closures-unique.rs b/src/test/compile-fail/borrowck-closures-unique.rs index 9a772cc49b87b..f9a6d5ac84575 100644 --- a/src/test/compile-fail/borrowck-closures-unique.rs +++ b/src/test/compile-fail/borrowck-closures-unique.rs @@ -14,35 +14,35 @@ // may be *immutable*, but we cannot allow // multiple borrows. -fn get(x: &int) -> int { +fn get(x: &isize) -> isize { *x } -fn set(x: &mut int) -> int { +fn set(x: &mut isize) -> isize { *x } -fn a(x: &mut int) { +fn a(x: &mut isize) { let c1 = |&mut:| get(x); let c2 = |&mut:| get(x); } -fn b(x: &mut int) { +fn b(x: &mut isize) { let c1 = |&mut:| get(x); let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x` } -fn c(x: &mut int) { +fn c(x: &mut isize) { let c1 = |&mut:| get(x); let c2 = |&mut:| { get(x); set(x); }; //~ ERROR closure requires unique access to `x` } -fn d(x: &mut int) { +fn d(x: &mut isize) { let c1 = |&mut:| set(x); let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x` } -fn e(x: &mut int) { +fn e(x: &mut isize) { let c1 = |&mut:| x = panic!(); //~ ERROR closure cannot assign to immutable local variable } diff --git a/src/test/compile-fail/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck-closures-use-after-free.rs index 9aa9a50483c66..b6529da18838b 100644 --- a/src/test/compile-fail/borrowck-closures-use-after-free.rs +++ b/src/test/compile-fail/borrowck-closures-use-after-free.rs @@ -15,7 +15,7 @@ #![feature(box_syntax)] struct Foo { - x: int + x: isize } impl Drop for Foo { diff --git a/src/test/compile-fail/borrowck-field-sensitivity.rs b/src/test/compile-fail/borrowck-field-sensitivity.rs index 52761fa348868..fe5142a77341f 100644 --- a/src/test/compile-fail/borrowck-field-sensitivity.rs +++ b/src/test/compile-fail/borrowck-field-sensitivity.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -struct A { a: int, b: Box } +struct A { a: isize, b: Box } fn deref_after_move() { let x = A { a: 1, b: box 2 }; diff --git a/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs b/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs index bdcbc839c0056..17c69a40e58ee 100644 --- a/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs +++ b/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs @@ -13,7 +13,7 @@ #![feature(box_syntax)] struct Foo { - a: [Box; 3], + a: [Box; 3], } fn main() { diff --git a/src/test/compile-fail/borrowck-if-no-else.rs b/src/test/compile-fail/borrowck-if-no-else.rs index 854d42219ea25..08f91e729cd8d 100644 --- a/src/test/compile-fail/borrowck-if-no-else.rs +++ b/src/test/compile-fail/borrowck-if-no-else.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } fn main() { - let x: int; if 1i > 2 { x = 10; } + let x: isize; if 1i > 2 { x = 10; } foo(x); //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/borrowck-if-with-else.rs b/src/test/compile-fail/borrowck-if-with-else.rs index e6d59062af207..01e292ec89d8a 100644 --- a/src/test/compile-fail/borrowck-if-with-else.rs +++ b/src/test/compile-fail/borrowck-if-with-else.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } fn main() { - let x: int; + let x: isize; if 1i > 2 { println!("whoops"); } else { diff --git a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs index 5496a9dd4b361..3c20abab8bdef 100644 --- a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs @@ -9,8 +9,8 @@ // except according to those terms. fn main() { - let j = |&:| -> int { - let i: int; + let j = |&:| -> isize { + let i: isize; i //~ ERROR use of possibly uninitialized variable: `i` }; j(); diff --git a/src/test/compile-fail/borrowck-init-in-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-fn-expr.rs index 33c284c71b341..31ca39c3f9b36 100644 --- a/src/test/compile-fail/borrowck-init-in-fn-expr.rs +++ b/src/test/compile-fail/borrowck-init-in-fn-expr.rs @@ -9,8 +9,8 @@ // except according to those terms. fn main() { - let f = |&:| -> int { - let i: int; + let f = |&:| -> isize { + let i: isize; i //~ ERROR use of possibly uninitialized variable: `i` }; println!("{}", f()); diff --git a/src/test/compile-fail/borrowck-init-in-fru.rs b/src/test/compile-fail/borrowck-init-in-fru.rs index ac90b7cb4328e..569ddb80c2fe2 100644 --- a/src/test/compile-fail/borrowck-init-in-fru.rs +++ b/src/test/compile-fail/borrowck-init-in-fru.rs @@ -10,8 +10,8 @@ #[derive(Clone)] struct point { - x: int, - y: int, + x: isize, + y: isize, } fn main() { diff --git a/src/test/compile-fail/borrowck-init-op-equal.rs b/src/test/compile-fail/borrowck-init-op-equal.rs index d6065c81a2d89..e0d93fd1d475b 100644 --- a/src/test/compile-fail/borrowck-init-op-equal.rs +++ b/src/test/compile-fail/borrowck-init-op-equal.rs @@ -10,7 +10,7 @@ fn test() { - let v: int; + let v: isize; v += 1; //~ ERROR use of possibly uninitialized variable: `v` v.clone(); } diff --git a/src/test/compile-fail/borrowck-init-plus-equal.rs b/src/test/compile-fail/borrowck-init-plus-equal.rs index 6e813809f03dc..a036286f3634a 100644 --- a/src/test/compile-fail/borrowck-init-plus-equal.rs +++ b/src/test/compile-fail/borrowck-init-plus-equal.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test() { - let mut v: int; + let mut v: isize; v = v + 1; //~ ERROR use of possibly uninitialized variable: `v` v.clone(); } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 0428ee8306517..d729af844cb39 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -12,11 +12,11 @@ extern crate collections; use std::collections::HashSet; struct Foo { - n: HashSet, + n: HashSet, } impl Foo { - pub fn foo(&mut self, mut fun: F) where F: FnMut(&int) { + pub fn foo(&mut self, mut fun: F) where F: FnMut(&isize) { for f in self.n.iter() { fun(f); } diff --git a/src/test/compile-fail/borrowck-issue-14498.rs b/src/test/compile-fail/borrowck-issue-14498.rs index 8e46db5eba8bc..cc562afa9f818 100644 --- a/src/test/compile-fail/borrowck-issue-14498.rs +++ b/src/test/compile-fail/borrowck-issue-14498.rs @@ -13,11 +13,11 @@ #![feature(box_syntax)] -struct A { a: int } -struct B<'a> { a: Box<&'a mut int> } +struct A { a: isize } +struct B<'a> { a: Box<&'a mut isize> } fn borrow_in_var_from_var() { - let mut x: int = 1; + let mut x: isize = 1; let y = box &mut x; let p = &y; let q = &***p; @@ -37,7 +37,7 @@ fn borrow_in_var_from_field() { } fn borrow_in_field_from_var() { - let mut x: int = 1; + let mut x: isize = 1; let y = B { a: box &mut x }; let p = &y.a; let q = &***p; diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index 8a618dfec1183..ca8efb5dc967d 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -16,13 +16,13 @@ #![feature(box_syntax)] -fn borrow(_v: &int) {} -fn borrow_mut(_v: &mut int) {} +fn borrow(_v: &isize) {} +fn borrow_mut(_v: &mut isize) {} fn cond() -> bool { panic!() } fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } -fn inc(v: &mut Box) { +fn inc(v: &mut Box) { *v = box() (**v + 1); } diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 954b801024421..83fddcf696496 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -16,12 +16,12 @@ #![feature(box_syntax)] -fn borrow(_v: &int) {} -fn borrow_mut(_v: &mut int) {} +fn borrow(_v: &isize) {} +fn borrow_mut(_v: &mut isize) {} fn cond() -> bool { panic!() } fn produce() -> T { panic!(); } -fn inc(v: &mut Box) { +fn inc(v: &mut Box) { *v = box() (**v + 1); } diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index d5419b0585111..177976c15f0f4 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -16,13 +16,13 @@ #![feature(box_syntax)] -fn borrow(_v: &int) {} -fn borrow_mut(_v: &mut int) {} +fn borrow(_v: &isize) {} +fn borrow_mut(_v: &mut isize) {} fn cond() -> bool { panic!() } fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } -fn inc(v: &mut Box) { +fn inc(v: &mut Box) { *v = box() (**v + 1); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 8b39b6ff661b3..8906e2d42b25a 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -12,7 +12,7 @@ use std::thread::Thread; -fn borrow(v: &int, f: F) where F: FnOnce(&int) { +fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move.rs b/src/test/compile-fail/borrowck-loan-blocks-move.rs index f588dbab4fa14..f3f18807314f9 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn take(_v: Box) { +fn take(_v: Box) { } fn box_imm() { diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index e59baa1e37c8c..a52a4484b20d1 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn borrow(v: &int, f: F) where F: FnOnce(&int) { +fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { f(v); } diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index 5aa2deb44f192..b1eb06d16b19a 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -12,20 +12,20 @@ use std::ops::Add; #[derive(Copy)] struct Point { - x: int, - y: int, + x: isize, + y: isize, } -impl Add for Point { - type Output = int; +impl Add for Point { + type Output = isize; - fn add(self, z: int) -> int { + fn add(self, z: isize) -> isize { self.x + self.y + z } } impl Point { - pub fn times(&self, z: int) -> int { + pub fn times(&self, z: isize) -> isize { self.x * self.y * z } } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index 0ada3db47a4b6..014b27f9659b0 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -9,7 +9,7 @@ // except according to those terms. -struct point { x: int, y: int } +struct point { x: isize, y: isize } trait methods { fn impurem(&self); diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index efb7a5253ed3d..21d9dea77b26a 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -12,17 +12,17 @@ // (locally rooted) mutable, unique vector, and that we then prevent // modifications to the contents. -fn takes_imm_elt(_v: &int, f: F) where F: FnOnce() { +fn takes_imm_elt(_v: &isize, f: F) where F: FnOnce() { f(); } fn has_mut_vec_and_does_not_try_to_change_it() { - let mut v: Vec = vec!(1, 2, 3); + let mut v: Vec = vec!(1, 2, 3); takes_imm_elt(&v[0], || {}) } fn has_mut_vec_but_tries_to_change_it() { - let mut v: Vec = vec!(1, 2, 3); + let mut v: Vec = vec!(1, 2, 3); takes_imm_elt( &v[0], || { //~ ERROR cannot borrow `v` as mutable diff --git a/src/test/compile-fail/borrowck-match-binding-is-assignment.rs b/src/test/compile-fail/borrowck-match-binding-is-assignment.rs index fe0519b8198bc..819ff73a5805c 100644 --- a/src/test/compile-fail/borrowck-match-binding-is-assignment.rs +++ b/src/test/compile-fail/borrowck-match-binding-is-assignment.rs @@ -11,11 +11,11 @@ // Test that immutable pattern bindings cannot be reassigned. enum E { - Foo(int) + Foo(isize) } struct S { - bar: int, + bar: isize, } pub fn main() { diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index 2021276218817..b0d546cd5c803 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -13,6 +13,6 @@ pub fn main() { let bar = box 3; let _g = |&mut:| { - let _h = move |:| -> int { *bar }; //~ ERROR cannot move out of captured outer variable + let _h = move |:| -> isize { *bar }; //~ ERROR cannot move out of captured outer variable }; } diff --git a/src/test/compile-fail/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck-move-error-with-note.rs index 4984987c5ca92..2d82c8be51971 100644 --- a/src/test/compile-fail/borrowck-move-error-with-note.rs +++ b/src/test/compile-fail/borrowck-move-error-with-note.rs @@ -45,7 +45,7 @@ fn move_in_match() { // from issue-8064 struct A { - a: Box, + a: Box, } fn free(_: T) {} diff --git a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs index 87bb8ef7a5882..8310d4ba1444a 100644 --- a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs +++ b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn foo(x: *const Box) -> Box { +fn foo(x: *const Box) -> Box { let y = *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block return y; } diff --git a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs index 35aef1352d1de..43bf3f25d1ab9 100644 --- a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs +++ b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn call_f int>(f: F) -> int { +fn call_f isize>(f: F) -> isize { f() } diff --git a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs index ce2755dbc0f20..5bdea6a2bd996 100644 --- a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs @@ -13,8 +13,8 @@ // // Example from src/middle/borrowck/doc.rs -fn foo(t0: &mut int) { - let p: &int = &*t0; // Freezes `*t0` +fn foo(t0: &mut isize) { + let p: &isize = &*t0; // Freezes `*t0` let t1 = t0; //~ ERROR cannot move out of `t0` *t1 = 22; } diff --git a/src/test/compile-fail/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck-move-out-of-static-item.rs index 730a0c3e23545..2f81aa8f3818e 100644 --- a/src/test/compile-fail/borrowck-move-out-of-static-item.rs +++ b/src/test/compile-fail/borrowck-move-out-of-static-item.rs @@ -13,7 +13,7 @@ use std::marker; struct Foo { - foo: int, + foo: isize, nocopy: marker::NoCopy } diff --git a/src/test/compile-fail/borrowck-move-subcomponent.rs b/src/test/compile-fail/borrowck-move-subcomponent.rs index bdf6fe1f21d2c..88871dda659cf 100644 --- a/src/test/compile-fail/borrowck-move-subcomponent.rs +++ b/src/test/compile-fail/borrowck-move-subcomponent.rs @@ -14,7 +14,7 @@ #![feature(box_syntax)] struct S { - x : Box + x : Box } fn f(_: T) {} diff --git a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs index 0c0377e74112c..b6626a835e454 100644 --- a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs +++ b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs @@ -9,8 +9,8 @@ // except according to those terms. fn main() { - let x: int = 3; - let y: &mut int = &mut x; //~ ERROR cannot borrow + let x: isize = 3; + let y: &mut isize = &mut x; //~ ERROR cannot borrow *y = 5; println!("{}", *y); } diff --git a/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs b/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs index fb018f3d4bc10..71dc61abb64e9 100644 --- a/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs @@ -13,16 +13,16 @@ // // Example from src/middle/borrowck/doc.rs -fn foo<'a>(mut t0: &'a mut int, - mut t1: &'a mut int) { - let p: &int = &*t0; // Freezes `*t0` +fn foo<'a>(mut t0: &'a mut isize, + mut t1: &'a mut isize) { + let p: &isize = &*t0; // Freezes `*t0` let mut t2 = &mut t0; //~ ERROR cannot borrow `t0` **t2 += 1; // Mutates `*t0` } -fn bar<'a>(mut t0: &'a mut int, - mut t1: &'a mut int) { - let p: &mut int = &mut *t0; // Claims `*t0` +fn bar<'a>(mut t0: &'a mut isize, + mut t1: &'a mut isize) { + let p: &mut isize = &mut *t0; // Claims `*t0` let mut t2 = &mut t0; //~ ERROR cannot borrow `t0` **t2 += 1; // Mutates `*t0` but not through `*p` } diff --git a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs index 283d6398e9ad3..b8a92db4e4223 100644 --- a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs +++ b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn write(v: &mut [int]) { +fn write(v: &mut [isize]) { v[0] += 1; } diff --git a/src/test/compile-fail/borrowck-mutate-in-guard.rs b/src/test/compile-fail/borrowck-mutate-in-guard.rs index 464e42df8aa37..44353ab5d960a 100644 --- a/src/test/compile-fail/borrowck-mutate-in-guard.rs +++ b/src/test/compile-fail/borrowck-mutate-in-guard.rs @@ -9,11 +9,11 @@ // except according to those terms. enum Enum<'a> { - A(&'a int), + A(&'a isize), B(bool), } -fn foo() -> int { +fn foo() -> isize { let mut n = 42; let mut x = Enum::A(&mut n); match x { diff --git a/src/test/compile-fail/borrowck-or-init.rs b/src/test/compile-fail/borrowck-or-init.rs index 270eeca4c4b6e..27871a6ab16cd 100644 --- a/src/test/compile-fail/borrowck-or-init.rs +++ b/src/test/compile-fail/borrowck-or-init.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let i: int; + let i: isize; println!("{}", false || { i = 5; true }); println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i` diff --git a/src/test/compile-fail/borrowck-overloaded-call.rs b/src/test/compile-fail/borrowck-overloaded-call.rs index 938fc53d61054..de959521514b2 100644 --- a/src/test/compile-fail/borrowck-overloaded-call.rs +++ b/src/test/compile-fail/borrowck-overloaded-call.rs @@ -13,23 +13,23 @@ use std::ops::{Fn, FnMut, FnOnce}; struct SFn { - x: int, - y: int, + x: isize, + y: isize, } -impl Fn<(int,),int> for SFn { - extern "rust-call" fn call(&self, (z,): (int,)) -> int { +impl Fn<(isize,),isize> for SFn { + extern "rust-call" fn call(&self, (z,): (isize,)) -> isize { self.x * self.y * z } } struct SFnMut { - x: int, - y: int, + x: isize, + y: isize, } -impl FnMut<(int,),int> for SFnMut { - extern "rust-call" fn call_mut(&mut self, (z,): (int,)) -> int { +impl FnMut<(isize,),isize> for SFnMut { + extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize { self.x * self.y * z } } diff --git a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs index 416e67dac0ced..9193a28511e70 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs @@ -14,14 +14,14 @@ use std::ops::{Index, IndexMut}; struct Foo { - x: int, - y: int, + x: isize, + y: isize, } impl Index for Foo { - type Output = int; + type Output = isize; - fn index<'a>(&'a self, z: &String) -> &'a int { + fn index<'a>(&'a self, z: &String) -> &'a isize { if z.as_slice() == "x" { &self.x } else { @@ -31,9 +31,9 @@ impl Index for Foo { } impl IndexMut for Foo { - type Output = int; + type Output = isize; - fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize { if z.as_slice() == "x" { &mut self.x } else { diff --git a/src/test/compile-fail/borrowck-overloaded-index.rs b/src/test/compile-fail/borrowck-overloaded-index.rs index 80b68dbf519ee..ec317277e40b7 100644 --- a/src/test/compile-fail/borrowck-overloaded-index.rs +++ b/src/test/compile-fail/borrowck-overloaded-index.rs @@ -11,14 +11,14 @@ use std::ops::{Index, IndexMut}; struct Foo { - x: int, - y: int, + x: isize, + y: isize, } impl Index for Foo { - type Output = int; + type Output = isize; - fn index<'a>(&'a self, z: &String) -> &'a int { + fn index<'a>(&'a self, z: &String) -> &'a isize { if z.as_slice() == "x" { &self.x } else { @@ -28,9 +28,9 @@ impl Index for Foo { } impl IndexMut for Foo { - type Output = int; + type Output = isize; - fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut int { + fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize { if z.as_slice() == "x" { &mut self.x } else { @@ -40,13 +40,13 @@ impl IndexMut for Foo { } struct Bar { - x: int, + x: isize, } -impl Index for Bar { - type Output = int; +impl Index for Bar { + type Output = isize; - fn index<'a>(&'a self, z: &int) -> &'a int { + fn index<'a>(&'a self, z: &isize) -> &'a isize { &self.x } } diff --git a/src/test/compile-fail/borrowck-pat-reassign-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-binding.rs index f33e5e9b02d59..d176245823ef5 100644 --- a/src/test/compile-fail/borrowck-pat-reassign-binding.rs +++ b/src/test/compile-fail/borrowck-pat-reassign-binding.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut x: Option = None; + let mut x: Option = None; match x { None => { // Note: on this branch, no borrow has occurred. diff --git a/src/test/compile-fail/borrowck-reborrow-from-mut.rs b/src/test/compile-fail/borrowck-reborrow-from-mut.rs index b4bd64f213586..6f5dfa67be50d 100644 --- a/src/test/compile-fail/borrowck-reborrow-from-mut.rs +++ b/src/test/compile-fail/borrowck-reborrow-from-mut.rs @@ -14,8 +14,8 @@ struct Foo { } struct Bar { - int1: int, - int2: int, + int1: isize, + int2: isize, } fn borrow_same_field_twice_mut_mut(foo: &mut Foo) { diff --git a/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs b/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs index 05cadfd536567..eee407472bf14 100644 --- a/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs +++ b/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs @@ -12,7 +12,7 @@ // borrowed (but otherwise non-aliasable) location is illegal. struct S<'a> { - pointer: &'a mut int + pointer: &'a mut isize } fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> { diff --git a/src/test/compile-fail/borrowck-ref-mut-of-imm.rs b/src/test/compile-fail/borrowck-ref-mut-of-imm.rs index 4a34b85c3edfa..1784b72a69927 100644 --- a/src/test/compile-fail/borrowck-ref-mut-of-imm.rs +++ b/src/test/compile-fail/borrowck-ref-mut-of-imm.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn destructure(x: Option) -> int { +fn destructure(x: Option) -> isize { match x { None => 0, Some(ref mut v) => *v //~ ERROR cannot borrow diff --git a/src/test/compile-fail/borrowck-return.rs b/src/test/compile-fail/borrowck-return.rs index 6558bc579685a..74d435b35e7eb 100644 --- a/src/test/compile-fail/borrowck-return.rs +++ b/src/test/compile-fail/borrowck-return.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f() -> int { - let x: int; +fn f() -> isize { + let x: isize; return x; //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs index 98a29f01faf1c..bbfc5f89a8d7a 100644 --- a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs +++ b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs @@ -15,10 +15,10 @@ use std::marker::NoCopy as NP; -struct S { a: int, np: NP } +struct S { a: isize, np: NP } impl Drop for S { fn drop(&mut self) { } } -struct T { a: int, mv: Box } +struct T { a: isize, mv: Box } impl Drop for T { fn drop(&mut self) { } } fn f(s0:S) { diff --git a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs index 3e8a0f87659dd..0102a90918846 100644 --- a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs @@ -15,9 +15,9 @@ use std::mem::swap; -fn foo<'a>(mut t0: &'a mut int, - mut t1: &'a mut int) { - let p: &int = &*t0; // Freezes `*t0` +fn foo<'a>(mut t0: &'a mut isize, + mut t1: &'a mut isize) { + let p: &isize = &*t0; // Freezes `*t0` swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0` *t1 = 22; } diff --git a/src/test/compile-fail/borrowck-unary-move.rs b/src/test/compile-fail/borrowck-unary-move.rs index 72941f7721044..5b5c5f4da912c 100644 --- a/src/test/compile-fail/borrowck-unary-move.rs +++ b/src/test/compile-fail/borrowck-unary-move.rs @@ -9,13 +9,13 @@ // except according to those terms. -fn foo(x: Box) -> int { +fn foo(x: Box) -> isize { let y = &*x; free(x); //~ ERROR cannot move out of `x` because it is borrowed *y } -fn free(_x: Box) { +fn free(_x: Box) { } fn main() { diff --git a/src/test/compile-fail/borrowck-unboxed-closures.rs b/src/test/compile-fail/borrowck-unboxed-closures.rs index cca3dcb8b34db..8e7e2e3e77782 100644 --- a/src/test/compile-fail/borrowck-unboxed-closures.rs +++ b/src/test/compile-fail/borrowck-unboxed-closures.rs @@ -10,17 +10,17 @@ #![feature(overloaded_calls, unboxed_closures)] -fn a int>(mut f: F) { +fn a isize>(mut f: F) { let g = &mut f; f(1, 2); //~ ERROR cannot borrow `f` as immutable //~^ ERROR cannot borrow `f` as immutable } -fn b int>(f: F) { +fn b isize>(f: F) { f(1, 2); //~ ERROR cannot borrow immutable local variable } -fn c int>(f: F) { +fn c isize>(f: F) { f(1, 2); f(1, 2); //~ ERROR use of moved value } diff --git a/src/test/compile-fail/borrowck-uninit-after-item.rs b/src/test/compile-fail/borrowck-uninit-after-item.rs index a828b1d6b9f52..acd827d6c620b 100644 --- a/src/test/compile-fail/borrowck-uninit-after-item.rs +++ b/src/test/compile-fail/borrowck-uninit-after-item.rs @@ -10,6 +10,6 @@ fn main() { let bar; - fn baz(_x: int) { } + fn baz(_x: isize) { } baz(bar); //~ ERROR use of possibly uninitialized variable: `bar` } diff --git a/src/test/compile-fail/borrowck-uninit-in-assignop.rs b/src/test/compile-fail/borrowck-uninit-in-assignop.rs index b5e462e592a76..e253ecc74b9a5 100644 --- a/src/test/compile-fail/borrowck-uninit-in-assignop.rs +++ b/src/test/compile-fail/borrowck-uninit-in-assignop.rs @@ -12,33 +12,33 @@ // expression is detected. pub fn main() { - let x: int; + let x: isize; x += 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x -= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x *= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x /= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x %= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x ^= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x &= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x |= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x <<= 1; //~ ERROR use of possibly uninitialized variable: `x` - let x: int; + let x: isize; x >>= 1; //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/borrowck-uninit.rs b/src/test/compile-fail/borrowck-uninit.rs index a64216df6c7fe..f4b73bc889fb7 100644 --- a/src/test/compile-fail/borrowck-uninit.rs +++ b/src/test/compile-fail/borrowck-uninit.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { println!("{}", x); } +fn foo(x: isize) { println!("{}", x); } fn main() { - let x: int; + let x: isize; foo(x); //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs index b0e8b2a523bd8..9c14a6990323a 100644 --- a/src/test/compile-fail/borrowck-uniq-via-lend.rs +++ b/src/test/compile-fail/borrowck-uniq-via-lend.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn borrow(_v: &int) {} +fn borrow(_v: &isize) {} fn local() { let mut v = box 3i; @@ -18,7 +18,7 @@ fn local() { } fn local_rec() { - struct F { f: Box } + struct F { f: Box } let mut v = F {f: box 3}; borrow(&*v.f); } @@ -26,7 +26,7 @@ fn local_rec() { fn local_recs() { struct F { f: G } struct G { g: H } - struct H { h: Box } + struct H { h: Box } let mut v = F {f: G {g: H {h: box 3}}}; borrow(&*v.f.g.h); } diff --git a/src/test/compile-fail/borrowck-use-in-index-lvalue.rs b/src/test/compile-fail/borrowck-use-in-index-lvalue.rs index 3cd582ca0b8c3..94c1d3a6a4505 100644 --- a/src/test/compile-fail/borrowck-use-in-index-lvalue.rs +++ b/src/test/compile-fail/borrowck-use-in-index-lvalue.rs @@ -9,10 +9,10 @@ // except according to those terms. fn test() { - let w: &mut [int]; + let w: &mut [isize]; w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w` - let mut w: &mut [int]; + let mut w: &mut [isize]; w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w` } diff --git a/src/test/compile-fail/borrowck-use-mut-borrow.rs b/src/test/compile-fail/borrowck-use-mut-borrow.rs index 45813c45f0365..42e12622b6920 100644 --- a/src/test/compile-fail/borrowck-use-mut-borrow.rs +++ b/src/test/compile-fail/borrowck-use-mut-borrow.rs @@ -10,14 +10,14 @@ #![feature(box_syntax)] -struct A { a: int, b: int } +struct A { a: isize, b: isize } impl Copy for A {} -struct B { a: int, b: Box } +struct B { a: isize, b: Box } fn var_copy_after_var_borrow() { - let mut x: int = 1; + let mut x: isize = 1; let p = &mut x; drop(x); //~ ERROR cannot use `x` because it was mutably borrowed *p = 2; @@ -61,7 +61,7 @@ fn fu_field_copy_after_field_borrow() { } fn var_deref_after_var_borrow() { - let mut x: Box = box 1; + let mut x: Box = box 1; let p = &mut x; drop(*x); //~ ERROR cannot use `*x` because it was mutably borrowed **p = 2; diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index 4a5418a4f20c2..577334cce9504 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -10,9 +10,9 @@ #![feature(advanced_slice_patterns)] -fn a<'a>() -> &'a [int] { +fn a<'a>() -> &'a [isize] { let vec = vec!(1, 2, 3, 4); - let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough + let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough let tail = match vec { [_, tail..] => tail, _ => panic!("a") @@ -20,9 +20,9 @@ fn a<'a>() -> &'a [int] { tail } -fn b<'a>() -> &'a [int] { +fn b<'a>() -> &'a [isize] { let vec = vec!(1, 2, 3, 4); - let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough + let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough let init = match vec { [init.., _] => init, _ => panic!("b") @@ -30,9 +30,9 @@ fn b<'a>() -> &'a [int] { init } -fn c<'a>() -> &'a [int] { +fn c<'a>() -> &'a [isize] { let vec = vec!(1, 2, 3, 4); - let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough + let vec: &[isize] = vec.as_slice(); //~ ERROR does not live long enough let slice = match vec { [_, slice.., _] => slice, _ => panic!("c") diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs index cc1dbc8195543..565b8ca2f6856 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs @@ -10,7 +10,7 @@ fn a() { let mut v = vec!(1, 2, 3); - let vb: &mut [int] = v.as_mut_slice(); + let vb: &mut [isize] = v.as_mut_slice(); match vb { [_a, tail..] => { v.push(tail[0] + tail[1]); //~ ERROR cannot borrow diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index c0abc3a25606a..98a511f090090 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -22,7 +22,7 @@ fn a() { fn b() { let mut vec = vec!(box 1i, box 2, box 3); - let vec: &mut [Box] = vec.as_mut_slice(); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_b..] => { vec[0] = box 4; //~ ERROR cannot assign @@ -32,7 +32,7 @@ fn b() { fn c() { let mut vec = vec!(box 1i, box 2, box 3); - let vec: &mut [Box] = vec.as_mut_slice(); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, //~ ERROR cannot move out _b..] => { //~^ NOTE attempting to move value to here @@ -50,7 +50,7 @@ fn c() { fn d() { let mut vec = vec!(box 1i, box 2, box 3); - let vec: &mut [Box] = vec.as_mut_slice(); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a.., //~ ERROR cannot move out _b] => {} //~ NOTE attempting to move value to here @@ -61,7 +61,7 @@ fn d() { fn e() { let mut vec = vec!(box 1i, box 2, box 3); - let vec: &mut [Box] = vec.as_mut_slice(); + let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, _b, _c] => {} //~ ERROR cannot move out //~^ NOTE attempting to move value to here diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index 852eb172c59d1..bcd1aa81d4c2e 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a<'a>() -> &'a int { +fn a<'a>() -> &'a isize { let vec = vec!(1, 2, 3, 4); - let vec: &[int] = vec.as_slice(); //~ ERROR `vec` does not live long enough + let vec: &[isize] = vec.as_slice(); //~ ERROR `vec` does not live long enough let tail = match vec { [_a, tail..] => &tail[0], _ => panic!("foo") diff --git a/src/test/compile-fail/borrowck-while.rs b/src/test/compile-fail/borrowck-while.rs index b5703e56642ad..17eb19a44e6eb 100644 --- a/src/test/compile-fail/borrowck-while.rs +++ b/src/test/compile-fail/borrowck-while.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f() -> int { - let mut x: int; +fn f() -> isize { + let mut x: isize; while 1i == 1 { x = 10; } return x; //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/capture1.rs b/src/test/compile-fail/capture1.rs index 7d590ca49ddca..fd50918a313e2 100644 --- a/src/test/compile-fail/capture1.rs +++ b/src/test/compile-fail/capture1.rs @@ -12,6 +12,6 @@ // error-pattern: can't capture dynamic environment in a fn item; fn main() { - let bar: int = 5; - fn foo() -> int { return bar; } + let bar: isize = 5; + fn foo() -> isize { return bar; } } diff --git a/src/test/compile-fail/cast-to-bare-fn.rs b/src/test/compile-fail/cast-to-bare-fn.rs index 1db813292b012..a7f0917ed86b9 100644 --- a/src/test/compile-fail/cast-to-bare-fn.rs +++ b/src/test/compile-fail/cast-to-bare-fn.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(_x: int) { } +fn foo(_x: isize) { } fn main() { let v: u64 = 5; - let x = foo as extern "C" fn() -> int; + let x = foo as extern "C" fn() -> isize; //~^ ERROR mismatched types - let y = v as extern "Rust" fn(int) -> (int, int); + let y = v as extern "Rust" fn(isize) -> (isize, isize); //~^ ERROR non-scalar cast y(x()); } diff --git a/src/test/compile-fail/check-static-immutable-mut-slices.rs b/src/test/compile-fail/check-static-immutable-mut-slices.rs index 2945a05024792..d1e3fe252537d 100644 --- a/src/test/compile-fail/check-static-immutable-mut-slices.rs +++ b/src/test/compile-fail/check-static-immutable-mut-slices.rs @@ -10,7 +10,7 @@ // Checks that immutable static items can't have mutable slices -static TEST: &'static mut [int] = &mut []; +static TEST: &'static mut [isize] = &mut []; //~^ ERROR statics are not allowed to have mutable references pub fn main() { } diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index c13faacfee443..7c4f9ada2d35e 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -26,7 +26,7 @@ impl Drop for WithDtor { // 3. Expr calls with unsafe arguments for statics are rejected enum SafeEnum { Variant1, - Variant2(int), + Variant2(isize), Variant3(WithDtor), Variant4(String) } @@ -45,7 +45,7 @@ static STATIC3: SafeEnum = SafeEnum::Variant3(WithDtor); // a destructor. enum UnsafeEnum { Variant5, - Variant6(int) + Variant6(isize) } impl Drop for UnsafeEnum { @@ -132,11 +132,11 @@ static STATIC16: (&'static Box, &'static Box) = ( static mut STATIC17: SafeEnum = SafeEnum::Variant1; //~^ ERROR mutable statics are not allowed to have destructors -static STATIC19: Box = +static STATIC19: Box = box 3; //~^ ERROR statics are not allowed to have custom pointers pub fn main() { - let y = { static x: Box = box 3; x }; + let y = { static x: Box = box 3; x }; //~^ ERROR statics are not allowed to have custom pointers } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 25abd904d21cc..c64112d5dfd8d 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -17,7 +17,7 @@ trait noisy { struct cat { meows : uint, - how_hungry : int, + how_hungry : isize, name : String, } @@ -50,7 +50,7 @@ impl cat { } } -fn cat(in_x : uint, in_y : int, in_name: String) -> cat { +fn cat(in_x : uint, in_y : isize, in_name: String) -> cat { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/compile-fail/coherence-all-remote.rs b/src/test/compile-fail/coherence-all-remote.rs index d86256a77765e..f8ddf83c9c637 100644 --- a/src/test/compile-fail/coherence-all-remote.rs +++ b/src/test/compile-fail/coherence-all-remote.rs @@ -13,7 +13,7 @@ extern crate "coherence-lib" as lib; use lib::Remote1; -impl Remote1 for int { } +impl Remote1 for isize { } //~^ ERROR E0117 fn main() { } diff --git a/src/test/compile-fail/coherence-bigint-int.rs b/src/test/compile-fail/coherence-bigint-int.rs index b4917d0c29f37..684773098cd95 100644 --- a/src/test/compile-fail/coherence-bigint-int.rs +++ b/src/test/compile-fail/coherence-bigint-int.rs @@ -15,6 +15,6 @@ use lib::Remote1; pub struct BigInt; -impl Remote1 for int { } //~ ERROR E0117 +impl Remote1 for isize { } //~ ERROR E0117 fn main() { } diff --git a/src/test/compile-fail/coherence-bigint-vecint.rs b/src/test/compile-fail/coherence-bigint-vecint.rs index de4e656110f29..28747674b8b10 100644 --- a/src/test/compile-fail/coherence-bigint-vecint.rs +++ b/src/test/compile-fail/coherence-bigint-vecint.rs @@ -15,6 +15,6 @@ use lib::Remote1; pub struct BigInt; -impl Remote1 for Vec { } //~ ERROR E0117 +impl Remote1 for Vec { } //~ ERROR E0117 fn main() { } diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs index c0d82d35e30f4..1372d9930ee35 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs @@ -23,7 +23,7 @@ trait Even { } trait Odd { } -impl Even for int { } +impl Even for isize { } impl Odd for uint { } diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-cross-crate.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-cross-crate.rs index 2e163bc11a804..1f6bb08871c76 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-cross-crate.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-cross-crate.rs @@ -19,11 +19,11 @@ use std::default::Default; struct MyThingy; impl Go for MyThingy { - fn go(&self, arg: int) { } + fn go(&self, arg: isize) { } } impl GoMut for MyThingy { //~ ERROR conflicting implementations - fn go_mut(&mut self, arg: int) { } + fn go_mut(&mut self, arg: isize) { } } fn main() { } diff --git a/src/test/compile-fail/coherence-orphan.rs b/src/test/compile-fail/coherence-orphan.rs index 30a382c143dab..568a35cc58963 100644 --- a/src/test/compile-fail/coherence-orphan.rs +++ b/src/test/compile-fail/coherence-orphan.rs @@ -16,10 +16,10 @@ use lib::TheTrait; struct TheType; -impl TheTrait for int { } //~ ERROR E0117 +impl TheTrait for isize { } //~ ERROR E0117 -impl TheTrait for int { } //~ ERROR E0117 +impl TheTrait for isize { } //~ ERROR E0117 -impl TheTrait for TheType { } +impl TheTrait for TheType { } fn main() { } diff --git a/src/test/compile-fail/comm-not-freeze-receiver.rs b/src/test/compile-fail/comm-not-freeze-receiver.rs index a7962c09fb3b9..305acfec40114 100644 --- a/src/test/compile-fail/comm-not-freeze-receiver.rs +++ b/src/test/compile-fail/comm-not-freeze-receiver.rs @@ -13,5 +13,5 @@ use std::sync::mpsc::Receiver; fn test() {} fn main() { - test::>(); //~ ERROR: `core::marker::Sync` is not implemented + test::>(); //~ ERROR: `core::marker::Sync` is not implemented } diff --git a/src/test/compile-fail/comm-not-freeze.rs b/src/test/compile-fail/comm-not-freeze.rs index 1977438d42320..de2c96920c38b 100644 --- a/src/test/compile-fail/comm-not-freeze.rs +++ b/src/test/compile-fail/comm-not-freeze.rs @@ -13,5 +13,5 @@ use std::sync::mpsc::Sender; fn test() {} fn main() { - test::>(); //~ ERROR: `core::marker::Sync` is not implemented + test::>(); //~ ERROR: `core::marker::Sync` is not implemented } diff --git a/src/test/compile-fail/const-recursive.rs b/src/test/compile-fail/const-recursive.rs index 9c633e082b194..ad05c7c423f95 100644 --- a/src/test/compile-fail/const-recursive.rs +++ b/src/test/compile-fail/const-recursive.rs @@ -9,8 +9,8 @@ // except according to those terms. // error-pattern: recursive constant -static a: int = b; -static b: int = a; +static a: isize = b; +static b: isize = a; fn main() { } diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs index 01c6970506cd3..1201db437b961 100644 --- a/src/test/compile-fail/copy-a-resource.rs +++ b/src/test/compile-fail/copy-a-resource.rs @@ -10,14 +10,14 @@ #[derive(Show)] struct foo { - i: int, + i: isize, } impl Drop for foo { fn drop(&mut self) {} } -fn foo(i:int) -> foo { +fn foo(i:isize) -> foo { foo { i: i } diff --git a/src/test/compile-fail/deriving-primitive.rs b/src/test/compile-fail/deriving-primitive.rs index a3c6c8672c837..901f0c58f458d 100644 --- a/src/test/compile-fail/deriving-primitive.rs +++ b/src/test/compile-fail/deriving-primitive.rs @@ -9,25 +9,25 @@ // except according to those terms. use std::num::FromPrimitive; -use std::int; +use std::isize; #[derive(FromPrimitive)] -struct A { x: int } +struct A { x: isize } //~^^ ERROR `FromPrimitive` cannot be derived for structs //~^^^ ERROR `FromPrimitive` cannot be derived for structs #[derive(FromPrimitive)] -struct B(int); +struct B(isize); //~^^ ERROR `FromPrimitive` cannot be derived for structs //~^^^ ERROR `FromPrimitive` cannot be derived for structs #[derive(FromPrimitive)] -enum C { Foo(int), Bar(uint) } +enum C { Foo(isize), Bar(uint) } //~^^ ERROR `FromPrimitive` cannot be derived for enum variants with arguments //~^^^ ERROR `FromPrimitive` cannot be derived for enum variants with arguments #[derive(FromPrimitive)] -enum D { Baz { x: int } } +enum D { Baz { x: isize } } //~^^ ERROR `FromPrimitive` cannot be derived for enums with struct variants //~^^^ ERROR `FromPrimitive` cannot be derived for enums with struct variants diff --git a/src/test/compile-fail/destructure-trait-ref.rs b/src/test/compile-fail/destructure-trait-ref.rs index 0351040d329c4..89062576a50ad 100644 --- a/src/test/compile-fail/destructure-trait-ref.rs +++ b/src/test/compile-fail/destructure-trait-ref.rs @@ -14,7 +14,7 @@ #![feature(box_syntax)] trait T {} -impl T for int {} +impl T for isize {} fn main() { // For an expression of the form: diff --git a/src/test/compile-fail/drop-on-non-struct.rs b/src/test/compile-fail/drop-on-non-struct.rs index 8d2ca0b0a6b66..26b247d0d0f2e 100644 --- a/src/test/compile-fail/drop-on-non-struct.rs +++ b/src/test/compile-fail/drop-on-non-struct.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -impl<'a> Drop for &'a mut int { +impl<'a> Drop for &'a mut isize { //~^ ERROR the Drop trait may only be implemented on structures //~^^ ERROR E0117 fn drop(&mut self) { diff --git a/src/test/compile-fail/dst-bad-assign-2.rs b/src/test/compile-fail/dst-bad-assign-2.rs index 6c40ca558de11..7dbb8fc92e345 100644 --- a/src/test/compile-fail/dst-bad-assign-2.rs +++ b/src/test/compile-fail/dst-bad-assign-2.rs @@ -13,7 +13,7 @@ #![feature(box_syntax)] struct Fat { - f1: int, + f1: isize, f2: &'static str, ptr: T } @@ -23,19 +23,19 @@ struct Bar; #[derive(PartialEq,Eq)] struct Bar1 { - f: int + f: isize } trait ToBar { fn to_bar(&self) -> Bar; - fn to_val(&self) -> int; + fn to_val(&self) -> isize; } impl ToBar for Bar1 { fn to_bar(&self) -> Bar { Bar } - fn to_val(&self) -> int { + fn to_val(&self) -> isize { self.f } } diff --git a/src/test/compile-fail/dst-bad-assign.rs b/src/test/compile-fail/dst-bad-assign.rs index 78f70b9add051..634b5999e9ef2 100644 --- a/src/test/compile-fail/dst-bad-assign.rs +++ b/src/test/compile-fail/dst-bad-assign.rs @@ -13,7 +13,7 @@ #![feature(box_syntax)] struct Fat { - f1: int, + f1: isize, f2: &'static str, ptr: T } @@ -23,19 +23,19 @@ struct Bar; #[derive(PartialEq,Eq)] struct Bar1 { - f: int + f: isize } trait ToBar { fn to_bar(&self) -> Bar; - fn to_val(&self) -> int; + fn to_val(&self) -> isize; } impl ToBar for Bar1 { fn to_bar(&self) -> Bar { Bar } - fn to_val(&self) -> int { + fn to_val(&self) -> isize { self.f } } diff --git a/src/test/compile-fail/dst-bad-coerce2.rs b/src/test/compile-fail/dst-bad-coerce2.rs index 54c625221ba7d..160197368d6d9 100644 --- a/src/test/compile-fail/dst-bad-coerce2.rs +++ b/src/test/compile-fail/dst-bad-coerce2.rs @@ -21,8 +21,8 @@ impl Bar for Foo {} pub fn main() { // With a vec of ints. let f1 = Fat { ptr: [1, 2, 3] }; - let f2: &Fat<[int; 3]> = &f1; - let f3: &mut Fat<[int]> = f2; //~ ERROR mismatched types + let f2: &Fat<[isize; 3]> = &f1; + let f3: &mut Fat<[isize]> = f2; //~ ERROR mismatched types // With a trait. let f1 = Fat { ptr: Foo }; diff --git a/src/test/compile-fail/dst-bad-coerce3.rs b/src/test/compile-fail/dst-bad-coerce3.rs index 192d43e32fd27..347a2d2ecbe68 100644 --- a/src/test/compile-fail/dst-bad-coerce3.rs +++ b/src/test/compile-fail/dst-bad-coerce3.rs @@ -21,8 +21,8 @@ impl Bar for Foo {} fn baz<'a>() { // With a vec of ints. let f1 = Fat { ptr: [1, 2, 3] }; - let f2: &Fat<[int; 3]> = &f1; //~ ERROR `f1` does not live long enough - let f3: &'a Fat<[int]> = f2; + let f2: &Fat<[isize; 3]> = &f1; //~ ERROR `f1` does not live long enough + let f3: &'a Fat<[isize]> = f2; // With a trait. let f1 = Fat { ptr: Foo }; diff --git a/src/test/compile-fail/dst-bad-deep.rs b/src/test/compile-fail/dst-bad-deep.rs index 0276e2e418df8..354898f6cf0ec 100644 --- a/src/test/compile-fail/dst-bad-deep.rs +++ b/src/test/compile-fail/dst-bad-deep.rs @@ -18,8 +18,8 @@ struct Fat { } pub fn main() { - let f: Fat<[int; 3]> = Fat { ptr: [5i, 6, 7] }; - let g: &Fat<[int]> = &f; - let h: &Fat> = &Fat { ptr: *g }; + let f: Fat<[isize; 3]> = Fat { ptr: [5i, 6, 7] }; + let g: &Fat<[isize]> = &f; + let h: &Fat> = &Fat { ptr: *g }; //~^ ERROR the trait `core::marker::Sized` is not implemented } diff --git a/src/test/compile-fail/dst-rvalue.rs b/src/test/compile-fail/dst-rvalue.rs index 74e952364cd45..6e33fdf3f7bd0 100644 --- a/src/test/compile-fail/dst-rvalue.rs +++ b/src/test/compile-fail/dst-rvalue.rs @@ -17,8 +17,8 @@ pub fn main() { //~^ ERROR E0161 //~^^ ERROR cannot move out of dereference - let array: &[int] = &[1, 2, 3]; - let _x: Box<[int]> = box *array; + let array: &[isize] = &[1, 2, 3]; + let _x: Box<[isize]> = box *array; //~^ ERROR E0161 //~^^ ERROR cannot move out of dereference } diff --git a/src/test/compile-fail/duplicate-parameter.rs b/src/test/compile-fail/duplicate-parameter.rs index c1c0f974de9e5..18ec55e10bb9a 100644 --- a/src/test/compile-fail/duplicate-parameter.rs +++ b/src/test/compile-fail/duplicate-parameter.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(a: int, a: int) {} +fn f(a: isize, a: isize) {} //~^ ERROR identifier `a` is bound more than once in this parameter list fn main() { diff --git a/src/test/compile-fail/enum-and-module-in-same-scope.rs b/src/test/compile-fail/enum-and-module-in-same-scope.rs index 7526c6753e632..f3d8fcf31d76c 100644 --- a/src/test/compile-fail/enum-and-module-in-same-scope.rs +++ b/src/test/compile-fail/enum-and-module-in-same-scope.rs @@ -9,7 +9,7 @@ // except according to those terms. mod Foo { - pub static X: int = 42; + pub static X: isize = 42; } enum Foo { //~ ERROR duplicate definition of type or module `Foo` diff --git a/src/test/compile-fail/enum-discrim-too-small.rs b/src/test/compile-fail/enum-discrim-too-small.rs index 2de50ad1d1d0d..55e9b6d6ece9c 100644 --- a/src/test/compile-fail/enum-discrim-too-small.rs +++ b/src/test/compile-fail/enum-discrim-too-small.rs @@ -53,6 +53,6 @@ enum Ei32 { // u64 currently allows negative numbers, and i64 allows numbers greater than `1<<63`. This is a // little counterintuitive, but since the discriminant can store all the bits, and extracting it // with a cast requires specifying the signedness, there is no loss of information in those cases. -// This also applies to int and uint on 64-bit targets. +// This also applies to isize and uint on 64-bit targets. pub fn main() { } diff --git a/src/test/compile-fail/enum-in-scope.rs b/src/test/compile-fail/enum-in-scope.rs index cccf66ef2d54e..7be06ec7de812 100644 --- a/src/test/compile-fail/enum-in-scope.rs +++ b/src/test/compile-fail/enum-in-scope.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct hello(int); +struct hello(isize); fn main() { let hello = 0; //~ERROR declaration of `hello` shadows diff --git a/src/test/compile-fail/explicit-call-to-dtor.rs b/src/test/compile-fail/explicit-call-to-dtor.rs index 6b334dd6ecdfc..90030488dd60b 100644 --- a/src/test/compile-fail/explicit-call-to-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-dtor.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int + x: isize } impl Drop for Foo { diff --git a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs index d0dd0e68da6bd..63ed74dfa490e 100644 --- a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int + x: isize } trait Bar : Drop { diff --git a/src/test/compile-fail/explicit-self-lifetime-mismatch.rs b/src/test/compile-fail/explicit-self-lifetime-mismatch.rs index 9b2264b8902a3..fbc5263d82d10 100644 --- a/src/test/compile-fail/explicit-self-lifetime-mismatch.rs +++ b/src/test/compile-fail/explicit-self-lifetime-mismatch.rs @@ -9,8 +9,8 @@ // except according to those terms. struct Foo<'a,'b> { - x: &'a int, - y: &'b int, + x: &'a isize, + y: &'b isize, } impl<'a,'b> Foo<'a,'b> { diff --git a/src/test/compile-fail/export.rs b/src/test/compile-fail/export.rs index dec65d4b4f87e..3a391e7c609ff 100644 --- a/src/test/compile-fail/export.rs +++ b/src/test/compile-fail/export.rs @@ -10,8 +10,8 @@ // error-pattern: unresolved name mod foo { - pub fn x(y: int) { log(debug, y); } - fn z(y: int) { log(debug, y); } + pub fn x(y: isize) { log(debug, y); } + fn z(y: isize) { log(debug, y); } } fn main() { foo::z(10); } diff --git a/src/test/compile-fail/feature-gate-int-uint.rs b/src/test/compile-fail/feature-gate-int-uint.rs index 78b931b383f90..668c9980a2edd 100644 --- a/src/test/compile-fail/feature-gate-int-uint.rs +++ b/src/test/compile-fail/feature-gate-int-uint.rs @@ -20,11 +20,11 @@ mod u { } } mod i { - type X = int; //~ WARN the `int` type is deprecated + type X = isize; //~ WARN the `isize` type is deprecated struct Foo { - x: int //~ WARN the `int` type is deprecated + x: isize //~ WARN the `isize` type is deprecated } - fn bar(x: int) { //~ WARN the `int` type is deprecated + fn bar(x: isize) { //~ WARN the `isize` type is deprecated 1i; //~ WARN the `u` suffix on integers is deprecated } } diff --git a/src/test/compile-fail/fn-bad-block-type.rs b/src/test/compile-fail/fn-bad-block-type.rs index ba568ef5f843d..c5c355cfbce84 100644 --- a/src/test/compile-fail/fn-bad-block-type.rs +++ b/src/test/compile-fail/fn-bad-block-type.rs @@ -10,6 +10,6 @@ // error-pattern:mismatched types -fn f() -> int { true } +fn f() -> isize { true } fn main() { } diff --git a/src/test/compile-fail/fn-item-type.rs b/src/test/compile-fail/fn-item-type.rs index dd4a24bfb2fdc..b2394a29899e7 100644 --- a/src/test/compile-fail/fn-item-type.rs +++ b/src/test/compile-fail/fn-item-type.rs @@ -11,8 +11,8 @@ // Test that the types of distinct fn items are not compatible by // default. See also `run-pass/fn-item-type-*.rs`. -fn foo(x: int) -> int { x * 2 } -fn bar(x: int) -> int { x * 4 } +fn foo(x: isize) -> isize { x * 2 } +fn bar(x: isize) -> isize { x * 4 } fn eq(x: T, y: T) { } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index 039628b675282..838e65e1d0574 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn takes_imm(x: &int) { } +fn takes_imm(x: &isize) { } -fn takes_mut(x: &mut int) { } +fn takes_mut(x: &mut isize) { } fn apply(t: T, f: F) where F: FnOnce(T) { f(t) diff --git a/src/test/compile-fail/for-loop-bogosity.rs b/src/test/compile-fail/for-loop-bogosity.rs index 67d07ca4bd1fb..fd920f923944d 100644 --- a/src/test/compile-fail/for-loop-bogosity.rs +++ b/src/test/compile-fail/for-loop-bogosity.rs @@ -9,12 +9,12 @@ // except according to those terms. struct MyStruct { - x: int, - y: int, + x: isize, + y: isize, } impl MyStruct { - fn next(&mut self) -> Option { + fn next(&mut self) -> Option { Some(self.x) } } diff --git a/src/test/compile-fail/forget-init-unsafe.rs b/src/test/compile-fail/forget-init-unsafe.rs index 12df0c71cc57e..46a18c981835b 100644 --- a/src/test/compile-fail/forget-init-unsafe.rs +++ b/src/test/compile-fail/forget-init-unsafe.rs @@ -12,6 +12,6 @@ use std::intrinsics::{init, forget}; // Test that the `forget` and `init` intrinsics are really unsafe pub fn main() { - let stuff = init::(); //~ ERROR call to unsafe function requires unsafe + let stuff = init::(); //~ ERROR call to unsafe function requires unsafe forget(stuff); //~ ERROR call to unsafe function requires unsafe } diff --git a/src/test/compile-fail/fully-qualified-type-name3.rs b/src/test/compile-fail/fully-qualified-type-name3.rs index 0a5a54b9a275a..c69c30216f9e1 100644 --- a/src/test/compile-fail/fully-qualified-type-name3.rs +++ b/src/test/compile-fail/fully-qualified-type-name3.rs @@ -13,7 +13,7 @@ // ignore-test type T1 = uint; -type T2 = int; +type T2 = isize; fn bar(x: T1) -> T2 { return x; diff --git a/src/test/compile-fail/functional-struct-update-noncopyable.rs b/src/test/compile-fail/functional-struct-update-noncopyable.rs index da246f85c43e3..7ce32bbc975c6 100644 --- a/src/test/compile-fail/functional-struct-update-noncopyable.rs +++ b/src/test/compile-fail/functional-struct-update-noncopyable.rs @@ -12,7 +12,7 @@ use std::sync::Arc; -struct A { y: Arc, x: Arc } +struct A { y: Arc, x: Arc } impl Drop for A { fn drop(&mut self) { println!("x={}", *self.x); } diff --git a/src/test/compile-fail/gated-non-ascii-idents.rs b/src/test/compile-fail/gated-non-ascii-idents.rs index 4cbb61d9853b0..f4b9830d579a4 100644 --- a/src/test/compile-fail/gated-non-ascii-idents.rs +++ b/src/test/compile-fail/gated-non-ascii-idents.rs @@ -17,9 +17,9 @@ mod föö { //~ ERROR non-ascii idents } fn bär( //~ ERROR non-ascii idents - bäz: int //~ ERROR non-ascii idents + bäz: isize //~ ERROR non-ascii idents ) { - let _ö: int; //~ ERROR non-ascii idents + let _ö: isize; //~ ERROR non-ascii idents match (1, 2) { (_ä, _) => {} //~ ERROR non-ascii idents @@ -27,12 +27,12 @@ fn bär( //~ ERROR non-ascii idents } struct Föö { //~ ERROR non-ascii idents - föö: int //~ ERROR non-ascii idents + föö: isize //~ ERROR non-ascii idents } enum Bär { //~ ERROR non-ascii idents Bäz { //~ ERROR non-ascii idents - qüx: int //~ ERROR non-ascii idents + qüx: isize //~ ERROR non-ascii idents } } diff --git a/src/test/compile-fail/generic-impl-less-params-with-defaults.rs b/src/test/compile-fail/generic-impl-less-params-with-defaults.rs index a8b1911426c42..02f09749d614d 100644 --- a/src/test/compile-fail/generic-impl-less-params-with-defaults.rs +++ b/src/test/compile-fail/generic-impl-less-params-with-defaults.rs @@ -15,6 +15,6 @@ impl Foo { } fn main() { - Foo::::new(); + Foo::::new(); //~^ ERROR too few type parameters provided } diff --git a/src/test/compile-fail/generic-impl-more-params-with-defaults.rs b/src/test/compile-fail/generic-impl-more-params-with-defaults.rs index 696235333a123..d88da2625c187 100644 --- a/src/test/compile-fail/generic-impl-more-params-with-defaults.rs +++ b/src/test/compile-fail/generic-impl-more-params-with-defaults.rs @@ -17,6 +17,6 @@ impl Vec { } fn main() { - Vec::::new(); + Vec::::new(); //~^ ERROR too many type parameters provided } diff --git a/src/test/compile-fail/generic-type-more-params-with-defaults.rs b/src/test/compile-fail/generic-type-more-params-with-defaults.rs index ee3e1818779f3..19d303488acb0 100644 --- a/src/test/compile-fail/generic-type-more-params-with-defaults.rs +++ b/src/test/compile-fail/generic-type-more-params-with-defaults.rs @@ -13,6 +13,6 @@ struct Heap; struct Vec; fn main() { - let _: Vec; + let _: Vec; //~^ ERROR wrong number of type arguments: expected at most 2, found 3 } diff --git a/src/test/compile-fail/glob-resolve1.rs b/src/test/compile-fail/glob-resolve1.rs index d8258a72ce35b..fce8a07d7270d 100644 --- a/src/test/compile-fail/glob-resolve1.rs +++ b/src/test/compile-fail/glob-resolve1.rs @@ -23,7 +23,7 @@ mod bar { struct C; - type D = int; + type D = isize; } fn foo() {} diff --git a/src/test/compile-fail/hrtb-conflate-regions.rs b/src/test/compile-fail/hrtb-conflate-regions.rs index 5eb8fd6931258..3efe0501267e9 100644 --- a/src/test/compile-fail/hrtb-conflate-regions.rs +++ b/src/test/compile-fail/hrtb-conflate-regions.rs @@ -16,12 +16,12 @@ trait Foo { } fn want_foo2() - where T : for<'a,'b> Foo<(&'a int, &'b int)> + where T : for<'a,'b> Foo<(&'a isize, &'b isize)> { } fn want_foo1() - where T : for<'z> Foo<(&'z int, &'z int)> + where T : for<'z> Foo<(&'z isize, &'z isize)> { } @@ -30,7 +30,7 @@ fn want_foo1() struct SomeStruct; -impl<'a> Foo<(&'a int, &'a int)> for SomeStruct +impl<'a> Foo<(&'a isize, &'a isize)> for SomeStruct { } diff --git a/src/test/compile-fail/hrtb-higher-ranker-supertraits-transitive.rs b/src/test/compile-fail/hrtb-higher-ranker-supertraits-transitive.rs index 4199deee7b80e..249256f8e01a6 100644 --- a/src/test/compile-fail/hrtb-higher-ranker-supertraits-transitive.rs +++ b/src/test/compile-fail/hrtb-higher-ranker-supertraits-transitive.rs @@ -12,13 +12,13 @@ trait Foo<'tcx> { - fn foo(&'tcx self) -> &'tcx int; + fn foo(&'tcx self) -> &'tcx isize; } trait Bar<'ccx> : for<'tcx> Foo<'tcx> { - fn bar(&'ccx self) -> &'ccx int; + fn bar(&'ccx self) -> &'ccx isize; } trait Baz diff --git a/src/test/compile-fail/hrtb-higher-ranker-supertraits.rs b/src/test/compile-fail/hrtb-higher-ranker-supertraits.rs index 108ca1b82e0df..441ad76b6023c 100644 --- a/src/test/compile-fail/hrtb-higher-ranker-supertraits.rs +++ b/src/test/compile-fail/hrtb-higher-ranker-supertraits.rs @@ -12,13 +12,13 @@ trait Foo<'tcx> { - fn foo(&'tcx self) -> &'tcx int; + fn foo(&'tcx self) -> &'tcx isize; } trait Bar<'ccx> : for<'tcx> Foo<'tcx> { - fn bar(&'ccx self) -> &'ccx int; + fn bar(&'ccx self) -> &'ccx isize; } fn want_foo_for_some_tcx<'x,F>(f: &'x F) diff --git a/src/test/compile-fail/hrtb-identity-fn-borrows.rs b/src/test/compile-fail/hrtb-identity-fn-borrows.rs index 733a5b2a85af1..17939cf9fe026 100644 --- a/src/test/compile-fail/hrtb-identity-fn-borrows.rs +++ b/src/test/compile-fail/hrtb-identity-fn-borrows.rs @@ -16,7 +16,7 @@ trait FnLike { } fn call_repeatedly(f: F) - where F : for<'a> FnLike<&'a int, &'a int> + where F : for<'a> FnLike<&'a isize, &'a isize> { // Result is stored: cannot re-assign `x` let mut x = 3; diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 827e648cca86d..99927d8b9bf55 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -9,12 +9,12 @@ // except according to those terms. -fn f(y: Box) { +fn f(y: Box) { *y = 5; //~ ERROR cannot assign } fn g() { - let _frob = |&: q: Box| { *q = 2; }; //~ ERROR cannot assign + let _frob = |&: q: Box| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/impl-bounds-checking.rs b/src/test/compile-fail/impl-bounds-checking.rs index 69a35bcbd7b11..8c8f67e40abef 100644 --- a/src/test/compile-fail/impl-bounds-checking.rs +++ b/src/test/compile-fail/impl-bounds-checking.rs @@ -17,8 +17,8 @@ trait Getter { fn get(&self) -> T; } -impl Getter for int { //~ ERROR the trait `Clone2` is not implemented - fn get(&self) -> int { *self } +impl Getter for isize { //~ ERROR the trait `Clone2` is not implemented + fn get(&self) -> isize { *self } } fn main() { } diff --git a/src/test/compile-fail/impl-not-adjacent-to-type.rs b/src/test/compile-fail/impl-not-adjacent-to-type.rs index 7a5428d63e83f..7a7673d871d75 100644 --- a/src/test/compile-fail/impl-not-adjacent-to-type.rs +++ b/src/test/compile-fail/impl-not-adjacent-to-type.rs @@ -10,8 +10,8 @@ mod foo { pub struct Foo { - x: int, - y: int, + x: isize, + y: isize, } } diff --git a/src/test/compile-fail/impl-unused-tps.rs b/src/test/compile-fail/impl-unused-tps.rs index 99c6c6b89858c..c9399afbb93b2 100644 --- a/src/test/compile-fail/impl-unused-tps.rs +++ b/src/test/compile-fail/impl-unused-tps.rs @@ -16,19 +16,19 @@ trait Bar { type Out; } -impl Foo for [int;0] { +impl Foo for [isize;0] { // OK, T is used in `Foo`. } -impl Foo for [int;1] { +impl Foo for [isize;1] { //~^ ERROR the type parameter `U` is not constrained } -impl Foo for [int;2] where T : Bar { +impl Foo for [isize;2] where T : Bar { // OK, `U` is now constrained by the output type parameter. } -impl,U> Foo for [int;3] { +impl,U> Foo for [isize;3] { // OK, same as above but written differently. } diff --git a/src/test/compile-fail/import-shadow-1.rs b/src/test/compile-fail/import-shadow-1.rs index eac5a98140f89..503fa4eca527b 100644 --- a/src/test/compile-fail/import-shadow-1.rs +++ b/src/test/compile-fail/import-shadow-1.rs @@ -16,11 +16,11 @@ use foo::*; use bar::*; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-2.rs b/src/test/compile-fail/import-shadow-2.rs index 8b0809fd55a8a..0c107cf27f592 100644 --- a/src/test/compile-fail/import-shadow-2.rs +++ b/src/test/compile-fail/import-shadow-2.rs @@ -16,11 +16,11 @@ use foo::*; use foo::*; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-3.rs b/src/test/compile-fail/import-shadow-3.rs index cef481af6ba5f..bf90973c2857e 100644 --- a/src/test/compile-fail/import-shadow-3.rs +++ b/src/test/compile-fail/import-shadow-3.rs @@ -16,11 +16,11 @@ use foo::Baz; use bar::*; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-4.rs b/src/test/compile-fail/import-shadow-4.rs index 919eea0e04601..f21fdaae47ba0 100644 --- a/src/test/compile-fail/import-shadow-4.rs +++ b/src/test/compile-fail/import-shadow-4.rs @@ -16,11 +16,11 @@ use foo::*; use bar::Baz; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-5.rs b/src/test/compile-fail/import-shadow-5.rs index df17b7f0a2057..dc300bc7baa77 100644 --- a/src/test/compile-fail/import-shadow-5.rs +++ b/src/test/compile-fail/import-shadow-5.rs @@ -16,11 +16,11 @@ use foo::Baz; use bar::Baz; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-6.rs b/src/test/compile-fail/import-shadow-6.rs index 94269043b0205..fa3b75c70f0b6 100644 --- a/src/test/compile-fail/import-shadow-6.rs +++ b/src/test/compile-fail/import-shadow-6.rs @@ -16,11 +16,11 @@ use qux::*; use foo::*; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/import-shadow-7.rs b/src/test/compile-fail/import-shadow-7.rs index b3bac380710cd..34aba15b39228 100644 --- a/src/test/compile-fail/import-shadow-7.rs +++ b/src/test/compile-fail/import-shadow-7.rs @@ -16,11 +16,11 @@ use foo::*; use qux::*; //~ERROR a type named `Baz` has already been imported in this module mod foo { - pub type Baz = int; + pub type Baz = isize; } mod bar { - pub type Baz = int; + pub type Baz = isize; } mod qux { diff --git a/src/test/compile-fail/indexing-requires-a-uint.rs b/src/test/compile-fail/indexing-requires-a-uint.rs index e5edb2358f8e1..e40457a86c96f 100644 --- a/src/test/compile-fail/indexing-requires-a-uint.rs +++ b/src/test/compile-fail/indexing-requires-a-uint.rs @@ -20,7 +20,7 @@ fn main() { let i = 0; // i is an IntVar [0][i]; // i should be locked to uint - bar::(i); // i should not be re-coerced back to an int + bar::(i); // i should not be re-coerced back to an isize //~^ ERROR: mismatched types } diff --git a/src/test/compile-fail/infinite-tag-type-recursion.rs b/src/test/compile-fail/infinite-tag-type-recursion.rs index f8d89a8269dde..a57c015d684b6 100644 --- a/src/test/compile-fail/infinite-tag-type-recursion.rs +++ b/src/test/compile-fail/infinite-tag-type-recursion.rs @@ -11,6 +11,6 @@ // error-pattern: illegal recursive enum type; wrap the inner value in a box -enum mlist { cons(int, mlist), nil, } +enum mlist { cons(isize, mlist), nil, } fn main() { let a = mlist::cons(10, mlist::cons(11, mlist::nil)); } diff --git a/src/test/compile-fail/int-literal-too-large-span.rs b/src/test/compile-fail/int-literal-too-large-span.rs index 8a496c934b9c9..2eb66816cba36 100644 --- a/src/test/compile-fail/int-literal-too-large-span.rs +++ b/src/test/compile-fail/int-literal-too-large-span.rs @@ -11,7 +11,7 @@ // issue #17123 fn main() { - 100000000000000000000000000000000 //~ ERROR int literal is too large + 100000000000000000000000000000000 //~ ERROR isize literal is too large ; // the span shouldn't point to this. } diff --git a/src/test/compile-fail/integral-indexing.rs b/src/test/compile-fail/integral-indexing.rs index bbceb00abd39d..08a8f72a6686d 100644 --- a/src/test/compile-fail/integral-indexing.rs +++ b/src/test/compile-fail/integral-indexing.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let v: Vec = vec!(0, 1, 2, 3, 4, 5); + let v: Vec = vec!(0, 1, 2, 3, 4, 5); let s: String = "abcdef".to_string(); v.as_slice()[3u]; v.as_slice()[3]; diff --git a/src/test/compile-fail/intrinsic-return-address.rs b/src/test/compile-fail/intrinsic-return-address.rs index 9c1db4057c6cd..a80d393155539 100644 --- a/src/test/compile-fail/intrinsic-return-address.rs +++ b/src/test/compile-fail/intrinsic-return-address.rs @@ -20,7 +20,7 @@ unsafe fn f() { //~^ ERROR invalid use of `return_address` intrinsic: function does not use out pointer } -unsafe fn g() -> int { +unsafe fn g() -> isize { let _ = return_address(); //~^ ERROR invalid use of `return_address` intrinsic: function does not use out pointer 0 diff --git a/src/test/compile-fail/issue-10291.rs b/src/test/compile-fail/issue-10291.rs index 453746ffd6af1..45f6e55914a1b 100644 --- a/src/test/compile-fail/issue-10291.rs +++ b/src/test/compile-fail/issue-10291.rs @@ -10,8 +10,8 @@ #![feature(box_syntax)] -fn test<'x>(x: &'x int) { - drop:: FnMut(&'z int) -> &'z int>>(box |z| { +fn test<'x>(x: &'x isize) { + drop:: FnMut(&'z isize) -> &'z isize>>(box |z| { x //~^ ERROR cannot infer an appropriate lifetime }); diff --git a/src/test/compile-fail/issue-10392-2.rs b/src/test/compile-fail/issue-10392-2.rs index 2cbb59cc15a20..b077081c5b0c8 100644 --- a/src/test/compile-fail/issue-10392-2.rs +++ b/src/test/compile-fail/issue-10392-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct A { foo: int } +struct A { foo: isize } fn a() -> A { panic!() } diff --git a/src/test/compile-fail/issue-10392.rs b/src/test/compile-fail/issue-10392.rs index 4d0e02c6310c2..3f8d26bfec05d 100644 --- a/src/test/compile-fail/issue-10392.rs +++ b/src/test/compile-fail/issue-10392.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct A { foo: int } +struct A { foo: isize } fn a() -> A { panic!() } diff --git a/src/test/compile-fail/issue-10636-2.rs b/src/test/compile-fail/issue-10636-2.rs index 2303f858fcc76..a92ef24892432 100644 --- a/src/test/compile-fail/issue-10636-2.rs +++ b/src/test/compile-fail/issue-10636-2.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn trace_option(option: Option) { +pub fn trace_option(option: Option) { option.map(|some| 42; //~ NOTE: unclosed delimiter } //~ ERROR: incorrect close delimiter diff --git a/src/test/compile-fail/issue-10877.rs b/src/test/compile-fail/issue-10877.rs index 2a9cadf1f33ae..132298eba99e4 100644 --- a/src/test/compile-fail/issue-10877.rs +++ b/src/test/compile-fail/issue-10877.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Foo { x: int } +struct Foo { x: isize } extern { fn foo(1: ()); //~^ ERROR: patterns aren't allowed in foreign function declarations - fn bar((): int); + fn bar((): isize); //~^ ERROR: patterns aren't allowed in foreign function declarations - fn baz(Foo { x }: int); + fn baz(Foo { x }: isize); //~^ ERROR: patterns aren't allowed in foreign function declarations fn qux((x,y): ()); //~^ ERROR: patterns aren't allowed in foreign function declarations diff --git a/src/test/compile-fail/issue-11192.rs b/src/test/compile-fail/issue-11192.rs index 3784d3d6437ae..0d7a846bff633 100644 --- a/src/test/compile-fail/issue-11192.rs +++ b/src/test/compile-fail/issue-11192.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] struct Foo { - x: int + x: isize } impl Drop for Foo { diff --git a/src/test/compile-fail/issue-11714.rs b/src/test/compile-fail/issue-11714.rs index ed00d4131dbad..dd3fad978eb59 100644 --- a/src/test/compile-fail/issue-11714.rs +++ b/src/test/compile-fail/issue-11714.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn blah() -> int { //~ ERROR not all control paths return a value +fn blah() -> isize { //~ ERROR not all control paths return a value 1i ; //~ HELP consider removing this semicolon: diff --git a/src/test/compile-fail/issue-12116.rs b/src/test/compile-fail/issue-12116.rs index 8a5e8c27259da..6f75909fada78 100644 --- a/src/test/compile-fail/issue-12116.rs +++ b/src/test/compile-fail/issue-12116.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] enum IntList { - Cons(int, Box), + Cons(isize, Box), Nil } diff --git a/src/test/compile-fail/issue-12127.rs b/src/test/compile-fail/issue-12127.rs index 2d87bdaf5242e..c06082de3cd08 100644 --- a/src/test/compile-fail/issue-12127.rs +++ b/src/test/compile-fail/issue-12127.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn do_it(x: &int) { } +fn do_it(x: &isize) { } fn main() { let x = box 22; diff --git a/src/test/compile-fail/issue-12369.rs b/src/test/compile-fail/issue-12369.rs index 4522b536ffd34..0587bdf6136b8 100644 --- a/src/test/compile-fail/issue-12369.rs +++ b/src/test/compile-fail/issue-12369.rs @@ -10,7 +10,7 @@ fn main() { let sl = vec![1,2,3]; - let v: int = match sl.as_slice() { + let v: isize = match sl.as_slice() { [] => 0, [a,b,c] => 3, [a, rest..] => a, diff --git a/src/test/compile-fail/issue-12470.rs b/src/test/compile-fail/issue-12470.rs index 3187465530292..93785817e14f3 100644 --- a/src/test/compile-fail/issue-12470.rs +++ b/src/test/compile-fail/issue-12470.rs @@ -11,16 +11,16 @@ #![feature(box_syntax)] trait X { - fn get_i(&self) -> int; + fn get_i(&self) -> isize; } struct B { - i: int + i: isize } impl X for B { - fn get_i(&self) -> int { + fn get_i(&self) -> isize { self.i } } diff --git a/src/test/compile-fail/issue-12997-1.rs b/src/test/compile-fail/issue-12997-1.rs index 193cbcb25b74d..2d8d7857c99fb 100644 --- a/src/test/compile-fail/issue-12997-1.rs +++ b/src/test/compile-fail/issue-12997-1.rs @@ -16,4 +16,4 @@ fn foo() { } //~ ERROR functions used as benches #[bench] -fn bar(x: int, y: int) { } //~ ERROR functions used as benches +fn bar(x: isize, y: isize) { } //~ ERROR functions used as benches diff --git a/src/test/compile-fail/issue-13359.rs b/src/test/compile-fail/issue-13359.rs index 25e64e070f40b..607874de49d70 100644 --- a/src/test/compile-fail/issue-13359.rs +++ b/src/test/compile-fail/issue-13359.rs @@ -13,7 +13,7 @@ fn foo(_s: i16) { } fn bar(_s: u32) { } fn main() { - foo(1*(1 as int)); + foo(1*(1 as isize)); //~^ ERROR: mismatched types: expected `i16`, found `isize` (expected i16, found isize) bar(1*(1 as uint)); diff --git a/src/test/compile-fail/issue-13853-4.rs b/src/test/compile-fail/issue-13853-4.rs index 7d653f5ab9e29..b0db9e58dba31 100644 --- a/src/test/compile-fail/issue-13853-4.rs +++ b/src/test/compile-fail/issue-13853-4.rs @@ -9,7 +9,7 @@ // except according to those terms. struct AutoBuilder<'a> { - context: &'a int + context: &'a isize } impl<'a> Drop for AutoBuilder<'a> { diff --git a/src/test/compile-fail/issue-14182.rs b/src/test/compile-fail/issue-14182.rs index 5033576a23482..364951a4feafb 100644 --- a/src/test/compile-fail/issue-14182.rs +++ b/src/test/compile-fail/issue-14182.rs @@ -11,8 +11,8 @@ // ignore-test FIXME(japari) remove test struct Foo { - f: for <'b> |&'b int|: - 'b -> &'b int //~ ERROR use of undeclared lifetime name `'b` + f: for <'b> |&'b isize|: + 'b -> &'b isize //~ ERROR use of undeclared lifetime name `'b` } fn main() { diff --git a/src/test/compile-fail/issue-14254.rs b/src/test/compile-fail/issue-14254.rs index dc19b9d51c8c4..74eea0c57a01a 100644 --- a/src/test/compile-fail/issue-14254.rs +++ b/src/test/compile-fail/issue-14254.rs @@ -15,7 +15,7 @@ trait Foo { } struct BarTy { - x : int, + x : isize, y : f64, } @@ -76,7 +76,7 @@ impl Foo for Box { } } -impl Foo for *const int { +impl Foo for *const isize { fn bar(&self) { baz(); //~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`? @@ -85,7 +85,7 @@ impl Foo for *const int { } } -impl<'a> Foo for &'a int { +impl<'a> Foo for &'a isize { fn bar(&self) { baz(); //~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`? @@ -94,7 +94,7 @@ impl<'a> Foo for &'a int { } } -impl<'a> Foo for &'a mut int { +impl<'a> Foo for &'a mut isize { fn bar(&self) { baz(); //~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`? @@ -103,7 +103,7 @@ impl<'a> Foo for &'a mut int { } } -impl Foo for Box { +impl Foo for Box { fn bar(&self) { baz(); //~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`? diff --git a/src/test/compile-fail/issue-14303-impl.rs b/src/test/compile-fail/issue-14303-impl.rs index 46d0219da81a2..c4a00581274ac 100644 --- a/src/test/compile-fail/issue-14303-impl.rs +++ b/src/test/compile-fail/issue-14303-impl.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct X { x: int } +struct X { x: isize } impl<'a, T, 'b> X {} //~^ ERROR lifetime parameters must be declared prior to type parameters diff --git a/src/test/compile-fail/issue-15129.rs b/src/test/compile-fail/issue-15129.rs index f56430f42289a..7a7ba46de74f3 100644 --- a/src/test/compile-fail/issue-15129.rs +++ b/src/test/compile-fail/issue-15129.rs @@ -14,7 +14,7 @@ pub enum T { } pub enum V { - V1(int), + V1(isize), V2(bool) } diff --git a/src/test/compile-fail/issue-15524.rs b/src/test/compile-fail/issue-15524.rs index 6d9657ab28912..b378d2f885e83 100644 --- a/src/test/compile-fail/issue-15524.rs +++ b/src/test/compile-fail/issue-15524.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const N: int = 1; +const N: isize = 1; enum Foo { A = 1, diff --git a/src/test/compile-fail/issue-16149.rs b/src/test/compile-fail/issue-16149.rs index aa586e58f7084..a924cc9f9bbd5 100644 --- a/src/test/compile-fail/issue-16149.rs +++ b/src/test/compile-fail/issue-16149.rs @@ -9,7 +9,7 @@ // except according to those terms. extern { - static externalValue: int; + static externalValue: isize; } fn main() { diff --git a/src/test/compile-fail/issue-16465.rs b/src/test/compile-fail/issue-16465.rs index 280f19cfe9cc7..825b40cb322df 100644 --- a/src/test/compile-fail/issue-16465.rs +++ b/src/test/compile-fail/issue-16465.rs @@ -14,7 +14,7 @@ struct Foo{ x : T } -type FooInt = Foo; +type FooInt = Foo; impl Drop for FooInt { //~^ ERROR cannot implement a destructor on a structure with type parameters diff --git a/src/test/compile-fail/issue-17263.rs b/src/test/compile-fail/issue-17263.rs index ba993259216e5..543063b3fc968 100644 --- a/src/test/compile-fail/issue-17263.rs +++ b/src/test/compile-fail/issue-17263.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -struct Foo { a: int, b: int } +struct Foo { a: isize, b: isize } fn main() { let mut x = box Foo { a: 1, b: 2 }; diff --git a/src/test/compile-fail/issue-17383.rs b/src/test/compile-fail/issue-17383.rs index 240073645500c..c71e0ecd49496 100644 --- a/src/test/compile-fail/issue-17383.rs +++ b/src/test/compile-fail/issue-17383.rs @@ -12,7 +12,7 @@ enum X { A = b'a' //~ ERROR discriminator values can only be used with a c-like enum , - B(int) + B(isize) } fn main() {} diff --git a/src/test/compile-fail/issue-17385.rs b/src/test/compile-fail/issue-17385.rs index 62a5c7318b98f..e7cab292ea7ef 100644 --- a/src/test/compile-fail/issue-17385.rs +++ b/src/test/compile-fail/issue-17385.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct X(int); +struct X(isize); enum Enum { Variant1, diff --git a/src/test/compile-fail/issue-17405.rs b/src/test/compile-fail/issue-17405.rs index c956f00c8e77f..cb541835fbb0d 100644 --- a/src/test/compile-fail/issue-17405.rs +++ b/src/test/compile-fail/issue-17405.rs @@ -9,7 +9,7 @@ // except according to those terms. enum Foo { - Bar(int) + Bar(isize) } fn main() { diff --git a/src/test/compile-fail/issue-17450.rs b/src/test/compile-fail/issue-17450.rs index ca611c625770d..5471d8522dffd 100644 --- a/src/test/compile-fail/issue-17450.rs +++ b/src/test/compile-fail/issue-17450.rs @@ -10,8 +10,8 @@ #![allow(dead_code)] -static mut x: int = 3; -static mut y: int = unsafe { +static mut x: isize = 3; +static mut y: isize = unsafe { x //~^ ERROR cannot refer to other statics by value, use the address-of operator or a constant instea }; diff --git a/src/test/compile-fail/issue-17718-const-naming.rs b/src/test/compile-fail/issue-17718-const-naming.rs index 0cfee6daf3f19..15f66493f8842 100644 --- a/src/test/compile-fail/issue-17718-const-naming.rs +++ b/src/test/compile-fail/issue-17718-const-naming.rs @@ -10,7 +10,7 @@ #[deny(warnings)] -const foo: int = 3; +const foo: isize = 3; //~^ ERROR: should have an uppercase name such as //~^^ ERROR: constant item is never used diff --git a/src/test/compile-fail/issue-18118.rs b/src/test/compile-fail/issue-18118.rs index 4497c8088c31c..129f28f1d89c7 100644 --- a/src/test/compile-fail/issue-18118.rs +++ b/src/test/compile-fail/issue-18118.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - static z: &'static int = { + static z: &'static isize = { let p = 3; &p //~^ ERROR cannot borrow a local variable inside a static block, define a separate static instead diff --git a/src/test/compile-fail/issue-18423.rs b/src/test/compile-fail/issue-18423.rs index 63b110b557934..5945a7a1c9a7e 100644 --- a/src/test/compile-fail/issue-18423.rs +++ b/src/test/compile-fail/issue-18423.rs @@ -11,7 +11,7 @@ // Test that `Box` cannot be used with a lifetime parameter. struct Foo<'a> { - x: Box<'a, int> //~ ERROR wrong number of lifetime parameters + x: Box<'a, isize> //~ ERROR wrong number of lifetime parameters } pub fn main() { diff --git a/src/test/compile-fail/issue-19096.rs b/src/test/compile-fail/issue-19096.rs index 5d915d6a59b15..1e68de1f92338 100644 --- a/src/test/compile-fail/issue-19096.rs +++ b/src/test/compile-fail/issue-19096.rs @@ -10,5 +10,5 @@ fn main() { let t = (42i, 42i); - t.0::; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::` + t.0::; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::` } diff --git a/src/test/compile-fail/issue-19244-1.rs b/src/test/compile-fail/issue-19244-1.rs index fafe6377397a3..c3700f2f90acf 100644 --- a/src/test/compile-fail/issue-19244-1.rs +++ b/src/test/compile-fail/issue-19244-1.rs @@ -11,6 +11,6 @@ const TUP: (uint,) = (42,); fn main() { - let a: [int; TUP.1]; + let a: [isize; TUP.1]; //~^ ERROR expected constant expr for array length: tuple index out of bounds } diff --git a/src/test/compile-fail/issue-19244-2.rs b/src/test/compile-fail/issue-19244-2.rs index 95965ca35f944..7c7271552d2ef 100644 --- a/src/test/compile-fail/issue-19244-2.rs +++ b/src/test/compile-fail/issue-19244-2.rs @@ -12,6 +12,6 @@ struct MyStruct { field: uint } const STRUCT: MyStruct = MyStruct { field: 42 }; fn main() { - let a: [int; STRUCT.nonexistent_field]; + let a: [isize; STRUCT.nonexistent_field]; //~^ ERROR expected constant expr for array length: nonexistent struct field } diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 455cde63f272a..90b5ff8475e61 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -12,7 +12,7 @@ #![allow(unused_variables)] #![allow(dead_code)] -fn fail_len(v: Vec ) -> uint { +fn fail_len(v: Vec ) -> uint { let mut i = 3; panic!(); for x in v.iter() { i += 1u; } diff --git a/src/test/compile-fail/issue-2330.rs b/src/test/compile-fail/issue-2330.rs index 6291b0240533f..63f146a21d925 100644 --- a/src/test/compile-fail/issue-2330.rs +++ b/src/test/compile-fail/issue-2330.rs @@ -15,8 +15,8 @@ trait channel { } // `chan` is not a trait, it's an enum -impl chan for int { //~ ERROR `chan` is not a trait - fn send(&self, v: int) { panic!() } +impl chan for isize { //~ ERROR `chan` is not a trait + fn send(&self, v: isize) { panic!() } } fn main() { diff --git a/src/test/compile-fail/issue-2354-1.rs b/src/test/compile-fail/issue-2354-1.rs index 67b5c6becc741..d37837b9714f0 100644 --- a/src/test/compile-fail/issue-2354-1.rs +++ b/src/test/compile-fail/issue-2354-1.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static foo: int = 2; } //~ ERROR incorrect close delimiter: +static foo: isize = 2; } //~ ERROR incorrect close delimiter: diff --git a/src/test/compile-fail/issue-2356.rs b/src/test/compile-fail/issue-2356.rs index 850edd05781a2..d6acc13c2897c 100644 --- a/src/test/compile-fail/issue-2356.rs +++ b/src/test/compile-fail/issue-2356.rs @@ -13,7 +13,7 @@ trait Groom { } pub struct cat { - whiskers: int, + whiskers: isize, } pub enum MaybeDog { diff --git a/src/test/compile-fail/issue-2478.rs b/src/test/compile-fail/issue-2478.rs index 860192ba3e59d..3aea9c32e3ad2 100644 --- a/src/test/compile-fail/issue-2478.rs +++ b/src/test/compile-fail/issue-2478.rs @@ -10,8 +10,8 @@ // ignore-test -fn foo<'a>() -> &'a int { //~ ERROR unconstrained region +fn foo<'a>() -> &'a isize { //~ ERROR unconstrained region return &x; } -static x: int = 5; +static x: isize = 5; fn main() {} diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs index 79a66e30fdb91..60a270b2c9449 100644 --- a/src/test/compile-fail/issue-2590.rs +++ b/src/test/compile-fail/issue-2590.rs @@ -10,15 +10,15 @@ struct parser { - tokens: Vec , + tokens: Vec , } trait parse { - fn parse(&self) -> Vec ; + fn parse(&self) -> Vec ; } impl parse for parser { - fn parse(&self) -> Vec { + fn parse(&self) -> Vec { self.tokens //~ ERROR cannot move out of dereference of `&`-pointer } } diff --git a/src/test/compile-fail/issue-2611-4.rs b/src/test/compile-fail/issue-2611-4.rs index 70ffa86359d5a..b141c1f441aeb 100644 --- a/src/test/compile-fail/issue-2611-4.rs +++ b/src/test/compile-fail/issue-2611-4.rs @@ -16,7 +16,7 @@ trait A { } struct E { - f: int + f: isize } impl A for E { diff --git a/src/test/compile-fail/issue-2611-5.rs b/src/test/compile-fail/issue-2611-5.rs index 2eda5d67edd8e..440294f38ae92 100644 --- a/src/test/compile-fail/issue-2611-5.rs +++ b/src/test/compile-fail/issue-2611-5.rs @@ -16,7 +16,7 @@ trait A { } struct E { - f: int + f: isize } impl A for E { diff --git a/src/test/compile-fail/issue-2823.rs b/src/test/compile-fail/issue-2823.rs index b6820a1d8e424..1996cb737fc72 100644 --- a/src/test/compile-fail/issue-2823.rs +++ b/src/test/compile-fail/issue-2823.rs @@ -9,7 +9,7 @@ // except according to those terms. struct C { - x: int, + x: isize, } impl Drop for C { diff --git a/src/test/compile-fail/issue-2849.rs b/src/test/compile-fail/issue-2849.rs index 5aaeb7e8c6d77..48f4cac9711a8 100644 --- a/src/test/compile-fail/issue-2849.rs +++ b/src/test/compile-fail/issue-2849.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum foo { alpha, beta(int) } +enum foo { alpha, beta(isize) } fn main() { match foo::alpha { diff --git a/src/test/compile-fail/issue-2995.rs b/src/test/compile-fail/issue-2995.rs index 920897e6828a0..8fbf97411cc7d 100644 --- a/src/test/compile-fail/issue-2995.rs +++ b/src/test/compile-fail/issue-2995.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn bad (p: *const int) { - let _q: &int = p as ∫ //~ ERROR non-scalar cast +fn bad (p: *const isize) { + let _q: &isize = p as &isize; //~ ERROR non-scalar cast } fn main() { } diff --git a/src/test/compile-fail/issue-3038.rs b/src/test/compile-fail/issue-3038.rs index d9fe3550c9e75..1eec62df78801 100644 --- a/src/test/compile-fail/issue-3038.rs +++ b/src/test/compile-fail/issue-3038.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum f { g(int, int) } +enum f { g(isize, isize) } enum h { i(j, k) } -enum j { l(int, int) } -enum k { m(int, int) } +enum j { l(isize, isize) } +enum k { m(isize, isize) } fn main() { diff --git a/src/test/compile-fail/issue-3521-2.rs b/src/test/compile-fail/issue-3521-2.rs index cdfc990677657..678618d721692 100644 --- a/src/test/compile-fail/issue-3521-2.rs +++ b/src/test/compile-fail/issue-3521-2.rs @@ -11,7 +11,7 @@ fn main() { let foo = 100; - static y: int = foo + 1; //~ ERROR: attempt to use a non-constant value in a constant + static y: isize = foo + 1; //~ ERROR: attempt to use a non-constant value in a constant println!("{}", y); } diff --git a/src/test/compile-fail/issue-3668-2.rs b/src/test/compile-fail/issue-3668-2.rs index f7637f684be5a..0577b1527234d 100644 --- a/src/test/compile-fail/issue-3668-2.rs +++ b/src/test/compile-fail/issue-3668-2.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(x:int) { - static child: int = x + 1; //~ ERROR attempt to use a non-constant value in a constant +fn f(x:isize) { + static child: isize = x + 1; //~ ERROR attempt to use a non-constant value in a constant } fn main() {} diff --git a/src/test/compile-fail/issue-3702-2.rs b/src/test/compile-fail/issue-3702-2.rs index 1e80fd7a7e910..2b732899ea42f 100644 --- a/src/test/compile-fail/issue-3702-2.rs +++ b/src/test/compile-fail/issue-3702-2.rs @@ -11,13 +11,13 @@ use std::num::ToPrimitive; trait Add { - fn to_int(&self) -> int; - fn add_dynamic(&self, other: &Add) -> int; + fn to_int(&self) -> isize; + fn add_dynamic(&self, other: &Add) -> isize; } -impl Add for int { - fn to_int(&self) -> int { *self } - fn add_dynamic(&self, other: &Add) -> int { +impl Add for isize { + fn to_int(&self) -> isize { *self } + fn add_dynamic(&self, other: &Add) -> isize { self.to_int() + other.to_int() //~ ERROR multiple applicable methods in scope } } diff --git a/src/test/compile-fail/issue-3763.rs b/src/test/compile-fail/issue-3763.rs index 06939d8f35801..6e6c19a5bf6b0 100644 --- a/src/test/compile-fail/issue-3763.rs +++ b/src/test/compile-fail/issue-3763.rs @@ -12,7 +12,7 @@ mod my_mod { pub struct MyStruct { - priv_field: int + priv_field: isize } pub fn MyStruct () -> MyStruct { MyStruct {priv_field: 4} diff --git a/src/test/compile-fail/issue-3820.rs b/src/test/compile-fail/issue-3820.rs index 06577afa6dd46..28de76f18da76 100644 --- a/src/test/compile-fail/issue-3820.rs +++ b/src/test/compile-fail/issue-3820.rs @@ -9,11 +9,11 @@ // except according to those terms. struct Thing { - x: int + x: isize } impl Thing { - fn mul(&self, c: &int) -> Thing { + fn mul(&self, c: &isize) -> Thing { Thing {x: self.x * *c} } } diff --git a/src/test/compile-fail/issue-3907-2.rs b/src/test/compile-fail/issue-3907-2.rs index 546b808a38f47..9a166a6752b7e 100644 --- a/src/test/compile-fail/issue-3907-2.rs +++ b/src/test/compile-fail/issue-3907-2.rs @@ -14,7 +14,7 @@ extern crate issue_3907; type Foo = issue_3907::Foo+'static; struct S { - name: int + name: isize } fn bar(_x: Foo) {} //~ ERROR the trait `core::marker::Sized` is not implemented diff --git a/src/test/compile-fail/issue-3907.rs b/src/test/compile-fail/issue-3907.rs index a2faef59fd828..001de796b4ad7 100644 --- a/src/test/compile-fail/issue-3907.rs +++ b/src/test/compile-fail/issue-3907.rs @@ -14,7 +14,7 @@ extern crate issue_3907; type Foo = issue_3907::Foo; struct S { - name: int + name: isize } impl Foo for S { //~ ERROR: `Foo` is not a trait diff --git a/src/test/compile-fail/issue-3953.rs b/src/test/compile-fail/issue-3953.rs index ab2018af99900..0f1dd2d7fd6a8 100644 --- a/src/test/compile-fail/issue-3953.rs +++ b/src/test/compile-fail/issue-3953.rs @@ -16,7 +16,7 @@ trait Hahaha: PartialEq + PartialEq { //~^ ERROR trait `PartialEq` already appears in the list of bounds } -struct Lol(int); +struct Lol(isize); impl Hahaha for Lol { } diff --git a/src/test/compile-fail/issue-4366-2.rs b/src/test/compile-fail/issue-4366-2.rs index 289e9855525ac..e8dfac4544744 100644 --- a/src/test/compile-fail/issue-4366-2.rs +++ b/src/test/compile-fail/issue-4366-2.rs @@ -18,7 +18,7 @@ mod foo { mod a { pub mod b { use foo::foo; - type bar = int; + type bar = isize; } pub mod sub { use a::b::*; diff --git a/src/test/compile-fail/issue-4366.rs b/src/test/compile-fail/issue-4366.rs index 289aa21e1cba5..5625ac00c85d7 100644 --- a/src/test/compile-fail/issue-4366.rs +++ b/src/test/compile-fail/issue-4366.rs @@ -21,11 +21,11 @@ mod foo { mod a { pub mod b { use foo::foo; - type bar = int; + type bar = isize; } pub mod sub { use a::b::*; - fn sub() -> int { foo(); 1 } //~ ERROR: unresolved name `foo` + fn sub() -> isize { foo(); 1 } //~ ERROR: unresolved name `foo` } } diff --git a/src/test/compile-fail/issue-5035.rs b/src/test/compile-fail/issue-5035.rs index 8ffe308a66939..cdf9d3bd36ece 100644 --- a/src/test/compile-fail/issue-5035.rs +++ b/src/test/compile-fail/issue-5035.rs @@ -10,6 +10,6 @@ trait I {} type K = I; -impl K for int {} //~ ERROR: `K` is not a trait +impl K for isize {} //~ ERROR: `K` is not a trait //~^ NOTE: `type` aliases cannot be used for traits fn main() {} diff --git a/src/test/compile-fail/issue-5153.rs b/src/test/compile-fail/issue-5153.rs index 57a158d2438dd..c10c7cba45559 100644 --- a/src/test/compile-fail/issue-5153.rs +++ b/src/test/compile-fail/issue-5153.rs @@ -14,8 +14,8 @@ trait Foo { fn foo(self: Box); } -impl Foo for int { - fn foo(self: Box) { } +impl Foo for isize { + fn foo(self: Box) { } } fn main() { diff --git a/src/test/compile-fail/issue-5439.rs b/src/test/compile-fail/issue-5439.rs index 72074d64edc3d..4e618f3d85848 100644 --- a/src/test/compile-fail/issue-5439.rs +++ b/src/test/compile-fail/issue-5439.rs @@ -11,15 +11,15 @@ #![feature(box_syntax)] struct Foo { - foo: int, + foo: isize, } struct Bar { - bar: int, + bar: isize, } impl Bar { - fn make_foo (&self, i: int) -> Box { + fn make_foo (&self, i: isize) -> Box { return box Foo { nonexistent: self, foo: i }; //~ ERROR: no field named } } diff --git a/src/test/compile-fail/issue-5544-a.rs b/src/test/compile-fail/issue-5544-a.rs index 42a18ba5fb765..6db126f403a4a 100644 --- a/src/test/compile-fail/issue-5544-a.rs +++ b/src/test/compile-fail/issue-5544-a.rs @@ -10,5 +10,5 @@ fn main() { let _i = 18446744073709551616; // 2^64 - //~^ ERROR int literal is too large + //~^ ERROR isize literal is too large } diff --git a/src/test/compile-fail/issue-5544-b.rs b/src/test/compile-fail/issue-5544-b.rs index bbe43e652a800..4b04fe1a36aaa 100644 --- a/src/test/compile-fail/issue-5544-b.rs +++ b/src/test/compile-fail/issue-5544-b.rs @@ -10,5 +10,5 @@ fn main() { let _i = 0xff_ffff_ffff_ffff_ffff; - //~^ ERROR int literal is too large + //~^ ERROR isize literal is too large } diff --git a/src/test/compile-fail/issue-5997-enum.rs b/src/test/compile-fail/issue-5997-enum.rs index 39e1e117cd0ab..ad485f2d3302b 100644 --- a/src/test/compile-fail/issue-5997-enum.rs +++ b/src/test/compile-fail/issue-5997-enum.rs @@ -16,6 +16,6 @@ fn f() -> bool { } fn main() { - let b = f::(); + let b = f::(); assert!(b); } diff --git a/src/test/compile-fail/issue-5997-struct.rs b/src/test/compile-fail/issue-5997-struct.rs index b2a63ed1c7b8f..587c7c63f4cf1 100644 --- a/src/test/compile-fail/issue-5997-struct.rs +++ b/src/test/compile-fail/issue-5997-struct.rs @@ -16,6 +16,6 @@ fn f() -> bool { } fn main() { - let b = f::(); + let b = f::(); assert!(b); } diff --git a/src/test/compile-fail/issue-6702.rs b/src/test/compile-fail/issue-6702.rs index 3e35e4a659d1e..d035c615ec378 100644 --- a/src/test/compile-fail/issue-6702.rs +++ b/src/test/compile-fail/issue-6702.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Monster { - damage: int + damage: isize } diff --git a/src/test/compile-fail/issue-7044.rs b/src/test/compile-fail/issue-7044.rs index ee332789b0ed5..6f9fb2e61f2a8 100644 --- a/src/test/compile-fail/issue-7044.rs +++ b/src/test/compile-fail/issue-7044.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static X: int = 0; +static X: isize = 0; struct X; //~ ERROR error: duplicate definition of value `X` fn main() {} diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index b4df38a6aac03..2e644b6540234 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -13,7 +13,7 @@ use std::cell::RefCell; // Regresion test for issue 7364 -static boxed: Box> = box RefCell::new(0); +static boxed: Box> = box RefCell::new(0); //~^ ERROR statics are not allowed to have custom pointers //~| ERROR: the trait `core::marker::Sync` is not implemented for the type //~| ERROR: the trait `core::marker::Sync` is not implemented for the type diff --git a/src/test/compile-fail/issue-7607-1.rs b/src/test/compile-fail/issue-7607-1.rs index 9bf1bd2e011bb..48fc393d0da8e 100644 --- a/src/test/compile-fail/issue-7607-1.rs +++ b/src/test/compile-fail/issue-7607-1.rs @@ -11,7 +11,7 @@ // ignore-tidy-linelength struct Foo { - x: int + x: isize } impl Fo { //~ERROR inherent implementations are not allowed for types not defined in the current module diff --git a/src/test/compile-fail/issue-8153.rs b/src/test/compile-fail/issue-8153.rs index 2af531135eca3..ea7224939ce56 100644 --- a/src/test/compile-fail/issue-8153.rs +++ b/src/test/compile-fail/issue-8153.rs @@ -13,12 +13,12 @@ struct Foo; trait Bar { - fn bar(&self) -> int; + fn bar(&self) -> isize; } impl Bar for Foo { - fn bar(&self) -> int {1} - fn bar(&self) -> int {2} //~ ERROR duplicate method + fn bar(&self) -> isize {1} + fn bar(&self) -> isize {2} //~ ERROR duplicate method } fn main() { diff --git a/src/test/compile-fail/issue-9243.rs b/src/test/compile-fail/issue-9243.rs index eb3618c9f0408..808aa098c5a28 100644 --- a/src/test/compile-fail/issue-9243.rs +++ b/src/test/compile-fail/issue-9243.rs @@ -11,7 +11,7 @@ // Regresion test for issue 9243 struct Test { - mem: int, + mem: isize, } pub static g_test: Test = Test {mem: 0}; //~ ERROR statics are not allowed to have destructors diff --git a/src/test/compile-fail/issue-9725.rs b/src/test/compile-fail/issue-9725.rs index 9545ad43ff8b4..1a3c926ba384b 100644 --- a/src/test/compile-fail/issue-9725.rs +++ b/src/test/compile-fail/issue-9725.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct A { foo: int } +struct A { foo: isize } fn main() { let A { foo, foo } = A { foo: 3 }; diff --git a/src/test/compile-fail/issue-9814.rs b/src/test/compile-fail/issue-9814.rs index d6cc493e93656..8aefc5919d133 100644 --- a/src/test/compile-fail/issue-9814.rs +++ b/src/test/compile-fail/issue-9814.rs @@ -11,7 +11,7 @@ // Verify that single-variant enums cant be de-referenced // Regression test for issue #9814 -enum Foo { Bar(int) } +enum Foo { Bar(isize) } fn main() { let _ = *Foo::Bar(2); //~ ERROR type `Foo` cannot be dereferenced diff --git a/src/test/compile-fail/keyword-super.rs b/src/test/compile-fail/keyword-super.rs index 6cbc8aa1ea642..0c94f76f1f6f6 100644 --- a/src/test/compile-fail/keyword-super.rs +++ b/src/test/compile-fail/keyword-super.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - let super: int; //~ ERROR expected identifier, found keyword `super` + let super: isize; //~ ERROR expected identifier, found keyword `super` } diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index ac088e69a28e5..4398be4b212da 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -18,8 +18,8 @@ fn assert_copy() { } trait Dummy { } struct MyStruct { - x: int, - y: int, + x: isize, + y: isize, } impl Copy for MyStruct {} @@ -28,22 +28,22 @@ struct MyNoncopyStruct { x: Box, } -fn test<'a,T,U:Copy>(_: &'a int) { +fn test<'a,T,U:Copy>(_: &'a isize) { // lifetime pointers are ok... - assert_copy::<&'static int>(); - assert_copy::<&'a int>(); + assert_copy::<&'static isize>(); + assert_copy::<&'a isize>(); assert_copy::<&'a str>(); - assert_copy::<&'a [int]>(); + assert_copy::<&'a [isize]>(); // ...unless they are mutable - assert_copy::<&'static mut int>(); //~ ERROR `core::marker::Copy` is not implemented - assert_copy::<&'a mut int>(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy::<&'static mut isize>(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy::<&'a mut isize>(); //~ ERROR `core::marker::Copy` is not implemented // ~ pointers are not ok - assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented assert_copy::(); //~ ERROR `core::marker::Copy` is not implemented - assert_copy:: >(); //~ ERROR `core::marker::Copy` is not implemented - assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy:: >(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented // borrowed object types are generally ok assert_copy::<&'a Dummy>(); @@ -58,16 +58,16 @@ fn test<'a,T,U:Copy>(_: &'a int) { assert_copy::<&'a mut (Dummy+Copy)>(); //~ ERROR `core::marker::Copy` is not implemented // unsafe ptrs are ok - assert_copy::<*const int>(); - assert_copy::<*const &'a mut int>(); + assert_copy::<*const isize>(); + assert_copy::<*const &'a mut isize>(); // regular old ints and such are ok - assert_copy::(); + assert_copy::(); assert_copy::(); assert_copy::<()>(); // tuples are ok - assert_copy::<(int,int)>(); + assert_copy::<(isize,isize)>(); // structs of POD are ok assert_copy::(); @@ -76,7 +76,7 @@ fn test<'a,T,U:Copy>(_: &'a int) { assert_copy::(); //~ ERROR `core::marker::Copy` is not implemented // ref counted types are not ok - assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented + assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented } pub fn main() { diff --git a/src/test/compile-fail/kindck-destructor-owned.rs b/src/test/compile-fail/kindck-destructor-owned.rs index 803da617abdc0..7f3704144bef6 100644 --- a/src/test/compile-fail/kindck-destructor-owned.rs +++ b/src/test/compile-fail/kindck-destructor-owned.rs @@ -10,7 +10,7 @@ struct Bar<'a> { - f: &'a int, + f: &'a isize, } impl<'a> Drop for Bar<'a> { @@ -20,7 +20,7 @@ impl<'a> Drop for Bar<'a> { } struct Baz { - f: &'static int, + f: &'static isize, } impl Drop for Baz { diff --git a/src/test/compile-fail/kindck-impl-type-params.rs b/src/test/compile-fail/kindck-impl-type-params.rs index 34e77353463d1..5d09068941544 100644 --- a/src/test/compile-fail/kindck-impl-type-params.rs +++ b/src/test/compile-fail/kindck-impl-type-params.rs @@ -34,8 +34,8 @@ fn g(val: T) { } fn foo<'a>() { - let t: S<&'a int> = S; - let a = &t as &Gettable<&'a int>; + let t: S<&'a isize> = S; + let a = &t as &Gettable<&'a isize>; //~^ ERROR declared lifetime bound not satisfied } diff --git a/src/test/compile-fail/kindck-send-owned.rs b/src/test/compile-fail/kindck-send-owned.rs index 11148d2846c16..7025249fafb6e 100644 --- a/src/test/compile-fail/kindck-send-owned.rs +++ b/src/test/compile-fail/kindck-send-owned.rs @@ -13,13 +13,13 @@ fn assert_send() { } // owned content are ok -fn test30() { assert_send::>(); } +fn test30() { assert_send::>(); } fn test31() { assert_send::(); } -fn test32() { assert_send:: >(); } +fn test32() { assert_send:: >(); } // but not if they own a bad thing -fn test40<'a>(_: &'a int) { - assert_send::>(); //~ ERROR declared lifetime bound not satisfied +fn test40<'a>(_: &'a isize) { + assert_send::>(); //~ ERROR declared lifetime bound not satisfied } fn main() { } diff --git a/src/test/compile-fail/kindck-send-region-pointers.rs b/src/test/compile-fail/kindck-send-region-pointers.rs index 04172932cfe6f..c6987e89e3af2 100644 --- a/src/test/compile-fail/kindck-send-region-pointers.rs +++ b/src/test/compile-fail/kindck-send-region-pointers.rs @@ -13,22 +13,22 @@ fn assert_send() { } // lifetime pointers with 'static lifetime are ok -fn test01() { assert_send::<&'static int>(); } +fn test01() { assert_send::<&'static isize>(); } fn test02() { assert_send::<&'static str>(); } -fn test03() { assert_send::<&'static [int]>(); } +fn test03() { assert_send::<&'static [isize]>(); } // whether or not they are mutable -fn test10() { assert_send::<&'static mut int>(); } +fn test10() { assert_send::<&'static mut isize>(); } // otherwise lifetime pointers are not ok -fn test20<'a>(_: &'a int) { - assert_send::<&'a int>(); //~ ERROR declared lifetime bound not satisfied +fn test20<'a>(_: &'a isize) { + assert_send::<&'a isize>(); //~ ERROR declared lifetime bound not satisfied } -fn test21<'a>(_: &'a int) { +fn test21<'a>(_: &'a isize) { assert_send::<&'a str>(); //~ ERROR declared lifetime bound not satisfied } -fn test22<'a>(_: &'a int) { - assert_send::<&'a [int]>(); //~ ERROR declared lifetime bound not satisfied +fn test22<'a>(_: &'a isize) { + assert_send::<&'a [isize]>(); //~ ERROR declared lifetime bound not satisfied } fn main() { } diff --git a/src/test/compile-fail/kindck-send-unsafe.rs b/src/test/compile-fail/kindck-send-unsafe.rs index 1bfd0d4a11f55..bce765a986a22 100644 --- a/src/test/compile-fail/kindck-send-unsafe.rs +++ b/src/test/compile-fail/kindck-send-unsafe.rs @@ -13,7 +13,7 @@ extern crate core; fn assert_send() { } fn test71<'a>() { - assert_send::<*mut &'a int>(); + assert_send::<*mut &'a isize>(); //~^ ERROR the trait `core::marker::Send` is not implemented for the type } diff --git a/src/test/compile-fail/lang-item-missing.rs b/src/test/compile-fail/lang-item-missing.rs index bcde10a0b2238..793d9c77c3bc4 100644 --- a/src/test/compile-fail/lang-item-missing.rs +++ b/src/test/compile-fail/lang-item-missing.rs @@ -16,6 +16,6 @@ #![no_std] #[start] -fn start(argc: int, argv: *const *const u8) -> int { +fn start(argc: isize, argv: *const *const u8) -> isize { 0 } diff --git a/src/test/compile-fail/lex-bad-numeric-literals.rs b/src/test/compile-fail/lex-bad-numeric-literals.rs index 9a490be6a0169..273a7627d73bf 100644 --- a/src/test/compile-fail/lex-bad-numeric-literals.rs +++ b/src/test/compile-fail/lex-bad-numeric-literals.rs @@ -21,8 +21,8 @@ fn main() { 0o; //~ ERROR: no valid digits 1e+; //~ ERROR: expected at least one digit in exponent 0x539.0; //~ ERROR: hexadecimal float literal is not supported - 99999999999999999999999999999999; //~ ERROR: int literal is too large - 99999999999999999999999999999999u32; //~ ERROR: int literal is too large + 99999999999999999999999999999999; //~ ERROR: isize literal is too large + 99999999999999999999999999999999u32; //~ ERROR: isize literal is too large 0x; //~ ERROR: no valid digits 0xu32; //~ ERROR: no valid digits 0ou32; //~ ERROR: no valid digits diff --git a/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs b/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs index 817582a877fa9..55cce01633540 100644 --- a/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs +++ b/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs @@ -9,29 +9,29 @@ // except according to those terms. // Lifetime annotation needed because we have no arguments. -fn f() -> &int { //~ ERROR missing lifetime specifier +fn f() -> &isize { //~ ERROR missing lifetime specifier //~^ HELP there is no value for it to be borrowed from panic!() } // Lifetime annotation needed because we have two by-reference parameters. -fn g(_x: &int, _y: &int) -> &int { //~ ERROR missing lifetime specifier +fn g(_x: &isize, _y: &isize) -> &isize { //~ ERROR missing lifetime specifier //~^ HELP the signature does not say whether it is borrowed from `_x` or `_y` panic!() } struct Foo<'a> { - x: &'a int, + x: &'a isize, } // Lifetime annotation needed because we have two lifetimes: one as a parameter // and one on the reference. -fn h(_x: &Foo) -> &int { //~ ERROR missing lifetime specifier +fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier //~^ HELP the signature does not say which one of `_x`'s 2 elided lifetimes it is borrowed from panic!() } -fn i(_x: int) -> &int { //~ ERROR missing lifetime specifier +fn i(_x: isize) -> &isize { //~ ERROR missing lifetime specifier //~^ HELP this function's return type contains a borrowed value panic!() } diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs index 29265b8750ca7..18ef30f5b2812 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs @@ -10,17 +10,17 @@ // ignore-tidy-linelength -struct Bar<'x, 'y, 'z> { bar: &'y int, baz: int } -fn bar1<'a>(x: &Bar) -> (&'a int, &'a int, &'a int) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a int, &'a int, &'a int) +struct Bar<'x, 'y, 'z> { bar: &'y isize, baz: isize } +fn bar1<'a>(x: &Bar) -> (&'a isize, &'a isize, &'a isize) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a isize, &'a isize, &'a isize) (x.bar, &x.baz, &x.baz) //~^ ERROR: cannot infer //~^^ ERROR: cannot infer //~^^^ ERROR: cannot infer } -fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a int, &'a int, &'a int) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a int, &'a int, &'a int) +fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a isize, &'a isize, &'a isize) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a isize, &'a isize, &'a isize) (x.bar, &x.baz, &x.baz) //~^ ERROR: cannot infer //~^^ ERROR: cannot infer diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs index 4abf045501c26..c60e321219bd2 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs @@ -10,43 +10,43 @@ // ignore-tidy-linelength -struct Foo<'x> { bar: int } -fn foo1<'a>(x: &Foo) -> &'a int { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a int +struct Foo<'x> { bar: isize } +fn foo1<'a>(x: &Foo) -> &'a isize { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a isize &x.bar //~ ERROR: cannot infer } -fn foo2<'a, 'b>(x: &'a Foo) -> &'b int { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo2<'a>(x: &'a Foo) -> &'a int +fn foo2<'a, 'b>(x: &'a Foo) -> &'b isize { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo2<'a>(x: &'a Foo) -> &'a isize &x.bar //~ ERROR: cannot infer } -fn foo3<'a>(x: &Foo) -> (&'a int, &'a int) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo3<'a>(x: &'a Foo) -> (&'a int, &'a int) +fn foo3<'a>(x: &Foo) -> (&'a isize, &'a isize) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo3<'a>(x: &'a Foo) -> (&'a isize, &'a isize) (&x.bar, &x.bar) //~ ERROR: cannot infer //~^ ERROR: cannot infer } -fn foo4<'a, 'b>(x: &'a Foo) -> (&'b int, &'a int, &'b int) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo4<'a>(x: &'a Foo) -> (&'a int, &'a int, &'a int) +fn foo4<'a, 'b>(x: &'a Foo) -> (&'b isize, &'a isize, &'b isize) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo4<'a>(x: &'a Foo) -> (&'a isize, &'a isize, &'a isize) (&x.bar, &x.bar, &x.bar) //~ ERROR: cannot infer //~^ ERROR: cannot infer } -struct Cat<'x, T> { cat: &'x int, t: T } -struct Dog<'y> { dog: &'y int } +struct Cat<'x, T> { cat: &'x isize, t: T } +struct Dog<'y> { dog: &'y isize } -fn cat2<'x, 'y>(x: Cat<'x, Dog<'y>>) -> &'x int { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn cat2<'x>(x: Cat<'x, Dog<'x>>) -> &'x int +fn cat2<'x, 'y>(x: Cat<'x, Dog<'y>>) -> &'x isize { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn cat2<'x>(x: Cat<'x, Dog<'x>>) -> &'x isize x.t.dog //~ ERROR: cannot infer } struct Baz<'x> { - bar: &'x int + bar: &'x isize } impl<'a> Baz<'a> { - fn baz2<'b>(&self, x: &int) -> (&'b int, &'b int) { + fn baz2<'b>(&self, x: &isize) -> (&'b isize, &'b isize) { // The lifetime that gets assigned to `x` seems somewhat random. // I have disabled this test for the time being. --pcwalton (self.bar, x) //~ ERROR: cannot infer diff --git a/src/test/compile-fail/lifetime-no-keyword.rs b/src/test/compile-fail/lifetime-no-keyword.rs index 0ef13d73fab2b..8ffbcd90df877 100644 --- a/src/test/compile-fail/lifetime-no-keyword.rs +++ b/src/test/compile-fail/lifetime-no-keyword.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo<'a>(a: &'a int) { } -fn bar(a: &'static int) { } -fn baz(a: &'let int) { } //~ ERROR invalid lifetime name +fn foo<'a>(a: &'a isize) { } +fn bar(a: &'static isize) { } +fn baz(a: &'let isize) { } //~ ERROR invalid lifetime name fn main() { } diff --git a/src/test/compile-fail/lifetime-obsoleted-self.rs b/src/test/compile-fail/lifetime-obsoleted-self.rs index a99daaab24936..766922f2f8864 100644 --- a/src/test/compile-fail/lifetime-obsoleted-self.rs +++ b/src/test/compile-fail/lifetime-obsoleted-self.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn baz(a: &'self int) { } //~ ERROR invalid lifetime name: 'self is no longer a special lifetime +fn baz(a: &'self isize) { } //~ ERROR invalid lifetime name: 'self is no longer a special lifetime fn main() { } diff --git a/src/test/compile-fail/linkage1.rs b/src/test/compile-fail/linkage1.rs index a045b838d5157..555cc2b9a7aad 100644 --- a/src/test/compile-fail/linkage1.rs +++ b/src/test/compile-fail/linkage1.rs @@ -9,6 +9,6 @@ // except according to those terms. extern { - #[linkage = "extern_weak"] static foo: int; + #[linkage = "extern_weak"] static foo: isize; //~^ ERROR: the `linkage` attribute is experimental and not portable } diff --git a/src/test/compile-fail/linkage4.rs b/src/test/compile-fail/linkage4.rs index 8f68f3e553cd7..635d58e04c7ab 100644 --- a/src/test/compile-fail/linkage4.rs +++ b/src/test/compile-fail/linkage4.rs @@ -9,7 +9,7 @@ // except according to those terms. #[linkage = "external"] -static foo: int = 0; +static foo: isize = 0; //~^ ERROR: the `linkage` attribute is experimental and not portable fn main() {} diff --git a/src/test/compile-fail/lint-ctypes.rs b/src/test/compile-fail/lint-ctypes.rs index 1755a9a2481b4..e0ed095b1a1dc 100644 --- a/src/test/compile-fail/lint-ctypes.rs +++ b/src/test/compile-fail/lint-ctypes.rs @@ -13,9 +13,9 @@ extern crate libc; extern { - pub fn bare_type1(size: int); //~ ERROR: found rust type + pub fn bare_type1(size: isize); //~ ERROR: found rust type pub fn bare_type2(size: uint); //~ ERROR: found rust type - pub fn ptr_type1(size: *const int); //~ ERROR: found rust type + pub fn ptr_type1(size: *const isize); //~ ERROR: found rust type pub fn ptr_type2(size: *const uint); //~ ERROR: found rust type pub fn good1(size: *const libc::c_int); diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 9e5f15c272196..e55922db3d5fc 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -29,28 +29,28 @@ mod foo2 { pub struct Bar2; } -pub static pub_static: int = 0; -static priv_static: int = 0; //~ ERROR: static item is never used -const used_static: int = 0; -pub static used_static2: int = used_static; -const USED_STATIC: int = 0; -const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10; - -pub const pub_const: int = 0; -const priv_const: int = 0; //~ ERROR: constant item is never used -const used_const: int = 0; -pub const used_const2: int = used_const; -const USED_CONST: int = 1; -const CONST_USED_IN_ENUM_DISCRIMINANT: int = 11; +pub static pub_static: isize = 0; +static priv_static: isize = 0; //~ ERROR: static item is never used +const used_static: isize = 0; +pub static used_static2: isize = used_static; +const USED_STATIC: isize = 0; +const STATIC_USED_IN_ENUM_DISCRIMINANT: isize = 10; + +pub const pub_const: isize = 0; +const priv_const: isize = 0; //~ ERROR: constant item is never used +const used_const: isize = 0; +pub const used_const2: isize = used_const; +const USED_CONST: isize = 1; +const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11; pub type typ = *const UsedStruct4; pub struct PubStruct; struct PrivStruct; //~ ERROR: struct is never used struct UsedStruct1 { #[allow(dead_code)] - x: int + x: isize } -struct UsedStruct2(int); +struct UsedStruct2(isize); struct UsedStruct3; struct UsedStruct4; // this struct is never used directly, but its method is, so we don't want diff --git a/src/test/compile-fail/lint-dead-code-2.rs b/src/test/compile-fail/lint-dead-code-2.rs index c7199eec8a3e8..e8b85ffd69a44 100644 --- a/src/test/compile-fail/lint-dead-code-2.rs +++ b/src/test/compile-fail/lint-dead-code-2.rs @@ -36,7 +36,7 @@ fn dead_fn2() {} //~ ERROR: function is never used fn used_fn() {} #[start] -fn start(_: int, _: *const *const u8) -> int { +fn start(_: isize, _: *const *const u8) -> isize { used_fn(); let foo = Foo; foo.bar2(); diff --git a/src/test/compile-fail/lint-dead-code-3.rs b/src/test/compile-fail/lint-dead-code-3.rs index 4ef76030bcc54..3662855a72049 100644 --- a/src/test/compile-fail/lint-dead-code-3.rs +++ b/src/test/compile-fail/lint-dead-code-3.rs @@ -79,7 +79,7 @@ mod inner { fn f(&self) { f(); } } - impl Trait for int {} + impl Trait for isize {} fn f() {} } diff --git a/src/test/compile-fail/lint-dead-code-4.rs b/src/test/compile-fail/lint-dead-code-4.rs index 21e1ab4c33e1d..2653c1d5b2410 100644 --- a/src/test/compile-fail/lint-dead-code-4.rs +++ b/src/test/compile-fail/lint-dead-code-4.rs @@ -30,7 +30,7 @@ enum XYZ { X, //~ ERROR variant is never used Y { //~ ERROR variant is never used a: String, - b: int //~ ERROR: struct field is never used + b: isize //~ ERROR: struct field is never used }, Z } diff --git a/src/test/compile-fail/lint-dead-code-5.rs b/src/test/compile-fail/lint-dead-code-5.rs index d6a31c96100f2..04d6547d93812 100644 --- a/src/test/compile-fail/lint-dead-code-5.rs +++ b/src/test/compile-fail/lint-dead-code-5.rs @@ -12,16 +12,16 @@ #![deny(dead_code)] enum Enum1 { - Variant1(int), + Variant1(isize), Variant2 //~ ERROR: variant is never used } enum Enum2 { Variant3(bool), #[allow(dead_code)] - Variant4(int), - Variant5 { _x: int }, //~ ERROR: variant is never used: `Variant5` - Variant6(int), //~ ERROR: variant is never used: `Variant6` + Variant4(isize), + Variant5 { _x: isize }, //~ ERROR: variant is never used: `Variant5` + Variant6(isize), //~ ERROR: variant is never used: `Variant6` _Variant7, } diff --git a/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs b/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs index efb284495648a..18159aec70844 100644 --- a/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs +++ b/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs @@ -16,7 +16,7 @@ // ignored. #[allow(dead_code)] -mod a { pub static x: int = 3; pub static y: int = 4; } +mod a { pub static x: isize = 3; pub static y: isize = 4; } mod b { use a::x; //~ ERROR: unused import diff --git a/src/test/compile-fail/lint-exceeding-bitshifts.rs b/src/test/compile-fail/lint-exceeding-bitshifts.rs index dbb65d8b7cefd..cbb416b62a6a2 100644 --- a/src/test/compile-fail/lint-exceeding-bitshifts.rs +++ b/src/test/compile-fail/lint-exceeding-bitshifts.rs @@ -56,7 +56,7 @@ fn main() { let n = 1u8 << (4+3); let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits - let n = 1i << std::int::BITS; //~ ERROR: bitshift exceeds the type's number of bits + let n = 1i << std::isize::BITS; //~ ERROR: bitshift exceeds the type's number of bits let n = 1u << std::uint::BITS; //~ ERROR: bitshift exceeds the type's number of bits } diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs index 63d65fc06aa4c..24d16bcaafc1a 100644 --- a/src/test/compile-fail/lint-group-style.rs +++ b/src/test/compile-fail/lint-group-style.rs @@ -24,7 +24,7 @@ mod test { mod bad { fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name - static bad: int = 1; //~ ERROR static constant `bad` should have an uppercase name + static bad: isize = 1; //~ ERROR static constant `bad` should have an uppercase name } mod warn { diff --git a/src/test/compile-fail/lint-impl-fn.rs b/src/test/compile-fail/lint-impl-fn.rs index eaef43a90836d..608aec327b63a 100644 --- a/src/test/compile-fail/lint-impl-fn.rs +++ b/src/test/compile-fail/lint-impl-fn.rs @@ -11,7 +11,7 @@ #![allow(while_true)] #![allow(dead_code)] -struct A(int); +struct A(isize); impl A { fn foo(&self) { while true {} } @@ -22,7 +22,7 @@ impl A { #[deny(while_true)] mod foo { - struct B(int); + struct B(isize); impl B { fn foo(&self) { while true {} } //~ ERROR: infinite loops diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index e50f636050c53..55103f10f2ce1 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -21,19 +21,19 @@ type Typedef = String; pub type PubTypedef = String; //~ ERROR: missing documentation struct Foo { - a: int, - b: int, + a: isize, + b: isize, } pub struct PubFoo { //~ ERROR: missing documentation - pub a: int, //~ ERROR: missing documentation - b: int, + pub a: isize, //~ ERROR: missing documentation + b: isize, } #[allow(missing_docs)] pub struct PubFoo2 { - pub a: int, - pub c: int, + pub a: isize, + pub c: isize, } mod module_no_dox {} @@ -100,15 +100,15 @@ mod a { enum Baz { BazA { - a: int, - b: int + a: isize, + b: isize }, BarB } pub enum PubBaz { //~ ERROR: missing documentation PubBazA { //~ ERROR: missing documentation - a: int, //~ ERROR: missing documentation + a: isize, //~ ERROR: missing documentation }, } @@ -117,14 +117,14 @@ pub enum PubBaz2 { /// dox PubBaz2A { /// dox - a: int, + a: isize, }, } #[allow(missing_docs)] pub enum PubBaz3 { PubBaz3A { - b: int + b: isize }, } diff --git a/src/test/compile-fail/lint-non-camel-case-types.rs b/src/test/compile-fail/lint-non-camel-case-types.rs index 6ce63e2ecdb77..70d6b240985b0 100644 --- a/src/test/compile-fail/lint-non-camel-case-types.rs +++ b/src/test/compile-fail/lint-non-camel-case-types.rs @@ -12,7 +12,7 @@ #![allow(dead_code)] struct foo { //~ ERROR type `foo` should have a camel case name such as `Foo` - bar: int, + bar: isize, } enum foo2 { //~ ERROR type `foo2` should have a camel case name such as `Foo2` @@ -20,10 +20,10 @@ enum foo2 { //~ ERROR type `foo2` should have a camel case name such as `Foo2` } struct foo3 { //~ ERROR type `foo3` should have a camel case name such as `Foo3` - bar: int + bar: isize } -type foo4 = int; //~ ERROR type `foo4` should have a camel case name such as `Foo4` +type foo4 = isize; //~ ERROR type `foo4` should have a camel case name such as `Foo4` enum Foo5 { bar //~ ERROR variant `bar` should have a camel case name such as `Bar` @@ -36,9 +36,9 @@ fn f(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name s #[repr(C)] struct foo7 { - bar: int, + bar: isize, } -type __ = int; //~ ERROR type `__` should have a camel case name such as `CamelCase` +type __ = isize; //~ ERROR type `__` should have a camel case name such as `CamelCase` fn main() { } diff --git a/src/test/compile-fail/lint-non-uppercase-statics.rs b/src/test/compile-fail/lint-non-uppercase-statics.rs index 7ff5cafd097a2..10475f967d716 100644 --- a/src/test/compile-fail/lint-non-uppercase-statics.rs +++ b/src/test/compile-fail/lint-non-uppercase-statics.rs @@ -11,6 +11,6 @@ #![forbid(non_upper_case_globals)] #![allow(dead_code)] -static foo: int = 1; //~ ERROR static constant `foo` should have an uppercase name such as `FOO` +static foo: isize = 1; //~ ERROR static constant `foo` should have an uppercase name such as `FOO` fn main() { } diff --git a/src/test/compile-fail/lint-owned-heap-memory.rs b/src/test/compile-fail/lint-owned-heap-memory.rs index 1702cefec6d3a..9c68da8beafd6 100644 --- a/src/test/compile-fail/lint-owned-heap-memory.rs +++ b/src/test/compile-fail/lint-owned-heap-memory.rs @@ -13,7 +13,7 @@ #![feature(box_syntax)] struct Foo { - x: Box //~ ERROR type uses owned + x: Box //~ ERROR type uses owned } fn main() { diff --git a/src/test/compile-fail/lint-raw-ptr-derive.rs b/src/test/compile-fail/lint-raw-ptr-derive.rs index 3198e782df893..9fcd6b33c9d56 100644 --- a/src/test/compile-fail/lint-raw-ptr-derive.rs +++ b/src/test/compile-fail/lint-raw-ptr-derive.rs @@ -13,21 +13,21 @@ #[derive(Clone)] struct Foo { - x: *const int //~ ERROR use of `#[derive]` with a raw pointer + x: *const isize //~ ERROR use of `#[derive]` with a raw pointer } #[derive(Clone)] -struct Bar(*mut int); //~ ERROR use of `#[derive]` with a raw pointer +struct Bar(*mut isize); //~ ERROR use of `#[derive]` with a raw pointer #[derive(Clone)] enum Baz { - A(*const int), //~ ERROR use of `#[derive]` with a raw pointer - B { x: *mut int } //~ ERROR use of `#[derive]` with a raw pointer + A(*const isize), //~ ERROR use of `#[derive]` with a raw pointer + B { x: *mut isize } //~ ERROR use of `#[derive]` with a raw pointer } #[derive(Clone)] struct Buzz { - x: (*const int, //~ ERROR use of `#[derive]` with a raw pointer + x: (*const isize, //~ ERROR use of `#[derive]` with a raw pointer *const uint) //~ ERROR use of `#[derive]` with a raw pointer } diff --git a/src/test/compile-fail/lint-shorthand-field.rs b/src/test/compile-fail/lint-shorthand-field.rs index eb4da4d66f33c..97a976a493f80 100644 --- a/src/test/compile-fail/lint-shorthand-field.rs +++ b/src/test/compile-fail/lint-shorthand-field.rs @@ -12,8 +12,8 @@ #![deny(non_shorthand_field_patterns)] struct Foo { - x: int, - y: int, + x: isize, + y: isize, } fn main() { @@ -30,7 +30,7 @@ fn main() { } { - const x: int = 1; + const x: isize = 1; match (Foo { x: 1, y: 1 }) { Foo { x: x, ..} => {}, diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 0e24269ec4449..b0a3a6bd10e7d 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -287,18 +287,18 @@ mod this_crate { impl Trait for MethodTester {} #[deprecated] - pub struct DeprecatedStruct { i: int } + pub struct DeprecatedStruct { i: isize } #[experimental] - pub struct ExperimentalStruct { i: int } + pub struct ExperimentalStruct { i: isize } #[unstable] - pub struct UnstableStruct { i: int } - pub struct UnmarkedStruct { i: int } + pub struct UnstableStruct { i: isize } + pub struct UnmarkedStruct { i: isize } #[stable] - pub struct StableStruct { i: int } + pub struct StableStruct { i: isize } #[frozen] - pub struct FrozenStruct { i: int } + pub struct FrozenStruct { i: isize } #[locked] - pub struct LockedStruct { i: int } + pub struct LockedStruct { i: isize } #[deprecated] pub struct DeprecatedUnitStruct; @@ -332,18 +332,18 @@ mod this_crate { } #[deprecated] - pub struct DeprecatedTupleStruct(int); + pub struct DeprecatedTupleStruct(isize); #[experimental] - pub struct ExperimentalTupleStruct(int); + pub struct ExperimentalTupleStruct(isize); #[unstable] - pub struct UnstableTupleStruct(int); - pub struct UnmarkedTupleStruct(int); + pub struct UnstableTupleStruct(isize); + pub struct UnmarkedTupleStruct(isize); #[stable] - pub struct StableTupleStruct(int); + pub struct StableTupleStruct(isize); #[frozen] - pub struct FrozenTupleStruct(int); + pub struct FrozenTupleStruct(isize); #[locked] - pub struct LockedTupleStruct(int); + pub struct LockedTupleStruct(isize); fn test() { // Only the deprecated cases of the following should generate diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs index 67ef9cd06803f..d5ea092617dc1 100644 --- a/src/test/compile-fail/lint-type-limits.rs +++ b/src/test/compile-fail/lint-type-limits.rs @@ -50,12 +50,12 @@ fn qux() { } fn quy() { - let i = -23u; //~ WARNING negation of unsigned int literal may be unintentional + let i = -23u; //~ WARNING negation of unsigned isize literal may be unintentional //~^ WARNING unused variable } fn quz() { let i = 23u; - let j = -i; //~ WARNING negation of unsigned int variable may be unintentional + let j = -i; //~ WARNING negation of unsigned isize variable may be unintentional //~^ WARNING unused variable } diff --git a/src/test/compile-fail/lint-unnecessary-parens.rs b/src/test/compile-fail/lint-unnecessary-parens.rs index 1c7a2d7e9d5e7..158f13bf3f174 100644 --- a/src/test/compile-fail/lint-unnecessary-parens.rs +++ b/src/test/compile-fail/lint-unnecessary-parens.rs @@ -16,7 +16,7 @@ impl X { fn foo(&self) -> bool { self.y } } -fn foo() -> int { +fn foo() -> isize { return (1i); //~ ERROR unnecessary parentheses around `return` value } fn bar() -> X { diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index b5c0dce6e531e..44579bb55e08a 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -43,7 +43,7 @@ mod test { } mod foo { - pub struct Point{pub x: int, pub y: int} + pub struct Point{pub x: isize, pub y: isize} pub struct Square{pub p: Point, pub h: uint, pub w: uint} } @@ -54,7 +54,7 @@ mod bar { pub mod c { use foo::Point; use foo::Square; //~ ERROR unused import - pub fn cc(p: Point) -> int { return 2i * (p.x + p.y); } + pub fn cc(p: Point) -> isize { return 2i * (p.x + p.y); } } #[allow(unused_imports)] diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 7513e1bc21a4a..4c1a01aac64c4 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -35,8 +35,8 @@ fn main() { _ => {} } - let x = |&: mut y: int| 10i; //~ ERROR: variable does not need to be mutable - fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable + let x = |&: mut y: isize| 10i; //~ ERROR: variable does not need to be mutable + fn what(mut foo: isize) {} //~ ERROR: variable does not need to be mutable // positive cases let mut a = 2i; @@ -65,8 +65,8 @@ fn main() { _ => {} } - let x = |&mut: mut y: int| y = 32i; - fn nothing(mut foo: int) { foo = 37i; } + let x = |&mut: mut y: isize| y = 32i; + fn nothing(mut foo: isize) { foo = 37i; } // leading underscore should avoid the warning, just like the // unused variable lint. @@ -77,7 +77,7 @@ fn callback(f: F) where F: FnOnce() {} // make sure the lint attribute can be turned off #[allow(unused_mut)] -fn foo(mut a: int) { +fn foo(mut a: isize) { let mut a = 3i; let mut b = vec!(2i); } diff --git a/src/test/compile-fail/lint-visible-private-types.rs b/src/test/compile-fail/lint-visible-private-types.rs index 373bcb1f85913..8cf375f80fbb1 100644 --- a/src/test/compile-fail/lint-visible-private-types.rs +++ b/src/test/compile-fail/lint-visible-private-types.rs @@ -15,108 +15,108 @@ struct Private; pub struct Public; -impl Private> { - pub fn a(&self) -> Private { panic!() } - fn b(&self) -> Private { panic!() } +impl Private> { + pub fn a(&self) -> Private { panic!() } + fn b(&self) -> Private { panic!() } - pub fn c() -> Private { panic!() } - fn d() -> Private { panic!() } + pub fn c() -> Private { panic!() } + fn d() -> Private { panic!() } } -impl Private { - pub fn e(&self) -> Private { panic!() } - fn f(&self) -> Private { panic!() } +impl Private { + pub fn e(&self) -> Private { panic!() } + fn f(&self) -> Private { panic!() } } -impl Public> { - pub fn a(&self) -> Private { panic!() } - fn b(&self) -> Private { panic!() } +impl Public> { + pub fn a(&self) -> Private { panic!() } + fn b(&self) -> Private { panic!() } - pub fn c() -> Private { panic!() } //~ ERROR private type in exported type signature - fn d() -> Private { panic!() } + pub fn c() -> Private { panic!() } //~ ERROR private type in exported type signature + fn d() -> Private { panic!() } } -impl Public { - pub fn e(&self) -> Private { panic!() } //~ ERROR private type in exported type signature - fn f(&self) -> Private { panic!() } +impl Public { + pub fn e(&self) -> Private { panic!() } //~ ERROR private type in exported type signature + fn f(&self) -> Private { panic!() } } -pub fn x(_: Private) {} //~ ERROR private type in exported type signature +pub fn x(_: Private) {} //~ ERROR private type in exported type signature -fn y(_: Private) {} +fn y(_: Private) {} pub struct Foo { - pub x: Private, //~ ERROR private type in exported type signature - y: Private + pub x: Private, //~ ERROR private type in exported type signature + y: Private } struct Bar { - x: Private, + x: Private, } pub enum Baz { - Baz1(Private), //~ ERROR private type in exported type signature + Baz1(Private), //~ ERROR private type in exported type signature Baz2 { - y: Private //~ ERROR private type in exported type signature + y: Private //~ ERROR private type in exported type signature }, } enum Qux { - Qux1(Private), + Qux1(Private), Qux2 { - x: Private, + x: Private, } } pub trait PubTrait { - fn foo(&self) -> Private { panic!( )} //~ ERROR private type in exported type signature - fn bar(&self) -> Private; //~ ERROR private type in exported type signature - fn baz() -> Private; //~ ERROR private type in exported type signature + fn foo(&self) -> Private { panic!( )} //~ ERROR private type in exported type signature + fn bar(&self) -> Private; //~ ERROR private type in exported type signature + fn baz() -> Private; //~ ERROR private type in exported type signature } -impl PubTrait for Public { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } +impl PubTrait for Public { + fn bar(&self) -> Private { panic!() } + fn baz() -> Private { panic!() } } -impl PubTrait for Public> { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } +impl PubTrait for Public> { + fn bar(&self) -> Private { panic!() } + fn baz() -> Private { panic!() } } -impl PubTrait for Private { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } +impl PubTrait for Private { + fn bar(&self) -> Private { panic!() } + fn baz() -> Private { panic!() } } -impl PubTrait for (Private,) { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } +impl PubTrait for (Private,) { + fn bar(&self) -> Private { panic!() } + fn baz() -> Private { panic!() } } trait PrivTrait { - fn foo(&self) -> Private { panic!( )} - fn bar(&self) -> Private; + fn foo(&self) -> Private { panic!( )} + fn bar(&self) -> Private; } -impl PrivTrait for Private { - fn bar(&self) -> Private { panic!() } +impl PrivTrait for Private { + fn bar(&self) -> Private { panic!() } } -impl PrivTrait for (Private,) { - fn bar(&self) -> Private { panic!() } +impl PrivTrait for (Private,) { + fn bar(&self) -> Private { panic!() } } pub trait ParamTrait { fn foo() -> T; } -impl ParamTrait> //~ ERROR private type in exported type signature - for Public { - fn foo() -> Private { panic!() } +impl ParamTrait> //~ ERROR private type in exported type signature + for Public { + fn foo() -> Private { panic!() } } -impl ParamTrait> for Private { - fn foo() -> Private { panic!( )} +impl ParamTrait> for Private { + fn foo() -> Private { panic!( )} } -impl>> //~ ERROR private type in exported type signature +impl>> //~ ERROR private type in exported type signature ParamTrait for Public { fn foo() -> T { panic!() } } diff --git a/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs b/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs index f8afc10c49b9d..f50a934510697 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-in-loop.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test() { - let v: int; + let v: isize; loop { v = 1; //~ ERROR re-assignment of immutable variable //~^ NOTE prior assignment occurs here diff --git a/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs b/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs index 43d7ca8375328..df57bb9e4417e 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test() { - let v: int; + let v: isize; v = 2; //~ NOTE prior assignment occurs here v += 1; //~ ERROR re-assignment of immutable variable v.clone(); diff --git a/src/test/compile-fail/liveness-assign-imm-local-with-init.rs b/src/test/compile-fail/liveness-assign-imm-local-with-init.rs index 8eb84525b8396..28218bff60d68 100644 --- a/src/test/compile-fail/liveness-assign-imm-local-with-init.rs +++ b/src/test/compile-fail/liveness-assign-imm-local-with-init.rs @@ -9,7 +9,7 @@ // except according to those terms. fn test() { - let v: int = 1; //~ NOTE prior assignment occurs here + let v: isize = 1; //~ NOTE prior assignment occurs here v.clone(); v = 2; //~ ERROR re-assignment of immutable variable v.clone(); diff --git a/src/test/compile-fail/liveness-closure-require-ret.rs b/src/test/compile-fail/liveness-closure-require-ret.rs index 82de02f09813c..17cd8231222f2 100644 --- a/src/test/compile-fail/liveness-closure-require-ret.rs +++ b/src/test/compile-fail/liveness-closure-require-ret.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn force(f: F) -> int where F: FnOnce() -> int { f() } +fn force(f: F) -> isize where F: FnOnce() -> isize { f() } fn main() { println!("{}", force(|| {})); } //~ ERROR mismatched types diff --git a/src/test/compile-fail/liveness-dead.rs b/src/test/compile-fail/liveness-dead.rs index 18baf7a9c3f75..dc7b0fc4fd0f2 100644 --- a/src/test/compile-fail/liveness-dead.rs +++ b/src/test/compile-fail/liveness-dead.rs @@ -11,18 +11,18 @@ #![allow(dead_code)] #![deny(unused_assignments)] -fn f1(x: &mut int) { +fn f1(x: &mut isize) { *x = 1; // no error } fn f2() { - let mut x: int = 3; //~ ERROR: value assigned to `x` is never read + let mut x: isize = 3; //~ ERROR: value assigned to `x` is never read x = 4; x.clone(); } fn f3() { - let mut x: int = 3; + let mut x: isize = 3; x.clone(); x = 4; //~ ERROR: value assigned to `x` is never read } diff --git a/src/test/compile-fail/liveness-forgot-ret.rs b/src/test/compile-fail/liveness-forgot-ret.rs index 305cbcad73837..e08515e40af78 100644 --- a/src/test/compile-fail/liveness-forgot-ret.rs +++ b/src/test/compile-fail/liveness-forgot-ret.rs @@ -10,8 +10,8 @@ // error-pattern: not all control paths return a value -fn god_exists(a: int) -> bool { return god_exists(a); } +fn god_exists(a: isize) -> bool { return god_exists(a); } -fn f(a: int) -> int { if god_exists(a) { return 5; }; } +fn f(a: isize) -> isize { if god_exists(a) { return 5; }; } fn main() { f(12); } diff --git a/src/test/compile-fail/liveness-issue-2163.rs b/src/test/compile-fail/liveness-issue-2163.rs index e46d00c4ab9f6..69bceec8c3225 100644 --- a/src/test/compile-fail/liveness-issue-2163.rs +++ b/src/test/compile-fail/liveness-issue-2163.rs @@ -11,7 +11,7 @@ use std::vec::Vec; fn main() { - let a: Vec = Vec::new(); + let a: Vec = Vec::new(); a.iter().all(|_| -> bool { //~^ ERROR mismatched types }); diff --git a/src/test/compile-fail/liveness-missing-ret2.rs b/src/test/compile-fail/liveness-missing-ret2.rs index 541e8ec97fa6c..b53bb6159e8dd 100644 --- a/src/test/compile-fail/liveness-missing-ret2.rs +++ b/src/test/compile-fail/liveness-missing-ret2.rs @@ -10,7 +10,7 @@ // error-pattern: not all control paths return a value -fn f() -> int { +fn f() -> isize { // Make sure typestate doesn't interpret this match expression as // the function result match true { true => { } _ => {} }; diff --git a/src/test/compile-fail/liveness-move-call-arg.rs b/src/test/compile-fail/liveness-move-call-arg.rs index 08a523fb8ffb2..9340964c1fb0d 100644 --- a/src/test/compile-fail/liveness-move-call-arg.rs +++ b/src/test/compile-fail/liveness-move-call-arg.rs @@ -10,11 +10,11 @@ #![feature(box_syntax)] -fn take(_x: Box) {} +fn take(_x: Box) {} fn main() { - let x: Box = box 25; + let x: Box = box 25; loop { take(x); //~ ERROR use of moved value: `x` } diff --git a/src/test/compile-fail/liveness-move-in-loop.rs b/src/test/compile-fail/liveness-move-in-loop.rs index b2142258fb01d..65ccaceac0821 100644 --- a/src/test/compile-fail/liveness-move-in-loop.rs +++ b/src/test/compile-fail/liveness-move-in-loop.rs @@ -11,8 +11,8 @@ #![feature(box_syntax)] fn main() { - let y: Box = box 42; - let mut x: Box; + let y: Box = box 42; + let mut x: Box; loop { println!("{}", y); loop { diff --git a/src/test/compile-fail/liveness-move-in-while.rs b/src/test/compile-fail/liveness-move-in-while.rs index 549cf523d0329..cadfd48712111 100644 --- a/src/test/compile-fail/liveness-move-in-while.rs +++ b/src/test/compile-fail/liveness-move-in-while.rs @@ -11,8 +11,8 @@ #![feature(box_syntax)] fn main() { - let y: Box = box 42; - let mut x: Box; + let y: Box = box 42; + let mut x: Box; loop { println!("{}", y); //~ ERROR use of moved value: `y` while true { while true { while true { x = y; x.clone(); } } } diff --git a/src/test/compile-fail/liveness-return-last-stmt-semi.rs b/src/test/compile-fail/liveness-return-last-stmt-semi.rs index 9cfffb5fa6b62..b274ad9f3d4ba 100644 --- a/src/test/compile-fail/liveness-return-last-stmt-semi.rs +++ b/src/test/compile-fail/liveness-return-last-stmt-semi.rs @@ -10,11 +10,11 @@ // // regression test for #8005 -macro_rules! test { () => { fn foo() -> int { 1i; } } } +macro_rules! test { () => { fn foo() -> isize { 1i; } } } //~^ ERROR not all control paths return a value //~^^ HELP consider removing this semicolon -fn no_return() -> int {} //~ ERROR not all control paths return a value +fn no_return() -> isize {} //~ ERROR not all control paths return a value fn bar(x: u32) -> u32 { //~ ERROR not all control paths return a value x * 2; //~ HELP consider removing this semicolon diff --git a/src/test/compile-fail/liveness-unused.rs b/src/test/compile-fail/liveness-unused.rs index e93872eba0c3e..0971709229bc5 100644 --- a/src/test/compile-fail/liveness-unused.rs +++ b/src/test/compile-fail/liveness-unused.rs @@ -12,19 +12,19 @@ #![deny(unused_assignments)] #![allow(dead_code, non_camel_case_types)] -fn f1(x: int) { +fn f1(x: isize) { //~^ ERROR unused variable: `x` } -fn f1b(x: &mut int) { +fn f1b(x: &mut isize) { //~^ ERROR unused variable: `x` } #[allow(unused_variables)] -fn f1c(x: int) {} +fn f1c(x: isize) {} fn f1d() { - let x: int; + let x: isize; //~^ ERROR unused variable: `x` } @@ -71,10 +71,10 @@ fn f4() { } enum tri { - a(int), b(int), c(int) + a(isize), b(isize), c(isize) } -fn f4b() -> int { +fn f4b() -> isize { match tri::a(3i) { tri::a(i) | tri::b(i) | tri::c(i) => { i diff --git a/src/test/compile-fail/liveness-use-after-send.rs b/src/test/compile-fail/liveness-use-after-send.rs index 44d45463f19f0..4ba24800f5d33 100644 --- a/src/test/compile-fail/liveness-use-after-send.rs +++ b/src/test/compile-fail/liveness-use-after-send.rs @@ -15,11 +15,11 @@ fn send(ch: _chan, data: T) { } #[derive(Show)] -struct _chan(int); +struct _chan(isize); // Tests that "log(debug, message);" is flagged as using // message after the send deinitializes it -fn test00_start(ch: _chan>, message: Box, _count: Box) { +fn test00_start(ch: _chan>, message: Box, _count: Box) { send(ch, message); println!("{}", message); //~ ERROR use of moved value: `message` } diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs index ae990880523f9..d9c617a71720e 100644 --- a/src/test/compile-fail/main-wrong-type.rs +++ b/src/test/compile-fail/main-wrong-type.rs @@ -9,8 +9,8 @@ // except according to those terms. struct S { - x: int, - y: int, + x: isize, + y: isize, } fn main(foo: S) { diff --git a/src/test/compile-fail/match-join.rs b/src/test/compile-fail/match-join.rs index e78561b9fdb68..4ec426fd3aa8b 100644 --- a/src/test/compile-fail/match-join.rs +++ b/src/test/compile-fail/match-join.rs @@ -17,5 +17,5 @@ fn main() { match true { false => { my_panic(); } true => { } } println!("{}", x); //~ ERROR unresolved name `x` - let x: int; + let x: isize; } diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index 15a832aad89ad..345c4aa69a720 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -14,7 +14,7 @@ #![deny(non_upper_case_globals)] #[allow(non_upper_case_globals)] -pub const a : int = 97; +pub const a : isize = 97; fn f() { let r = match (0,0) { @@ -27,7 +27,7 @@ fn f() { mod m { #[allow(non_upper_case_globals)] - pub const aha : int = 7; + pub const aha : isize = 7; } fn g() { @@ -41,7 +41,7 @@ fn g() { } mod n { - pub const OKAY : int = 8; + pub const OKAY : isize = 8; } fn h() { diff --git a/src/test/compile-fail/match-struct.rs b/src/test/compile-fail/match-struct.rs index 65082f93d3536..e3b47372a4f40 100644 --- a/src/test/compile-fail/match-struct.rs +++ b/src/test/compile-fail/match-struct.rs @@ -9,8 +9,8 @@ // except according to those terms. -struct S { a: int } -enum E { C(int) } +struct S { a: isize } +enum E { C(isize) } fn main() { match (S { a: 1 }) { diff --git a/src/test/compile-fail/match-tag-unary.rs b/src/test/compile-fail/match-tag-unary.rs index 89012e42bdcc0..48733fd423d46 100644 --- a/src/test/compile-fail/match-tag-unary.rs +++ b/src/test/compile-fail/match-tag-unary.rs @@ -10,7 +10,7 @@ // error-pattern: mismatched types -enum a { A(int), } -enum b { B(int), } +enum a { A(isize), } +enum b { B(isize), } fn main() { let x: a = a::A(0); match x { b::B(y) => { } } } diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index a85ce660e8b1f..e2671552b4349 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -10,8 +10,8 @@ fn main() { - let x: Vec<(int, int)> = Vec::new(); - let x: &[(int, int)] = x.as_slice(); + let x: Vec<(isize, isize)> = Vec::new(); + let x: &[(isize, isize)] = x.as_slice(); match x { [a, (2, 3), _] => (), [(1, 2), (2, 3), b] => (), //~ ERROR unreachable pattern diff --git a/src/test/compile-fail/method-ambig-one-trait-coerce.rs b/src/test/compile-fail/method-ambig-one-trait-coerce.rs index 5e3206ea51696..cb5da4bb54772 100644 --- a/src/test/compile-fail/method-ambig-one-trait-coerce.rs +++ b/src/test/compile-fail/method-ambig-one-trait-coerce.rs @@ -15,15 +15,15 @@ trait Object { } trait foo { - fn foo(self) -> int; + fn foo(self) -> isize; } impl foo for Box { - fn foo(self) -> int {1} + fn foo(self) -> isize {1} } impl foo for Box { - fn foo(self) -> int {2} + fn foo(self) -> isize {2} } fn test1(x: Box) { diff --git a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs index e211db2dcd296..f0cc7c80417e0 100644 --- a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs +++ b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs @@ -13,15 +13,15 @@ // of what kind of `Vec` we have, eventually leading to a type error. trait foo { - fn foo(&self) -> int; + fn foo(&self) -> isize; } impl foo for Vec { - fn foo(&self) -> int {1} + fn foo(&self) -> isize {1} } -impl foo for Vec { - fn foo(&self) -> int {2} +impl foo for Vec { + fn foo(&self) -> isize {2} } // This is very hokey: we have heuristics to suppress messages about diff --git a/src/test/compile-fail/method-call-err-msg.rs b/src/test/compile-fail/method-call-err-msg.rs index 3610a0e2e9d90..2f82441762f75 100644 --- a/src/test/compile-fail/method-call-err-msg.rs +++ b/src/test/compile-fail/method-call-err-msg.rs @@ -13,8 +13,8 @@ pub struct Foo; impl Foo { fn zero(self) -> Foo { self } - fn one(self, _: int) -> Foo { self } - fn two(self, _: int, _: int) -> Foo { self } + fn one(self, _: isize) -> Foo { self } + fn two(self, _: isize, _: isize) -> Foo { self } } fn main() { diff --git a/src/test/compile-fail/method-missing-call.rs b/src/test/compile-fail/method-missing-call.rs index ddfa447f60e22..83418cbc104cb 100644 --- a/src/test/compile-fail/method-missing-call.rs +++ b/src/test/compile-fail/method-missing-call.rs @@ -14,21 +14,21 @@ struct Point { - x: int, - y: int + x: isize, + y: isize } impl Point { fn new() -> Point { Point{x:0, y:0} } - fn get_x(&self) -> int { + fn get_x(&self) -> isize { self.x } } fn main() { let point: Point = Point::new(); - let px: int = point + let px: isize = point .get_x;//~ ERROR attempted to take value of method `get_x` on type `Point` //~^ HELP maybe a `()` to call it is missing diff --git a/src/test/compile-fail/missing-derivable-attr.rs b/src/test/compile-fail/missing-derivable-attr.rs index db960ac340913..7eee51e40764e 100644 --- a/src/test/compile-fail/missing-derivable-attr.rs +++ b/src/test/compile-fail/missing-derivable-attr.rs @@ -13,11 +13,11 @@ trait MyEq { } struct A { - x: int + x: isize } -impl MyEq for int { - fn eq(&self, other: &int) -> bool { *self == *other } +impl MyEq for isize { + fn eq(&self, other: &isize) -> bool { *self == *other } } impl MyEq for A {} //~ ERROR not all trait items implemented, missing: `eq` diff --git a/src/test/compile-fail/missing-return.rs b/src/test/compile-fail/missing-return.rs index 1dc817cc6e6be..efd0c827a35f7 100644 --- a/src/test/compile-fail/missing-return.rs +++ b/src/test/compile-fail/missing-return.rs @@ -10,6 +10,6 @@ // error-pattern: return -fn f() -> int { } +fn f() -> isize { } fn main() { f(); } diff --git a/src/test/compile-fail/mod_file_aux.rs b/src/test/compile-fail/mod_file_aux.rs index 4d18decdc13a4..b7470811f6034 100644 --- a/src/test/compile-fail/mod_file_aux.rs +++ b/src/test/compile-fail/mod_file_aux.rs @@ -10,4 +10,4 @@ // ignore-test Not a test. Used by other tests -pub fn foo() -> int { 10 } +pub fn foo() -> isize { 10 } diff --git a/src/test/compile-fail/move-fragments-1.rs b/src/test/compile-fail/move-fragments-1.rs index e45862a7fc6e4..3f14be2da109a 100644 --- a/src/test/compile-fail/move-fragments-1.rs +++ b/src/test/compile-fail/move-fragments-1.rs @@ -18,7 +18,7 @@ // These are all fairly trivial cases: unused variables or direct // drops of substructure. -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } #[rustc_move_fragments] diff --git a/src/test/compile-fail/move-fragments-2.rs b/src/test/compile-fail/move-fragments-2.rs index ceb1d5a0f0910..6c0635d6be931 100644 --- a/src/test/compile-fail/move-fragments-2.rs +++ b/src/test/compile-fail/move-fragments-2.rs @@ -20,7 +20,7 @@ use self::Lonely::{Zero, One, Two}; -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub enum Lonely { Zero, One(X), Two(X, Y) } diff --git a/src/test/compile-fail/move-fragments-3.rs b/src/test/compile-fail/move-fragments-3.rs index 4540b0c5a9132..24d73ec2274ba 100644 --- a/src/test/compile-fail/move-fragments-3.rs +++ b/src/test/compile-fail/move-fragments-3.rs @@ -20,7 +20,7 @@ use self::Lonely::{Zero, One, Two}; -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub enum Lonely { Zero, One(X), Two(X, Y) } diff --git a/src/test/compile-fail/move-fragments-4.rs b/src/test/compile-fail/move-fragments-4.rs index dc43dcb9b0e23..97e8e45ed0656 100644 --- a/src/test/compile-fail/move-fragments-4.rs +++ b/src/test/compile-fail/move-fragments-4.rs @@ -19,7 +19,7 @@ // early draft of the code did not properly traverse up through all of // the parents of the leaf fragment.) -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub struct Pair { x: X, y: Y } diff --git a/src/test/compile-fail/move-fragments-5.rs b/src/test/compile-fail/move-fragments-5.rs index bef2f12d642bd..9f70421fa8425 100644 --- a/src/test/compile-fail/move-fragments-5.rs +++ b/src/test/compile-fail/move-fragments-5.rs @@ -17,7 +17,7 @@ // This is the first test that checks moving into local variables. -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub struct Pair { x: X, y: Y } diff --git a/src/test/compile-fail/move-fragments-7.rs b/src/test/compile-fail/move-fragments-7.rs index 6b2c77bcac15e..2af2b2957f8d6 100644 --- a/src/test/compile-fail/move-fragments-7.rs +++ b/src/test/compile-fail/move-fragments-7.rs @@ -19,7 +19,7 @@ // both moving out of the structure (i.e. reading `*p.x`) and writing // into the container (i.e. writing `*p.x`). -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub struct Pair { x: X, y: Y } diff --git a/src/test/compile-fail/move-fragments-8.rs b/src/test/compile-fail/move-fragments-8.rs index 40ab541128c3f..18bf4066076ba 100644 --- a/src/test/compile-fail/move-fragments-8.rs +++ b/src/test/compile-fail/move-fragments-8.rs @@ -22,7 +22,7 @@ // also that in this case we cannot do a move out of `&T`, so we only // test writing `*p.x` here. -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } pub struct Pair { x: X, y: Y } diff --git a/src/test/compile-fail/move-fragments-9.rs b/src/test/compile-fail/move-fragments-9.rs index 0b095ff6f820d..4dd6c5eb4e644 100644 --- a/src/test/compile-fail/move-fragments-9.rs +++ b/src/test/compile-fail/move-fragments-9.rs @@ -14,7 +14,7 @@ // Note also that the `test_move_array_then_overwrite` tests represent // cases that we probably should make illegal. -pub struct D { d: int } +pub struct D { d: isize } impl Drop for D { fn drop(&mut self) { } } #[rustc_move_fragments] diff --git a/src/test/compile-fail/move-out-of-tuple-field.rs b/src/test/compile-fail/move-out-of-tuple-field.rs index 78b6736c1c86d..ca09d43d79c9d 100644 --- a/src/test/compile-fail/move-out-of-tuple-field.rs +++ b/src/test/compile-fail/move-out-of-tuple-field.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -struct Foo(Box); +struct Foo(Box); fn main() { let x = (box 1i,); diff --git a/src/test/compile-fail/moves-based-on-type-access-to-field.rs b/src/test/compile-fail/moves-based-on-type-access-to-field.rs index c9efce0d68478..b8572fbd2150d 100644 --- a/src/test/compile-fail/moves-based-on-type-access-to-field.rs +++ b/src/test/compile-fail/moves-based-on-type-access-to-field.rs @@ -11,7 +11,7 @@ // Tests that if you move from `x.f` or `x[0]`, `x` is inaccessible. // Also tests that we give a more specific error message. -struct Foo { f: String, y: int } +struct Foo { f: String, y: isize } fn consume(_s: String) {} fn touch(_a: &A) {} diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index 379397f22bd61..179c71d3659f2 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -18,7 +18,7 @@ struct S { enum E { Foo(Box), - Bar(Box), + Bar(Box), Baz } diff --git a/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs b/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs index 805c82f03f94c..865784c2f1eed 100644 --- a/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs +++ b/src/test/compile-fail/moves-based-on-type-cyclic-types-issue-4821.rs @@ -13,9 +13,9 @@ // See middle::ty::type_contents() for more information. -struct List { key: int, next: Option> } +struct List { key: isize, next: Option> } -fn foo(node: Box) -> int { +fn foo(node: Box) -> isize { let r = match node.next { Some(right) => consume(right), None => 0 @@ -23,7 +23,7 @@ fn foo(node: Box) -> int { consume(node) + r //~ ERROR use of partially moved value: `node` } -fn consume(v: Box) -> int { +fn consume(v: Box) -> isize { v.key } diff --git a/src/test/compile-fail/moves-based-on-type-tuple.rs b/src/test/compile-fail/moves-based-on-type-tuple.rs index 397b22c486e77..30388f9d2f7e5 100644 --- a/src/test/compile-fail/moves-based-on-type-tuple.rs +++ b/src/test/compile-fail/moves-based-on-type-tuple.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn dup(x: Box) -> Box<(Box,Box)> { box() (x, x) } //~ ERROR use of moved value +fn dup(x: Box) -> Box<(Box,Box)> { box() (x, x) } //~ ERROR use of moved value fn main() { dup(box 3); } diff --git a/src/test/compile-fail/moves-sru-moved-field.rs b/src/test/compile-fail/moves-sru-moved-field.rs index 6c351f887132d..15977fbeb734d 100644 --- a/src/test/compile-fail/moves-sru-moved-field.rs +++ b/src/test/compile-fail/moves-sru-moved-field.rs @@ -10,11 +10,11 @@ #![feature(box_syntax)] -type Noncopyable = Box; +type Noncopyable = Box; struct Foo { - copied: int, - moved: Box, + copied: isize, + moved: Box, noncopyable: Noncopyable } diff --git a/src/test/compile-fail/multitrait.rs b/src/test/compile-fail/multitrait.rs index 7add747fbfa53..a0e210aed40e6 100644 --- a/src/test/compile-fail/multitrait.rs +++ b/src/test/compile-fail/multitrait.rs @@ -9,7 +9,7 @@ // except according to those terms. struct S { - y: int + y: isize } impl Cmp, ToString for S { //~ ERROR: expected one of `(`, `+`, `::`, or `{`, found `,` diff --git a/src/test/compile-fail/mut-cross-borrowing.rs b/src/test/compile-fail/mut-cross-borrowing.rs index 90bc0019531b3..ee4d11c96cacf 100644 --- a/src/test/compile-fail/mut-cross-borrowing.rs +++ b/src/test/compile-fail/mut-cross-borrowing.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -fn f(_: &mut int) {} +fn f(_: &mut isize) {} fn main() { let mut x = box 3i; diff --git a/src/test/compile-fail/mut-patterns.rs b/src/test/compile-fail/mut-patterns.rs index a78e82bb73ca4..cde05bc1d524e 100644 --- a/src/test/compile-fail/mut-patterns.rs +++ b/src/test/compile-fail/mut-patterns.rs @@ -11,6 +11,6 @@ // Can't put mut in non-ident pattern pub fn main() { - struct Foo { x: int } + struct Foo { x: isize } let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected one of `:`, `;`, `=`, or `@`, found `{` } diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 377c745acf321..3d8b095cb4eec 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -11,7 +11,7 @@ struct cat { meows : uint, - how_hungry : int, + how_hungry : isize, } impl cat { @@ -21,7 +21,7 @@ impl cat { } -fn cat(in_x : uint, in_y : int) -> cat { +fn cat(in_x : uint, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/mutable-class-fields.rs b/src/test/compile-fail/mutable-class-fields.rs index 4d77d1824ab82..b2a76d8fd3785 100644 --- a/src/test/compile-fail/mutable-class-fields.rs +++ b/src/test/compile-fail/mutable-class-fields.rs @@ -10,10 +10,10 @@ struct cat { meows : uint, - how_hungry : int, + how_hungry : isize, } -fn cat(in_x : uint, in_y : int) -> cat { +fn cat(in_x : uint, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/name-clash-nullary.rs b/src/test/compile-fail/name-clash-nullary.rs index 2f0588b261e54..1250318a7291d 100644 --- a/src/test/compile-fail/name-clash-nullary.rs +++ b/src/test/compile-fail/name-clash-nullary.rs @@ -12,6 +12,6 @@ use std::option::*; fn main() { - let None: int = 42; + let None: isize = 42; log(debug, None); } diff --git a/src/test/compile-fail/namespaced-enum-glob-import-no-impls.rs b/src/test/compile-fail/namespaced-enum-glob-import-no-impls.rs index 602ec9ba76280..4437482fb67cc 100644 --- a/src/test/compile-fail/namespaced-enum-glob-import-no-impls.rs +++ b/src/test/compile-fail/namespaced-enum-glob-import-no-impls.rs @@ -11,8 +11,8 @@ mod m2 { pub enum Foo { A, - B(int), - C { a: int }, + B(isize), + C { a: isize }, } impl Foo { diff --git a/src/test/compile-fail/no_send-struct.rs b/src/test/compile-fail/no_send-struct.rs index c2d6f04c7d49c..bef7052378726 100644 --- a/src/test/compile-fail/no_send-struct.rs +++ b/src/test/compile-fail/no_send-struct.rs @@ -11,7 +11,7 @@ use std::marker; struct Foo { - a: int, + a: isize, ns: marker::NoSend } diff --git a/src/test/compile-fail/no_share-struct.rs b/src/test/compile-fail/no_share-struct.rs index 59864b63b0494..c7028ce978698 100644 --- a/src/test/compile-fail/no_share-struct.rs +++ b/src/test/compile-fail/no_share-struct.rs @@ -10,7 +10,7 @@ use std::marker; -struct Foo { a: int, m: marker::NoSync } +struct Foo { a: isize, m: marker::NoSync } fn bar(_: T) {} diff --git a/src/test/compile-fail/noexporttypeexe.rs b/src/test/compile-fail/noexporttypeexe.rs index 4081792b6544a..8fa4e81c88955 100644 --- a/src/test/compile-fail/noexporttypeexe.rs +++ b/src/test/compile-fail/noexporttypeexe.rs @@ -17,6 +17,6 @@ fn main() { // This used to cause internal errors when serializing // because the def_id associated with the type was // not convertible to a path. - let x: int = noexporttypelib::foo(); + let x: isize = noexporttypelib::foo(); //~^ ERROR expected `isize`, found `core::option::Option` } diff --git a/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs index 85d734ddaf2b9..14d2c8d0326a1 100644 --- a/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs +++ b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs @@ -11,8 +11,8 @@ // Check that non-constant exprs do fail as count in fixed length vec type fn main() { - fn bar(n: int) { - let _x: [int; n]; + fn bar(n: isize) { + let _x: [isize; n]; //~^ ERROR expected constant expr for array length: non-constant path in constant expr } } diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs index cd134ccf71d7e..40b641519b06d 100644 --- a/src/test/compile-fail/non-copyable-void.rs +++ b/src/test/compile-fail/non-copyable-void.rs @@ -11,7 +11,7 @@ extern crate libc; fn main() { - let x : *const Vec = &vec!(1,2,3); + let x : *const Vec = &vec!(1,2,3); let y : *const libc::c_void = x as *const libc::c_void; unsafe { let _z = (*y).clone(); diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs index 8fcf10f1c356d..4c421a689ee39 100644 --- a/src/test/compile-fail/non-exhaustive-match.rs +++ b/src/test/compile-fail/non-exhaustive-match.rs @@ -36,14 +36,14 @@ fn main() { (t::b, t::b) => {} } let vec = vec!(Some(42i), None, Some(21i)); - let vec: &[Option] = vec.as_slice(); + let vec: &[Option] = vec.as_slice(); match vec { //~ ERROR non-exhaustive patterns: `[]` not covered [Some(..), None, tail..] => {} [Some(..), Some(..), tail..] => {} [None] => {} } let vec = vec!(1i); - let vec: &[int] = vec.as_slice(); + let vec: &[isize] = vec.as_slice(); match vec { [_, tail..] => (), [] => () @@ -57,7 +57,7 @@ fn main() { [] => () } let vec = vec!(Some(42i), None, Some(21i)); - let vec: &[Option] = vec.as_slice(); + let vec: &[Option] = vec.as_slice(); match vec { [Some(..), None, tail..] => {} [Some(..), Some(..), tail..] => {} diff --git a/src/test/compile-fail/noncopyable-class.rs b/src/test/compile-fail/noncopyable-class.rs index ec8369d6736fb..029b848599309 100644 --- a/src/test/compile-fail/noncopyable-class.rs +++ b/src/test/compile-fail/noncopyable-class.rs @@ -13,14 +13,14 @@ #[derive(Show)] struct bar { - x: int, + x: isize, } impl Drop for bar { fn drop(&mut self) {} } -fn bar(x:int) -> bar { +fn bar(x:isize) -> bar { bar { x: x } @@ -28,11 +28,11 @@ fn bar(x:int) -> bar { #[derive(Show)] struct foo { - i: int, + i: isize, j: bar, } -fn foo(i:int) -> foo { +fn foo(i:isize) -> foo { foo { i: i, j: bar(5) diff --git a/src/test/compile-fail/nonscalar-cast.rs b/src/test/compile-fail/nonscalar-cast.rs index 728f66a6aa76c..f32c96b7b6430 100644 --- a/src/test/compile-fail/nonscalar-cast.rs +++ b/src/test/compile-fail/nonscalar-cast.rs @@ -12,9 +12,9 @@ #[derive(Show)] struct foo { - x: int + x: isize } fn main() { - println!("{}", foo{ x: 1 } as int); + println!("{}", foo{ x: 1 } as isize); } diff --git a/src/test/compile-fail/not-a-pred.rs b/src/test/compile-fail/not-a-pred.rs index 2e16c58eaad93..782c90a6c26b0 100644 --- a/src/test/compile-fail/not-a-pred.rs +++ b/src/test/compile-fail/not-a-pred.rs @@ -10,8 +10,8 @@ // error-pattern: lt -fn f(a: int, b: int) : lt(a, b) { } +fn f(a: isize, b: isize) : lt(a, b) { } -fn lt(a: int, b: int) { } +fn lt(a: isize, b: isize) { } -fn main() { let a: int = 10; let b: int = 23; check (lt(a, b)); f(a, b); } +fn main() { let a: isize = 10; let b: isize = 23; check (lt(a, b)); f(a, b); } diff --git a/src/test/compile-fail/not-enough-arguments.rs b/src/test/compile-fail/not-enough-arguments.rs index 2deb9591a834d..c952906e5e89a 100644 --- a/src/test/compile-fail/not-enough-arguments.rs +++ b/src/test/compile-fail/not-enough-arguments.rs @@ -12,7 +12,7 @@ // mismatch between the # of params, and not other // unrelated errors. -fn foo(a: int, b: int, c: int, d:int) { +fn foo(a: isize, b: isize, c: isize, d:isize) { panic!(); } diff --git a/src/test/compile-fail/obsolete-tilde.rs b/src/test/compile-fail/obsolete-tilde.rs index fa59798c1d566..9c395406f0380 100644 --- a/src/test/compile-fail/obsolete-tilde.rs +++ b/src/test/compile-fail/obsolete-tilde.rs @@ -10,9 +10,9 @@ // Test that ~ pointers give an obsolescence message. -fn foo(x: ~int) {} //~ ERROR obsolete syntax: `~` notation for owned pointers +fn foo(x: ~isize) {} //~ ERROR obsolete syntax: `~` notation for owned pointers fn bar(x: ~str) {} //~ ERROR obsolete syntax: `~` notation for owned pointers -fn baz(x: ~[int]) {} //~ ERROR obsolete syntax: `~[T]` is no longer a type +fn baz(x: ~[isize]) {} //~ ERROR obsolete syntax: `~[T]` is no longer a type fn main() { let x = ~4i; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation diff --git a/src/test/compile-fail/obsolete-tuple-struct-deref.rs b/src/test/compile-fail/obsolete-tuple-struct-deref.rs index 9ea7d960da9f3..ad5fac3e21e88 100644 --- a/src/test/compile-fail/obsolete-tuple-struct-deref.rs +++ b/src/test/compile-fail/obsolete-tuple-struct-deref.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - struct S(int); + struct S(isize); let s = S(0); let x = *s; //~ ERROR single-field tuple-structs can no longer be dereferenced } diff --git a/src/test/compile-fail/occurs-check-3.rs b/src/test/compile-fail/occurs-check-3.rs index 4cda97bcb4ac4..ba7688e852485 100644 --- a/src/test/compile-fail/occurs-check-3.rs +++ b/src/test/compile-fail/occurs-check-3.rs @@ -11,4 +11,4 @@ // error-pattern:mismatched types // From Issue #778 enum clam { a(T), } -fn main() { let c; c = clam::a(c); match c { clam::a::(_) => { } } } +fn main() { let c; c = clam::a(c); match c { clam::a::(_) => { } } } diff --git a/src/test/compile-fail/or-patter-mismatch.rs b/src/test/compile-fail/or-patter-mismatch.rs index e79113ceb89a5..7f30e36560932 100644 --- a/src/test/compile-fail/or-patter-mismatch.rs +++ b/src/test/compile-fail/or-patter-mismatch.rs @@ -10,6 +10,6 @@ // error-pattern: mismatched types -enum blah { a(int, int, uint), b(int, int), } +enum blah { a(isize, isize, uint), b(isize, isize), } fn main() { match blah::a(1, 1, 2u) { blah::a(_, x, y) | blah::b(x, y) => { } } } diff --git a/src/test/compile-fail/output-type-mismatch.rs b/src/test/compile-fail/output-type-mismatch.rs index bc77765ebf446..158e99ac2003e 100644 --- a/src/test/compile-fail/output-type-mismatch.rs +++ b/src/test/compile-fail/output-type-mismatch.rs @@ -12,4 +12,4 @@ fn f() { } -fn main() { let i: int; i = f(); } +fn main() { let i: isize; i = f(); } diff --git a/src/test/compile-fail/overloaded-calls-bad.rs b/src/test/compile-fail/overloaded-calls-bad.rs index b3a4c3125891f..d784ba2d0d6bd 100644 --- a/src/test/compile-fail/overloaded-calls-bad.rs +++ b/src/test/compile-fail/overloaded-calls-bad.rs @@ -13,12 +13,12 @@ use std::ops::FnMut; struct S { - x: int, - y: int, + x: isize, + y: isize, } -impl FnMut<(int,),int> for S { - extern "rust-call" fn call_mut(&mut self, (z,): (int,)) -> int { +impl FnMut<(isize,),isize> for S { + extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize { self.x * self.y * z } } diff --git a/src/test/compile-fail/overloaded-calls-nontuple.rs b/src/test/compile-fail/overloaded-calls-nontuple.rs index 396a809c2e12f..c06ab04cd849a 100644 --- a/src/test/compile-fail/overloaded-calls-nontuple.rs +++ b/src/test/compile-fail/overloaded-calls-nontuple.rs @@ -13,12 +13,12 @@ use std::ops::FnMut; struct S { - x: int, - y: int, + x: isize, + y: isize, } -impl FnMut for S { - extern "rust-call" fn call_mut(&mut self, z: int) -> int { +impl FnMut for S { + extern "rust-call" fn call_mut(&mut self, z: isize) -> isize { self.x + self.y + z } } diff --git a/src/test/compile-fail/oversized-literal.rs b/src/test/compile-fail/oversized-literal.rs index 5416bcacf3d59..2a70653bd6c03 100644 --- a/src/test/compile-fail/oversized-literal.rs +++ b/src/test/compile-fail/oversized-literal.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - println!("{}", 18446744073709551616u64); //~ error: int literal is too large + println!("{}", 18446744073709551616u64); //~ error: isize literal is too large } diff --git a/src/test/compile-fail/pat-ref-enum.rs b/src/test/compile-fail/pat-ref-enum.rs index f1f0637a31805..062d3308c3de6 100644 --- a/src/test/compile-fail/pat-ref-enum.rs +++ b/src/test/compile-fail/pat-ref-enum.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn matcher(x: Option) { +fn matcher(x: Option) { match x { ref Some(i) => {} //~ ERROR expected identifier, found enum pattern None => {} diff --git a/src/test/compile-fail/pattern-error-continue.rs b/src/test/compile-fail/pattern-error-continue.rs index 8b65af00fb1c8..c288429dcda0c 100644 --- a/src/test/compile-fail/pattern-error-continue.rs +++ b/src/test/compile-fail/pattern-error-continue.rs @@ -11,13 +11,13 @@ // Test that certain pattern-match type errors are non-fatal enum A { - B(int, int), - C(int, int, int), + B(isize, isize), + C(isize, isize, isize), D } struct S { - a: int + a: isize } fn f(_c: char) {} diff --git a/src/test/compile-fail/pattern-ident-path-generics.rs b/src/test/compile-fail/pattern-ident-path-generics.rs index ab77e376979b0..58288fa484221 100644 --- a/src/test/compile-fail/pattern-ident-path-generics.rs +++ b/src/test/compile-fail/pattern-ident-path-generics.rs @@ -10,7 +10,7 @@ fn main() { match Some("foo") { - None:: => {} //~ ERROR mismatched types + None:: => {} //~ ERROR mismatched types Some(_) => {} } } diff --git a/src/test/compile-fail/pattern-tyvar-2.rs b/src/test/compile-fail/pattern-tyvar-2.rs index ff898ebd16b9c..cd4a98835c8c7 100644 --- a/src/test/compile-fail/pattern-tyvar-2.rs +++ b/src/test/compile-fail/pattern-tyvar-2.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum bar { t1((), Option>), t2, } +enum bar { t1((), Option>), t2, } // n.b. my change changes this error message, but I think it's right -- tjc -fn foo(t: bar) -> int { match t { bar::t1(_, Some(x)) => { return x * 3; } _ => { panic!(); } } } +fn foo(t: bar) -> isize { match t { bar::t1(_, Some(x)) => { return x * 3; } _ => { panic!(); } } } //~^ ERROR binary operation `*` cannot be applied to fn main() { } diff --git a/src/test/compile-fail/pattern-tyvar.rs b/src/test/compile-fail/pattern-tyvar.rs index 01b288fdaad1f..be8d3e027e7f2 100644 --- a/src/test/compile-fail/pattern-tyvar.rs +++ b/src/test/compile-fail/pattern-tyvar.rs @@ -10,11 +10,11 @@ // error-pattern: mismatched types -enum bar { t1((), Option >), t2, } +enum bar { t1((), Option >), t2, } fn foo(t: bar) { match t { - bar::t1(_, Some::(x)) => { + bar::t1(_, Some::(x)) => { println!("{}", x); } _ => { panic!(); } diff --git a/src/test/compile-fail/prim-with-args.rs b/src/test/compile-fail/prim-with-args.rs index 0587e033a9789..b4dba4f3a60cf 100644 --- a/src/test/compile-fail/prim-with-args.rs +++ b/src/test/compile-fail/prim-with-args.rs @@ -10,19 +10,19 @@ fn main() { -let x: int; //~ ERROR type parameters are not allowed on this type -let x: i8; //~ ERROR type parameters are not allowed on this type -let x: i16; //~ ERROR type parameters are not allowed on this type -let x: i32; //~ ERROR type parameters are not allowed on this type -let x: i64; //~ ERROR type parameters are not allowed on this type -let x: uint; //~ ERROR type parameters are not allowed on this type -let x: u8; //~ ERROR type parameters are not allowed on this type -let x: u16; //~ ERROR type parameters are not allowed on this type -let x: u32; //~ ERROR type parameters are not allowed on this type -let x: u64; //~ ERROR type parameters are not allowed on this type -let x: char; //~ ERROR type parameters are not allowed on this type +let x: isize; //~ ERROR type parameters are not allowed on this type +let x: i8; //~ ERROR type parameters are not allowed on this type +let x: i16; //~ ERROR type parameters are not allowed on this type +let x: i32; //~ ERROR type parameters are not allowed on this type +let x: i64; //~ ERROR type parameters are not allowed on this type +let x: uint; //~ ERROR type parameters are not allowed on this type +let x: u8; //~ ERROR type parameters are not allowed on this type +let x: u16; //~ ERROR type parameters are not allowed on this type +let x: u32; //~ ERROR type parameters are not allowed on this type +let x: u64; //~ ERROR type parameters are not allowed on this type +let x: char; //~ ERROR type parameters are not allowed on this type -let x: int<'static>; //~ ERROR lifetime parameters are not allowed on this type +let x: isize<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type diff --git a/src/test/compile-fail/privacy1.rs b/src/test/compile-fail/privacy1.rs index ffee00642acf6..9dafae3d87dca 100644 --- a/src/test/compile-fail/privacy1.rs +++ b/src/test/compile-fail/privacy1.rs @@ -41,7 +41,7 @@ mod bar { fn foo() -> Self; } - impl B for int { fn foo() -> int { 3 } } + impl B for isize { fn foo() -> isize { 3 } } pub enum Enum { Pub @@ -119,7 +119,7 @@ mod foo { //~^ ERROR: method `bar2` is private //~^^ NOTE: module `baz` is private - let _: int = + let _: isize = ::bar::B::foo(); //~ ERROR: method `foo` is inaccessible //~^ NOTE: trait `B` is private ::lol(); @@ -186,4 +186,4 @@ pub mod mytest { } } -#[start] fn main(_: int, _: *const *const u8) -> int { 3 } +#[start] fn main(_: isize, _: *const *const u8) -> isize { 3 } diff --git a/src/test/compile-fail/privacy2.rs b/src/test/compile-fail/privacy2.rs index b38d7aedf841c..b59905776d38a 100644 --- a/src/test/compile-fail/privacy2.rs +++ b/src/test/compile-fail/privacy2.rs @@ -32,4 +32,4 @@ fn test2() { //~^ ERROR unresolved import `bar::glob::foo`. There is no `foo` in `bar::glob` } -#[start] fn main(_: int, _: *const *const u8) -> int { 3 } +#[start] fn main(_: isize, _: *const *const u8) -> isize { 3 } diff --git a/src/test/compile-fail/privacy3.rs b/src/test/compile-fail/privacy3.rs index 5ec10d5a4caa9..80219b70e07b5 100644 --- a/src/test/compile-fail/privacy3.rs +++ b/src/test/compile-fail/privacy3.rs @@ -29,4 +29,4 @@ fn test1() { gpriv(); } -#[start] fn main(_: int, _: *const *const u8) -> int { 3 } +#[start] fn main(_: isize, _: *const *const u8) -> isize { 3 } diff --git a/src/test/compile-fail/privacy4.rs b/src/test/compile-fail/privacy4.rs index 92f3a57c69d0b..3f17d463890be 100644 --- a/src/test/compile-fail/privacy4.rs +++ b/src/test/compile-fail/privacy4.rs @@ -32,4 +32,4 @@ fn test2() { gpriv(); } -#[start] fn main(_: int, _: *const *const u8) -> int { 3 } +#[start] fn main(_: isize, _: *const *const u8) -> isize { 3 } diff --git a/src/test/compile-fail/privacy5.rs b/src/test/compile-fail/privacy5.rs index 555969b65ff07..df570fd464792 100644 --- a/src/test/compile-fail/privacy5.rs +++ b/src/test/compile-fail/privacy5.rs @@ -15,9 +15,9 @@ extern crate "privacy-tuple-struct" as other; mod a { pub struct A(()); - pub struct B(int); - pub struct C(pub int, int); - pub struct D(pub int); + pub struct B(isize); + pub struct C(pub isize, isize); + pub struct D(pub isize); fn test() { let a = A(()); diff --git a/src/test/compile-fail/private-impl-method.rs b/src/test/compile-fail/private-impl-method.rs index fe5908b40ab4f..c6e329aab041a 100644 --- a/src/test/compile-fail/private-impl-method.rs +++ b/src/test/compile-fail/private-impl-method.rs @@ -10,7 +10,7 @@ mod a { pub struct Foo { - pub x: int + pub x: isize } impl Foo { diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index 88ab73e1f9dcf..d09481cfd6449 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -14,14 +14,14 @@ mod kitties { pub struct cat { meows : uint, - how_hungry : int, + how_hungry : isize, } impl cat { fn nap(&self) {} } - pub fn cat(in_x : uint, in_y : int) -> cat { + pub fn cat(in_x : uint, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/private-struct-field-ctor.rs b/src/test/compile-fail/private-struct-field-ctor.rs index ae19c22149669..0a0f2d490a8ec 100644 --- a/src/test/compile-fail/private-struct-field-ctor.rs +++ b/src/test/compile-fail/private-struct-field-ctor.rs @@ -10,7 +10,7 @@ mod a { pub struct Foo { - x: int + x: isize } } diff --git a/src/test/compile-fail/private-struct-field-pattern.rs b/src/test/compile-fail/private-struct-field-pattern.rs index 991457ef1ce7c..e9dd6cd1d7478 100644 --- a/src/test/compile-fail/private-struct-field-pattern.rs +++ b/src/test/compile-fail/private-struct-field-pattern.rs @@ -12,7 +12,7 @@ use a::Foo; mod a { pub struct Foo { - x: int + x: isize } pub fn make() -> Foo { diff --git a/src/test/compile-fail/ptr-coercion.rs b/src/test/compile-fail/ptr-coercion.rs index d9b20748a7a29..b7d122cd79d87 100644 --- a/src/test/compile-fail/ptr-coercion.rs +++ b/src/test/compile-fail/ptr-coercion.rs @@ -13,12 +13,12 @@ pub fn main() { // *const -> *mut - let x: *const int = &42i; - let x: *mut int = x; //~ERROR values differ in mutability + let x: *const isize = &42i; + let x: *mut isize = x; //~ERROR values differ in mutability // & -> *mut - let x: *mut int = &42; //~ERROR values differ in mutability + let x: *mut isize = &42; //~ERROR values differ in mutability - let x: *const int = &42; - let x: *mut int = x; //~ERROR values differ in mutability + let x: *const isize = &42; + let x: *mut isize = x; //~ERROR values differ in mutability } diff --git a/src/test/compile-fail/qquote-2.rs b/src/test/compile-fail/qquote-2.rs index 94485dddd136b..978287a681eb1 100644 --- a/src/test/compile-fail/qquote-2.rs +++ b/src/test/compile-fail/qquote-2.rs @@ -52,7 +52,7 @@ fn mk_ctxt() -> fake_ext_ctxt { fn main() { let cx = mk_ctxt(); - let stmt = quote_stmt!(cx, let x int = 20;); //~ ERROR expected end-of-string + let stmt = quote_stmt!(cx, let x isize = 20;); //~ ERROR expected end-of-string check_pp(*stmt, pprust::print_stmt, ""); } diff --git a/src/test/compile-fail/recursion.rs b/src/test/compile-fail/recursion.rs index da05514f76300..ffc21a5ce6123 100644 --- a/src/test/compile-fail/recursion.rs +++ b/src/test/compile-fail/recursion.rs @@ -16,17 +16,17 @@ // that is more helpful. enum Nil {NilValue} -struct Cons {head:int, tail:T} -trait Dot {fn dot(&self, other:Self) -> int;} +struct Cons {head:isize, tail:T} +trait Dot {fn dot(&self, other:Self) -> isize;} impl Dot for Nil { - fn dot(&self, _:Nil) -> int {0} + fn dot(&self, _:Nil) -> isize {0} } impl Dot for Cons { - fn dot(&self, other:Cons) -> int { + fn dot(&self, other:Cons) -> isize { self.head * other.head + self.tail.dot(other.tail) } } -fn test (n:int, i:int, first:T, second:T) ->int { +fn test (n:isize, i:isize, first:T, second:T) ->isize { match n { 0 => {first.dot(second)} //~^ ERROR: reached the recursion limit during monomorphization // Error message should be here. It should be a type error diff --git a/src/test/compile-fail/refutable-pattern-errors.rs b/src/test/compile-fail/refutable-pattern-errors.rs index 98d616ee3afb5..54b8c7fe4b9be 100644 --- a/src/test/compile-fail/refutable-pattern-errors.rs +++ b/src/test/compile-fail/refutable-pattern-errors.rs @@ -9,7 +9,7 @@ // except according to those terms. -fn func((1, (Some(1), 2...3)): (int, (Option, int))) { } +fn func((1, (Some(1), 2...3)): (isize, (Option, isize))) { } //~^ ERROR refutable pattern in function argument: `(_, _)` not covered fn main() { diff --git a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs index 575e9864a92d3..53f923e506196 100644 --- a/src/test/compile-fail/refutable-pattern-in-fn-arg.rs +++ b/src/test/compile-fail/refutable-pattern-in-fn-arg.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let f = |&: 3: int| println!("hello"); + let f = |&: 3: isize| println!("hello"); //~^ ERROR refutable pattern in function argument: `_` not covered f(4); } diff --git a/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs b/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs index 3e6a95b04f743..ee05ba676ac70 100644 --- a/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a<'a, 'b>(x: &mut &'a int, y: &mut &'b int) where 'b: 'a { +fn a<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) where 'b: 'a { // Note: this is legal because of the `'b:'a` declaration. *x = *y; } -fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) { +fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //~ ERROR cannot infer } -fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { +fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { // Here we try to call `foo` but do not know that `'a` and `'b` are // related as required. a(x, y); //~ ERROR cannot infer @@ -27,13 +27,13 @@ fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { fn d() { // 'a and 'b are early bound in the function `a` because they appear // inconstraints: - let _: fn(&mut &int, &mut &int) = a; //~ ERROR mismatched types + let _: fn(&mut &isize, &mut &isize) = a; //~ ERROR mismatched types } fn e() { // 'a and 'b are late bound in the function `b` because there are // no constraints: - let _: fn(&mut &int, &mut &int) = b; + let _: fn(&mut &isize, &mut &isize) = b; } fn main() { } diff --git a/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs b/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs index 2d635e9fc2718..30e6a4e12773f 100644 --- a/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs @@ -8,19 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a<'a, 'b, 'c>(x: &mut &'a int, y: &mut &'b int, z: &mut &'c int) where 'b: 'a + 'c { +fn a<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) where 'b: 'a + 'c { // Note: this is legal because of the `'b:'a` declaration. *x = *y; *z = *y; } -fn b<'a, 'b, 'c>(x: &mut &'a int, y: &mut &'b int, z: &mut &'c int) { +fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //~ ERROR cannot infer *z = *y; //~ ERROR cannot infer } -fn c<'a,'b, 'c>(x: &mut &'a int, y: &mut &'b int, z: &mut &'c int) { +fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { // Here we try to call `foo` but do not know that `'a` and `'b` are // related as required. a(x, y, z); //~ ERROR cannot infer @@ -29,13 +29,13 @@ fn c<'a,'b, 'c>(x: &mut &'a int, y: &mut &'b int, z: &mut &'c int) { fn d() { // 'a and 'b are early bound in the function `a` because they appear // inconstraints: - let _: fn(&mut &int, &mut &int, &mut &int) = a; //~ ERROR mismatched types + let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; //~ ERROR mismatched types } fn e() { // 'a and 'b are late bound in the function `b` because there are // no constraints: - let _: fn(&mut &int, &mut &int, &mut &int) = b; + let _: fn(&mut &isize, &mut &isize, &mut &isize) = b; } fn main() { } diff --git a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs b/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs index 75e9e55138e06..cdaa3468a463c 100644 --- a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs +++ b/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs @@ -17,7 +17,7 @@ fn main() { { let c = 1; let c_ref = &c; //~ ERROR `c` does not live long enough - f = move |&mut: a: int, b: int| { a + b + *c_ref }; + f = move |&mut: a: isize, b: isize| { a + b + *c_ref }; } } diff --git a/src/test/compile-fail/regions-addr-of-arg.rs b/src/test/compile-fail/regions-addr-of-arg.rs index 3e568180b53a4..c54b4aaace5fb 100644 --- a/src/test/compile-fail/regions-addr-of-arg.rs +++ b/src/test/compile-fail/regions-addr-of-arg.rs @@ -11,15 +11,15 @@ // Check that taking the address of an argument yields a lifetime // bounded by the current function call. -fn foo(a: int) { - let _p: &'static int = &a; //~ ERROR `a` does not live long enough +fn foo(a: isize) { + let _p: &'static isize = &a; //~ ERROR `a` does not live long enough } -fn bar(a: int) { - let _q: &int = &a; +fn bar(a: isize) { + let _q: &isize = &a; } -fn zed<'a>(a: int) -> &'a int { +fn zed<'a>(a: isize) -> &'a isize { &a //~ ERROR `a` does not live long enough } diff --git a/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs b/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs index c6a9f67cfc651..5028ec8997261 100644 --- a/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs +++ b/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs @@ -13,7 +13,7 @@ // checked. struct Inv<'a> { // invariant w/r/t 'a - x: &'a mut &'a int + x: &'a mut &'a isize } pub trait Foo<'a> { @@ -24,7 +24,7 @@ pub trait Foo<'a> { } -impl<'a> Foo<'a> for &'a int { +impl<'a> Foo<'a> for &'a isize { fn no_bound<'b:'a>(self, b: Inv<'b>) { //~^ ERROR lifetime parameters or bounds on method `no_bound` do not match } diff --git a/src/test/compile-fail/regions-bounded-by-send.rs b/src/test/compile-fail/regions-bounded-by-send.rs index 0628bbb8bb08e..e3f0d3bcdb69e 100644 --- a/src/test/compile-fail/regions-bounded-by-send.rs +++ b/src/test/compile-fail/regions-bounded-by-send.rs @@ -20,41 +20,41 @@ trait Dummy:Send { } // lifetime pointers with 'static lifetime are ok -fn static_lifime_ok<'a,T,U:Send>(_: &'a int) { - assert_send::<&'static int>(); +fn static_lifime_ok<'a,T,U:Send>(_: &'a isize) { + assert_send::<&'static isize>(); assert_send::<&'static str>(); - assert_send::<&'static [int]>(); + assert_send::<&'static [isize]>(); // whether or not they are mutable - assert_send::<&'static mut int>(); + assert_send::<&'static mut isize>(); } // otherwise lifetime pointers are not ok -fn param_not_ok<'a>(x: &'a int) { - assert_send::<&'a int>(); //~ ERROR declared lifetime bound not satisfied +fn param_not_ok<'a>(x: &'a isize) { + assert_send::<&'a isize>(); //~ ERROR declared lifetime bound not satisfied } -fn param_not_ok1<'a>(_: &'a int) { +fn param_not_ok1<'a>(_: &'a isize) { assert_send::<&'a str>(); //~ ERROR declared lifetime bound not satisfied } -fn param_not_ok2<'a>(_: &'a int) { - assert_send::<&'a [int]>(); //~ ERROR declared lifetime bound not satisfied +fn param_not_ok2<'a>(_: &'a isize) { + assert_send::<&'a [isize]>(); //~ ERROR declared lifetime bound not satisfied } // boxes are ok fn box_ok() { - assert_send::>(); + assert_send::>(); assert_send::(); - assert_send::>(); + assert_send::>(); } // but not if they own a bad thing fn box_with_region_not_ok<'a>() { - assert_send::>(); //~ ERROR declared lifetime bound not satisfied + assert_send::>(); //~ ERROR declared lifetime bound not satisfied } // objects with insufficient bounds no ok @@ -71,11 +71,11 @@ fn object_with_send_bound_not_ok<'a>() { // unsafe pointers are ok unless they point at unsendable things -struct UniqueUnsafePtr(Unique<*const int>); +struct UniqueUnsafePtr(Unique<*const isize>); unsafe impl Send for UniqueUnsafePtr {} -fn unsafe_ok1<'a>(_: &'a int) { +fn unsafe_ok1<'a>(_: &'a isize) { assert_send::(); } diff --git a/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs index e3939a4e39046..8194af25d73b1 100644 --- a/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs +++ b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs @@ -17,56 +17,56 @@ fn assert_send() { } // lifetime pointers with 'static lifetime are ok -fn static_lifime_ok<'a,T,U:Send>(_: &'a int) { - assert_send::<&'static int>(); +fn static_lifime_ok<'a,T,U:Send>(_: &'a isize) { + assert_send::<&'static isize>(); assert_send::<&'static str>(); - assert_send::<&'static [int]>(); + assert_send::<&'static [isize]>(); // whether or not they are mutable - assert_send::<&'static mut int>(); + assert_send::<&'static mut isize>(); } // otherwise lifetime pointers are not ok -fn param_not_ok<'a>(x: &'a int) { - assert_send::<&'a int>(); //~ ERROR declared lifetime bound not satisfied +fn param_not_ok<'a>(x: &'a isize) { + assert_send::<&'a isize>(); //~ ERROR declared lifetime bound not satisfied } -fn param_not_ok1<'a>(_: &'a int) { +fn param_not_ok1<'a>(_: &'a isize) { assert_send::<&'a str>(); //~ ERROR declared lifetime bound not satisfied } -fn param_not_ok2<'a>(_: &'a int) { - assert_send::<&'a [int]>(); //~ ERROR declared lifetime bound not satisfied +fn param_not_ok2<'a>(_: &'a isize) { + assert_send::<&'a [isize]>(); //~ ERROR declared lifetime bound not satisfied } // boxes are ok fn box_ok() { - assert_send::>(); + assert_send::>(); assert_send::(); - assert_send::>(); + assert_send::>(); } // but not if they own a bad thing fn box_with_region_not_ok<'a>() { - assert_send::>(); //~ ERROR declared lifetime bound not satisfied + assert_send::>(); //~ ERROR declared lifetime bound not satisfied } // unsafe pointers are ok unless they point at unsendable things -fn unsafe_ok1<'a>(_: &'a int) { - assert_send::<*const int>(); - assert_send::<*mut int>(); +fn unsafe_ok1<'a>(_: &'a isize) { + assert_send::<*const isize>(); + assert_send::<*mut isize>(); } -fn unsafe_ok2<'a>(_: &'a int) { - assert_send::<*const &'a int>(); //~ ERROR declared lifetime bound not satisfied +fn unsafe_ok2<'a>(_: &'a isize) { + assert_send::<*const &'a isize>(); //~ ERROR declared lifetime bound not satisfied } -fn unsafe_ok3<'a>(_: &'a int) { - assert_send::<*mut &'a int>(); //~ ERROR declared lifetime bound not satisfied +fn unsafe_ok3<'a>(_: &'a isize) { + assert_send::<*mut &'a isize>(); //~ ERROR declared lifetime bound not satisfied } fn main() { diff --git a/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs b/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs index e628eb3285ae6..acc721f26b394 100644 --- a/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs +++ b/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs @@ -19,7 +19,7 @@ trait Sized { } struct Inv<'a> { // invariant w/r/t 'a - x: &'a mut &'a int + x: &'a mut &'a isize } trait Foo<'x> { diff --git a/src/test/compile-fail/regions-bounded-method-type-parameters.rs b/src/test/compile-fail/regions-bounded-method-type-parameters.rs index 10484925980a7..9afacacd66218 100644 --- a/src/test/compile-fail/regions-bounded-method-type-parameters.rs +++ b/src/test/compile-fail/regions-bounded-method-type-parameters.rs @@ -18,8 +18,8 @@ impl Foo { fn some_method(self) { } } -fn caller<'a>(x: &int) { - Foo.some_method::<&'a int>(); +fn caller<'a>(x: &isize) { + Foo.some_method::<&'a isize>(); //~^ ERROR declared lifetime bound not satisfied } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index e13a6b211a503..c26740c9598d6 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -12,8 +12,8 @@ // nominal types (but not on other types) and that they are type // checked. -struct an_enum<'a>(&'a int); -struct a_class<'a> { x:&'a int } +struct an_enum<'a>(&'a isize); +struct a_class<'a> { x:&'a isize } fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> { return e; //~ ERROR mismatched types: expected `an_enum<'b>`, found `an_enum<'a>` diff --git a/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs b/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs index e17786e6a5112..25b8137d29cad 100644 --- a/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs +++ b/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs @@ -12,12 +12,12 @@ trait Foo { } -impl<'a> Foo for &'a int { } +impl<'a> Foo for &'a isize { } fn main() { let blah; { - let ss: &int = &1; //~ ERROR borrowed value does not live long enough + let ss: &isize = &1; //~ ERROR borrowed value does not live long enough blah = box ss as Box; } } diff --git a/src/test/compile-fail/regions-close-over-type-parameter-1.rs b/src/test/compile-fail/regions-close-over-type-parameter-1.rs index 985ae6116f006..fc18095fc8336 100644 --- a/src/test/compile-fail/regions-close-over-type-parameter-1.rs +++ b/src/test/compile-fail/regions-close-over-type-parameter-1.rs @@ -14,7 +14,7 @@ // an object. This should yield errors unless `A` (and the object) // both have suitable bounds. -trait SomeTrait { fn get(&self) -> int; } +trait SomeTrait { fn get(&self) -> isize; } fn make_object1(v: A) -> Box { box v as Box diff --git a/src/test/compile-fail/regions-close-over-type-parameter-2.rs b/src/test/compile-fail/regions-close-over-type-parameter-2.rs index 85ff336b4cbda..8d9bd92a8def2 100644 --- a/src/test/compile-fail/regions-close-over-type-parameter-2.rs +++ b/src/test/compile-fail/regions-close-over-type-parameter-2.rs @@ -26,7 +26,7 @@ fn repeater3<'a,A:'a>(v: A) -> Box { fn main() { // Error results because the type of is inferred to be - // ~Repeat<&'blk int> where blk is the lifetime of the block below. + // ~Repeat<&'blk isize> where blk is the lifetime of the block below. let _ = { let tmp0 = 3i; diff --git a/src/test/compile-fail/regions-close-over-type-parameter-multiple.rs b/src/test/compile-fail/regions-close-over-type-parameter-multiple.rs index 2aa77b2e53d71..0f8bc6d684f12 100644 --- a/src/test/compile-fail/regions-close-over-type-parameter-multiple.rs +++ b/src/test/compile-fail/regions-close-over-type-parameter-multiple.rs @@ -13,7 +13,7 @@ // Various tests where we over type parameters with multiple lifetime // bounds. -trait SomeTrait { fn get(&self) -> int; } +trait SomeTrait { fn get(&self) -> isize; } fn make_object_good1<'a,'b,A:SomeTrait+'a+'b>(v: A) -> Box { // A outlives 'a AND 'b... diff --git a/src/test/compile-fail/regions-early-bound-error-method.rs b/src/test/compile-fail/regions-early-bound-error-method.rs index 0cb88b924f85c..9de0ed070c7ca 100644 --- a/src/test/compile-fail/regions-early-bound-error-method.rs +++ b/src/test/compile-fail/regions-early-bound-error-method.rs @@ -12,21 +12,21 @@ // the value for a type parameter in a bound. trait GetRef<'a> { - fn get(&self) -> &'a int; + fn get(&self) -> &'a isize; } struct Box<'a> { - t: &'a int + t: &'a isize } impl<'a> GetRef<'a> for Box<'a> { - fn get(&self) -> &'a int { + fn get(&self) -> &'a isize { self.t } } impl<'a> Box<'a> { - fn or<'b,G:GetRef<'b>>(&self, g2: G) -> &'a int { + fn or<'b,G:GetRef<'b>>(&self, g2: G) -> &'a isize { g2.get() //~ ERROR cannot infer an appropriate lifetime for automatic coercion due to } } diff --git a/src/test/compile-fail/regions-early-bound-error.rs b/src/test/compile-fail/regions-early-bound-error.rs index 5da281d93dd55..37b74aea53913 100644 --- a/src/test/compile-fail/regions-early-bound-error.rs +++ b/src/test/compile-fail/regions-early-bound-error.rs @@ -25,7 +25,7 @@ impl<'a,T:Clone> GetRef<'a,T> for Box<'a,T> { } } -fn get<'a,'b,G:GetRef<'a, int>>(g1: G, b: &'b int) -> &'b int { +fn get<'a,'b,G:GetRef<'a, isize>>(g1: G, b: &'b isize) -> &'b isize { g1.get() //~ ERROR cannot infer an appropriate lifetime for automatic coercion due to } diff --git a/src/test/compile-fail/regions-enum-not-wf.rs b/src/test/compile-fail/regions-enum-not-wf.rs index 0691ad0de7323..0165dbdabf3c2 100644 --- a/src/test/compile-fail/regions-enum-not-wf.rs +++ b/src/test/compile-fail/regions-enum-not-wf.rs @@ -18,7 +18,7 @@ enum Ref1<'a, T> { //~ ERROR the parameter type `T` may not live long enough enum Ref2<'a, T> { //~ ERROR the parameter type `T` may not live long enough Ref2Variant1, - Ref2Variant2(int, &'a T), + Ref2Variant2(isize, &'a T), } enum RefOk<'a, T:'a> { @@ -26,7 +26,7 @@ enum RefOk<'a, T:'a> { } enum RefIndirect<'a, T> { //~ ERROR the parameter type `T` may not live long enough - RefIndirectVariant1(int, RefOk<'a,T>) + RefIndirectVariant1(isize, RefOk<'a,T>) } enum RefDouble<'a, 'b, T> { //~ ERROR reference has a longer lifetime than the data diff --git a/src/test/compile-fail/regions-escape-bound-fn-2.rs b/src/test/compile-fail/regions-escape-bound-fn-2.rs index 547accbf0860d..1329d05a0f690 100644 --- a/src/test/compile-fail/regions-escape-bound-fn-2.rs +++ b/src/test/compile-fail/regions-escape-bound-fn-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: F) where F: FnOnce(&int) { +fn with_int(f: F) where F: FnOnce(&isize) { let x = 3; f(&x); } diff --git a/src/test/compile-fail/regions-escape-bound-fn.rs b/src/test/compile-fail/regions-escape-bound-fn.rs index 6d67bd80650fa..02e62ffddfd50 100644 --- a/src/test/compile-fail/regions-escape-bound-fn.rs +++ b/src/test/compile-fail/regions-escape-bound-fn.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn with_int(f: F) where F: FnOnce(&int) { +fn with_int(f: F) where F: FnOnce(&isize) { let x = 3; f(&x); } fn main() { - let mut x: Option<&int> = None; + let mut x: Option<&isize> = None; with_int(|y| x = Some(y)); //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-escape-unboxed-closure.rs b/src/test/compile-fail/regions-escape-unboxed-closure.rs index 70f0d61b5ee1f..06768fa68804c 100644 --- a/src/test/compile-fail/regions-escape-unboxed-closure.rs +++ b/src/test/compile-fail/regions-escape-unboxed-closure.rs @@ -10,10 +10,10 @@ #![feature(unboxed_closures)] -fn with_int(f: &mut FnMut(&int)) { +fn with_int(f: &mut FnMut(&isize)) { } fn main() { - let mut x: Option<&int> = None; + let mut x: Option<&isize> = None; with_int(&mut |&mut: y| x = Some(y)); //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index 873d4cea0395e..a4363b00e1c93 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -11,20 +11,20 @@ #![allow(dead_code)] trait Deref { - fn get(self) -> int; + fn get(self) -> isize; } -impl<'a> Deref for &'a int { - fn get(self) -> int { +impl<'a> Deref for &'a isize { + fn get(self) -> isize { *self } } -fn with(f: F) -> int where F: FnOnce(&int) -> R { +fn with(f: F) -> isize where F: FnOnce(&isize) -> R { f(&3).get() } -fn return_it() -> int { +fn return_it() -> isize { with(|o| o) //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-in-consts.rs b/src/test/compile-fail/regions-in-consts.rs index 9f2facf4e1f9f..8d0829a4cffc3 100644 --- a/src/test/compile-fail/regions-in-consts.rs +++ b/src/test/compile-fail/regions-in-consts.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static c_y: &int = &22; //~ ERROR missing lifetime specifier -static c_z: &'static int = &22; +static c_y: &isize = &22; //~ ERROR missing lifetime specifier +static c_z: &'static isize = &22; fn main() { } diff --git a/src/test/compile-fail/regions-in-enums-anon.rs b/src/test/compile-fail/regions-in-enums-anon.rs index 5c7a37d0359a4..305bf88c4d5d7 100644 --- a/src/test/compile-fail/regions-in-enums-anon.rs +++ b/src/test/compile-fail/regions-in-enums-anon.rs @@ -11,7 +11,7 @@ // Test that anonymous lifetimes are not permitted in enum declarations enum Foo { - Bar(&int) //~ ERROR missing lifetime specifier + Bar(&isize) //~ ERROR missing lifetime specifier } fn main() {} diff --git a/src/test/compile-fail/regions-in-structs-anon.rs b/src/test/compile-fail/regions-in-structs-anon.rs index 0f2036a56cdd6..b85928b1b9fa3 100644 --- a/src/test/compile-fail/regions-in-structs-anon.rs +++ b/src/test/compile-fail/regions-in-structs-anon.rs @@ -11,7 +11,7 @@ // Test that anonymous lifetimes are not permitted in struct declarations struct Foo { - x: &int //~ ERROR missing lifetime specifier + x: &isize //~ ERROR missing lifetime specifier } fn main() {} diff --git a/src/test/compile-fail/regions-in-structs.rs b/src/test/compile-fail/regions-in-structs.rs index 0c5cb98e6a465..f46f73bf26a26 100644 --- a/src/test/compile-fail/regions-in-structs.rs +++ b/src/test/compile-fail/regions-in-structs.rs @@ -17,8 +17,8 @@ struct yes2<'a> { } struct StructDecl { - a: &'a int, //~ ERROR use of undeclared lifetime name `'a` - b: &'a int, //~ ERROR use of undeclared lifetime name `'a` + a: &'a isize, //~ ERROR use of undeclared lifetime name `'a` + b: &'a isize, //~ ERROR use of undeclared lifetime name `'a` } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs index b710578969b0d..2628e6a1ce279 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs @@ -10,15 +10,15 @@ struct point { - x: int, - y: int, + x: isize, + y: isize, } -fn x_coord<'r>(p: &'r point) -> &'r int { +fn x_coord<'r>(p: &'r point) -> &'r isize { return &p.x; } -fn foo<'a>(p: Box) -> &'a int { +fn foo<'a>(p: Box) -> &'a isize { let xc = x_coord(&*p); //~ ERROR `*p` does not live long enough assert_eq!(*xc, 3); return xc; diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index c8edd936bf28b..a05658e9e581d 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -13,9 +13,9 @@ fn borrow(x: &T) -> &T {x} fn foo(mut cond: C, mut make_box: M) where C: FnMut() -> bool, - M: FnMut() -> Box, + M: FnMut() -> Box, { - let mut y: ∫ + let mut y: &isize; loop { let x = make_box(); diff --git a/src/test/compile-fail/regions-infer-bound-from-trait-self.rs b/src/test/compile-fail/regions-infer-bound-from-trait-self.rs index aeb003ca5d091..23b8ebfe54b44 100644 --- a/src/test/compile-fail/regions-infer-bound-from-trait-self.rs +++ b/src/test/compile-fail/regions-infer-bound-from-trait-self.rs @@ -16,7 +16,7 @@ trait Static : 'static { } trait Is<'a> : 'a { } struct Inv<'a> { - x: Option<&'a mut &'a int> + x: Option<&'a mut &'a isize> } fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { } diff --git a/src/test/compile-fail/regions-infer-bound-from-trait.rs b/src/test/compile-fail/regions-infer-bound-from-trait.rs index d1111377f1e4b..f7a910547669b 100644 --- a/src/test/compile-fail/regions-infer-bound-from-trait.rs +++ b/src/test/compile-fail/regions-infer-bound-from-trait.rs @@ -16,7 +16,7 @@ trait Static : 'static { } trait Is<'a> : 'a { } struct Inv<'a> { - x: Option<&'a mut &'a int> + x: Option<&'a mut &'a isize> } fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { } diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index ac41f2a5b3e47..95783a420b6dd 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x } +fn select<'r>(x: &'r isize, y: &'r isize) -> &'r isize { x } -fn with(f: F) -> T where F: FnOnce(&int) -> T { +fn with(f: F) -> T where F: FnOnce(&isize) -> T { f(&20) } -fn manip<'a>(x: &'a int) -> int { +fn manip<'a>(x: &'a isize) -> isize { let z = with(|y| { select(x, y) }); //~^ ERROR cannot infer *z diff --git a/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs b/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs index 4d31d2c8e6927..6c5e90a54de2b 100644 --- a/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs +++ b/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs @@ -24,8 +24,8 @@ struct Contravariant<'a> { } fn use_<'short,'long>(c: Contravariant<'short>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { // Test whether Contravariant<'short> <: Contravariant<'long>. Since diff --git a/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs b/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs index 1c3b7bb5960e1..d8e31fa1374a8 100644 --- a/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs +++ b/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs @@ -21,8 +21,8 @@ struct Covariant<'a> { } fn use_<'short,'long>(c: Covariant<'long>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { // Test whether Covariant<'long> <: Covariant<'short>. Since diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs index 190e444fe7e83..e42aa684e149e 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: Box, + f: Box, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs index 71d0c988c5e27..2e634dfe3eb61 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs @@ -10,7 +10,7 @@ struct invariant<'a> { - f: Box FnOnce() -> &'b mut &'a int + 'static>, + f: Box FnOnce() -> &'b mut &'a isize + 'static>, } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index 323ebc3c20b37..5d7a218ca8a5b 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -9,7 +9,7 @@ // except according to those terms. struct direct<'a> { - f: &'a int + f: &'a isize } struct indirect1 { diff --git a/src/test/compile-fail/regions-infer-paramd-method.rs b/src/test/compile-fail/regions-infer-paramd-method.rs index 772ccadda5273..ef331bb0fd7bc 100644 --- a/src/test/compile-fail/regions-infer-paramd-method.rs +++ b/src/test/compile-fail/regions-infer-paramd-method.rs @@ -25,9 +25,9 @@ // refers to self. trait foo<'a> { - fn self_int(self) -> &'a int; + fn self_int(self) -> &'a isize; - fn any_int(self) -> ∫ + fn any_int(self) -> &isize; } struct with_foo<'a> { @@ -47,7 +47,7 @@ impl<'a> set_foo_foo for with_foo<'a> { // Bar is not region parameterized. trait bar { - fn any_int(&self) -> ∫ + fn any_int(&self) -> &isize; } struct with_bar { diff --git a/src/test/compile-fail/regions-infer-proc-static-upvar.rs b/src/test/compile-fail/regions-infer-proc-static-upvar.rs index 8b2fdfe7cdd15..bf05554e6d0ec 100644 --- a/src/test/compile-fail/regions-infer-proc-static-upvar.rs +++ b/src/test/compile-fail/regions-infer-proc-static-upvar.rs @@ -13,7 +13,7 @@ fn foo(_p: F) { } -static i: int = 3; +static i: isize = 3; fn capture_local() { let x = 3i; diff --git a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs index 4a42728da6f58..43940d499d210 100644 --- a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs +++ b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a<'a, 'b:'a>(x: &mut &'a int, y: &mut &'b int) { +fn a<'a, 'b:'a>(x: &mut &'a isize, y: &mut &'b isize) { // Note: this is legal because of the `'b:'a` declaration. *x = *y; } -fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) { +fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //~ ERROR cannot infer } -fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { +fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { // Here we try to call `foo` but do not know that `'a` and `'b` are // related as required. a(x, y); //~ ERROR cannot infer @@ -27,13 +27,13 @@ fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { fn d() { // 'a and 'b are early bound in the function `a` because they appear // inconstraints: - let _: fn(&mut &int, &mut &int) = a; //~ ERROR mismatched types + let _: fn(&mut &isize, &mut &isize) = a; //~ ERROR mismatched types } fn e() { // 'a and 'b are late bound in the function `b` because there are // no constraints: - let _: fn(&mut &int, &mut &int) = b; + let _: fn(&mut &isize, &mut &isize) = b; } fn main() { } diff --git a/src/test/compile-fail/regions-name-duplicated.rs b/src/test/compile-fail/regions-name-duplicated.rs index 518fe0b00b6ce..b4b9cfd75cbc9 100644 --- a/src/test/compile-fail/regions-name-duplicated.rs +++ b/src/test/compile-fail/regions-name-duplicated.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo<'a, 'a> { //~ ERROR lifetime name `'a` declared twice - x: &'a int + x: &'a isize } fn main() {} diff --git a/src/test/compile-fail/regions-name-static.rs b/src/test/compile-fail/regions-name-static.rs index 9f50ad3666025..29896aa486b49 100644 --- a/src/test/compile-fail/regions-name-static.rs +++ b/src/test/compile-fail/regions-name-static.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo<'static> { //~ ERROR illegal lifetime parameter name: `'static` - x: &'static int + x: &'static isize } fn main() {} diff --git a/src/test/compile-fail/regions-name-undeclared.rs b/src/test/compile-fail/regions-name-undeclared.rs index b9c721159f2b4..a61d30949334a 100644 --- a/src/test/compile-fail/regions-name-undeclared.rs +++ b/src/test/compile-fail/regions-name-undeclared.rs @@ -12,48 +12,48 @@ // rules correctly in various scenarios. struct Foo<'a> { - x: &'a int + x: &'a isize } impl<'a> Foo<'a> { // &'a is inherited: - fn m1(&self, arg: &'a int) { } + fn m1(&self, arg: &'a isize) { } fn m2(&'a self) { } fn m3(&self, arg: Foo<'a>) { } // &'b is not: - fn m4(&self, arg: &'b int) { } //~ ERROR undeclared lifetime + fn m4(&self, arg: &'b isize) { } //~ ERROR undeclared lifetime fn m5(&'b self) { } //~ ERROR undeclared lifetime fn m6(&self, arg: Foo<'b>) { } //~ ERROR undeclared lifetime } -fn bar<'a>(x: &'a int) { +fn bar<'a>(x: &'a isize) { // &'a is visible to code: - let y: &'a int = x; + let y: &'a isize = x; // &'a is not visible to *items*: - type X = Option<&'a int>; //~ ERROR undeclared lifetime + type X = Option<&'a isize>; //~ ERROR undeclared lifetime enum E { - E1(&'a int) //~ ERROR undeclared lifetime + E1(&'a isize) //~ ERROR undeclared lifetime } struct S { - f: &'a int //~ ERROR undeclared lifetime + f: &'a isize //~ ERROR undeclared lifetime } - fn f(a: &'a int) { } //~ ERROR undeclared lifetime + fn f(a: &'a isize) { } //~ ERROR undeclared lifetime // &'a CAN be declared on functions and used then: - fn g<'a>(a: &'a int) { } // OK - fn h(a: Box FnOnce(&'a int)>) { } // OK + fn g<'a>(a: &'a isize) { } // OK + fn h(a: Box FnOnce(&'a isize)>) { } // OK } // Test nesting of lifetimes in fn type declarations -fn fn_types(a: &'a int, //~ ERROR undeclared lifetime - b: Box FnOnce(&'a int, - &'b int, //~ ERROR undeclared lifetime - Box FnOnce(&'a int, - &'b int)>, - &'b int)>, //~ ERROR undeclared lifetime - c: &'a int) //~ ERROR undeclared lifetime +fn fn_types(a: &'a isize, //~ ERROR undeclared lifetime + b: Box FnOnce(&'a isize, + &'b isize, //~ ERROR undeclared lifetime + Box FnOnce(&'a isize, + &'b isize)>, + &'b isize)>, //~ ERROR undeclared lifetime + c: &'a isize) //~ ERROR undeclared lifetime { } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index b7fe893a1f5bb..bdebadb2832ca 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ignore(_f: F) where F: for<'z> FnOnce(&'z int) -> &'z int {} +fn ignore(_f: F) where F: for<'z> FnOnce(&'z isize) -> &'z isize {} fn nested() { let y = 3; diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index e8054779774b6..58386c319f8ab 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -12,17 +12,17 @@ fn ignore(t: T) {} -fn nested<'x>(x: &'x int) { +fn nested<'x>(x: &'x isize) { let y = 3; let mut ay = &y; - ignore:: FnMut(&'z int)>>(box |z| { + ignore:: FnMut(&'z isize)>>(box |z| { ay = x; //~ ERROR cannot infer ay = &y; ay = z; }); - ignore::< Box FnMut(&'z int) -> &'z int>>(box |z| { + ignore::< Box FnMut(&'z isize) -> &'z isize>>(box |z| { if false { return x; } //~ ERROR cannot infer an appropriate lifetime for automatic if false { return ay; } return z; diff --git a/src/test/compile-fail/regions-proc-bound-capture.rs b/src/test/compile-fail/regions-proc-bound-capture.rs index b849ddf7b8201..7ea4d1c7507af 100644 --- a/src/test/compile-fail/regions-proc-bound-capture.rs +++ b/src/test/compile-fail/regions-proc-bound-capture.rs @@ -10,13 +10,13 @@ #![feature(box_syntax)] -fn borrowed_proc<'a>(x: &'a int) -> Box(int) + 'a> { +fn borrowed_proc<'a>(x: &'a isize) -> Box(isize) + 'a> { // This is legal, because the region bound on `proc` // states that it captures `x`. box move|| { *x } } -fn static_proc(x: &int) -> Box(int) + 'static> { +fn static_proc(x: &isize) -> Box(isize) + 'static> { // This is illegal, because the region bound on `proc` is 'static. box move|| { *x } //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs index 783009f6dcbfc..9743f11c9667b 100644 --- a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs +++ b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs @@ -10,7 +10,7 @@ // Issue #8624. Test for reborrowing with 3 levels, not just two. -fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut int) -> &'b mut int { +fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut isize) -> &'b mut isize { &mut ***p //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs index 4b1c7a2928b8e..399ebd6a2a726 100644 --- a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs +++ b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs @@ -12,7 +12,7 @@ // pointer which is backed by another `&'a mut` can only be done // for `'a` (which must be a sublifetime of `'b`). -fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut int) -> &'b mut int { +fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize { &mut **p //~ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index e47fddbdc36fd..13a903bf2b559 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -10,13 +10,13 @@ #![feature(box_syntax)] -fn arg_item(box ref x: Box) -> &'static int { +fn arg_item(box ref x: Box) -> &'static isize { x //~^ ERROR borrowed value does not live long enough } -fn with(f: F) -> R where F: FnOnce(Box) -> R { f(box 3) } +fn with(f: F) -> R where F: FnOnce(Box) -> R { f(box 3) } -fn arg_closure() -> &'static int { +fn arg_closure() -> &'static isize { with(|box ref x| x) //~ ERROR borrowed value does not live long enough } diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index bd14d31217e88..b8cebe665181c 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,11 +12,11 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with(f: F) -> R where F: for<'a> FnOnce(&'a int) -> R { +fn with(f: F) -> R where F: for<'a> FnOnce(&'a isize) -> R { f(&3) } -fn return_it<'a>() -> &'a int { +fn return_it<'a>() -> &'a isize { with(|o| o) //~^ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index 4dfd4f1709a6f..40909ddd4adb5 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -10,16 +10,16 @@ // Ensure that you cannot use generic types to return a region outside // of its bound. Here, in the `return_it()` fn, we call with() but -// with R bound to &int from the return_it. Meanwhile, with() +// with R bound to &isize from the return_it. Meanwhile, with() // provides a value that is only good within its own stack frame. This // used to successfully compile because we failed to account for the -// fact that fn(x: &int) rebound the region &. +// fact that fn(x: &isize) rebound the region &. -fn with(f: F) -> R where F: FnOnce(&int) -> R { +fn with(f: F) -> R where F: FnOnce(&isize) -> R { f(&3) } -fn return_it<'a>() -> &'a int { +fn return_it<'a>() -> &'a isize { with(|o| o) //~^ ERROR cannot infer } diff --git a/src/test/compile-fail/regions-ret.rs b/src/test/compile-fail/regions-ret.rs index 4986771c79397..61c98d69d808f 100644 --- a/src/test/compile-fail/regions-ret.rs +++ b/src/test/compile-fail/regions-ret.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(_x: &int) -> &int { +fn f(_x: &isize) -> &isize { return &3; //~ ERROR borrowed value does not live long enough } diff --git a/src/test/compile-fail/regions-return-stack-allocated-vec.rs b/src/test/compile-fail/regions-return-stack-allocated-vec.rs index 3c5423c44d089..b5d4e07d04bb8 100644 --- a/src/test/compile-fail/regions-return-stack-allocated-vec.rs +++ b/src/test/compile-fail/regions-return-stack-allocated-vec.rs @@ -10,7 +10,7 @@ // Test that we cannot return a stack allocated slice -fn function(x: int) -> &'static [int] { +fn function(x: isize) -> &'static [isize] { &[x] //~ ERROR borrowed value does not live long enough } diff --git a/src/test/compile-fail/regions-trait-variance.rs b/src/test/compile-fail/regions-trait-variance.rs index 22e43c0bf8965..9ba4ef4e35837 100644 --- a/src/test/compile-fail/regions-trait-variance.rs +++ b/src/test/compile-fail/regions-trait-variance.rs @@ -13,15 +13,15 @@ // Issue #12470. trait X { - fn get_i(&self) -> int; + fn get_i(&self) -> isize; } struct B { - i: int + i: isize } impl X for B { - fn get_i(&self) -> int { + fn get_i(&self) -> isize { self.i } } diff --git a/src/test/compile-fail/regions-undeclared.rs b/src/test/compile-fail/regions-undeclared.rs index 2d1de23616b2f..3190875158055 100644 --- a/src/test/compile-fail/regions-undeclared.rs +++ b/src/test/compile-fail/regions-undeclared.rs @@ -8,15 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static c_x: &'blk int = &22; //~ ERROR use of undeclared lifetime name `'blk` +static c_x: &'blk isize = &22; //~ ERROR use of undeclared lifetime name `'blk` enum EnumDecl { - Foo(&'a int), //~ ERROR use of undeclared lifetime name `'a` - Bar(&'a int), //~ ERROR use of undeclared lifetime name `'a` + Foo(&'a isize), //~ ERROR use of undeclared lifetime name `'a` + Bar(&'a isize), //~ ERROR use of undeclared lifetime name `'a` } -fn fnDecl(x: &'a int, //~ ERROR use of undeclared lifetime name `'a` - y: &'a int) //~ ERROR use of undeclared lifetime name `'a` +fn fnDecl(x: &'a isize, //~ ERROR use of undeclared lifetime name `'a` + y: &'a isize) //~ ERROR use of undeclared lifetime name `'a` {} fn main() { diff --git a/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs b/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs index 14ead8da1587b..a7ef3ec9ac190 100644 --- a/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs +++ b/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs @@ -16,13 +16,13 @@ // `S` is contravariant with respect to both parameters. struct S<'a, 'b> { - f: &'a int, - g: &'b int, + f: &'a isize, + g: &'b isize, } fn use_<'short,'long>(c: S<'long, 'short>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { let _: S<'long, 'short> = c; // OK diff --git a/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs b/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs index 3fc58071d2ce8..a79249ade4f5c 100644 --- a/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs +++ b/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs @@ -18,12 +18,12 @@ // Contravariant<'long> <: Contravariant<'short> iff // 'short <= 'long struct Contravariant<'a> { - f: &'a int + f: &'a isize } fn use_<'short,'long>(c: Contravariant<'short>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { // Test whether Contravariant<'short> <: Contravariant<'long>. Since diff --git a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs index 844c8151a642a..f42b7027d9e00 100644 --- a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs @@ -18,12 +18,12 @@ // Covariant<'foo> <: Covariant<'static> because // 'foo <= 'static struct Covariant<'a> { - f: extern "Rust" fn(&'a int) + f: extern "Rust" fn(&'a isize) } fn use_<'short,'long>(c: Covariant<'long>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { // Test whether Covariant<'long> <: Covariant<'short>. Since diff --git a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs index d09e6babe096a..71023b26c2769 100644 --- a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs @@ -15,12 +15,12 @@ // variance inference works in the first place. struct Invariant<'a> { - f: &'a mut &'a int + f: &'a mut &'a isize } fn use_<'short,'long>(c: Invariant<'long>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { // Test whether Invariant<'long> <: Invariant<'short>. Since diff --git a/src/test/compile-fail/regions-variance-invariant-use-covariant.rs b/src/test/compile-fail/regions-variance-invariant-use-covariant.rs index 861668ad50d34..bd944a8b52cfb 100644 --- a/src/test/compile-fail/regions-variance-invariant-use-covariant.rs +++ b/src/test/compile-fail/regions-variance-invariant-use-covariant.rs @@ -15,7 +15,7 @@ // variance inference works in the first place. struct Invariant<'a> { - f: &'a mut &'a int + f: &'a mut &'a isize } fn use_<'b>(c: Invariant<'b>) { diff --git a/src/test/compile-fail/removed-syntax-enum-newtype.rs b/src/test/compile-fail/removed-syntax-enum-newtype.rs index ba1b5a616df9d..3b45fd81288fd 100644 --- a/src/test/compile-fail/removed-syntax-enum-newtype.rs +++ b/src/test/compile-fail/removed-syntax-enum-newtype.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum e = int; //~ ERROR expected one of `<` or `{`, found `=` +enum e = isize; //~ ERROR expected one of `<` or `{`, found `=` diff --git a/src/test/compile-fail/removed-syntax-extern-const.rs b/src/test/compile-fail/removed-syntax-extern-const.rs index 2f98552a953fc..98eec0977e0c1 100644 --- a/src/test/compile-fail/removed-syntax-extern-const.rs +++ b/src/test/compile-fail/removed-syntax-extern-const.rs @@ -9,5 +9,5 @@ // except according to those terms. extern { - const i: int; //~ ERROR unexpected token: `const` + const i: isize; //~ ERROR unexpected token: `const` } diff --git a/src/test/compile-fail/removed-syntax-fixed-vec.rs b/src/test/compile-fail/removed-syntax-fixed-vec.rs index 6537e3ddd27d0..0ca2380ef68c7 100644 --- a/src/test/compile-fail/removed-syntax-fixed-vec.rs +++ b/src/test/compile-fail/removed-syntax-fixed-vec.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type v = [int * 3]; //~ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `*` +type v = [isize * 3]; //~ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `*` diff --git a/src/test/compile-fail/removed-syntax-mode.rs b/src/test/compile-fail/removed-syntax-mode.rs index d2ab1881b1a07..b02de5ce08e94 100644 --- a/src/test/compile-fail/removed-syntax-mode.rs +++ b/src/test/compile-fail/removed-syntax-mode.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(+x: int) {} //~ ERROR unexpected token: `+` +fn f(+x: isize) {} //~ ERROR unexpected token: `+` diff --git a/src/test/compile-fail/removed-syntax-mut-vec-ty.rs b/src/test/compile-fail/removed-syntax-mut-vec-ty.rs index efde1f1b24d61..0f67a1d04eec3 100644 --- a/src/test/compile-fail/removed-syntax-mut-vec-ty.rs +++ b/src/test/compile-fail/removed-syntax-mut-vec-ty.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type v = [mut int]; +type v = [mut isize]; //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `int` + //~^^ ERROR expected one of `(`, `+`, `::`, `;`, or `]`, found `isize` diff --git a/src/test/compile-fail/removed-syntax-ptr-lifetime.rs b/src/test/compile-fail/removed-syntax-ptr-lifetime.rs index 1a1c4c9b40a15..d94f2ec1e073e 100644 --- a/src/test/compile-fail/removed-syntax-ptr-lifetime.rs +++ b/src/test/compile-fail/removed-syntax-ptr-lifetime.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type bptr = &lifetime/int; //~ ERROR expected one of `(`, `+`, `::`, or `;`, found `/` +type bptr = &lifetime/isize; //~ ERROR expected one of `(`, `+`, `::`, or `;`, found `/` diff --git a/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs b/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs index 8c3db89bad236..c051059aee6f4 100644 --- a/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs +++ b/src/test/compile-fail/removed-syntax-uniq-mut-ty.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type mut_box = Box; +type mut_box = Box; //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `(`, `+`, `,`, `::`, or `>`, found `int` + //~^^ ERROR expected one of `(`, `+`, `,`, `::`, or `>`, found `isize` diff --git a/src/test/compile-fail/repeat-to-run-dtor-twice.rs b/src/test/compile-fail/repeat-to-run-dtor-twice.rs index 762c976a94397..c8457adb8d6e6 100644 --- a/src/test/compile-fail/repeat-to-run-dtor-twice.rs +++ b/src/test/compile-fail/repeat-to-run-dtor-twice.rs @@ -12,7 +12,7 @@ // literal syntax. struct Foo { - x: int, + x: isize, } diff --git a/src/test/compile-fail/resolve-inconsistent-binding-mode.rs b/src/test/compile-fail/resolve-inconsistent-binding-mode.rs index df54a66f0a266..cdb812790480c 100644 --- a/src/test/compile-fail/resolve-inconsistent-binding-mode.rs +++ b/src/test/compile-fail/resolve-inconsistent-binding-mode.rs @@ -9,7 +9,7 @@ // except according to those terms. enum opts { - a(int), b(int), c(int) + a(isize), b(isize), c(isize) } fn matcher1(x: opts) { diff --git a/src/test/compile-fail/resolve-unknown-trait.rs b/src/test/compile-fail/resolve-unknown-trait.rs index 699a30ad4ebdd..0d0dc0a05d12a 100644 --- a/src/test/compile-fail/resolve-unknown-trait.rs +++ b/src/test/compile-fail/resolve-unknown-trait.rs @@ -12,7 +12,7 @@ trait NewTrait : SomeNonExistentTrait {} //~^ ERROR attempt to derive a nonexistent trait `SomeNonExistentTrait` -impl SomeNonExistentTrait for int {} +impl SomeNonExistentTrait for isize {} //~^ ERROR attempt to implement a nonexistent trait `SomeNonExistentTrait` fn f() {} diff --git a/src/test/compile-fail/ret-non-nil.rs b/src/test/compile-fail/ret-non-nil.rs index d0cb2d4e8129e..4ee3cf4abac4e 100644 --- a/src/test/compile-fail/ret-non-nil.rs +++ b/src/test/compile-fail/ret-non-nil.rs @@ -12,6 +12,6 @@ fn f() { return; } -fn g() -> int { return; } +fn g() -> isize { return; } fn main() { f(); g(); } diff --git a/src/test/compile-fail/shadowed-lifetime.rs b/src/test/compile-fail/shadowed-lifetime.rs index ff8ce7769d77e..a2a603a4b6a4b 100644 --- a/src/test/compile-fail/shadowed-lifetime.rs +++ b/src/test/compile-fail/shadowed-lifetime.rs @@ -10,27 +10,27 @@ // Test that shadowed lifetimes generate an error. -struct Foo<'a>(&'a int); +struct Foo<'a>(&'a isize); impl<'a> Foo<'a> { //~^ HELP shadowed lifetime `'a` declared here - fn shadow_in_method<'a>(&'a self) -> &'a int { + fn shadow_in_method<'a>(&'a self) -> &'a isize { //~^ WARNING lifetime name `'a` shadows another lifetime name that is already in scope //~| HELP deprecated self.0 } - fn shadow_in_type<'b>(&'b self) -> &'b int { + fn shadow_in_type<'b>(&'b self) -> &'b isize { //~^ HELP shadowed lifetime `'b` declared here - let x: for<'b> fn(&'b int) = panic!(); + let x: for<'b> fn(&'b isize) = panic!(); //~^ WARNING lifetime name `'b` shadows another lifetime name that is already in scope //~| HELP deprecated self.0 } fn not_shadow_in_item<'b>(&'b self) { - struct Bar<'a, 'b>(&'a int, &'b int); // not a shadow, separate item - fn foo<'a, 'b>(x: &'a int, y: &'b int) { } // same + struct Bar<'a, 'b>(&'a isize, &'b isize); // not a shadow, separate item + fn foo<'a, 'b>(x: &'a isize, y: &'b isize) { } // same } } @@ -39,5 +39,5 @@ fn main() { // just to ensure that this test fails to compile; when shadowed // lifetimes become either an error or a proper lint, this will // not be needed. - let x: int = 3u; //~ ERROR mismatched types + let x: isize = 3u; //~ ERROR mismatched types } diff --git a/src/test/compile-fail/shadowing-in-the-same-pattern.rs b/src/test/compile-fail/shadowing-in-the-same-pattern.rs index 0b78023d318af..c29534128ae45 100644 --- a/src/test/compile-fail/shadowing-in-the-same-pattern.rs +++ b/src/test/compile-fail/shadowing-in-the-same-pattern.rs @@ -10,7 +10,7 @@ // Test for issue #14581. -fn f((a, a): (int, int)) {} //~ ERROR identifier `a` is bound more than once +fn f((a, a): (isize, isize)) {} //~ ERROR identifier `a` is bound more than once fn main() { let (a, a) = (1, 1); //~ ERROR identifier `a` is bound more than once diff --git a/src/test/compile-fail/simd-type.rs b/src/test/compile-fail/simd-type.rs index 16be3941298de..c47bc1747de3c 100644 --- a/src/test/compile-fail/simd-type.rs +++ b/src/test/compile-fail/simd-type.rs @@ -20,6 +20,6 @@ struct empty; //~ ERROR SIMD vector cannot be empty struct i64f64(i64, f64); //~ ERROR SIMD vector should be homogeneous #[simd] -struct int4(int, int, int, int); //~ ERROR SIMD vector element type should be machine type +struct int4(isize, isize, isize, isize); //~ ERROR SIMD vector element type should be machine type fn main() {} diff --git a/src/test/compile-fail/slice-borrow.rs b/src/test/compile-fail/slice-borrow.rs index 43c4326628d33..0062f66ae2209 100644 --- a/src/test/compile-fail/slice-borrow.rs +++ b/src/test/compile-fail/slice-borrow.rs @@ -13,7 +13,7 @@ fn main() { let y; { - let x: &[int] = &[1, 2, 3, 4, 5]; //~ ERROR borrowed value does not live long enough + let x: &[isize] = &[1, 2, 3, 4, 5]; //~ ERROR borrowed value does not live long enough y = &x[1..]; } } diff --git a/src/test/compile-fail/slice-mut-2.rs b/src/test/compile-fail/slice-mut-2.rs index 12f184d410c90..ecbd360e14e51 100644 --- a/src/test/compile-fail/slice-mut-2.rs +++ b/src/test/compile-fail/slice-mut-2.rs @@ -11,8 +11,8 @@ // Test mutability and slicing syntax. fn main() { - let x: &[int] = &[1, 2, 3, 4, 5]; + let x: &[isize] = &[1, 2, 3, 4, 5]; // Can't mutably slice an immutable slice - let slice: &mut [int] = &mut [0, 1]; + let slice: &mut [isize] = &mut [0, 1]; let _ = &mut x[2..4]; //~ERROR cannot borrow immutable dereference of `&`-pointer `*x` as mutabl } diff --git a/src/test/compile-fail/slice-mut.rs b/src/test/compile-fail/slice-mut.rs index 9bd9a752e4e89..6de1bdd3eab59 100644 --- a/src/test/compile-fail/slice-mut.rs +++ b/src/test/compile-fail/slice-mut.rs @@ -11,7 +11,7 @@ // Test mutability and slicing syntax. fn main() { - let x: &[int] = &[1, 2, 3, 4, 5]; + let x: &[isize] = &[1, 2, 3, 4, 5]; // Immutable slices are not mutable. let y: &mut[_] = &x[2..4]; //~ ERROR cannot borrow immutable dereference of `&`-pointer as mutab } diff --git a/src/test/compile-fail/static-items-cant-move.rs b/src/test/compile-fail/static-items-cant-move.rs index 14ad1b3041f5b..422e95338edb9 100644 --- a/src/test/compile-fail/static-items-cant-move.rs +++ b/src/test/compile-fail/static-items-cant-move.rs @@ -13,7 +13,7 @@ use std::marker; struct Foo { - foo: int, + foo: isize, nocopy: marker::NoCopy } diff --git a/src/test/compile-fail/static-mut-bad-types.rs b/src/test/compile-fail/static-mut-bad-types.rs index 7aed3ce30bc59..088c8ef3ab8c2 100644 --- a/src/test/compile-fail/static-mut-bad-types.rs +++ b/src/test/compile-fail/static-mut-bad-types.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static mut a: int = 3; +static mut a: isize = 3; fn main() { unsafe { diff --git a/src/test/compile-fail/static-mut-not-constant.rs b/src/test/compile-fail/static-mut-not-constant.rs index fd05f05502e9c..7c228ce413f0f 100644 --- a/src/test/compile-fail/static-mut-not-constant.rs +++ b/src/test/compile-fail/static-mut-not-constant.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -static mut a: Box = box 3; +static mut a: Box = box 3; //~^ ERROR statics are not allowed to have custom pointers //~^^ ERROR mutable statics are not allowed to have owned pointers diff --git a/src/test/compile-fail/static-mut-not-pat.rs b/src/test/compile-fail/static-mut-not-pat.rs index de93422cd7a08..d4170608559ec 100644 --- a/src/test/compile-fail/static-mut-not-pat.rs +++ b/src/test/compile-fail/static-mut-not-pat.rs @@ -12,7 +12,7 @@ // statics cannot. This ensures that there's some form of error if this is // attempted. -static mut a: int = 3; +static mut a: isize = 3; fn main() { // If they can't be matched against, then it's possible to capture the same diff --git a/src/test/compile-fail/static-mut-requires-unsafe.rs b/src/test/compile-fail/static-mut-requires-unsafe.rs index 7337920cce68c..f6ad46a0527b3 100644 --- a/src/test/compile-fail/static-mut-requires-unsafe.rs +++ b/src/test/compile-fail/static-mut-requires-unsafe.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static mut a: int = 3; +static mut a: isize = 3; fn main() { a += 3; //~ ERROR: requires unsafe diff --git a/src/test/compile-fail/static-priv-by-default.rs b/src/test/compile-fail/static-priv-by-default.rs index 98b37242c03a6..14299a9b639c1 100644 --- a/src/test/compile-fail/static-priv-by-default.rs +++ b/src/test/compile-fail/static-priv-by-default.rs @@ -14,12 +14,12 @@ extern crate static_priv_by_default; mod child { pub mod childs_child { - static private: int = 0; - pub static public: int = 0; + static private: isize = 0; + pub static public: isize = 0; } } -fn foo(_: int) {} +fn foo(_: isize) {} fn full_ref() { foo(static_priv_by_default::private); //~ ERROR: static `private` is private diff --git a/src/test/compile-fail/static-priv-by-default2.rs b/src/test/compile-fail/static-priv-by-default2.rs index 2141099c7aa0e..577e4f7542d26 100644 --- a/src/test/compile-fail/static-priv-by-default2.rs +++ b/src/test/compile-fail/static-priv-by-default2.rs @@ -14,8 +14,8 @@ extern crate static_priv_by_default; mod child { pub mod childs_child { - static private: int = 0; - pub static public: int = 0; + static private: isize = 0; + pub static public: isize = 0; } } diff --git a/src/test/compile-fail/static-reference-to-fn-1.rs b/src/test/compile-fail/static-reference-to-fn-1.rs index bce397c47932f..cf8ee1ecb4183 100644 --- a/src/test/compile-fail/static-reference-to-fn-1.rs +++ b/src/test/compile-fail/static-reference-to-fn-1.rs @@ -9,16 +9,16 @@ // except according to those terms. struct A<'a> { - func: &'a fn() -> Option + func: &'a fn() -> Option } impl<'a> A<'a> { - fn call(&self) -> Option { + fn call(&self) -> Option { (*self.func)() } } -fn foo() -> Option { +fn foo() -> Option { None } diff --git a/src/test/compile-fail/static-vec-repeat-not-constant.rs b/src/test/compile-fail/static-vec-repeat-not-constant.rs index ff84ed5bf0cd4..7cb7615526a8e 100644 --- a/src/test/compile-fail/static-vec-repeat-not-constant.rs +++ b/src/test/compile-fail/static-vec-repeat-not-constant.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() -> int { 23 } +fn foo() -> isize { 23 } -static a: [int; 2] = [foo(); 2]; +static a: [isize; 2] = [foo(); 2]; //~^ ERROR: function calls in constants are limited to struct and enum constructors fn main() {} diff --git a/src/test/compile-fail/staticness-mismatch.rs b/src/test/compile-fail/staticness-mismatch.rs index a6082d3148071..bf4e46cace304 100644 --- a/src/test/compile-fail/staticness-mismatch.rs +++ b/src/test/compile-fail/staticness-mismatch.rs @@ -13,7 +13,7 @@ trait foo { fn bar(); } -impl foo for int { +impl foo for isize { fn bar(&self) {} //~^ ERROR method `bar` has a `&self` declaration in the impl, but not in the trait } diff --git a/src/test/compile-fail/struct-base-wrong-type.rs b/src/test/compile-fail/struct-base-wrong-type.rs index af6fc64535149..2bb8d32a7e3e2 100644 --- a/src/test/compile-fail/struct-base-wrong-type.rs +++ b/src/test/compile-fail/struct-base-wrong-type.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Foo { a: int, b: int } -struct Bar { x: int } +struct Foo { a: isize, b: isize } +struct Bar { x: isize } static bar: Bar = Bar { x: 5 }; static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo`, found `Bar` diff --git a/src/test/compile-fail/struct-field-assignability.rs b/src/test/compile-fail/struct-field-assignability.rs index 2c3d48e9bf735..685ce28d510a8 100644 --- a/src/test/compile-fail/struct-field-assignability.rs +++ b/src/test/compile-fail/struct-field-assignability.rs @@ -12,7 +12,7 @@ struct Foo<'a> { - x: &'a int + x: &'a isize } pub fn main() { diff --git a/src/test/compile-fail/struct-field-privacy.rs b/src/test/compile-fail/struct-field-privacy.rs index ae421815e4d11..667e944f92c56 100644 --- a/src/test/compile-fail/struct-field-privacy.rs +++ b/src/test/compile-fail/struct-field-privacy.rs @@ -13,17 +13,17 @@ extern crate "struct-field-privacy" as xc; struct A { - a: int, + a: isize, } mod inner { struct A { - a: int, - pub b: int, + a: isize, + pub b: isize, } pub struct B { - pub a: int, - b: int, + pub a: isize, + b: isize, } } diff --git a/src/test/compile-fail/struct-fields-decl-dupe.rs b/src/test/compile-fail/struct-fields-decl-dupe.rs index 78216d5f4af63..049569e8a184f 100644 --- a/src/test/compile-fail/struct-fields-decl-dupe.rs +++ b/src/test/compile-fail/struct-fields-decl-dupe.rs @@ -9,8 +9,8 @@ // except according to those terms. struct BuildData { - foo: int, - foo: int, //~ ERROR field `foo` is already declared + foo: isize, + foo: isize, //~ ERROR field `foo` is already declared } fn main() { diff --git a/src/test/compile-fail/struct-fields-dupe.rs b/src/test/compile-fail/struct-fields-dupe.rs index ffbfecdc48c7e..578091f5e9a28 100644 --- a/src/test/compile-fail/struct-fields-dupe.rs +++ b/src/test/compile-fail/struct-fields-dupe.rs @@ -9,7 +9,7 @@ // except according to those terms. struct BuildData { - foo: int, + foo: isize, } fn main() { diff --git a/src/test/compile-fail/struct-fields-missing.rs b/src/test/compile-fail/struct-fields-missing.rs index 0afc84ee1b367..1fd9357cf2d4e 100644 --- a/src/test/compile-fail/struct-fields-missing.rs +++ b/src/test/compile-fail/struct-fields-missing.rs @@ -10,8 +10,8 @@ struct BuildData { - foo: int, - bar: Box, + foo: isize, + bar: Box, } fn main() { diff --git a/src/test/compile-fail/struct-fields-too-many.rs b/src/test/compile-fail/struct-fields-too-many.rs index de58b5d110e5f..9244a9d4f9d0f 100644 --- a/src/test/compile-fail/struct-fields-too-many.rs +++ b/src/test/compile-fail/struct-fields-too-many.rs @@ -9,7 +9,7 @@ // except according to those terms. struct BuildData { - foo: int, + foo: isize, } fn main() { diff --git a/src/test/compile-fail/struct-like-enum-nonexhaustive.rs b/src/test/compile-fail/struct-like-enum-nonexhaustive.rs index 1115d78e5608d..a14e43f4c9435 100644 --- a/src/test/compile-fail/struct-like-enum-nonexhaustive.rs +++ b/src/test/compile-fail/struct-like-enum-nonexhaustive.rs @@ -9,7 +9,7 @@ // except according to those terms. enum A { - B { x: Option }, + B { x: Option }, C } diff --git a/src/test/compile-fail/struct-literal-in-for.rs b/src/test/compile-fail/struct-literal-in-for.rs index a37197b889de8..4bb5d5e6aa176 100644 --- a/src/test/compile-fail/struct-literal-in-for.rs +++ b/src/test/compile-fail/struct-literal-in-for.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } impl Foo { diff --git a/src/test/compile-fail/struct-literal-in-if.rs b/src/test/compile-fail/struct-literal-in-if.rs index 9759e4f7bdaa9..b2bc8a4901f4c 100644 --- a/src/test/compile-fail/struct-literal-in-if.rs +++ b/src/test/compile-fail/struct-literal-in-if.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } impl Foo { diff --git a/src/test/compile-fail/struct-literal-in-match-discriminant.rs b/src/test/compile-fail/struct-literal-in-match-discriminant.rs index 297d3f7347f48..8f50940806a58 100644 --- a/src/test/compile-fail/struct-literal-in-match-discriminant.rs +++ b/src/test/compile-fail/struct-literal-in-match-discriminant.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } fn main() { diff --git a/src/test/compile-fail/struct-literal-in-while.rs b/src/test/compile-fail/struct-literal-in-while.rs index 5b1679cf9a142..05fa3a8dd5fc2 100644 --- a/src/test/compile-fail/struct-literal-in-while.rs +++ b/src/test/compile-fail/struct-literal-in-while.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - x: int, + x: isize, } impl Foo { diff --git a/src/test/compile-fail/struct-pattern-match-useless.rs b/src/test/compile-fail/struct-pattern-match-useless.rs index b9c0be9276dab..9f7ebc261ad2e 100644 --- a/src/test/compile-fail/struct-pattern-match-useless.rs +++ b/src/test/compile-fail/struct-pattern-match-useless.rs @@ -9,8 +9,8 @@ // except according to those terms. struct Foo { - x: int, - y: int, + x: isize, + y: isize, } pub fn main() { diff --git a/src/test/compile-fail/struct-variant-no-pub.rs b/src/test/compile-fail/struct-variant-no-pub.rs index 15ed69083e0bf..e62b39ad5aabd 100644 --- a/src/test/compile-fail/struct-variant-no-pub.rs +++ b/src/test/compile-fail/struct-variant-no-pub.rs @@ -10,7 +10,7 @@ enum Foo { Bar { - pub a: int //~ ERROR: `pub` is not allowed here + pub a: isize //~ ERROR: `pub` is not allowed here } } diff --git a/src/test/compile-fail/struct-variant-privacy.rs b/src/test/compile-fail/struct-variant-privacy.rs index bf404c276482b..f36862364e734 100644 --- a/src/test/compile-fail/struct-variant-privacy.rs +++ b/src/test/compile-fail/struct-variant-privacy.rs @@ -9,7 +9,7 @@ // except according to those terms. mod foo { enum Bar { - Baz { a: int } + Baz { a: isize } } } diff --git a/src/test/compile-fail/tag-variant-cast-non-nullary.rs b/src/test/compile-fail/tag-variant-cast-non-nullary.rs index 1d05c5d181da5..b01063291266c 100644 --- a/src/test/compile-fail/tag-variant-cast-non-nullary.rs +++ b/src/test/compile-fail/tag-variant-cast-non-nullary.rs @@ -12,10 +12,10 @@ enum non_nullary { nullary, - other(int), + other(isize), } fn main() { let v = non_nullary::nullary; - let val = v as int; + let val = v as isize; } diff --git a/src/test/compile-fail/tail-typeck.rs b/src/test/compile-fail/tail-typeck.rs index 786d1e121379a..aeb01c93ed0e7 100644 --- a/src/test/compile-fail/tail-typeck.rs +++ b/src/test/compile-fail/tail-typeck.rs @@ -10,7 +10,7 @@ // error-pattern: mismatched types -fn f() -> int { return g(); } +fn f() -> isize { return g(); } fn g() -> uint { return 0u; } diff --git a/src/test/compile-fail/terr-in-field.rs b/src/test/compile-fail/terr-in-field.rs index 88da7bc854201..975c7e7de1ff7 100644 --- a/src/test/compile-fail/terr-in-field.rs +++ b/src/test/compile-fail/terr-in-field.rs @@ -9,12 +9,12 @@ // except according to those terms. struct foo { - a: int, - b: int, + a: isize, + b: isize, } struct bar { - a: int, + a: isize, b: uint, } diff --git a/src/test/compile-fail/terr-sorts.rs b/src/test/compile-fail/terr-sorts.rs index 53ebe1f9b5b64..d1a37c99c47b2 100644 --- a/src/test/compile-fail/terr-sorts.rs +++ b/src/test/compile-fail/terr-sorts.rs @@ -10,8 +10,8 @@ struct foo { - a: int, - b: int, + a: isize, + b: isize, } type bar = Box; diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs index c11b5d2287855..87d32a0041d31 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs @@ -15,7 +15,7 @@ struct Foo { } enum Bar { - ABar(int), + ABar(isize), BBar(T), CBar(uint), } @@ -33,7 +33,7 @@ impl Foo { struct Baz { //~^ ERROR not implemented - a: Foo, + a: Foo, } enum Boo { diff --git a/src/test/compile-fail/trait-impl-1.rs b/src/test/compile-fail/trait-impl-1.rs index 44b478bfb152b..1c7fa1e426397 100644 --- a/src/test/compile-fail/trait-impl-1.rs +++ b/src/test/compile-fail/trait-impl-1.rs @@ -18,7 +18,7 @@ impl<'a> T+'a { fn foo(&self) {} } -impl T for int {} +impl T for isize {} fn main() { let x = &42is; diff --git a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs index 1471d9232b2b0..3538c7f1289c7 100644 --- a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs +++ b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs @@ -10,7 +10,7 @@ trait A { } -impl A for int { +impl A for isize { fn foo(&self) { } //~ ERROR method `foo` is not a member of trait `A` } diff --git a/src/test/compile-fail/trait-impl-different-num-params.rs b/src/test/compile-fail/trait-impl-different-num-params.rs index ea2062dd27209..6c3e987944109 100644 --- a/src/test/compile-fail/trait-impl-different-num-params.rs +++ b/src/test/compile-fail/trait-impl-different-num-params.rs @@ -11,8 +11,8 @@ trait foo { fn bar(&self, x: uint) -> Self; } -impl foo for int { - fn bar(&self) -> int { +impl foo for isize { + fn bar(&self) -> isize { //~^ ERROR method `bar` has 1 parameter but the declaration in trait `foo::bar` has 2 *self } diff --git a/src/test/compile-fail/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs b/src/test/compile-fail/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs index 716362415a64a..44c53e70f8653 100644 --- a/src/test/compile-fail/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs +++ b/src/test/compile-fail/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs @@ -13,26 +13,26 @@ // an impl of T1<'a>, but we have an impl of T1<'b>. trait T1<'x> { - fn x(&self) -> &'x int; + fn x(&self) -> &'x isize; } trait T2<'x, 'y> : T1<'x> { - fn y(&self) -> &'y int; + fn y(&self) -> &'y isize; } struct S<'a, 'b> { - a: &'a int, - b: &'b int + a: &'a isize, + b: &'b isize } impl<'a,'b> T1<'b> for S<'a, 'b> { - fn x(&self) -> &'b int { + fn x(&self) -> &'b isize { self.b } } impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { //~ ERROR cannot infer an appropriate lifetime - fn y(&self) -> &'b int { + fn y(&self) -> &'b isize { self.b } } diff --git a/src/test/compile-fail/trait-matching-lifetimes.rs b/src/test/compile-fail/trait-matching-lifetimes.rs index 333730e0c4b80..5ab80065572c0 100644 --- a/src/test/compile-fail/trait-matching-lifetimes.rs +++ b/src/test/compile-fail/trait-matching-lifetimes.rs @@ -12,8 +12,8 @@ // (Issue #15517.) struct Foo<'a,'b> { - x: &'a int, - y: &'b int, + x: &'a isize, + y: &'b isize, } trait Tr : Sized { diff --git a/src/test/compile-fail/trait-safety-fn-body.rs b/src/test/compile-fail/trait-safety-fn-body.rs index f894e2ee28e2f..499b58f70d77a 100644 --- a/src/test/compile-fail/trait-safety-fn-body.rs +++ b/src/test/compile-fail/trait-safety-fn-body.rs @@ -15,7 +15,7 @@ unsafe trait UnsafeTrait : Sized { fn foo(self) { } } -unsafe impl UnsafeTrait for *mut int { +unsafe impl UnsafeTrait for *mut isize { fn foo(self) { // Unsafe actions are not made legal by taking place in an unsafe trait: *self += 1; //~ ERROR E0133 diff --git a/src/test/compile-fail/trait-safety-trait-impl-cc.rs b/src/test/compile-fail/trait-safety-trait-impl-cc.rs index 21dd5a237c5db..032deb2e017ac 100644 --- a/src/test/compile-fail/trait-safety-trait-impl-cc.rs +++ b/src/test/compile-fail/trait-safety-trait-impl-cc.rs @@ -17,8 +17,8 @@ extern crate "trait-safety-lib" as lib; struct Bar; impl lib::Foo for Bar { //~ ERROR requires an `unsafe impl` declaration - fn foo(&self) -> int { - *self as int + fn foo(&self) -> isize { + *self as isize } } diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index f66034e395c88..f1ff82662b966 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -11,11 +11,11 @@ #![feature(box_syntax)] trait bar { fn dup(&self) -> Self; fn blah(&self); } -impl bar for int { fn dup(&self) -> int { *self } fn blah(&self) {} } +impl bar for isize { fn dup(&self) -> isize { *self } fn blah(&self) {} } impl bar for uint { fn dup(&self) -> uint { *self } fn blah(&self) {} } fn main() { - 10i.dup::(); //~ ERROR does not take type parameters - 10i.blah::(); //~ ERROR incorrect number of type parameters + 10i.dup::(); //~ ERROR does not take type parameters + 10i.blah::(); //~ ERROR incorrect number of type parameters (box 10i as Box).dup(); //~ ERROR cannot convert to a trait object } diff --git a/src/test/compile-fail/trait-test.rs b/src/test/compile-fail/trait-test.rs index 1682e98fb2383..6039e646407e3 100644 --- a/src/test/compile-fail/trait-test.rs +++ b/src/test/compile-fail/trait-test.rs @@ -10,6 +10,6 @@ trait foo { fn foo(&self); } -impl int for uint { fn foo(&self) {} } //~ ERROR trait +impl isize for uint { fn foo(&self) {} } //~ ERROR trait fn main() {} diff --git a/src/test/compile-fail/traits-multidispatch-bad.rs b/src/test/compile-fail/traits-multidispatch-bad.rs index f5ce904a4bb5c..d155735d69cf8 100644 --- a/src/test/compile-fail/traits-multidispatch-bad.rs +++ b/src/test/compile-fail/traits-multidispatch-bad.rs @@ -14,7 +14,7 @@ trait Convert { fn convert(&self) -> Target; } -impl Convert for int { +impl Convert for isize { fn convert(&self) -> uint { *self as uint } diff --git a/src/test/compile-fail/transmute-impl.rs b/src/test/compile-fail/transmute-impl.rs index a68bba285df29..a77a37a77e146 100644 --- a/src/test/compile-fail/transmute-impl.rs +++ b/src/test/compile-fail/transmute-impl.rs @@ -19,12 +19,12 @@ struct Foo { } impl Foo { - fn m(x: &T) -> &int where T : Sized { + fn m(x: &T) -> &isize where T : Sized { // OK here, because T : Sized is in scope. unsafe { transmute(x) } } - fn n(x: &T) -> &int { + fn n(x: &T) -> &isize { // Not OK here, because T : Sized is not in scope. unsafe { transmute(x) } //~ ERROR transmute called on types with potentially different sizes } diff --git a/src/test/compile-fail/transmute-type-parameters.rs b/src/test/compile-fail/transmute-type-parameters.rs index 2286c0e75bd9d..b06966bd867ca 100644 --- a/src/test/compile-fail/transmute-type-parameters.rs +++ b/src/test/compile-fail/transmute-type-parameters.rs @@ -13,15 +13,15 @@ use std::mem::transmute; unsafe fn f(x: T) { - let _: int = transmute(x); //~ ERROR cannot transmute + let _: isize = transmute(x); //~ ERROR cannot transmute } -unsafe fn g(x: (T, int)) { - let _: int = transmute(x); //~ ERROR cannot transmute +unsafe fn g(x: (T, isize)) { + let _: isize = transmute(x); //~ ERROR cannot transmute } unsafe fn h(x: [T; 10]) { - let _: int = transmute(x); //~ ERROR cannot transmute + let _: isize = transmute(x); //~ ERROR cannot transmute } struct Bad { @@ -29,7 +29,7 @@ struct Bad { } unsafe fn i(x: Bad) { - let _: int = transmute(x); //~ ERROR cannot transmute + let _: isize = transmute(x); //~ ERROR cannot transmute } enum Worse { @@ -38,11 +38,11 @@ enum Worse { } unsafe fn j(x: Worse) { - let _: int = transmute(x); //~ ERROR cannot transmute + let _: isize = transmute(x); //~ ERROR cannot transmute } unsafe fn k(x: Option) { - let _: int = transmute(x); //~ ERROR cannot transmute + let _: isize = transmute(x); //~ ERROR cannot transmute } fn main() {} diff --git a/src/test/compile-fail/tuple-index-not-tuple.rs b/src/test/compile-fail/tuple-index-not-tuple.rs index 33aeebb369166..bf2a63abbfd6c 100644 --- a/src/test/compile-fail/tuple-index-not-tuple.rs +++ b/src/test/compile-fail/tuple-index-not-tuple.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Point { x: int, y: int } +struct Point { x: isize, y: isize } struct Empty; fn main() { diff --git a/src/test/compile-fail/tuple-struct-nonexhaustive.rs b/src/test/compile-fail/tuple-struct-nonexhaustive.rs index 1f14fbb27adee..e4fda6dd53417 100644 --- a/src/test/compile-fail/tuple-struct-nonexhaustive.rs +++ b/src/test/compile-fail/tuple-struct-nonexhaustive.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Foo(int, int); +struct Foo(isize, isize); fn main() { let x = Foo(1, 2); diff --git a/src/test/compile-fail/tutorial-suffix-inference-test.rs b/src/test/compile-fail/tutorial-suffix-inference-test.rs index 85ad302f3ed4d..1b44c7e8128a2 100644 --- a/src/test/compile-fail/tutorial-suffix-inference-test.rs +++ b/src/test/compile-fail/tutorial-suffix-inference-test.rs @@ -23,7 +23,7 @@ fn main() { let a = 3is; - fn identity_i(n: isize) -> int { n } + fn identity_i(n: isize) -> isize { n } identity_i(a); // ok identity_u16(a); diff --git a/src/test/compile-fail/type-parameters-in-field-exprs.rs b/src/test/compile-fail/type-parameters-in-field-exprs.rs index 023f7d1c29f5f..54ddb3e19fa48 100644 --- a/src/test/compile-fail/type-parameters-in-field-exprs.rs +++ b/src/test/compile-fail/type-parameters-in-field-exprs.rs @@ -9,8 +9,8 @@ // except according to those terms. struct Foo { - x: int, - y: int, + x: isize, + y: isize, } fn main() { @@ -18,7 +18,7 @@ fn main() { x: 1, y: 2, }; - f.x::; + f.x::; //~^ ERROR field expressions may not have type parameters } diff --git a/src/test/compile-fail/type-recursive.rs b/src/test/compile-fail/type-recursive.rs index a2b4e8d9782fd..9dcb60628a907 100644 --- a/src/test/compile-fail/type-recursive.rs +++ b/src/test/compile-fail/type-recursive.rs @@ -10,7 +10,7 @@ // error-pattern:this type cannot be instantiated struct t1 { - foo: int, + foo: isize, foolish: t1 } diff --git a/src/test/compile-fail/type-shadow.rs b/src/test/compile-fail/type-shadow.rs index 50c8cf99d3c4a..6d8c0fe22bdb7 100644 --- a/src/test/compile-fail/type-shadow.rs +++ b/src/test/compile-fail/type-shadow.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - type X = int; + type X = isize; type Y = X; if true { type X = &'static str; diff --git a/src/test/compile-fail/ufcs-explicit-self-bad.rs b/src/test/compile-fail/ufcs-explicit-self-bad.rs index 5ba660495f705..60b2002ae97c8 100644 --- a/src/test/compile-fail/ufcs-explicit-self-bad.rs +++ b/src/test/compile-fail/ufcs-explicit-self-bad.rs @@ -11,11 +11,11 @@ #![feature(box_syntax)] struct Foo { - f: int, + f: isize, } impl Foo { - fn foo(self: int, x: int) -> int { //~ ERROR mismatched self type + fn foo(self: isize, x: isize) -> isize { //~ ERROR mismatched self type self.f + x } } @@ -25,10 +25,10 @@ struct Bar { } impl Bar { - fn foo(self: Bar, x: int) -> int { //~ ERROR mismatched self type + fn foo(self: Bar, x: isize) -> isize { //~ ERROR mismatched self type x } - fn bar(self: &Bar, x: int) -> int { //~ ERROR mismatched self type + fn bar(self: &Bar, x: isize) -> isize { //~ ERROR mismatched self type x } } diff --git a/src/test/compile-fail/unboxed-closure-feature-gate.rs b/src/test/compile-fail/unboxed-closure-feature-gate.rs index 9bb8037e2c344..5eb67a9bb71d4 100644 --- a/src/test/compile-fail/unboxed-closure-feature-gate.rs +++ b/src/test/compile-fail/unboxed-closure-feature-gate.rs @@ -15,11 +15,11 @@ trait Foo { } fn main() { - let x: Box; + let x: Box; //~^ ERROR parenthetical notation is only stable when used with the `Fn` family // No errors with these: - let x: Box; - let x: Box; - let x: Box; + let x: Box; + let x: Box; + let x: Box; } diff --git a/src/test/compile-fail/unboxed-closure-sugar-default.rs b/src/test/compile-fail/unboxed-closure-sugar-default.rs index 82355ddf68176..0d9e406b0867c 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-default.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-default.rs @@ -24,14 +24,14 @@ fn eq() where A : Eq { } fn test<'a,'b>() { // Parens are equivalent to omitting default in angle. - eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(isize,),()>, Foo(isize) >(); // In angle version, we supply something other than the default - eq::< Foo<(int,),(),int>, Foo(int) >(); + eq::< Foo<(isize,),(),isize>, Foo(isize) >(); //~^ ERROR not implemented // Supply default explicitly. - eq::< Foo<(int,),(),(int,)>, Foo(int) >(); + eq::< Foo<(isize,),(),(isize,)>, Foo(isize) >(); } fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs index f36fad306704f..f37dcfb774581 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs @@ -27,26 +27,26 @@ fn eq>() { } fn test<'a,'b>() { // No errors expected: eq::< Foo<(),()>, Foo() >(); - eq::< Foo<(int,),()>, Foo(int) >(); - eq::< Foo<(int,uint),()>, Foo(int,uint) >(); - eq::< Foo<(int,uint),uint>, Foo(int,uint) -> uint >(); - eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >(); + eq::< Foo<(isize,),()>, Foo(isize) >(); + eq::< Foo<(isize,uint),()>, Foo(isize,uint) >(); + eq::< Foo<(isize,uint),uint>, Foo(isize,uint) -> uint >(); + eq::< Foo<(&'a isize,&'b uint),uint>, Foo(&'a isize,&'b uint) -> uint >(); // Test that anonymous regions in `()` form are equivalent // to fresh bound regions, and that we can intermingle // named and anonymous as we choose: - eq::< for<'x,'y> Foo<(&'x int,&'y uint),uint>, - for<'x,'y> Foo(&'x int,&'y uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x int,&'y uint),uint>, - for<'x> Foo(&'x int,&uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x int,&'y uint),uint>, - for<'y> Foo(&int,&'y uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x int,&'y uint),uint>, - Foo(&int,&uint) -> uint >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, + for<'x,'y> Foo(&'x isize,&'y uint) -> uint >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, + for<'x> Foo(&'x isize,&uint) -> uint >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, + for<'y> Foo(&isize,&'y uint) -> uint >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, + Foo(&isize,&uint) -> uint >(); // lifetime elision - eq::< for<'x> Foo<(&'x int,), &'x int>, - Foo(&int) -> &int >(); + eq::< for<'x> Foo<(&'x isize,), &'x isize>, + Foo(&isize) -> &isize >(); // Errors expected: eq::< Foo<(),()>, Foo(char) >(); diff --git a/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs b/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs index 2617be295cd2a..176970703c5e3 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs @@ -25,10 +25,10 @@ impl Eq for X { } fn eq>() { } fn main() { - eq::< for<'a> Foo<(&'a int,), &'a int>, - Foo(&int) -> &int >(); - eq::< for<'a> Foo<(&'a int,), (&'a int, &'a int)>, - Foo(&int) -> (&int, &int) >(); + eq::< for<'a> Foo<(&'a isize,), &'a isize>, + Foo(&isize) -> &isize >(); + eq::< for<'a> Foo<(&'a isize,), (&'a isize, &'a isize)>, + Foo(&isize) -> (&isize, &isize) >(); - let _: Foo(&int, &uint) -> &uint; //~ ERROR missing lifetime specifier + let _: Foo(&isize, &uint) -> &uint; //~ ERROR missing lifetime specifier } diff --git a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs index 23e2d2f4365af..12f62d805e15a 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs @@ -10,11 +10,11 @@ #![feature(unboxed_closures)] -fn f int>(x: F) {} //~ ERROR nonexistent trait `Nonexist` +fn f isize>(x: F) {} //~ ERROR nonexistent trait `Nonexist` -type Typedef = int; +type Typedef = isize; -fn g int>(x: F) {} //~ ERROR `Typedef` is not a trait +fn g isize>(x: F) {} //~ ERROR `Typedef` is not a trait fn main() {} diff --git a/src/test/compile-fail/unboxed-closure-sugar-region.rs b/src/test/compile-fail/unboxed-closure-sugar-region.rs index e0783b09cbdf5..c8dd33c11fd3b 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-region.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-region.rs @@ -29,14 +29,14 @@ fn same_type>(a: A, b: B) { } fn test<'a,'b>() { // Parens are equivalent to omitting default in angle. - eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(isize,),()>, Foo(isize) >(); // Here we specify 'static explicitly in angle-bracket version. // Parenthesized winds up getting inferred. - eq::< Foo<'static, (int,),()>, Foo(int) >(); + eq::< Foo<'static, (isize,),()>, Foo(isize) >(); } -fn test2(x: &Foo<(int,),()>, y: &Foo(int)) { +fn test2(x: &Foo<(isize,),()>, y: &Foo(isize)) { // Here, the omitted lifetimes are expanded to distinct things. same_type(x, y) //~ ERROR cannot infer } diff --git a/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs b/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs index 5e16adc4e4247..b2bd030f3c46a 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs @@ -19,7 +19,7 @@ impl Bar { } fn bar() { - let b = Box::Bar::::new(); // OK + let b = Box::Bar::::new(); // OK let b = Box::Bar::()::new(); //~^ ERROR expected ident, found `(` diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs index ba1e931ac6434..b58e08355c118 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs @@ -12,7 +12,7 @@ trait Trait {} -fn f int>(x: F) {} +fn f isize>(x: F) {} //~^ ERROR wrong number of type arguments: expected 0, found 2 fn main() {} diff --git a/src/test/compile-fail/unboxed-closures-fnmut-as-fn.rs b/src/test/compile-fail/unboxed-closures-fnmut-as-fn.rs index 9fbb8a18ae93a..fc87ec9f9598c 100644 --- a/src/test/compile-fail/unboxed-closures-fnmut-as-fn.rs +++ b/src/test/compile-fail/unboxed-closures-fnmut-as-fn.rs @@ -18,13 +18,13 @@ use std::ops::{Fn,FnMut,FnOnce}; struct S; -impl FnMut<(int,),int> for S { - extern "rust-call" fn call_mut(&mut self, (x,): (int,)) -> int { +impl FnMut<(isize,),isize> for S { + extern "rust-call" fn call_mut(&mut self, (x,): (isize,)) -> isize { x * x } } -fn call_itint>(f: &F, x: int) -> int { +fn call_itisize>(f: &F, x: isize) -> isize { f.call((x,)) } diff --git a/src/test/compile-fail/unboxed-closures-type-mismatch.rs b/src/test/compile-fail/unboxed-closures-type-mismatch.rs index 61f1317283272..6c2e9f431fe82 100644 --- a/src/test/compile-fail/unboxed-closures-type-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-type-mismatch.rs @@ -13,7 +13,7 @@ use std::ops::FnMut; pub fn main() { - let mut f = |&mut: x: int, y: int| -> int { x + y }; + let mut f = |&mut: x: isize, y: isize| -> isize { x + y }; let z = f(1u, 2); //~ ERROR mismatched types println!("{}", z); } diff --git a/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs index b0b37d077c170..ab909717cab65 100644 --- a/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs +++ b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs @@ -14,11 +14,11 @@ use std::ops::{Fn,FnMut,FnOnce}; -unsafe fn square(x: &int) -> int { (*x) * (*x) } +unsafe fn square(x: &isize) -> isize { (*x) * (*x) } -fn call_itint>(_: &F, _: int) -> int { 0 } -fn call_it_mutint>(_: &mut F, _: int) -> int { 0 } -fn call_it_onceint>(_: F, _: int) -> int { 0 } +fn call_itisize>(_: &F, _: isize) -> isize { 0 } +fn call_it_mutisize>(_: &mut F, _: isize) -> isize { 0 } +fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~ ERROR not implemented diff --git a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs index 85b33f73bbcb7..ca641e39aedfc 100644 --- a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs @@ -12,12 +12,12 @@ use std::ops::FnMut; -fn call_it>(y: int, mut f: F) -> int { +fn call_it>(y: isize, mut f: F) -> isize { f(2, y) } pub fn main() { - let f = |&mut: x: uint, y: int| -> int { (x as int) + y }; + let f = |&mut: x: uint, y: isize| -> isize { (x as isize) + y }; let z = call_it(3, f); //~ ERROR type mismatch println!("{}", z); } diff --git a/src/test/compile-fail/unboxed-closures-wrong-abi.rs b/src/test/compile-fail/unboxed-closures-wrong-abi.rs index 20a4ab85d7ba8..4a0b55558c049 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-abi.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-abi.rs @@ -14,11 +14,11 @@ use std::ops::{Fn,FnMut,FnOnce}; -extern "C" fn square(x: &int) -> int { (*x) * (*x) } +extern "C" fn square(x: &isize) -> isize { (*x) * (*x) } -fn call_itint>(_: &F, _: int) -> int { 0 } -fn call_it_mutint>(_: &mut F, _: int) -> int { 0 } -fn call_it_onceint>(_: F, _: int) -> int { 0 } +fn call_itisize>(_: &F, _: isize) -> isize { 0 } +fn call_it_mutisize>(_: &mut F, _: isize) -> isize { 0 } +fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~ ERROR not implemented diff --git a/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs index f08cff3cd6821..b2fdf79263019 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs @@ -14,12 +14,12 @@ use std::ops::{Fn,FnMut,FnOnce}; -unsafe fn square(x: int) -> int { x * x } -// note: argument type here is `int`, not `&int` +unsafe fn square(x: isize) -> isize { x * x } +// note: argument type here is `isize`, not `&isize` -fn call_itint>(_: &F, _: int) -> int { 0 } -fn call_it_mutint>(_: &mut F, _: int) -> int { 0 } -fn call_it_onceint>(_: F, _: int) -> int { 0 } +fn call_itisize>(_: &F, _: isize) -> isize { 0 } +fn call_it_mutisize>(_: &mut F, _: isize) -> isize { 0 } +fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~ ERROR not implemented diff --git a/src/test/compile-fail/unboxed-closures-wrong-trait.rs b/src/test/compile-fail/unboxed-closures-wrong-trait.rs index e15fe8ad049b0..e4255d0024feb 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-trait.rs @@ -10,13 +10,13 @@ #![feature(lang_items, overloaded_calls, unboxed_closures)] -fn c int>(f: F) -> int { +fn c isize>(f: F) -> isize { f(5, 6) } fn main() { - let z: int = 7; - assert_eq!(c(|&mut: x: int, y| x + y + z), 10); + let z: isize = 7; + assert_eq!(c(|&mut: x: isize, y| x + y + z), 10); //~^ ERROR not implemented } diff --git a/src/test/compile-fail/uninhabited-enum-cast.rs b/src/test/compile-fail/uninhabited-enum-cast.rs index 9f91337db9f21..b4df5fb1e2acc 100644 --- a/src/test/compile-fail/uninhabited-enum-cast.rs +++ b/src/test/compile-fail/uninhabited-enum-cast.rs @@ -11,7 +11,7 @@ enum E {} fn f(e: E) { - println!("{}", (e as int).to_string()); //~ ERROR non-scalar cast + println!("{}", (e as isize).to_string()); //~ ERROR non-scalar cast } fn main() {} diff --git a/src/test/compile-fail/unique-object-noncopyable.rs b/src/test/compile-fail/unique-object-noncopyable.rs index 2dde11ada2855..5074d00ca1587 100644 --- a/src/test/compile-fail/unique-object-noncopyable.rs +++ b/src/test/compile-fail/unique-object-noncopyable.rs @@ -15,7 +15,7 @@ trait Foo { } struct Bar { - x: int, + x: isize, } impl Drop for Bar { diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index b558989304f64..4a84bb4c5ab04 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -16,7 +16,7 @@ use std::cell::Cell; #[derive(Show)] struct r<'a> { - i: &'a Cell, + i: &'a Cell, } #[unsafe_destructor] diff --git a/src/test/compile-fail/unnecessary-private.rs b/src/test/compile-fail/unnecessary-private.rs index abbb084dbc043..6e6ffd23c4a87 100644 --- a/src/test/compile-fail/unnecessary-private.rs +++ b/src/test/compile-fail/unnecessary-private.rs @@ -19,7 +19,7 @@ fn main() { } struct D { - pub foo: int, //~ ERROR: visibility has no effect + pub foo: isize, //~ ERROR: visibility has no effect } pub fn foo() {} //~ ERROR: visibility has no effect pub mod bar {} //~ ERROR: visibility has no effect diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs index 934ddb5f80bb1..c4c0e648f3470 100644 --- a/src/test/compile-fail/unreachable-arm.rs +++ b/src/test/compile-fail/unreachable-arm.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] -enum foo { a(Box, int), b(uint), } +enum foo { a(Box, isize), b(uint), } fn main() { match foo::b(1u) { foo::b(_) | foo::a(box _, 1) => { } foo::a(_, 1) => { } } } diff --git a/src/test/compile-fail/unsafe-fn-autoderef.rs b/src/test/compile-fail/unsafe-fn-autoderef.rs index 464abd57872bc..97a7bf147105a 100644 --- a/src/test/compile-fail/unsafe-fn-autoderef.rs +++ b/src/test/compile-fail/unsafe-fn-autoderef.rs @@ -9,10 +9,10 @@ // except according to those terms. struct Rec { - f: int + f: isize } -fn f(p: *const Rec) -> int { +fn f(p: *const Rec) -> isize { // Test that * ptrs do not autoderef. There is a deeper reason for // prohibiting this, beyond making unsafe things annoying (which doesn't diff --git a/src/test/compile-fail/unsendable-class.rs b/src/test/compile-fail/unsendable-class.rs index 96f36af53aad2..abd93fdfc6c61 100644 --- a/src/test/compile-fail/unsendable-class.rs +++ b/src/test/compile-fail/unsendable-class.rs @@ -16,11 +16,11 @@ use std::sync::mpsc::channel; use std::rc::Rc; struct foo { - i: int, + i: isize, j: Rc, } -fn foo(i:int, j: Rc) -> foo { +fn foo(i:isize, j: Rc) -> foo { foo { i: i, j: j diff --git a/src/test/compile-fail/unsized5.rs b/src/test/compile-fail/unsized5.rs index 026d496aa43c7..02a8b5899d734 100644 --- a/src/test/compile-fail/unsized5.rs +++ b/src/test/compile-fail/unsized5.rs @@ -12,12 +12,12 @@ struct S1 { f1: X, //~ ERROR `core::marker::Sized` is not implemented - f2: int, + f2: isize, } struct S2 { - f: int, + f: isize, g: X, //~ ERROR `core::marker::Sized` is not implemented - h: int, + h: isize, } struct S3 { f: str, //~ ERROR `core::marker::Sized` is not implemented @@ -28,10 +28,10 @@ struct S4 { g: uint } enum E { - V1(X, int), //~ERROR `core::marker::Sized` is not implemented + V1(X, isize), //~ERROR `core::marker::Sized` is not implemented } enum F { - V2{f1: X, f: int}, //~ERROR `core::marker::Sized` is not implemented + V2{f1: X, f: isize}, //~ERROR `core::marker::Sized` is not implemented } pub fn main() { diff --git a/src/test/compile-fail/unsized6.rs b/src/test/compile-fail/unsized6.rs index 02f3404b72b11..2129f075a81b5 100644 --- a/src/test/compile-fail/unsized6.rs +++ b/src/test/compile-fail/unsized6.rs @@ -15,13 +15,13 @@ trait T {} fn f1(x: &X) { let _: X; // <-- this is OK, no bindings created, no initializer. - let _: (int, (X, int)); // same + let _: (isize, (X, isize)); // same let y: X; //~ERROR the trait `core::marker::Sized` is not implemented - let y: (int, (X, int)); //~ERROR the trait `core::marker::Sized` is not implemented + let y: (isize, (X, isize)); //~ERROR the trait `core::marker::Sized` is not implemented } fn f2(x: &X) { let y: X; //~ERROR the trait `core::marker::Sized` is not implemented - let y: (int, (X, int)); //~ERROR the trait `core::marker::Sized` is not implemented + let y: (isize, (X, isize)); //~ERROR the trait `core::marker::Sized` is not implemented } fn f3(x1: Box, x2: Box, x3: Box) { diff --git a/src/test/compile-fail/unused-attr.rs b/src/test/compile-fail/unused-attr.rs index 786421c4ef9d4..635ceec73a385 100644 --- a/src/test/compile-fail/unused-attr.rs +++ b/src/test/compile-fail/unused-attr.rs @@ -44,7 +44,7 @@ fn bar(f: foo::Foo) { #[foo] //~ ERROR unused attribute struct Foo { #[foo] //~ ERROR unused attribute - a: int + a: isize } #[foo] //~ ERROR unused attribute diff --git a/src/test/compile-fail/unused-result.rs b/src/test/compile-fail/unused-result.rs index 1263d7c5710f6..6ed3b081c97fd 100644 --- a/src/test/compile-fail/unused-result.rs +++ b/src/test/compile-fail/unused-result.rs @@ -19,30 +19,30 @@ enum MustUseMsg { Test2 } fn foo() -> T { panic!() } -fn bar() -> int { return foo::(); } +fn bar() -> isize { return foo::(); } fn baz() -> MustUse { return foo::(); } fn qux() -> MustUseMsg { return foo::(); } #[allow(unused_results)] fn test() { - foo::(); + foo::(); foo::(); //~ ERROR: unused result which must be used foo::(); //~ ERROR: unused result which must be used: some message } #[allow(unused_results, unused_must_use)] fn test2() { - foo::(); + foo::(); foo::(); foo::(); } fn main() { - foo::(); //~ ERROR: unused result + foo::(); //~ ERROR: unused result foo::(); //~ ERROR: unused result which must be used foo::(); //~ ERROR: unused result which must be used: some message - let _ = foo::(); + let _ = foo::(); let _ = foo::(); let _ = foo::(); } diff --git a/src/test/compile-fail/use-after-move-self-based-on-type.rs b/src/test/compile-fail/use-after-move-self-based-on-type.rs index a1b7f83da2fcf..810fc68a0f4da 100644 --- a/src/test/compile-fail/use-after-move-self-based-on-type.rs +++ b/src/test/compile-fail/use-after-move-self-based-on-type.rs @@ -9,7 +9,7 @@ // except according to those terms. struct S { - x: int, + x: isize, } impl Drop for S { @@ -17,7 +17,7 @@ impl Drop for S { } impl S { - pub fn foo(self) -> int { + pub fn foo(self) -> isize { self.bar(); return self.x; //~ ERROR use of moved value: `self.x` } diff --git a/src/test/compile-fail/use-after-move-self.rs b/src/test/compile-fail/use-after-move-self.rs index ce0f2808e33fe..e9ffb26aba5b7 100644 --- a/src/test/compile-fail/use-after-move-self.rs +++ b/src/test/compile-fail/use-after-move-self.rs @@ -11,11 +11,11 @@ #![feature(box_syntax)] struct S { - x: Box, + x: Box, } impl S { - pub fn foo(self) -> int { + pub fn foo(self) -> isize { self.bar(); return *self.x; //~ ERROR use of moved value: `*self.x` } diff --git a/src/test/compile-fail/use-mod-3.rs b/src/test/compile-fail/use-mod-3.rs index 040674fd6d93b..bd954272fcca2 100644 --- a/src/test/compile-fail/use-mod-3.rs +++ b/src/test/compile-fail/use-mod-3.rs @@ -17,7 +17,7 @@ use foo::bar::{ }; mod foo { - mod bar { pub type Bar = int; } + mod bar { pub type Bar = isize; } } fn main() {} diff --git a/src/test/compile-fail/useless-priv.rs b/src/test/compile-fail/useless-priv.rs index bb39107463e11..d8531f4543dff 100644 --- a/src/test/compile-fail/useless-priv.rs +++ b/src/test/compile-fail/useless-priv.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct A { pub i: int } +struct A { pub i: isize } pub enum C { pub Variant } //~ ERROR: unnecessary `pub` pub trait E { diff --git a/src/test/compile-fail/variadic-ffi-1.rs b/src/test/compile-fail/variadic-ffi-1.rs index 93f702d8052de..34846ab496d2f 100644 --- a/src/test/compile-fail/variadic-ffi-1.rs +++ b/src/test/compile-fail/variadic-ffi-1.rs @@ -10,7 +10,7 @@ extern { fn printf(...); //~ ERROR: variadic function must be declared with at least one named argument - fn printf(..., foo: int); //~ ERROR: `...` must be last in argument list for variadic function + fn printf(..., foo: isize); //~ ERROR: `...` must be last in argument list for variadic function } fn main() {} diff --git a/src/test/compile-fail/variadic-ffi-3.rs b/src/test/compile-fail/variadic-ffi-3.rs index f143e715450ff..331a45239345c 100644 --- a/src/test/compile-fail/variadic-ffi-3.rs +++ b/src/test/compile-fail/variadic-ffi-3.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int, ...) { +fn foo(x: isize, ...) { //~^ ERROR: only foreign functions are allowed to be variadic } diff --git a/src/test/compile-fail/variadic-ffi-4.rs b/src/test/compile-fail/variadic-ffi-4.rs index d4c54dfffe0a3..62e985f44f734 100644 --- a/src/test/compile-fail/variadic-ffi-4.rs +++ b/src/test/compile-fail/variadic-ffi-4.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern "C" fn foo(x: int, ...) { +extern "C" fn foo(x: isize, ...) { //~^ ERROR: only foreign functions are allowed to be variadic } diff --git a/src/test/compile-fail/variance-cell-is-invariant.rs b/src/test/compile-fail/variance-cell-is-invariant.rs index 0efca74f3ced6..b8a8f9ad91c72 100644 --- a/src/test/compile-fail/variance-cell-is-invariant.rs +++ b/src/test/compile-fail/variance-cell-is-invariant.rs @@ -14,12 +14,12 @@ use std::cell::Cell; struct Foo<'a> { - x: Cell>, + x: Cell>, } fn use_<'short,'long>(c: Foo<'short>, - s: &'short int, - l: &'long int, + s: &'short isize, + l: &'long isize, _where:Option<&'short &'long ()>) { let _: Foo<'long> = c; //~ ERROR mismatched types } diff --git a/src/test/compile-fail/variance-regions-direct.rs b/src/test/compile-fail/variance-regions-direct.rs index fa38482b21c50..04389b67dba04 100644 --- a/src/test/compile-fail/variance-regions-direct.rs +++ b/src/test/compile-fail/variance-regions-direct.rs @@ -15,8 +15,8 @@ #[rustc_variance] struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[]] - x: &'a int, - y: &'b [int], + x: &'a isize, + y: &'b [isize], c: &'c str } @@ -24,8 +24,8 @@ struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[]] #[rustc_variance] struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]] - x: extern "Rust" fn(&'a int), - y: extern "Rust" fn(&'b [int]), + x: extern "Rust" fn(&'a isize), + y: extern "Rust" fn(&'b [isize]), c: extern "Rust" fn(&'c str), } @@ -33,7 +33,7 @@ struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]] #[rustc_variance] struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]] - x: &'a mut &'b int, + x: &'a mut &'b isize, } // Mutability induces invariance, even when in a @@ -41,32 +41,32 @@ struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]] #[rustc_variance] struct Test5<'a, 'b> { //~ ERROR regions=[[+, o];[];[]] - x: extern "Rust" fn(&'a mut &'b int), + x: extern "Rust" fn(&'a mut &'b isize), } // Invariance is a trap from which NO ONE CAN ESCAPE. -// In other words, even though the `&'b int` occurs in +// In other words, even though the `&'b isize` occurs in // a argument list (which is contravariant), that // argument list occurs in an invariant context. #[rustc_variance] struct Test6<'a, 'b> { //~ ERROR regions=[[-, o];[];[]] - x: &'a mut extern "Rust" fn(&'b int), + x: &'a mut extern "Rust" fn(&'b isize), } // No uses at all is bivariant: #[rustc_variance] struct Test7<'a> { //~ ERROR regions=[[*];[];[]] - x: int + x: isize } // Try enums too. #[rustc_variance] enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]] - Test8A(extern "Rust" fn(&'a int)), - Test8B(&'b [int]), + Test8A(extern "Rust" fn(&'a isize)), + Test8B(&'b [isize]), Test8C(&'b mut &'c str), } diff --git a/src/test/compile-fail/variance-regions-indirect.rs b/src/test/compile-fail/variance-regions-indirect.rs index c049fbc0fedbc..e2c7958b31dec 100644 --- a/src/test/compile-fail/variance-regions-indirect.rs +++ b/src/test/compile-fail/variance-regions-indirect.rs @@ -14,8 +14,8 @@ #[rustc_variance] enum Base<'a, 'b, 'c:'b, 'd> { //~ ERROR regions=[[+, -, o, *];[];[]] - Test8A(extern "Rust" fn(&'a int)), - Test8B(&'b [int]), + Test8A(extern "Rust" fn(&'a isize)), + Test8B(&'b [isize]), Test8C(&'b mut &'c str), } diff --git a/src/test/compile-fail/variance-trait-matching.rs b/src/test/compile-fail/variance-trait-matching.rs index 1644705222f70..d4dab5f0ed05d 100644 --- a/src/test/compile-fail/variance-trait-matching.rs +++ b/src/test/compile-fail/variance-trait-matching.rs @@ -11,18 +11,18 @@ // Issue #5781. Tests that subtyping is handled properly in trait matching. trait Make<'a> { - fn make(x: &'a mut int) -> Self; + fn make(x: &'a mut isize) -> Self; } -impl<'a> Make<'a> for &'a mut int { - fn make(x: &'a mut int) -> &'a mut int { +impl<'a> Make<'a> for &'a mut isize { + fn make(x: &'a mut isize) -> &'a mut isize { x } } -fn f() -> &'static mut int { +fn f() -> &'static mut isize { let mut x = 1; - let y: &'static mut int = Make::make(&mut x); //~ ERROR `x` does not live long enough + let y: &'static mut isize = Make::make(&mut x); //~ ERROR `x` does not live long enough y } diff --git a/src/test/compile-fail/vec-mut-iter-borrow.rs b/src/test/compile-fail/vec-mut-iter-borrow.rs index c03956c42cb30..b60d1799f7714 100644 --- a/src/test/compile-fail/vec-mut-iter-borrow.rs +++ b/src/test/compile-fail/vec-mut-iter-borrow.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut xs: Vec = vec!(); + let mut xs: Vec = vec!(); for x in xs.iter_mut() { xs.push(1i) //~ ERROR cannot borrow `xs` diff --git a/src/test/compile-fail/vec-res-add.rs b/src/test/compile-fail/vec-res-add.rs index dc166f9fd9d26..97a684b24593f 100644 --- a/src/test/compile-fail/vec-res-add.rs +++ b/src/test/compile-fail/vec-res-add.rs @@ -10,10 +10,10 @@ #[derive(Show)] struct r { - i:int + i:isize } -fn r(i:int) -> r { r { i: i } } +fn r(i:isize) -> r { r { i: i } } impl Drop for r { fn drop(&mut self) {} diff --git a/src/test/compile-fail/virtual-structs.rs b/src/test/compile-fail/virtual-structs.rs index 69125bab2ce7c..3b3c7d5a30f94 100644 --- a/src/test/compile-fail/virtual-structs.rs +++ b/src/test/compile-fail/virtual-structs.rs @@ -12,7 +12,7 @@ #![feature(struct_inherit)] virtual struct SuperStruct { //~ ERROR `virtual` structs have been removed from the language - f1: int, + f1: isize, } struct Struct : SuperStruct; //~ ERROR `virtual` structs have been removed from the language diff --git a/src/test/compile-fail/vtable-res-trait-param.rs b/src/test/compile-fail/vtable-res-trait-param.rs index 12cfe9c20fa9b..32a6c65b133d0 100644 --- a/src/test/compile-fail/vtable-res-trait-param.rs +++ b/src/test/compile-fail/vtable-res-trait-param.rs @@ -9,20 +9,20 @@ // except according to those terms. trait TraitA { - fn method_a(&self) -> int; + fn method_a(&self) -> isize; } trait TraitB { - fn gimme_an_a(&self, a: A) -> int; + fn gimme_an_a(&self, a: A) -> isize; } -impl TraitB for int { - fn gimme_an_a(&self, a: A) -> int { +impl TraitB for isize { + fn gimme_an_a(&self, a: A) -> isize { a.method_a() + *self } } -fn call_it(b: B) -> int { +fn call_it(b: B) -> isize { let y = 4u; b.gimme_an_a(y) //~ ERROR the trait `TraitA` is not implemented } diff --git a/src/test/compile-fail/walk-struct-literal-with.rs b/src/test/compile-fail/walk-struct-literal-with.rs index bb3b310a68f79..0f3754e09e41e 100644 --- a/src/test/compile-fail/walk-struct-literal-with.rs +++ b/src/test/compile-fail/walk-struct-literal-with.rs @@ -10,7 +10,7 @@ struct Mine{ test: String, - other_val: int + other_val: isize } impl Mine{ diff --git a/src/test/compile-fail/where-clause-method-substituion.rs b/src/test/compile-fail/where-clause-method-substituion.rs index 40d2df45488f5..a5108f005dc0e 100644 --- a/src/test/compile-fail/where-clause-method-substituion.rs +++ b/src/test/compile-fail/where-clause-method-substituion.rs @@ -19,7 +19,7 @@ struct X; // Remove this impl causing the below resolution to fail // impl Foo for X {} -impl Bar for int { +impl Bar for isize { fn method(&self) where X: Foo { } } diff --git a/src/test/compile-fail/where-clauses-not-parameter.rs b/src/test/compile-fail/where-clauses-not-parameter.rs index d8af859c081e9..65205cc72ee29 100644 --- a/src/test/compile-fail/where-clauses-not-parameter.rs +++ b/src/test/compile-fail/where-clauses-not-parameter.rs @@ -35,7 +35,7 @@ trait Baz where isize : Eq { //~^ ERROR cannot bound type `isize`, where clause } -impl Baz for int where isize : Eq { +impl Baz for isize where isize : Eq { //~^ ERROR cannot bound type `isize`, where clause bounds fn baz() where String : Eq {} } diff --git a/src/test/compile-fail/writing-to-immutable-vec.rs b/src/test/compile-fail/writing-to-immutable-vec.rs index 4e9f1545f3add..09c9439b464ec 100644 --- a/src/test/compile-fail/writing-to-immutable-vec.rs +++ b/src/test/compile-fail/writing-to-immutable-vec.rs @@ -10,6 +10,6 @@ fn main() { - let v: Vec = vec!(1, 2, 3); + let v: Vec = vec!(1, 2, 3); v[1] = 4; //~ ERROR cannot borrow immutable local variable `v` as mutable } diff --git a/src/test/compile-fail/wrong-ret-type.rs b/src/test/compile-fail/wrong-ret-type.rs index ba3f3df7990d7..d744ad804e7a9 100644 --- a/src/test/compile-fail/wrong-ret-type.rs +++ b/src/test/compile-fail/wrong-ret-type.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern: mismatched types -fn mk_int() -> uint { let i: int = 3; return i; } +fn mk_int() -> uint { let i: isize = 3; return i; } fn main() { } From 85f961e2ccf056965fd7a95c44ce0922a865ae8d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 22:02:42 +1100 Subject: [PATCH 14/25] Update compile fail tests to use usize. --- src/test/compile-fail/assign-to-method.rs | 4 ++-- .../compile-fail/associated-types-eq-2.rs | 4 ++-- .../compile-fail/associated-types-eq-3.rs | 4 ++-- .../associated-types-eq-expr-path.rs | 4 ++-- .../compile-fail/associated-types-eq-hr.rs | 6 ++--- .../associated-types-incomplete-object.rs | 8 +++---- .../compile-fail/associated-types-path-2.rs | 2 +- .../associated-types-unconstrained.rs | 2 +- src/test/compile-fail/bad-bang-ann-3.rs | 2 +- src/test/compile-fail/bad-bang-ann.rs | 2 +- .../compile-fail/bad-method-typaram-kind.rs | 2 +- .../borrow-immutable-upvar-mutation.rs | 2 +- .../borrowck-anon-fields-struct.rs | 2 +- .../borrowck-anon-fields-variant.rs | 2 +- .../compile-fail/borrowck-autoref-3261.rs | 4 ++-- .../borrowck-bad-nested-calls-free.rs | 4 ++-- .../borrowck-bad-nested-calls-move.rs | 4 ++-- .../borrowck-borrowed-uniq-rvalue.rs | 2 +- .../compile-fail/borrowck-lend-flow-loop.rs | 10 ++++----- .../borrowck-loan-in-overloaded-op.rs | 2 +- .../compile-fail/borrowck-overloaded-call.rs | 4 ++-- .../borrowck-overloaded-index-2.rs | 4 ++-- src/test/compile-fail/class-cast-to-trait.rs | 4 ++-- .../class-implements-bad-trait.rs | 4 ++-- src/test/compile-fail/class-method-missing.rs | 4 ++-- src/test/compile-fail/class-missing-self.rs | 2 +- ...nket-conflicts-with-blanket-implemented.rs | 8 +++---- ...et-conflicts-with-blanket-unimplemented.rs | 6 ++--- ...t-conflicts-with-specific-multidispatch.rs | 4 ++-- ...e-blanket-conflicts-with-specific-trait.rs | 8 +++---- ...herence-blanket-conflicts-with-specific.rs | 8 +++---- src/test/compile-fail/coherence-orphan.rs | 2 +- .../compile-fail/coherence-tuple-conflict.rs | 6 ++--- .../const-block-non-item-statement.rs | 8 +++---- src/test/compile-fail/deriving-non-type.rs | 6 ++--- src/test/compile-fail/deriving-primitive.rs | 2 +- src/test/compile-fail/dst-index.rs | 10 ++++----- .../compile-fail/enum-discrim-too-small.rs | 2 +- .../compile-fail/extern-with-type-bounds.rs | 4 ++-- .../compile-fail/feature-gate-int-uint.rs | 6 ++--- .../fully-qualified-type-name3.rs | 2 +- .../compile-fail/hrtb-debruijn-in-receiver.rs | 2 +- src/test/compile-fail/huge-array-simple.rs | 2 +- src/test/compile-fail/import-glob-circular.rs | 4 ++-- .../compile-fail/indexing-requires-a-uint.rs | 6 ++--- .../compile-fail/infinite-instantiation.rs | 6 ++--- src/test/compile-fail/issue-10200.rs | 2 +- src/test/compile-fail/issue-10636-1.rs | 2 +- src/test/compile-fail/issue-10877.rs | 4 ++-- src/test/compile-fail/issue-13359.rs | 2 +- src/test/compile-fail/issue-1362.rs | 2 +- src/test/compile-fail/issue-14303-fncall.rs | 2 +- src/test/compile-fail/issue-1448-2.rs | 2 +- src/test/compile-fail/issue-15260.rs | 2 +- src/test/compile-fail/issue-15783.rs | 2 +- src/test/compile-fail/issue-15896.rs | 2 +- src/test/compile-fail/issue-16538.rs | 4 ++-- src/test/compile-fail/issue-16562.rs | 6 ++--- src/test/compile-fail/issue-16747.rs | 4 ++-- src/test/compile-fail/issue-17252.rs | 6 ++--- src/test/compile-fail/issue-17283.rs | 2 +- src/test/compile-fail/issue-17458.rs | 2 +- .../issue-17718-borrow-interior.rs | 12 +++++----- .../issue-17718-const-bad-values.rs | 6 ++--- .../compile-fail/issue-17718-const-borrow.rs | 8 +++---- .../compile-fail/issue-17718-const-mut.rs | 2 +- .../compile-fail/issue-17718-const-privacy.rs | 2 +- .../issue-17718-constants-not-static.rs | 4 ++-- src/test/compile-fail/issue-17718-patterns.rs | 6 ++--- .../compile-fail/issue-17718-recursive.rs | 4 ++-- .../compile-fail/issue-17718-references.rs | 22 +++++++++---------- .../compile-fail/issue-17718-static-sync.rs | 2 +- src/test/compile-fail/issue-17933.rs | 2 +- src/test/compile-fail/issue-18252.rs | 2 +- src/test/compile-fail/issue-18294.rs | 2 +- src/test/compile-fail/issue-18566.rs | 12 +++++----- src/test/compile-fail/issue-19244-1.rs | 2 +- src/test/compile-fail/issue-19244-2.rs | 2 +- src/test/compile-fail/issue-2111.rs | 2 +- src/test/compile-fail/issue-2150.rs | 2 +- src/test/compile-fail/issue-2356.rs | 4 ++-- src/test/compile-fail/issue-3344.rs | 2 +- src/test/compile-fail/issue-3707.rs | 2 +- src/test/compile-fail/issue-4265.rs | 2 +- src/test/compile-fail/issue-4935.rs | 2 +- src/test/compile-fail/issue-5358-1.rs | 2 +- src/test/compile-fail/issue-5500-1.rs | 2 +- src/test/compile-fail/issue-6801.rs | 6 ++--- src/test/compile-fail/issue-6991.rs | 4 ++-- src/test/compile-fail/issue-7607-2.rs | 2 +- src/test/compile-fail/issue-9957.rs | 2 +- src/test/compile-fail/kindck-nonsendable-1.rs | 2 +- ...me-inference-give-expl-lifetime-param-2.rs | 8 +++---- src/test/compile-fail/lint-ctypes.rs | 4 ++-- src/test/compile-fail/lint-dead-code-4.rs | 6 ++--- .../compile-fail/lint-exceeding-bitshifts.rs | 2 +- src/test/compile-fail/lint-raw-ptr-derive.rs | 2 +- src/test/compile-fail/lint-stability.rs | 2 +- .../compile-fail/lint-unused-extern-crate.rs | 2 +- src/test/compile-fail/lint-unused-imports.rs | 2 +- .../compile-fail/lint-uppercase-variables.rs | 6 ++--- src/test/compile-fail/liveness-bad-bang-2.rs | 2 +- .../match-pattern-field-mismatch-2.rs | 4 ++-- .../match-pattern-field-mismatch.rs | 4 ++-- ...method-ambig-one-trait-unknown-int-type.rs | 4 ++-- .../method-ambig-two-traits-cross-crate.rs | 4 ++-- ...od-ambig-two-traits-with-default-method.rs | 4 ++-- src/test/compile-fail/move-fragments-9.rs | 8 +++---- ...type-move-out-of-closure-env-issue-1965.rs | 4 ++-- .../compile-fail/mutable-class-fields-2.rs | 4 ++-- src/test/compile-fail/mutable-class-fields.rs | 4 ++-- .../non-constant-enum-for-vec-repeat.rs | 2 +- .../non-constant-expr-for-vec-repeat.rs | 2 +- .../non-exhaustive-pattern-witness.rs | 2 +- src/test/compile-fail/or-patter-mismatch.rs | 2 +- .../compile-fail/packed-struct-transmute.rs | 4 ++-- .../pat-shadow-in-nested-binding.rs | 2 +- src/test/compile-fail/prim-with-args.rs | 4 ++-- src/test/compile-fail/private-method.rs | 4 ++-- src/test/compile-fail/private-struct-field.rs | 2 +- src/test/compile-fail/recursion_limit.rs | 2 +- .../region-bound-on-closure-outlives-call.rs | 2 +- src/test/compile-fail/regions-addr-of-self.rs | 6 ++--- .../regions-addr-of-upvar-self.rs | 6 ++--- .../compile-fail/regions-creating-enums.rs | 6 ++--- .../compile-fail/regions-creating-enums3.rs | 2 +- .../compile-fail/regions-creating-enums4.rs | 2 +- .../regions-free-region-ordering-callee.rs | 18 +++++++-------- .../regions-free-region-ordering-caller.rs | 12 +++++----- .../regions-free-region-ordering-caller1.rs | 8 +++---- .../compile-fail/regions-glb-free-free.rs | 4 ++-- src/test/compile-fail/regions-in-enums.rs | 8 +++---- src/test/compile-fail/regions-in-structs.rs | 4 ++-- src/test/compile-fail/regions-trait-1.rs | 4 ++-- src/test/compile-fail/regions-trait-2.rs | 2 +- src/test/compile-fail/regions-trait-3.rs | 6 ++--- .../compile-fail/std-uncopyable-atomics.rs | 2 +- .../compile-fail/struct-pat-derived-error.rs | 4 ++-- src/test/compile-fail/tail-typeck.rs | 2 +- src/test/compile-fail/terr-in-field.rs | 2 +- ...rait-bounds-on-structs-and-enums-locals.rs | 2 +- ...rait-bounds-on-structs-and-enums-static.rs | 2 +- .../trait-bounds-on-structs-and-enums-xc.rs | 2 +- .../trait-bounds-on-structs-and-enums.rs | 6 ++--- .../trait-impl-different-num-params.rs | 2 +- .../trait-impl-method-mismatch.rs | 6 ++--- src/test/compile-fail/trait-test-2.rs | 2 +- src/test/compile-fail/trait-test.rs | 2 +- .../compile-fail/traits-multidispatch-bad.rs | 6 ++--- .../typeck_type_placeholder_item.rs | 4 ++-- .../typeck_type_placeholder_lifetime_2.rs | 2 +- .../compile-fail/ufcs-explicit-self-bad.rs | 2 +- .../unboxed-closure-immutable-capture.rs | 2 +- .../unboxed-closure-sugar-equiv.rs | 22 +++++++++---------- .../unboxed-closure-sugar-lifetime-elision.rs | 2 +- .../unboxed-closure-sugar-used-on-struct-3.rs | 2 +- .../unboxed-closures-vtable-mismatch.rs | 2 +- src/test/compile-fail/unreachable-arm.rs | 2 +- src/test/compile-fail/unsized5.rs | 4 ++-- src/test/compile-fail/utf8_idents.rs | 2 +- src/test/compile-fail/variadic-ffi-2.rs | 2 +- src/test/compile-fail/wrong-ret-type.rs | 2 +- 162 files changed, 325 insertions(+), 325 deletions(-) diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index f810851949232..047e332566653 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -9,7 +9,7 @@ // except according to those terms. struct cat { - meows : uint, + meows : usize, how_hungry : isize, } @@ -18,7 +18,7 @@ impl cat { pub fn speak(&self) { self.meows += 1u; } } -fn cat(in_x : uint, in_y : isize) -> cat { +fn cat(in_x : usize, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/associated-types-eq-2.rs b/src/test/compile-fail/associated-types-eq-2.rs index 34c7a6eaa6c47..755a9f2d73f62 100644 --- a/src/test/compile-fail/associated-types-eq-2.rs +++ b/src/test/compile-fail/associated-types-eq-2.rs @@ -19,8 +19,8 @@ pub trait Foo { struct Bar; impl Foo for isize { - type A = uint; - fn boo(&self) -> uint { 42 } + type A = usize; + fn boo(&self) -> usize { 42 } } fn baz(x: &>::A) {} diff --git a/src/test/compile-fail/associated-types-eq-3.rs b/src/test/compile-fail/associated-types-eq-3.rs index f04698100fc88..037f503788844 100644 --- a/src/test/compile-fail/associated-types-eq-3.rs +++ b/src/test/compile-fail/associated-types-eq-3.rs @@ -19,8 +19,8 @@ pub trait Foo { struct Bar; impl Foo for isize { - type A = uint; - fn boo(&self) -> uint { + type A = usize; + fn boo(&self) -> usize { 42 } } diff --git a/src/test/compile-fail/associated-types-eq-expr-path.rs b/src/test/compile-fail/associated-types-eq-expr-path.rs index 90c4c97b5bdfd..9baa7f1ad5a69 100644 --- a/src/test/compile-fail/associated-types-eq-expr-path.rs +++ b/src/test/compile-fail/associated-types-eq-expr-path.rs @@ -16,11 +16,11 @@ trait Foo { } impl Foo for isize { - type A = uint; + type A = usize; fn bar() -> isize { 42 } } pub fn main() { - let x: isize = Foo::::bar(); + let x: isize = Foo::::bar(); //~^ERROR unexpected binding of associated item in expression path } diff --git a/src/test/compile-fail/associated-types-eq-hr.rs b/src/test/compile-fail/associated-types-eq-hr.rs index c180e2f61122f..d5678c155fd2d 100644 --- a/src/test/compile-fail/associated-types-eq-hr.rs +++ b/src/test/compile-fail/associated-types-eq-hr.rs @@ -33,9 +33,9 @@ struct UintStruct { } impl<'a> TheTrait<&'a isize> for UintStruct { - type A = &'a uint; + type A = &'a usize; - fn get(&self, t: &'a isize) -> &'a uint { + fn get(&self, t: &'a isize) -> &'a usize { panic!() } } @@ -47,7 +47,7 @@ fn foo() } fn bar() - where T : for<'x> TheTrait<&'x isize, A = &'x uint> + where T : for<'x> TheTrait<&'x isize, A = &'x usize> { // ok for UintStruct, but not IntStruct } diff --git a/src/test/compile-fail/associated-types-incomplete-object.rs b/src/test/compile-fail/associated-types-incomplete-object.rs index 898403f1d6144..30923f0912734 100644 --- a/src/test/compile-fail/associated-types-incomplete-object.rs +++ b/src/test/compile-fail/associated-types-incomplete-object.rs @@ -20,17 +20,17 @@ pub trait Foo { struct Bar; impl Foo for isize { - type A = uint; + type A = usize; type B = char; - fn boo(&self) -> uint { + fn boo(&self) -> usize { 42 } } pub fn main() { - let a = &42i as &Foo; + let a = &42i as &Foo; - let b = &42i as &Foo; + let b = &42i as &Foo; //~^ ERROR the value of the associated type `B` (from the trait `Foo`) must be specified let c = &42i as &Foo; diff --git a/src/test/compile-fail/associated-types-path-2.rs b/src/test/compile-fail/associated-types-path-2.rs index 4a9e077769788..74c8dffced5cf 100644 --- a/src/test/compile-fail/associated-types-path-2.rs +++ b/src/test/compile-fail/associated-types-path-2.rs @@ -15,7 +15,7 @@ pub trait Foo { } impl Foo for isize { - type A = uint; + type A = usize; } pub fn f1(a: T, x: T::A) {} diff --git a/src/test/compile-fail/associated-types-unconstrained.rs b/src/test/compile-fail/associated-types-unconstrained.rs index 8b80ab92e0797..aecbf217a5b25 100644 --- a/src/test/compile-fail/associated-types-unconstrained.rs +++ b/src/test/compile-fail/associated-types-unconstrained.rs @@ -16,7 +16,7 @@ trait Foo { } impl Foo for isize { - type A = uint; + type A = usize; fn bar() -> isize { 42 } } diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs index d204c8c750aae..e364d0283c4b1 100644 --- a/src/test/compile-fail/bad-bang-ann-3.rs +++ b/src/test/compile-fail/bad-bang-ann-3.rs @@ -10,7 +10,7 @@ // Tests that a function with a ! annotation always actually fails -fn bad_bang(i: uint) -> ! { +fn bad_bang(i: usize) -> ! { return 7u; //~ ERROR `return` in a function declared as diverging [E0166] } diff --git a/src/test/compile-fail/bad-bang-ann.rs b/src/test/compile-fail/bad-bang-ann.rs index 7e8142dbb2908..817b107d8140c 100644 --- a/src/test/compile-fail/bad-bang-ann.rs +++ b/src/test/compile-fail/bad-bang-ann.rs @@ -10,7 +10,7 @@ // Tests that a function with a ! annotation always actually fails -fn bad_bang(i: uint) -> ! { //~ ERROR computation may converge in a function marked as diverging +fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging if i < 0u { } else { panic!(); } } diff --git a/src/test/compile-fail/bad-method-typaram-kind.rs b/src/test/compile-fail/bad-method-typaram-kind.rs index 349c33a30a531..636c881a3e162 100644 --- a/src/test/compile-fail/bad-method-typaram-kind.rs +++ b/src/test/compile-fail/bad-method-typaram-kind.rs @@ -16,7 +16,7 @@ trait bar { fn bar(&self); } -impl bar for uint { +impl bar for usize { fn bar(&self) { } } diff --git a/src/test/compile-fail/borrow-immutable-upvar-mutation.rs b/src/test/compile-fail/borrow-immutable-upvar-mutation.rs index f748c40065447..228b07555f29c 100644 --- a/src/test/compile-fail/borrow-immutable-upvar-mutation.rs +++ b/src/test/compile-fail/borrow-immutable-upvar-mutation.rs @@ -13,7 +13,7 @@ // Tests that we can't assign to or mutably borrow upvars from `Fn` // closures (issue #17780) -fn set(x: &mut uint) { *x = 5; } +fn set(x: &mut usize) { *x = 5; } fn main() { // By-ref captures diff --git a/src/test/compile-fail/borrowck-anon-fields-struct.rs b/src/test/compile-fail/borrowck-anon-fields-struct.rs index 514dd584c6a02..5ee2b89dd9839 100644 --- a/src/test/compile-fail/borrowck-anon-fields-struct.rs +++ b/src/test/compile-fail/borrowck-anon-fields-struct.rs @@ -11,7 +11,7 @@ // Tests that we are able to distinguish when loans borrow different // anonymous fields of a tuple vs the same anonymous field. -struct Y(uint, uint); +struct Y(usize, usize); fn distinct_variant() { let mut y = Y(1, 2); diff --git a/src/test/compile-fail/borrowck-anon-fields-variant.rs b/src/test/compile-fail/borrowck-anon-fields-variant.rs index 8b54f146d0412..4e1b85283a6b1 100644 --- a/src/test/compile-fail/borrowck-anon-fields-variant.rs +++ b/src/test/compile-fail/borrowck-anon-fields-variant.rs @@ -12,7 +12,7 @@ // anonymous fields of an enum variant vs the same anonymous field. enum Foo { - X, Y(uint, uint) + X, Y(usize, usize) } fn distinct_variant() { diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 2804b8c48a703..d5f09305808f0 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -10,10 +10,10 @@ enum Either { Left(T), Right(U) } -struct X(Either<(uint,uint), fn()>); +struct X(Either<(usize,usize), fn()>); impl X { - pub fn with(&self, blk: F) where F: FnOnce(&Either<(uint, uint), fn()>) { + pub fn with(&self, blk: F) where F: FnOnce(&Either<(usize, usize), fn()>) { let X(ref e) = *self; blk(e) } diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs index 5a7788ed855ac..4d1939be5b9f7 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs @@ -13,12 +13,12 @@ #![feature(box_syntax)] -fn rewrite(v: &mut Box) -> uint { +fn rewrite(v: &mut Box) -> usize { *v = box 22; **v } -fn add(v: &uint, w: uint) -> uint { +fn add(v: &usize, w: usize) -> usize { *v + w } diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs index 263b7f9576b9f..9eda3689334c1 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs @@ -13,12 +13,12 @@ #![feature(box_syntax)] -fn rewrite(v: &mut Box) -> uint { +fn rewrite(v: &mut Box) -> usize { *v = box 22; **v } -fn add(v: &uint, w: Box) -> uint { +fn add(v: &usize, w: Box) -> usize { *v + *w } diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs index 04ad583a2db42..98d1905ed9068 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs @@ -16,7 +16,7 @@ extern crate collections; use std::collections::HashMap; fn main() { - let mut buggy_map: HashMap = HashMap::new(); + let mut buggy_map: HashMap = HashMap::new(); buggy_map.insert(42, &*box 1); //~ ERROR borrowed value does not live long enough // but it is ok if we use a temporary diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 83fddcf696496..00dba3856a283 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -113,8 +113,8 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) { } } -fn loop_break_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where - F: FnMut(&'r mut uint) -> bool, +fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where + F: FnMut(&'r mut usize) -> bool, { // Here we check that when you break out of an inner loop, the // borrows that go out of scope as you exit the inner loop are @@ -123,7 +123,7 @@ fn loop_break_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where while cond() { while cond() { // this borrow is limited to the scope of `r`... - let r: &'r mut uint = produce(); + let r: &'r mut usize = produce(); if !f(&mut *r) { break; // ...so it is not live as exit the `while` loop here } @@ -131,13 +131,13 @@ fn loop_break_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where } } -fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [uint], mut f: F) where F: FnMut(&'r mut uint) -> bool { +fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where F: FnMut(&'r mut usize) -> bool { // Similar to `loop_break_pops_scopes` but for the `loop` keyword while cond() { while cond() { // this borrow is limited to the scope of `r`... - let r: &'r mut uint = produce(); + let r: &'r mut usize = produce(); if !f(&mut *r) { continue; // ...so it is not live as exit (and re-enter) the `while` loop here } diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs index d955e8984bf39..902762f687ed9 100644 --- a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs @@ -13,7 +13,7 @@ use std::ops::Add; #[derive(Clone)] -struct foo(Box); +struct foo(Box); impl Add for foo { type Output = foo; diff --git a/src/test/compile-fail/borrowck-overloaded-call.rs b/src/test/compile-fail/borrowck-overloaded-call.rs index de959521514b2..7d35a27c0ae20 100644 --- a/src/test/compile-fail/borrowck-overloaded-call.rs +++ b/src/test/compile-fail/borrowck-overloaded-call.rs @@ -38,8 +38,8 @@ struct SFnOnce { x: String, } -impl FnOnce<(String,),uint> for SFnOnce { - extern "rust-call" fn call_once(self, (z,): (String,)) -> uint { +impl FnOnce<(String,),usize> for SFnOnce { + extern "rust-call" fn call_once(self, (z,): (String,)) -> usize { self.x.len() + z.len() } } diff --git a/src/test/compile-fail/borrowck-overloaded-index-2.rs b/src/test/compile-fail/borrowck-overloaded-index-2.rs index 5e6d235574e69..bfdd46345de00 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-2.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-2.rs @@ -16,10 +16,10 @@ struct MyVec { data: Vec, } -impl Index for MyVec { +impl Index for MyVec { type Output = T; - fn index(&self, &i: &uint) -> &T { + fn index(&self, &i: &usize) -> &T { &self.data[i] } } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index c64112d5dfd8d..31e09e877c708 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -15,7 +15,7 @@ trait noisy { } struct cat { - meows : uint, + meows : usize, how_hungry : isize, name : String, @@ -50,7 +50,7 @@ impl cat { } } -fn cat(in_x : uint, in_y : isize, in_name: String) -> cat { +fn cat(in_x : usize, in_y : isize, in_name: String) -> cat { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/compile-fail/class-implements-bad-trait.rs b/src/test/compile-fail/class-implements-bad-trait.rs index 9e7366a643d27..8d57380630837 100644 --- a/src/test/compile-fail/class-implements-bad-trait.rs +++ b/src/test/compile-fail/class-implements-bad-trait.rs @@ -10,8 +10,8 @@ // error-pattern:nonexistent class cat : nonexistent { - let meows: uint; - new(in_x : uint) { self.meows = in_x; } + let meows: usize; + new(in_x : usize) { self.meows = in_x; } } fn main() { diff --git a/src/test/compile-fail/class-method-missing.rs b/src/test/compile-fail/class-method-missing.rs index 17cf36b73f643..56b3caf6d2133 100644 --- a/src/test/compile-fail/class-method-missing.rs +++ b/src/test/compile-fail/class-method-missing.rs @@ -13,14 +13,14 @@ trait animal { } struct cat { - meows: uint, + meows: usize, } impl animal for cat { //~^ ERROR not all trait items implemented, missing: `eat` } -fn cat(in_x : uint) -> cat { +fn cat(in_x : usize) -> cat { cat { meows: in_x } diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs index 0e75e702277a3..af172cd492459 100644 --- a/src/test/compile-fail/class-missing-self.rs +++ b/src/test/compile-fail/class-missing-self.rs @@ -9,7 +9,7 @@ // except according to those terms. struct cat { - meows : uint, + meows : usize, } impl cat { diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs index 1372d9930ee35..27d97d18c949f 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-implemented.rs @@ -16,7 +16,7 @@ use std::default::Default; // for the same type (though this crate doesn't). trait MyTrait { - fn get(&self) -> uint; + fn get(&self) -> usize; } trait Even { } @@ -25,14 +25,14 @@ trait Odd { } impl Even for isize { } -impl Odd for uint { } +impl Odd for usize { } impl MyTrait for T { //~ ERROR E0119 - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } impl MyTrait for T { - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } fn main() { } diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-unimplemented.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-unimplemented.rs index c44844bcf0b6c..0f233b78c7216 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-unimplemented.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-blanket-unimplemented.rs @@ -16,7 +16,7 @@ use std::default::Default; // for the same type (though this crate doesn't implement them at all). trait MyTrait { - fn get(&self) -> uint; + fn get(&self) -> usize; } trait Even { } @@ -24,11 +24,11 @@ trait Even { } trait Odd { } impl MyTrait for T { //~ ERROR E0119 - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } impl MyTrait for T { - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } fn main() { } diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-multidispatch.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-multidispatch.rs index f3efca369b310..c3563792ce3c7 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-multidispatch.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-multidispatch.rs @@ -26,11 +26,11 @@ impl MyTrait for T { //~ ERROR E0119 #[derive(Clone)] struct MyType { - dummy: uint + dummy: usize } impl MyTrait for MyType { - fn get(&self) -> uint { (*self).clone() } + fn get(&self) -> usize { (*self).clone() } } fn main() { } diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-trait.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-trait.rs index 9db322a5517fb..eeaa68677eb67 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-specific-trait.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-specific-trait.rs @@ -16,19 +16,19 @@ trait OtherTrait { } trait MyTrait { - fn get(&self) -> uint; + fn get(&self) -> usize; } impl MyTrait for T { //~ ERROR E0119 - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } struct MyType { - dummy: uint + dummy: usize } impl MyTrait for MyType { - fn get(&self) -> uint { self.dummy } + fn get(&self) -> usize { self.dummy } } impl OtherTrait for MyType { diff --git a/src/test/compile-fail/coherence-blanket-conflicts-with-specific.rs b/src/test/compile-fail/coherence-blanket-conflicts-with-specific.rs index 936025385bb5e..980e4256d2b85 100644 --- a/src/test/compile-fail/coherence-blanket-conflicts-with-specific.rs +++ b/src/test/compile-fail/coherence-blanket-conflicts-with-specific.rs @@ -15,19 +15,19 @@ use std::default::Default; // specific T. trait MyTrait { - fn get(&self) -> uint; + fn get(&self) -> usize; } impl MyTrait for T { //~ ERROR E0119 - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } struct MyType { - dummy: uint + dummy: usize } impl MyTrait for MyType { - fn get(&self) -> uint { self.dummy } + fn get(&self) -> usize { self.dummy } } fn main() { } diff --git a/src/test/compile-fail/coherence-orphan.rs b/src/test/compile-fail/coherence-orphan.rs index 568a35cc58963..0bd0224b246d1 100644 --- a/src/test/compile-fail/coherence-orphan.rs +++ b/src/test/compile-fail/coherence-orphan.rs @@ -16,7 +16,7 @@ use lib::TheTrait; struct TheType; -impl TheTrait for isize { } //~ ERROR E0117 +impl TheTrait for isize { } //~ ERROR E0117 impl TheTrait for isize { } //~ ERROR E0117 diff --git a/src/test/compile-fail/coherence-tuple-conflict.rs b/src/test/compile-fail/coherence-tuple-conflict.rs index 92fa725cb1e16..9673fb6a21392 100644 --- a/src/test/compile-fail/coherence-tuple-conflict.rs +++ b/src/test/compile-fail/coherence-tuple-conflict.rs @@ -15,15 +15,15 @@ use std::default::Default; // specific T. trait MyTrait { - fn get(&self) -> uint; + fn get(&self) -> usize; } impl MyTrait for (T,T) { //~ ERROR E0119 - fn get(&self) -> uint { 0 } + fn get(&self) -> usize { 0 } } impl MyTrait for (A,B) { - fn get(&self) -> uint { self.dummy } + fn get(&self) -> usize { self.dummy } } fn main() { } diff --git a/src/test/compile-fail/const-block-non-item-statement.rs b/src/test/compile-fail/const-block-non-item-statement.rs index 1814b1cd544ef..053efe3b41b54 100644 --- a/src/test/compile-fail/const-block-non-item-statement.rs +++ b/src/test/compile-fail/const-block-non-item-statement.rs @@ -8,18 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static A: uint = { 1u; 2 }; +static A: usize = { 1u; 2 }; //~^ ERROR: blocks in constants are limited to items and tail expressions -static B: uint = { { } 2 }; +static B: usize = { { } 2 }; //~^ ERROR: blocks in constants are limited to items and tail expressions macro_rules! foo { () => (()) //~ ERROR: blocks in constants are limited to items and tail expressions } -static C: uint = { foo!(); 2 }; +static C: usize = { foo!(); 2 }; -static D: uint = { let x = 4u; 2 }; +static D: usize = { let x = 4u; 2 }; //~^ ERROR: blocks in constants are limited to items and tail expressions pub fn main() { diff --git a/src/test/compile-fail/deriving-non-type.rs b/src/test/compile-fail/deriving-non-type.rs index 717ce6e11efba..324f189bbfb92 100644 --- a/src/test/compile-fail/deriving-non-type.rs +++ b/src/test/compile-fail/deriving-non-type.rs @@ -22,10 +22,10 @@ impl S { } impl T for S { } #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums -static s: uint = 0u; +static s: usize = 0u; #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums -const c: uint = 0u; +const c: usize = 0u; #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums mod m { } @@ -34,7 +34,7 @@ mod m { } extern "C" { } #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums -type A = uint; +type A = usize; #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums fn main() { } diff --git a/src/test/compile-fail/deriving-primitive.rs b/src/test/compile-fail/deriving-primitive.rs index 901f0c58f458d..6e9b120aa69b5 100644 --- a/src/test/compile-fail/deriving-primitive.rs +++ b/src/test/compile-fail/deriving-primitive.rs @@ -22,7 +22,7 @@ struct B(isize); //~^^^ ERROR `FromPrimitive` cannot be derived for structs #[derive(FromPrimitive)] -enum C { Foo(isize), Bar(uint) } +enum C { Foo(isize), Bar(usize) } //~^^ ERROR `FromPrimitive` cannot be derived for enum variants with arguments //~^^^ ERROR `FromPrimitive` cannot be derived for enum variants with arguments diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index e297ecaac233e..f64093200c4f9 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -18,10 +18,10 @@ struct S; impl Copy for S {} -impl Index for S { +impl Index for S { type Output = str; - fn index<'a>(&'a self, _: &uint) -> &'a str { + fn index<'a>(&'a self, _: &usize) -> &'a str { "hello" } } @@ -30,11 +30,11 @@ struct T; impl Copy for T {} -impl Index for T { +impl Index for T { type Output = Show + 'static; - fn index<'a>(&'a self, idx: &uint) -> &'a (Show + 'static) { - static x: uint = 42; + fn index<'a>(&'a self, idx: &usize) -> &'a (Show + 'static) { + static x: usize = 42; &x } } diff --git a/src/test/compile-fail/enum-discrim-too-small.rs b/src/test/compile-fail/enum-discrim-too-small.rs index 55e9b6d6ece9c..1d7794336a096 100644 --- a/src/test/compile-fail/enum-discrim-too-small.rs +++ b/src/test/compile-fail/enum-discrim-too-small.rs @@ -53,6 +53,6 @@ enum Ei32 { // u64 currently allows negative numbers, and i64 allows numbers greater than `1<<63`. This is a // little counterintuitive, but since the discriminant can store all the bits, and extracting it // with a cast requires specifying the signedness, there is no loss of information in those cases. -// This also applies to isize and uint on 64-bit targets. +// This also applies to isize and usize on 64-bit targets. pub fn main() { } diff --git a/src/test/compile-fail/extern-with-type-bounds.rs b/src/test/compile-fail/extern-with-type-bounds.rs index 8c7d00a9a11d4..d2c88865d54f2 100644 --- a/src/test/compile-fail/extern-with-type-bounds.rs +++ b/src/test/compile-fail/extern-with-type-bounds.rs @@ -22,10 +22,10 @@ extern "rust-intrinsic" { // Bounds aren't checked right now, so this should work // even though it's incorrect. - fn size_of() -> uint; + fn size_of() -> usize; // Unresolved bounds should still error. - fn align_of() -> uint; + fn align_of() -> usize; //~^ ERROR attempt to bound type parameter with a nonexistent trait `NoSuchTrait` } diff --git a/src/test/compile-fail/feature-gate-int-uint.rs b/src/test/compile-fail/feature-gate-int-uint.rs index 668c9980a2edd..0c730b5f593f7 100644 --- a/src/test/compile-fail/feature-gate-int-uint.rs +++ b/src/test/compile-fail/feature-gate-int-uint.rs @@ -11,11 +11,11 @@ #![allow(dead_code)] mod u { - type X = uint; //~ WARN the `uint` type is deprecated + type X = usize; //~ WARN the `usize` type is deprecated struct Foo { - x: uint //~ WARN the `uint` type is deprecated + x: usize //~ WARN the `usize` type is deprecated } - fn bar(x: uint) { //~ WARN the `uint` type is deprecated + fn bar(x: usize) { //~ WARN the `usize` type is deprecated 1u; //~ WARN the `u` suffix on integers is deprecated } } diff --git a/src/test/compile-fail/fully-qualified-type-name3.rs b/src/test/compile-fail/fully-qualified-type-name3.rs index c69c30216f9e1..dc0c9a093fff8 100644 --- a/src/test/compile-fail/fully-qualified-type-name3.rs +++ b/src/test/compile-fail/fully-qualified-type-name3.rs @@ -12,7 +12,7 @@ // ignore-test -type T1 = uint; +type T1 = usize; type T2 = isize; fn bar(x: T1) -> T2 { diff --git a/src/test/compile-fail/hrtb-debruijn-in-receiver.rs b/src/test/compile-fail/hrtb-debruijn-in-receiver.rs index 2dbd16107b0d5..2365f494075d2 100644 --- a/src/test/compile-fail/hrtb-debruijn-in-receiver.rs +++ b/src/test/compile-fail/hrtb-debruijn-in-receiver.rs @@ -14,7 +14,7 @@ use std::collections::HashMap; struct Foo<'a> { - map: HashMap + map: HashMap } impl<'a> Foo<'a> { diff --git a/src/test/compile-fail/huge-array-simple.rs b/src/test/compile-fail/huge-array-simple.rs index a9dda771b7ff8..1e04e685e41b8 100644 --- a/src/test/compile-fail/huge-array-simple.rs +++ b/src/test/compile-fail/huge-array-simple.rs @@ -11,5 +11,5 @@ // error-pattern: too big for the current fn main() { - let fat : [u8; (1<<61)+(1<<31)] = [0; (1u64<<61) as uint +(1u64<<31) as uint]; + let fat : [u8; (1<<61)+(1<<31)] = [0; (1u64<<61) as usize +(1u64<<31) as usize]; } diff --git a/src/test/compile-fail/import-glob-circular.rs b/src/test/compile-fail/import-glob-circular.rs index fda7b190d72b4..37c2d2ffdc57f 100644 --- a/src/test/compile-fail/import-glob-circular.rs +++ b/src/test/compile-fail/import-glob-circular.rs @@ -13,13 +13,13 @@ mod circ1 { pub use circ2::f2; pub fn f1() { println!("f1"); } - pub fn common() -> uint { return 0u; } + pub fn common() -> usize { return 0u; } } mod circ2 { pub use circ1::f1; pub fn f2() { println!("f2"); } - pub fn common() -> uint { return 1u; } + pub fn common() -> usize { return 1u; } } mod test { diff --git a/src/test/compile-fail/indexing-requires-a-uint.rs b/src/test/compile-fail/indexing-requires-a-uint.rs index e40457a86c96f..901d8783d0278 100644 --- a/src/test/compile-fail/indexing-requires-a-uint.rs +++ b/src/test/compile-fail/indexing-requires-a-uint.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Make sure that indexing an array is only valid with a `uint`, not any other +// Make sure that indexing an array is only valid with a `usize`, not any other // integral type. fn main() { @@ -16,10 +16,10 @@ fn main() { [0][0u8]; //~ ERROR: the trait `core::ops::Index` is not implemented //~^ ERROR: the trait `core::ops::Index` is not implemented - [0][0]; // should infer to be a uint + [0][0]; // should infer to be a usize let i = 0; // i is an IntVar - [0][i]; // i should be locked to uint + [0][i]; // i should be locked to usize bar::(i); // i should not be re-coerced back to an isize //~^ ERROR: mismatched types } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index b8fa6285d9955..514557a96a4b3 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -15,8 +15,8 @@ trait to_opt { fn to_option(&self) -> Option; } -impl to_opt for uint { - fn to_option(&self) -> Option { +impl to_opt for usize { + fn to_option(&self) -> Option { Some(*self) } } @@ -27,7 +27,7 @@ impl to_opt for Option { } } -fn function(counter: uint, t: T) { +fn function(counter: usize, t: T) { if counter > 0u { function(counter - 1u, t.to_option()); } diff --git a/src/test/compile-fail/issue-10200.rs b/src/test/compile-fail/issue-10200.rs index 2b9ac705f3215..03d4e9b81eb29 100644 --- a/src/test/compile-fail/issue-10200.rs +++ b/src/test/compile-fail/issue-10200.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo(bool); -fn foo(_: uint) -> Foo { Foo(false) } +fn foo(_: usize) -> Foo { Foo(false) } fn main() { match Foo(true) { diff --git a/src/test/compile-fail/issue-10636-1.rs b/src/test/compile-fail/issue-10636-1.rs index 710c5a306f377..bb020d55bdb0b 100644 --- a/src/test/compile-fail/issue-10636-1.rs +++ b/src/test/compile-fail/issue-10636-1.rs @@ -9,5 +9,5 @@ // except according to those terms. struct Obj { //~ NOTE: unclosed delimiter - member: uint + member: usize ) //~ ERROR: incorrect close delimiter diff --git a/src/test/compile-fail/issue-10877.rs b/src/test/compile-fail/issue-10877.rs index 132298eba99e4..39f25b837cd49 100644 --- a/src/test/compile-fail/issue-10877.rs +++ b/src/test/compile-fail/issue-10877.rs @@ -18,7 +18,7 @@ extern { //~^ ERROR: patterns aren't allowed in foreign function declarations fn qux((x,y): ()); //~^ ERROR: patterns aren't allowed in foreign function declarations - fn this_is_actually_ok(a: uint); - fn and_so_is_this(_: uint); + fn this_is_actually_ok(a: usize); + fn and_so_is_this(_: usize); } fn main() {} diff --git a/src/test/compile-fail/issue-13359.rs b/src/test/compile-fail/issue-13359.rs index 607874de49d70..2e33886037708 100644 --- a/src/test/compile-fail/issue-13359.rs +++ b/src/test/compile-fail/issue-13359.rs @@ -16,6 +16,6 @@ fn main() { foo(1*(1 as isize)); //~^ ERROR: mismatched types: expected `i16`, found `isize` (expected i16, found isize) - bar(1*(1 as uint)); + bar(1*(1 as usize)); //~^ ERROR: mismatched types: expected `u32`, found `usize` (expected u32, found usize) } diff --git a/src/test/compile-fail/issue-1362.rs b/src/test/compile-fail/issue-1362.rs index bfbbc9d8aed6c..64c503376d561 100644 --- a/src/test/compile-fail/issue-1362.rs +++ b/src/test/compile-fail/issue-1362.rs @@ -11,7 +11,7 @@ // Regression test for issue #1362 - without that fix the span will be bogus // no-reformat fn main() { - let x: uint = 20i; //~ ERROR mismatched types + let x: usize = 20i; //~ ERROR mismatched types } // NOTE: Do not add any extra lines as the line number the error is // on is significant; an error later in the source file might not diff --git a/src/test/compile-fail/issue-14303-fncall.rs b/src/test/compile-fail/issue-14303-fncall.rs index 3a5c8bbc5461f..0ec64ba6a3f9b 100644 --- a/src/test/compile-fail/issue-14303-fncall.rs +++ b/src/test/compile-fail/issue-14303-fncall.rs @@ -11,6 +11,6 @@ fn main() { range(0, 4) .map(|x| x * 2) - .collect::>() + .collect::>() //~^ ERROR lifetime parameters must be declared prior to type parameters } diff --git a/src/test/compile-fail/issue-1448-2.rs b/src/test/compile-fail/issue-1448-2.rs index 234fa85c89afd..72803ea9ad188 100644 --- a/src/test/compile-fail/issue-1448-2.rs +++ b/src/test/compile-fail/issue-1448-2.rs @@ -10,7 +10,7 @@ // Regression test for issue #1448 and #1386 -fn foo(a: uint) -> uint { a } +fn foo(a: usize) -> usize { a } fn main() { println!("{}", foo(10i)); //~ ERROR mismatched types diff --git a/src/test/compile-fail/issue-15260.rs b/src/test/compile-fail/issue-15260.rs index e3d19729710af..2228b6d37799d 100644 --- a/src/test/compile-fail/issue-15260.rs +++ b/src/test/compile-fail/issue-15260.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - a: uint, + a: usize, } fn main() { diff --git a/src/test/compile-fail/issue-15783.rs b/src/test/compile-fail/issue-15783.rs index f3e7a65db481e..1b1b03023839d 100644 --- a/src/test/compile-fail/issue-15783.rs +++ b/src/test/compile-fail/issue-15783.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn foo(params: Option<&[&str]>) -> uint { +pub fn foo(params: Option<&[&str]>) -> usize { params.unwrap().first().unwrap().len() } diff --git a/src/test/compile-fail/issue-15896.rs b/src/test/compile-fail/issue-15896.rs index 7b91063e2f98d..c4373ba335157 100644 --- a/src/test/compile-fail/issue-15896.rs +++ b/src/test/compile-fail/issue-15896.rs @@ -12,7 +12,7 @@ fn main() { enum R { REB(()) } - struct Tau { t: uint } + struct Tau { t: usize } enum E { B(R, Tau) } let e = E::B(R::REB(()), Tau { t: 3 }); diff --git a/src/test/compile-fail/issue-16538.rs b/src/test/compile-fail/issue-16538.rs index af686b8681316..a6b73dcc19cea 100644 --- a/src/test/compile-fail/issue-16538.rs +++ b/src/test/compile-fail/issue-16538.rs @@ -9,9 +9,9 @@ // except according to those terms. mod Y { - type X = uint; + type X = usize; extern { - static x: *const uint; + static x: *const usize; } fn foo(value: *const X) -> *const X { value diff --git a/src/test/compile-fail/issue-16562.rs b/src/test/compile-fail/issue-16562.rs index 626a442a2c355..a400263a24327 100644 --- a/src/test/compile-fail/issue-16562.rs +++ b/src/test/compile-fail/issue-16562.rs @@ -15,11 +15,11 @@ struct Col { col: C, } -trait Collection { fn len(&self) -> uint; } +trait Collection { fn len(&self) -> usize; } -impl Collection for Col { +impl Collection for Col { //~^ ERROR type parameter `T` is not constrained - fn len(&self) -> uint { + fn len(&self) -> usize { unimplemented!() } } diff --git a/src/test/compile-fail/issue-16747.rs b/src/test/compile-fail/issue-16747.rs index 22e3e9ed09e7d..814b885e3aafc 100644 --- a/src/test/compile-fail/issue-16747.rs +++ b/src/test/compile-fail/issue-16747.rs @@ -12,7 +12,7 @@ trait ListItem<'a> { fn list_name() -> &'a str; } -trait Collection { fn len(&self) -> uint; } +trait Collection { fn len(&self) -> usize; } struct List<'a, T: ListItem<'a>> { //~^ ERROR the parameter type `T` may not live long enough @@ -22,7 +22,7 @@ struct List<'a, T: ListItem<'a>> { } impl<'a, T: ListItem<'a>> Collection for List<'a, T> { - fn len(&self) -> uint { + fn len(&self) -> usize { 0 } } diff --git a/src/test/compile-fail/issue-17252.rs b/src/test/compile-fail/issue-17252.rs index 4adb3f041a3f4..2e9ef8d607784 100644 --- a/src/test/compile-fail/issue-17252.rs +++ b/src/test/compile-fail/issue-17252.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static FOO: uint = FOO; //~ ERROR recursive constant +static FOO: usize = FOO; //~ ERROR recursive constant fn main() { let _x: [u8; FOO]; // caused stack overflow prior to fix - let _y: uint = 1 + { - static BAR: uint = BAR; //~ ERROR recursive constant + let _y: usize = 1 + { + static BAR: usize = BAR; //~ ERROR recursive constant let _z: [u8; BAR]; // caused stack overflow prior to fix 1 }; diff --git a/src/test/compile-fail/issue-17283.rs b/src/test/compile-fail/issue-17283.rs index 122c1f083951f..9f76feeaf0465 100644 --- a/src/test/compile-fail/issue-17283.rs +++ b/src/test/compile-fail/issue-17283.rs @@ -12,7 +12,7 @@ // within assignments in if expressions. struct Foo { - foo: uint + foo: usize } fn main() { diff --git a/src/test/compile-fail/issue-17458.rs b/src/test/compile-fail/issue-17458.rs index b1fbe6f5549e4..d9fd67f9197dd 100644 --- a/src/test/compile-fail/issue-17458.rs +++ b/src/test/compile-fail/issue-17458.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static X: uint = 0 as *const uint as uint; +static X: usize = 0 as *const usize as usize; //~^ ERROR: can not cast a pointer to an integer in a constant expression fn main() { diff --git a/src/test/compile-fail/issue-17718-borrow-interior.rs b/src/test/compile-fail/issue-17718-borrow-interior.rs index 8aa5fdf1c4d21..d33c12668f288 100644 --- a/src/test/compile-fail/issue-17718-borrow-interior.rs +++ b/src/test/compile-fail/issue-17718-borrow-interior.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S { a: uint } +struct S { a: usize } static A: S = S { a: 3 }; -static B: &'static uint = &A.a; +static B: &'static usize = &A.a; //~^ ERROR: cannot refer to the interior of another static -static C: &'static uint = &(A.a); +static C: &'static usize = &(A.a); //~^ ERROR: cannot refer to the interior of another static -static D: [uint; 1] = [1]; -static E: uint = D[0]; +static D: [usize; 1] = [1]; +static E: usize = D[0]; //~^ ERROR: cannot refer to other statics by value -static F: &'static uint = &D[0]; +static F: &'static usize = &D[0]; //~^ ERROR: cannot refer to the interior of another static fn main() {} diff --git a/src/test/compile-fail/issue-17718-const-bad-values.rs b/src/test/compile-fail/issue-17718-const-bad-values.rs index 6425dbda5c6c9..daa250d12f52e 100644 --- a/src/test/compile-fail/issue-17718-const-bad-values.rs +++ b/src/test/compile-fail/issue-17718-const-bad-values.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const C1: &'static mut [uint] = &mut []; +const C1: &'static mut [usize] = &mut []; //~^ ERROR: constants are not allowed to have mutable references -static mut S: uint = 3; -const C2: &'static mut uint = &mut S; +static mut S: usize = 3; +const C2: &'static mut usize = &mut S; //~^ ERROR: constants cannot refer to other statics //~^^ ERROR: are not allowed to have mutable references diff --git a/src/test/compile-fail/issue-17718-const-borrow.rs b/src/test/compile-fail/issue-17718-const-borrow.rs index 21cc9a757cf19..dfa5bca8ccdb6 100644 --- a/src/test/compile-fail/issue-17718-const-borrow.rs +++ b/src/test/compile-fail/issue-17718-const-borrow.rs @@ -10,13 +10,13 @@ use std::cell::UnsafeCell; -const A: UnsafeCell = UnsafeCell { value: 1 }; -const B: &'static UnsafeCell = &A; +const A: UnsafeCell = UnsafeCell { value: 1 }; +const B: &'static UnsafeCell = &A; //~^ ERROR: cannot borrow a constant which contains interior mutability -struct C { a: UnsafeCell } +struct C { a: UnsafeCell } const D: C = C { a: UnsafeCell { value: 1 } }; -const E: &'static UnsafeCell = &D.a; +const E: &'static UnsafeCell = &D.a; //~^ ERROR: cannot borrow a constant which contains interior mutability const F: &'static C = &D; //~^ ERROR: cannot borrow a constant which contains interior mutability diff --git a/src/test/compile-fail/issue-17718-const-mut.rs b/src/test/compile-fail/issue-17718-const-mut.rs index 12b9cf4ba8c0c..5177ebbc1882f 100644 --- a/src/test/compile-fail/issue-17718-const-mut.rs +++ b/src/test/compile-fail/issue-17718-const-mut.rs @@ -11,7 +11,7 @@ const mut //~ ERROR: const globals cannot be mutable //~^ HELP did you mean to declare a static? -FOO: uint = 3; +FOO: usize = 3; fn main() { } diff --git a/src/test/compile-fail/issue-17718-const-privacy.rs b/src/test/compile-fail/issue-17718-const-privacy.rs index d3be9f3dd3f77..a9af30a3ff03d 100644 --- a/src/test/compile-fail/issue-17718-const-privacy.rs +++ b/src/test/compile-fail/issue-17718-const-privacy.rs @@ -20,7 +20,7 @@ use other::{ }; mod a { - const B: uint = 3; + const B: usize = 3; } fn main() {} diff --git a/src/test/compile-fail/issue-17718-constants-not-static.rs b/src/test/compile-fail/issue-17718-constants-not-static.rs index 8c51b592054a5..db56d2c6cf3c6 100644 --- a/src/test/compile-fail/issue-17718-constants-not-static.rs +++ b/src/test/compile-fail/issue-17718-constants-not-static.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const FOO: uint = 3; +const FOO: usize = 3; -fn foo() -> &'static uint { &FOO } +fn foo() -> &'static usize { &FOO } //~^ ERROR: borrowed value does not live long enough fn main() { diff --git a/src/test/compile-fail/issue-17718-patterns.rs b/src/test/compile-fail/issue-17718-patterns.rs index 01dfb1b4af93c..ab95606da4445 100644 --- a/src/test/compile-fail/issue-17718-patterns.rs +++ b/src/test/compile-fail/issue-17718-patterns.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static A1: uint = 1; -static mut A2: uint = 1; -const A3: uint = 1; +static A1: usize = 1; +static mut A2: usize = 1; +const A3: usize = 1; fn main() { match 1u { diff --git a/src/test/compile-fail/issue-17718-recursive.rs b/src/test/compile-fail/issue-17718-recursive.rs index a13dfe639c12b..9959b0c6fc523 100644 --- a/src/test/compile-fail/issue-17718-recursive.rs +++ b/src/test/compile-fail/issue-17718-recursive.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const A: uint = B; //~ ERROR: recursive constant -const B: uint = A; //~ ERROR: recursive constant +const A: usize = B; //~ ERROR: recursive constant +const B: usize = A; //~ ERROR: recursive constant fn main() {} diff --git a/src/test/compile-fail/issue-17718-references.rs b/src/test/compile-fail/issue-17718-references.rs index 7b272e1610c7f..9d8b116f56982 100644 --- a/src/test/compile-fail/issue-17718-references.rs +++ b/src/test/compile-fail/issue-17718-references.rs @@ -8,21 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Struct { a: uint } +struct Struct { a: usize } -const C: uint = 1; -static S: uint = 1; +const C: usize = 1; +static S: usize = 1; -const T1: &'static uint = &C; -const T2: &'static uint = &S; //~ ERROR: constants cannot refer to other statics -static T3: &'static uint = &C; -static T4: &'static uint = &S; +const T1: &'static usize = &C; +const T2: &'static usize = &S; //~ ERROR: constants cannot refer to other statics +static T3: &'static usize = &C; +static T4: &'static usize = &S; -const T5: uint = C; -const T6: uint = S; //~ ERROR: constants cannot refer to other statics +const T5: usize = C; +const T6: usize = S; //~ ERROR: constants cannot refer to other statics //~^ cannot refer to other statics -static T7: uint = C; -static T8: uint = S; //~ ERROR: cannot refer to other statics by value +static T7: usize = C; +static T8: usize = S; //~ ERROR: cannot refer to other statics by value const T9: Struct = Struct { a: C }; const T10: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value diff --git a/src/test/compile-fail/issue-17718-static-sync.rs b/src/test/compile-fail/issue-17718-static-sync.rs index 147bff2e9777e..394a9cc69bee7 100644 --- a/src/test/compile-fail/issue-17718-static-sync.rs +++ b/src/test/compile-fail/issue-17718-static-sync.rs @@ -12,7 +12,7 @@ use std::marker; struct Foo { marker: marker::NoSync } -static FOO: uint = 3; +static FOO: usize = 3; static BAR: Foo = Foo { marker: marker::NoSync }; //~^ ERROR: the trait `core::marker::Sync` is not implemented diff --git a/src/test/compile-fail/issue-17933.rs b/src/test/compile-fail/issue-17933.rs index de5a38507bc34..1a490245cfc4d 100644 --- a/src/test/compile-fail/issue-17933.rs +++ b/src/test/compile-fail/issue-17933.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub static X: uint = 1u; +pub static X: usize = 1u; fn main() { match 1u { diff --git a/src/test/compile-fail/issue-18252.rs b/src/test/compile-fail/issue-18252.rs index 02493b96dc88d..dd9626f74eccf 100644 --- a/src/test/compile-fail/issue-18252.rs +++ b/src/test/compile-fail/issue-18252.rs @@ -9,7 +9,7 @@ // except according to those terms. enum Foo { - Variant { x: uint } + Variant { x: usize } } fn main() { diff --git a/src/test/compile-fail/issue-18294.rs b/src/test/compile-fail/issue-18294.rs index ca4cf526f07a4..efc1ba1635c95 100644 --- a/src/test/compile-fail/issue-18294.rs +++ b/src/test/compile-fail/issue-18294.rs @@ -10,6 +10,6 @@ fn main() { const X: u32 = 1; - const Y: uint = &X as *const u32 as uint; //~ ERROR E0018 + const Y: usize = &X as *const u32 as usize; //~ ERROR E0018 println!("{}", Y); } diff --git a/src/test/compile-fail/issue-18566.rs b/src/test/compile-fail/issue-18566.rs index 0d1a1f16c2c93..17dc59dbc8d7d 100644 --- a/src/test/compile-fail/issue-18566.rs +++ b/src/test/compile-fail/issue-18566.rs @@ -10,19 +10,19 @@ use std::ops::Deref; -struct MyPtr<'a>(&'a mut uint); +struct MyPtr<'a>(&'a mut usize); impl<'a> Deref for MyPtr<'a> { - type Target = uint; + type Target = usize; - fn deref<'b>(&'b self) -> &'b uint { self.0 } + fn deref<'b>(&'b self) -> &'b usize { self.0 } } trait Tr { - fn poke(&self, s: &mut uint); + fn poke(&self, s: &mut usize); } -impl Tr for uint { - fn poke(&self, s: &mut uint) { +impl Tr for usize { + fn poke(&self, s: &mut usize) { *s = 2; } } diff --git a/src/test/compile-fail/issue-19244-1.rs b/src/test/compile-fail/issue-19244-1.rs index c3700f2f90acf..0850705aee6cb 100644 --- a/src/test/compile-fail/issue-19244-1.rs +++ b/src/test/compile-fail/issue-19244-1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const TUP: (uint,) = (42,); +const TUP: (usize,) = (42,); fn main() { let a: [isize; TUP.1]; diff --git a/src/test/compile-fail/issue-19244-2.rs b/src/test/compile-fail/issue-19244-2.rs index 7c7271552d2ef..93a3fc87eb010 100644 --- a/src/test/compile-fail/issue-19244-2.rs +++ b/src/test/compile-fail/issue-19244-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct MyStruct { field: uint } +struct MyStruct { field: usize } const STRUCT: MyStruct = MyStruct { field: 42 }; fn main() { diff --git a/src/test/compile-fail/issue-2111.rs b/src/test/compile-fail/issue-2111.rs index 3d9c7401ded24..8180ce52bdbc1 100644 --- a/src/test/compile-fail/issue-2111.rs +++ b/src/test/compile-fail/issue-2111.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(a: Option, b: Option) { +fn foo(a: Option, b: Option) { match (a,b) { //~^ ERROR: non-exhaustive patterns: `(None, None)` not covered (Some(a), Some(b)) if a == b => { } diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 90b5ff8475e61..5ebc445bace26 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -12,7 +12,7 @@ #![allow(unused_variables)] #![allow(dead_code)] -fn fail_len(v: Vec ) -> uint { +fn fail_len(v: Vec ) -> usize { let mut i = 3; panic!(); for x in v.iter() { i += 1u; } diff --git a/src/test/compile-fail/issue-2356.rs b/src/test/compile-fail/issue-2356.rs index d6acc13c2897c..f0ae0eb59f532 100644 --- a/src/test/compile-fail/issue-2356.rs +++ b/src/test/compile-fail/issue-2356.rs @@ -30,7 +30,7 @@ impl MaybeDog { } impl Groom for cat { - fn shave(&self, other: uint) { + fn shave(&self, other: usize) { whiskers -= other; //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? shave(4); @@ -75,7 +75,7 @@ impl cat { //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? } - pub fn grow_older(other:uint) { + pub fn grow_older(other:usize) { whiskers = 4; //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`? purr_louder(); diff --git a/src/test/compile-fail/issue-3344.rs b/src/test/compile-fail/issue-3344.rs index 27a91f891a2df..73532cb768ad8 100644 --- a/src/test/compile-fail/issue-3344.rs +++ b/src/test/compile-fail/issue-3344.rs @@ -9,7 +9,7 @@ // except according to those terms. #[derive(PartialEq)] -struct thing(uint); +struct thing(usize); impl PartialOrd for thing { //~ ERROR not all trait items implemented, missing: `partial_cmp` fn le(&self, other: &thing) -> bool { true } fn ge(&self, other: &thing) -> bool { true } diff --git a/src/test/compile-fail/issue-3707.rs b/src/test/compile-fail/issue-3707.rs index 2445638d62e60..ad818cf9f8316 100644 --- a/src/test/compile-fail/issue-3707.rs +++ b/src/test/compile-fail/issue-3707.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Obj { - member: uint + member: usize } impl Obj { diff --git a/src/test/compile-fail/issue-4265.rs b/src/test/compile-fail/issue-4265.rs index a1a77092b12a5..b4bc7ecdc5f89 100644 --- a/src/test/compile-fail/issue-4265.rs +++ b/src/test/compile-fail/issue-4265.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - baz: uint + baz: usize } impl Foo { diff --git a/src/test/compile-fail/issue-4935.rs b/src/test/compile-fail/issue-4935.rs index 3a0db4246be62..b37b8e237edda 100644 --- a/src/test/compile-fail/issue-4935.rs +++ b/src/test/compile-fail/issue-4935.rs @@ -10,5 +10,5 @@ // Regression test for issue #4935 -fn foo(a: uint) {} +fn foo(a: usize) {} fn main() { foo(5, 6) } //~ ERROR this function takes 1 parameter but 2 parameters were supplied diff --git a/src/test/compile-fail/issue-5358-1.rs b/src/test/compile-fail/issue-5358-1.rs index 576dfe8b67bc1..96bad3a6a4455 100644 --- a/src/test/compile-fail/issue-5358-1.rs +++ b/src/test/compile-fail/issue-5358-1.rs @@ -9,7 +9,7 @@ // except according to those terms. enum Either { Left(T), Right(U) } -struct S(Either); +struct S(Either); fn main() { match S(Either::Left(5)) { diff --git a/src/test/compile-fail/issue-5500-1.rs b/src/test/compile-fail/issue-5500-1.rs index 0edcfa8a5477d..7e5809cdee0b0 100644 --- a/src/test/compile-fail/issue-5500-1.rs +++ b/src/test/compile-fail/issue-5500-1.rs @@ -9,7 +9,7 @@ // except according to those terms. struct TrieMapIterator<'a> { - node: &'a uint + node: &'a usize } fn main() { diff --git a/src/test/compile-fail/issue-6801.rs b/src/test/compile-fail/issue-6801.rs index 27230989f63bc..9424ff22dc75c 100644 --- a/src/test/compile-fail/issue-6801.rs +++ b/src/test/compile-fail/issue-6801.rs @@ -14,16 +14,16 @@ #![feature(box_syntax)] -fn twice(x: Box) -> uint { +fn twice(x: Box) -> usize { *x * 2 } -fn invoke(f: F) where F: FnOnce() -> uint { +fn invoke(f: F) where F: FnOnce() -> usize { f(); } fn main() { - let x : Box = box 9; + let x : Box = box 9; let sq = |:| { *x * *x }; twice(x); //~ ERROR: cannot move out of diff --git a/src/test/compile-fail/issue-6991.rs b/src/test/compile-fail/issue-6991.rs index a5d23c70bd5e8..0cc5898adfca1 100644 --- a/src/test/compile-fail/issue-6991.rs +++ b/src/test/compile-fail/issue-6991.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static x: &'static uint = &1; -static y: uint = *x; +static x: &'static usize = &1; +static y: usize = *x; //~^ ERROR cannot refer to other statics by value, // use the address-of operator or a constant instead fn main() {} diff --git a/src/test/compile-fail/issue-7607-2.rs b/src/test/compile-fail/issue-7607-2.rs index 8a7022a9a32c3..9541899b46913 100644 --- a/src/test/compile-fail/issue-7607-2.rs +++ b/src/test/compile-fail/issue-7607-2.rs @@ -11,7 +11,7 @@ // ignore-tidy-linelength pub mod a { - pub struct Foo { a: uint } + pub struct Foo { a: usize } } pub mod b { diff --git a/src/test/compile-fail/issue-9957.rs b/src/test/compile-fail/issue-9957.rs index 573d847cbe3b8..b1204e828900c 100644 --- a/src/test/compile-fail/issue-9957.rs +++ b/src/test/compile-fail/issue-9957.rs @@ -11,5 +11,5 @@ pub extern crate core; //~ ERROR: `pub` visibility is not allowed fn main() { - pub use std::uint; //~ ERROR: imports in functions are never reachable + pub use std::usize; //~ ERROR: imports in functions are never reachable } diff --git a/src/test/compile-fail/kindck-nonsendable-1.rs b/src/test/compile-fail/kindck-nonsendable-1.rs index a13a3f7c4ab71..172587dc1e4aa 100644 --- a/src/test/compile-fail/kindck-nonsendable-1.rs +++ b/src/test/compile-fail/kindck-nonsendable-1.rs @@ -11,7 +11,7 @@ use std::rc::Rc; -fn foo(_x: Rc) {} +fn foo(_x: Rc) {} fn bar(_: F) { } diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs index 7d91b1998bf24..fac518c763569 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs @@ -14,15 +14,15 @@ use std::iter::{Range,range}; trait Itble<'r, T, I: Iterator> { fn iter(&'r self) -> I; } -impl<'r> Itble<'r, uint, Range> for (uint, uint) { - fn iter(&'r self) -> Range { +impl<'r> Itble<'r, usize, Range> for (usize, usize) { + fn iter(&'r self) -> Range { let &(min, max) = self; range(min, max) } } -fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &T) -> bool { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn check<'r, I: Iterator, T: Itble<'r, uint, I>>(cont: &'r T) +fn check<'r, I: Iterator, T: Itble<'r, usize, I>>(cont: &T) -> bool { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn check<'r, I: Iterator, T: Itble<'r, usize, I>>(cont: &'r T) let cont_iter = cont.iter(); //~ ERROR: cannot infer let result = cont_iter.fold(Some(0u16), |state, val| { state.map_or(None, |mask| { diff --git a/src/test/compile-fail/lint-ctypes.rs b/src/test/compile-fail/lint-ctypes.rs index e0ed095b1a1dc..801f9dfd1cf3b 100644 --- a/src/test/compile-fail/lint-ctypes.rs +++ b/src/test/compile-fail/lint-ctypes.rs @@ -14,9 +14,9 @@ extern crate libc; extern { pub fn bare_type1(size: isize); //~ ERROR: found rust type - pub fn bare_type2(size: uint); //~ ERROR: found rust type + pub fn bare_type2(size: usize); //~ ERROR: found rust type pub fn ptr_type1(size: *const isize); //~ ERROR: found rust type - pub fn ptr_type2(size: *const uint); //~ ERROR: found rust type + pub fn ptr_type2(size: *const usize); //~ ERROR: found rust type pub fn good1(size: *const libc::c_int); pub fn good2(size: *const libc::c_uint); diff --git a/src/test/compile-fail/lint-dead-code-4.rs b/src/test/compile-fail/lint-dead-code-4.rs index 2653c1d5b2410..bc2e0940f4471 100644 --- a/src/test/compile-fail/lint-dead-code-4.rs +++ b/src/test/compile-fail/lint-dead-code-4.rs @@ -17,12 +17,12 @@ extern crate libc; use std::num::Int; struct Foo { - x: uint, + x: usize, b: bool, //~ ERROR: struct field is never used marker: std::marker::NoCopy } -fn field_read(f: Foo) -> uint { +fn field_read(f: Foo) -> usize { f.x.pow(2) } @@ -43,7 +43,7 @@ fn field_match_in_patterns(b: XYZ) -> String { } struct Bar { - x: uint, //~ ERROR: struct field is never used + x: usize, //~ ERROR: struct field is never used b: bool, _guard: () } diff --git a/src/test/compile-fail/lint-exceeding-bitshifts.rs b/src/test/compile-fail/lint-exceeding-bitshifts.rs index cbb416b62a6a2..3d8d5b407fdf4 100644 --- a/src/test/compile-fail/lint-exceeding-bitshifts.rs +++ b/src/test/compile-fail/lint-exceeding-bitshifts.rs @@ -57,6 +57,6 @@ fn main() { let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits let n = 1i << std::isize::BITS; //~ ERROR: bitshift exceeds the type's number of bits - let n = 1u << std::uint::BITS; //~ ERROR: bitshift exceeds the type's number of bits + let n = 1u << std::usize::BITS; //~ ERROR: bitshift exceeds the type's number of bits } diff --git a/src/test/compile-fail/lint-raw-ptr-derive.rs b/src/test/compile-fail/lint-raw-ptr-derive.rs index 9fcd6b33c9d56..4320b3e744152 100644 --- a/src/test/compile-fail/lint-raw-ptr-derive.rs +++ b/src/test/compile-fail/lint-raw-ptr-derive.rs @@ -28,7 +28,7 @@ enum Baz { #[derive(Clone)] struct Buzz { x: (*const isize, //~ ERROR use of `#[derive]` with a raw pointer - *const uint) //~ ERROR use of `#[derive]` with a raw pointer + *const usize) //~ ERROR use of `#[derive]` with a raw pointer } fn main() {} diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index b0a3a6bd10e7d..c8469fb7f8cf3 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -174,7 +174,7 @@ mod inheritance { let _ = Experimental::ExperimentalVariant; //~ ERROR use of experimental item let _ = Experimental::StableVariant; - let x: uint = 0; + let x: usize = 0; x.experimental(); //~ ERROR use of experimental item x.stable(); } diff --git a/src/test/compile-fail/lint-unused-extern-crate.rs b/src/test/compile-fail/lint-unused-extern-crate.rs index a77de551f5d2c..c9d34d40479cf 100644 --- a/src/test/compile-fail/lint-unused-extern-crate.rs +++ b/src/test/compile-fail/lint-unused-extern-crate.rs @@ -28,6 +28,6 @@ use rand::isaac::IsaacRng; use other::*; fn main() { - let x: collecs::vec::Vec = Vec::new(); + let x: collecs::vec::Vec = Vec::new(); let y = foo(); } diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index 44579bb55e08a..a6d7c587c7bd5 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -44,7 +44,7 @@ mod test { mod foo { pub struct Point{pub x: isize, pub y: isize} - pub struct Square{pub p: Point, pub h: uint, pub w: uint} + pub struct Square{pub p: Point, pub h: usize, pub w: usize} } mod bar { diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs index b6eda8635c2f4..9317e465a7a07 100644 --- a/src/test/compile-fail/lint-uppercase-variables.rs +++ b/src/test/compile-fail/lint-uppercase-variables.rs @@ -17,15 +17,15 @@ use std::io::File; use std::io::IoError; struct Something { - X: uint //~ ERROR structure field `X` should have a snake case name such as `x` + X: usize //~ ERROR structure field `X` should have a snake case name such as `x` } -fn test(Xx: uint) { //~ ERROR variable `Xx` should have a snake case name such as `xx` +fn test(Xx: usize) { //~ ERROR variable `Xx` should have a snake case name such as `xx` println!("{}", Xx); } fn main() { - let Test: uint = 0; //~ ERROR variable `Test` should have a snake case name such as `test` + let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name such as `test` println!("{}", Test); let mut f = File::open(&Path::new("something.txt")); diff --git a/src/test/compile-fail/liveness-bad-bang-2.rs b/src/test/compile-fail/liveness-bad-bang-2.rs index 04364e4e01088..c612a02336591 100644 --- a/src/test/compile-fail/liveness-bad-bang-2.rs +++ b/src/test/compile-fail/liveness-bad-bang-2.rs @@ -10,7 +10,7 @@ // Tests that a function with a ! annotation always actually fails -fn bad_bang(i: uint) -> ! { //~ ERROR computation may converge in a function marked as diverging +fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging println!("{}", 3i); } diff --git a/src/test/compile-fail/match-pattern-field-mismatch-2.rs b/src/test/compile-fail/match-pattern-field-mismatch-2.rs index ab9efdcc8cc50..e63ddf6c7fd9b 100644 --- a/src/test/compile-fail/match-pattern-field-mismatch-2.rs +++ b/src/test/compile-fail/match-pattern-field-mismatch-2.rs @@ -10,8 +10,8 @@ fn main() { enum color { - rgb(uint, uint, uint), - cmyk(uint, uint, uint, uint), + rgb(usize, usize, usize), + cmyk(usize, usize, usize, usize), no_color, } diff --git a/src/test/compile-fail/match-pattern-field-mismatch.rs b/src/test/compile-fail/match-pattern-field-mismatch.rs index 243690bbf31dc..8426ecdaf995e 100644 --- a/src/test/compile-fail/match-pattern-field-mismatch.rs +++ b/src/test/compile-fail/match-pattern-field-mismatch.rs @@ -10,8 +10,8 @@ fn main() { enum color { - rgb(uint, uint, uint), - cmyk(uint, uint, uint, uint), + rgb(usize, usize, usize), + cmyk(usize, usize, usize, usize), no_color, } diff --git a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs index f0cc7c80417e0..c6d45f1c9db8a 100644 --- a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs +++ b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs @@ -16,7 +16,7 @@ trait foo { fn foo(&self) -> isize; } -impl foo for Vec { +impl foo for Vec { fn foo(&self) -> isize {1} } @@ -39,7 +39,7 @@ fn m2() { let mut x = Vec::new(); // ...but we still resolved `foo()` to the trait and hence know the return type. - let y: uint = x.foo(); //~ ERROR mismatched types + let y: usize = x.foo(); //~ ERROR mismatched types } fn main() { } diff --git a/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs b/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs index 30e635149c442..91d1e73e232ab 100644 --- a/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs +++ b/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs @@ -15,8 +15,8 @@ extern crate ambig_impl_2_lib; use ambig_impl_2_lib::me; trait me2 { - fn me(&self) -> uint; + fn me(&self) -> usize; } -impl me2 for uint { fn me(&self) -> uint { *self } } +impl me2 for usize { fn me(&self) -> usize { *self } } fn main() { 1u.me(); } //~ ERROR E0034 diff --git a/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs b/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs index 87efaed4e3dda..dc5f1023b9964 100644 --- a/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs +++ b/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs @@ -15,8 +15,8 @@ trait Foo { fn method(&self) {} } trait Bar { fn method(&self) {} } -impl Foo for uint {} -impl Bar for uint {} +impl Foo for usize {} +impl Bar for usize {} fn main() { 1u.method(); //~ ERROR E0034 diff --git a/src/test/compile-fail/move-fragments-9.rs b/src/test/compile-fail/move-fragments-9.rs index 4dd6c5eb4e644..d0eeebd02f809 100644 --- a/src/test/compile-fail/move-fragments-9.rs +++ b/src/test/compile-fail/move-fragments-9.rs @@ -34,7 +34,7 @@ pub fn test_move_array_into_recv(a: [D; 3], recv: &mut [D; 3]) { } #[rustc_move_fragments] -pub fn test_extract_array_elem(a: [D; 3], i: uint) -> D { +pub fn test_extract_array_elem(a: [D; 3], i: usize) -> D { //~^ ERROR parent_of_fragments: `$(local a)` //~| ERROR assigned_leaf_path: `$(local i)` //~| ERROR moved_leaf_path: `$(local a).[]` @@ -43,7 +43,7 @@ pub fn test_extract_array_elem(a: [D; 3], i: uint) -> D { } #[rustc_move_fragments] -pub fn test_overwrite_array_elem(mut a: [D; 3], i: uint, d: D) { +pub fn test_overwrite_array_elem(mut a: [D; 3], i: usize, d: D) { //~^ ERROR parent_of_fragments: `$(local mut a)` //~| ERROR assigned_leaf_path: `$(local i)` //~| ERROR assigned_leaf_path: `$(local d)` @@ -59,7 +59,7 @@ pub fn test_overwrite_array_elem(mut a: [D; 3], i: uint, d: D) { // See RFC PR 320 for more discussion. #[rustc_move_fragments] -pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: uint, recv: &mut [D; 3], d: D) { +pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: usize, recv: &mut [D; 3], d: D) { //~^ ERROR parent_of_fragments: `$(local mut a)` //~| ERROR parent_of_fragments: `$(local recv)` //~| ERROR assigned_leaf_path: `$(local recv).*` @@ -76,7 +76,7 @@ pub fn test_move_array_then_overwrite_elem1(mut a: [D; 3], i: uint, recv: &mut [ } #[rustc_move_fragments] -pub fn test_move_array_then_overwrite_elem2(mut a: [D; 3], i: uint, j: uint, +pub fn test_move_array_then_overwrite_elem2(mut a: [D; 3], i: usize, j: usize, recv: &mut [D; 3], d1: D, d2: D) { //~^^ ERROR parent_of_fragments: `$(local mut a)` //~| ERROR parent_of_fragments: `$(local recv)` diff --git a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs index 0f5e012ef1950..5dfe7f0c71f14 100644 --- a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs +++ b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs @@ -10,9 +10,9 @@ #![feature(box_syntax)] -use std::uint; +use std::usize; -fn test(_x: Box) {} +fn test(_x: Box) {} fn main() { let i = box 3; diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 3d8b095cb4eec..708affe30f34a 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -9,7 +9,7 @@ // except according to those terms. struct cat { - meows : uint, + meows : usize, how_hungry : isize, } @@ -21,7 +21,7 @@ impl cat { } -fn cat(in_x : uint, in_y : isize) -> cat { +fn cat(in_x : usize, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/mutable-class-fields.rs b/src/test/compile-fail/mutable-class-fields.rs index b2a76d8fd3785..15046c4c51be0 100644 --- a/src/test/compile-fail/mutable-class-fields.rs +++ b/src/test/compile-fail/mutable-class-fields.rs @@ -9,11 +9,11 @@ // except according to those terms. struct cat { - meows : uint, + meows : usize, how_hungry : isize, } -fn cat(in_x : uint, in_y : isize) -> cat { +fn cat(in_x : usize, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs b/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs index a1dc2ab2041a5..0212adff305d0 100644 --- a/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs +++ b/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs @@ -11,6 +11,6 @@ enum State { ST_NULL, ST_WHITESPACE } fn main() { - [State::ST_NULL; (State::ST_WHITESPACE as uint)]; + [State::ST_NULL; (State::ST_WHITESPACE as usize)]; //~^ ERROR expected constant integer for repeat count, found non-constant expression } diff --git a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs index 2e063e5237c44..26528543b435a 100644 --- a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs +++ b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs @@ -11,7 +11,7 @@ // Check that non constant exprs fail for vector repeat syntax fn main() { - fn bar(n: uint) { + fn bar(n: usize) { let _x = [0; n]; //~ ERROR expected constant integer for repeat count, found variable } } diff --git a/src/test/compile-fail/non-exhaustive-pattern-witness.rs b/src/test/compile-fail/non-exhaustive-pattern-witness.rs index d35e3ad3c55b0..7442900c9b778 100644 --- a/src/test/compile-fail/non-exhaustive-pattern-witness.rs +++ b/src/test/compile-fail/non-exhaustive-pattern-witness.rs @@ -12,7 +12,7 @@ struct Foo { first: bool, - second: Option<[uint; 4]> + second: Option<[usize; 4]> } enum Color { diff --git a/src/test/compile-fail/or-patter-mismatch.rs b/src/test/compile-fail/or-patter-mismatch.rs index 7f30e36560932..f845d1e6344ec 100644 --- a/src/test/compile-fail/or-patter-mismatch.rs +++ b/src/test/compile-fail/or-patter-mismatch.rs @@ -10,6 +10,6 @@ // error-pattern: mismatched types -enum blah { a(isize, isize, uint), b(isize, isize), } +enum blah { a(isize, isize, usize), b(isize, isize), } fn main() { match blah::a(1, 1, 2u) { blah::a(_, x, y) | blah::b(x, y) => { } } } diff --git a/src/test/compile-fail/packed-struct-transmute.rs b/src/test/compile-fail/packed-struct-transmute.rs index 200c8a5137a8b..b80dd0b36ed52 100644 --- a/src/test/compile-fail/packed-struct-transmute.rs +++ b/src/test/compile-fail/packed-struct-transmute.rs @@ -20,13 +20,13 @@ use std::mem; #[repr(packed)] struct Foo { bar: u8, - baz: uint + baz: usize } #[derive(Show)] struct Oof { rab: u8, - zab: uint + zab: usize } fn main() { diff --git a/src/test/compile-fail/pat-shadow-in-nested-binding.rs b/src/test/compile-fail/pat-shadow-in-nested-binding.rs index 4d89ec14d94b2..526e4c1618721 100644 --- a/src/test/compile-fail/pat-shadow-in-nested-binding.rs +++ b/src/test/compile-fail/pat-shadow-in-nested-binding.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct foo(uint); +struct foo(usize); fn main() { let (foo, _) = (2, 3); //~ ERROR declaration of `foo` shadows diff --git a/src/test/compile-fail/prim-with-args.rs b/src/test/compile-fail/prim-with-args.rs index b4dba4f3a60cf..cc0b74dc82a5b 100644 --- a/src/test/compile-fail/prim-with-args.rs +++ b/src/test/compile-fail/prim-with-args.rs @@ -15,7 +15,7 @@ let x: i8; //~ ERROR type parameters are not allowed on this type let x: i16; //~ ERROR type parameters are not allowed on this type let x: i32; //~ ERROR type parameters are not allowed on this type let x: i64; //~ ERROR type parameters are not allowed on this type -let x: uint; //~ ERROR type parameters are not allowed on this type +let x: usize; //~ ERROR type parameters are not allowed on this type let x: u8; //~ ERROR type parameters are not allowed on this type let x: u16; //~ ERROR type parameters are not allowed on this type let x: u32; //~ ERROR type parameters are not allowed on this type @@ -27,7 +27,7 @@ let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: i64<'static>; //~ ERROR lifetime parameters are not allowed on this type -let x: uint<'static>; //~ ERROR lifetime parameters are not allowed on this type +let x: usize<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index d09481cfd6449..f897a2bc9f3ae 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -12,7 +12,7 @@ mod kitties { pub struct cat { - meows : uint, + meows : usize, how_hungry : isize, } @@ -21,7 +21,7 @@ mod kitties { fn nap(&self) {} } - pub fn cat(in_x : uint, in_y : isize) -> cat { + pub fn cat(in_x : usize, in_y : isize) -> cat { cat { meows: in_x, how_hungry: in_y diff --git a/src/test/compile-fail/private-struct-field.rs b/src/test/compile-fail/private-struct-field.rs index 3f6fa573cc0b5..b98719e157ea6 100644 --- a/src/test/compile-fail/private-struct-field.rs +++ b/src/test/compile-fail/private-struct-field.rs @@ -10,7 +10,7 @@ mod cat { pub struct Cat { - meows: uint + meows: usize } pub fn new_cat() -> Cat { diff --git a/src/test/compile-fail/recursion_limit.rs b/src/test/compile-fail/recursion_limit.rs index 6e1ecb10e3a2a..6cd984c071a0c 100644 --- a/src/test/compile-fail/recursion_limit.rs +++ b/src/test/compile-fail/recursion_limit.rs @@ -35,7 +35,7 @@ link! { K, L } link! { L, M } link! { M, N } -enum N { N(uint) } +enum N { N(usize) } fn is_send() { } diff --git a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs index 9e8281faf2f56..5b04fa3d87ca5 100644 --- a/src/test/compile-fail/region-bound-on-closure-outlives-call.rs +++ b/src/test/compile-fail/region-bound-on-closure-outlives-call.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn call_rec(mut f: F) -> uint where F: FnMut(uint) -> uint { +fn call_rec(mut f: F) -> usize where F: FnMut(usize) -> usize { (|&mut: x| f(x))(call_rec(f)) //~ ERROR cannot move out of `f` } diff --git a/src/test/compile-fail/regions-addr-of-self.rs b/src/test/compile-fail/regions-addr-of-self.rs index fb2dbacef84e7..6aeac1bd1b376 100644 --- a/src/test/compile-fail/regions-addr-of-self.rs +++ b/src/test/compile-fail/regions-addr-of-self.rs @@ -9,17 +9,17 @@ // except according to those terms. struct dog { - cats_chased: uint, + cats_chased: usize, } impl dog { pub fn chase_cat(&mut self) { - let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer + let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer *p += 1u; } pub fn chase_cat_2(&mut self) { - let p: &mut uint = &mut self.cats_chased; + let p: &mut usize = &mut self.cats_chased; *p += 1u; } } diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index fb60d8f7b27a4..33898b2e782cb 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::uint; +use std::usize; struct dog { - food: uint, + food: usize, } impl dog { pub fn chase_cat(&mut self) { let _f = |&:| { - let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer + let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer *p = 3u; }; } diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 1774c9fada946..2e7a4051ff221 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -9,7 +9,7 @@ // except according to those terms. enum ast<'a> { - num(uint), + num(usize), add(&'a ast<'a>, &'a ast<'a>) } @@ -20,14 +20,14 @@ fn build() { compute(&z); } -fn compute(x: &ast) -> uint { +fn compute(x: &ast) -> usize { match *x { ast::num(x) => { x } ast::add(x, y) => { compute(x) + compute(y) } } } -fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(uint) -> uint { +fn map_nums<'a,'b, F>(x: &ast, f: &mut F) -> &'a ast<'b> where F: FnMut(usize) -> usize { match *x { ast::num(x) => { return &ast::num((*f)(x)); //~ ERROR borrowed value does not live long enough diff --git a/src/test/compile-fail/regions-creating-enums3.rs b/src/test/compile-fail/regions-creating-enums3.rs index 6f38f29591f32..4c8484540aabb 100644 --- a/src/test/compile-fail/regions-creating-enums3.rs +++ b/src/test/compile-fail/regions-creating-enums3.rs @@ -9,7 +9,7 @@ // except according to those terms. enum ast<'a> { - num(uint), + num(usize), add(&'a ast<'a>, &'a ast<'a>) } diff --git a/src/test/compile-fail/regions-creating-enums4.rs b/src/test/compile-fail/regions-creating-enums4.rs index 34a125c809f6b..5dc9b370f32b5 100644 --- a/src/test/compile-fail/regions-creating-enums4.rs +++ b/src/test/compile-fail/regions-creating-enums4.rs @@ -9,7 +9,7 @@ // except according to those terms. enum ast<'a> { - num(uint), + num(usize), add(&'a ast<'a>, &'a ast<'a>) } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index 6e59a29b8cf22..22724081a1bce 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -12,32 +12,32 @@ // that appear in their parameter list. See also // regions-free-region-ordering-caller.rs -fn ordering1<'a, 'b>(x: &'a &'b uint) -> &'a uint { +fn ordering1<'a, 'b>(x: &'a &'b usize) -> &'a usize { // It is safe to assume that 'a <= 'b due to the type of x - let y: &'b uint = &**x; + let y: &'b usize = &**x; return y; } -fn ordering2<'a, 'b>(x: &'a &'b uint, y: &'a uint) -> &'b uint { +fn ordering2<'a, 'b>(x: &'a &'b usize, y: &'a usize) -> &'b usize { // However, it is not safe to assume that 'b <= 'a &*y //~ ERROR cannot infer } -fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint { +fn ordering3<'a, 'b>(x: &'a usize, y: &'b usize) -> &'a &'b usize { // Do not infer an ordering from the return value. - let z: &'b uint = &*x; + let z: &'b usize = &*x; //~^ ERROR cannot infer panic!(); } -fn ordering4<'a, 'b, F>(a: &'a uint, b: &'b uint, x: F) where F: FnOnce(&'a &'b uint) { +fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { // Do not infer ordering from closure argument types. - let z: Option<&'a &'b uint> = None; + let z: Option<&'a &'b usize> = None; //~^ ERROR reference has a longer lifetime than the data it references } -fn ordering5<'a, 'b>(a: &'a uint, b: &'b uint, x: Option<&'a &'b uint>) { - let z: Option<&'a &'b uint> = None; +fn ordering5<'a, 'b>(a: &'a usize, b: &'b usize, x: Option<&'a &'b usize>) { + let z: Option<&'a &'b usize> = None; } fn main() {} diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index 55c0cf3bb260d..edca3b7ed41e4 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -12,21 +12,21 @@ // than the thing it points at and ensure that they result in // errors. See also regions-free-region-ordering-callee.rs -struct Paramd<'a> { x: &'a uint } +struct Paramd<'a> { x: &'a usize } -fn call2<'a, 'b>(a: &'a uint, b: &'b uint) { - let z: Option<&'b &'a uint> = None; +fn call2<'a, 'b>(a: &'a usize, b: &'b usize) { + let z: Option<&'b &'a usize> = None; //~^ ERROR reference has a longer lifetime than the data it references } -fn call3<'a, 'b>(a: &'a uint, b: &'b uint) { +fn call3<'a, 'b>(a: &'a usize, b: &'b usize) { let y: Paramd<'a> = Paramd { x: a }; let z: Option<&'b Paramd<'a>> = None; //~^ ERROR reference has a longer lifetime than the data it references } -fn call4<'a, 'b>(a: &'a uint, b: &'b uint) { - let z: Option<&'a &'b uint> = None; +fn call4<'a, 'b>(a: &'a usize, b: &'b usize) { + let z: Option<&'a &'b usize> = None; //~^ ERROR reference has a longer lifetime than the data it references } diff --git a/src/test/compile-fail/regions-free-region-ordering-caller1.rs b/src/test/compile-fail/regions-free-region-ordering-caller1.rs index b117a1a647643..b29518ccdabb5 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller1.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller1.rs @@ -12,11 +12,11 @@ // than the thing it points at and ensure that they result in // errors. See also regions-free-region-ordering-callee.rs -fn call1<'a>(x: &'a uint) { +fn call1<'a>(x: &'a usize) { // Test that creating a pointer like - // &'a &'z uint requires that 'a <= 'z: - let y: uint = 3; - let z: &'a & uint = &(&y); + // &'a &'z usize requires that 'a <= 'z: + let y: usize = 3; + let z: &'a & usize = &(&y); //~^ ERROR borrowed value does not live long enough //~^^ ERROR `y` does not live long enough } diff --git a/src/test/compile-fail/regions-glb-free-free.rs b/src/test/compile-fail/regions-glb-free-free.rs index 0eb47da16b600..f43d35c579e25 100644 --- a/src/test/compile-fail/regions-glb-free-free.rs +++ b/src/test/compile-fail/regions-glb-free-free.rs @@ -12,8 +12,8 @@ mod argparse { pub struct Flag<'a> { name: &'a str, desc: &'a str, - max_count: uint, - value: uint + max_count: usize, + value: usize } pub fn flag<'r>(name: &'r str, desc: &'r str) -> Flag<'r> { diff --git a/src/test/compile-fail/regions-in-enums.rs b/src/test/compile-fail/regions-in-enums.rs index 72b32e4a9af45..613a90dda67c8 100644 --- a/src/test/compile-fail/regions-in-enums.rs +++ b/src/test/compile-fail/regions-in-enums.rs @@ -12,19 +12,19 @@ // See also regions-undeclared.rs enum yes0<'lt> { - X3(&'lt uint) + X3(&'lt usize) } enum yes1<'a> { - X4(&'a uint) + X4(&'a usize) } enum no0 { - X5(&'foo uint) //~ ERROR use of undeclared lifetime name `'foo` + X5(&'foo usize) //~ ERROR use of undeclared lifetime name `'foo` } enum no1 { - X6(&'a uint) //~ ERROR use of undeclared lifetime name `'a` + X6(&'a usize) //~ ERROR use of undeclared lifetime name `'a` } fn main() {} diff --git a/src/test/compile-fail/regions-in-structs.rs b/src/test/compile-fail/regions-in-structs.rs index f46f73bf26a26..c231d3a913e0c 100644 --- a/src/test/compile-fail/regions-in-structs.rs +++ b/src/test/compile-fail/regions-in-structs.rs @@ -9,11 +9,11 @@ // except according to those terms. struct yes1<'a> { - x: &'a uint, + x: &'a usize, } struct yes2<'a> { - x: &'a uint, + x: &'a usize, } struct StructDecl { diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index 32d89607e4b3e..d5ef9f3a9642e 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -struct ctxt { v: uint } +struct ctxt { v: usize } trait get_ctxt { // Here the `&` is bound in the method definition: @@ -29,7 +29,7 @@ impl<'a> get_ctxt for has_ctxt<'a> { } -fn get_v(gc: Box) -> uint { +fn get_v(gc: Box) -> usize { gc.get_ctxt().v } diff --git a/src/test/compile-fail/regions-trait-2.rs b/src/test/compile-fail/regions-trait-2.rs index 92c1849c15b83..0f298492e612e 100644 --- a/src/test/compile-fail/regions-trait-2.rs +++ b/src/test/compile-fail/regions-trait-2.rs @@ -13,7 +13,7 @@ // Test that you cannot escape a reference // into a trait. -struct ctxt { v: uint } +struct ctxt { v: usize } trait get_ctxt { fn get_ctxt(&self) -> &'a ctxt; diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index 78d84fb7c757d..8943abb49ae93 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -22,7 +22,7 @@ // except according to those terms. trait get_ctxt<'a> { - fn get_ctxt(self) -> &'a uint; + fn get_ctxt(self) -> &'a usize; } fn make_gc1(gc: @get_ctxt<'a>) -> @get_ctxt<'b> { @@ -30,11 +30,11 @@ fn make_gc1(gc: @get_ctxt<'a>) -> @get_ctxt<'b> { } struct Foo { - r: &'a uint + r: &'a usize } impl get_ctxt for Foo<'a> { - fn get_ctxt(&self) -> &'a uint { self.r } + fn get_ctxt(&self) -> &'a usize { self.r } } fn make_gc2<'a,'b>(foo: Foo<'a>) -> @get_ctxt<'b> { diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 5ebabc2e3548c..c1affeca8d955 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -21,6 +21,6 @@ fn main() { let x = *&x; //~ ERROR: cannot move out of dereference let x = ATOMIC_UINT_INIT; let x = *&x; //~ ERROR: cannot move out of dereference - let x: AtomicPtr = AtomicPtr::new(ptr::null_mut()); + let x: AtomicPtr = AtomicPtr::new(ptr::null_mut()); let x = *&x; //~ ERROR: cannot move out of dereference } diff --git a/src/test/compile-fail/struct-pat-derived-error.rs b/src/test/compile-fail/struct-pat-derived-error.rs index cafead3af0e66..4b65292340fa1 100644 --- a/src/test/compile-fail/struct-pat-derived-error.rs +++ b/src/test/compile-fail/struct-pat-derived-error.rs @@ -9,8 +9,8 @@ // except according to those terms. struct a { - b: uint, - c: uint + b: usize, + c: usize } impl a { diff --git a/src/test/compile-fail/tail-typeck.rs b/src/test/compile-fail/tail-typeck.rs index aeb01c93ed0e7..99e98b24b63c3 100644 --- a/src/test/compile-fail/tail-typeck.rs +++ b/src/test/compile-fail/tail-typeck.rs @@ -12,6 +12,6 @@ fn f() -> isize { return g(); } -fn g() -> uint { return 0u; } +fn g() -> usize { return 0u; } fn main() { let y = f(); } diff --git a/src/test/compile-fail/terr-in-field.rs b/src/test/compile-fail/terr-in-field.rs index 975c7e7de1ff7..1e5422a798e33 100644 --- a/src/test/compile-fail/terr-in-field.rs +++ b/src/test/compile-fail/terr-in-field.rs @@ -15,7 +15,7 @@ struct foo { struct bar { a: isize, - b: uint, + b: usize, } fn want_foo(f: foo) {} diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs index 52035c09dd6dd..479f21ea3a160 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs @@ -20,7 +20,7 @@ fn main() { x: 3i }; - let baz: Foo = panic!(); + let baz: Foo = panic!(); //~^ ERROR not implemented } diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums-static.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums-static.rs index c26cccc8b146c..d5369817e9ac1 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums-static.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums-static.rs @@ -14,7 +14,7 @@ struct Foo { x: T, } -static X: Foo = Foo { +static X: Foo = Foo { //~^ ERROR not implemented x: 1, }; diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc.rs index d01f9d59fb437..ded75aa1d85e4 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc.rs @@ -14,7 +14,7 @@ extern crate trait_bounds_on_structs_and_enums_xc; use trait_bounds_on_structs_and_enums_xc::{Bar, Foo, Trait}; -fn explode(x: Foo) {} +fn explode(x: Foo) {} //~^ ERROR not implemented fn kaboom(y: Bar) {} diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs index 87d32a0041d31..490ee0e8ad6f3 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums.rs @@ -17,7 +17,7 @@ struct Foo { enum Bar { ABar(isize), BBar(T), - CBar(uint), + CBar(usize), } fn explode(x: Foo) {} @@ -38,7 +38,7 @@ struct Baz { enum Boo { //~^ ERROR not implemented - Quux(Bar), + Quux(Bar), } struct Badness { @@ -57,7 +57,7 @@ trait PolyTrait { struct Struct; -impl PolyTrait> for Struct { +impl PolyTrait> for Struct { //~^ ERROR not implemented fn whatever() {} } diff --git a/src/test/compile-fail/trait-impl-different-num-params.rs b/src/test/compile-fail/trait-impl-different-num-params.rs index 6c3e987944109..647dd4e05faf5 100644 --- a/src/test/compile-fail/trait-impl-different-num-params.rs +++ b/src/test/compile-fail/trait-impl-different-num-params.rs @@ -9,7 +9,7 @@ // except according to those terms. trait foo { - fn bar(&self, x: uint) -> Self; + fn bar(&self, x: usize) -> Self; } impl foo for isize { fn bar(&self) -> isize { diff --git a/src/test/compile-fail/trait-impl-method-mismatch.rs b/src/test/compile-fail/trait-impl-method-mismatch.rs index 73224c7b45cec..4e2eb22421354 100644 --- a/src/test/compile-fail/trait-impl-method-mismatch.rs +++ b/src/test/compile-fail/trait-impl-method-mismatch.rs @@ -10,12 +10,12 @@ trait Mumbo { - fn jumbo(&self, x: &uint) -> uint; + fn jumbo(&self, x: &usize) -> usize; } -impl Mumbo for uint { +impl Mumbo for usize { // Cannot have a larger effect than the trait: - unsafe fn jumbo(&self, x: &uint) { *self + *x; } + unsafe fn jumbo(&self, x: &usize) { *self + *x; } //~^ ERROR expected normal fn, found unsafe fn } diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index f1ff82662b966..583d0421d1eb1 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -12,7 +12,7 @@ trait bar { fn dup(&self) -> Self; fn blah(&self); } impl bar for isize { fn dup(&self) -> isize { *self } fn blah(&self) {} } -impl bar for uint { fn dup(&self) -> uint { *self } fn blah(&self) {} } +impl bar for usize { fn dup(&self) -> usize { *self } fn blah(&self) {} } fn main() { 10i.dup::(); //~ ERROR does not take type parameters diff --git a/src/test/compile-fail/trait-test.rs b/src/test/compile-fail/trait-test.rs index 6039e646407e3..d53e353d9d928 100644 --- a/src/test/compile-fail/trait-test.rs +++ b/src/test/compile-fail/trait-test.rs @@ -10,6 +10,6 @@ trait foo { fn foo(&self); } -impl isize for uint { fn foo(&self) {} } //~ ERROR trait +impl isize for usize { fn foo(&self) {} } //~ ERROR trait fn main() {} diff --git a/src/test/compile-fail/traits-multidispatch-bad.rs b/src/test/compile-fail/traits-multidispatch-bad.rs index d155735d69cf8..f655844e2f36f 100644 --- a/src/test/compile-fail/traits-multidispatch-bad.rs +++ b/src/test/compile-fail/traits-multidispatch-bad.rs @@ -14,9 +14,9 @@ trait Convert { fn convert(&self) -> Target; } -impl Convert for isize { - fn convert(&self) -> uint { - *self as uint +impl Convert for isize { + fn convert(&self) -> usize { + *self as usize } } diff --git a/src/test/compile-fail/typeck_type_placeholder_item.rs b/src/test/compile-fail/typeck_type_placeholder_item.rs index 723c5fda3a7d3..aa4ecad639372 100644 --- a/src/test/compile-fail/typeck_type_placeholder_item.rs +++ b/src/test/compile-fail/typeck_type_placeholder_item.rs @@ -31,7 +31,7 @@ static TEST5: (_, _) = (1, 2); fn test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures -fn test7(x: _) { let _x: uint = x; } +fn test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures fn test8(_f: fn() -> _) { } @@ -84,7 +84,7 @@ pub fn main() { fn fn_test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures - fn fn_test7(x: _) { let _x: uint = x; } + fn fn_test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures fn fn_test8(_f: fn() -> _) { } diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs index 365b786cc1a2a..8178335de5931 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs @@ -16,6 +16,6 @@ struct Foo<'a, T:'a> { } pub fn main() { - let c: Foo<_, uint> = Foo { r: &5 }; + let c: Foo<_, usize> = Foo { r: &5 }; //~^ ERROR wrong number of type arguments: expected 1, found 2 } diff --git a/src/test/compile-fail/ufcs-explicit-self-bad.rs b/src/test/compile-fail/ufcs-explicit-self-bad.rs index 60b2002ae97c8..6c323e8c1ae50 100644 --- a/src/test/compile-fail/ufcs-explicit-self-bad.rs +++ b/src/test/compile-fail/ufcs-explicit-self-bad.rs @@ -28,7 +28,7 @@ impl Bar { fn foo(self: Bar, x: isize) -> isize { //~ ERROR mismatched self type x } - fn bar(self: &Bar, x: isize) -> isize { //~ ERROR mismatched self type + fn bar(self: &Bar, x: isize) -> isize { //~ ERROR mismatched self type x } } diff --git a/src/test/compile-fail/unboxed-closure-immutable-capture.rs b/src/test/compile-fail/unboxed-closure-immutable-capture.rs index e28abaf2b1fd6..3848f07a08970 100644 --- a/src/test/compile-fail/unboxed-closure-immutable-capture.rs +++ b/src/test/compile-fail/unboxed-closure-immutable-capture.rs @@ -14,7 +14,7 @@ // environment cannot mutate captured variables that have not been // declared mutable (#18335) -fn set(x: &mut uint) { *x = 0; } +fn set(x: &mut usize) { *x = 0; } fn main() { let x = 0u; diff --git a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs index f37dcfb774581..9dff0e9e01e34 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs @@ -28,21 +28,21 @@ fn test<'a,'b>() { // No errors expected: eq::< Foo<(),()>, Foo() >(); eq::< Foo<(isize,),()>, Foo(isize) >(); - eq::< Foo<(isize,uint),()>, Foo(isize,uint) >(); - eq::< Foo<(isize,uint),uint>, Foo(isize,uint) -> uint >(); - eq::< Foo<(&'a isize,&'b uint),uint>, Foo(&'a isize,&'b uint) -> uint >(); + eq::< Foo<(isize,usize),()>, Foo(isize,usize) >(); + eq::< Foo<(isize,usize),usize>, Foo(isize,usize) -> usize >(); + eq::< Foo<(&'a isize,&'b usize),usize>, Foo(&'a isize,&'b usize) -> usize >(); // Test that anonymous regions in `()` form are equivalent // to fresh bound regions, and that we can intermingle // named and anonymous as we choose: - eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, - for<'x,'y> Foo(&'x isize,&'y uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, - for<'x> Foo(&'x isize,&uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, - for<'y> Foo(&isize,&'y uint) -> uint >(); - eq::< for<'x,'y> Foo<(&'x isize,&'y uint),uint>, - Foo(&isize,&uint) -> uint >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>, + for<'x,'y> Foo(&'x isize,&'y usize) -> usize >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>, + for<'x> Foo(&'x isize,&usize) -> usize >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>, + for<'y> Foo(&isize,&'y usize) -> usize >(); + eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>, + Foo(&isize,&usize) -> usize >(); // lifetime elision eq::< for<'x> Foo<(&'x isize,), &'x isize>, diff --git a/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs b/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs index 176970703c5e3..29429c708d255 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-lifetime-elision.rs @@ -30,5 +30,5 @@ fn main() { eq::< for<'a> Foo<(&'a isize,), (&'a isize, &'a isize)>, Foo(&isize) -> (&isize, &isize) >(); - let _: Foo(&isize, &uint) -> &uint; //~ ERROR missing lifetime specifier + let _: Foo(&isize, &usize) -> &usize; //~ ERROR missing lifetime specifier } diff --git a/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs b/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs index b2bd030f3c46a..d86f55d53685a 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs @@ -19,7 +19,7 @@ impl Bar { } fn bar() { - let b = Box::Bar::::new(); // OK + let b = Box::Bar::::new(); // OK let b = Box::Bar::()::new(); //~^ ERROR expected ident, found `(` diff --git a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs index ca641e39aedfc..95673a513190b 100644 --- a/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-vtable-mismatch.rs @@ -17,7 +17,7 @@ fn call_it>(y: isize, mut f: F) -> isize { } pub fn main() { - let f = |&mut: x: uint, y: isize| -> isize { (x as isize) + y }; + let f = |&mut: x: usize, y: isize| -> isize { (x as isize) + y }; let z = call_it(3, f); //~ ERROR type mismatch println!("{}", z); } diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs index c4c0e648f3470..c277e63aba9fe 100644 --- a/src/test/compile-fail/unreachable-arm.rs +++ b/src/test/compile-fail/unreachable-arm.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] -enum foo { a(Box, isize), b(uint), } +enum foo { a(Box, isize), b(usize), } fn main() { match foo::b(1u) { foo::b(_) | foo::a(box _, 1) => { } foo::a(_, 1) => { } } } diff --git a/src/test/compile-fail/unsized5.rs b/src/test/compile-fail/unsized5.rs index 02a8b5899d734..dc10f795cd422 100644 --- a/src/test/compile-fail/unsized5.rs +++ b/src/test/compile-fail/unsized5.rs @@ -21,11 +21,11 @@ struct S2 { } struct S3 { f: str, //~ ERROR `core::marker::Sized` is not implemented - g: [uint] + g: [usize] } struct S4 { f: str, //~ ERROR `core::marker::Sized` is not implemented - g: uint + g: usize } enum E { V1(X, isize), //~ERROR `core::marker::Sized` is not implemented diff --git a/src/test/compile-fail/utf8_idents.rs b/src/test/compile-fail/utf8_idents.rs index 9bd14305b9a40..a5471e87f2204 100644 --- a/src/test/compile-fail/utf8_idents.rs +++ b/src/test/compile-fail/utf8_idents.rs @@ -16,7 +16,7 @@ fn foo< >() {} struct X { - δ: uint //~ ERROR non-ascii idents are not fully supported + δ: usize //~ ERROR non-ascii idents are not fully supported } pub fn main() { diff --git a/src/test/compile-fail/variadic-ffi-2.rs b/src/test/compile-fail/variadic-ffi-2.rs index 9e2b015f33d96..1d519c978a35c 100644 --- a/src/test/compile-fail/variadic-ffi-2.rs +++ b/src/test/compile-fail/variadic-ffi-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn baz(f: extern "stdcall" fn(uint, ...)) { +fn baz(f: extern "stdcall" fn(usize, ...)) { //~^ ERROR: variadic function must have C calling convention f(22, 44); } diff --git a/src/test/compile-fail/wrong-ret-type.rs b/src/test/compile-fail/wrong-ret-type.rs index d744ad804e7a9..6db11fcffd227 100644 --- a/src/test/compile-fail/wrong-ret-type.rs +++ b/src/test/compile-fail/wrong-ret-type.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern: mismatched types -fn mk_int() -> uint { let i: isize = 3; return i; } +fn mk_int() -> usize { let i: isize = 3; return i; } fn main() { } From 441044f071181b52144bad15a50bf91dc06771a5 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 22:05:56 +1100 Subject: [PATCH 15/25] Update compile-fail tests to use is/us, not i/u. --- src/test/compile-fail/array-old-syntax-1.rs | 2 +- src/test/compile-fail/array-old-syntax-2.rs | 2 +- src/test/compile-fail/asm-in-bad-modifier.rs | 4 +- src/test/compile-fail/asm-misplaced-option.rs | 4 +- src/test/compile-fail/asm-out-assign-imm.rs | 2 +- src/test/compile-fail/asm-out-no-modifier.rs | 2 +- src/test/compile-fail/assign-to-method.rs | 4 +- .../compile-fail/associated-types-eq-3.rs | 2 +- .../associated-types-incomplete-object.rs | 8 ++-- src/test/compile-fail/bad-bang-ann-3.rs | 4 +- src/test/compile-fail/bad-bang-ann.rs | 4 +- .../compile-fail/bad-method-typaram-kind.rs | 2 +- src/test/compile-fail/bang-tailexpr.rs | 2 +- .../borrow-immutable-upvar-mutation.rs | 12 +++--- src/test/compile-fail/borrow-tuple-fields.rs | 12 +++--- .../borrowck-anon-fields-tuple.rs | 4 +- .../borrowck-array-double-move.rs | 4 +- .../compile-fail/borrowck-break-uninit-2.rs | 4 +- .../borrowck-closures-mut-and-imm.rs | 12 +++--- .../compile-fail/borrowck-closures-two-mut.rs | 8 ++-- ...rrowck-for-loop-correct-cmt-for-pattern.rs | 4 +- .../borrowck-for-loop-head-linkage.rs | 4 +- src/test/compile-fail/borrowck-if-no-else.rs | 2 +- .../compile-fail/borrowck-if-with-else.rs | 2 +- ...k-imm-ref-to-mut-rec-field-issue-3162-c.rs | 2 +- .../compile-fail/borrowck-issue-2657-1.rs | 2 +- .../compile-fail/borrowck-issue-2657-2.rs | 2 +- .../compile-fail/borrowck-lend-flow-loop.rs | 2 +- .../compile-fail/borrowck-lend-flow-match.rs | 4 +- .../compile-fail/borrowck-let-suggestion.rs | 2 +- .../borrowck-loan-blocks-move-cc.rs | 4 +- .../borrowck-match-binding-is-assignment.rs | 6 +-- ...owck-move-from-subpath-of-borrowed-path.rs | 2 +- ...rowck-move-out-of-overloaded-auto-deref.rs | 2 +- .../borrowck-multiple-captures.rs | 12 +++--- .../borrowck-overloaded-index-2.rs | 2 +- .../borrowck-report-with-custom-diagnostic.rs | 6 +-- .../compile-fail/borrowck-uniq-via-lend.rs | 14 +++---- .../borrowck-vec-pattern-move-tail.rs | 2 +- .../borrowck-vec-pattern-nesting.rs | 10 ++--- src/test/compile-fail/borrowck-while-break.rs | 2 +- src/test/compile-fail/borrowck-while.rs | 2 +- .../builtin-superkinds-self-type.rs | 4 +- .../cannot-mutate-captured-non-mut-var.rs | 2 +- .../class-implements-bad-trait.rs | 2 +- src/test/compile-fail/class-method-missing.rs | 2 +- src/test/compile-fail/class-missing-self.rs | 2 +- .../const-block-non-item-statement.rs | 4 +- src/test/compile-fail/deriving-non-type.rs | 4 +- .../compile-fail/destructure-trait-ref.rs | 18 ++++---- src/test/compile-fail/dst-bad-deep.rs | 2 +- .../feature-gate-advanced-slice-features.rs | 2 +- .../compile-fail/feature-gate-int-uint.rs | 4 +- src/test/compile-fail/fn-trait-formatting.rs | 2 +- ...or-loop-refutable-pattern-error-message.rs | 4 +- .../hashmap-iter-value-lifetime.rs | 2 +- src/test/compile-fail/hashmap-lifetimes.rs | 2 +- src/test/compile-fail/if-let.rs | 14 +++---- src/test/compile-fail/implicit-method-bind.rs | 2 +- src/test/compile-fail/import-glob-circular.rs | 4 +- src/test/compile-fail/index-bot.rs | 2 +- .../compile-fail/infinite-instantiation.rs | 6 +-- src/test/compile-fail/integral-indexing.rs | 4 +- src/test/compile-fail/issue-10398.rs | 2 +- src/test/compile-fail/issue-11493.rs | 4 +- src/test/compile-fail/issue-11714.rs | 2 +- src/test/compile-fail/issue-11873.rs | 4 +- src/test/compile-fail/issue-11925.rs | 2 +- src/test/compile-fail/issue-12041.rs | 2 +- src/test/compile-fail/issue-13058.rs | 2 +- src/test/compile-fail/issue-13482-2.rs | 2 +- src/test/compile-fail/issue-1362.rs | 2 +- src/test/compile-fail/issue-1448-2.rs | 2 +- src/test/compile-fail/issue-15094.rs | 2 +- src/test/compile-fail/issue-15167.rs | 2 +- src/test/compile-fail/issue-15480.rs | 2 +- src/test/compile-fail/issue-17283.rs | 2 +- src/test/compile-fail/issue-17385.rs | 4 +- src/test/compile-fail/issue-17405.rs | 2 +- src/test/compile-fail/issue-17441.rs | 8 ++-- src/test/compile-fail/issue-17718-patterns.rs | 2 +- src/test/compile-fail/issue-17800.rs | 4 +- src/test/compile-fail/issue-17913.rs | 6 +-- src/test/compile-fail/issue-17933.rs | 4 +- src/test/compile-fail/issue-17999.rs | 2 +- src/test/compile-fail/issue-18107.rs | 2 +- src/test/compile-fail/issue-18252.rs | 2 +- src/test/compile-fail/issue-18566.rs | 2 +- src/test/compile-fail/issue-18783.rs | 4 +- src/test/compile-fail/issue-18959.rs | 2 +- src/test/compile-fail/issue-19096.rs | 2 +- src/test/compile-fail/issue-1962.rs | 6 +-- src/test/compile-fail/issue-2150.rs | 2 +- src/test/compile-fail/issue-3707.rs | 4 +- src/test/compile-fail/issue-4335.rs | 2 +- src/test/compile-fail/issue-7575.rs | 6 +-- .../compile-fail/kindck-impl-type-params-2.rs | 2 +- .../kindck-inherited-copy-bound.rs | 4 +- src/test/compile-fail/kindck-nonsendable-1.rs | 2 +- src/test/compile-fail/lint-dead-code-1.rs | 2 +- src/test/compile-fail/lint-dead-code-3.rs | 2 +- src/test/compile-fail/lint-dead-code-4.rs | 2 +- .../compile-fail/lint-exceeding-bitshifts.rs | 4 +- src/test/compile-fail/lint-type-limits.rs | 6 +-- .../compile-fail/lint-unnecessary-parens.rs | 12 +++--- src/test/compile-fail/lint-unused-imports.rs | 6 +-- .../compile-fail/lint-unused-mut-variables.rs | 42 +++++++++---------- src/test/compile-fail/liveness-bad-bang-2.rs | 4 +- .../liveness-return-last-stmt-semi.rs | 2 +- src/test/compile-fail/liveness-unused.rs | 28 ++++++------- .../compile-fail/liveness-use-after-move.rs | 2 +- .../compile-fail/loop-does-not-diverge.rs | 2 +- .../macro-no-implicit-reexport.rs | 2 +- .../macro-reexport-not-locally-visible.rs | 2 +- src/test/compile-fail/match-ill-type1.rs | 2 +- src/test/compile-fail/match-ill-type2.rs | 8 ++-- src/test/compile-fail/match-non-exhaustive.rs | 4 +- .../compile-fail/match-range-fail-dominate.rs | 18 ++++---- src/test/compile-fail/match-range-fail.rs | 8 ++-- src/test/compile-fail/match-vec-fixed.rs | 2 +- .../method-ambig-two-traits-cross-crate.rs | 2 +- ...od-ambig-two-traits-with-default-method.rs | 2 +- src/test/compile-fail/method-missing-call.rs | 2 +- .../compile-fail/move-out-of-tuple-field.rs | 4 +- .../compile-fail/moves-based-on-type-exprs.rs | 12 +++--- src/test/compile-fail/mut-cant-alias.rs | 2 +- src/test/compile-fail/mut-cross-borrowing.rs | 2 +- src/test/compile-fail/mut-not-freeze.rs | 2 +- .../mut-pattern-internal-mutability.rs | 2 +- .../compile-fail/mut-ptr-cant-outlive-ref.rs | 2 +- .../compile-fail/mutable-class-fields-2.rs | 2 +- src/test/compile-fail/mutable-class-fields.rs | 2 +- src/test/compile-fail/no-capture-arc.rs | 2 +- src/test/compile-fail/no-reuse-move-arc.rs | 2 +- src/test/compile-fail/no_send-rc.rs | 2 +- src/test/compile-fail/no_share-rc.rs | 2 +- src/test/compile-fail/non-exhaustive-match.rs | 10 ++--- .../non-exhaustive-pattern-witness.rs | 2 +- src/test/compile-fail/obsolete-tilde.rs | 4 +- src/test/compile-fail/or-patter-mismatch.rs | 2 +- src/test/compile-fail/pat-range-bad-dots.rs | 2 +- .../compile-fail/pattern-bindings-after-at.rs | 2 +- src/test/compile-fail/pptypedef.rs | 4 +- src/test/compile-fail/private-method.rs | 2 +- .../private-struct-field-cross-crate.rs | 4 +- src/test/compile-fail/ptr-coercion.rs | 2 +- src/test/compile-fail/range-1.rs | 4 +- src/test/compile-fail/range-2.rs | 2 +- .../compile-fail/refutable-pattern-errors.rs | 2 +- src/test/compile-fail/regions-addr-of-self.rs | 6 +-- .../regions-addr-of-upvar-self.rs | 2 +- .../regions-close-over-type-parameter-2.rs | 2 +- .../compile-fail/regions-creating-enums.rs | 4 +- .../regions-escape-loop-via-variable.rs | 4 +- .../regions-escape-loop-via-vec.rs | 2 +- .../regions-infer-proc-static-upvar.rs | 2 +- ...regions-return-ref-to-upvar-issue-17403.rs | 2 +- .../compile-fail/regions-steal-closure.rs | 2 +- src/test/compile-fail/regions-trait-1.rs | 4 +- src/test/compile-fail/regions-trait-2.rs | 2 +- .../regions-var-type-out-of-scope.rs | 4 +- src/test/compile-fail/repeat_count.rs | 2 +- src/test/compile-fail/shadowed-lifetime.rs | 2 +- src/test/compile-fail/static-assert2.rs | 2 +- src/test/compile-fail/static-mut-not-pat.rs | 2 +- src/test/compile-fail/static-region-bound.rs | 4 +- src/test/compile-fail/tail-typeck.rs | 2 +- .../compile-fail/trailing-plus-in-bounds.rs | 2 +- ...rait-bounds-on-structs-and-enums-locals.rs | 2 +- .../trait-bounds-on-structs-and-enums-xc1.rs | 2 +- src/test/compile-fail/trait-test-2.rs | 6 +-- .../compile-fail/traits-multidispatch-bad.rs | 2 +- .../typeck-unsafe-always-share.rs | 2 +- .../typeck_type_placeholder_item.rs | 4 +- .../typeck_type_placeholder_lifetime_1.rs | 2 +- .../unboxed-closure-illegal-move.rs | 12 +++--- .../unboxed-closure-immutable-capture.rs | 2 +- .../compile-fail/unboxed-closure-region.rs | 2 +- .../unboxed-closures-borrow-conflict.rs | 2 +- ...nfer-argument-types-two-region-pointers.rs | 2 +- ...nboxed-closures-static-call-wrong-trait.rs | 2 +- .../unboxed-closures-type-mismatch.rs | 2 +- src/test/compile-fail/unique-unique-kind.rs | 2 +- src/test/compile-fail/unreachable-arm.rs | 2 +- src/test/compile-fail/unreachable-code.rs | 2 +- src/test/compile-fail/unsized3.rs | 4 +- src/test/compile-fail/unsized6.rs | 4 +- .../unused-mut-warning-captured-var.rs | 2 +- .../vec-matching-obsolete-syntax.rs | 2 +- src/test/compile-fail/vec-mut-iter-borrow.rs | 2 +- .../compile-fail/vtable-res-trait-param.rs | 4 +- src/test/compile-fail/warn-path-statement.rs | 2 +- .../where-clauses-not-parameter.rs | 2 +- src/test/compile-fail/while-let.rs | 6 +-- 194 files changed, 379 insertions(+), 379 deletions(-) diff --git a/src/test/compile-fail/array-old-syntax-1.rs b/src/test/compile-fail/array-old-syntax-1.rs index 2dbc9e3da2181..3b4810a86abd5 100644 --- a/src/test/compile-fail/array-old-syntax-1.rs +++ b/src/test/compile-fail/array-old-syntax-1.rs @@ -11,5 +11,5 @@ // Test that the old fixed length array syntax is a parsing error. fn main() { - let _x: [isize, ..3] = [0i, 1, 2]; //~ ERROR + let _x: [isize, ..3] = [0is, 1, 2]; //~ ERROR } diff --git a/src/test/compile-fail/array-old-syntax-2.rs b/src/test/compile-fail/array-old-syntax-2.rs index df2cc305ca8e1..c1b88290bc39c 100644 --- a/src/test/compile-fail/array-old-syntax-2.rs +++ b/src/test/compile-fail/array-old-syntax-2.rs @@ -11,5 +11,5 @@ // Test that the old repeating array syntax gives an error. fn main() { - let _ = [0i, ..3]; //~ ERROR + let _ = [0is, ..3]; //~ ERROR } diff --git a/src/test/compile-fail/asm-in-bad-modifier.rs b/src/test/compile-fail/asm-in-bad-modifier.rs index deff677ad0383..ffbb25e266ac6 100644 --- a/src/test/compile-fail/asm-in-bad-modifier.rs +++ b/src/test/compile-fail/asm-in-bad-modifier.rs @@ -20,8 +20,8 @@ pub fn main() { let x: isize; let y: isize; unsafe { - asm!("mov $1, $0" : "=r"(x) : "=r"(5u)); //~ ERROR input operand constraint contains '=' - asm!("mov $1, $0" : "=r"(y) : "+r"(5u)); //~ ERROR input operand constraint contains '+' + asm!("mov $1, $0" : "=r"(x) : "=r"(5us)); //~ ERROR input operand constraint contains '=' + asm!("mov $1, $0" : "=r"(y) : "+r"(5us)); //~ ERROR input operand constraint contains '+' } foo(x); foo(y); diff --git a/src/test/compile-fail/asm-misplaced-option.rs b/src/test/compile-fail/asm-misplaced-option.rs index 42f3c1692c198..8bc6f206dec02 100644 --- a/src/test/compile-fail/asm-misplaced-option.rs +++ b/src/test/compile-fail/asm-misplaced-option.rs @@ -21,14 +21,14 @@ pub fn main() { let mut x: isize = 0; unsafe { // extra colon - asm!("mov $1, $0" : "=r"(x) : "r"(5u), "0"(x) : : "cc"); + asm!("mov $1, $0" : "=r"(x) : "r"(5us), "0"(x) : : "cc"); //~^ WARNING unrecognized option } assert_eq!(x, 5); unsafe { // comma in place of a colon - asm!("add $2, $1; mov $1, $0" : "=r"(x) : "r"(x), "r"(8u) : "cc", "volatile"); + asm!("add $2, $1; mov $1, $0" : "=r"(x) : "r"(x), "r"(8us) : "cc", "volatile"); //~^ WARNING expected a clobber, found an option } assert_eq!(x, 13); diff --git a/src/test/compile-fail/asm-out-assign-imm.rs b/src/test/compile-fail/asm-out-assign-imm.rs index 031b1de91f26e..9ad5d7e9f09ee 100644 --- a/src/test/compile-fail/asm-out-assign-imm.rs +++ b/src/test/compile-fail/asm-out-assign-imm.rs @@ -21,7 +21,7 @@ pub fn main() { x = 1; //~ NOTE prior assignment occurs here foo(x); unsafe { - asm!("mov $1, $0" : "=r"(x) : "r"(5u)); //~ ERROR re-assignment of immutable variable `x` + asm!("mov $1, $0" : "=r"(x) : "r"(5us)); //~ ERROR re-assignment of immutable variable `x` } foo(x); } diff --git a/src/test/compile-fail/asm-out-no-modifier.rs b/src/test/compile-fail/asm-out-no-modifier.rs index 76f60a34f3c01..b58d41e1d825c 100644 --- a/src/test/compile-fail/asm-out-no-modifier.rs +++ b/src/test/compile-fail/asm-out-no-modifier.rs @@ -19,7 +19,7 @@ fn foo(x: isize) { println!("{}", x); } pub fn main() { let x: isize; unsafe { - asm!("mov $1, $0" : "r"(x) : "r"(5u)); //~ ERROR output operand constraint lacks '=' + asm!("mov $1, $0" : "r"(x) : "r"(5us)); //~ ERROR output operand constraint lacks '=' } foo(x); } diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 047e332566653..0694420e7666f 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -15,7 +15,7 @@ struct cat { } impl cat { - pub fn speak(&self) { self.meows += 1u; } + pub fn speak(&self) { self.meows += 1us; } } fn cat(in_x : usize, in_y : isize) -> cat { @@ -26,6 +26,6 @@ fn cat(in_x : usize, in_y : isize) -> cat { } fn main() { - let nyan : cat = cat(52u, 99); + let nyan : cat = cat(52us, 99); nyan.speak = |&:| println!("meow"); //~ ERROR attempted to take value of method } diff --git a/src/test/compile-fail/associated-types-eq-3.rs b/src/test/compile-fail/associated-types-eq-3.rs index 037f503788844..ed81c0fccbc85 100644 --- a/src/test/compile-fail/associated-types-eq-3.rs +++ b/src/test/compile-fail/associated-types-eq-3.rs @@ -40,7 +40,7 @@ pub fn baz(x: &Foo) { pub fn main() { - let a = 42i; + let a = 42is; foo1(a); //~ERROR expected usize, found struct Bar baz(&a); //~ERROR expected usize, found struct Bar } diff --git a/src/test/compile-fail/associated-types-incomplete-object.rs b/src/test/compile-fail/associated-types-incomplete-object.rs index 30923f0912734..31492406fedd3 100644 --- a/src/test/compile-fail/associated-types-incomplete-object.rs +++ b/src/test/compile-fail/associated-types-incomplete-object.rs @@ -28,15 +28,15 @@ impl Foo for isize { } pub fn main() { - let a = &42i as &Foo; + let a = &42is as &Foo; - let b = &42i as &Foo; + let b = &42is as &Foo; //~^ ERROR the value of the associated type `B` (from the trait `Foo`) must be specified - let c = &42i as &Foo; + let c = &42is as &Foo; //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified - let d = &42i as &Foo; + let d = &42is as &Foo; //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified //~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified } diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs index e364d0283c4b1..e5dbdbd237db8 100644 --- a/src/test/compile-fail/bad-bang-ann-3.rs +++ b/src/test/compile-fail/bad-bang-ann-3.rs @@ -11,7 +11,7 @@ // Tests that a function with a ! annotation always actually fails fn bad_bang(i: usize) -> ! { - return 7u; //~ ERROR `return` in a function declared as diverging [E0166] + return 7us; //~ ERROR `return` in a function declared as diverging [E0166] } -fn main() { bad_bang(5u); } +fn main() { bad_bang(5us); } diff --git a/src/test/compile-fail/bad-bang-ann.rs b/src/test/compile-fail/bad-bang-ann.rs index 817b107d8140c..414421c8b77ce 100644 --- a/src/test/compile-fail/bad-bang-ann.rs +++ b/src/test/compile-fail/bad-bang-ann.rs @@ -11,7 +11,7 @@ // Tests that a function with a ! annotation always actually fails fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging - if i < 0u { } else { panic!(); } + if i < 0us { } else { panic!(); } } -fn main() { bad_bang(5u); } +fn main() { bad_bang(5us); } diff --git a/src/test/compile-fail/bad-method-typaram-kind.rs b/src/test/compile-fail/bad-method-typaram-kind.rs index 636c881a3e162..8e5a6054b8928 100644 --- a/src/test/compile-fail/bad-method-typaram-kind.rs +++ b/src/test/compile-fail/bad-method-typaram-kind.rs @@ -9,7 +9,7 @@ // except according to those terms. fn foo() { - 1u.bar::(); //~ ERROR `core::marker::Send` is not implemented + 1us.bar::(); //~ ERROR `core::marker::Send` is not implemented } trait bar { diff --git a/src/test/compile-fail/bang-tailexpr.rs b/src/test/compile-fail/bang-tailexpr.rs index ec576ff4bd8c2..d17fa68b47cbe 100644 --- a/src/test/compile-fail/bang-tailexpr.rs +++ b/src/test/compile-fail/bang-tailexpr.rs @@ -9,6 +9,6 @@ // except according to those terms. fn f() -> ! { //~ ERROR computation may converge in a function marked as diverging - 3i + 3is } fn main() { } diff --git a/src/test/compile-fail/borrow-immutable-upvar-mutation.rs b/src/test/compile-fail/borrow-immutable-upvar-mutation.rs index 228b07555f29c..12555c550729c 100644 --- a/src/test/compile-fail/borrow-immutable-upvar-mutation.rs +++ b/src/test/compile-fail/borrow-immutable-upvar-mutation.rs @@ -18,24 +18,24 @@ fn set(x: &mut usize) { *x = 5; } fn main() { // By-ref captures { - let mut x = 0u; + let mut x = 0us; let _f = |&:| x = 42; //~ ERROR cannot assign - let mut y = 0u; + let mut y = 0us; let _g = |&:| set(&mut y); //~ ERROR cannot borrow - let mut z = 0u; + let mut z = 0us; let _h = |&mut:| { set(&mut z); |&:| z = 42; }; //~ ERROR cannot assign } // By-value captures { - let mut x = 0u; + let mut x = 0us; let _f = move |&:| x = 42; //~ ERROR cannot assign - let mut y = 0u; + let mut y = 0us; let _g = move |&:| set(&mut y); //~ ERROR cannot borrow - let mut z = 0u; + let mut z = 0us; let _h = move |&mut:| { set(&mut z); move |&:| z = 42; }; //~ ERROR cannot assign } } diff --git a/src/test/compile-fail/borrow-tuple-fields.rs b/src/test/compile-fail/borrow-tuple-fields.rs index 63fd3c60e8c9d..e6fe60a9004b6 100644 --- a/src/test/compile-fail/borrow-tuple-fields.rs +++ b/src/test/compile-fail/borrow-tuple-fields.rs @@ -16,28 +16,28 @@ struct Foo(Box, isize); struct Bar(isize, isize); fn main() { - let x = (box 1i, 2i); + let x = (box 1is, 2is); let r = &x.0; let y = x; //~ ERROR cannot move out of `x` because it is borrowed - let mut x = (1i, 2i); + let mut x = (1is, 2is); let a = &x.0; let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as - let mut x = (1i, 2i); + let mut x = (1is, 2is); let a = &mut x.0; let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time - let x = Foo(box 1i, 2i); + let x = Foo(box 1is, 2is); let r = &x.0; let y = x; //~ ERROR cannot move out of `x` because it is borrowed - let mut x = Bar(1i, 2i); + let mut x = Bar(1is, 2is); let a = &x.0; let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as - let mut x = Bar(1i, 2i); + let mut x = Bar(1is, 2is); let a = &mut x.0; let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time } diff --git a/src/test/compile-fail/borrowck-anon-fields-tuple.rs b/src/test/compile-fail/borrowck-anon-fields-tuple.rs index 9a452ed18f67e..88486756b6659 100644 --- a/src/test/compile-fail/borrowck-anon-fields-tuple.rs +++ b/src/test/compile-fail/borrowck-anon-fields-tuple.rs @@ -12,7 +12,7 @@ // anonymous fields of a tuple vs the same anonymous field. fn distinct_variant() { - let mut y = (1i, 2i); + let mut y = (1is, 2is); let a = match y { (ref mut a, _) => a @@ -27,7 +27,7 @@ fn distinct_variant() { } fn same_variant() { - let mut y = (1i, 2i); + let mut y = (1is, 2is); let a = match y { (ref mut a, _) => a diff --git a/src/test/compile-fail/borrowck-array-double-move.rs b/src/test/compile-fail/borrowck-array-double-move.rs index ef2c629acfebd..ac9ddc2ce6503 100644 --- a/src/test/compile-fail/borrowck-array-double-move.rs +++ b/src/test/compile-fail/borrowck-array-double-move.rs @@ -12,9 +12,9 @@ #![feature(box_syntax)] fn f() { - let mut a = [box 0i, box 1i]; + let mut a = [box 0is, box 1is]; drop(a[0]); - a[1] = box 2i; + a[1] = box 2is; drop(a[0]); //~ ERROR use of moved value: `a[..]` } diff --git a/src/test/compile-fail/borrowck-break-uninit-2.rs b/src/test/compile-fail/borrowck-break-uninit-2.rs index 1ecf9f999b7c5..a52eaeeb9c3e3 100644 --- a/src/test/compile-fail/borrowck-break-uninit-2.rs +++ b/src/test/compile-fail/borrowck-break-uninit-2.rs @@ -11,14 +11,14 @@ fn foo() -> isize { let x: isize; - while 1i != 2 { + while 1is != 2 { break; x = 0; } println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x` - return 17i; + return 17is; } fn main() { println!("{}", foo()); } diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs index 14d57062660b9..29c7d6920bd95 100644 --- a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs @@ -22,37 +22,37 @@ fn set(x: &mut isize) { } fn a() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| x = 4; let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x` } fn b() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| set(&mut x); let c2 = |&mut:| get(&x); //~ ERROR cannot borrow `x` } fn c() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| set(&mut x); let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x` } fn d() { - let mut x = 3i; + let mut x = 3is; let c2 = |&mut:| x * 5; x = 5; //~ ERROR cannot assign } fn e() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| get(&x); x = 5; //~ ERROR cannot assign } fn f() { - let mut x = box 3i; + let mut x = box 3is; let c1 = |&mut:| get(&*x); *x = 5; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs index d442e3ac3f80c..5cb49ab77114b 100644 --- a/src/test/compile-fail/borrowck-closures-two-mut.rs +++ b/src/test/compile-fail/borrowck-closures-two-mut.rs @@ -15,7 +15,7 @@ #![feature(box_syntax)] fn a() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| x = 4; let c2 = |&mut:| x = 5; //~ ERROR cannot borrow `x` as mutable more than once } @@ -25,19 +25,19 @@ fn set(x: &mut isize) { } fn b() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| set(&mut x); let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once } fn c() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| x = 5; let c2 = |&mut:| set(&mut x); //~ ERROR cannot borrow `x` as mutable more than once } fn d() { - let mut x = 3i; + let mut x = 3is; let c1 = |&mut:| x = 5; let c2 = |&mut:| { let _y = |&mut:| set(&mut x); }; // (nested closure) //~^ ERROR cannot borrow `x` as mutable more than once diff --git a/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs b/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs index 17c69a40e58ee..6884ac153a16b 100644 --- a/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs +++ b/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs @@ -17,7 +17,7 @@ struct Foo { } fn main() { - let mut y = 1i; + let mut y = 1is; let x = Some(&mut y); for &a in x.iter() { //~ ERROR cannot move out } @@ -28,7 +28,7 @@ fn main() { for &a in f.a.iter() { //~ ERROR cannot move out } - let x = Some(box 1i); + let x = Some(box 1is); for &a in x.iter() { //~ ERROR cannot move out } } diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs index cb673f9be34fc..d2f99ea696af2 100644 --- a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs +++ b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs @@ -11,11 +11,11 @@ use std::iter::repeat; fn main() { - let mut vector = vec![1u, 2]; + let mut vector = vec![1us, 2]; for &x in vector.iter() { let cap = vector.capacity(); vector.extend(repeat(0)); //~ ERROR cannot borrow - vector[1u] = 5u; //~ ERROR cannot borrow + vector[1us] = 5us; //~ ERROR cannot borrow } } diff --git a/src/test/compile-fail/borrowck-if-no-else.rs b/src/test/compile-fail/borrowck-if-no-else.rs index 08f91e729cd8d..b98833776fbaf 100644 --- a/src/test/compile-fail/borrowck-if-no-else.rs +++ b/src/test/compile-fail/borrowck-if-no-else.rs @@ -11,6 +11,6 @@ fn foo(x: isize) { println!("{}", x); } fn main() { - let x: isize; if 1i > 2 { x = 10; } + let x: isize; if 1is > 2 { x = 10; } foo(x); //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/borrowck-if-with-else.rs b/src/test/compile-fail/borrowck-if-with-else.rs index 01e292ec89d8a..c74edfd8d070c 100644 --- a/src/test/compile-fail/borrowck-if-with-else.rs +++ b/src/test/compile-fail/borrowck-if-with-else.rs @@ -12,7 +12,7 @@ fn foo(x: isize) { println!("{}", x); } fn main() { let x: isize; - if 1i > 2 { + if 1is > 2 { println!("whoops"); } else { x = 10; diff --git a/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs b/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs index d127e9345cde1..fabfce6ffb388 100644 --- a/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs +++ b/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut _a = 3i; + let mut _a = 3is; let _b = &mut _a; { let _c = &*_b; diff --git a/src/test/compile-fail/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck-issue-2657-1.rs index fa80bf38cfed9..dc1c73efc409e 100644 --- a/src/test/compile-fail/borrowck-issue-2657-1.rs +++ b/src/test/compile-fail/borrowck-issue-2657-1.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] fn main() { - let x = Some(box 1i); + let x = Some(box 1is); match x { Some(ref _y) => { let _a = x; //~ ERROR cannot move diff --git a/src/test/compile-fail/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck-issue-2657-2.rs index f531b585ddef8..0b76044f8d61b 100644 --- a/src/test/compile-fail/borrowck-issue-2657-2.rs +++ b/src/test/compile-fail/borrowck-issue-2657-2.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] fn main() { - let x = Some(box 1i); + let x = Some(box 1is); match x { Some(ref y) => { let _b = *y; //~ ERROR cannot move out diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 00dba3856a283..97f5978906800 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -41,7 +41,7 @@ fn block_overarching_alias_mut() { let mut v = box 3; let mut x = &mut v; - for _ in range(0i, 3) { + for _ in range(0is, 3) { borrow(&*v); //~ ERROR cannot borrow } *x = box 5; diff --git a/src/test/compile-fail/borrowck-lend-flow-match.rs b/src/test/compile-fail/borrowck-lend-flow-match.rs index 0b40a78425f6e..f501682847f5f 100644 --- a/src/test/compile-fail/borrowck-lend-flow-match.rs +++ b/src/test/compile-fail/borrowck-lend-flow-match.rs @@ -19,10 +19,10 @@ fn separate_arms() { None => { // It is ok to reassign x here, because there is in // fact no outstanding loan of x! - x = Some(0i); + x = Some(0is); } Some(ref _i) => { - x = Some(1i); //~ ERROR cannot assign + x = Some(1is); //~ ERROR cannot assign } } x.clone(); // just to prevent liveness warnings diff --git a/src/test/compile-fail/borrowck-let-suggestion.rs b/src/test/compile-fail/borrowck-let-suggestion.rs index cd1101c05d15f..5f5ff4014e109 100644 --- a/src/test/compile-fail/borrowck-let-suggestion.rs +++ b/src/test/compile-fail/borrowck-let-suggestion.rs @@ -9,7 +9,7 @@ // except according to those terms. fn f() { - let x = [1i].iter(); //~ ERROR borrowed value does not live long enough + let x = [1is].iter(); //~ ERROR borrowed value does not live long enough //~^^ NOTE reference must be valid for the block //~^^ HELP consider using a `let` binding to increase its lifetime } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 8906e2d42b25a..bff22257760eb 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -17,7 +17,7 @@ fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { } fn box_imm() { - let v = box 3i; + let v = box 3is; let _w = &v; Thread::spawn(move|| { println!("v={}", *v); @@ -26,7 +26,7 @@ fn box_imm() { } fn box_imm_explicit() { - let v = box 3i; + let v = box 3is; let _w = &v; Thread::spawn(move|| { println!("v={}", *v); diff --git a/src/test/compile-fail/borrowck-match-binding-is-assignment.rs b/src/test/compile-fail/borrowck-match-binding-is-assignment.rs index 819ff73a5805c..575d67c0b834a 100644 --- a/src/test/compile-fail/borrowck-match-binding-is-assignment.rs +++ b/src/test/compile-fail/borrowck-match-binding-is-assignment.rs @@ -19,7 +19,7 @@ struct S { } pub fn main() { - match 1i { + match 1is { x => { x += 1; //~ ERROR re-assignment of immutable variable `x` } @@ -37,13 +37,13 @@ pub fn main() { } } - match (1i,) { + match (1is,) { (x,) => { x += 1; //~ ERROR re-assignment of immutable variable `x` } } - match [1i,2,3] { + match [1is,2,3] { [x,_,_] => { x += 1; //~ ERROR re-assignment of immutable variable `x` } diff --git a/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs b/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs index 936092df42e62..0d1a51bbf351e 100644 --- a/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs +++ b/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs @@ -14,7 +14,7 @@ #![feature(box_syntax)] fn main() { - let a = box box 2i; + let a = box box 2is; let b = &a; let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed diff --git a/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs index a6723a04611af..ebe06fb4a226e 100644 --- a/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs +++ b/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs @@ -11,6 +11,6 @@ use std::rc::Rc; pub fn main() { - let _x = Rc::new(vec!(1i, 2)).into_iter(); + let _x = Rc::new(vec!(1is, 2)).into_iter(); //~^ ERROR cannot move out of dereference of `&`-pointer } diff --git a/src/test/compile-fail/borrowck-multiple-captures.rs b/src/test/compile-fail/borrowck-multiple-captures.rs index e90d25c781b42..33ac5d7fceba0 100644 --- a/src/test/compile-fail/borrowck-multiple-captures.rs +++ b/src/test/compile-fail/borrowck-multiple-captures.rs @@ -15,9 +15,9 @@ use std::thread::Thread; fn borrow(_: &T) { } fn different_vars_after_borrows() { - let x1 = box 1i; + let x1 = box 1is; let p1 = &x1; - let x2 = box 2i; + let x2 = box 2is; let p2 = &x2; Thread::spawn(move|| { drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed @@ -28,9 +28,9 @@ fn different_vars_after_borrows() { } fn different_vars_after_moves() { - let x1 = box 1i; + let x1 = box 1is; drop(x1); - let x2 = box 2i; + let x2 = box 2is; drop(x2); Thread::spawn(move|| { drop(x1); //~ ERROR capture of moved value: `x1` @@ -39,7 +39,7 @@ fn different_vars_after_moves() { } fn same_var_after_borrow() { - let x = box 1i; + let x = box 1is; let p = &x; Thread::spawn(move|| { drop(x); //~ ERROR cannot move `x` into closure because it is borrowed @@ -49,7 +49,7 @@ fn same_var_after_borrow() { } fn same_var_after_move() { - let x = box 1i; + let x = box 1is; drop(x); Thread::spawn(move|| { drop(x); //~ ERROR capture of moved value: `x` diff --git a/src/test/compile-fail/borrowck-overloaded-index-2.rs b/src/test/compile-fail/borrowck-overloaded-index-2.rs index bfdd46345de00..074c448a0ecf8 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-2.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-2.rs @@ -25,7 +25,7 @@ impl Index for MyVec { } fn main() { - let v = MyVec { data: vec!(box 1i, box 2, box 3) }; + let v = MyVec { data: vec!(box 1is, box 2, box 3) }; let good = &v[0]; // Shouldn't fail here let bad = v[0]; //~^ ERROR cannot move out of dereference (dereference is implicit, due to indexing) diff --git a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs index 0a47353683cfb..c3a1e808e37f8 100644 --- a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs +++ b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs @@ -11,7 +11,7 @@ #![allow(dead_code)] fn main() { // Original borrow ends at end of function - let mut x = 1u; + let mut x = 1us; let y = &mut x; let z = &x; //~ ERROR cannot borrow } @@ -21,7 +21,7 @@ fn foo() { match true { true => { // Original borrow ends at end of match arm - let mut x = 1u; + let mut x = 1us; let y = &x; let z = &mut x; //~ ERROR cannot borrow } @@ -33,7 +33,7 @@ fn foo() { fn bar() { // Original borrow ends at end of closure |&:| { - let mut x = 1u; + let mut x = 1us; let y = &mut x; let z = &mut x; //~ ERROR cannot borrow }; diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs index 9c14a6990323a..7fadf6d466033 100644 --- a/src/test/compile-fail/borrowck-uniq-via-lend.rs +++ b/src/test/compile-fail/borrowck-uniq-via-lend.rs @@ -13,7 +13,7 @@ fn borrow(_v: &isize) {} fn local() { - let mut v = box 3i; + let mut v = box 3is; borrow(&*v); } @@ -32,27 +32,27 @@ fn local_recs() { } fn aliased_imm() { - let mut v = box 3i; + let mut v = box 3is; let _w = &v; borrow(&*v); } fn aliased_mut() { - let mut v = box 3i; + let mut v = box 3is; let _w = &mut v; borrow(&*v); //~ ERROR cannot borrow `*v` } fn aliased_other() { - let mut v = box 3i; - let mut w = box 4i; + let mut v = box 3is; + let mut w = box 4is; let _x = &mut w; borrow(&*v); } fn aliased_other_reassign() { - let mut v = box 3i; - let mut w = box 4i; + let mut v = box 3is; + let mut w = box 4is; let mut _x = &mut w; _x = &mut v; borrow(&*v); //~ ERROR cannot borrow `*v` diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs index cb8762f44fb79..8869e99efd52a 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut a = [1i, 2, 3, 4]; + let mut a = [1is, 2, 3, 4]; let t = match a { [1, 2, tail..] => tail, _ => unreachable!() diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 98a511f090090..49994ebdbba44 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] fn a() { - let mut vec = [box 1i, box 2, box 3]; + let mut vec = [box 1is, box 2, box 3]; match vec { [box ref _a, _, _] => { vec[0] = box 4; //~ ERROR cannot assign @@ -21,7 +21,7 @@ fn a() { } fn b() { - let mut vec = vec!(box 1i, box 2, box 3); + let mut vec = vec!(box 1is, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_b..] => { @@ -31,7 +31,7 @@ fn b() { } fn c() { - let mut vec = vec!(box 1i, box 2, box 3); + let mut vec = vec!(box 1is, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, //~ ERROR cannot move out @@ -49,7 +49,7 @@ fn c() { } fn d() { - let mut vec = vec!(box 1i, box 2, box 3); + let mut vec = vec!(box 1is, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a.., //~ ERROR cannot move out @@ -60,7 +60,7 @@ fn d() { } fn e() { - let mut vec = vec!(box 1i, box 2, box 3); + let mut vec = vec!(box 1is, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, _b, _c] => {} //~ ERROR cannot move out diff --git a/src/test/compile-fail/borrowck-while-break.rs b/src/test/compile-fail/borrowck-while-break.rs index 15a70b2444d5c..4752120d69126 100644 --- a/src/test/compile-fail/borrowck-while-break.rs +++ b/src/test/compile-fail/borrowck-while-break.rs @@ -11,7 +11,7 @@ fn test(cond: bool) { let v; while cond { - v = 3i; + v = 3is; break; } println!("{}", v); //~ ERROR use of possibly uninitialized variable: `v` diff --git a/src/test/compile-fail/borrowck-while.rs b/src/test/compile-fail/borrowck-while.rs index 17eb19a44e6eb..f163cf602bfa6 100644 --- a/src/test/compile-fail/borrowck-while.rs +++ b/src/test/compile-fail/borrowck-while.rs @@ -10,7 +10,7 @@ fn f() -> isize { let mut x: isize; - while 1i == 1 { x = 10; } + while 1is == 1 { x = 10; } return x; //~ ERROR use of possibly uninitialized variable: `x` } diff --git a/src/test/compile-fail/builtin-superkinds-self-type.rs b/src/test/compile-fail/builtin-superkinds-self-type.rs index 9826a5a0126f4..0ec4f3dce1171 100644 --- a/src/test/compile-fail/builtin-superkinds-self-type.rs +++ b/src/test/compile-fail/builtin-superkinds-self-type.rs @@ -22,6 +22,6 @@ impl Foo for T { } fn main() { let (tx, rx) = channel(); - 1193182i.foo(tx); - assert!(rx.recv() == 1193182i); + 1193182is.foo(tx); + assert!(rx.recv() == 1193182is); } diff --git a/src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs b/src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs index 143e78e5d9f00..9148f13c4ddd3 100644 --- a/src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs +++ b/src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = 1i; + let x = 1is; move|:| { x = 2; }; //~^ ERROR: cannot assign to immutable captured outer variable diff --git a/src/test/compile-fail/class-implements-bad-trait.rs b/src/test/compile-fail/class-implements-bad-trait.rs index 8d57380630837..d709ffdc3fc12 100644 --- a/src/test/compile-fail/class-implements-bad-trait.rs +++ b/src/test/compile-fail/class-implements-bad-trait.rs @@ -15,5 +15,5 @@ class cat : nonexistent { } fn main() { - let nyan = cat(0u); + let nyan = cat(0us); } diff --git a/src/test/compile-fail/class-method-missing.rs b/src/test/compile-fail/class-method-missing.rs index 56b3caf6d2133..3b921e072790b 100644 --- a/src/test/compile-fail/class-method-missing.rs +++ b/src/test/compile-fail/class-method-missing.rs @@ -27,5 +27,5 @@ fn cat(in_x : usize) -> cat { } fn main() { - let nyan = cat(0u); + let nyan = cat(0us); } diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs index af172cd492459..4d8e4bca784be 100644 --- a/src/test/compile-fail/class-missing-self.rs +++ b/src/test/compile-fail/class-missing-self.rs @@ -16,7 +16,7 @@ impl cat { fn sleep(&self) { loop{} } fn meow(&self) { println!("Meow"); - meows += 1u; //~ ERROR unresolved name + meows += 1us; //~ ERROR unresolved name sleep(); //~ ERROR unresolved name } diff --git a/src/test/compile-fail/const-block-non-item-statement.rs b/src/test/compile-fail/const-block-non-item-statement.rs index 053efe3b41b54..62e8fccbda058 100644 --- a/src/test/compile-fail/const-block-non-item-statement.rs +++ b/src/test/compile-fail/const-block-non-item-statement.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static A: usize = { 1u; 2 }; +static A: usize = { 1us; 2 }; //~^ ERROR: blocks in constants are limited to items and tail expressions static B: usize = { { } 2 }; @@ -19,7 +19,7 @@ macro_rules! foo { } static C: usize = { foo!(); 2 }; -static D: usize = { let x = 4u; 2 }; +static D: usize = { let x = 4us; 2 }; //~^ ERROR: blocks in constants are limited to items and tail expressions pub fn main() { diff --git a/src/test/compile-fail/deriving-non-type.rs b/src/test/compile-fail/deriving-non-type.rs index 324f189bbfb92..6015652668e35 100644 --- a/src/test/compile-fail/deriving-non-type.rs +++ b/src/test/compile-fail/deriving-non-type.rs @@ -22,10 +22,10 @@ impl S { } impl T for S { } #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums -static s: usize = 0u; +static s: usize = 0us; #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums -const c: usize = 0u; +const c: usize = 0us; #[derive(PartialEq)] //~ ERROR: `derive` may only be applied to structs and enums mod m { } diff --git a/src/test/compile-fail/destructure-trait-ref.rs b/src/test/compile-fail/destructure-trait-ref.rs index 89062576a50ad..5166ef8f72f8b 100644 --- a/src/test/compile-fail/destructure-trait-ref.rs +++ b/src/test/compile-fail/destructure-trait-ref.rs @@ -27,17 +27,17 @@ fn main() { // if n > m, it's a type mismatch error. // n < m - let &x = &(&1i as &T); - let &x = &&(&1i as &T); - let &&x = &&(&1i as &T); + let &x = &(&1is as &T); + let &x = &&(&1is as &T); + let &&x = &&(&1is as &T); // n == m - let &x = &1i as &T; //~ ERROR type `&T` cannot be dereferenced - let &&x = &(&1i as &T); //~ ERROR type `&T` cannot be dereferenced - let box x = box 1i as Box; //~ ERROR type `Box` cannot be dereferenced + let &x = &1is as &T; //~ ERROR type `&T` cannot be dereferenced + let &&x = &(&1is as &T); //~ ERROR type `&T` cannot be dereferenced + let box x = box 1is as Box; //~ ERROR type `Box` cannot be dereferenced // n > m - let &&x = &1i as &T; //~ ERROR found &-ptr - let &&&x = &(&1i as &T); //~ ERROR found &-ptr - let box box x = box 1i as Box; //~ ERROR found box + let &&x = &1is as &T; //~ ERROR found &-ptr + let &&&x = &(&1is as &T); //~ ERROR found &-ptr + let box box x = box 1is as Box; //~ ERROR found box } diff --git a/src/test/compile-fail/dst-bad-deep.rs b/src/test/compile-fail/dst-bad-deep.rs index 354898f6cf0ec..032835d9460cb 100644 --- a/src/test/compile-fail/dst-bad-deep.rs +++ b/src/test/compile-fail/dst-bad-deep.rs @@ -18,7 +18,7 @@ struct Fat { } pub fn main() { - let f: Fat<[isize; 3]> = Fat { ptr: [5i, 6, 7] }; + let f: Fat<[isize; 3]> = Fat { ptr: [5is, 6, 7] }; let g: &Fat<[isize]> = &f; let h: &Fat> = &Fat { ptr: *g }; //~^ ERROR the trait `core::marker::Sized` is not implemented diff --git a/src/test/compile-fail/feature-gate-advanced-slice-features.rs b/src/test/compile-fail/feature-gate-advanced-slice-features.rs index 97d593d310e13..a37a8a326a66c 100644 --- a/src/test/compile-fail/feature-gate-advanced-slice-features.rs +++ b/src/test/compile-fail/feature-gate-advanced-slice-features.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = [ 1i, 2, 3, 4, 5 ]; + let x = [ 1is, 2, 3, 4, 5 ]; match x { [ xs.., 4, 5 ] => {} //~ ERROR multiple-element slice matches [ 1, xs.., 5 ] => {} //~ ERROR multiple-element slice matches diff --git a/src/test/compile-fail/feature-gate-int-uint.rs b/src/test/compile-fail/feature-gate-int-uint.rs index 0c730b5f593f7..94190cc15115d 100644 --- a/src/test/compile-fail/feature-gate-int-uint.rs +++ b/src/test/compile-fail/feature-gate-int-uint.rs @@ -16,7 +16,7 @@ mod u { x: usize //~ WARN the `usize` type is deprecated } fn bar(x: usize) { //~ WARN the `usize` type is deprecated - 1u; //~ WARN the `u` suffix on integers is deprecated + 1us; //~ WARN the `u` suffix on integers is deprecated } } mod i { @@ -25,7 +25,7 @@ mod i { x: isize //~ WARN the `isize` type is deprecated } fn bar(x: isize) { //~ WARN the `isize` type is deprecated - 1i; //~ WARN the `u` suffix on integers is deprecated + 1is; //~ WARN the `u` suffix on integers is deprecated } } diff --git a/src/test/compile-fail/fn-trait-formatting.rs b/src/test/compile-fail/fn-trait-formatting.rs index 723192952f2ee..3f5a92605b7e9 100644 --- a/src/test/compile-fail/fn-trait-formatting.rs +++ b/src/test/compile-fail/fn-trait-formatting.rs @@ -21,5 +21,5 @@ fn main() { let _: () = (box |&mut:| -> isize unimplemented!()) as Box isize>; //~^ ERROR Box isize> - needs_fn(1i); //~ ERROR `core::ops::Fn(isize) -> isize` + needs_fn(1is); //~ ERROR `core::ops::Fn(isize) -> isize` } diff --git a/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs b/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs index 8de613ac03d0f..c381fcf3efb06 100644 --- a/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs +++ b/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs @@ -11,6 +11,6 @@ fn main() { for - &1i //~ ERROR refutable pattern in `for` loop binding - in [1i].iter() {} + &1is //~ ERROR refutable pattern in `for` loop binding + in [1is].iter() {} } diff --git a/src/test/compile-fail/hashmap-iter-value-lifetime.rs b/src/test/compile-fail/hashmap-iter-value-lifetime.rs index d9d7705fef6fb..db1e1e8efe42f 100644 --- a/src/test/compile-fail/hashmap-iter-value-lifetime.rs +++ b/src/test/compile-fail/hashmap-iter-value-lifetime.rs @@ -10,7 +10,7 @@ fn main() { let mut my_stuff = std::collections::HashMap::new(); - my_stuff.insert(0i, 42i); + my_stuff.insert(0is, 42is); let (_, thing) = my_stuff.iter().next().unwrap(); diff --git a/src/test/compile-fail/hashmap-lifetimes.rs b/src/test/compile-fail/hashmap-lifetimes.rs index edd57477d7699..40673dd92b89d 100644 --- a/src/test/compile-fail/hashmap-lifetimes.rs +++ b/src/test/compile-fail/hashmap-lifetimes.rs @@ -10,7 +10,7 @@ fn main() { let mut my_stuff = std::collections::HashMap::new(); - my_stuff.insert(0i, 42i); + my_stuff.insert(0is, 42is); let mut it = my_stuff.iter(); my_stuff.insert(1, 43); //~ ERROR cannot borrow diff --git a/src/test/compile-fail/if-let.rs b/src/test/compile-fail/if-let.rs index 971f643c0fe91..d83779c4f0f0c 100644 --- a/src/test/compile-fail/if-let.rs +++ b/src/test/compile-fail/if-let.rs @@ -20,20 +20,20 @@ fn macros() { }} } - foo!(a, 1i, { //~ ERROR irrefutable if-let + foo!(a, 1is, { //~ ERROR irrefutable if-let println!("irrefutable pattern"); }); - bar!(a, 1i, { //~ ERROR irrefutable if-let + bar!(a, 1is, { //~ ERROR irrefutable if-let println!("irrefutable pattern"); }); } pub fn main() { - if let a = 1i { //~ ERROR irrefutable if-let + if let a = 1is { //~ ERROR irrefutable if-let println!("irrefutable pattern"); } - if let a = 1i { //~ ERROR irrefutable if-let + if let a = 1is { //~ ERROR irrefutable if-let println!("irrefutable pattern"); } else if true { println!("else-if in irrefutable if-let"); @@ -41,15 +41,15 @@ pub fn main() { println!("else in irrefutable if-let"); } - if let 1i = 2i { + if let 1is = 2is { println!("refutable pattern"); - } else if let a = 1i { //~ ERROR irrefutable if-let + } else if let a = 1is { //~ ERROR irrefutable if-let println!("irrefutable pattern"); } if true { println!("if"); - } else if let a = 1i { //~ ERROR irrefutable if-let + } else if let a = 1is { //~ ERROR irrefutable if-let println!("irrefutable pattern"); } } diff --git a/src/test/compile-fail/implicit-method-bind.rs b/src/test/compile-fail/implicit-method-bind.rs index 34367f06793fc..d329f72f788ae 100644 --- a/src/test/compile-fail/implicit-method-bind.rs +++ b/src/test/compile-fail/implicit-method-bind.rs @@ -11,5 +11,5 @@ use std::num::SignedInt; fn main() { - let _f = 10i.abs; //~ ERROR attempted to take value of method + let _f = 10is.abs; //~ ERROR attempted to take value of method } diff --git a/src/test/compile-fail/import-glob-circular.rs b/src/test/compile-fail/import-glob-circular.rs index 37c2d2ffdc57f..0f6e3dc134d9b 100644 --- a/src/test/compile-fail/import-glob-circular.rs +++ b/src/test/compile-fail/import-glob-circular.rs @@ -13,13 +13,13 @@ mod circ1 { pub use circ2::f2; pub fn f1() { println!("f1"); } - pub fn common() -> usize { return 0u; } + pub fn common() -> usize { return 0us; } } mod circ2 { pub use circ1::f1; pub fn f2() { println!("f2"); } - pub fn common() -> usize { return 1u; } + pub fn common() -> usize { return 1us; } } mod test { diff --git a/src/test/compile-fail/index-bot.rs b/src/test/compile-fail/index-bot.rs index bd01d45fd44ec..876c1e481f604 100644 --- a/src/test/compile-fail/index-bot.rs +++ b/src/test/compile-fail/index-bot.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - (return)[0u]; //~ ERROR the type of this value must be known in this context + (return)[0us]; //~ ERROR the type of this value must be known in this context } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 514557a96a4b3..a922f5fe4527e 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -28,11 +28,11 @@ impl to_opt for Option { } fn function(counter: usize, t: T) { - if counter > 0u { - function(counter - 1u, t.to_option()); + if counter > 0us { + function(counter - 1us, t.to_option()); } } fn main() { - function(22u, 22u); + function(22us, 22us); } diff --git a/src/test/compile-fail/integral-indexing.rs b/src/test/compile-fail/integral-indexing.rs index 08a8f72a6686d..ef651dd9ce729 100644 --- a/src/test/compile-fail/integral-indexing.rs +++ b/src/test/compile-fail/integral-indexing.rs @@ -11,7 +11,7 @@ pub fn main() { let v: Vec = vec!(0, 1, 2, 3, 4, 5); let s: String = "abcdef".to_string(); - v.as_slice()[3u]; + v.as_slice()[3us]; v.as_slice()[3]; v.as_slice()[3u8]; //~ERROR the trait `core::ops::Index` is not implemented //~^ ERROR the trait `core::ops::Index` is not implemented @@ -21,7 +21,7 @@ pub fn main() { //~^ ERROR the trait `core::ops::Index` is not implemented v.as_slice()[3i32]; //~ERROR the trait `core::ops::Index` is not implemented //~^ ERROR the trait `core::ops::Index` is not implemented - s.as_bytes()[3u]; + s.as_bytes()[3us]; s.as_bytes()[3]; s.as_bytes()[3u8]; //~ERROR the trait `core::ops::Index` is not implemented //~^ERROR the trait `core::ops::Index` is not implemented diff --git a/src/test/compile-fail/issue-10398.rs b/src/test/compile-fail/issue-10398.rs index 11c577f9dc38d..c1102bc84aba7 100644 --- a/src/test/compile-fail/issue-10398.rs +++ b/src/test/compile-fail/issue-10398.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] fn main() { - let x = box 1i; + let x = box 1is; let f = move|:| { let _a = x; drop(x); diff --git a/src/test/compile-fail/issue-11493.rs b/src/test/compile-fail/issue-11493.rs index 7856a5dcf7f2e..895eb4cf96f43 100644 --- a/src/test/compile-fail/issue-11493.rs +++ b/src/test/compile-fail/issue-11493.rs @@ -11,6 +11,6 @@ // This file must never have a trailing newline fn main() { - let x = Some(3i); - let y = x.as_ref().unwrap_or(&5i); //~ ERROR: borrowed value does not live long enough + let x = Some(3is); + let y = x.as_ref().unwrap_or(&5is); //~ ERROR: borrowed value does not live long enough } diff --git a/src/test/compile-fail/issue-11714.rs b/src/test/compile-fail/issue-11714.rs index dd3fad978eb59..eef035d3d9445 100644 --- a/src/test/compile-fail/issue-11714.rs +++ b/src/test/compile-fail/issue-11714.rs @@ -9,7 +9,7 @@ // except according to those terms. fn blah() -> isize { //~ ERROR not all control paths return a value - 1i + 1is ; //~ HELP consider removing this semicolon: } diff --git a/src/test/compile-fail/issue-11873.rs b/src/test/compile-fail/issue-11873.rs index 8966793753153..67578de89226e 100644 --- a/src/test/compile-fail/issue-11873.rs +++ b/src/test/compile-fail/issue-11873.rs @@ -9,8 +9,8 @@ // except according to those terms. fn main() { - let mut v = vec!(1i); - let mut f = |&mut:| v.push(2i); + let mut v = vec!(1is); + let mut f = |&mut:| v.push(2is); let _w = v; //~ ERROR: cannot move out of `v` f(); diff --git a/src/test/compile-fail/issue-11925.rs b/src/test/compile-fail/issue-11925.rs index 71e4598d63560..e5f3b7d62d386 100644 --- a/src/test/compile-fail/issue-11925.rs +++ b/src/test/compile-fail/issue-11925.rs @@ -12,7 +12,7 @@ fn main() { let r = { - let x = box 42i; + let x = box 42is; let f = move|:| &x; //~ ERROR: `x` does not live long enough f() }; diff --git a/src/test/compile-fail/issue-12041.rs b/src/test/compile-fail/issue-12041.rs index 094f6d64edc2e..02c19204f79ff 100644 --- a/src/test/compile-fail/issue-12041.rs +++ b/src/test/compile-fail/issue-12041.rs @@ -17,7 +17,7 @@ fn main() { loop { let tx = tx; //~^ ERROR: use of moved value: `tx` - tx.send(1i); + tx.send(1is); } }); } diff --git a/src/test/compile-fail/issue-13058.rs b/src/test/compile-fail/issue-13058.rs index 8f50786405283..eee82483cae1d 100644 --- a/src/test/compile-fail/issue-13058.rs +++ b/src/test/compile-fail/issue-13058.rs @@ -34,6 +34,6 @@ fn check<'r, I: Iterator, T: Itble<'r, usize, I>>(cont: &T) -> bool } fn main() { - check((3u, 5u)); + check((3us, 5us)); //~^ ERROR mismatched types: expected `&_`, found `(usize, usize)` (expected &-ptr, found tuple) } diff --git a/src/test/compile-fail/issue-13482-2.rs b/src/test/compile-fail/issue-13482-2.rs index ef7d3d4d158d9..5c9b0473cea13 100644 --- a/src/test/compile-fail/issue-13482-2.rs +++ b/src/test/compile-fail/issue-13482-2.rs @@ -14,7 +14,7 @@ fn main() { let x = [1,2]; let y = match x { [] => None, - //~^ ERROR types: expected `[_#0i; 2]`, found `[_#7t; 0]` + //~^ ERROR types: expected `[_#0is; 2]`, found `[_#7t; 0]` // (expected array of 2 elements, found array of 0 elements) [a,_] => Some(a) }; diff --git a/src/test/compile-fail/issue-1362.rs b/src/test/compile-fail/issue-1362.rs index 64c503376d561..28d16f9c0b787 100644 --- a/src/test/compile-fail/issue-1362.rs +++ b/src/test/compile-fail/issue-1362.rs @@ -11,7 +11,7 @@ // Regression test for issue #1362 - without that fix the span will be bogus // no-reformat fn main() { - let x: usize = 20i; //~ ERROR mismatched types + let x: usize = 20is; //~ ERROR mismatched types } // NOTE: Do not add any extra lines as the line number the error is // on is significant; an error later in the source file might not diff --git a/src/test/compile-fail/issue-1448-2.rs b/src/test/compile-fail/issue-1448-2.rs index 72803ea9ad188..371adf931b066 100644 --- a/src/test/compile-fail/issue-1448-2.rs +++ b/src/test/compile-fail/issue-1448-2.rs @@ -13,5 +13,5 @@ fn foo(a: usize) -> usize { a } fn main() { - println!("{}", foo(10i)); //~ ERROR mismatched types + println!("{}", foo(10is)); //~ ERROR mismatched types } diff --git a/src/test/compile-fail/issue-15094.rs b/src/test/compile-fail/issue-15094.rs index 5292848f8ee45..5b33069b59502 100644 --- a/src/test/compile-fail/issue-15094.rs +++ b/src/test/compile-fail/issue-15094.rs @@ -28,6 +28,6 @@ fn make_shower(x: T) -> Shower { } pub fn main() { - let show3 = make_shower(3i); + let show3 = make_shower(3is); show3(); } diff --git a/src/test/compile-fail/issue-15167.rs b/src/test/compile-fail/issue-15167.rs index d4de4e177f026..630c35d6a4fbc 100644 --- a/src/test/compile-fail/issue-15167.rs +++ b/src/test/compile-fail/issue-15167.rs @@ -18,7 +18,7 @@ macro_rules! f { () => (n) } fn main() -> (){ - for n in range(0i, 1) { + for n in range(0is, 1) { println!("{}", f!()); //~ ERROR unresolved name `n` } } diff --git a/src/test/compile-fail/issue-15480.rs b/src/test/compile-fail/issue-15480.rs index abcc2eb1f98d3..59d87b5277a46 100644 --- a/src/test/compile-fail/issue-15480.rs +++ b/src/test/compile-fail/issue-15480.rs @@ -10,7 +10,7 @@ fn main() { let v = vec![ - &3i + &3is //~^ ERROR borrowed value does not live long enough ]; diff --git a/src/test/compile-fail/issue-17283.rs b/src/test/compile-fail/issue-17283.rs index 9f76feeaf0465..0c9fd9d9486d6 100644 --- a/src/test/compile-fail/issue-17283.rs +++ b/src/test/compile-fail/issue-17283.rs @@ -16,7 +16,7 @@ struct Foo { } fn main() { - let x = 1u; + let x = 1us; let y: Foo; // `x { ... }` should not be interpreted as a struct literal here diff --git a/src/test/compile-fail/issue-17385.rs b/src/test/compile-fail/issue-17385.rs index e7cab292ea7ef..38278c524c886 100644 --- a/src/test/compile-fail/issue-17385.rs +++ b/src/test/compile-fail/issue-17385.rs @@ -23,10 +23,10 @@ impl Drop for Enum { } fn main() { - let foo = X(1i); + let foo = X(1is); drop(foo); match foo { //~ ERROR use of moved value - X(1i) => (), + X(1is) => (), _ => unreachable!() } diff --git a/src/test/compile-fail/issue-17405.rs b/src/test/compile-fail/issue-17405.rs index cb541835fbb0d..63120e85b0973 100644 --- a/src/test/compile-fail/issue-17405.rs +++ b/src/test/compile-fail/issue-17405.rs @@ -13,7 +13,7 @@ enum Foo { } fn main() { - match Foo::Bar(1i) { + match Foo::Bar(1is) { Foo { i } => () //~ ERROR `Foo` does not name a struct or a struct variant } } diff --git a/src/test/compile-fail/issue-17441.rs b/src/test/compile-fail/issue-17441.rs index a28162159a510..e9e69dadd3b83 100644 --- a/src/test/compile-fail/issue-17441.rs +++ b/src/test/compile-fail/issue-17441.rs @@ -11,16 +11,16 @@ #![feature(box_syntax)] fn main() { - let _foo = &[1u, 2] as [usize]; + let _foo = &[1us, 2] as [usize]; //~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]` //~^^ HELP consider using an implicit coercion to `&[usize]` instead - let _bar = box 1u as std::fmt::Show; + let _bar = box 1us as std::fmt::Show; //~^ ERROR cast to unsized type: `Box` as `core::fmt::Show` //~^^ HELP did you mean `Box`? - let _baz = 1u as std::fmt::Show; + let _baz = 1us as std::fmt::Show; //~^ ERROR cast to unsized type: `usize` as `core::fmt::Show` //~^^ HELP consider using a box or reference as appropriate - let _quux = [1u, 2] as [usize]; + let _quux = [1us, 2] as [usize]; //~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]` //~^^ HELP consider using a box or reference as appropriate } diff --git a/src/test/compile-fail/issue-17718-patterns.rs b/src/test/compile-fail/issue-17718-patterns.rs index ab95606da4445..6c4d087470382 100644 --- a/src/test/compile-fail/issue-17718-patterns.rs +++ b/src/test/compile-fail/issue-17718-patterns.rs @@ -13,7 +13,7 @@ static mut A2: usize = 1; const A3: usize = 1; fn main() { - match 1u { + match 1us { A1 => {} //~ ERROR: static variables cannot be referenced in a pattern A2 => {} //~ ERROR: static variables cannot be referenced in a pattern A3 => {} diff --git a/src/test/compile-fail/issue-17800.rs b/src/test/compile-fail/issue-17800.rs index 9590ef3dab48c..89611e4f3fe78 100644 --- a/src/test/compile-fail/issue-17800.rs +++ b/src/test/compile-fail/issue-17800.rs @@ -14,8 +14,8 @@ enum MyOption { } fn main() { - match MyOption::MySome(42i) { - MyOption::MySome { x: 42i } => (), + match MyOption::MySome(42is) { + MyOption::MySome { x: 42is } => (), //~^ ERROR `MyOption::MySome` does not name a struct or a struct variant _ => (), } diff --git a/src/test/compile-fail/issue-17913.rs b/src/test/compile-fail/issue-17913.rs index e2dbad56f84f2..56cd544b3c605 100644 --- a/src/test/compile-fail/issue-17913.rs +++ b/src/test/compile-fail/issue-17913.rs @@ -15,14 +15,14 @@ #[cfg(any(all(stage0, target_word_size = "64"), all(not(stage0), target_pointer_width = "64")))] fn main() { - let n = 0u; - let a = box [&n; 0xF000000000000000u]; + let n = 0us; + let a = box [&n; 0xF000000000000000us]; println!("{}", a[0xFFFFFFu]); } #[cfg(any(all(stage0, target_word_size = "32"), all(not(stage0), target_pointer_width = "32")))] fn main() { - let n = 0u; + let n = 0us; let a = box [&n; 0xFFFFFFFFu]; println!("{}", a[0xFFFFFFu]); } diff --git a/src/test/compile-fail/issue-17933.rs b/src/test/compile-fail/issue-17933.rs index 1a490245cfc4d..47f8d75250d63 100644 --- a/src/test/compile-fail/issue-17933.rs +++ b/src/test/compile-fail/issue-17933.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub static X: usize = 1u; +pub static X: usize = 1us; fn main() { - match 1u { + match 1us { self::X => { }, //~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead _ => { }, diff --git a/src/test/compile-fail/issue-17999.rs b/src/test/compile-fail/issue-17999.rs index e3ad2dd1b067b..5726960f66a1c 100644 --- a/src/test/compile-fail/issue-17999.rs +++ b/src/test/compile-fail/issue-17999.rs @@ -11,7 +11,7 @@ #![deny(unused_variables)] fn main() { - for _ in range(1i, 101) { + for _ in range(1is, 101) { let x = (); //~ ERROR: unused variable: `x` match () { a => {} //~ ERROR: unused variable: `a` diff --git a/src/test/compile-fail/issue-18107.rs b/src/test/compile-fail/issue-18107.rs index b8249ebd4792c..83427e8aa67f9 100644 --- a/src/test/compile-fail/issue-18107.rs +++ b/src/test/compile-fail/issue-18107.rs @@ -16,7 +16,7 @@ fn _create_render(_: &()) -> AbstractRenderer //~^ ERROR: the trait `core::marker::Sized` is not implemented { - match 0u { + match 0us { _ => unimplemented!() } } diff --git a/src/test/compile-fail/issue-18252.rs b/src/test/compile-fail/issue-18252.rs index dd9626f74eccf..822c86d1d3e94 100644 --- a/src/test/compile-fail/issue-18252.rs +++ b/src/test/compile-fail/issue-18252.rs @@ -13,5 +13,5 @@ enum Foo { } fn main() { - let f = Foo::Variant(42u); //~ ERROR uses it like a function + let f = Foo::Variant(42us); //~ ERROR uses it like a function } diff --git a/src/test/compile-fail/issue-18566.rs b/src/test/compile-fail/issue-18566.rs index 17dc59dbc8d7d..85dda340d191e 100644 --- a/src/test/compile-fail/issue-18566.rs +++ b/src/test/compile-fail/issue-18566.rs @@ -28,7 +28,7 @@ impl Tr for usize { } fn main() { - let s = &mut 1u; + let s = &mut 1us; MyPtr(s).poke(s); //~^ ERROR cannot borrow `*s` as mutable more than once at a time diff --git a/src/test/compile-fail/issue-18783.rs b/src/test/compile-fail/issue-18783.rs index 657ef85233d5f..bed835d9bde8c 100644 --- a/src/test/compile-fail/issue-18783.rs +++ b/src/test/compile-fail/issue-18783.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; fn main() { let c = RefCell::new(vec![]); - let mut y = 1u; + let mut y = 1us; c.push(box || y = 0); c.push(box || y = 0); //~^ ERROR cannot borrow `y` as mutable more than once at a time @@ -22,7 +22,7 @@ fn main() { fn ufcs() { let c = RefCell::new(vec![]); - let mut y = 1u; + let mut y = 1us; Push::push(&c, box || y = 0); Push::push(&c, box || y = 0); diff --git a/src/test/compile-fail/issue-18959.rs b/src/test/compile-fail/issue-18959.rs index 7aba1bc8e65c7..e174fb9b7ad3e 100644 --- a/src/test/compile-fail/issue-18959.rs +++ b/src/test/compile-fail/issue-18959.rs @@ -17,7 +17,7 @@ impl Foo for Thing { fn foo(&self, _: &T) {} } -#[inline(never)] fn foo(b: &Bar) { b.foo(&0u) } +#[inline(never)] fn foo(b: &Bar) { b.foo(&0us) } fn main() { let mut thing = Thing; diff --git a/src/test/compile-fail/issue-19096.rs b/src/test/compile-fail/issue-19096.rs index 1e68de1f92338..7bc79463d3a95 100644 --- a/src/test/compile-fail/issue-19096.rs +++ b/src/test/compile-fail/issue-19096.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - let t = (42i, 42i); + let t = (42is, 42is); t.0::; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::` } diff --git a/src/test/compile-fail/issue-1962.rs b/src/test/compile-fail/issue-1962.rs index c59ee328eff40..44abfca165324 100644 --- a/src/test/compile-fail/issue-1962.rs +++ b/src/test/compile-fail/issue-1962.rs @@ -10,9 +10,9 @@ // compile-flags: -D while-true fn main() { - let mut i = 0i; + let mut i = 0is; while true { //~ ERROR denote infinite loops with loop - i += 1i; - if i == 5i { break; } + i += 1is; + if i == 5is { break; } } } diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 5ebc445bace26..f18db94acf33f 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -15,7 +15,7 @@ fn fail_len(v: Vec ) -> usize { let mut i = 3; panic!(); - for x in v.iter() { i += 1u; } + for x in v.iter() { i += 1us; } //~^ ERROR: unreachable statement return i; } diff --git a/src/test/compile-fail/issue-3707.rs b/src/test/compile-fail/issue-3707.rs index ad818cf9f8316..0aa357f239851 100644 --- a/src/test/compile-fail/issue-3707.rs +++ b/src/test/compile-fail/issue-3707.rs @@ -14,7 +14,7 @@ struct Obj { impl Obj { pub fn boom() -> bool { - return 1i+1 == 2 + return 1is+1 == 2 } pub fn chirp(&self) { self.boom(); //~ ERROR `&Obj` does not implement any method in scope named `boom` @@ -24,5 +24,5 @@ impl Obj { fn main() { let o = Obj { member: 0 }; o.chirp(); - 1i + 1; + 1is + 1; } diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index f35332a2f039e..292d1d9616a1d 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -18,6 +18,6 @@ fn f<'r, T>(v: &'r T) -> Box T + 'r> { } fn main() { - let v = &5i; + let v = &5is; println!("{}", f(v).call_mut(())); } diff --git a/src/test/compile-fail/issue-7575.rs b/src/test/compile-fail/issue-7575.rs index 0d5156956e566..49e54f25bf64b 100644 --- a/src/test/compile-fail/issue-7575.rs +++ b/src/test/compile-fail/issue-7575.rs @@ -30,17 +30,17 @@ trait UnusedTrait { impl CtxtFn for usize { fn f8(self, i: usize) -> usize { - i * 4u + i * 4us } fn f9(i: usize) -> usize { - i * 4u + i * 4us } } impl OtherTrait for usize { fn f9(i: usize) -> usize { - i * 8u + i * 8us } } diff --git a/src/test/compile-fail/kindck-impl-type-params-2.rs b/src/test/compile-fail/kindck-impl-type-params-2.rs index e188fa9b813fe..cd47bd721fcfd 100644 --- a/src/test/compile-fail/kindck-impl-type-params-2.rs +++ b/src/test/compile-fail/kindck-impl-type-params-2.rs @@ -19,7 +19,7 @@ impl Foo for T { fn take_param(foo: &T) { } fn main() { - let x = box 3i; + let x = box 3is; take_param(&x); //~^ ERROR the trait `core::marker::Copy` is not implemented } diff --git a/src/test/compile-fail/kindck-inherited-copy-bound.rs b/src/test/compile-fail/kindck-inherited-copy-bound.rs index 192e358283fa7..4ccb240071d04 100644 --- a/src/test/compile-fail/kindck-inherited-copy-bound.rs +++ b/src/test/compile-fail/kindck-inherited-copy-bound.rs @@ -23,12 +23,12 @@ impl Foo for T { fn take_param(foo: &T) { } fn a() { - let x = box 3i; + let x = box 3is; take_param(&x); //~ ERROR `core::marker::Copy` is not implemented } fn b() { - let x = box 3i; + let x = box 3is; let y = &x; let z = &x as &Foo; //~ ERROR `core::marker::Copy` is not implemented } diff --git a/src/test/compile-fail/kindck-nonsendable-1.rs b/src/test/compile-fail/kindck-nonsendable-1.rs index 172587dc1e4aa..79aec386d9a77 100644 --- a/src/test/compile-fail/kindck-nonsendable-1.rs +++ b/src/test/compile-fail/kindck-nonsendable-1.rs @@ -16,7 +16,7 @@ fn foo(_x: Rc) {} fn bar(_: F) { } fn main() { - let x = Rc::new(3u); + let x = Rc::new(3us); bar(move|| foo(x)); //~^ ERROR `core::marker::Send` is not implemented //~^^ ERROR `core::marker::Send` is not implemented diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index e55922db3d5fc..34c79be7118ba 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -90,7 +90,7 @@ pub fn pub_fn() { let e = used_enum::foo3; SemiUsedStruct::la_la_la(); - let i = 1i; + let i = 1is; match i { USED_STATIC => (), USED_CONST => (), diff --git a/src/test/compile-fail/lint-dead-code-3.rs b/src/test/compile-fail/lint-dead-code-3.rs index 3662855a72049..03b89c522ce8d 100644 --- a/src/test/compile-fail/lint-dead-code-3.rs +++ b/src/test/compile-fail/lint-dead-code-3.rs @@ -85,6 +85,6 @@ mod inner { } pub fn foo() { - let a = &1i as &inner::Trait; + let a = &1is as &inner::Trait; a.f(); } diff --git a/src/test/compile-fail/lint-dead-code-4.rs b/src/test/compile-fail/lint-dead-code-4.rs index bc2e0940f4471..ac8f158f8fb28 100644 --- a/src/test/compile-fail/lint-dead-code-4.rs +++ b/src/test/compile-fail/lint-dead-code-4.rs @@ -61,6 +61,6 @@ fn field_match_in_let(f: Bar) -> bool { fn main() { field_read(Foo { x: 1, b: false, marker: std::marker::NoCopy }); field_match_in_patterns(XYZ::Z); - field_match_in_let(Bar { x: 42u, b: true, _guard: () }); + field_match_in_let(Bar { x: 42us, b: true, _guard: () }); let _ = Baz { x: 0 }; } diff --git a/src/test/compile-fail/lint-exceeding-bitshifts.rs b/src/test/compile-fail/lint-exceeding-bitshifts.rs index 3d8d5b407fdf4..91a4d0fea0af4 100644 --- a/src/test/compile-fail/lint-exceeding-bitshifts.rs +++ b/src/test/compile-fail/lint-exceeding-bitshifts.rs @@ -56,7 +56,7 @@ fn main() { let n = 1u8 << (4+3); let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits - let n = 1i << std::isize::BITS; //~ ERROR: bitshift exceeds the type's number of bits - let n = 1u << std::usize::BITS; //~ ERROR: bitshift exceeds the type's number of bits + let n = 1is << std::isize::BITS; //~ ERROR: bitshift exceeds the type's number of bits + let n = 1us << std::usize::BITS; //~ ERROR: bitshift exceeds the type's number of bits } diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs index d5ea092617dc1..3224dec1c997d 100644 --- a/src/test/compile-fail/lint-type-limits.rs +++ b/src/test/compile-fail/lint-type-limits.rs @@ -14,7 +14,7 @@ fn main() { } fn foo() { - let mut i = 100u; + let mut i = 100us; while i >= 0 { //~ ERROR comparison is useless due to type limits i -= 1; } @@ -50,12 +50,12 @@ fn qux() { } fn quy() { - let i = -23u; //~ WARNING negation of unsigned isize literal may be unintentional + let i = -23us; //~ WARNING negation of unsigned isize literal may be unintentional //~^ WARNING unused variable } fn quz() { - let i = 23u; + let i = 23us; let j = -i; //~ WARNING negation of unsigned isize variable may be unintentional //~^ WARNING unused variable } diff --git a/src/test/compile-fail/lint-unnecessary-parens.rs b/src/test/compile-fail/lint-unnecessary-parens.rs index 158f13bf3f174..4ccc3d8b64151 100644 --- a/src/test/compile-fail/lint-unnecessary-parens.rs +++ b/src/test/compile-fail/lint-unnecessary-parens.rs @@ -17,7 +17,7 @@ impl X { } fn foo() -> isize { - return (1i); //~ ERROR unnecessary parentheses around `return` value + return (1is); //~ ERROR unnecessary parentheses around `return` value } fn bar() -> X { return (X { y: true }); //~ ERROR unnecessary parentheses around `return` value @@ -32,8 +32,8 @@ fn main() { match (true) { //~ ERROR unnecessary parentheses around `match` head expression _ => {} } - if let 1i = (1i) {} //~ ERROR unnecessary parentheses around `if let` head expression - while let 1i = (2i) {} //~ ERROR unnecessary parentheses around `while let` head expression + if let 1is = (1is) {} //~ ERROR unnecessary parentheses around `if let` head expression + while let 1is = (2is) {} //~ ERROR unnecessary parentheses around `while let` head expression let v = X { y: false }; // struct lits needs parens, so these shouldn't warn. if (v == X { y: true }) {} @@ -47,7 +47,7 @@ fn main() { _ => {} } - let mut _a = (0i); //~ ERROR unnecessary parentheses around assigned value - _a = (0i); //~ ERROR unnecessary parentheses around assigned value - _a += (1i); //~ ERROR unnecessary parentheses around assigned value + let mut _a = (0is); //~ ERROR unnecessary parentheses around assigned value + _a = (0is); //~ ERROR unnecessary parentheses around assigned value + _a += (1is); //~ ERROR unnecessary parentheses around assigned value } diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index a6d7c587c7bd5..84d7200314f9d 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -54,7 +54,7 @@ mod bar { pub mod c { use foo::Point; use foo::Square; //~ ERROR unused import - pub fn cc(p: Point) -> isize { return 2i * (p.x + p.y); } + pub fn cc(p: Point) -> isize { return 2is * (p.x + p.y); } } #[allow(unused_imports)] @@ -65,8 +65,8 @@ mod bar { fn main() { cal(foo::Point{x:3, y:9}); - let mut a = 3i; - let mut b = 4i; + let mut a = 3is; + let mut b = 4is; swap(&mut a, &mut b); test::C.b(); let _a = foo(); diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 4c1a01aac64c4..501eea770d814 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -18,16 +18,16 @@ fn main() { // negative cases - let mut a = 3i; //~ ERROR: variable does not need to be mutable - let mut a = 2i; //~ ERROR: variable does not need to be mutable - let mut b = 3i; //~ ERROR: variable does not need to be mutable - let mut a = vec!(3i); //~ ERROR: variable does not need to be mutable - let (mut a, b) = (1i, 2i); //~ ERROR: variable does not need to be mutable + let mut a = 3is; //~ ERROR: variable does not need to be mutable + let mut a = 2is; //~ ERROR: variable does not need to be mutable + let mut b = 3is; //~ ERROR: variable does not need to be mutable + let mut a = vec!(3is); //~ ERROR: variable does not need to be mutable + let (mut a, b) = (1is, 2is); //~ ERROR: variable does not need to be mutable - match 30i { + match 30is { mut x => {} //~ ERROR: variable does not need to be mutable } - match (30i, 2i) { + match (30is, 2is) { (mut x, 1) | //~ ERROR: variable does not need to be mutable (mut x, 2) | (mut x, 3) => { @@ -35,28 +35,28 @@ fn main() { _ => {} } - let x = |&: mut y: isize| 10i; //~ ERROR: variable does not need to be mutable + let x = |&: mut y: isize| 10is; //~ ERROR: variable does not need to be mutable fn what(mut foo: isize) {} //~ ERROR: variable does not need to be mutable // positive cases - let mut a = 2i; - a = 3i; + let mut a = 2is; + a = 3is; let mut a = Vec::new(); - a.push(3i); + a.push(3is); let mut a = Vec::new(); callback(|| { - a.push(3i); + a.push(3is); }); - let (mut a, b) = (1i, 2i); + let (mut a, b) = (1is, 2is); a = 34; - match 30i { + match 30is { mut x => { - x = 21i; + x = 21is; } } - match (30i, 2i) { + match (30is, 2is) { (mut x, 1) | (mut x, 2) | (mut x, 3) => { @@ -65,12 +65,12 @@ fn main() { _ => {} } - let x = |&mut: mut y: isize| y = 32i; - fn nothing(mut foo: isize) { foo = 37i; } + let x = |&mut: mut y: isize| y = 32is; + fn nothing(mut foo: isize) { foo = 37is; } // leading underscore should avoid the warning, just like the // unused variable lint. - let mut _allowed = 1i; + let mut _allowed = 1is; } fn callback(f: F) where F: FnOnce() {} @@ -78,6 +78,6 @@ fn callback(f: F) where F: FnOnce() {} // make sure the lint attribute can be turned off #[allow(unused_mut)] fn foo(mut a: isize) { - let mut a = 3i; - let mut b = vec!(2i); + let mut a = 3is; + let mut b = vec!(2is); } diff --git a/src/test/compile-fail/liveness-bad-bang-2.rs b/src/test/compile-fail/liveness-bad-bang-2.rs index c612a02336591..bb0491755942e 100644 --- a/src/test/compile-fail/liveness-bad-bang-2.rs +++ b/src/test/compile-fail/liveness-bad-bang-2.rs @@ -11,7 +11,7 @@ // Tests that a function with a ! annotation always actually fails fn bad_bang(i: usize) -> ! { //~ ERROR computation may converge in a function marked as diverging - println!("{}", 3i); + println!("{}", 3is); } -fn main() { bad_bang(5u); } +fn main() { bad_bang(5us); } diff --git a/src/test/compile-fail/liveness-return-last-stmt-semi.rs b/src/test/compile-fail/liveness-return-last-stmt-semi.rs index b274ad9f3d4ba..4b8f84ae70486 100644 --- a/src/test/compile-fail/liveness-return-last-stmt-semi.rs +++ b/src/test/compile-fail/liveness-return-last-stmt-semi.rs @@ -10,7 +10,7 @@ // // regression test for #8005 -macro_rules! test { () => { fn foo() -> isize { 1i; } } } +macro_rules! test { () => { fn foo() -> isize { 1is; } } } //~^ ERROR not all control paths return a value //~^^ HELP consider removing this semicolon diff --git a/src/test/compile-fail/liveness-unused.rs b/src/test/compile-fail/liveness-unused.rs index 0971709229bc5..c9f8230b6c5ae 100644 --- a/src/test/compile-fail/liveness-unused.rs +++ b/src/test/compile-fail/liveness-unused.rs @@ -29,40 +29,40 @@ fn f1d() { } fn f2() { - let x = 3i; + let x = 3is; //~^ ERROR unused variable: `x` } fn f3() { - let mut x = 3i; + let mut x = 3is; //~^ ERROR variable `x` is assigned to, but never used - x += 4i; + x += 4is; //~^ ERROR value assigned to `x` is never read } fn f3b() { - let mut z = 3i; + let mut z = 3is; //~^ ERROR variable `z` is assigned to, but never used loop { - z += 4i; + z += 4is; } } #[allow(unused_variables)] fn f3c() { - let mut z = 3i; - loop { z += 4i; } + let mut z = 3is; + loop { z += 4is; } } #[allow(unused_variables)] #[allow(unused_assignments)] fn f3d() { - let mut x = 3i; - x += 4i; + let mut x = 3is; + x += 4is; } fn f4() { - match Some(3i) { + match Some(3is) { Some(i) => { //~^ ERROR unused variable: `i` } @@ -75,7 +75,7 @@ enum tri { } fn f4b() -> isize { - match tri::a(3i) { + match tri::a(3is) { tri::a(i) | tri::b(i) | tri::c(i) => { i } @@ -83,17 +83,17 @@ fn f4b() -> isize { } fn f5a() { - for x in range(1i, 10) { } + for x in range(1is, 10) { } //~^ ERROR unused variable: `x` } fn f5b() { - for (x, _) in [1i, 2, 3].iter().enumerate() { } + for (x, _) in [1is, 2, 3].iter().enumerate() { } //~^ ERROR unused variable: `x` } fn f5c() { - for (_, x) in [1i, 2, 3].iter().enumerate() { + for (_, x) in [1is, 2, 3].iter().enumerate() { //~^ ERROR unused variable: `x` continue; std::os::set_exit_status(*x); //~ WARNING unreachable statement diff --git a/src/test/compile-fail/liveness-use-after-move.rs b/src/test/compile-fail/liveness-use-after-move.rs index e1cd12989cacd..21e52f130609d 100644 --- a/src/test/compile-fail/liveness-use-after-move.rs +++ b/src/test/compile-fail/liveness-use-after-move.rs @@ -11,7 +11,7 @@ #![feature(box_syntax)] fn main() { - let x = box 5i; + let x = box 5is; let y = x; println!("{}", *x); //~ ERROR use of moved value: `*x` y.clone(); diff --git a/src/test/compile-fail/loop-does-not-diverge.rs b/src/test/compile-fail/loop-does-not-diverge.rs index 9488e6bf969f0..e2d3d059ad815 100644 --- a/src/test/compile-fail/loop-does-not-diverge.rs +++ b/src/test/compile-fail/loop-does-not-diverge.rs @@ -14,7 +14,7 @@ fn forever() -> ! { loop { break; } - return 42i; //~ ERROR `return` in a function declared as diverging + return 42is; //~ ERROR `return` in a function declared as diverging } fn main() { diff --git a/src/test/compile-fail/macro-no-implicit-reexport.rs b/src/test/compile-fail/macro-no-implicit-reexport.rs index 4a427f121fcab..1e2172f4a7cff 100644 --- a/src/test/compile-fail/macro-no-implicit-reexport.rs +++ b/src/test/compile-fail/macro-no-implicit-reexport.rs @@ -16,5 +16,5 @@ extern crate macro_non_reexport_2; fn main() { - assert_eq!(reexported!(), 3u); //~ ERROR macro undefined + assert_eq!(reexported!(), 3us); //~ ERROR macro undefined } diff --git a/src/test/compile-fail/macro-reexport-not-locally-visible.rs b/src/test/compile-fail/macro-reexport-not-locally-visible.rs index c8e59f98d3cea..cf0d79e0fefd3 100644 --- a/src/test/compile-fail/macro-reexport-not-locally-visible.rs +++ b/src/test/compile-fail/macro-reexport-not-locally-visible.rs @@ -16,5 +16,5 @@ extern crate macro_reexport_1; fn main() { - assert_eq!(reexported!(), 3u); //~ ERROR macro undefined + assert_eq!(reexported!(), 3us); //~ ERROR macro undefined } diff --git a/src/test/compile-fail/match-ill-type1.rs b/src/test/compile-fail/match-ill-type1.rs index 2b4c77bf9e873..908d46f398ca7 100644 --- a/src/test/compile-fail/match-ill-type1.rs +++ b/src/test/compile-fail/match-ill-type1.rs @@ -10,7 +10,7 @@ fn main() { match 1 { - 1...2u => 1, //~ ERROR mismatched types in range + 1...2us => 1, //~ ERROR mismatched types in range _ => 2, }; } diff --git a/src/test/compile-fail/match-ill-type2.rs b/src/test/compile-fail/match-ill-type2.rs index 17f02abc8ec89..6b6954101b246 100644 --- a/src/test/compile-fail/match-ill-type2.rs +++ b/src/test/compile-fail/match-ill-type2.rs @@ -9,9 +9,9 @@ // except according to those terms. fn main() { - match 1i { - 1i => 1i, - 2u => 1i, //~ ERROR mismatched types - _ => 2i, + match 1is { + 1is => 1is, + 2us => 1is, //~ ERROR mismatched types + _ => 2is, }; } diff --git a/src/test/compile-fail/match-non-exhaustive.rs b/src/test/compile-fail/match-non-exhaustive.rs index 20adbeebdf1d7..2aeccacb0f6ee 100644 --- a/src/test/compile-fail/match-non-exhaustive.rs +++ b/src/test/compile-fail/match-non-exhaustive.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - match 0i { 1i => () } //~ ERROR non-exhaustive patterns - match 0i { 0i if false => () } //~ ERROR non-exhaustive patterns + match 0is { 1is => () } //~ ERROR non-exhaustive patterns + match 0is { 0is if false => () } //~ ERROR non-exhaustive patterns } diff --git a/src/test/compile-fail/match-range-fail-dominate.rs b/src/test/compile-fail/match-range-fail-dominate.rs index 7a4451f99ab0c..7d33963003ffc 100644 --- a/src/test/compile-fail/match-range-fail-dominate.rs +++ b/src/test/compile-fail/match-range-fail-dominate.rs @@ -15,21 +15,21 @@ //error-pattern: unreachable fn main() { - match 5u { - 1u ... 10u => { } - 5u ... 6u => { } + match 5us { + 1us ... 10us => { } + 5us ... 6us => { } _ => {} }; - match 5u { - 3u ... 6u => { } - 4u ... 6u => { } + match 5us { + 3us ... 6us => { } + 4us ... 6us => { } _ => {} }; - match 5u { - 4u ... 6u => { } - 4u ... 6u => { } + match 5us { + 4us ... 6us => { } + 4us ... 6us => { } _ => {} }; diff --git a/src/test/compile-fail/match-range-fail.rs b/src/test/compile-fail/match-range-fail.rs index 9fbd1545fcf67..1c804b0552cc9 100644 --- a/src/test/compile-fail/match-range-fail.rs +++ b/src/test/compile-fail/match-range-fail.rs @@ -13,8 +13,8 @@ //error-pattern: mismatched types fn main() { - match 5u { - 6u ... 1u => { } + match 5us { + 6us ... 1us => { } _ => { } }; @@ -22,8 +22,8 @@ fn main() { "bar" ... "foo" => { } }; - match 5u { - 'c' ... 100u => { } + match 5us { + 'c' ... 100us => { } _ => { } }; } diff --git a/src/test/compile-fail/match-vec-fixed.rs b/src/test/compile-fail/match-vec-fixed.rs index bac9fef2b1777..c35dc8d7c86eb 100644 --- a/src/test/compile-fail/match-vec-fixed.rs +++ b/src/test/compile-fail/match-vec-fixed.rs @@ -9,7 +9,7 @@ // except according to those terms. fn a() { - let v = [1i, 2, 3]; + let v = [1is, 2, 3]; match v { [_, _, _] => {} [_, _, _] => {} //~ ERROR unreachable pattern diff --git a/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs b/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs index 91d1e73e232ab..cab6a8610bfb3 100644 --- a/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs +++ b/src/test/compile-fail/method-ambig-two-traits-cross-crate.rs @@ -18,5 +18,5 @@ trait me2 { fn me(&self) -> usize; } impl me2 for usize { fn me(&self) -> usize { *self } } -fn main() { 1u.me(); } //~ ERROR E0034 +fn main() { 1us.me(); } //~ ERROR E0034 diff --git a/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs b/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs index dc5f1023b9964..87e3655d31e1a 100644 --- a/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs +++ b/src/test/compile-fail/method-ambig-two-traits-with-default-method.rs @@ -19,5 +19,5 @@ impl Foo for usize {} impl Bar for usize {} fn main() { - 1u.method(); //~ ERROR E0034 + 1us.method(); //~ ERROR E0034 } diff --git a/src/test/compile-fail/method-missing-call.rs b/src/test/compile-fail/method-missing-call.rs index 83418cbc104cb..899c1ef16a665 100644 --- a/src/test/compile-fail/method-missing-call.rs +++ b/src/test/compile-fail/method-missing-call.rs @@ -33,7 +33,7 @@ fn main() { //~^ HELP maybe a `()` to call it is missing // Ensure the span is useful - let ys = &[1i,2,3,4,5,6,7]; + let ys = &[1is,2,3,4,5,6,7]; let a = ys.iter() .map(|x| x) .filter(|&&x| x == 1) diff --git a/src/test/compile-fail/move-out-of-tuple-field.rs b/src/test/compile-fail/move-out-of-tuple-field.rs index ca09d43d79c9d..ace6c80e3e3ee 100644 --- a/src/test/compile-fail/move-out-of-tuple-field.rs +++ b/src/test/compile-fail/move-out-of-tuple-field.rs @@ -13,11 +13,11 @@ struct Foo(Box); fn main() { - let x = (box 1i,); + let x = (box 1is,); let y = x.0; let z = x.0; //~ ERROR use of moved value: `x.0` - let x = Foo(box 1i); + let x = Foo(box 1is); let y = x.0; let z = x.0; //~ ERROR use of moved value: `x.0` } diff --git a/src/test/compile-fail/moves-based-on-type-exprs.rs b/src/test/compile-fail/moves-based-on-type-exprs.rs index d8d84e558a947..58f1f78fa5d6d 100644 --- a/src/test/compile-fail/moves-based-on-type-exprs.rs +++ b/src/test/compile-fail/moves-based-on-type-exprs.rs @@ -24,13 +24,13 @@ fn f10() { fn f20() { let x = "hi".to_string(); - let _y = (x, 3i); + let _y = (x, 3is); touch(&x); //~ ERROR use of moved value: `x` } fn f21() { - let x = vec!(1i, 2, 3); - let _y = (x[0], 3i); + let x = vec!(1is, 2, 3); + let _y = (x[0], 3is); touch(&x); } @@ -61,9 +61,9 @@ fn f50(cond: bool) { let x = "hi".to_string(); let y = "ho".to_string(); let _y = match cond { - _ if guard(x) => 10i, - true => 10i, - false => 20i, + _ if guard(x) => 10is, + true => 10is, + false => 20is, }; touch(&x); //~ ERROR use of moved value: `x` touch(&y); diff --git a/src/test/compile-fail/mut-cant-alias.rs b/src/test/compile-fail/mut-cant-alias.rs index ce6e793d55d4d..847a3eaf8a1e7 100644 --- a/src/test/compile-fail/mut-cant-alias.rs +++ b/src/test/compile-fail/mut-cant-alias.rs @@ -11,7 +11,7 @@ use std::cell::RefCell; fn main() { - let m = RefCell::new(0i); + let m = RefCell::new(0is); let mut b = m.borrow_mut(); let b1 = &mut *b; let b2 = &mut *b; //~ ERROR cannot borrow diff --git a/src/test/compile-fail/mut-cross-borrowing.rs b/src/test/compile-fail/mut-cross-borrowing.rs index ee4d11c96cacf..7fb5c2ac4a4ff 100644 --- a/src/test/compile-fail/mut-cross-borrowing.rs +++ b/src/test/compile-fail/mut-cross-borrowing.rs @@ -13,7 +13,7 @@ fn f(_: &mut isize) {} fn main() { - let mut x = box 3i; + let mut x = box 3is; f(x) //~ ERROR mismatched types } diff --git a/src/test/compile-fail/mut-not-freeze.rs b/src/test/compile-fail/mut-not-freeze.rs index d7529c86aa528..8c39320276a16 100644 --- a/src/test/compile-fail/mut-not-freeze.rs +++ b/src/test/compile-fail/mut-not-freeze.rs @@ -13,7 +13,7 @@ use std::cell::RefCell; fn f(_: T) {} fn main() { - let x = RefCell::new(0i); + let x = RefCell::new(0is); f(x); //~^ ERROR `core::marker::Sync` is not implemented //~^^ ERROR `core::marker::Sync` is not implemented diff --git a/src/test/compile-fail/mut-pattern-internal-mutability.rs b/src/test/compile-fail/mut-pattern-internal-mutability.rs index 05c6c4a96557c..92f02114a1360 100644 --- a/src/test/compile-fail/mut-pattern-internal-mutability.rs +++ b/src/test/compile-fail/mut-pattern-internal-mutability.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let foo = &mut 1i; + let foo = &mut 1is; let &mut x = foo; x += 1; //~ ERROR re-assignment of immutable variable diff --git a/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs b/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs index e269a736ce257..74b561c37aacb 100644 --- a/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs +++ b/src/test/compile-fail/mut-ptr-cant-outlive-ref.rs @@ -11,7 +11,7 @@ use std::cell::RefCell; fn main() { - let m = RefCell::new(0i); + let m = RefCell::new(0is); let p; { let b = m.borrow(); diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 708affe30f34a..932c2a9715ff4 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -29,6 +29,6 @@ fn cat(in_x : usize, in_y : isize) -> cat { } fn main() { - let nyan : cat = cat(52u, 99); + let nyan : cat = cat(52us, 99); nyan.eat(); } diff --git a/src/test/compile-fail/mutable-class-fields.rs b/src/test/compile-fail/mutable-class-fields.rs index 15046c4c51be0..a840ac63dd8e9 100644 --- a/src/test/compile-fail/mutable-class-fields.rs +++ b/src/test/compile-fail/mutable-class-fields.rs @@ -21,6 +21,6 @@ fn cat(in_x : usize, in_y : isize) -> cat { } fn main() { - let nyan : cat = cat(52u, 99); + let nyan : cat = cat(52us, 99); nyan.how_hungry = 0; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 3d4d0fee0bfe2..beb0d0ee47e2f 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -14,7 +14,7 @@ use std::sync::Arc; use std::thread::Thread; fn main() { - let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10); + let v = vec!(1is, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); Thread::spawn(move|| { diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index 02028fe62e5eb..d8f0fa497a4f3 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use std::thread::Thread; fn main() { - let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10); + let v = vec!(1is, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); Thread::spawn(move|| { diff --git a/src/test/compile-fail/no_send-rc.rs b/src/test/compile-fail/no_send-rc.rs index 95855ed584bc9..82cc319466a6d 100644 --- a/src/test/compile-fail/no_send-rc.rs +++ b/src/test/compile-fail/no_send-rc.rs @@ -13,7 +13,7 @@ use std::rc::Rc; fn bar(_: T) {} fn main() { - let x = Rc::new(5i); + let x = Rc::new(5is); bar(x); //~^ ERROR `core::marker::Send` is not implemented //~^^ ERROR `core::marker::Send` is not implemented diff --git a/src/test/compile-fail/no_share-rc.rs b/src/test/compile-fail/no_share-rc.rs index 0f3573e0ad5a9..0d3e380d4a122 100644 --- a/src/test/compile-fail/no_share-rc.rs +++ b/src/test/compile-fail/no_share-rc.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; fn bar(_: T) {} fn main() { - let x = Rc::new(RefCell::new(5i)); + let x = Rc::new(RefCell::new(5is)); bar(x); //~^ ERROR the trait `core::marker::Sync` is not implemented //~^^ ERROR the trait `core::marker::Sync` is not implemented diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs index 4c421a689ee39..ccf69a4d2c8b1 100644 --- a/src/test/compile-fail/non-exhaustive-match.rs +++ b/src/test/compile-fail/non-exhaustive-match.rs @@ -16,10 +16,10 @@ fn main() { match true { //~ ERROR non-exhaustive patterns: `false` not covered true => {} } - match Some(10i) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered + match Some(10is) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered None => {} } - match (2i, 3i, 4i) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered + match (2is, 3is, 4is) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered (_, _, 4) => {} } match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered @@ -35,14 +35,14 @@ fn main() { (_, t::a) => {} (t::b, t::b) => {} } - let vec = vec!(Some(42i), None, Some(21i)); + let vec = vec!(Some(42is), None, Some(21is)); let vec: &[Option] = vec.as_slice(); match vec { //~ ERROR non-exhaustive patterns: `[]` not covered [Some(..), None, tail..] => {} [Some(..), Some(..), tail..] => {} [None] => {} } - let vec = vec!(1i); + let vec = vec!(1is); let vec: &[isize] = vec.as_slice(); match vec { [_, tail..] => (), @@ -56,7 +56,7 @@ fn main() { [0.1] => (), [] => () } - let vec = vec!(Some(42i), None, Some(21i)); + let vec = vec!(Some(42is), None, Some(21is)); let vec: &[Option] = vec.as_slice(); match vec { [Some(..), None, tail..] => {} diff --git a/src/test/compile-fail/non-exhaustive-pattern-witness.rs b/src/test/compile-fail/non-exhaustive-pattern-witness.rs index 7442900c9b778..3bd3a0c653ca1 100644 --- a/src/test/compile-fail/non-exhaustive-pattern-witness.rs +++ b/src/test/compile-fail/non-exhaustive-pattern-witness.rs @@ -27,7 +27,7 @@ fn struct_with_a_nested_enum_and_vector() { Foo { first: true, second: None } => (), Foo { first: true, second: Some(_) } => (), Foo { first: false, second: None } => (), - Foo { first: false, second: Some([1u, 2u, 3u, 4u]) } => () + Foo { first: false, second: Some([1us, 2us, 3us, 4us]) } => () } } diff --git a/src/test/compile-fail/obsolete-tilde.rs b/src/test/compile-fail/obsolete-tilde.rs index 9c395406f0380..d290d5536a4a2 100644 --- a/src/test/compile-fail/obsolete-tilde.rs +++ b/src/test/compile-fail/obsolete-tilde.rs @@ -15,7 +15,7 @@ fn bar(x: ~str) {} //~ ERROR obsolete syntax: `~` notation for owned pointers fn baz(x: ~[isize]) {} //~ ERROR obsolete syntax: `~[T]` is no longer a type fn main() { - let x = ~4i; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation + let x = ~4is; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation let y = ~"hello"; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation - let z = ~[1i, 2, 3]; //~ ERROR obsolete syntax: `~[T]` is no longer a type + let z = ~[1is, 2, 3]; //~ ERROR obsolete syntax: `~[T]` is no longer a type } diff --git a/src/test/compile-fail/or-patter-mismatch.rs b/src/test/compile-fail/or-patter-mismatch.rs index f845d1e6344ec..74f674e64baf5 100644 --- a/src/test/compile-fail/or-patter-mismatch.rs +++ b/src/test/compile-fail/or-patter-mismatch.rs @@ -12,4 +12,4 @@ enum blah { a(isize, isize, usize), b(isize, isize), } -fn main() { match blah::a(1, 1, 2u) { blah::a(_, x, y) | blah::b(x, y) => { } } } +fn main() { match blah::a(1, 1, 2us) { blah::a(_, x, y) | blah::b(x, y) => { } } } diff --git a/src/test/compile-fail/pat-range-bad-dots.rs b/src/test/compile-fail/pat-range-bad-dots.rs index 7fe073a4c3d69..7f67d7a5fb19e 100644 --- a/src/test/compile-fail/pat-range-bad-dots.rs +++ b/src/test/compile-fail/pat-range-bad-dots.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - match 22i { + match 22is { 0 .. 3 => {} //~ ERROR expected one of `...`, `=>`, or `|`, found `..` _ => {} } diff --git a/src/test/compile-fail/pattern-bindings-after-at.rs b/src/test/compile-fail/pattern-bindings-after-at.rs index 54ac3cba636f2..70840200aad7d 100644 --- a/src/test/compile-fail/pattern-bindings-after-at.rs +++ b/src/test/compile-fail/pattern-bindings-after-at.rs @@ -14,7 +14,7 @@ enum Option { } fn main() { - match &mut Some(1i) { + match &mut Some(1is) { ref mut z @ &mut Some(ref a) => { //~^ ERROR pattern bindings are not allowed after an `@` **z = None; diff --git a/src/test/compile-fail/pptypedef.rs b/src/test/compile-fail/pptypedef.rs index b33b89be35d82..e3c440d61cec3 100644 --- a/src/test/compile-fail/pptypedef.rs +++ b/src/test/compile-fail/pptypedef.rs @@ -11,9 +11,9 @@ fn let_in(x: T, f: F) where F: FnOnce(T) {} fn main() { - let_in(3u, |i| { assert!(i == 3is); }); + let_in(3us, |i| { assert!(i == 3is); }); //~^ ERROR expected `usize`, found `isize` - let_in(3i, |i| { assert!(i == 3us); }); + let_in(3is, |i| { assert!(i == 3us); }); //~^ ERROR expected `isize`, found `usize` } diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index f897a2bc9f3ae..e8e26cf8ce33d 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -30,6 +30,6 @@ mod kitties { } fn main() { - let nyan : kitties::cat = kitties::cat(52u, 99); + let nyan : kitties::cat = kitties::cat(52us, 99); nyan.nap(); } diff --git a/src/test/compile-fail/private-struct-field-cross-crate.rs b/src/test/compile-fail/private-struct-field-cross-crate.rs index 45c4b2b7ae1b0..36b6000ceebe1 100644 --- a/src/test/compile-fail/private-struct-field-cross-crate.rs +++ b/src/test/compile-fail/private-struct-field-cross-crate.rs @@ -13,7 +13,7 @@ extern crate cci_class; use cci_class::kitties::cat; fn main() { - let nyan : cat = cat(52u, 99); - assert!((nyan.meows == 52u)); + let nyan : cat = cat(52us, 99); + assert!((nyan.meows == 52us)); //~^ ERROR field `meows` of struct `cci_class::kitties::cat` is private } diff --git a/src/test/compile-fail/ptr-coercion.rs b/src/test/compile-fail/ptr-coercion.rs index b7d122cd79d87..392a803b0dd9f 100644 --- a/src/test/compile-fail/ptr-coercion.rs +++ b/src/test/compile-fail/ptr-coercion.rs @@ -13,7 +13,7 @@ pub fn main() { // *const -> *mut - let x: *const isize = &42i; + let x: *const isize = &42is; let x: *mut isize = x; //~ERROR values differ in mutability // & -> *mut diff --git a/src/test/compile-fail/range-1.rs b/src/test/compile-fail/range-1.rs index 1668b868e641e..9888c0856953f 100644 --- a/src/test/compile-fail/range-1.rs +++ b/src/test/compile-fail/range-1.rs @@ -12,7 +12,7 @@ pub fn main() { // Mixed types. - let _ = 0u..10i; + let _ = 0us..10is; //~^ ERROR start and end of range have incompatible types // Float => does not implement iterator. @@ -20,7 +20,7 @@ pub fn main() { //~^ ERROR `for` loop expression has type `core::ops::Range` which does not implement // Unsized type. - let arr: &[_] = &[1u, 2, 3]; + let arr: &[_] = &[1us, 2, 3]; let range = (*arr)..; //~^ ERROR the trait `core::marker::Sized` is not implemented } diff --git a/src/test/compile-fail/range-2.rs b/src/test/compile-fail/range-2.rs index 40690bd844bce..6d176ca3700b9 100644 --- a/src/test/compile-fail/range-2.rs +++ b/src/test/compile-fail/range-2.rs @@ -12,7 +12,7 @@ pub fn main() { let r = { - (&42i)..&42 + (&42is)..&42 //~^ ERROR borrowed value does not live long enough //~^^ ERROR borrowed value does not live long enough }; diff --git a/src/test/compile-fail/refutable-pattern-errors.rs b/src/test/compile-fail/refutable-pattern-errors.rs index 54b8c7fe4b9be..d06c73c4cc039 100644 --- a/src/test/compile-fail/refutable-pattern-errors.rs +++ b/src/test/compile-fail/refutable-pattern-errors.rs @@ -13,6 +13,6 @@ fn func((1, (Some(1), 2...3)): (isize, (Option, isize))) { } //~^ ERROR refutable pattern in function argument: `(_, _)` not covered fn main() { - let (1i, (Some(1i), 2i...3i)) = (1i, (None, 2i)); + let (1is, (Some(1is), 2is...3is)) = (1is, (None, 2is)); //~^ ERROR refutable pattern in local binding: `(_, _)` not covered } diff --git a/src/test/compile-fail/regions-addr-of-self.rs b/src/test/compile-fail/regions-addr-of-self.rs index 6aeac1bd1b376..b69224d449957 100644 --- a/src/test/compile-fail/regions-addr-of-self.rs +++ b/src/test/compile-fail/regions-addr-of-self.rs @@ -15,18 +15,18 @@ struct dog { impl dog { pub fn chase_cat(&mut self) { let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer - *p += 1u; + *p += 1us; } pub fn chase_cat_2(&mut self) { let p: &mut usize = &mut self.cats_chased; - *p += 1u; + *p += 1us; } } fn dog() -> dog { dog { - cats_chased: 0u + cats_chased: 0us } } diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index 33898b2e782cb..fa76ab758ab56 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -18,7 +18,7 @@ impl dog { pub fn chase_cat(&mut self) { let _f = |&:| { let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer - *p = 3u; + *p = 3us; }; } } diff --git a/src/test/compile-fail/regions-close-over-type-parameter-2.rs b/src/test/compile-fail/regions-close-over-type-parameter-2.rs index 8d9bd92a8def2..543d4d1620b79 100644 --- a/src/test/compile-fail/regions-close-over-type-parameter-2.rs +++ b/src/test/compile-fail/regions-close-over-type-parameter-2.rs @@ -29,7 +29,7 @@ fn main() { // ~Repeat<&'blk isize> where blk is the lifetime of the block below. let _ = { - let tmp0 = 3i; + let tmp0 = 3is; let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough repeater3(tmp1) }; diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 2e7a4051ff221..83cef9397c30b 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -14,8 +14,8 @@ enum ast<'a> { } fn build() { - let x = ast::num(3u); - let y = ast::num(4u); + let x = ast::num(3us); + let y = ast::num(4us); let z = ast::add(&x, &y); compute(&z); } diff --git a/src/test/compile-fail/regions-escape-loop-via-variable.rs b/src/test/compile-fail/regions-escape-loop-via-variable.rs index 472df87dd2b0d..c300c86f70fca 100644 --- a/src/test/compile-fail/regions-escape-loop-via-variable.rs +++ b/src/test/compile-fail/regions-escape-loop-via-variable.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = 3i; + let x = 3is; // Here, the variable `p` gets inferred to a type with a lifetime // of the loop body. The regionck then determines that this type @@ -17,7 +17,7 @@ fn main() { let mut p = &x; loop { - let x = 1i + *p; + let x = 1is + *p; p = &x; //~ ERROR `x` does not live long enough } } diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index 22c6bdd2d504c..5e6e1858cf1c1 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -10,7 +10,7 @@ // The type of `y` ends up getting inferred to the type of the block. fn broken() { - let mut x = 3i; + let mut x = 3is; let mut _y = vec!(&mut x); while x < 10 { //~ ERROR cannot use `x` because it was mutably borrowed let mut z = x; //~ ERROR cannot use `x` because it was mutably borrowed diff --git a/src/test/compile-fail/regions-infer-proc-static-upvar.rs b/src/test/compile-fail/regions-infer-proc-static-upvar.rs index bf05554e6d0ec..4e99f64dbf7b3 100644 --- a/src/test/compile-fail/regions-infer-proc-static-upvar.rs +++ b/src/test/compile-fail/regions-infer-proc-static-upvar.rs @@ -16,7 +16,7 @@ fn foo(_p: F) { } static i: isize = 3; fn capture_local() { - let x = 3i; + let x = 3is; let y = &x; //~ ERROR `x` does not live long enough foo(move|| { let _a = *y; diff --git a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs index d7b2a45cc63bb..21586f78db342 100644 --- a/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs +++ b/src/test/compile-fail/regions-return-ref-to-upvar-issue-17403.rs @@ -15,7 +15,7 @@ fn main() { // Unboxed closure case { - let mut x = 0u; + let mut x = 0us; let mut f = |&mut:| &mut x; //~ ERROR cannot infer let x = f(); let y = f(); diff --git a/src/test/compile-fail/regions-steal-closure.rs b/src/test/compile-fail/regions-steal-closure.rs index 12f5f2954995f..583d9695be4cf 100644 --- a/src/test/compile-fail/regions-steal-closure.rs +++ b/src/test/compile-fail/regions-steal-closure.rs @@ -21,7 +21,7 @@ fn box_it<'r>(x: Box) -> closure_box<'r> { fn main() { let cl_box = { - let mut i = 3i; + let mut i = 3is; box_it(box || i += 1) //~ ERROR cannot infer }; cl_box.cl.call_mut(()); diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index d5ef9f3a9642e..63052580dc26d 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -34,7 +34,7 @@ fn get_v(gc: Box) -> usize { } fn main() { - let ctxt = ctxt { v: 22u }; + let ctxt = ctxt { v: 22us }; let hc = has_ctxt { c: &ctxt }; - assert_eq!(get_v(box hc as Box), 22u); + assert_eq!(get_v(box hc as Box), 22us); } diff --git a/src/test/compile-fail/regions-trait-2.rs b/src/test/compile-fail/regions-trait-2.rs index 0f298492e612e..8b36e87db3e53 100644 --- a/src/test/compile-fail/regions-trait-2.rs +++ b/src/test/compile-fail/regions-trait-2.rs @@ -26,7 +26,7 @@ impl<'a> get_ctxt for has_ctxt<'a> { } fn make_gc() -> @get_ctxt { - let ctxt = ctxt { v: 22u }; + let ctxt = ctxt { v: 22us }; let hc = has_ctxt { c: &ctxt }; return @hc as @get_ctxt; //~^ ERROR source contains reference diff --git a/src/test/compile-fail/regions-var-type-out-of-scope.rs b/src/test/compile-fail/regions-var-type-out-of-scope.rs index a954b16699fda..039de994ea32d 100644 --- a/src/test/compile-fail/regions-var-type-out-of-scope.rs +++ b/src/test/compile-fail/regions-var-type-out-of-scope.rs @@ -14,8 +14,8 @@ fn foo(cond: bool) { let mut x; if cond { - x = &3i; //~ ERROR borrowed value does not live long enough - assert_eq!(*x, 3i); + x = &3is; //~ ERROR borrowed value does not live long enough + assert_eq!(*x, 3is); } } diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index f851a8244f61e..e94bf19955bdc 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -24,6 +24,6 @@ fn main() { //~^ ERROR: expected `usize`, found `&'static str` let f = [0; -4]; //~^ ERROR expected positive integer for repeat count, found negative integer - let f = [0u; -1]; + let f = [0us; -1]; //~^ ERROR expected positive integer for repeat count, found negative integer } diff --git a/src/test/compile-fail/shadowed-lifetime.rs b/src/test/compile-fail/shadowed-lifetime.rs index a2a603a4b6a4b..57a2744d8f883 100644 --- a/src/test/compile-fail/shadowed-lifetime.rs +++ b/src/test/compile-fail/shadowed-lifetime.rs @@ -39,5 +39,5 @@ fn main() { // just to ensure that this test fails to compile; when shadowed // lifetimes become either an error or a proper lint, this will // not be needed. - let x: isize = 3u; //~ ERROR mismatched types + let x: isize = 3us; //~ ERROR mismatched types } diff --git a/src/test/compile-fail/static-assert2.rs b/src/test/compile-fail/static-assert2.rs index 6adc3b0aaf843..e988cfb9097ea 100644 --- a/src/test/compile-fail/static-assert2.rs +++ b/src/test/compile-fail/static-assert2.rs @@ -11,6 +11,6 @@ #![allow(dead_code)] #[static_assert] -static E: bool = 1i == 2; //~ ERROR static assertion failed +static E: bool = 1is == 2; //~ ERROR static assertion failed fn main() {} diff --git a/src/test/compile-fail/static-mut-not-pat.rs b/src/test/compile-fail/static-mut-not-pat.rs index d4170608559ec..bfdeff6ed7083 100644 --- a/src/test/compile-fail/static-mut-not-pat.rs +++ b/src/test/compile-fail/static-mut-not-pat.rs @@ -19,7 +19,7 @@ fn main() { // name as a variable, hence this should be an unreachable pattern situation // instead of spitting out a custom error about some identifier collisions // (we should allow shadowing) - match 4i { + match 4is { a => {} //~ ERROR static variables cannot be referenced in a pattern _ => {} } diff --git a/src/test/compile-fail/static-region-bound.rs b/src/test/compile-fail/static-region-bound.rs index 42f9d24bc52bb..4c59e7a769fbf 100644 --- a/src/test/compile-fail/static-region-bound.rs +++ b/src/test/compile-fail/static-region-bound.rs @@ -13,8 +13,8 @@ fn f(_: T) {} fn main() { - let x = box 3i; + let x = box 3is; f(x); - let x = &3i; //~ ERROR borrowed value does not live long enough + let x = &3is; //~ ERROR borrowed value does not live long enough f(x); } diff --git a/src/test/compile-fail/tail-typeck.rs b/src/test/compile-fail/tail-typeck.rs index 99e98b24b63c3..a934bbe61c434 100644 --- a/src/test/compile-fail/tail-typeck.rs +++ b/src/test/compile-fail/tail-typeck.rs @@ -12,6 +12,6 @@ fn f() -> isize { return g(); } -fn g() -> usize { return 0u; } +fn g() -> usize { return 0us; } fn main() { let y = f(); } diff --git a/src/test/compile-fail/trailing-plus-in-bounds.rs b/src/test/compile-fail/trailing-plus-in-bounds.rs index b189acb685a33..069c2e88793da 100644 --- a/src/test/compile-fail/trailing-plus-in-bounds.rs +++ b/src/test/compile-fail/trailing-plus-in-bounds.rs @@ -11,7 +11,7 @@ use std::fmt::Show; fn main() { - let x: Box = box 3i as Box; + let x: Box = box 3is as Box; //~^ ERROR at least one type parameter bound must be specified //~^^ ERROR at least one type parameter bound must be specified } diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs index 479f21ea3a160..45a74a235e0e2 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums-locals.rs @@ -17,7 +17,7 @@ struct Foo { fn main() { let foo = Foo { //~^ ERROR not implemented - x: 3i + x: 3is }; let baz: Foo = panic!(); diff --git a/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc1.rs b/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc1.rs index d3689067aef71..6179301c11da1 100644 --- a/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc1.rs +++ b/src/test/compile-fail/trait-bounds-on-structs-and-enums-xc1.rs @@ -17,7 +17,7 @@ use trait_bounds_on_structs_and_enums_xc::{Bar, Foo, Trait}; fn main() { let foo = Foo { //~^ ERROR not implemented - x: 3i + x: 3is }; let bar: Bar = return; //~^ ERROR not implemented diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index 583d0421d1eb1..bdfc6dcda8837 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -15,7 +15,7 @@ impl bar for isize { fn dup(&self) -> isize { *self } fn blah(&self) {} } impl bar for usize { fn dup(&self) -> usize { *self } fn blah(&self) {} } fn main() { - 10i.dup::(); //~ ERROR does not take type parameters - 10i.blah::(); //~ ERROR incorrect number of type parameters - (box 10i as Box).dup(); //~ ERROR cannot convert to a trait object + 10is.dup::(); //~ ERROR does not take type parameters + 10is.blah::(); //~ ERROR incorrect number of type parameters + (box 10is as Box).dup(); //~ ERROR cannot convert to a trait object } diff --git a/src/test/compile-fail/traits-multidispatch-bad.rs b/src/test/compile-fail/traits-multidispatch-bad.rs index f655844e2f36f..e9a4005b4b4f2 100644 --- a/src/test/compile-fail/traits-multidispatch-bad.rs +++ b/src/test/compile-fail/traits-multidispatch-bad.rs @@ -26,7 +26,7 @@ where T : Convert } fn a() { - test(22i, 44i); //~ ERROR not implemented + test(22is, 44is); //~ ERROR not implemented } fn main() {} diff --git a/src/test/compile-fail/typeck-unsafe-always-share.rs b/src/test/compile-fail/typeck-unsafe-always-share.rs index 5166a4e96540d..a9113c6e99f43 100644 --- a/src/test/compile-fail/typeck-unsafe-always-share.rs +++ b/src/test/compile-fail/typeck-unsafe-always-share.rs @@ -28,7 +28,7 @@ fn test(s: T){ } fn main() { - let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0i)}); + let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0is)}); test(us); //~^ ERROR `core::marker::Sync` is not implemented diff --git a/src/test/compile-fail/typeck_type_placeholder_item.rs b/src/test/compile-fail/typeck_type_placeholder_item.rs index aa4ecad639372..d69c0dc5d1fa8 100644 --- a/src/test/compile-fail/typeck_type_placeholder_item.rs +++ b/src/test/compile-fail/typeck_type_placeholder_item.rs @@ -14,7 +14,7 @@ fn test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures -fn test2() -> (_, _) { (5u, 5u) } +fn test2() -> (_, _) { (5us, 5us) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures @@ -67,7 +67,7 @@ pub fn main() { fn fn_test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures - fn fn_test2() -> (_, _) { (5u, 5u) } + fn fn_test2() -> (_, _) { (5us, 5us) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs index 9694c1d9f980e..e1d17e4fef7b0 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs @@ -16,6 +16,6 @@ struct Foo<'a, T:'a> { } pub fn main() { - let c: Foo<_, _> = Foo { r: &5u }; + let c: Foo<_, _> = Foo { r: &5us }; //~^ ERROR wrong number of type arguments: expected 1, found 2 } diff --git a/src/test/compile-fail/unboxed-closure-illegal-move.rs b/src/test/compile-fail/unboxed-closure-illegal-move.rs index 4d6f04da02661..d489c3a64fabd 100644 --- a/src/test/compile-fail/unboxed-closure-illegal-move.rs +++ b/src/test/compile-fail/unboxed-closure-illegal-move.rs @@ -18,28 +18,28 @@ fn main() { // By-ref cases { - let x = box 0u; + let x = box 0us; let f = |&:| drop(x); //~ cannot move } { - let x = box 0u; + let x = box 0us; let f = |&mut:| drop(x); //~ cannot move } { - let x = box 0u; + let x = box 0us; let f = |:| drop(x); //~ cannot move } // By-value cases { - let x = box 0u; + let x = box 0us; let f = move |&:| drop(x); //~ cannot move } { - let x = box 0u; + let x = box 0us; let f = move |&mut:| drop(x); //~ cannot move } { - let x = box 0u; + let x = box 0us; let f = move |:| drop(x); // this one is ok } } diff --git a/src/test/compile-fail/unboxed-closure-immutable-capture.rs b/src/test/compile-fail/unboxed-closure-immutable-capture.rs index 3848f07a08970..ebdd3c3107f3f 100644 --- a/src/test/compile-fail/unboxed-closure-immutable-capture.rs +++ b/src/test/compile-fail/unboxed-closure-immutable-capture.rs @@ -17,7 +17,7 @@ fn set(x: &mut usize) { *x = 0; } fn main() { - let x = 0u; + let x = 0us; move |&mut:| x = 1; //~ ERROR cannot assign move |&mut:| set(&mut x); //~ ERROR cannot borrow move |:| x = 1; //~ ERROR cannot assign diff --git a/src/test/compile-fail/unboxed-closure-region.rs b/src/test/compile-fail/unboxed-closure-region.rs index 2a71aeaca5f35..9d9667986949e 100644 --- a/src/test/compile-fail/unboxed-closure-region.rs +++ b/src/test/compile-fail/unboxed-closure-region.rs @@ -14,7 +14,7 @@ // reference cannot escape the region of that variable. fn main() { let _f = { - let x = 0u; + let x = 0us; |:| x //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements }; } diff --git a/src/test/compile-fail/unboxed-closures-borrow-conflict.rs b/src/test/compile-fail/unboxed-closures-borrow-conflict.rs index baf7f3f5e58a4..bb92e57d70c0e 100644 --- a/src/test/compile-fail/unboxed-closures-borrow-conflict.rs +++ b/src/test/compile-fail/unboxed-closures-borrow-conflict.rs @@ -14,7 +14,7 @@ // cause borrow conflicts. fn main() { - let mut x = 0u; + let mut x = 0us; let f = |:| x += 1; let _y = x; //~ ERROR cannot use `x` because it was mutably borrowed } diff --git a/src/test/compile-fail/unboxed-closures-infer-argument-types-two-region-pointers.rs b/src/test/compile-fail/unboxed-closures-infer-argument-types-two-region-pointers.rs index 72109b22957e0..525d0b31995c2 100644 --- a/src/test/compile-fail/unboxed-closures-infer-argument-types-two-region-pointers.rs +++ b/src/test/compile-fail/unboxed-closures-infer-argument-types-two-region-pointers.rs @@ -23,7 +23,7 @@ fn doit(val: T, f: &F) } pub fn main() { - doit(0i, &|&: x, y| { + doit(0is, &|&: x, y| { x.set(y); //~ ERROR cannot infer }); } diff --git a/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs b/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs index ddd2649a3fee5..22bfabf040ae4 100644 --- a/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs @@ -12,6 +12,6 @@ fn main() { let mut_ = |&mut: x| x; - mut_.call((0i, )); //~ ERROR does not implement any method in scope named `call` + mut_.call((0is, )); //~ ERROR does not implement any method in scope named `call` } diff --git a/src/test/compile-fail/unboxed-closures-type-mismatch.rs b/src/test/compile-fail/unboxed-closures-type-mismatch.rs index 6c2e9f431fe82..f7ac2274ffb3a 100644 --- a/src/test/compile-fail/unboxed-closures-type-mismatch.rs +++ b/src/test/compile-fail/unboxed-closures-type-mismatch.rs @@ -14,6 +14,6 @@ use std::ops::FnMut; pub fn main() { let mut f = |&mut: x: isize, y: isize| -> isize { x + y }; - let z = f(1u, 2); //~ ERROR mismatched types + let z = f(1us, 2); //~ ERROR mismatched types println!("{}", z); } diff --git a/src/test/compile-fail/unique-unique-kind.rs b/src/test/compile-fail/unique-unique-kind.rs index ae354729b9202..4b7f11b05609c 100644 --- a/src/test/compile-fail/unique-unique-kind.rs +++ b/src/test/compile-fail/unique-unique-kind.rs @@ -16,7 +16,7 @@ fn f(_i: T) { } fn main() { - let i = box Rc::new(100i); + let i = box Rc::new(100is); f(i); //~^ ERROR `core::marker::Send` is not implemented //~^^ ERROR `core::marker::Send` is not implemented diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs index c277e63aba9fe..f403457efbc1b 100644 --- a/src/test/compile-fail/unreachable-arm.rs +++ b/src/test/compile-fail/unreachable-arm.rs @@ -14,4 +14,4 @@ enum foo { a(Box, isize), b(usize), } -fn main() { match foo::b(1u) { foo::b(_) | foo::a(box _, 1) => { } foo::a(_, 1) => { } } } +fn main() { match foo::b(1us) { foo::b(_) | foo::a(box _, 1) => { } foo::a(_, 1) => { } } } diff --git a/src/test/compile-fail/unreachable-code.rs b/src/test/compile-fail/unreachable-code.rs index 87342352e9ae4..d96578f2df94a 100644 --- a/src/test/compile-fail/unreachable-code.rs +++ b/src/test/compile-fail/unreachable-code.rs @@ -14,5 +14,5 @@ fn main() { loop{} - let a = 3i; //~ ERROR: unreachable statement + let a = 3is; //~ ERROR: unreachable statement } diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index 2d330654881ba..9d4cfe0f4ac65 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -55,12 +55,12 @@ fn f8(x1: &S, x2: &S) { // Test some tuples. fn f9(x1: Box>, x2: Box>) { - f5(&(*x1, 34i)); + f5(&(*x1, 34is)); //~^ ERROR the trait `core::marker::Sized` is not implemented } fn f10(x1: Box>, x2: Box>) { - f5(&(32i, *x2)); + f5(&(32is, *x2)); //~^ ERROR the trait `core::marker::Sized` is not implemented } diff --git a/src/test/compile-fail/unsized6.rs b/src/test/compile-fail/unsized6.rs index 2129f075a81b5..21953d1bb09f9 100644 --- a/src/test/compile-fail/unsized6.rs +++ b/src/test/compile-fail/unsized6.rs @@ -27,12 +27,12 @@ fn f2(x: &X) { fn f3(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~ERROR the trait `core::marker::Sized` is not implemented let y = *x2; //~ERROR the trait `core::marker::Sized` is not implemented - let (y, z) = (*x3, 4i); //~ERROR the trait `core::marker::Sized` is not implemented + let (y, z) = (*x3, 4is); //~ERROR the trait `core::marker::Sized` is not implemented } fn f4(x1: Box, x2: Box, x3: Box) { let y: X = *x1; //~ERROR the trait `core::marker::Sized` is not implemented let y = *x2; //~ERROR the trait `core::marker::Sized` is not implemented - let (y, z) = (*x3, 4i); //~ERROR the trait `core::marker::Sized` is not implemented + let (y, z) = (*x3, 4is); //~ERROR the trait `core::marker::Sized` is not implemented } fn g1(x: X) {} //~ERROR the trait `core::marker::Sized` is not implemented diff --git a/src/test/compile-fail/unused-mut-warning-captured-var.rs b/src/test/compile-fail/unused-mut-warning-captured-var.rs index 2c000e03ce43a..aa5adb6a6b0cd 100644 --- a/src/test/compile-fail/unused-mut-warning-captured-var.rs +++ b/src/test/compile-fail/unused-mut-warning-captured-var.rs @@ -11,7 +11,7 @@ #![forbid(unused_mut)] fn main() { - let mut x = 1i; + let mut x = 1is; //~^ ERROR: variable does not need to be mutable move|:| { println!("{}", x); }; } diff --git a/src/test/compile-fail/vec-matching-obsolete-syntax.rs b/src/test/compile-fail/vec-matching-obsolete-syntax.rs index 6330aac2d8b75..2715b31d1960e 100644 --- a/src/test/compile-fail/vec-matching-obsolete-syntax.rs +++ b/src/test/compile-fail/vec-matching-obsolete-syntax.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let x = [1i, 2, 3]; + let x = [1is, 2, 3]; match x { [a, b, ..c] => { //~ ERROR obsolete syntax assert_eq!(a, 1); diff --git a/src/test/compile-fail/vec-mut-iter-borrow.rs b/src/test/compile-fail/vec-mut-iter-borrow.rs index b60d1799f7714..59c490f2fff27 100644 --- a/src/test/compile-fail/vec-mut-iter-borrow.rs +++ b/src/test/compile-fail/vec-mut-iter-borrow.rs @@ -12,6 +12,6 @@ fn main() { let mut xs: Vec = vec!(); for x in xs.iter_mut() { - xs.push(1i) //~ ERROR cannot borrow `xs` + xs.push(1is) //~ ERROR cannot borrow `xs` } } diff --git a/src/test/compile-fail/vtable-res-trait-param.rs b/src/test/compile-fail/vtable-res-trait-param.rs index 32a6c65b133d0..bbe88379aa737 100644 --- a/src/test/compile-fail/vtable-res-trait-param.rs +++ b/src/test/compile-fail/vtable-res-trait-param.rs @@ -23,11 +23,11 @@ impl TraitB for isize { } fn call_it(b: B) -> isize { - let y = 4u; + let y = 4us; b.gimme_an_a(y) //~ ERROR the trait `TraitA` is not implemented } fn main() { - let x = 3i; + let x = 3is; assert_eq!(call_it(x), 22); } diff --git a/src/test/compile-fail/warn-path-statement.rs b/src/test/compile-fail/warn-path-statement.rs index 8b6d160a6c5a9..304900df776c1 100644 --- a/src/test/compile-fail/warn-path-statement.rs +++ b/src/test/compile-fail/warn-path-statement.rs @@ -11,6 +11,6 @@ // compile-flags: -D path-statement fn main() { - let x = 10i; + let x = 10is; x; //~ ERROR path statement with no effect } diff --git a/src/test/compile-fail/where-clauses-not-parameter.rs b/src/test/compile-fail/where-clauses-not-parameter.rs index 65205cc72ee29..5573464c5ab6c 100644 --- a/src/test/compile-fail/where-clauses-not-parameter.rs +++ b/src/test/compile-fail/where-clauses-not-parameter.rs @@ -41,5 +41,5 @@ impl Baz for isize where isize : Eq { } fn main() { - equal(&0i, &0i); + equal(&0is, &0is); } diff --git a/src/test/compile-fail/while-let.rs b/src/test/compile-fail/while-let.rs index adb8ee6940d3b..45e0d0aaeab13 100644 --- a/src/test/compile-fail/while-let.rs +++ b/src/test/compile-fail/while-let.rs @@ -20,16 +20,16 @@ fn macros() { }} } - foo!(a, 1i, { //~ ERROR irrefutable while-let + foo!(a, 1is, { //~ ERROR irrefutable while-let println!("irrefutable pattern"); }); - bar!(a, 1i, { //~ ERROR irrefutable while-let + bar!(a, 1is, { //~ ERROR irrefutable while-let println!("irrefutable pattern"); }); } pub fn main() { - while let a = 1i { //~ ERROR irrefutable while-let + while let a = 1is { //~ ERROR irrefutable while-let println!("irrefutable pattern"); } } From dc1ba08d1603aeedf37a4a7182e990207891379d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 23:36:24 +1100 Subject: [PATCH 16/25] Test fixes. --- src/libsyntax/ext/deriving/rand.rs | 6 +++--- src/libsyntax/feature_gate.rs | 2 +- src/test/compile-fail/feature-gate-int-uint.rs | 16 ++++++++-------- src/test/compile-fail/issue-13482-2.rs | 2 +- src/test/compile-fail/issue-5544-a.rs | 2 +- .../compile-fail/lex-bad-numeric-literals.rs | 4 ++-- src/test/compile-fail/lint-type-limits.rs | 4 ++-- src/test/compile-fail/oversized-literal.rs | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 5517019f804ce..1359cada67396 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -98,13 +98,13 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) rand_name, vec!(rng.clone())); - // need to specify the uint-ness of the random number - let uint_ty = cx.ty_ident(trait_span, cx.ident_of("uint")); + // need to specify the usize-ness of the random number + let usize_ty = cx.ty_ident(trait_span, cx.ident_of("usize")); let value_ident = cx.ident_of("__value"); let let_statement = cx.stmt_let_typed(trait_span, false, value_ident, - uint_ty, + usize_ty, rv_call); // rand() % variants.len() diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6deffa804b2df..ec1910f90174f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -355,7 +355,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { Some("the `int` type is deprecated; \ use `isize` or a fixed-sized integer") } else if name == "uint" { - Some("the `unt` type is deprecated; \ + Some("the `uint` type is deprecated; \ use `usize` or a fixed-sized integer") } else { None diff --git a/src/test/compile-fail/feature-gate-int-uint.rs b/src/test/compile-fail/feature-gate-int-uint.rs index 94190cc15115d..016a03942891f 100644 --- a/src/test/compile-fail/feature-gate-int-uint.rs +++ b/src/test/compile-fail/feature-gate-int-uint.rs @@ -11,21 +11,21 @@ #![allow(dead_code)] mod u { - type X = usize; //~ WARN the `usize` type is deprecated + type X = uint; //~ WARN the `uint` type is deprecated struct Foo { - x: usize //~ WARN the `usize` type is deprecated + x: uint //~ WARN the `uint` type is deprecated } - fn bar(x: usize) { //~ WARN the `usize` type is deprecated - 1us; //~ WARN the `u` suffix on integers is deprecated + fn bar(x: uint) { //~ WARN the `uint` type is deprecated + 1u; //~ WARN the `u` suffix on integers is deprecated } } mod i { - type X = isize; //~ WARN the `isize` type is deprecated + type X = int; //~ WARN the `int` type is deprecated struct Foo { - x: isize //~ WARN the `isize` type is deprecated + x: int //~ WARN the `int` type is deprecated } - fn bar(x: isize) { //~ WARN the `isize` type is deprecated - 1is; //~ WARN the `u` suffix on integers is deprecated + fn bar(x: int) { //~ WARN the `int` type is deprecated + 1i; //~ WARN the `i` suffix on integers is deprecated } } diff --git a/src/test/compile-fail/issue-13482-2.rs b/src/test/compile-fail/issue-13482-2.rs index 5c9b0473cea13..ef7d3d4d158d9 100644 --- a/src/test/compile-fail/issue-13482-2.rs +++ b/src/test/compile-fail/issue-13482-2.rs @@ -14,7 +14,7 @@ fn main() { let x = [1,2]; let y = match x { [] => None, - //~^ ERROR types: expected `[_#0is; 2]`, found `[_#7t; 0]` + //~^ ERROR types: expected `[_#0i; 2]`, found `[_#7t; 0]` // (expected array of 2 elements, found array of 0 elements) [a,_] => Some(a) }; diff --git a/src/test/compile-fail/issue-5544-a.rs b/src/test/compile-fail/issue-5544-a.rs index 6db126f403a4a..42a18ba5fb765 100644 --- a/src/test/compile-fail/issue-5544-a.rs +++ b/src/test/compile-fail/issue-5544-a.rs @@ -10,5 +10,5 @@ fn main() { let _i = 18446744073709551616; // 2^64 - //~^ ERROR isize literal is too large + //~^ ERROR int literal is too large } diff --git a/src/test/compile-fail/lex-bad-numeric-literals.rs b/src/test/compile-fail/lex-bad-numeric-literals.rs index 273a7627d73bf..9a490be6a0169 100644 --- a/src/test/compile-fail/lex-bad-numeric-literals.rs +++ b/src/test/compile-fail/lex-bad-numeric-literals.rs @@ -21,8 +21,8 @@ fn main() { 0o; //~ ERROR: no valid digits 1e+; //~ ERROR: expected at least one digit in exponent 0x539.0; //~ ERROR: hexadecimal float literal is not supported - 99999999999999999999999999999999; //~ ERROR: isize literal is too large - 99999999999999999999999999999999u32; //~ ERROR: isize literal is too large + 99999999999999999999999999999999; //~ ERROR: int literal is too large + 99999999999999999999999999999999u32; //~ ERROR: int literal is too large 0x; //~ ERROR: no valid digits 0xu32; //~ ERROR: no valid digits 0ou32; //~ ERROR: no valid digits diff --git a/src/test/compile-fail/lint-type-limits.rs b/src/test/compile-fail/lint-type-limits.rs index 3224dec1c997d..a2bc464ac4978 100644 --- a/src/test/compile-fail/lint-type-limits.rs +++ b/src/test/compile-fail/lint-type-limits.rs @@ -50,12 +50,12 @@ fn qux() { } fn quy() { - let i = -23us; //~ WARNING negation of unsigned isize literal may be unintentional + let i = -23us; //~ WARNING negation of unsigned int literal may be unintentional //~^ WARNING unused variable } fn quz() { let i = 23us; - let j = -i; //~ WARNING negation of unsigned isize variable may be unintentional + let j = -i; //~ WARNING negation of unsigned int variable may be unintentional //~^ WARNING unused variable } diff --git a/src/test/compile-fail/oversized-literal.rs b/src/test/compile-fail/oversized-literal.rs index 2a70653bd6c03..5416bcacf3d59 100644 --- a/src/test/compile-fail/oversized-literal.rs +++ b/src/test/compile-fail/oversized-literal.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - println!("{}", 18446744073709551616u64); //~ error: isize literal is too large + println!("{}", 18446744073709551616u64); //~ error: int literal is too large } From 2259fe1214b086bf37cd64bff201f3ef9c08ad50 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 8 Jan 2015 15:05:17 +0100 Subject: [PATCH 17/25] Accommodate the "int literal is too large" error message currently embedded in rustc. --- src/test/compile-fail/int-literal-too-large-span.rs | 2 +- src/test/compile-fail/issue-5544-b.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/compile-fail/int-literal-too-large-span.rs b/src/test/compile-fail/int-literal-too-large-span.rs index 2eb66816cba36..2aeaf6efaa4c0 100644 --- a/src/test/compile-fail/int-literal-too-large-span.rs +++ b/src/test/compile-fail/int-literal-too-large-span.rs @@ -11,7 +11,7 @@ // issue #17123 fn main() { - 100000000000000000000000000000000 //~ ERROR isize literal is too large + 100000000000000000000000000000000is //~ ERROR int literal is too large ; // the span shouldn't point to this. } diff --git a/src/test/compile-fail/issue-5544-b.rs b/src/test/compile-fail/issue-5544-b.rs index 4b04fe1a36aaa..1f166ec0d1cc9 100644 --- a/src/test/compile-fail/issue-5544-b.rs +++ b/src/test/compile-fail/issue-5544-b.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - let _i = 0xff_ffff_ffff_ffff_ffff; - //~^ ERROR isize literal is too large + let _i = 0xff_ffff_ffff_ffff_ffff_is; + //~^ ERROR int literal is too large } From b2e93e276773edaa497989064181cbc706c4ecc1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 8 Jan 2015 15:09:03 +0100 Subject: [PATCH 18/25] Update the compile-fail-fulldeps tests with new isize/usize literal suffixes. --- src/test/compile-fail-fulldeps/issue-18986.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail-fulldeps/issue-18986.rs b/src/test/compile-fail-fulldeps/issue-18986.rs index 25d78c273e77a..6845116e4a4ce 100644 --- a/src/test/compile-fail-fulldeps/issue-18986.rs +++ b/src/test/compile-fail-fulldeps/issue-18986.rs @@ -15,6 +15,6 @@ pub use use_from_trait_xc::Trait; fn main() { match () { - Trait { x: 42u } => () //~ ERROR use of trait `Trait` in a struct pattern + Trait { x: 42us } => () //~ ERROR use of trait `Trait` in a struct pattern } } From a0f53b0a5b5a2e0320689885ee606ea4b61f4c56 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 8 Jan 2015 15:19:12 +0100 Subject: [PATCH 19/25] Update graphviz tests to accommodate new isize/usize types and is/us suffixes. --- src/test/run-make/graphviz-flowgraph/f01.rs | 2 +- .../graphviz-flowgraph/f02.dot-expected.dot | 4 ++-- src/test/run-make/graphviz-flowgraph/f02.rs | 2 +- src/test/run-make/graphviz-flowgraph/f03.rs | 2 +- src/test/run-make/graphviz-flowgraph/f04.rs | 2 +- src/test/run-make/graphviz-flowgraph/f05.rs | 2 +- src/test/run-make/graphviz-flowgraph/f06.rs | 2 +- src/test/run-make/graphviz-flowgraph/f07.rs | 2 +- src/test/run-make/graphviz-flowgraph/f08.rs | 6 +++--- src/test/run-make/graphviz-flowgraph/f10.rs | 6 +++--- src/test/run-make/graphviz-flowgraph/f11.rs | 4 ++-- src/test/run-make/graphviz-flowgraph/f12.rs | 6 +++--- src/test/run-make/graphviz-flowgraph/f13.rs | 2 +- src/test/run-make/graphviz-flowgraph/f14.rs | 4 ++-- src/test/run-make/graphviz-flowgraph/f15.rs | 14 ++++++------- src/test/run-make/graphviz-flowgraph/f16.rs | 14 ++++++------- src/test/run-make/graphviz-flowgraph/f17.rs | 2 +- .../graphviz-flowgraph/f18.dot-expected.dot | 4 ++-- src/test/run-make/graphviz-flowgraph/f18.rs | 2 +- .../graphviz-flowgraph/f19.dot-expected.dot | 4 ++-- src/test/run-make/graphviz-flowgraph/f19.rs | 2 +- src/test/run-make/graphviz-flowgraph/f20.rs | 4 ++-- src/test/run-make/graphviz-flowgraph/f21.rs | 12 +++++------ src/test/run-make/graphviz-flowgraph/f22.rs | 12 +++++------ src/test/run-make/graphviz-flowgraph/f23.rs | 18 ++++++++--------- src/test/run-make/graphviz-flowgraph/f24.rs | 20 +++++++++---------- src/test/run-make/graphviz-flowgraph/f25.rs | 20 +++++++++---------- 27 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/test/run-make/graphviz-flowgraph/f01.rs b/src/test/run-make/graphviz-flowgraph/f01.rs index f1f1a1d5472f7..27b198078651a 100644 --- a/src/test/run-make/graphviz-flowgraph/f01.rs +++ b/src/test/run-make/graphviz-flowgraph/f01.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn lit_1() { - 1i; + 1is; } diff --git a/src/test/run-make/graphviz-flowgraph/f02.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f02.dot-expected.dot index 230dcbaeb98f8..1f4a58ba0a3c2 100644 --- a/src/test/run-make/graphviz-flowgraph/f02.dot-expected.dot +++ b/src/test/run-make/graphviz-flowgraph/f02.dot-expected.dot @@ -2,8 +2,8 @@ digraph block { N0[label="entry"]; N1[label="exit"]; N2[label="local _x"]; - N3[label="stmt let _x: int;"]; - N4[label="block { let _x: int; }"]; + N3[label="stmt let _x: isize;"]; + N4[label="block { let _x: isize; }"]; N0 -> N2; N2 -> N3; N3 -> N4; diff --git a/src/test/run-make/graphviz-flowgraph/f02.rs b/src/test/run-make/graphviz-flowgraph/f02.rs index 3cdd73a49e18e..f7fe126619853 100644 --- a/src/test/run-make/graphviz-flowgraph/f02.rs +++ b/src/test/run-make/graphviz-flowgraph/f02.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn decl_x_2() { - let _x : int; + let _x : isize; } diff --git a/src/test/run-make/graphviz-flowgraph/f03.rs b/src/test/run-make/graphviz-flowgraph/f03.rs index 051409a49b144..c95dbcbb31c2e 100644 --- a/src/test/run-make/graphviz-flowgraph/f03.rs +++ b/src/test/run-make/graphviz-flowgraph/f03.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn expr_add_3() { - 3i + 4; + 3is + 4; } diff --git a/src/test/run-make/graphviz-flowgraph/f04.rs b/src/test/run-make/graphviz-flowgraph/f04.rs index ed2f7e25dae6c..552cb24c7506e 100644 --- a/src/test/run-make/graphviz-flowgraph/f04.rs +++ b/src/test/run-make/graphviz-flowgraph/f04.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn pat_id_4() { - let _x = 4i; + let _x = 4is; } diff --git a/src/test/run-make/graphviz-flowgraph/f05.rs b/src/test/run-make/graphviz-flowgraph/f05.rs index b2591bdd08a16..09a45c9bd2151 100644 --- a/src/test/run-make/graphviz-flowgraph/f05.rs +++ b/src/test/run-make/graphviz-flowgraph/f05.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn pat_tup_5() { - let (_x, _y) = (5i, 55i); + let (_x, _y) = (5is, 55is); } diff --git a/src/test/run-make/graphviz-flowgraph/f06.rs b/src/test/run-make/graphviz-flowgraph/f06.rs index c914409629cb0..538ef2af89896 100644 --- a/src/test/run-make/graphviz-flowgraph/f06.rs +++ b/src/test/run-make/graphviz-flowgraph/f06.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S6 { val: int } +struct S6 { val: isize } pub fn pat_struct_6() { let S6 { val: _x } = S6{ val: 6 }; } diff --git a/src/test/run-make/graphviz-flowgraph/f07.rs b/src/test/run-make/graphviz-flowgraph/f07.rs index fb3f2d24cddc7..8334f81c080d7 100644 --- a/src/test/run-make/graphviz-flowgraph/f07.rs +++ b/src/test/run-make/graphviz-flowgraph/f07.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn pat_vec_7() { - match [7i, 77i, 777i, 7777i] { + match [7is, 77is, 777is, 7777is] { [x, y, ..] => x + y }; } diff --git a/src/test/run-make/graphviz-flowgraph/f08.rs b/src/test/run-make/graphviz-flowgraph/f08.rs index 5d166e5ffcd5d..ad96f30073bc6 100644 --- a/src/test/run-make/graphviz-flowgraph/f08.rs +++ b/src/test/run-make/graphviz-flowgraph/f08.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn expr_if_onearm_8() { - let x = 8i; let _y; - if x > 88i { - _y = 888i; + let x = 8is; let _y; + if x > 88is { + _y = 888is; } } diff --git a/src/test/run-make/graphviz-flowgraph/f10.rs b/src/test/run-make/graphviz-flowgraph/f10.rs index af263f0cf10db..456f740d468d5 100644 --- a/src/test/run-make/graphviz-flowgraph/f10.rs +++ b/src/test/run-make/graphviz-flowgraph/f10.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn expr_while_10() { - let mut x = 10i; - while x > 0i { - x -= 1i; + let mut x = 10is; + while x > 0is { + x -= 1is; } } diff --git a/src/test/run-make/graphviz-flowgraph/f11.rs b/src/test/run-make/graphviz-flowgraph/f11.rs index 95260c608eca4..65262f249bcd6 100644 --- a/src/test/run-make/graphviz-flowgraph/f11.rs +++ b/src/test/run-make/graphviz-flowgraph/f11.rs @@ -10,9 +10,9 @@ #[allow(unreachable_code)] pub fn expr_loop_11() { - let mut _x = 11i; + let mut _x = 11is; loop { - _x -= 1i; + _x -= 1is; } "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f12.rs b/src/test/run-make/graphviz-flowgraph/f12.rs index 625dd8cb03ef9..5651d73baffef 100644 --- a/src/test/run-make/graphviz-flowgraph/f12.rs +++ b/src/test/run-make/graphviz-flowgraph/f12.rs @@ -10,9 +10,9 @@ #[allow(unreachable_code)] pub fn expr_loop_12() { - let mut x = 12i; + let mut x = 12is; loop { - x -= 1i; - if x == 2i { break; "unreachable"; } + x -= 1is; + if x == 2is { break; "unreachable"; } } } diff --git a/src/test/run-make/graphviz-flowgraph/f13.rs b/src/test/run-make/graphviz-flowgraph/f13.rs index fdda50b431201..babb283c7342c 100644 --- a/src/test/run-make/graphviz-flowgraph/f13.rs +++ b/src/test/run-make/graphviz-flowgraph/f13.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum E13 { E13a, E13b(int) } +enum E13 { E13a, E13b(isize) } pub fn expr_match_13() { let x = E13::E13b(13); let _y; match x { diff --git a/src/test/run-make/graphviz-flowgraph/f14.rs b/src/test/run-make/graphviz-flowgraph/f14.rs index 72616f3159487..adb7b193d1617 100644 --- a/src/test/run-make/graphviz-flowgraph/f14.rs +++ b/src/test/run-make/graphviz-flowgraph/f14.rs @@ -10,8 +10,8 @@ #[allow(unreachable_code)] pub fn expr_ret_14() { - let x = 14i; - if x > 1i { + let x = 14is; + if x > 1is { return; "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f15.rs b/src/test/run-make/graphviz-flowgraph/f15.rs index 62233dcb7d8a1..a1141eb67689a 100644 --- a/src/test/run-make/graphviz-flowgraph/f15.rs +++ b/src/test/run-make/graphviz-flowgraph/f15.rs @@ -10,21 +10,21 @@ #[allow(unreachable_code)] pub fn expr_break_label_15() { - let mut x = 15i; - let mut y = 151i; + let mut x = 15is; + let mut y = 151is; 'outer: loop { 'inner: loop { - if x == 1i { + if x == 1is { break 'outer; "unreachable"; } - if y >= 2i { + if y >= 2is { break; "unreachable"; } - y -= 3i; + y -= 3is; } - y -= 4i; - x -= 5i; + y -= 4is; + x -= 5is; } } diff --git a/src/test/run-make/graphviz-flowgraph/f16.rs b/src/test/run-make/graphviz-flowgraph/f16.rs index 2683d8bd06b97..5d0e9f963a021 100644 --- a/src/test/run-make/graphviz-flowgraph/f16.rs +++ b/src/test/run-make/graphviz-flowgraph/f16.rs @@ -10,22 +10,22 @@ #[allow(unreachable_code)] pub fn expr_continue_label_16() { - let mut x = 16i; - let mut y = 16i; + let mut x = 16is; + let mut y = 16is; 'outer: loop { 'inner: loop { - if x == 1i { + if x == 1is { continue 'outer; "unreachable"; } - if y >= 1i { + if y >= 1is { break; "unreachable"; } - y -= 1i; + y -= 1is; } - y -= 1i; - x -= 1i; + y -= 1is; + x -= 1is; } "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f17.rs b/src/test/run-make/graphviz-flowgraph/f17.rs index 23ce212c0af48..de9b3bd567611 100644 --- a/src/test/run-make/graphviz-flowgraph/f17.rs +++ b/src/test/run-make/graphviz-flowgraph/f17.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn expr_vec_17() { - let _v = [1i, 7i, 17i]; + let _v = [1is, 7is, 17is]; } diff --git a/src/test/run-make/graphviz-flowgraph/f18.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f18.dot-expected.dot index c4a39a519eddf..78120e9009e69 100644 --- a/src/test/run-make/graphviz-flowgraph/f18.dot-expected.dot +++ b/src/test/run-make/graphviz-flowgraph/f18.dot-expected.dot @@ -1,14 +1,14 @@ digraph block { N0[label="entry"]; N1[label="exit"]; - N2[label="stmt fn inner(x: int) -> int { x + x }"]; + N2[label="stmt fn inner(x: isize) -> isize { x + x }"]; N3[label="expr inner"]; N4[label="expr inner"]; N5[label="expr 18"]; N6[label="expr inner(18)"]; N7[label="expr inner(inner(18))"]; N8[label="stmt inner(inner(18));"]; - N9[label="block {\l fn inner(x: int) -> int { x + x }\l inner(inner(18));\l}\l"]; + N9[label="block {\l fn inner(x: isize) -> isize { x + x }\l inner(inner(18));\l}\l"]; N0 -> N2; N2 -> N3; N3 -> N4; diff --git a/src/test/run-make/graphviz-flowgraph/f18.rs b/src/test/run-make/graphviz-flowgraph/f18.rs index 0ace542b8f5db..cbf8aa5db4391 100644 --- a/src/test/run-make/graphviz-flowgraph/f18.rs +++ b/src/test/run-make/graphviz-flowgraph/f18.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn expr_call_18() { - fn inner(x:int) -> int { x + x } + fn inner(x:isize) -> isize { x + x } inner(inner(18)); } diff --git a/src/test/run-make/graphviz-flowgraph/f19.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f19.dot-expected.dot index 8d21ef8091734..4752eac3e2856 100644 --- a/src/test/run-make/graphviz-flowgraph/f19.dot-expected.dot +++ b/src/test/run-make/graphviz-flowgraph/f19.dot-expected.dot @@ -1,7 +1,7 @@ digraph block { N0[label="entry"]; N1[label="exit"]; - N2[label="stmt struct S19 {\l x: int,\l}\l"]; + N2[label="stmt struct S19 {\l x: isize,\l}\l"]; N3[label="stmt impl S19 {\l fn inner(self) -> S19 { S19{x: self.x + self.x,} }\l}\l"]; N4[label="expr 19"]; N5[label="expr S19{x: 19,}"]; @@ -11,7 +11,7 @@ digraph block { N9[label="expr s.inner()"]; N10[label="expr s.inner().inner()"]; N11[label="stmt s.inner().inner();"]; - N12[label="block {\l struct S19 {\l x: int,\l }\l impl S19 {\l fn inner(self) -> S19 { S19{x: self.x + self.x,} }\l }\l let s = S19{x: 19,};\l s.inner().inner();\l}\l"]; + N12[label="block {\l struct S19 {\l x: isize,\l }\l impl S19 {\l fn inner(self) -> S19 { S19{x: self.x + self.x,} }\l }\l let s = S19{x: 19,};\l s.inner().inner();\l}\l"]; N0 -> N2; N2 -> N3; N3 -> N4; diff --git a/src/test/run-make/graphviz-flowgraph/f19.rs b/src/test/run-make/graphviz-flowgraph/f19.rs index 092f6890a152a..78c15dd64adc4 100644 --- a/src/test/run-make/graphviz-flowgraph/f19.rs +++ b/src/test/run-make/graphviz-flowgraph/f19.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn expr_method_call_19() { - struct S19 { x: int } + struct S19 { x: isize } impl S19 { fn inner(self) -> S19 { S19 { x: self.x + self.x } } } let s = S19 { x: 19 }; s.inner().inner(); diff --git a/src/test/run-make/graphviz-flowgraph/f20.rs b/src/test/run-make/graphviz-flowgraph/f20.rs index 7110ebe2b5429..3ca55cb521baf 100644 --- a/src/test/run-make/graphviz-flowgraph/f20.rs +++ b/src/test/run-make/graphviz-flowgraph/f20.rs @@ -9,6 +9,6 @@ // except according to those terms. pub fn expr_index_20() { - let v = [2u, 0u, 20u]; - v[20u]; + let v = [2us, 0us, 20us]; + v[20us]; } diff --git a/src/test/run-make/graphviz-flowgraph/f21.rs b/src/test/run-make/graphviz-flowgraph/f21.rs index bff2da2506107..25e93f65110ad 100644 --- a/src/test/run-make/graphviz-flowgraph/f21.rs +++ b/src/test/run-make/graphviz-flowgraph/f21.rs @@ -10,20 +10,20 @@ #[allow(unreachable_code)] pub fn expr_break_label_21() { - let mut x = 15i; - let mut y = 151i; + let mut x = 15is; + let mut y = 151is; 'outer: loop { 'inner: loop { - if x == 1i { + if x == 1is { break 'outer; "unreachable"; } - if y >= 2i { + if y >= 2is { return; "unreachable"; } - y -= 3i; - x -= 5i; + y -= 3is; + x -= 5is; } "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f22.rs b/src/test/run-make/graphviz-flowgraph/f22.rs index a6e3d571debab..6de703a42f696 100644 --- a/src/test/run-make/graphviz-flowgraph/f22.rs +++ b/src/test/run-make/graphviz-flowgraph/f22.rs @@ -10,20 +10,20 @@ #[allow(unreachable_code)] pub fn expr_break_label_21() { - let mut x = 15i; - let mut y = 151i; + let mut x = 15is; + let mut y = 151is; 'outer: loop { 'inner: loop { - if x == 1i { + if x == 1is { continue 'outer; "unreachable"; } - if y >= 2i { + if y >= 2is { return; "unreachable"; } - x -= 1i; - y -= 3i; + x -= 1is; + y -= 3is; } "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f23.rs b/src/test/run-make/graphviz-flowgraph/f23.rs index 73bcc288ca7a2..6ffa1838903f0 100644 --- a/src/test/run-make/graphviz-flowgraph/f23.rs +++ b/src/test/run-make/graphviz-flowgraph/f23.rs @@ -10,19 +10,19 @@ #[allow(unreachable_code)] pub fn expr_while_23() { - let mut x = 23i; - let mut y = 23i; - let mut z = 23i; + let mut x = 23is; + let mut y = 23is; + let mut z = 23is; - while x > 0i { - x -= 1i; + while x > 0is { + x -= 1is; - while y > 0i { - y -= 1i; + while y > 0is { + y -= 1is; - while z > 0i { z -= 1i; } + while z > 0is { z -= 1is; } - if x > 10i { + if x > 10is { return; "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f24.rs b/src/test/run-make/graphviz-flowgraph/f24.rs index afba1d202c927..ebaf7f2810103 100644 --- a/src/test/run-make/graphviz-flowgraph/f24.rs +++ b/src/test/run-make/graphviz-flowgraph/f24.rs @@ -10,24 +10,24 @@ #[allow(unreachable_code)] pub fn expr_while_24() { - let mut x = 24i; - let mut y = 24i; - let mut z = 24i; + let mut x = 24is; + let mut y = 24is; + let mut z = 24is; loop { - if x == 0i { break; "unreachable"; } - x -= 1i; + if x == 0is { break; "unreachable"; } + x -= 1is; loop { - if y == 0i { break; "unreachable"; } - y -= 1i; + if y == 0is { break; "unreachable"; } + y -= 1is; loop { - if z == 0i { break; "unreachable"; } - z -= 1i; + if z == 0is { break; "unreachable"; } + z -= 1is; } - if x > 10i { + if x > 10is { return; "unreachable"; } diff --git a/src/test/run-make/graphviz-flowgraph/f25.rs b/src/test/run-make/graphviz-flowgraph/f25.rs index 933f95f228cd9..8896a854787b9 100644 --- a/src/test/run-make/graphviz-flowgraph/f25.rs +++ b/src/test/run-make/graphviz-flowgraph/f25.rs @@ -10,24 +10,24 @@ #[allow(unreachable_code)] pub fn expr_while_25() { - let mut x = 25i; - let mut y = 25i; - let mut z = 25i; + let mut x = 25is; + let mut y = 25is; + let mut z = 25is; 'a: loop { - if x == 0i { break; "unreachable"; } - x -= 1i; + if x == 0is { break; "unreachable"; } + x -= 1is; 'a: loop { - if y == 0i { break; "unreachable"; } - y -= 1i; + if y == 0is { break; "unreachable"; } + y -= 1is; 'a: loop { - if z == 0i { break; "unreachable"; } - z -= 1i; + if z == 0is { break; "unreachable"; } + z -= 1is; } - if x > 10i { + if x > 10is { continue 'a; "unreachable"; } From 20744c6b855956eb3d39f5afda332480546f9e28 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 10:28:59 -0500 Subject: [PATCH 20/25] Allow shift operator to take any integral type (and add a test). --- src/librustc_typeck/check/mod.rs | 20 ++++++- .../compile-fail/shift-various-bad-types.rs | 39 +++++++++++++ src/test/run-pass/shift-various-types.rs | 56 +++++++++++++++++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/shift-various-bad-types.rs create mode 100644 src/test/run-pass/shift-various-types.rs diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f3778eb054037..a6df676e63c8f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3208,8 +3208,24 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op) { // Shift is a special case: rhs must be uint, no matter what lhs is - check_expr_has_type(fcx, &**rhs, fcx.tcx().types.uint); - fcx.write_ty(expr.id, lhs_t); + check_expr(fcx, &**rhs); + let rhs_ty = fcx.expr_ty(&**rhs); + let rhs_ty = fcx.infcx().resolve_type_vars_if_possible(&rhs_ty); + if ty::type_is_integral(rhs_ty) { + fcx.write_ty(expr.id, lhs_t); + } else { + fcx.type_error_message( + expr.span, + |actual| { + format!( + "right-hand-side of a shift operation must have integral type, \ + not `{}`", + actual) + }, + rhs_ty, + None); + fcx.write_ty(expr.id, fcx.tcx().types.err); + } return; } diff --git a/src/test/compile-fail/shift-various-bad-types.rs b/src/test/compile-fail/shift-various-bad-types.rs new file mode 100644 index 0000000000000..6287d79e15d7d --- /dev/null +++ b/src/test/compile-fail/shift-various-bad-types.rs @@ -0,0 +1,39 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we can do shifts by any integral type. + +struct Panolpy { + char: char, + str: &'static str, +} + +fn foo(p: &Panolpy) { + 22 >> p.char; + //~^ ERROR right-hand-side of a shift operation must have integral type + + 22 >> p.str; + //~^ ERROR right-hand-side of a shift operation must have integral type + + 22 >> p; + //~^ ERROR right-hand-side of a shift operation must have integral type + + // We could be more accepting in the case of a type not yet inferred, but not + // known to be an integer, but meh. + let x; + 22 >> x; + //~^ ERROR right-hand-side of a shift operation must have integral type + + 22 >> 1; + // Integer literal types are OK +} + +fn main() { +} diff --git a/src/test/run-pass/shift-various-types.rs b/src/test/run-pass/shift-various-types.rs new file mode 100644 index 0000000000000..3482dd4921b38 --- /dev/null +++ b/src/test/run-pass/shift-various-types.rs @@ -0,0 +1,56 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we can do shifts by any integral type. + +struct Panolpy { + i8: i8, + i16: i16, + i32: i32, + i64: i64, + isize: isize, + + u8: u8, + u16: u16, + u32: u32, + u64: u64, + usize: usize, +} + +fn foo(p: &Panolpy) { + assert_eq!(22 >> p.i8, 11_i8); + assert_eq!(22 >> p.i16, 11_i16); + assert_eq!(22 >> p.i32, 11_i32); + assert_eq!(22 >> p.i64, 11_i64); + assert_eq!(22 >> p.isize, 11_is); + + assert_eq!(22 >> p.u8, 11_u8); + assert_eq!(22 >> p.u16, 11_u16); + assert_eq!(22 >> p.u32, 11_u32); + assert_eq!(22 >> p.u64, 11_u64); + assert_eq!(22 >> p.usize, 11_us); +} + +fn main() { + let p = Panolpy { + i8: 1, + i16: 1, + i32: 1, + i64: 1, + isize: 1, + + u8: 1, + u16: 1, + u32: 1, + u64: 1, + usize: 1, + }; + foo(&p) +} From bf43e8315ec8ccc821c550e7367950a538bd6c9c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 10:56:56 -0500 Subject: [PATCH 21/25] Modify lifetime-infereence-give-expl-lifetime-param-3 to use a shorter type name so that messages do not wrap. --- .../lifetime-inference-give-expl-lifetime-param-3.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs index 18ef30f5b2812..04c5b223cb875 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs @@ -10,17 +10,17 @@ // ignore-tidy-linelength -struct Bar<'x, 'y, 'z> { bar: &'y isize, baz: isize } -fn bar1<'a>(x: &Bar) -> (&'a isize, &'a isize, &'a isize) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a isize, &'a isize, &'a isize) +struct Bar<'x, 'y, 'z> { bar: &'y i32, baz: i32 } +fn bar1<'a>(x: &Bar) -> (&'a i32, &'a i32, &'a i32) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a i32, &'a i32, &'a i32) (x.bar, &x.baz, &x.baz) //~^ ERROR: cannot infer //~^^ ERROR: cannot infer //~^^^ ERROR: cannot infer } -fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a isize, &'a isize, &'a isize) { -//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a isize, &'a isize, &'a isize) +fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a i32, &'a i32, &'a i32) { +//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a i32, &'a i32, &'a i32) (x.bar, &x.baz, &x.baz) //~^ ERROR: cannot infer //~^^ ERROR: cannot infer From 705b92bdfe33d0d6febdf945340262514e1b3b5c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 10:59:40 -0500 Subject: [PATCH 22/25] Wrap long line --- src/test/compile-fail/borrowck-lend-flow-loop.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 97f5978906800..491a0d40bec42 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -131,7 +131,9 @@ fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where } } -fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where F: FnMut(&'r mut usize) -> bool { +fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) + where F: FnMut(&'r mut usize) -> bool +{ // Similar to `loop_break_pops_scopes` but for the `loop` keyword while cond() { From a661bd6575dd3fac17cf77fdea8b76ca790ac212 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Jan 2015 11:26:42 -0500 Subject: [PATCH 23/25] Adjust tests to be clearer about the type that results from a shift expression. --- .../compile-fail/shift-various-bad-types.rs | 4 ++++ src/test/run-pass/shift-various-types.rs | 20 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/test/compile-fail/shift-various-bad-types.rs b/src/test/compile-fail/shift-various-bad-types.rs index 6287d79e15d7d..4178858404905 100644 --- a/src/test/compile-fail/shift-various-bad-types.rs +++ b/src/test/compile-fail/shift-various-bad-types.rs @@ -33,6 +33,10 @@ fn foo(p: &Panolpy) { 22 >> 1; // Integer literal types are OK + + // Type of the result follows the LHS, not the RHS: + let _: i32 = 22_i64 >> 1_i32; + //~^ ERROR mismatched types: expected `i32`, found `i64` } fn main() { diff --git a/src/test/run-pass/shift-various-types.rs b/src/test/run-pass/shift-various-types.rs index 3482dd4921b38..2f56e09b2df83 100644 --- a/src/test/run-pass/shift-various-types.rs +++ b/src/test/run-pass/shift-various-types.rs @@ -25,17 +25,17 @@ struct Panolpy { } fn foo(p: &Panolpy) { - assert_eq!(22 >> p.i8, 11_i8); - assert_eq!(22 >> p.i16, 11_i16); - assert_eq!(22 >> p.i32, 11_i32); - assert_eq!(22 >> p.i64, 11_i64); - assert_eq!(22 >> p.isize, 11_is); + assert_eq!(22_i32 >> p.i8, 11_i32); + assert_eq!(22_i32 >> p.i16, 11_i32); + assert_eq!(22_i32 >> p.i32, 11_i32); + assert_eq!(22_i32 >> p.i64, 11_i32); + assert_eq!(22_i32 >> p.isize, 11_i32); - assert_eq!(22 >> p.u8, 11_u8); - assert_eq!(22 >> p.u16, 11_u16); - assert_eq!(22 >> p.u32, 11_u32); - assert_eq!(22 >> p.u64, 11_u64); - assert_eq!(22 >> p.usize, 11_us); + assert_eq!(22_i32 >> p.u8, 11_i32); + assert_eq!(22_i32 >> p.u16, 11_i32); + assert_eq!(22_i32 >> p.u32, 11_i32); + assert_eq!(22_i32 >> p.u64, 11_i32); + assert_eq!(22_i32 >> p.usize, 11_i32); } fn main() { From 16a6ebd1f60871464c731306aa9007aab30f0dbf Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 2 Dec 2014 09:20:48 -0500 Subject: [PATCH 24/25] "The Rust Programming Language" This pulls all of our long-form documentation into a single document, nicknamed "the book" and formally titled "The Rust Programming Language." A few things motivated this change: * People knew of The Guide, but not the individual Guides. This merges them together, helping discoverability. * You can get all of Rust's longform documentation in one place, which is nice. * We now have rustbook in-tree, which can generate this kind of documentation. While its style is basic, the general idea is much better: a table of contents on the left-hand side. * Rather than a almost 10,000-line guide.md, there are now smaller files per section. --- README.md | 8 +- RELEASES.md | 7 +- configure | 12 - mk/crates.mk | 4 +- mk/docs.mk | 27 +- mk/prepare.mk | 2 +- mk/tests.mk | 29 +- src/doc/guide-container.md | 6 - src/doc/guide-strings.md | 308 - src/doc/guide.md | 5520 ----------------- src/doc/index.md | 27 +- src/doc/intro.md | 9 +- src/doc/reference.md | 23 +- src/doc/trpl/README.md | 35 + src/doc/trpl/SUMMARY.md | 35 + src/doc/trpl/rust-book.css | 59 + src/doc/trpl/src/advanced.md | 8 + src/doc/trpl/src/arrays-vectors-and-slices.md | 99 + src/doc/trpl/src/basic.md | 8 + src/doc/trpl/src/closures.md | 185 + src/doc/trpl/src/comments.md | 46 + src/doc/trpl/src/compound-data-types.md | 353 ++ src/doc/trpl/src/conclusion.md | 10 + .../src/crates-and-modules.md} | 0 .../src/error-handling.md} | 0 src/doc/{guide-ffi.md => trpl/src/ffi.md} | 0 src/doc/trpl/src/functions.md | 146 + src/doc/trpl/src/generics.md | 177 + src/doc/trpl/src/guessing-game.md | 891 +++ src/doc/trpl/src/guide-lifetimes.md | 565 ++ src/doc/trpl/src/hello-cargo.md | 108 + src/doc/trpl/src/hello-world.md | 164 + src/doc/trpl/src/if.md | 141 + src/doc/trpl/src/installing-rust.md | 89 + src/doc/trpl/src/intermediate.md | 7 + src/doc/trpl/src/iterators.md | 339 + src/doc/trpl/src/looping.md | 133 + .../{guide-macros.md => trpl/src/macros.md} | 0 src/doc/trpl/src/match.md | 156 + src/doc/trpl/src/method-syntax.md | 88 + .../src/ownership.md} | 0 src/doc/trpl/src/patterns.md | 199 + .../{guide-plugin.md => trpl/src/plugins.md} | 0 .../src/pointers.md} | 0 src/doc/trpl/src/standard-input.md | 159 + src/doc/trpl/src/strings.md | 79 + src/doc/{guide-tasks.md => trpl/src/tasks.md} | 0 .../{guide-testing.md => trpl/src/testing.md} | 0 src/doc/trpl/src/traits.md | 317 + .../{guide-unsafe.md => trpl/src/unsafe.md} | 0 src/doc/trpl/src/variable-bindings.md | 174 + src/rustbook/book.rs | 166 + src/rustbook/build.rs | 191 + src/rustbook/css.rs | 72 + src/rustbook/error.rs | 76 + src/rustbook/help.rs | 46 + src/rustbook/main.rs | 74 + src/rustbook/serve.rs | 36 + src/rustbook/subcommand.rs | 44 + src/rustbook/term.rs | 31 + src/rustbook/test.rs | 75 + 61 files changed, 5656 insertions(+), 5907 deletions(-) delete mode 100644 src/doc/guide-container.md delete mode 100644 src/doc/guide-strings.md delete mode 100644 src/doc/guide.md create mode 100644 src/doc/trpl/README.md create mode 100644 src/doc/trpl/SUMMARY.md create mode 100644 src/doc/trpl/rust-book.css create mode 100644 src/doc/trpl/src/advanced.md create mode 100644 src/doc/trpl/src/arrays-vectors-and-slices.md create mode 100644 src/doc/trpl/src/basic.md create mode 100644 src/doc/trpl/src/closures.md create mode 100644 src/doc/trpl/src/comments.md create mode 100644 src/doc/trpl/src/compound-data-types.md create mode 100644 src/doc/trpl/src/conclusion.md rename src/doc/{guide-crates.md => trpl/src/crates-and-modules.md} (100%) rename src/doc/{guide-error-handling.md => trpl/src/error-handling.md} (100%) rename src/doc/{guide-ffi.md => trpl/src/ffi.md} (100%) create mode 100644 src/doc/trpl/src/functions.md create mode 100644 src/doc/trpl/src/generics.md create mode 100644 src/doc/trpl/src/guessing-game.md create mode 100644 src/doc/trpl/src/guide-lifetimes.md create mode 100644 src/doc/trpl/src/hello-cargo.md create mode 100644 src/doc/trpl/src/hello-world.md create mode 100644 src/doc/trpl/src/if.md create mode 100644 src/doc/trpl/src/installing-rust.md create mode 100644 src/doc/trpl/src/intermediate.md create mode 100644 src/doc/trpl/src/iterators.md create mode 100644 src/doc/trpl/src/looping.md rename src/doc/{guide-macros.md => trpl/src/macros.md} (100%) create mode 100644 src/doc/trpl/src/match.md create mode 100644 src/doc/trpl/src/method-syntax.md rename src/doc/{guide-ownership.md => trpl/src/ownership.md} (100%) create mode 100644 src/doc/trpl/src/patterns.md rename src/doc/{guide-plugin.md => trpl/src/plugins.md} (100%) rename src/doc/{guide-pointers.md => trpl/src/pointers.md} (100%) create mode 100644 src/doc/trpl/src/standard-input.md create mode 100644 src/doc/trpl/src/strings.md rename src/doc/{guide-tasks.md => trpl/src/tasks.md} (100%) rename src/doc/{guide-testing.md => trpl/src/testing.md} (100%) create mode 100644 src/doc/trpl/src/traits.md rename src/doc/{guide-unsafe.md => trpl/src/unsafe.md} (100%) create mode 100644 src/doc/trpl/src/variable-bindings.md create mode 100644 src/rustbook/book.rs create mode 100755 src/rustbook/build.rs create mode 100644 src/rustbook/css.rs create mode 100644 src/rustbook/error.rs create mode 100644 src/rustbook/help.rs create mode 100755 src/rustbook/main.rs create mode 100644 src/rustbook/serve.rs create mode 100644 src/rustbook/subcommand.rs create mode 100644 src/rustbook/term.rs create mode 100644 src/rustbook/test.rs diff --git a/README.md b/README.md index f60629faef1b6..e858e91773b92 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,14 @@ documentation. ## Quick Start 1. Download a [binary installer][installer] for your platform. -2. Read the [guide]. +2. Read [The Rust Programming Language][trpl]. 3. Enjoy! > ***Note:*** Windows users can read the detailed > [using Rust on Windows][win-wiki] notes on the wiki. [installer]: http://www.rust-lang.org/install.html -[guide]: http://doc.rust-lang.org/guide.html +[trpl]: http://doc.rust-lang.org/book/index.html [win-wiki]: https://github.com/rust-lang/rust/wiki/Using-Rust-on-Windows ## Building from Source @@ -53,7 +53,7 @@ documentation. When complete, `make install` will place several programs into `/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the API-documentation tool. -3. Read the [guide]. +3. Read [The Rust Programming Language][trpl]. 4. Enjoy! ### Building on Windows @@ -75,7 +75,7 @@ To easily build on windows we can use [MSYS2](http://sourceforge.net/projects/ms [repo]: https://github.com/rust-lang/rust [tarball]: https://static.rust-lang.org/dist/rust-nightly.tar.gz -[guide]: http://doc.rust-lang.org/guide.html +[trpl]: http://doc.rust-lang.org/book/index.html ## Notes diff --git a/RELEASES.md b/RELEASES.md index f7c385cbe7c1f..b75fde6fd3268 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -19,8 +19,10 @@ Version 1.0.0-alpha (January 2015) distribution into the Cargo ecosystem so they can evolve separately and don't need to be stabilized as quickly, including 'time', 'getopts', 'num', 'regex', and 'term'. - * Documentation continues to be expanded with more guides, more - API coverage and more examples. + * Documentation continues to be expanded with more API coverage, more + examples, and more in-depth explanations. The guides have been + consolidated into [The Rust Programming Language][trpl]. + * "Rust By Example" is now maintained by the Rust team. * All official Rust binary installers now come with [Cargo], the Rust package manager. @@ -179,6 +181,7 @@ Version 1.0.0-alpha (January 2015) [objsafe]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md [assoc]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md [ints]: https://github.com/rust-lang/rfcs/pull/544#issuecomment-68760871 +[trpl]: http://doc.rust-lang.org/book/index.html Version 0.12.0 (October 2014) ----------------------------- diff --git a/configure b/configure index 61c737e0fd3af..d0b99b12fd90d 100755 --- a/configure +++ b/configure @@ -1055,18 +1055,6 @@ do make_dir $h/test/debuginfo-gdb make_dir $h/test/debuginfo-lldb make_dir $h/test/codegen - make_dir $h/test/doc-guide - make_dir $h/test/doc-guide-ffi - make_dir $h/test/doc-guide-runtime - make_dir $h/test/doc-guide-macros - make_dir $h/test/doc-guide-ownership - make_dir $h/test/doc-guide-pointers - make_dir $h/test/doc-guide-container - make_dir $h/test/doc-guide-tasks - make_dir $h/test/doc-guide-plugin - make_dir $h/test/doc-guide-crates - make_dir $h/test/doc-guide-error-handling - make_dir $h/test/doc-reference done # Configure submodules diff --git a/mk/crates.mk b/mk/crates.mk index cea92e19a2682..5b8772c4e0af5 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -57,7 +57,7 @@ RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \ rustc_trans rustc_back rustc_llvm HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros CRATES := $(TARGET_CRATES) $(HOST_CRATES) -TOOLS := compiletest rustdoc rustc +TOOLS := compiletest rustdoc rustc rustbook DEPS_core := DEPS_libc := core @@ -99,9 +99,11 @@ DEPS_fmt_macros = std TOOL_DEPS_compiletest := test getopts TOOL_DEPS_rustdoc := rustdoc TOOL_DEPS_rustc := rustc_driver +TOOL_DEPS_rustbook := std regex rustdoc TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs TOOL_SOURCE_rustc := $(S)src/driver/driver.rs +TOOL_SOURCE_rustbook := $(S)src/rustbook/main.rs ONLY_RLIB_core := 1 ONLY_RLIB_libc := 1 diff --git a/mk/docs.mk b/mk/docs.mk index 274598feada67..a84977b382b60 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -9,7 +9,7 @@ # except according to those terms. ###################################################################### -# The various pieces of standalone documentation: guides, manual, etc +# The various pieces of standalone documentation. # # The DOCS variable is their names (with no file extension). # @@ -25,13 +25,11 @@ # L10N_LANGS are the languages for which the docs have been # translated. ###################################################################### -DOCS := index intro tutorial guide guide-ffi guide-macros guide-ownership \ - guide-tasks guide-container guide-pointers guide-testing \ - guide-plugin guide-crates complement-bugreport guide-error-handling \ - complement-lang-faq complement-design-faq complement-project-faq \ - rustdoc guide-unsafe guide-strings reference +DOCS := index intro tutorial complement-bugreport \ + complement-lang-faq complement-design-faq complement-project-faq \ + rustdoc reference -PDF_DOCS := guide reference +PDF_DOCS := reference RUSTDOC_DEPS_reference := doc/full-toc.inc RUSTDOC_FLAGS_reference := --html-in-header=doc/full-toc.inc @@ -61,9 +59,15 @@ RUSTDOC_EXE = $(HBIN2_H_$(CFG_BUILD))/rustdoc$(X_$(CFG_BUILD)) # ./configure RUSTDOC = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTDOC_EXE) +# The rustbook executable... +RUSTBOOK_EXE = $(HBIN2_H_$(CFG_BUILD))/rustbook$(X_$(CFG_BUILD)) +# ...with rpath included in case --disable-rpath was provided to +# ./configure +RUSTBOOK = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTBOOK_EXE) + D := $(S)src/doc -DOC_TARGETS := +DOC_TARGETS := trpl COMPILER_DOC_TARGETS := DOC_L10N_TARGETS := @@ -270,3 +274,10 @@ endif docs: $(DOC_TARGETS) compiler-docs: $(COMPILER_DOC_TARGETS) + +trpl: tmp/trpl.ok + +tmp/trpl.ok: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) + $(Q)rm -rf doc/book + $(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book + $(Q)touch $@ diff --git a/mk/prepare.mk b/mk/prepare.mk index 52fbbef81bd78..6a5daeb690941 100644 --- a/mk/prepare.mk +++ b/mk/prepare.mk @@ -70,7 +70,7 @@ define PREPARE_MAN $(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1) endef -PREPARE_TOOLS = $(filter-out compiletest, $(TOOLS)) +PREPARE_TOOLS = $(filter-out compiletest rustbook, $(TOOLS)) # $(1) is tool diff --git a/mk/tests.mk b/mk/tests.mk index 714a9f8900547..97455e744d4bd 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -147,6 +147,17 @@ else CFG_ADB_TEST_DIR= endif +# $(1) - name of doc test +# $(2) - file of the test +define DOCTEST +DOC_NAMES := $$(DOC_NAMES) $(1) +DOCFILE_$(1) := $(2) +endef + +$(foreach doc,$(DOCS), \ + $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md))) +$(foreach file,$(wildcard $(S)src/doc/trpl/src/*), \ + $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/src/%.md=trpl-%),$(file)))) ###################################################################### # Main test targets @@ -292,6 +303,7 @@ tidy: | grep '^$(S)src/rust-installer' -v \ | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py + endif @@ -339,8 +351,8 @@ check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \ check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec) check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \ - $$(foreach docname,$$(DOCS), \ - check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) + $$(foreach docname,$$(DOC_NAMES), \ + check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) \ check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \ check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \ @@ -795,17 +807,18 @@ check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3) # rustdoc etc. ifeq ($(NO_REBUILD),) DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \ - $$(D)/$(4).md \ + $$(DOCFILE_$(4)) \ $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \ $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3)) else -DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md +DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(DOCFILE_$(4)) endif ifeq ($(2),$$(CFG_BUILD)) $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4)) @$$(call E, run doc-$(4) [$(2)]) - $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@ + $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \ + --test-args "$$(TESTARGS)" && touch $$@ else $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): touch $$@ @@ -815,7 +828,7 @@ endef $(foreach host,$(CFG_HOST), \ $(foreach target,$(CFG_TARGET), \ $(foreach stage,$(STAGES), \ - $(foreach docname,$(DOCS), \ + $(foreach docname,$(DOC_NAMES), \ $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname))))))) # Crates @@ -877,7 +890,7 @@ TEST_GROUPS = \ debuginfo-lldb \ codegen \ doc \ - $(foreach docname,$(DOCS),doc-$(docname)) \ + $(foreach docname,$(DOC_NAMES),doc-$(docname)) \ pretty \ pretty-rpass \ pretty-rpass-valgrind \ @@ -946,7 +959,7 @@ $(foreach stage,$(STAGES), \ $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group)))))) define DEF_CHECK_DOC_FOR_STAGE -check-stage$(1)-docs: $$(foreach docname,$$(DOCS), \ +check-stage$(1)-docs: $$(foreach docname,$$(DOC_NAMES), \ check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \ $$(foreach crate,$$(TEST_DOC_CRATES), \ check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate)) diff --git a/src/doc/guide-container.md b/src/doc/guide-container.md deleted file mode 100644 index e9bda17f4bc7d..0000000000000 --- a/src/doc/guide-container.md +++ /dev/null @@ -1,6 +0,0 @@ -% The Rust Containers and Iterators Guide - -This guide has been removed, with no direct replacement. - -You may enjoy reading the [iterator](std/iter/index.html) and -[collections](std/collections/index.html) documentation. diff --git a/src/doc/guide-strings.md b/src/doc/guide-strings.md deleted file mode 100644 index 43cc8483bcec5..0000000000000 --- a/src/doc/guide-strings.md +++ /dev/null @@ -1,308 +0,0 @@ -% The Guide to Rust Strings - -Strings are an important concept to master in any programming language. If you -come from a managed language background, you may be surprised at the complexity -of string handling in a systems programming language. Efficient access and -allocation of memory for a dynamically sized structure involves a lot of -details. Luckily, Rust has lots of tools to help us here. - -A **string** is a sequence of unicode scalar values encoded as a stream of -UTF-8 bytes. All strings are guaranteed to be validly-encoded UTF-8 sequences. -Additionally, strings are not null-terminated and can contain null bytes. - -Rust has two main types of strings: `&str` and `String`. - -# &str - -The first kind is a `&str`. This is pronounced a 'string slice'. -String literals are of the type `&str`: - -```{rust} -let string = "Hello there."; -``` - -Like any Rust type, string slices have an associated lifetime. A string literal -is a `&'static str`. A string slice can be written without an explicit -lifetime in many cases, such as in function arguments. In these cases the -lifetime will be inferred: - -```{rust} -fn takes_slice(slice: &str) { - println!("Got: {}", slice); -} -``` - -Like vector slices, string slices are simply a pointer plus a length. This -means that they're a 'view' into an already-allocated string, such as a -`&'static str` or a `String`. - -# String - -A `String` is a heap-allocated string. This string is growable, and is also -guaranteed to be UTF-8. - -```{rust} -let mut s = "Hello".to_string(); -println!("{}", s); - -s.push_str(", world."); -println!("{}", s); -``` - -You can coerce a `String` into a `&str` with the `as_slice()` method: - -```{rust} -fn takes_slice(slice: &str) { - println!("Got: {}", slice); -} - -fn main() { - let s = "Hello".to_string(); - takes_slice(s.as_slice()); -} -``` - -You can also get a `&str` from a stack-allocated array of bytes: - -```{rust} -use std::str; - -let x: &[u8] = &[b'a', b'b']; -let stack_str: &str = str::from_utf8(x).unwrap(); -``` - -# Best Practices - -## `String` vs. `&str` - -In general, you should prefer `String` when you need ownership, and `&str` when -you just need to borrow a string. This is very similar to using `Vec` vs. `&[T]`, -and `T` vs `&T` in general. - -This means starting off with this: - -```{rust,ignore} -fn foo(s: &str) { -``` - -and only moving to this: - -```{rust,ignore} -fn foo(s: String) { -``` - -If you have good reason. It's not polite to hold on to ownership you don't -need, and it can make your lifetimes more complex. - -## Generic functions - -To write a function that's generic over types of strings, use `&str`. - -```{rust} -fn some_string_length(x: &str) -> uint { - x.len() -} - -fn main() { - let s = "Hello, world"; - - println!("{}", some_string_length(s)); - - let s = "Hello, world".to_string(); - - println!("{}", some_string_length(s.as_slice())); -} -``` - -Both of these lines will print `12`. - -## Comparisons - -To compare a String to a constant string, prefer `as_slice()`... - -```{rust} -fn compare(x: String) { - if x.as_slice() == "Hello" { - println!("yes"); - } -} -``` - -... over `to_string()`: - -```{rust} -fn compare(x: String) { - if x == "Hello".to_string() { - println!("yes"); - } -} -``` - -Converting a `String` to a `&str` is cheap, but converting the `&str` to a -`String` involves an allocation. - -## Indexing strings - -You may be tempted to try to access a certain character of a `String`, like -this: - -```{rust,ignore} -let s = "hello".to_string(); - -println!("{}", s[0]); -``` - -This does not compile. This is on purpose. In the world of UTF-8, direct -indexing is basically never what you want to do. The reason is that each -character can be a variable number of bytes. This means that you have to iterate -through the characters anyway, which is an O(n) operation. - -There's 3 basic levels of unicode (and its encodings): - -- code units, the underlying data type used to store everything -- code points/unicode scalar values (char) -- graphemes (visible characters) - -Rust provides iterators for each of these situations: - -- `.bytes()` will iterate over the underlying bytes -- `.chars()` will iterate over the code points -- `.graphemes()` will iterate over each grapheme - -Usually, the `graphemes()` method on `&str` is what you want: - -```{rust} -let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé"; - -for l in s.graphemes(true) { - println!("{}", l); -} -``` - -This prints: - -```{text} -u͔ -n͈̰̎ -i̙̮͚̦ -c͚̉ -o̼̩̰͗ -d͔̆̓ͥ -é -``` - -Note that `l` has the type `&str` here, since a single grapheme can consist of -multiple codepoints, so a `char` wouldn't be appropriate. - -This will print out each visible character in turn, as you'd expect: first "u͔", then -"n͈̰̎", etc. If you wanted each individual codepoint of each grapheme, you can use `.chars()`: - -```{rust} -let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé"; - -for l in s.chars() { - println!("{}", l); -} -``` - -This prints: - -```{text} -u -͔ -n -̎ -͈ -̰ -i -̙ -̮ -͚ -̦ -c -̉ -͚ -o -͗ -̼ -̩ -̰ -d -̆ -̓ -ͥ -͔ -e -́ -``` - -You can see how some of them are combining characters, and therefore the output -looks a bit odd. - -If you want the individual byte representation of each codepoint, you can use -`.bytes()`: - -```{rust} -let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé"; - -for l in s.bytes() { - println!("{}", l); -} -``` - -This will print: - -```{text} -117 -205 -148 -110 -204 -142 -205 -136 -204 -176 -105 -204 -153 -204 -174 -205 -154 -204 -166 -99 -204 -137 -205 -154 -111 -205 -151 -204 -188 -204 -169 -204 -176 -100 -204 -134 -205 -131 -205 -165 -205 -148 -101 -204 -129 -``` - -Many more bytes than graphemes! - -# Other Documentation - -* [the `&str` API documentation](std/str/index.html) -* [the `String` API documentation](std/string/index.html) diff --git a/src/doc/guide.md b/src/doc/guide.md deleted file mode 100644 index 5ab3063033fc2..0000000000000 --- a/src/doc/guide.md +++ /dev/null @@ -1,5520 +0,0 @@ -% The Rust Guide - -Hey there! Welcome to the Rust guide. This is the place to be if you'd like to -learn how to program in Rust. Rust is a systems programming language with a -focus on "high-level, bare-metal programming": the lowest level control a -programming language can give you, but with zero-cost, higher level -abstractions, because people aren't computers. We really think Rust is -something special, and we hope you do too. - -To show you how to get going with Rust, we're going to write the traditional -"Hello, World!" program. Next, we'll introduce you to a tool that's useful for -writing real-world Rust programs and libraries: "Cargo." After that, we'll talk -about the basics of Rust, write a little program to try them out, and then learn -more advanced things. - -Sound good? Let's go! - -# Installing Rust - -The first step to using Rust is to install it! There are a number of ways to -install Rust, but the easiest is to use the `rustup` script. If you're on -Linux or a Mac, all you need to do is this (note that you don't need to type -in the `$`s, they just indicate the start of each command): - -```bash -$ curl -L https://static.rust-lang.org/rustup.sh | sudo sh -``` - -If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`, -please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script: - -```bash -$ curl -L https://static.rust-lang.org/rustup.sh -O -$ sudo sh rustup.sh -``` - -If you're on Windows, please download either the [32-bit -installer](https://static.rust-lang.org/dist/rust-nightly-i686-pc-windows-gnu.exe) -or the [64-bit -installer](https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-gnu.exe) -and run it. - -If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay. -Not every programming language is great for everyone. Just pass an argument to -the script: - -```bash -$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall -``` - -If you used the Windows installer, just re-run the `.exe` and it will give you -an uninstall option. - -You can re-run this script any time you want to update Rust. Which, at this -point, is often. Rust is still pre-1.0, and so people assume that you're using -a very recent Rust. - -This brings me to one other point: some people, and somewhat rightfully so, get -very upset when we tell you to `curl | sudo sh`. And they should be! Basically, -when you do this, you are trusting that the good people who maintain Rust -aren't going to hack your computer and do bad things. That's a good instinct! -If you're one of those people, please check out the documentation on [building -Rust from Source](https://github.com/rust-lang/rust#building-from-source), or -[the official binary downloads](http://www.rust-lang.org/install.html). And we -promise that this method will not be the way to install Rust forever: it's just -the easiest way to keep people updated while Rust is in its alpha state. - -Oh, we should also mention the officially supported platforms: - -* Windows (7, 8, Server 2008 R2) -* Linux (2.6.18 or later, various distributions), x86 and x86-64 -* OSX 10.7 (Lion) or greater, x86 and x86-64 - -We extensively test Rust on these platforms, and a few others, too, like -Android. But these are the ones most likely to work, as they have the most -testing. - -Finally, a comment about Windows. Rust considers Windows to be a first-class -platform upon release, but if we're honest, the Windows experience isn't as -integrated as the Linux/OS X experience is. We're working on it! If anything -does not work, it is a bug. Please let us know if that happens. Each and every -commit is tested against Windows just like any other platform. - -If you've got Rust installed, you can open up a shell, and type this: - -```bash -$ rustc --version -``` - -You should see some output that looks something like this: - -```bash -rustc 1.0.0-nightly (f11f3e7ba 2015-01-04 20:02:14 +0000) -``` - -If you did, Rust has been installed successfully! Congrats! - -If not, there are a number of places where you can get help. The easiest is -[the #rust IRC channel on irc.mozilla.org](irc://irc.mozilla.org/#rust), which -you can access through -[Mibbit](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust). Click -that link, and you'll be chatting with other Rustaceans (a silly nickname we -call ourselves), and we can help you out. Other great resources include [our -forum](http://discuss.rust-lang.org/), [the /r/rust -subreddit](http://www.reddit.com/r/rust), and [Stack -Overflow](http://stackoverflow.com/questions/tagged/rust). - -# Hello, world! - -Now that you have Rust installed, let's write your first Rust program. It's -traditional to make your first program in any new language one that prints the -text "Hello, world!" to the screen. The nice thing about starting with such a -simple program is that you can verify that your compiler isn't just installed, -but also working properly. And printing information to the screen is a pretty -common thing to do. - -The first thing that we need to do is make a file to put our code in. I like -to make a `projects` directory in my home directory, and keep all my projects -there. Rust does not care where your code lives. - -This actually leads to one other concern we should address: this guide will -assume that you have basic familiarity with the command line. Rust does not -require that you know a whole ton about the command line, but until the -language is in a more finished state, IDE support is spotty. Rust makes no -specific demands on your editing tooling, or where your code lives. - -With that said, let's make a directory in our projects directory. - -```{bash} -$ mkdir ~/projects -$ cd ~/projects -$ mkdir hello_world -$ cd hello_world -``` - -If you're on Windows and not using PowerShell, the `~` may not work. Consult -the documentation for your shell for more details. - -Let's make a new source file next. I'm going to use the syntax `editor -filename` to represent editing a file in these examples, but you should use -whatever method you want. We'll call our file `main.rs`: - -```{bash} -$ editor main.rs -``` - -Rust files always end in a `.rs` extension. If you're using more than one word -in your filename, use an underscore. `hello_world.rs` rather than -`helloworld.rs`. - -Now that you've got your file open, type this in: - -```{rust} -fn main() { - println!("Hello, world!"); -} -``` - -Save the file, and then type this into your terminal window: - -```{bash} -$ rustc main.rs -$ ./main # or main.exe on Windows -Hello, world! -``` - -You can also run these examples on [play.rust-lang.org](http://play.rust-lang.org/) by clicking on the arrow that appears in the upper right of the example when you mouse over the code. - -Success! Let's go over what just happened in detail. - -```{rust} -fn main() { - -} -``` - -These lines define a **function** in Rust. The `main` function is special: -it's the beginning of every Rust program. The first line says "I'm declaring a -function named `main`, which takes no arguments and returns nothing." If there -were arguments, they would go inside the parentheses (`(` and `)`), and because -we aren't returning anything from this function, we've dropped that notation -entirely. We'll get to it later. - -You'll also note that the function is wrapped in curly braces (`{` and `}`). -Rust requires these around all function bodies. It is also considered good -style to put the opening curly brace on the same line as the function -declaration, with one space in between. - -Next up is this line: - -```{rust} - println!("Hello, world!"); -``` - -This line does all of the work in our little program. There are a number of -details that are important here. The first is that it's indented with four -spaces, not tabs. Please configure your editor of choice to insert four spaces -with the tab key. We provide some [sample configurations for various -editors](https://github.com/rust-lang/rust/tree/master/src/etc). - -The second point is the `println!()` part. This is calling a Rust **macro**, -which is how metaprogramming is done in Rust. If it were a function instead, it -would look like this: `println()`. For our purposes, we don't need to worry -about this difference. Just know that sometimes, you'll see a `!`, and that -means that you're calling a macro instead of a normal function. Rust implements -`println!` as a macro rather than a function for good reasons, but that's a -very advanced topic. You'll learn more when we talk about macros later. One -last thing to mention: Rust's macros are significantly different from C macros, -if you've used those. Don't be scared of using macros. We'll get to the details -eventually, you'll just have to trust us for now. - -Next, `"Hello, world!"` is a **string**. Strings are a surprisingly complicated -topic in a systems programming language, and this is a **statically allocated** -string. We will talk more about different kinds of allocation later. We pass -this string as an argument to `println!`, which prints the string to the -screen. Easy enough! - -Finally, the line ends with a semicolon (`;`). Rust is an **expression -oriented** language, which means that most things are expressions. The `;` is -used to indicate that this expression is over, and the next one is ready to -begin. Most lines of Rust code end with a `;`. We will cover this in-depth -later in the guide. - -Finally, actually **compiling** and **running** our program. We can compile -with our compiler, `rustc`, by passing it the name of our source file: - -```{bash} -$ rustc main.rs -``` - -This is similar to `gcc` or `clang`, if you come from a C or C++ background. Rust -will output a binary executable. You can see it with `ls`: - -```{bash} -$ ls -main main.rs -``` - -Or on Windows: - -```{bash} -$ dir -main.exe main.rs -``` - -There are now two files: our source code, with the `.rs` extension, and the -executable (`main.exe` on Windows, `main` everywhere else) - -```{bash} -$ ./main # or main.exe on Windows -``` - -This prints out our `Hello, world!` text to our terminal. - -If you come from a dynamically typed language like Ruby, Python, or JavaScript, -you may not be used to these two steps being separate. Rust is an -**ahead-of-time compiled language**, which means that you can compile a -program, give it to someone else, and they don't need to have Rust installed. -If you give someone a `.rb` or `.py` or `.js` file, they need to have -Ruby/Python/JavaScript installed, but you just need one command to both compile -and run your program. Everything is a tradeoff in language design, and Rust has -made its choice. - -Congratulations! You have officially written a Rust program. That makes you a -Rust programmer! Welcome. - -Next, I'd like to introduce you to another tool, Cargo, which is used to write -real-world Rust programs. Just using `rustc` is nice for simple things, but as -your project grows, you'll want something to help you manage all of the options -that it has, and to make it easy to share your code with other people and -projects. - -# Hello, Cargo! - -[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their -Rust projects. Cargo is currently in an alpha state, just like Rust, and so it -is still a work in progress. However, it is already good enough to use for many -Rust projects, and so it is assumed that Rust projects will use Cargo from the -beginning. - -Cargo manages three things: building your code, downloading the dependencies -your code needs, and building the dependencies your code needs. At first, your -program doesn't have any dependencies, so we'll only be using the first part of -its functionality. Eventually, we'll add more. Since we started off by using -Cargo, it'll be easy to add later. - -If you installed Rust via the official installers you will also have -Cargo. If you installed Rust some other way, you may want to [check -the Cargo -README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies) -for specific instructions about installing it. - -Let's convert Hello World to Cargo. - -To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` -configuration file, and put our source file in the right place. Let's -do that part first: - -```{bash} -$ mkdir src -$ mv main.rs src/main.rs -``` - -Cargo expects your source files to live inside a `src` directory. That leaves -the top level for other things, like READMEs, license information, and anything -not related to your code. Cargo helps us keep our projects nice and tidy. A -place for everything, and everything in its place. - -Next, our configuration file: - -```{bash} -$ editor Cargo.toml -``` - -Make sure to get this name right: you need the capital `C`! - -Put this inside: - -```toml -[package] - -name = "hello_world" -version = "0.0.1" -authors = [ "Your name " ] - -[[bin]] - -name = "hello_world" -``` - -This file is in the [TOML](https://github.com/toml-lang/toml) format. Let's let -it explain itself to you: - -> TOML aims to be a minimal configuration file format that's easy to read due -> to obvious semantics. TOML is designed to map unambiguously to a hash table. -> TOML should be easy to parse into data structures in a wide variety of -> languages. - -TOML is very similar to INI, but with some extra goodies. - -Anyway, there are two **table**s in this file: `package` and `bin`. The first -tells Cargo metadata about your package. The second tells Cargo that we're -interested in building a binary, not a library (though we could do both!), as -well as what it is named. - -Once you have this file in place, we should be ready to build! Try this: - -```{bash} -$ cargo build - Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world) -$ ./target/hello_world -Hello, world! -``` - -Bam! We build our project with `cargo build`, and run it with -`./target/hello_world`. This hasn't bought us a whole lot over our simple use -of `rustc`, but think about the future: when our project has more than one -file, we would need to call `rustc` more than once, and pass it a bunch of options to -tell it to build everything together. With Cargo, as our project grows, we can -just `cargo build` and it'll work the right way. - -You'll also notice that Cargo has created a new file: `Cargo.lock`. - -```toml -[root] -name = "hello_world" -version = "0.0.1" -``` - -This file is used by Cargo to keep track of dependencies in your application. -Right now, we don't have any, so it's a bit sparse. You won't ever need -to touch this file yourself, just let Cargo handle it. - -That's it! We've successfully built `hello_world` with Cargo. Even though our -program is simple, it's using much of the real tooling that you'll use for the -rest of your Rust career. - -Now that you've got the tools down, let's actually learn more about the Rust -language itself. These are the basics that will serve you well through the rest -of your time with Rust. - -# Variable bindings - -The first thing we'll learn about are 'variable bindings.' They look like this: - -```{rust} -fn main() { - let x = 5; -} -``` - -Putting `fn main() {` in each example is a bit tedious, so we'll leave that out -in the future. If you're following along, make sure to edit your `main()` -function, rather than leaving it off. Otherwise, you'll get an error. - -In many languages, this is called a 'variable.' But Rust's variable bindings -have a few tricks up their sleeves. Rust has a very powerful feature called -'pattern matching' that we'll get into detail with later, but the left -hand side of a `let` expression is a full pattern, not just a variable name. -This means we can do things like: - -```{rust} -let (x, y) = (1, 2); -``` - -After this expression is evaluated, `x` will be one, and `y` will be two. -Patterns are really powerful, but this is about all we can do with them so far. -So let's just keep this in the back of our minds as we go forward. - -Rust is a statically typed language, which means that we specify our types up -front. So why does our first example compile? Well, Rust has this thing called -"type inference." If it can figure out what the type of something is, Rust -doesn't require you to actually type it out. - -We can add the type if we want to, though. Types come after a colon (`:`): - -```{rust} -let x: i32 = 5; -``` - -If I asked you to read this out loud to the rest of the class, you'd say "`x` -is a binding with the type `i32` and the value `five`." - -In future examples, we may annotate the type in a comment. The examples will -look like this: - -```{rust} -fn main() { - let x = 5; // x: i32 -} -``` - -Note the similarities between this annotation and the syntax you use with `let`. -Including these kinds of comments is not idiomatic Rust, but we'll occasionally -include them to help you understand what the types that Rust infers are. - -By default, bindings are **immutable**. This code will not compile: - -```{ignore} -let x = 5; -x = 10; -``` - -It will give you this error: - -```text -error: re-assignment of immutable variable `x` - x = 10; - ^~~~~~~ -``` - -If you want a binding to be mutable, you can use `mut`: - -```{rust} -let mut x = 5; // mut x: i32 -x = 10; -``` - -There is no single reason that bindings are immutable by default, but we can -think about it through one of Rust's primary focuses: safety. If you forget to -say `mut`, the compiler will catch it, and let you know that you have mutated -something you may not have intended to mutate. If bindings were mutable by -default, the compiler would not be able to tell you this. If you _did_ intend -mutation, then the solution is quite easy: add `mut`. - -There are other good reasons to avoid mutable state when possible, but they're -out of the scope of this guide. In general, you can often avoid explicit -mutation, and so it is preferable in Rust. That said, sometimes, mutation is -what you need, so it's not verboten. - -Let's get back to bindings. Rust variable bindings have one more aspect that -differs from other languages: bindings are required to be initialized with a -value before you're allowed to use them. If we try... - -```{ignore} -let x; -``` - -...we'll get an error: - -```text -src/main.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type -src/main.rs:2 let x; - ^ -``` - -Giving it a type will compile, though: - -```{rust} -let x: i32; -``` - -Let's try it out. Change your `src/main.rs` file to look like this: - -```{rust} -fn main() { - let x: i32; - - println!("Hello world!"); -} -``` - -You can use `cargo build` on the command line to build it. You'll get a warning, -but it will still print "Hello, world!": - -```text - Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world) -src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default -src/main.rs:2 let x: i32; - ^ -``` - -Rust warns us that we never use the variable binding, but since we never use it, -no harm, no foul. Things change if we try to actually use this `x`, however. Let's -do that. Change your program to look like this: - -```{rust,ignore} -fn main() { - let x: i32; - - println!("The value of x is: {}", x); -} -``` - -And try to build it. You'll get an error: - -```{bash} -$ cargo build - Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world) -src/main.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` -src/main.rs:4 println!("The value of x is: {}", x); - ^ -note: in expansion of format_args! -:2:23: 2:77 note: expansion site -:1:1: 3:2 note: in expansion of println! -src/main.rs:4:5: 4:42 note: expansion site -error: aborting due to previous error -Could not compile `hello_world`. -``` - -Rust will not let us use a value that has not been initialized. Next, let's -talk about this stuff we've added to `println!`. - -If you include two curly braces (`{}`, some call them moustaches...) in your -string to print, Rust will interpret this as a request to interpolate some sort -of value. **String interpolation** is a computer science term that means "stick -in the middle of a string." We add a comma, and then `x`, to indicate that we -want `x` to be the value we're interpolating. The comma is used to separate -arguments we pass to functions and macros, if you're passing more than one. - -When you just use the curly braces, Rust will attempt to display the -value in a meaningful way by checking out its type. If you want to specify the -format in a more detailed manner, there are a [wide number of options -available](std/fmt/index.html). For now, we'll just stick to the default: -integers aren't very complicated to print. - -# `if` - -Rust's take on `if` is not particularly complex, but it's much more like the -`if` you'll find in a dynamically typed language than in a more traditional -systems language. So let's talk about it, to make sure you grasp the nuances. - -`if` is a specific form of a more general concept, the 'branch.' The name comes -from a branch in a tree: a decision point, where depending on a choice, -multiple paths can be taken. - -In the case of `if`, there is one choice that leads down two paths: - -```rust -let x = 5; - -if x == 5 { - println!("x is five!"); -} -``` - -If we changed the value of `x` to something else, this line would not print. -More specifically, if the expression after the `if` evaluates to `true`, then -the block is executed. If it's `false`, then it is not. - -If you want something to happen in the `false` case, use an `else`: - -```{rust} -let x = 5; - -if x == 5 { - println!("x is five!"); -} else { - println!("x is not five :("); -} -``` - -This is all pretty standard. However, you can also do this: - - -```{rust} -let x = 5; - -let y = if x == 5 { - 10 -} else { - 15 -}; // y: i32 -``` - -Which we can (and probably should) write like this: - -```{rust} -let x = 5; - -let y = if x == 5 { 10 } else { 15 }; // y: i32 -``` - -This reveals two interesting things about Rust: it is an expression-based -language, and semicolons are different from semicolons in other 'curly brace -and semicolon'-based languages. These two things are related. - -## Expressions vs. Statements - -Rust is primarily an expression based language. There are only two kinds of -statements, and everything else is an expression. - -So what's the difference? Expressions return a value, and statements do not. -In many languages, `if` is a statement, and therefore, `let x = if ...` would -make no sense. But in Rust, `if` is an expression, which means that it returns -a value. We can then use this value to initialize the binding. - -Speaking of which, bindings are a kind of the first of Rust's two statements. -The proper name is a **declaration statement**. So far, `let` is the only kind -of declaration statement we've seen. Let's talk about that some more. - -In some languages, variable bindings can be written as expressions, not just -statements. Like Ruby: - -```{ruby} -x = y = 5 -``` - -In Rust, however, using `let` to introduce a binding is _not_ an expression. The -following will produce a compile-time error: - -```{ignore} -let x = (let y = 5); // expected identifier, found keyword `let` -``` - -The compiler is telling us here that it was expecting to see the beginning of -an expression, and a `let` can only begin a statement, not an expression. - -Note that assigning to an already-bound variable (e.g. `y = 5`) is still an -expression, although its value is not particularly useful. Unlike C, where an -assignment evaluates to the assigned value (e.g. `5` in the previous example), -in Rust the value of an assignment is the unit type `()` (which we'll cover later). - -The second kind of statement in Rust is the **expression statement**. Its -purpose is to turn any expression into a statement. In practical terms, Rust's -grammar expects statements to follow other statements. This means that you use -semicolons to separate expressions from each other. This means that Rust -looks a lot like most other languages that require you to use semicolons -at the end of every line, and you will see semicolons at the end of almost -every line of Rust code you see. - -What is this exception that makes us say 'almost?' You saw it already, in this -code: - -```{rust} -let x = 5; - -let y: i32 = if x == 5 { 10 } else { 15 }; -``` - -Note that I've added the type annotation to `y`, to specify explicitly that I -want `y` to be an integer. - -This is not the same as this, which won't compile: - -```{ignore} -let x = 5; - -let y: i32 = if x == 5 { 10; } else { 15; }; -``` - -Note the semicolons after the 10 and 15. Rust will give us the following error: - -```text -error: mismatched types: expected `i32` but found `()` (expected i32 but found ()) -``` - -We expected an integer, but we got `()`. `()` is pronounced 'unit', and is a -special type in Rust's type system. In Rust, `()` is _not_ a valid value for a -variable of type `i32`. It's only a valid value for variables of the type `()`, -which aren't very useful. Remember how we said statements don't return a value? -Well, that's the purpose of unit in this case. The semicolon turns any -expression into a statement by throwing away its value and returning unit -instead. - -There's one more time in which you won't see a semicolon at the end of a line -of Rust code. For that, we'll need our next concept: functions. - -# Functions - -You've already seen one function so far, the `main` function: - -```{rust} -fn main() { -} -``` - -This is the simplest possible function declaration. As we mentioned before, -`fn` says 'this is a function,' followed by the name, some parentheses because -this function takes no arguments, and then some curly braces to indicate the -body. Here's a function named `foo`: - -```{rust} -fn foo() { -} -``` - -So, what about taking arguments? Here's a function that prints a number: - -```{rust} -fn print_number(x: i32) { - println!("x is: {}", x); -} -``` - -Here's a complete program that uses `print_number`: - -```{rust} -fn main() { - print_number(5); -} - -fn print_number(x: i32) { - println!("x is: {}", x); -} -``` - -As you can see, function arguments work very similar to `let` declarations: -you add a type to the argument name, after a colon. - -Here's a complete program that adds two numbers together and prints them: - -```{rust} -fn main() { - print_sum(5, 6); -} - -fn print_sum(x: i32, y: i32) { - println!("sum is: {}", x + y); -} -``` - -You separate arguments with a comma, both when you call the function, as well -as when you declare it. - -Unlike `let`, you _must_ declare the types of function arguments. This does -not work: - -```{ignore} -fn print_number(x, y) { - println!("x is: {}", x + y); -} -``` - -You get this error: - -```text -hello.rs:5:18: 5:19 error: expected `:` but found `,` -hello.rs:5 fn print_number(x, y) { -``` - -This is a deliberate design decision. While full-program inference is possible, -languages which have it, like Haskell, often suggest that documenting your -types explicitly is a best-practice. We agree that forcing functions to declare -types while allowing for inference inside of function bodies is a wonderful -sweet spot between full inference and no inference. - -What about returning a value? Here's a function that adds one to an integer: - -```{rust} -fn add_one(x: i32) -> i32 { - x + 1 -} -``` - -Rust functions return exactly one value, and you declare the type after an -'arrow', which is a dash (`-`) followed by a greater-than sign (`>`). - -You'll note the lack of a semicolon here. If we added it in: - -```{ignore} -fn add_one(x: i32) -> i32 { - x + 1; -} -``` - -We would get an error: - -```text -error: not all control paths return a value -fn add_one(x: i32) -> i32 { - x + 1; -} - -help: consider removing this semicolon: - x + 1; - ^ -``` - -Remember our earlier discussions about semicolons and `()`? Our function claims -to return an `i32`, but with a semicolon, it would return `()` instead. Rust -realizes this probably isn't what we want, and suggests removing the semicolon. - -This is very much like our `if` statement before: the result of the block -(`{}`) is the value of the expression. Other expression-oriented languages, -such as Ruby, work like this, but it's a bit unusual in the systems programming -world. When people first learn about this, they usually assume that it -introduces bugs. But because Rust's type system is so strong, and because unit -is its own unique type, we have never seen an issue where adding or removing a -semicolon in a return position would cause a bug. - -But what about early returns? Rust does have a keyword for that, `return`: - -```{rust} -fn foo(x: i32) -> i32 { - if x < 5 { return x; } - - x + 1 -} -``` - -Using a `return` as the last line of a function works, but is considered poor -style: - -```{rust} -fn foo(x: i32) -> i32 { - if x < 5 { return x; } - - return x + 1; -} -``` - -There are some additional ways to define functions, but they involve features -that we haven't learned about yet, so let's just leave it at that for now. - - -# Comments - -Now that we have some functions, it's a good idea to learn about comments. -Comments are notes that you leave to other programmers to help explain things -about your code. The compiler mostly ignores them. - -Rust has two kinds of comments that you should care about: **line comment**s -and **doc comment**s. - -```{rust} -// Line comments are anything after '//' and extend to the end of the line. - -let x = 5; // this is also a line comment. - -// If you have a long explanation for something, you can put line comments next -// to each other. Put a space between the // and your comment so that it's -// more readable. -``` - -The other kind of comment is a doc comment. Doc comments use `///` instead of -`//`, and support Markdown notation inside: - -```{rust} -/// `hello` is a function that prints a greeting that is personalized based on -/// the name given. -/// -/// # Arguments -/// -/// * `name` - The name of the person you'd like to greet. -/// -/// # Example -/// -/// ```rust -/// let name = "Steve"; -/// hello(name); // prints "Hello, Steve!" -/// ``` -fn hello(name: &str) { - println!("Hello, {}!", name); -} -``` - -When writing doc comments, adding sections for any arguments, return values, -and providing some examples of usage is very, very helpful. - -You can use the [`rustdoc`](rustdoc.html) tool to generate HTML documentation -from these doc comments. - -# Compound Data Types - -Rust, like many programming languages, has a number of different data types -that are built-in. You've already done some simple work with integers and -strings, but next, let's talk about some more complicated ways of storing data. - -## Tuples - -The first compound data type we're going to talk about are called **tuple**s. -Tuples are an ordered list of a fixed size. Like this: - -```rust -let x = (1, "hello"); -``` - -The parentheses and commas form this two-length tuple. Here's the same code, but -with the type annotated: - -```rust -let x: (i32, &str) = (1, "hello"); -``` - -As you can see, the type of a tuple looks just like the tuple, but with each -position having a type name rather than the value. Careful readers will also -note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple. -You haven't seen `&str` as a type before, and we'll discuss the details of -strings later. In systems programming languages, strings are a bit more complex -than in other languages. For now, just read `&str` as "a string slice," and -we'll learn more soon. - -You can access the fields in a tuple through a **destructuring let**. Here's -an example: - -```rust -let (x, y, z) = (1, 2, 3); - -println!("x is {}", x); -``` - -Remember before when I said the left-hand side of a `let` statement was more -powerful than just assigning a binding? Here we are. We can put a pattern on -the left-hand side of the `let`, and if it matches up to the right-hand side, -we can assign multiple bindings at once. In this case, `let` 'destructures,' -or 'breaks up,' the tuple, and assigns the bits to three bindings. - -This pattern is very powerful, and we'll see it repeated more later. - -There are also a few things you can do with a tuple as a whole, without -destructuring. You can assign one tuple into another, if they have the same -arity and contained types. - -```rust -let mut x = (1, 2); // x: (i32, i32) -let y = (2, 3); // y: (i32, i32) - -x = y; -``` - -You can also check for equality with `==`. Again, this will only compile if the -tuples have the same type. - -```rust -let x = (1, 2, 3); -let y = (2, 2, 4); - -if x == y { - println!("yes"); -} else { - println!("no"); -} -``` - -This will print `no`, because some of the values aren't equal. - -One other use of tuples is to return multiple values from a function: - -```rust -fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) } - -fn main() { - let (x, y) = next_two(5); - println!("x, y = {}, {}", x, y); -} -``` - -Even though Rust functions can only return one value, a tuple _is_ one value, -that happens to be made up of more than one value. You can also see in this example how you -can destructure a pattern returned by a function, as well. - -Tuples are a very simple data structure, and so are not often what you want. -Let's move on to their bigger sibling, structs. - -## Structs - -A struct is another form of a 'record type,' just like a tuple. There's a -difference: structs give each element that they contain a name, called a -'field' or a 'member.' Check it out: - -```rust -struct Point { - x: i32, - y: i32, -} - -fn main() { - let origin = Point { x: 0, y: 0 }; // origin: Point - - println!("The origin is at ({}, {})", origin.x, origin.y); -} -``` - -There's a lot going on here, so let's break it down. We declare a struct with -the `struct` keyword, and then with a name. By convention, structs begin with a -capital letter and are also camel cased: `PointInSpace`, not `Point_In_Space`. - -We can create an instance of our struct via `let`, as usual, but we use a `key: -value` style syntax to set each field. The order doesn't need to be the same as -in the original declaration. - -Finally, because fields have names, we can access the field through dot -notation: `origin.x`. - -The values in structs are immutable by default, like other bindings in Rust. -Use `mut` to make them mutable: - -```{rust} -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut point = Point { x: 0, y: 0 }; - - point.x = 5; - - println!("The point is at ({}, {})", point.x, point.y); -} -``` - -This will print `The point is at (5, 0)`. - -## Tuple Structs and Newtypes - -Rust has another data type that's like a hybrid between a tuple and a struct, -called a **tuple struct**. Tuple structs do have a name, but their fields -don't: - - -```{rust} -struct Color(i32, i32, i32); -struct Point(i32, i32, i32); -``` - -These two will not be equal, even if they have the same values: - -```{rust} -# struct Color(i32, i32, i32); -# struct Point(i32, i32, i32); -let black = Color(0, 0, 0); -let origin = Point(0, 0, 0); -``` - -It is almost always better to use a struct than a tuple struct. We would write -`Color` and `Point` like this instead: - -```{rust} -struct Color { - red: i32, - blue: i32, - green: i32, -} - -struct Point { - x: i32, - y: i32, - z: i32, -} -``` - -Now, we have actual names, rather than positions. Good names are important, -and with a struct, we have actual names. - -There _is_ one case when a tuple struct is very useful, though, and that's a -tuple struct with only one element. We call this a 'newtype,' because it lets -you create a new type that's a synonym for another one: - -```{rust} -struct Inches(i32); - -let length = Inches(10); - -let Inches(integer_length) = length; -println!("length is {} inches", integer_length); -``` - -As you can see here, you can extract the inner integer type through a -destructuring `let`. - -## Enums - -Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful -feature of Rust, and are used throughout the standard library. This is an enum -that is provided by the Rust standard library: - -```{rust} -enum Ordering { - Less, - Equal, - Greater, -} -``` - -An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given -time. - -Because `Ordering` is provided by the standard library, we can use the `use` -keyword to use it in our code. We'll learn more about `use` later, but it's -used to bring names into scope. - -Here's an example of how to use `Ordering`: - -```{rust} -use std::cmp::Ordering; - -fn cmp(a: i32, b: i32) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} - -fn main() { - let x = 5; - let y = 10; - - let ordering = cmp(x, y); // ordering: Ordering - - if ordering == Ordering::Less { - println!("less"); - } else if ordering == Ordering::Greater { - println!("greater"); - } else if ordering == Ordering::Equal { - println!("equal"); - } -} -``` - -There's a symbol here we haven't seen before: the double colon (`::`). -This is used to indicate a namespace. In this case, `Ordering` lives in -the `cmp` submodule of the `std` module. We'll talk more about modules -later in the guide. For now, all you need to know is that you can `use` -things from the standard library if you need them. - -Okay, let's talk about the actual code in the example. `cmp` is a function that -compares two things, and returns an `Ordering`. We return either -`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on if -the two values are greater, less, or equal. Note that each variant of the -`enum` is namespaced under the `enum` itself: it's `Ordering::Greater` not -`Greater`. - -The `ordering` variable has the type `Ordering`, and so contains one of the -three values. We can then do a bunch of `if`/`else` comparisons to check which -one it is. However, repeated `if`/`else` comparisons get quite tedious. Rust -has a feature that not only makes them nicer to read, but also makes sure that -you never miss a case. Before we get to that, though, let's talk about another -kind of enum: one with values. - -This enum has two variants, one of which has a value: - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} -``` - -This enum represents an `i32` that we may or may not have. In the `Missing` -case, we have no value, but in the `Value` case, we do. This enum is specific -to `i32`s, though. We can make it usable by any type, but we haven't quite -gotten there yet! - -You can also have any number of values in an enum: - -```{rust} -enum OptionalColor { - Color(i32, i32, i32), - Missing, -} -``` - -And you can also have something like this: - -```{rust} -enum StringResult { - StringOK(String), - ErrorReason(String), -} -``` -Where a `StringResult` is either a `StringResult::StringOK`, with the result of -a computation, or an `StringResult::ErrorReason` with a `String` explaining -what caused the computation to fail. These kinds of `enum`s are actually very -useful and are even part of the standard library. - -Here is an example of using our `StringResult`: - -```rust -enum StringResult { - StringOK(String), - ErrorReason(String), -} - -fn respond(greeting: &str) -> StringResult { - if greeting == "Hello" { - StringResult::StringOK("Good morning!".to_string()) - } else { - StringResult::ErrorReason("I didn't understand you!".to_string()) - } -} -``` - -That's a lot of typing! We can use the `use` keyword to make it shorter: - -```rust -use StringResult::StringOK; -use StringResult::ErrorReason; - -enum StringResult { - StringOK(String), - ErrorReason(String), -} - -# fn main() {} - -fn respond(greeting: &str) -> StringResult { - if greeting == "Hello" { - StringOK("Good morning!".to_string()) - } else { - ErrorReason("I didn't understand you!".to_string()) - } -} -``` - -`use` declarations must come before anything else, which looks a little strange in this example, -since we `use` the variants before we define them. Anyway, in the body of `respond`, we can just -say `StringOK` now, rather than the full `StringResult::StringOK`. Importing variants can be -convenient, but can also cause name conflicts, so do this with caution. It's considered good style -to rarely import variants for this reason. - -As you can see, `enum`s with values are quite a powerful tool for data representation, -and can be even more useful when they're generic across types. Before we get to generics, -though, let's talk about how to use them with pattern matching, a tool that will -let us deconstruct this sum type (the type theory term for enums) in a very elegant -way and avoid all these messy `if`/`else`s. - -# Match - -Often, a simple `if`/`else` isn't enough, because you have more than two -possible options. Also, `else` conditions can get incredibly complicated, so -what's the solution? - -Rust has a keyword, `match`, that allows you to replace complicated `if`/`else` -groupings with something more powerful. Check it out: - -```{rust} -let x = 5; - -match x { - 1 => println!("one"), - 2 => println!("two"), - 3 => println!("three"), - 4 => println!("four"), - 5 => println!("five"), - _ => println!("something else"), -} -``` - -`match` takes an expression and then branches based on its value. Each 'arm' of -the branch is of the form `val => expression`. When the value matches, that arm's -expression will be evaluated. It's called `match` because of the term 'pattern -matching', which `match` is an implementation of. - -So what's the big advantage here? Well, there are a few. First of all, `match` -enforces 'exhaustiveness checking'. Do you see that last arm, the one with the -underscore (`_`)? If we remove that arm, Rust will give us an error: - -```text -error: non-exhaustive patterns: `_` not covered -``` - -In other words, Rust is trying to tell us we forgot a value. Because `x` is an -integer, Rust knows that it can have a number of different values – for example, -`6`. Without the `_`, however, there is no arm that could match, and so Rust refuses -to compile. `_` acts like a 'catch-all arm'. If none of the other arms match, -the arm with `_` will, and since we have this catch-all arm, we now have an arm -for every possible value of `x`, and so our program will compile successfully. - -`match` statements also destructure enums, as well. Remember this code from the -section on enums? - -```{rust} -use std::cmp::Ordering; - -fn cmp(a: i32, b: i32) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} - -fn main() { - let x = 5; - let y = 10; - - let ordering = cmp(x, y); - - if ordering == Ordering::Less { - println!("less"); - } else if ordering == Ordering::Greater { - println!("greater"); - } else if ordering == Ordering::Equal { - println!("equal"); - } -} -``` - -We can re-write this as a `match`: - -```{rust} -use std::cmp::Ordering; - -fn cmp(a: i32, b: i32) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} - -fn main() { - let x = 5; - let y = 10; - - match cmp(x, y) { - Ordering::Less => println!("less"), - Ordering::Greater => println!("greater"), - Ordering::Equal => println!("equal"), - } -} -``` - -This version has way less noise, and it also checks exhaustively to make sure -that we have covered all possible variants of `Ordering`. With our `if`/`else` -version, if we had forgotten the `Greater` case, for example, our program would -have happily compiled. If we forget in the `match`, it will not. Rust helps us -make sure to cover all of our bases. - -`match` expressions also allow us to get the values contained in an `enum` -(also known as destructuring) as follows: - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} - -fn main() { - let x = OptionalInt::Value(5); - let y = OptionalInt::Missing; - - match x { - OptionalInt::Value(n) => println!("x is {}", n), - OptionalInt::Missing => println!("x is missing!"), - } - - match y { - OptionalInt::Value(n) => println!("y is {}", n), - OptionalInt::Missing => println!("y is missing!"), - } -} -``` - -That is how you can get and use the values contained in `enum`s. -It can also allow us to handle errors or unexpected computations; for example, a -function that is not guaranteed to be able to compute a result (an `i32` here) -could return an `OptionalInt`, and we would handle that value with a `match`. -As you can see, `enum` and `match` used together are quite useful! - -`match` is also an expression, which means we can use it on the right-hand -side of a `let` binding or directly where an expression is used. We could -also implement the previous example like this: - -```{rust} -use std::cmp::Ordering; - -fn cmp(a: i32, b: i32) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} - -fn main() { - let x = 5; - let y = 10; - - println!("{}", match cmp(x, y) { - Ordering::Less => "less", - Ordering::Greater => "greater", - Ordering::Equal => "equal", - }); -} -``` - -Sometimes, it's a nice pattern. - -# Looping - -Looping is the last basic construct that we haven't learned yet in Rust. Rust has -two main looping constructs: `for` and `while`. - -## `for` - -The `for` loop is used to loop a particular number of times. Rust's `for` loops -work a bit differently than in other systems languages, however. Rust's `for` -loop doesn't look like this "C-style" `for` loop: - -```{c} -for (x = 0; x < 10; x++) { - printf( "%d\n", x ); -} -``` - -Instead, it looks like this: - -```{rust} -for x in range(0, 10) { - println!("{}", x); // x: i32 -} -``` - -In slightly more abstract terms, - -```{ignore} -for var in expression { - code -} -``` - -The expression is an iterator, which we will discuss in more depth later in the -guide. The iterator gives back a series of elements. Each element is one -iteration of the loop. That value is then bound to the name `var`, which is -valid for the loop body. Once the body is over, the next value is fetched from -the iterator, and we loop another time. When there are no more values, the -`for` loop is over. - -In our example, `range` is a function that takes a start and an end position, -and gives an iterator over those values. The upper bound is exclusive, though, -so our loop will print `0` through `9`, not `10`. - -Rust does not have the "C-style" `for` loop on purpose. Manually controlling -each element of the loop is complicated and error prone, even for experienced C -developers. - -We'll talk more about `for` when we cover **iterator**s, later in the Guide. - -## `while` - -The other kind of looping construct in Rust is the `while` loop. It looks like -this: - -```{rust} -let mut x = 5u; // mut x: uint -let mut done = false; // mut done: bool - -while !done { - x += x - 3; - println!("{}", x); - if x % 5 == 0 { done = true; } -} -``` - -`while` loops are the correct choice when you're not sure how many times -you need to loop. - -If you need an infinite loop, you may be tempted to write this: - -```{rust,ignore} -while true { -``` - -However, Rust has a dedicated keyword, `loop`, to handle this case: - -```{rust,ignore} -loop { -``` - -Rust's control-flow analysis treats this construct differently than a -`while true`, since we know that it will always loop. The details of what -that _means_ aren't super important to understand at this stage, but in -general, the more information we can give to the compiler, the better it -can do with safety and code generation, so you should always prefer -`loop` when you plan to loop infinitely. - -## Ending iteration early - -Let's take a look at that `while` loop we had earlier: - -```{rust} -let mut x = 5u; -let mut done = false; - -while !done { - x += x - 3; - println!("{}", x); - if x % 5 == 0 { done = true; } -} -``` - -We had to keep a dedicated `mut` boolean variable binding, `done`, to know -when we should exit out of the loop. Rust has two keywords to help us with -modifying iteration: `break` and `continue`. - -In this case, we can write the loop in a better way with `break`: - -```{rust} -let mut x = 5u; - -loop { - x += x - 3; - println!("{}", x); - if x % 5 == 0 { break; } -} -``` - -We now loop forever with `loop` and use `break` to break out early. - -`continue` is similar, but instead of ending the loop, goes to the next -iteration. This will only print the odd numbers: - -```{rust} -for x in range(0, 10) { - if x % 2 == 0 { continue; } - - println!("{}", x); -} -``` - -Both `continue` and `break` are valid in both kinds of loops. - -# Strings - -Strings are an important concept for any programmer to master. Rust's string -handling system is a bit different from other languages, due to its systems -focus. Any time you have a data structure of variable size, things can get -tricky, and strings are a re-sizable data structure. That being said, Rust's -strings also work differently than in some other systems languages, such as C. - -Let's dig into the details. A **string** is a sequence of Unicode scalar values -encoded as a stream of UTF-8 bytes. All strings are guaranteed to be -validly encoded UTF-8 sequences. Additionally, strings are not null-terminated -and can contain null bytes. - -Rust has two main types of strings: `&str` and `String`. - -The first kind is a `&str`. This is pronounced a 'string slice.' String literals -are of the type `&str`: - -```{rust} -let string = "Hello there."; // string: &str -``` - -This string is statically allocated, meaning that it's saved inside our -compiled program, and exists for the entire duration it runs. The `string` -binding is a reference to this statically allocated string. String slices -have a fixed size, and cannot be mutated. - -A `String`, on the other hand, is an in-memory string. This string is -growable, and is also guaranteed to be UTF-8. - -```{rust} -let mut s = "Hello".to_string(); // mut s: String -println!("{}", s); - -s.push_str(", world."); -println!("{}", s); -``` - -You can get a `&str` view into a `String` with the `as_slice()` method: - -```{rust} -fn takes_slice(slice: &str) { - println!("Got: {}", slice); -} - -fn main() { - let s = "Hello".to_string(); - takes_slice(s.as_slice()); -} -``` - -To compare a String to a constant string, prefer `as_slice()`... - -```{rust} -fn compare(string: String) { - if string.as_slice() == "Hello" { - println!("yes"); - } -} -``` - -... over `to_string()`: - -```{rust} -fn compare(string: String) { - if string == "Hello".to_string() { - println!("yes"); - } -} -``` - -Viewing a `String` as a `&str` is cheap, but converting the `&str` to a -`String` involves allocating memory. No reason to do that unless you have to! - -That's the basics of strings in Rust! They're probably a bit more complicated -than you are used to, if you come from a scripting language, but when the -low-level details matter, they really matter. Just remember that `String`s -allocate memory and control their data, while `&str`s are a reference to -another string, and you'll be all set. - -# Arrays, Vectors, and Slices - -Like many programming languages, Rust has list types to represent a sequence of -things. The most basic is the **array**, a fixed-size list of elements of the -same type. By default, arrays are immutable. - -```{rust} -let a = [1, 2, 3]; // a: [i32; 3] -let mut m = [1, 2, 3]; // mut m: [i32; 3] -``` - -There's a shorthand for initializing each element of an array to the same -value. In this example, each element of `a` will be initialized to `0`: - -```{rust} -let a = [0; 20]; // a: [i32; 20] -``` - -Arrays have type `[T; N]`. We'll talk about this `T` notation later, when we -cover generics. - -You can get the number of elements in an array `a` with `a.len()`, and use -`a.iter()` to iterate over them with a for loop. This code will print each -number in order: - -```{rust} -let a = [1, 2, 3]; - -println!("a has {} elements", a.len()); -for e in a.iter() { - println!("{}", e); -} -``` - -You can access a particular element of an array with **subscript notation**: - -```{rust} -let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3] - -println!("The second name is: {}", names[1]); -``` - -Subscripts start at zero, like in most programming languages, so the first name -is `names[0]` and the second name is `names[1]`. The above example prints -`The second name is: Brian`. If you try to use a subscript that is not in the -array, you will get an error: array access is bounds-checked at run-time. Such -errant access is the source of many bugs in other systems programming -languages. - -A **vector** is a dynamic or "growable" array, implemented as the standard -library type [`Vec`](std/vec/) (we'll talk about what the `` means -later). Vectors are to arrays what `String` is to `&str`. You can create them -with the `vec!` macro: - -```{rust} -let v = vec![1, 2, 3]; // v: Vec -``` - -(Notice that unlike the `println!` macro we've used in the past, we use square -brackets `[]` with `vec!`. Rust allows you to use either in either situation, -this is just convention.) - -You can get the length of, iterate over, and subscript vectors just like -arrays. In addition, (mutable) vectors can grow automatically: - -```{rust} -let mut nums = vec![1, 2, 3]; // mut nums: Vec - -nums.push(4); - -println!("The length of nums is now {}", nums.len()); // Prints 4 -``` - -Vectors have many more useful methods. - -A **slice** is a reference to (or "view" into) an array. They are useful for -allowing safe, efficient access to a portion of an array without copying. For -example, you might want to reference just one line of a file read into memory. -By nature, a slice is not created directly, but from an existing variable. -Slices have a length, can be mutable or not, and in many ways behave like -arrays: - -```{rust} -let a = [0, 1, 2, 3, 4]; -let middle = a.slice(1, 4); // A slice of a: just the elements [1,2,3] - -for e in middle.iter() { - println!("{}", e); // Prints 1, 2, 3 -} -``` - -You can also take a slice of a vector, `String`, or `&str`, because they are -backed by arrays. Slices have type `&[T]`, which we'll talk about when we cover -generics. - -We have now learned all of the most basic Rust concepts. We're ready to start -building our guessing game, we just need to know one last thing: how to get -input from the keyboard. You can't have a guessing game without the ability to -guess! - -# Standard Input - -Getting input from the keyboard is pretty easy, but uses some things -we haven't seen before. Here's a simple program that reads some input, -and then prints it back out: - -```{rust,ignore} -fn main() { - println!("Type something!"); - - let input = std::io::stdin().read_line().ok().expect("Failed to read line"); - - println!("{}", input); -} -``` - -Let's go over these chunks, one by one: - -```{rust,ignore} -std::io::stdin(); -``` - -This calls a function, `stdin()`, that lives inside the `std::io` module. As -you can imagine, everything in `std` is provided by Rust, the 'standard -library.' We'll talk more about the module system later. - -Since writing the fully qualified name all the time is annoying, we can use -the `use` statement to import it in: - -```{rust} -use std::io::stdin; - -stdin(); -``` - -However, it's considered better practice to not import individual functions, but -to import the module, and only use one level of qualification: - -```{rust} -use std::io; - -io::stdin(); -``` - -Let's update our example to use this style: - -```{rust,ignore} -use std::io; - -fn main() { - println!("Type something!"); - - let input = io::stdin().read_line().ok().expect("Failed to read line"); - - println!("{}", input); -} -``` - -Next up: - -```{rust,ignore} -.read_line() -``` - -The `read_line()` method can be called on the result of `stdin()` to return -a full line of input. Nice and easy. - -```{rust,ignore} -.ok().expect("Failed to read line"); -``` - -Do you remember this code? - -```{rust} -enum OptionalInt { - Value(i32), - Missing, -} - -fn main() { - let x = OptionalInt::Value(5); - let y = OptionalInt::Missing; - - match x { - OptionalInt::Value(n) => println!("x is {}", n), - OptionalInt::Missing => println!("x is missing!"), - } - - match y { - OptionalInt::Value(n) => println!("y is {}", n), - OptionalInt::Missing => println!("y is missing!"), - } -} -``` - -We had to match each time to see if we had a value or not. In this case, -though, we _know_ that `x` has a `Value`, but `match` forces us to handle -the `missing` case. This is what we want 99% of the time, but sometimes, we -know better than the compiler. - -Likewise, `read_line()` does not return a line of input. It _might_ return a -line of input, though it might also fail to do so. This could happen if our program -isn't running in a terminal, but as part of a cron job, or some other context -where there's no standard input. Because of this, `read_line` returns a type -very similar to our `OptionalInt`: an `IoResult`. We haven't talked about -`IoResult` yet because it is the **generic** form of our `OptionalInt`. -Until then, you can think of it as being the same thing, just for any type – -not just `i32`s. - -Rust provides a method on these `IoResult`s called `ok()`, which does the -same thing as our `match` statement but assumes that we have a valid value. -We then call `expect()` on the result, which will terminate our program if we -don't have a valid value. In this case, if we can't get input, our program -doesn't work, so we're okay with that. In most cases, we would want to handle -the error case explicitly. `expect()` allows us to give an error message if -this crash happens. - -We will cover the exact details of how all of this works later in the Guide. -For now, this gives you enough of a basic understanding to work with. - -Back to the code we were working on! Here's a refresher: - -```{rust,ignore} -use std::io; - -fn main() { - println!("Type something!"); - - let input = io::stdin().read_line().ok().expect("Failed to read line"); - - println!("{}", input); -} -``` - -With long lines like this, Rust gives you some flexibility with the whitespace. -We _could_ write the example like this: - -```{rust,ignore} -use std::io; - -fn main() { - println!("Type something!"); - - // here, we'll show the types at each step - - let input = io::stdin() // std::io::stdio::StdinReader - .read_line() // IoResult - .ok() // Option - .expect("Failed to read line"); // String - - println!("{}", input); -} -``` - -Sometimes, this makes things more readable – sometimes, less. Use your judgement -here. - -That's all you need to get basic input from the standard input! It's not too -complicated, but there are a number of small parts. - -# Guessing Game - -Okay! We've got the basics of Rust down. Let's write a bigger program. - -For our first project, we'll implement a classic beginner programming problem: -the guessing game. Here's how it works: Our program will generate a random -integer between one and a hundred. It will then prompt us to enter a guess. -Upon entering our guess, it will tell us if we're too low or too high. Once we -guess correctly, it will congratulate us. Sound good? - -## Set up - -Let's set up a new project. Go to your projects directory. Remember how we -had to create our directory structure and a `Cargo.toml` for `hello_world`? Cargo -has a command that does that for us. Let's give it a shot: - -```{bash} -$ cd ~/projects -$ cargo new guessing_game --bin -$ cd guessing_game -``` - -We pass the name of our project to `cargo new`, and then the `--bin` flag, -since we're making a binary, rather than a library. - -Check out the generated `Cargo.toml`: - -```toml -[package] - -name = "guessing_game" -version = "0.0.1" -authors = ["Your Name "] -``` - -Cargo gets this information from your environment. If it's not correct, go ahead -and fix that. - -Finally, Cargo generated a "Hello, world!" for us. Check out `src/main.rs`: - -```{rust} -fn main() { - println!("Hello, world!") -} -``` - -Let's try compiling what Cargo gave us: - -```{bash} -$ cargo build - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) -``` - -Excellent! Open up your `src/main.rs` again. We'll be writing all of -our code in this file. We'll talk about multiple-file projects later on in the -guide. - -Before we move on, let me show you one more Cargo command: `run`. `cargo run` -is kind of like `cargo build`, but it also then runs the produced executable. -Try it out: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Hello, world! -``` - -Great! The `run` command comes in handy when you need to rapidly iterate on a project. -Our game is just such a project, we need to quickly test each iteration before moving on to the next one. - -## Processing a Guess - -Let's get to it! The first thing we need to do for our guessing game is -allow our player to input a guess. Put this in your `src/main.rs`: - -```{rust,no_run} -use std::io; - -fn main() { - println!("Guess the number!"); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - println!("You guessed: {}", input); -} -``` - -You've seen this code before, when we talked about standard input. We -import the `std::io` module with `use`, and then our `main` function contains -our program's logic. We print a little message announcing the game, ask the -user to input a guess, get their input, and then print it out. - -Because we talked about this in the section on standard I/O, I won't go into -more details here. If you need a refresher, go re-read that section. - -## Generating a secret number - -Next, we need to generate a secret number. To do that, we need to use Rust's -random number generation, which we haven't talked about yet. Rust includes a -bunch of interesting functions in its standard library. If you need a bit of -code, it's possible that it's already been written for you! In this case, -we do know that Rust has random number generation, but we don't know how to -use it. - -Enter the docs. Rust has a page specifically to document the standard library. -You can find that page [here](std/index.html). There's a lot of information on -that page, but the best part is the search bar. Right up at the top, there's -a box that you can enter in a search term. The search is pretty primitive -right now, but is getting better all the time. If you type 'random' in that -box, the page will update to [this one](std/index.html?search=random). The very -first result is a link to [`std::rand::random`](std/rand/fn.random.html). If we -click on that result, we'll be taken to its documentation page. - -This page shows us a few things: the type signature of the function, some -explanatory text, and then an example. Let's try to modify our code to add in the -`random` function and see what happens: - -```{rust,ignore} -use std::io; -use std::rand; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random() % 100) + 1; // secret_number: i32 - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - - println!("You guessed: {}", input); -} -``` - -The first thing we changed was to `use std::rand`, as the docs -explained. We then added in a `let` expression to create a variable binding -named `secret_number`, and we printed out its result. - -Also, you may wonder why we are using `%` on the result of `rand::random()`. -This operator is called 'modulo', and it returns the remainder of a division. -By taking the modulo of the result of `rand::random()`, we're limiting the -values to be between 0 and 99. Then, we add one to the result, making it from 1 -to 100. Using modulo can give you a very, very small bias in the result, but -for this example, it is not important. - -Let's try to compile this using `cargo build`: - -```bash -$ cargo build - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) -src/main.rs:7:26: 7:34 error: the type of this value must be known in this context -src/main.rs:7 let secret_number = (rand::random() % 100) + 1; - ^~~~~~~~ -error: aborting due to previous error -``` - -It didn't work! Rust says "the type of this value must be known in this -context." What's up with that? Well, as it turns out, `rand::random()` can -generate many kinds of random values, not just integers. And in this case, Rust -isn't sure what kind of value `random()` should generate. So we have to help -it. With number literals, we can just add an `i32` onto the end to tell Rust they're -integers, but that does not work with functions. There's a different syntax, -and it looks like this: - -```{rust,ignore} -rand::random::(); -``` - -This says "please give me a random `i32` value." We can change our code to use -this hint: - -```{rust,no_run} -use std::io; -use std::rand; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100) + 1; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - - println!("You guessed: {}", input); -} -``` - -Try running our new program a few times: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 7 -Please input your guess. -4 -You guessed: 4 -$ ./target/guessing_game -Guess the number! -The secret number is: 83 -Please input your guess. -5 -You guessed: 5 -$ ./target/guessing_game -Guess the number! -The secret number is: -29 -Please input your guess. -42 -You guessed: 42 -``` - -Wait. Negative 29? We wanted a number between one and a hundred! We have two -options here: we can either ask `random()` to generate an unsigned integer, which -can only be positive, or we can use the `abs()` function. Let's go with the -unsigned integer approach. If we want a random positive number, we should ask for -a random positive number. Our code looks like this now: - -```{rust,no_run} -use std::io; -use std::rand; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - - println!("You guessed: {}", input); -} -``` - -And trying it out: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 57 -Please input your guess. -3 -You guessed: 3 -``` - -Great! Next up: let's compare our guess to the secret guess. - -## Comparing guesses - -If you remember, earlier in the guide, we made a `cmp` function that compared -two numbers. Let's add that in, along with a `match` statement to compare our -guess to the secret number: - -```{rust,ignore} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - - println!("You guessed: {}", input); - - match cmp(input, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } -} - -fn cmp(a: i32, b: i32) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -If we try to compile, we'll get some errors: - -```bash -$ cargo build - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) -src/main.rs:20:15: 20:20 error: mismatched types: expected `i32` but found `collections::string::String` (expected i32 but found struct collections::string::String) -src/main.rs:20 match cmp(input, secret_number) { - ^~~~~ -src/main.rs:20:22: 20:35 error: mismatched types: expected `i32` but found `uint` (expected i32 but found uint) -src/main.rs:20 match cmp(input, secret_number) { - ^~~~~~~~~~~~~ -error: aborting due to 2 previous errors -``` - -This often happens when writing Rust programs, and is one of Rust's greatest -strengths. You try out some code, see if it compiles, and Rust tells you that -you've done something wrong. In this case, our `cmp` function works on integers, -but we've given it unsigned integers. In this case, the fix is easy, because -we wrote the `cmp` function! Let's change it to take `uint`s: - -```{rust,ignore} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - - - println!("You guessed: {}", input); - - match cmp(input, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -And try compiling again: - -```bash -$ cargo build - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) -src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String) -src/main.rs:20 match cmp(input, secret_number) { - ^~~~~ -error: aborting due to previous error -``` - -This error is similar to the last one: we expected to get a `uint`, but we got -a `String` instead! That's because our `input` variable is coming from the -standard input, and you can guess anything. Try it: - -```bash -$ ./target/guessing_game -Guess the number! -The secret number is: 73 -Please input your guess. -hello -You guessed: hello -``` - -Oops! Also, you'll note that we just ran our program even though it didn't compile. -This works because the older version we did successfully compile was still lying -around. Gotta be careful! - -Anyway, we have a `String`, but we need a `uint`. What to do? Well, there's -a function for that: - -```{rust,ignore} -let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); -let input_num: Option = input.parse(); -``` - -The `parse` function takes in a `&str` value and converts it into something. -We tell it what kind of something with a type hint. Remember our type hint with -`random()`? It looked like this: - -```{rust,ignore} -rand::random::(); -``` - -There's an alternate way of providing a hint too, and that's declaring the type -in a `let`: - -```{rust,ignore} -let x: uint = rand::random(); -``` - -In this case, we say `x` is a `uint` explicitly, so Rust is able to properly -tell `random()` what to generate. In a similar fashion, both of these work: - -```{rust,ignore} -let input_num = "5".parse::(); // input_num: Option -let input_num: Option = "5".parse(); // input_num: Option -``` - -Anyway, with us now converting our input to a number, our code looks like this: - -```{rust,ignore} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.parse(); - - println!("You guessed: {}", input_num); - - match cmp(input_num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -Let's try it out! - -```bash -$ cargo build - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) -src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option` (expected uint but found enum core::option::Option) -src/main.rs:22 match cmp(input_num, secret_number) { - ^~~~~~~~~ -error: aborting due to previous error -``` - -Oh yeah! Our `input_num` has the type `Option`, rather than `uint`. We -need to unwrap the Option. If you remember from before, `match` is a great way -to do that. Try this code: - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - return; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -We use a `match` to either give us the `uint` inside of the `Option`, or else -print an error message and return. Let's give this a shot: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 17 -Please input your guess. -5 -Please input a number! -``` - -Uh, what? But we did! - -... actually, we didn't. See, when you get a line of input from `stdin()`, -you get all the input. Including the `\n` character from you pressing Enter. -Therefore, `parse()` sees the string `"5\n"` and says "nope, that's not a -number; there's non-number stuff in there!" Luckily for us, `&str`s have an easy -method we can use defined on them: `trim()`. One small modification, and our -code looks like this: - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - return; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -Let's try it! - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 58 -Please input your guess. - 76 -You guessed: 76 -Too big! -``` - -Nice! You can see I even added spaces before my guess, and it still figured -out that I guessed 76. Run the program a few times, and verify that guessing -the number works, as well as guessing a number too small. - -The Rust compiler helped us out quite a bit there! This technique is called -"lean on the compiler", and it's often useful when working on some code. Let -the error messages help guide you towards the correct types. - -Now we've got most of the game working, but we can only make one guess. Let's -change that by adding loops! - -## Looping - -As we already discussed, the `loop` keyword gives us an infinite loop. -Let's add that in: - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - loop { - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - return; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), - } - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -And try it out. But wait, didn't we just add an infinite loop? Yup. Remember -that `return`? If we give a non-number answer, we'll `return` and quit. Observe: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 59 -Please input your guess. -45 -You guessed: 45 -Too small! -Please input your guess. -60 -You guessed: 60 -Too big! -Please input your guess. -59 -You guessed: 59 -You win! -Please input your guess. -quit -Please input a number! -``` - -Ha! `quit` actually quits. As does any other non-number input. Well, this is -suboptimal to say the least. First, let's actually quit when you win the game: - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - loop { - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - return; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => { - println!("You win!"); - return; - }, - } - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -By adding the `return` line after the `You win!`, we'll exit the program when -we win. We have just one more tweak to make: when someone inputs a non-number, -we don't want to quit, we just want to ignore it. Change that `return` to -`continue`: - - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - println!("The secret number is: {}", secret_number); - - loop { - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - continue; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => { - println!("You win!"); - return; - }, - } - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -Now we should be good! Let's try: - -```bash -$ cargo run - Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) - Running `target/guessing_game` -Guess the number! -The secret number is: 61 -Please input your guess. -10 -You guessed: 10 -Too small! -Please input your guess. -99 -You guessed: 99 -Too big! -Please input your guess. -foo -Please input a number! -Please input your guess. -61 -You guessed: 61 -You win! -``` - -Awesome! With one tiny last tweak, we have finished the guessing game. Can you -think of what it is? That's right, we don't want to print out the secret number. -It was good for testing, but it kind of ruins the game. Here's our final source: - -```{rust,no_run} -use std::io; -use std::rand; -use std::cmp::Ordering; - -fn main() { - println!("Guess the number!"); - - let secret_number = (rand::random::() % 100u) + 1u; - - loop { - - println!("Please input your guess."); - - let input = io::stdin().read_line() - .ok() - .expect("Failed to read line"); - let input_num: Option = input.trim().parse(); - - let num = match input_num { - Some(num) => num, - None => { - println!("Please input a number!"); - continue; - } - }; - - - println!("You guessed: {}", num); - - match cmp(num, secret_number) { - Ordering::Less => println!("Too small!"), - Ordering::Greater => println!("Too big!"), - Ordering::Equal => { - println!("You win!"); - return; - }, - } - } -} - -fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Ordering::Less } - else if a > b { Ordering::Greater } - else { Ordering::Equal } -} -``` - -## Complete! - -At this point, you have successfully built the Guessing Game! Congratulations! - -You've now learned the basic syntax of Rust. All of this is relatively close to -various other programming languages you have used in the past. These -fundamental syntactical and semantic elements will form the foundation for the -rest of your Rust education. - -Now that you're an expert at the basics, it's time to learn about some of -Rust's more unique features. - -# Crates and Modules - -Rust features a strong module system, but it works a bit differently than in -other programming languages. Rust's module system has two main components: -**crate**s and **module**s. - -A crate is Rust's unit of independent compilation. Rust always compiles one -crate at a time, producing either a library or an executable. However, executables -usually depend on libraries, and many libraries depend on other libraries as well. -To support this, crates can depend on other crates. - -Each crate contains a hierarchy of modules. This tree starts off with a single -module, called the **crate root**. Within the crate root, we can declare other -modules, which can contain other modules, as deeply as you'd like. - -Note that we haven't mentioned anything about files yet. Rust does not impose a -particular relationship between your filesystem structure and your module -structure. That said, there is a conventional approach to how Rust looks for -modules on the file system, but it's also overridable. - -Enough talk, let's build something! Let's make a new project called `modules`. - -```{bash,ignore} -$ cd ~/projects -$ cargo new modules --bin -$ cd modules -``` - -Let's double check our work by compiling: - -```{bash} -$ cargo run - Compiling modules v0.0.1 (file:///home/you/projects/modules) - Running `target/modules` -Hello, world! -``` - -Excellent! We already have a single crate here: our `src/main.rs` is a crate. -Everything in that file is in the crate root. A crate that generates an executable -defines a `main` function inside its root, as we've done here. - -Let's define a new module inside our crate. Edit `src/main.rs` to look like this: - -``` -fn main() { - println!("Hello, world!") -} - -mod hello { - fn print_hello() { - println!("Hello, world!") - } -} -``` - -We now have a module named `hello` inside of our crate root. Modules use -`snake_case` naming, like functions and variable bindings. - -Inside the `hello` module, we've defined a `print_hello` function. This will -also print out our "hello world" message. Modules allow you to split up your -program into nice neat boxes of functionality, grouping common things together, -and keeping different things apart. It's kinda like having a set of shelves: -a place for everything and everything in its place. - -To call our `print_hello` function, we use the double colon (`::`): - -```{rust,ignore} -hello::print_hello(); -``` - -You've seen this before, with `io::stdin()` and `rand::random()`. Now you know -how to make your own. However, crates and modules have rules about -**visibility**, which controls who exactly may use the functions defined in a -given module. By default, everything in a module is private, which means that -it can only be used by other functions in the same module. This will not -compile: - -```{rust,ignore} -fn main() { - hello::print_hello(); -} - -mod hello { - fn print_hello() { - println!("Hello, world!") - } -} -``` - -It gives an error: - -```bash - Compiling modules v0.0.1 (file:///home/you/projects/modules) -src/main.rs:2:5: 2:23 error: function `print_hello` is private -src/main.rs:2 hello::print_hello(); - ^~~~~~~~~~~~~~~~~~ -``` - -To make it public, we use the `pub` keyword: - -```{rust} -fn main() { - hello::print_hello(); -} - -mod hello { - pub fn print_hello() { - println!("Hello, world!") - } -} -``` - -Usage of the `pub` keyword is sometimes called 'exporting', because -we're making the function available for other modules. This will work: - -```bash -$ cargo run - Compiling modules v0.0.1 (file:///home/you/projects/modules) - Running `target/modules` -Hello, world! -``` - -Nice! There are more things we can do with modules, including moving them into -their own files. This is enough detail for now. - -# Testing - -Traditionally, testing has not been a strong suit of most systems programming -languages. Rust, however, has very basic testing built into the language -itself. While automated testing cannot prove that your code is bug-free, it is -useful for verifying that certain behaviors work as intended. - -Here's a very basic test: - -```{rust} -#[test] -fn is_one_equal_to_one() { - assert_eq!(1, 1); -} -``` - -You may notice something new: that `#[test]`. Before we get into the mechanics -of testing, let's talk about attributes. - -## Attributes - -Rust's testing system uses **attribute**s to mark which functions are tests. -Attributes can be placed on any Rust **item**. Remember how most things in -Rust are an expression, but `let` is not? Item declarations are also not -expressions. Here's a list of things that qualify as an item: - -* functions -* modules -* type definitions -* structures -* enumerations -* static items -* traits -* implementations - -You haven't learned about all of these things yet, but that's the list. As -you can see, functions are at the top of it. - -Attributes can appear in three ways: - -1. A single identifier, the attribute name. `#[test]` is an example of this. -2. An identifier followed by an equals sign (`=`) and a literal. `#[cfg=test]` - is an example of this. -3. An identifier followed by a parenthesized list of sub-attribute arguments. - `#[cfg(unix, target_word_size = "32")]` is an example of this, where one of - the sub-arguments is of the second kind. - -There are a number of different kinds of attributes, enough that we won't go -over them all here. Before we talk about the testing-specific attributes, I -want to call out one of the most important kinds of attributes: stability -markers. - -## Stability attributes - -Rust provides six attributes to indicate the stability level of various -parts of your library. The six levels are: - -* deprecated: This item should no longer be used. No guarantee of backwards - compatibility. -* experimental: This item was only recently introduced or is otherwise in a - state of flux. It may change significantly, or even be removed. No guarantee - of backwards-compatibility. -* unstable: This item is still under development and requires more testing to - be considered stable. No guarantee of backwards-compatibility. -* stable: This item is considered stable, and will not change significantly. - Guarantee of backwards-compatibility. -* frozen: This item is very stable, and is unlikely to change. Guarantee of - backwards-compatibility. -* locked: This item will never change unless a serious bug is found. Guarantee - of backwards-compatibility. - -All of Rust's standard library uses these attribute markers to communicate -their relative stability, and you should use them in your code, as well. -There's an associated attribute, `warn`, that allows you to warn when you -import an item marked with certain levels: deprecated, experimental and -unstable. For now, only deprecated warns by default, but this will change once -the standard library has been stabilized. - -You can use the `warn` attribute like this: - -```{rust,ignore} -#![warn(unstable)] -``` - -And later, when you import a crate: - -```{rust,ignore} -extern crate some_crate; -``` - -You'll get a warning if you use something marked unstable. - -You may have noticed an exclamation point in the `warn` attribute declaration. -The `!` in this attribute means that this attribute applies to the enclosing -item, rather than to the item that follows the attribute. This `warn` -attribute declaration applies to the enclosing crate itself, rather than -to whatever item statement follows it: - -```{rust,ignore} -// applies to the crate we're in -#![warn(unstable)] - -extern crate some_crate; - -// applies to the following `fn`. -#[test] -fn a_test() { - // ... -} -``` - -## Writing tests - -Let's write a very simple crate in a test-driven manner. You know the drill by -now: make a new project: - -```{bash,ignore} -$ cd ~/projects -$ cargo new testing --bin -$ cd testing -``` - -And try it out: - -```bash -$ cargo run - Compiling testing v0.0.1 (file:///home/you/projects/testing) - Running `target/testing` -Hello, world! -``` - -Great. Rust's infrastructure supports tests in two sorts of places, and they're -for two kinds of tests: you include **unit test**s inside of the crate itself, -and you place **integration test**s inside a `tests` directory. "Unit tests" -are small tests that test one focused unit; "integration tests" test multiple -units in integration. That being said, this is a social convention – they're no -different in syntax. Let's make a `tests` directory: - -```{bash,ignore} -$ mkdir tests -``` - -Next, let's create an integration test in `tests/lib.rs`: - -```{rust,no_run} -#[test] -fn foo() { - assert!(false); -} -``` - -It doesn't matter what you name your test functions, though it's nice if -you give them descriptive names. You'll see why in a moment. We then use a -macro, `assert!`, to assert that something is true. In this case, we're giving -it `false`, so this test should fail. Let's try it! - -```bash -$ cargo test - Compiling testing v0.0.1 (file:///home/you/projects/testing) -/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default -/home/you/projects/testing/src/main.rs:1 fn main() { -/home/you/projects/testing/src/main.rs:2 println!("Hello, world!") -/home/you/projects/testing/src/main.rs:3 } - Running target/lib-654ce120f310a3a5 - -running 1 test -test foo ... FAILED - -failures: - ----- foo stdout ---- - thread 'foo' failed at 'assertion failed: false', /home/you/projects/testing/tests/lib.rs:3 - - - -failures: - foo - -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured - -thread '