From 73389f684fed8001f16ae999b18e57f45c56439d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 7 Apr 2016 15:12:13 -0400 Subject: [PATCH 01/11] add regression test for #32505 --- src/test/parse-fail/issue-32505.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/parse-fail/issue-32505.rs diff --git a/src/test/parse-fail/issue-32505.rs b/src/test/parse-fail/issue-32505.rs new file mode 100644 index 00000000000..e697e98bc06 --- /dev/null +++ b/src/test/parse-fail/issue-32505.rs @@ -0,0 +1,17 @@ +// 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. + +// compile-flags: -Z parse-only -Z continue-parse-after-error + +pub fn test() { + foo(|_|) //~ ERROR unexpected token: `)` +} + +fn main() { } From 69289c93666cad424627c0d696841c8f78e96448 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 8 Apr 2016 01:56:45 +0200 Subject: [PATCH 02/11] Add doc example for Iter and IterMut --- src/libcore/slice.rs | 166 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 162 insertions(+), 4 deletions(-) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 6e0e972fa0c..39ef2207187 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -38,6 +38,7 @@ use cmp::{Ordering, PartialEq, PartialOrd, Eq, Ord}; use cmp::Ordering::{Less, Equal, Greater}; use cmp; use default::Default; +use fmt; use intrinsics::assume; use iter::*; use ops::{FnMut, self, Index}; @@ -632,8 +633,7 @@ impl ops::Index> for [T] { #[inline] fn index(&self, index: ops::RangeToInclusive) -> &[T] { - // SNAP 4d3eebf change this to `0...index.end` - self.index(ops::RangeInclusive::NonEmpty { start: 0, end: index.end }) + self.index(0...index.end) } } @@ -723,8 +723,7 @@ impl ops::IndexMut> for [T] { impl ops::IndexMut> for [T] { #[inline] fn index_mut(&mut self, index: ops::RangeToInclusive) -> &mut [T] { - // SNAP 4d3eebf change this to `0...index.end` - self.index_mut(ops::RangeInclusive::NonEmpty { start: 0, end: index.end }) + self.index_mut(0...index.end) } } @@ -872,6 +871,20 @@ macro_rules! make_mut_slice { } /// Immutable slice iterator +/// +/// # Examples +/// +/// Basic usage: +/// +/// ``` +/// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize here]): +/// let slice = &[1, 2, 3]; +/// +/// // Then, we iterate over it: +/// for element in slice.iter() { +/// println!("{}", element); +/// } +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, T: 'a> { ptr: *const T, @@ -879,6 +892,15 @@ pub struct Iter<'a, T: 'a> { _marker: marker::PhantomData<&'a T>, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.as_slice()) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -889,6 +911,26 @@ 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. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// // First, we declare a type which has the `iter` method to get the `Iter` + /// // struct (&[usize here]): + /// let slice = &[1, 2, 3]; + /// + /// // Then, we get the iterator: + /// let mut iter = slice.iter(); + /// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]": + /// println!("{:?}", iter.as_slice()); + /// + /// // Next, we move to the second element of the slice: + /// iter.next(); + /// // Now `as_slice` returns "[2, 3]": + /// println!("{:?}", iter.as_slice()); + /// ``` #[stable(feature = "iter_to_slice", since = "1.4.0")] pub fn as_slice(&self) -> &'a [T] { make_slice!(self.ptr, self.end) @@ -920,6 +962,24 @@ impl<'a, T> Clone for Iter<'a, T> { } /// Mutable slice iterator. +/// +/// # Examples +/// +/// Basic usage: +/// +/// ``` +/// // First, we declare a type which has `iter_mut` method to get the `IterMut` +/// // struct (&[usize here]): +/// let mut slice = &mut [1, 2, 3]; +/// +/// // Then, we iterate over it and increment each element value: +/// for element in slice.iter_mut() { +/// *element += 1; +/// } +/// +/// // We now have "[2, 3, 4]": +/// println!("{:?}", slice); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct IterMut<'a, T: 'a> { ptr: *mut T, @@ -927,6 +987,15 @@ pub struct IterMut<'a, T: 'a> { _marker: marker::PhantomData<&'a mut T>, } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IterMut") + .field(&make_slice!(self.ptr, self.end)) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] @@ -939,6 +1008,35 @@ 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. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// // First, we declare a type which has `iter_mut` method to get the `IterMut` + /// // struct (&[usize here]): + /// let mut slice = &mut [1, 2, 3]; + /// + /// { + /// // Then, we get the iterator: + /// let mut iter = slice.iter_mut(); + /// // We move to next element: + /// iter.next(); + /// // So if we print what `into_slice` method returns here, we have "[2, 3]": + /// println!("{:?}", iter.into_slice()); + /// } + /// + /// // Now let's modify a value of the slice: + /// { + /// // First we get back the iterator: + /// let mut iter = slice.iter_mut(); + /// // We change the value of the first element of the slice returned by the `next` method: + /// *iter.next().unwrap() += 1; + /// } + /// // Now slice is "[2, 2, 3]": + /// println!("{:?}", slice); + /// ``` #[stable(feature = "iter_to_slice", since = "1.4.0")] pub fn into_slice(self) -> &'a mut [T] { make_mut_slice!(self.ptr, self.end) @@ -982,6 +1080,16 @@ pub struct Split<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for Split<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Split") + .field("v", &self.v) + .field("finished", &self.finished) + .finish() + } +} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, P> Clone for Split<'a, T, P> where P: Clone + FnMut(&T) -> bool { @@ -1055,6 +1163,16 @@ pub struct SplitMut<'a, T:'a, P> where P: FnMut(&T) -> bool { finished: bool } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitMut") + .field("v", &self.v) + .field("finished", &self.finished) + .finish() + } +} + impl<'a, T, P> SplitIter for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { #[inline] fn finish(&mut self) -> Option<&'a mut [T]> { @@ -1129,6 +1247,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where /// An private iterator over subslices separated by elements that /// match a predicate function, splitting at most a fixed number of /// times. +#[derive(Debug)] struct GenericSplitN { iter: I, count: usize, @@ -1164,6 +1283,15 @@ pub struct SplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitN<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitN") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. @@ -1172,6 +1300,15 @@ pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitN<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("RSplitN") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a predicate /// function, limited to a given number of splits. #[stable(feature = "rust1", since = "1.0.0")] @@ -1179,6 +1316,15 @@ pub struct SplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitNMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("SplitNMut") + .field("inner", &self.inner) + .finish() + } +} + /// An iterator over subslices separated by elements that match a /// predicate function, limited to a given number of splits, starting /// from the end of the slice. @@ -1187,6 +1333,15 @@ pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool { inner: GenericSplitN> } +#[stable(feature = "core_impl_debug", since = "1.9.0")] +impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for RSplitNMut<'a, T, P> where P: FnMut(&T) -> bool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("RSplitNMut") + .field("inner", &self.inner) + .finish() + } +} + macro_rules! forward_iterator { ($name:ident: $elem:ident, $iter_of:ty) => { #[stable(feature = "rust1", since = "1.0.0")] @@ -1214,6 +1369,7 @@ forward_iterator! { SplitNMut: T, &'a mut [T] } forward_iterator! { RSplitNMut: T, &'a mut [T] } /// An iterator over overlapping subslices of length `size`. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Windows<'a, T:'a> { v: &'a [T], @@ -1307,6 +1463,7 @@ impl<'a, T> ExactSizeIterator for Windows<'a, T> {} /// /// When the slice len is not evenly divided by the chunk size, the last slice /// of the iteration will be the remainder. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chunks<'a, T:'a> { v: &'a [T], @@ -1407,6 +1564,7 @@ impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} /// An iterator over a slice in (non-overlapping) mutable chunks (`size` /// elements at a time). When the slice len is not evenly divided by the chunk /// size, the last slice of the iteration will be the remainder. +#[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub struct ChunksMut<'a, T:'a> { v: &'a mut [T], From a6e86ec4dded4751ae2cc22478619c411388a519 Mon Sep 17 00:00:00 2001 From: pravic Date: Fri, 8 Apr 2016 11:24:19 +0300 Subject: [PATCH 03/11] Read "is-like-msvc" target option from JSON cc #32818 --- src/librustc_back/target/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index a8eac524971..bde88605e88 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -436,6 +436,7 @@ impl Target { key!(target_family, optional); key!(is_like_osx, bool); key!(is_like_windows, bool); + key!(is_like_msvc, bool); key!(linker_is_gnu, bool); key!(has_rpath, bool); key!(no_compiler_rt, bool); From 4d8fac078acad2944fb953359ee370eb57176d0f Mon Sep 17 00:00:00 2001 From: Alec S Date: Thu, 7 Apr 2016 23:50:37 -0500 Subject: [PATCH 04/11] Add data race to concurrency docs --- src/doc/book/concurrency.md | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/doc/book/concurrency.md b/src/doc/book/concurrency.md index ba4496b93f3..c179629a79a 100644 --- a/src/doc/book/concurrency.md +++ b/src/doc/book/concurrency.md @@ -162,7 +162,7 @@ The same [ownership system](ownership.html) that helps prevent using pointers incorrectly also helps rule out data races, one of the worst kinds of concurrency bugs. -As an example, here is a Rust program that could have a data race in many +As an example, here is a Rust program that would have a data race in many languages. It will not compile: ```ignore @@ -174,7 +174,7 @@ fn main() { for i in 0..3 { thread::spawn(move || { - data[i] += 1; + data[0] += i; }); } @@ -186,7 +186,7 @@ This gives us an error: ```text 8:17 error: capture of moved value: `data` - data[i] += 1; + data[0] += i; ^~~~ ``` @@ -195,11 +195,6 @@ thread, and the thread takes ownership of the reference, we'd have three owners! `data` gets moved out of `main` in the first call to `spawn()`, so subsequent calls in the loop cannot use this variable. -Note that this specific example will not cause a data race since different array -indices are being accessed. But this can't be determined at compile time, and in -a similar situation where `i` is a constant or is random, you would have a data -race. - So, we need some type that lets us have more than one owning reference to a value. Usually, we'd use `Rc` for this, which is a reference counted type that provides shared ownership. It has some runtime bookkeeping that keeps track @@ -223,7 +218,7 @@ fn main() { // use it in a thread thread::spawn(move || { - data_ref[i] += 1; + data_ref[0] += i; }); } @@ -266,7 +261,7 @@ fn main() { for i in 0..3 { let data = data.clone(); thread::spawn(move || { - data[i] += 1; + data[0] += i; }); } @@ -281,7 +276,7 @@ And... still gives us an error. ```text :11:24 error: cannot borrow immutable borrowed content as mutable -:11 data[i] += 1; +:11 data[0] += i; ^~~~ ``` @@ -317,7 +312,7 @@ fn main() { let data = data.clone(); thread::spawn(move || { let mut data = data.lock().unwrap(); - data[i] += 1; + data[0] += i; }); } @@ -360,7 +355,7 @@ Let's examine the body of the thread more closely: # let data = data.clone(); thread::spawn(move || { let mut data = data.lock().unwrap(); - data[i] += 1; + data[0] += i; }); # } # thread::sleep(Duration::from_millis(50)); From ca966b68e6a6e95d975e0511a16d38e058bbe449 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 9 Apr 2016 02:00:12 +0200 Subject: [PATCH 05/11] Add some missing commas and missing titles/formatting --- src/libcore/result.rs | 47 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 09f612c20ec..d59a80d4f0f 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -19,7 +19,7 @@ //! # #[allow(dead_code)] //! enum Result { //! Ok(T), -//! Err(E) +//! Err(E), //! } //! ``` //! @@ -39,7 +39,7 @@ //! None => Err("invalid header length"), //! Some(&1) => Ok(Version::Version1), //! Some(&2) => Ok(Version::Version2), -//! Some(_) => Err("invalid version") +//! Some(_) => Err("invalid version"), //! } //! } //! @@ -254,7 +254,7 @@ pub enum Result { /// Contains the error value #[stable(feature = "rust1", since = "1.0.0")] - Err(#[stable(feature = "rust1", since = "1.0.0")] E) + Err(#[stable(feature = "rust1", since = "1.0.0")] E), } ///////////////////////////////////////////////////////////////////////////// @@ -270,6 +270,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(-3); /// assert_eq!(x.is_ok(), true); @@ -290,6 +292,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(-3); /// assert_eq!(x.is_err(), false); @@ -314,6 +318,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// assert_eq!(x.ok(), Some(2)); @@ -337,6 +343,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// assert_eq!(x.err(), None); @@ -362,6 +370,10 @@ impl Result { /// Produces a new `Result`, containing a reference /// into the original, leaving the original in place. /// + /// # Examples + /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// assert_eq!(x.as_ref(), Ok(&2)); @@ -380,6 +392,10 @@ impl Result { /// Converts from `Result` to `Result<&mut T, &mut E>` /// + /// # Examples + /// + /// Basic usage: + /// /// ``` /// fn mutate(r: &mut Result) { /// match r.as_mut() { @@ -445,6 +461,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// fn stringify(x: u32) -> String { format!("error code: {}", x) } /// @@ -471,6 +489,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(7); /// assert_eq!(x.iter().next(), Some(&7)); @@ -488,6 +508,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let mut x: Result = Ok(7); /// match x.iter_mut().next() { @@ -513,6 +535,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// let y: Result<&str, &str> = Err("late error"); @@ -545,6 +569,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// fn sq(x: u32) -> Result { Ok(x * x) } /// fn err(x: u32) -> Result { Err(x) } @@ -567,6 +593,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// let y: Result = Err("late error"); @@ -599,6 +627,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// fn sq(x: u32) -> Result { Ok(x * x) } /// fn err(x: u32) -> Result { Err(x) } @@ -622,6 +652,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let optb = 2; /// let x: Result = Ok(9); @@ -644,6 +676,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// fn count(x: &str) -> usize { x.len() } /// @@ -670,6 +704,8 @@ impl Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(2); /// assert_eq!(x.unwrap(), 2); @@ -696,6 +732,9 @@ impl Result { /// passed message, and the content of the `Err`. /// /// # Examples + /// + /// Basic usage: + /// /// ```{.should_panic} /// let x: Result = Err("emergency failure"); /// x.expect("Testing expect"); // panics with `Testing expect: emergency failure` @@ -759,6 +798,8 @@ impl IntoIterator for Result { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// let x: Result = Ok(5); /// let v: Vec = x.into_iter().collect(); From 2944fab398155e65bd79f84f05b68195f7ca3e82 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 9 Apr 2016 01:06:57 +0000 Subject: [PATCH 06/11] Improve import resolution diagnostics --- src/librustc_resolve/resolve_imports.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 738a99fbe92..f0e834d4303 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -539,6 +539,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { (&Failed(_), &Failed(_)) => { let resolutions = target_module.resolutions.borrow(); let names = resolutions.iter().filter_map(|(&(ref name, _), resolution)| { + if *name == source { return None; } // Never suggest the same name match *resolution.borrow() { NameResolution { binding: Some(_), .. } => Some(name), NameResolution { single_imports: SingleImports::None, .. } => None, @@ -549,9 +550,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { Some(name) => format!(". Did you mean to use `{}`?", name), None => "".to_owned(), }; - let msg = format!("There is no `{}` in `{}`{}", - source, - module_to_string(target_module), lev_suggestion); + let module_str = module_to_string(target_module); + let msg = if &module_str == "???" { + format!("There is no `{}` in the crate root{}", source, lev_suggestion) + } else { + format!("There is no `{}` in `{}`{}", source, module_str, lev_suggestion) + }; return Failed(Some((directive.span, msg))); } _ => (), From 178c39632616fbf07038e4c1276b6fa127c36e51 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 9 Apr 2016 01:27:36 +0000 Subject: [PATCH 07/11] Update tests --- src/test/compile-fail/use-mod-2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/compile-fail/use-mod-2.rs b/src/test/compile-fail/use-mod-2.rs index e98224bee02..f2384912cdb 100644 --- a/src/test/compile-fail/use-mod-2.rs +++ b/src/test/compile-fail/use-mod-2.rs @@ -10,10 +10,10 @@ mod foo { use self::{self}; - //~^ ERROR unresolved import `self`. There is no `self` in `???` + //~^ ERROR unresolved import `self`. There is no `self` in the crate root use super::{self}; - //~^ ERROR unresolved import `super`. There is no `super` in `???` + //~^ ERROR unresolved import `super`. There is no `super` in the crate root } fn main() {} From 44ddaa2cd53782a3e654395c136a614e0601280f Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 9 Apr 2016 01:27:46 +0000 Subject: [PATCH 08/11] Add regression test --- src/test/compile-fail/issue-32833.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/compile-fail/issue-32833.rs diff --git a/src/test/compile-fail/issue-32833.rs b/src/test/compile-fail/issue-32833.rs new file mode 100644 index 00000000000..22261d98a12 --- /dev/null +++ b/src/test/compile-fail/issue-32833.rs @@ -0,0 +1,16 @@ +// Copyright 2016 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. + +use bar::Foo; //~ ERROR There is no `Foo` in `bar` [E0432] +mod bar { + use Foo; //~ ERROR There is no `Foo` in the crate root [E0432] +} + +fn main() {} From b2db97347bc4373deea24eb7b7c6ecffb117fd8c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sat, 9 Apr 2016 17:11:20 -0700 Subject: [PATCH 09/11] Bit-magic for faster is_char_boundary The asm generated for b < 128 || b >= 192 is not ideal, as it computes both sub-inequalities. This patch replaces it with bit magic. Fixes #32471 --- src/libcore/str/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 305546df5be..f1be10da872 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1940,7 +1940,8 @@ impl StrExt for str { if index == 0 || index == self.len() { return true; } match self.as_bytes().get(index) { None => false, - Some(&b) => b < 128 || b >= 192, + // This is bit magic equivalent to: b < 128 || b >= 192 + Some(&b) => (b as i8) >= -0x40, } } From 0fa0a6b67960bfd5636938b9140f647d5aed26f1 Mon Sep 17 00:00:00 2001 From: jethrogb Date: Sun, 10 Apr 2016 14:51:23 -0700 Subject: [PATCH 10/11] Fix Windows UNC paths in std::path docs --- src/libstd/path.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 5309cc3c858..f413bed86a8 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -466,7 +466,7 @@ enum State { Done = 3, } -/// A Windows path prefix, e.g. `C:` or `\server\share`. +/// A Windows path prefix, e.g. `C:` or `\\server\share`. /// /// Does not occur on Unix. #[stable(feature = "rust1", since = "1.0.0")] @@ -528,7 +528,7 @@ impl<'a> Hash for PrefixComponent<'a> { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub enum Component<'a> { - /// A Windows path prefix, e.g. `C:` or `\server\share`. + /// A Windows path prefix, e.g. `C:` or `\\server\share`. /// /// Does not occur on Unix. #[stable(feature = "rust1", since = "1.0.0")] From ed218f62b7b8688916f12e67784a49a7b683e582 Mon Sep 17 00:00:00 2001 From: jethrogb Date: Sun, 10 Apr 2016 22:28:24 -0700 Subject: [PATCH 11/11] Match signed/unsigned integer type docs * Copy documentation from signed implementation to unsigned implementation, where necessary. * Use signed integers in signed documentation, where possible. --- src/libcore/num/mod.rs | 94 ++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 229a864d712..9af8ef53851 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -149,7 +149,7 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// assert_eq!(u32::from_str_radix("A", 16), Ok(10)); + /// assert_eq!(i32::from_str_radix("A", 16), Ok(10)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_str_radix(src: &str, radix: u32) -> Result { @@ -163,9 +163,9 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0b01001100u8; + /// let n = -0b1000_0000i8; /// - /// assert_eq!(n.count_ones(), 3); + /// assert_eq!(n.count_ones(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -178,9 +178,9 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0b01001100u8; + /// let n = -0b1000_0000i8; /// - /// assert_eq!(n.count_zeros(), 5); + /// assert_eq!(n.count_zeros(), 7); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -196,9 +196,9 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0b0101000u16; + /// let n = -1i16; /// - /// assert_eq!(n.leading_zeros(), 10); + /// assert_eq!(n.leading_zeros(), 0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -214,9 +214,9 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0b0101000u16; + /// let n = -4i8; /// - /// assert_eq!(n.trailing_zeros(), 3); + /// assert_eq!(n.trailing_zeros(), 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -232,10 +232,10 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; - /// let m = 0x3456789ABCDEF012u64; + /// let n = 0x0123456789ABCDEFi64; + /// let m = -0x76543210FEDCBA99i64; /// - /// assert_eq!(n.rotate_left(12), m); + /// assert_eq!(n.rotate_left(32), m); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -252,10 +252,10 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; - /// let m = 0xDEF0123456789ABCu64; + /// let n = 0x0123456789ABCDEFi64; + /// let m = -0xFEDCBA987654322i64; /// - /// assert_eq!(n.rotate_right(12), m); + /// assert_eq!(n.rotate_right(4), m); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -270,8 +270,8 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; - /// let m = 0xEFCDAB8967452301u64; + /// let n = 0x0123456789ABCDEFi64; + /// let m = -0x1032547698BADCFFi64; /// /// assert_eq!(n.swap_bytes(), m); /// ``` @@ -291,12 +291,12 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; + /// let n = 0x0123456789ABCDEFi64; /// /// if cfg!(target_endian = "big") { - /// assert_eq!(u64::from_be(n), n) + /// assert_eq!(i64::from_be(n), n) /// } else { - /// assert_eq!(u64::from_be(n), n.swap_bytes()) + /// assert_eq!(i64::from_be(n), n.swap_bytes()) /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -315,12 +315,12 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; + /// let n = 0x0123456789ABCDEFi64; /// /// if cfg!(target_endian = "little") { - /// assert_eq!(u64::from_le(n), n) + /// assert_eq!(i64::from_le(n), n) /// } else { - /// assert_eq!(u64::from_le(n), n.swap_bytes()) + /// assert_eq!(i64::from_le(n), n.swap_bytes()) /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -339,7 +339,7 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; + /// let n = 0x0123456789ABCDEFi64; /// /// if cfg!(target_endian = "big") { /// assert_eq!(n.to_be(), n) @@ -363,7 +363,7 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; + /// let n = 0x0123456789ABCDEFi64; /// /// if cfg!(target_endian = "little") { /// assert_eq!(n.to_le(), n) @@ -385,8 +385,8 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// assert_eq!(5u16.checked_add(65530), Some(65535)); - /// assert_eq!(6u16.checked_add(65530), None); + /// assert_eq!(7i16.checked_add(32760), Some(32767)); + /// assert_eq!(8i16.checked_add(32760), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -421,8 +421,8 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// assert_eq!(5u8.checked_mul(51), Some(255)); - /// assert_eq!(5u8.checked_mul(52), None); + /// assert_eq!(6i8.checked_mul(21), Some(126)); + /// assert_eq!(6i8.checked_mul(22), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -753,8 +753,8 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// assert_eq!(1u8.wrapping_shl(7), 128); - /// assert_eq!(1u8.wrapping_shl(8), 1); + /// assert_eq!((-1i8).wrapping_shl(7), -128); + /// assert_eq!((-1i8).wrapping_shl(8), -1); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] #[inline(always)] @@ -778,8 +778,8 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// assert_eq!(128u8.wrapping_shr(7), 1); - /// assert_eq!(128u8.wrapping_shr(8), 128); + /// assert_eq!((-128i8).wrapping_shr(7), -1); + /// assert_eq!((-128i8).wrapping_shr(8), -128); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] #[inline(always)] @@ -1193,15 +1193,13 @@ macro_rules! uint_impl { /// /// Leading and trailing whitespace represent an error. /// - /// # Arguments + /// # Examples /// - /// * src - A string slice - /// * radix - The base to use. Must lie in the range [2 .. 36] + /// Basic usage: /// - /// # Return value - /// - /// `Err(ParseIntError)` if the string did not represent a valid number. - /// Otherwise, `Ok(n)` where `n` is the integer represented by `src`. + /// ``` + /// assert_eq!(u32::from_str_radix("A", 16), Ok(10)); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_str_radix(src: &str, radix: u32) -> Result { from_str_radix(src, radix) @@ -1745,7 +1743,7 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// assert_eq!(100i8.wrapping_rem(10), 0); + /// assert_eq!(100u8.wrapping_rem(10), 0); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] #[inline(always)] @@ -1783,6 +1781,13 @@ macro_rules! uint_impl { /// where `mask` removes any high-order bits of `rhs` that /// would cause the shift to exceed the bitwidth of the type. /// + /// Note that this is *not* the same as a rotate-left; the + /// RHS of a wrapping shift-left is restricted to the range + /// of the type, rather than the bits shifted out of the LHS + /// being returned to the other end. The primitive integer + /// types all implement a `rotate_left` function, which may + /// be what you want instead. + /// /// # Examples /// /// Basic usage: @@ -1801,6 +1806,13 @@ macro_rules! uint_impl { /// where `mask` removes any high-order bits of `rhs` that /// would cause the shift to exceed the bitwidth of the type. /// + /// Note that this is *not* the same as a rotate-right; the + /// RHS of a wrapping shift-right is restricted to the range + /// of the type, rather than the bits shifted out of the LHS + /// being returned to the other end. The primitive integer + /// types all implement a `rotate_right` function, which may + /// be what you want instead. + /// /// # Examples /// /// Basic usage: