Auto merge of #42212 - Mark-Simulacrum:rollup, r=Mark-Simulacrum

Rollup of 15 pull requests

- Successful merges: #41980, #42071, #42120, #42134, #42141, #42142, #42149, #42150, #42159, #42177, #42186, #42191, #42195, #42198, #42211
- Failed merges:
This commit is contained in:
bors 2017-05-25 01:51:35 +00:00
commit cf747fcbf7
279 changed files with 600 additions and 640 deletions

29
src/Cargo.lock generated
View file

@ -151,7 +151,6 @@ dependencies = [
"advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cargotest 0.1.0",
"chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crates-io 0.9.0",
"crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -219,15 +218,6 @@ name = "cfg-if"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "clap"
version = "2.19.3"
@ -969,11 +959,6 @@ dependencies = [
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex"
version = "0.1.80"
@ -1844,17 +1829,6 @@ dependencies = [
name = "tidy"
version = "0.1.0"
[[package]]
name = "time"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.1.30"
@ -2048,7 +2022,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f382711e76b9de6c744cc00d0497baba02fb00a787f088c879f01d09468e32"
"checksum cargo 0.20.0 (git+https://github.com/rust-lang/cargo)" = "<none>"
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9123be86fd2a8f627836c235ecdf331fdd067ecf7ac05aa1a68fbcf2429f056"
"checksum clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95b78f3fe0fc94c13c731714363260e04b557a637166f33a4570d3189d642374"
"checksum cmake 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "92278eb79412c8f75cfc89e707a1bb3a6490b68f7f2e78d15c774f30fe701122"
"checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97"
@ -2119,7 +2092,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum racer 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b0d72b3afd67882adfca61d609fafb8d7aa5f9e814f12c32fcc6e171995920e8"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum redox_syscall 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "29dbdfd4b9df8ab31dec47c6087b7b13cbf4a776f335e4de8efba8288dda075b"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
@ -2163,7 +2135,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df7875b676fddfadffd96deea3b1124e5ede707d4884248931077518cf1f773"
"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
"checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7"
"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3"
"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796"
"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4"
"checksum toml 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bd86ad9ebee246fdedd610e0f6d0587b754a3d81438db930a244d0480ed7878f"

View file

@ -127,13 +127,13 @@ def unpack(tarball, dst, verbose=False, match=None):
shutil.move(tp, fp)
shutil.rmtree(os.path.join(dst, fname))
def run(args, verbose=False, exception=False, cwd=None):
def run(args, verbose=False, exception=False, cwd=None, env=None):
if verbose:
print("running: " + ' '.join(args))
sys.stdout.flush()
# Use Popen here instead of call() as it apparently allows powershell on
# Windows to not lock up waiting for input presumably.
ret = subprocess.Popen(args, cwd=cwd)
ret = subprocess.Popen(args, cwd=cwd, env=env)
code = ret.wait()
if code != 0:
err = "failed to run: " + ' '.join(args)
@ -385,17 +385,15 @@ class RustBuild(object):
raise Exception("no cargo executable found at `%s`" % self.cargo())
args = [self.cargo(), "build", "--manifest-path",
os.path.join(self.rust_root, "src/bootstrap/Cargo.toml")]
if self.verbose:
args.append("--verbose")
if self.verbose > 1:
args.append("--verbose")
if self.use_locked_deps:
args.append("--locked")
if self.use_vendored_sources:
args.append("--frozen")
self.run(args, env)
def run(self, args, env=None, cwd=None):
proc = subprocess.Popen(args, env=env, cwd=cwd)
ret = proc.wait()
if ret != 0:
sys.exit(ret)
run(args, env=env, verbose=self.verbose)
def output(self, args, env=None, cwd=None):
default_encoding = sys.getdefaultencoding()
@ -567,7 +565,7 @@ class RustBuild(object):
path = line[1:].split(' ')[1]
submodules.append([path, line[0]])
self.run(["git", "submodule", "sync"], cwd=self.rust_root)
run(["git", "submodule", "sync"], cwd=self.rust_root)
for submod in submodules:
path, status = submod
@ -580,15 +578,15 @@ class RustBuild(object):
submod_path = os.path.join(self.rust_root, path)
if status == ' ':
self.run(["git", "reset", "--hard"], cwd=submod_path)
self.run(["git", "clean", "-fdx"], cwd=submod_path)
run(["git", "reset", "--hard"], cwd=submod_path)
run(["git", "clean", "-fdx"], cwd=submod_path)
elif status == '+':
self.run(["git", "submodule", "update", path], cwd=self.rust_root)
self.run(["git", "reset", "--hard"], cwd=submod_path)
self.run(["git", "clean", "-fdx"], cwd=submod_path)
run(["git", "submodule", "update", path], cwd=self.rust_root)
run(["git", "reset", "--hard"], cwd=submod_path)
run(["git", "clean", "-fdx"], cwd=submod_path)
elif status == '-':
self.run(["git", "submodule", "init", path], cwd=self.rust_root)
self.run(["git", "submodule", "update", path], cwd=self.rust_root)
run(["git", "submodule", "init", path], cwd=self.rust_root)
run(["git", "submodule", "update", path], cwd=self.rust_root)
else:
raise ValueError('unknown submodule status: ' + status)
@ -620,6 +618,11 @@ def bootstrap():
except:
pass
if '\nverbose = 2' in rb.config_toml:
rb.verbose = 2
elif '\nverbose = 1' in rb.config_toml:
rb.verbose = 1
rb.use_vendored_sources = '\nvendor = true' in rb.config_toml or \
'CFG_ENABLE_VENDOR' in rb.config_mk
@ -676,7 +679,7 @@ def bootstrap():
env["BUILD"] = rb.build
env["SRC"] = rb.rust_root
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
rb.run(args, env)
run(args, env=env, verbose=rb.verbose)
def main():
start_time = time()

View file

@ -64,6 +64,7 @@ if [ ! -d "$cache_src_dir/.git" ]; then
git clone https://github.com/rust-lang/rust.git $cache_src_dir"
fi
retry sh -c "cd $cache_src_dir && git reset --hard && git pull"
(cd $cache_src_dir && git rm src/llvm)
retry sh -c "cd $cache_src_dir && \
git submodule deinit -f . && git submodule sync && git submodule update --init"
@ -76,6 +77,15 @@ touch "$cache_valid_file"
# http://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
for module in $modules; do
if [ "$module" = src/llvm ]; then
commit="$(git ls-tree HEAD src/llvm | awk '{print $3}')"
git rm src/llvm
curl -sSL -O "https://github.com/rust-lang/llvm/archive/$commit.tar.gz"
tar -C src/ -xf "$commit.tar.gz"
rm "$commit.tar.gz"
mv "src/llvm-$commit" src/llvm
continue
fi
if [ ! -d "$cache_src_dir/$module" ]; then
echo "WARNING: $module not found in pristine repo"
retry sh -c "git submodule deinit -f $module && git submodule update --init $module"

View file

@ -106,16 +106,10 @@ impl<T> RangeArgument<T> for Range<T> {
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
impl<T> RangeArgument<T> for RangeInclusive<T> {
fn start(&self) -> Bound<&T> {
match *self {
RangeInclusive::Empty{ ref at } => Included(at),
RangeInclusive::NonEmpty { ref start, .. } => Included(start),
}
Included(&self.start)
}
fn end(&self) -> Bound<&T> {
match *self {
RangeInclusive::Empty{ ref at } => Excluded(at),
RangeInclusive::NonEmpty { ref end, .. } => Included(end),
}
Included(&self.end)
}
}

View file

@ -403,61 +403,35 @@ impl<A: Step + Clone> Iterator for StepBy<A, ops::RangeInclusive<A>> {
#[inline]
fn next(&mut self) -> Option<A> {
use ops::RangeInclusive::*;
let rev = self.step_by.is_negative();
// this function has a sort of odd structure due to borrowck issues
// we may need to replace self.range, so borrows of start and end need to end early
let (finishing, n) = match self.range {
Empty { .. } => return None, // empty iterators yield no values
NonEmpty { ref mut start, ref mut end } => {
let rev = self.step_by.is_negative();
// march start towards (maybe past!) end and yield the old value
if (rev && start >= end) ||
(!rev && start <= end)
{
match start.step(&self.step_by) {
Some(mut n) => {
mem::swap(start, &mut n);
(None, Some(n)) // yield old value, remain non-empty
},
None => {
let mut n = end.clone();
mem::swap(start, &mut n);
(None, Some(n)) // yield old value, remain non-empty
}
}
} else {
// found range in inconsistent state (start at or past end), so become empty
(Some(end.replace_zero()), None)
}
if (rev && self.range.start >= self.range.end) ||
(!rev && self.range.start <= self.range.end)
{
match self.range.start.step(&self.step_by) {
Some(n) => {
Some(mem::replace(&mut self.range.start, n))
},
None => {
let last = self.range.start.replace_one();
self.range.end.replace_zero();
self.step_by.replace_one();
Some(last)
},
}
};
// turn into an empty iterator if we've reached the end
if let Some(end) = finishing {
self.range = Empty { at: end };
}
n
else {
None
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
use ops::RangeInclusive::*;
match self.range {
Empty { .. } => (0, Some(0)),
NonEmpty { ref start, ref end } =>
match Step::steps_between(start,
end,
&self.step_by) {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)),
None => (0, None)
}
match Step::steps_between(&self.range.start,
&self.range.end,
&self.step_by) {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)),
None => (0, None)
}
}
}
@ -583,56 +557,31 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> where
#[inline]
fn next(&mut self) -> Option<A> {
use ops::RangeInclusive::*;
use cmp::Ordering::*;
// this function has a sort of odd structure due to borrowck issues
// we may need to replace self, so borrows of self.start and self.end need to end early
let (finishing, n) = match *self {
Empty { .. } => (None, None), // empty iterators yield no values
NonEmpty { ref mut start, ref mut end } => {
if start == end {
(Some(end.replace_one()), Some(start.replace_one()))
} else if start < end {
let mut n = start.add_one();
mem::swap(&mut n, start);
// if the iterator is done iterating, it will change from
// NonEmpty to Empty to avoid unnecessary drops or clones,
// we'll reuse either start or end (they are equal now, so
// it doesn't matter which) to pull out end, we need to swap
// something back in
(if n == *end { Some(end.replace_one()) } else { None },
// ^ are we done yet?
Some(n)) // < the value to output
} else {
(Some(start.replace_one()), None)
}
}
};
// turn into an empty iterator if this is the last value
if let Some(end) = finishing {
*self = Empty { at: end };
match self.start.partial_cmp(&self.end) {
Some(Less) => {
let n = self.start.add_one();
Some(mem::replace(&mut self.start, n))
},
Some(Equal) => {
let last = self.start.replace_one();
self.end.replace_zero();
Some(last)
},
_ => None,
}
n
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
use ops::RangeInclusive::*;
if !(self.start <= self.end) {
return (0, Some(0));
}
match *self {
Empty { .. } => (0, Some(0)),
NonEmpty { ref start, ref end } =>
match Step::steps_between_by_one(start, end) {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)),
None => (0, None),
}
match Step::steps_between_by_one(&self.start, &self.end) {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)),
None => (0, None),
}
}
}
@ -644,33 +593,20 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> where
{
#[inline]
fn next_back(&mut self) -> Option<A> {
use ops::RangeInclusive::*;
use cmp::Ordering::*;
// see Iterator::next for comments
let (finishing, n) = match *self {
Empty { .. } => return None,
NonEmpty { ref mut start, ref mut end } => {
if start == end {
(Some(start.replace_one()), Some(end.replace_one()))
} else if start < end {
let mut n = end.sub_one();
mem::swap(&mut n, end);
(if n == *start { Some(start.replace_one()) } else { None },
Some(n))
} else {
(Some(end.replace_one()), None)
}
}
};
if let Some(start) = finishing {
*self = Empty { at: start };
match self.start.partial_cmp(&self.end) {
Some(Less) => {
let n = self.end.sub_one();
Some(mem::replace(&mut self.end, n))
},
Some(Equal) => {
let last = self.end.replace_zero();
self.start.replace_one();
Some(last)
},
_ => None,
}
n
}
}

View file

@ -120,7 +120,7 @@ pub trait Sized {
/// [coerceunsized]: ../ops/trait.CoerceUnsized.html
/// [rc]: ../../std/rc/struct.Rc.html
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
/// [nomicon-coerce]: ../../nomicon/coercions.html
#[unstable(feature = "unsize", issue = "27732")]
#[lang="unsize"]
pub trait Unsize<T: ?Sized> {

View file

@ -153,6 +153,13 @@ use marker::Unsize;
/// The `Drop` trait is used to run some code when a value goes out of scope.
/// This is sometimes called a 'destructor'.
///
/// When a value goes out of scope, if it implements this trait, it will have
/// its `drop` method called. Then any fields the value contains will also
/// be dropped recursively.
///
/// Because of the recursive dropping, you do not need to implement this trait
/// unless your type needs its own destructor logic.
///
/// # Examples
///
/// A trivial implementation of `Drop`. The `drop` method is called when `_x`
@ -171,6 +178,43 @@ use marker::Unsize;
/// let _x = HasDrop;
/// }
/// ```
///
/// Showing the recursive nature of `Drop`. When `outer` goes out of scope, the
/// `drop` method will be called first for `Outer`, then for `Inner`. Therefore
/// `main` prints `Dropping Outer!` and then `Dropping Inner!`.
///
/// ```
/// struct Inner;
/// struct Outer(Inner);
///
/// impl Drop for Inner {
/// fn drop(&mut self) {
/// println!("Dropping Inner!");
/// }
/// }
///
/// impl Drop for Outer {
/// fn drop(&mut self) {
/// println!("Dropping Outer!");
/// }
/// }
///
/// fn main() {
/// let _x = Outer(Inner);
/// }
/// ```
///
/// Because variables are dropped in the reverse order they are declared,
/// `main` will print `Declared second!` and then `Declared first!`.
///
/// ```
/// struct PrintOnDrop(&'static str);
///
/// fn main() {
/// let _first = PrintOnDrop("Declared first!");
/// let _second = PrintOnDrop("Declared second!");
/// }
/// ```
#[lang = "drop"]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Drop {
@ -2271,7 +2315,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// ```
/// #![feature(inclusive_range,inclusive_range_syntax)]
/// fn main() {
/// assert_eq!((3...5), std::ops::RangeInclusive::NonEmpty{ start: 3, end: 5 });
/// assert_eq!((3...5), std::ops::RangeInclusive{ start: 3, end: 5 });
/// assert_eq!(3+4+5, (3...5).sum());
///
/// let arr = [0, 1, 2, 3];
@ -2281,45 +2325,23 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// ```
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
pub enum RangeInclusive<Idx> {
/// Empty range (iteration has finished)
pub struct RangeInclusive<Idx> {
/// The lower bound of the range (inclusive).
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
Empty {
/// The point at which iteration finished
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
at: Idx
},
/// Non-empty range (iteration will yield value(s))
pub start: Idx,
/// The upper bound of the range (inclusive).
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
NonEmpty {
/// The lower bound of the range (inclusive).
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
start: Idx,
/// The upper bound of the range (inclusive).
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
end: Idx,
},
pub end: Idx,
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use self::RangeInclusive::*;
match *self {
Empty { ref at } => write!(fmt, "[empty range @ {:?}]", at),
NonEmpty { ref start, ref end } => write!(fmt, "{:?}...{:?}", start, end),
}
write!(fmt, "{:?}...{:?}", self.start, self.end)
}
}
@ -2341,9 +2363,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// }
/// ```
pub fn contains(&self, item: Idx) -> bool {
if let &RangeInclusive::NonEmpty{ref start, ref end} = self {
(*start <= item) && (item <= *end)
} else { false }
self.start <= item && item <= self.end
}
}

View file

@ -981,95 +981,82 @@ impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {
#[inline]
fn get(self, slice: &[T]) -> Option<&[T]> {
match self {
ops::RangeInclusive::Empty { .. } => Some(&[]),
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() => None,
ops::RangeInclusive::NonEmpty { start, end } => (start..end + 1).get(slice),
}
if self.end == usize::max_value() { None }
else { (self.start..self.end + 1).get(slice) }
}
#[inline]
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
match self {
ops::RangeInclusive::Empty { .. } => Some(&mut []),
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() => None,
ops::RangeInclusive::NonEmpty { start, end } => (start..end + 1).get_mut(slice),
}
if self.end == usize::max_value() { None }
else { (self.start..self.end + 1).get_mut(slice) }
}
#[inline]
unsafe fn get_unchecked(self, slice: &[T]) -> &[T] {
match self {
ops::RangeInclusive::Empty { .. } => &[],
ops::RangeInclusive::NonEmpty { start, end } => (start..end + 1).get_unchecked(slice),
}
(self.start..self.end + 1).get_unchecked(slice)
}
#[inline]
unsafe fn get_unchecked_mut(self, slice: &mut [T]) -> &mut [T] {
match self {
ops::RangeInclusive::Empty { .. } => &mut [],
ops::RangeInclusive::NonEmpty { start, end } => {
(start..end + 1).get_unchecked_mut(slice)
}
}
(self.start..self.end + 1).get_unchecked_mut(slice)
}
#[inline]
fn index(self, slice: &[T]) -> &[T] {
match self {
ops::RangeInclusive::Empty { .. } => &[],
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() => {
panic!("attempted to index slice up to maximum usize");
},
ops::RangeInclusive::NonEmpty { start, end } => (start..end + 1).index(slice),
}
assert!(self.end != usize::max_value(),
"attempted to index slice up to maximum usize");
(self.start..self.end + 1).index(slice)
}
#[inline]
fn index_mut(self, slice: &mut [T]) -> &mut [T] {
match self {
ops::RangeInclusive::Empty { .. } => &mut [],
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() => {
panic!("attempted to index slice up to maximum usize");
},
ops::RangeInclusive::NonEmpty { start, end } => (start..end + 1).index_mut(slice),
}
assert!(self.end != usize::max_value(),
"attempted to index slice up to maximum usize");
(self.start..self.end + 1).index_mut(slice)
}
}
#[cfg(stage0)] // The bootstrap compiler has a different `...` desugar
fn inclusive(start: usize, end: usize) -> ops::RangeInclusive<usize> {
ops::RangeInclusive { start, end }
}
#[cfg(not(stage0))]
fn inclusive(start: usize, end: usize) -> ops::RangeInclusive<usize> {
start...end
}
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
type Output = [T];
#[inline]
fn get(self, slice: &[T]) -> Option<&[T]> {
(0...self.end).get(slice)
inclusive(0, self.end).get(slice)
}
#[inline]
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
(0...self.end).get_mut(slice)
inclusive(0, self.end).get_mut(slice)
}
#[inline]
unsafe fn get_unchecked(self, slice: &[T]) -> &[T] {
(0...self.end).get_unchecked(slice)
inclusive(0, self.end).get_unchecked(slice)
}
#[inline]
unsafe fn get_unchecked_mut(self, slice: &mut [T]) -> &mut [T] {
(0...self.end).get_unchecked_mut(slice)
inclusive(0, self.end).get_unchecked_mut(slice)
}
#[inline]
fn index(self, slice: &[T]) -> &[T] {
(0...self.end).index(slice)
inclusive(0, self.end).index(slice)
}
#[inline]
fn index_mut(self, slice: &mut [T]) -> &mut [T] {
(0...self.end).index_mut(slice)
inclusive(0, self.end).index_mut(slice)
}
}

View file

@ -1724,15 +1724,12 @@ mod traits {
#[inline]
fn index(&self, index: ops::RangeInclusive<usize>) -> &str {
match index {
ops::RangeInclusive::Empty { .. } => "",
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() =>
panic!("attempted to index slice up to maximum usize"),
ops::RangeInclusive::NonEmpty { start, end } =>
self.index(start .. end+1)
}
assert!(index.end != usize::max_value(),
"attempted to index str up to maximum usize");
self.index(index.start .. index.end+1)
}
}
#[unstable(feature = "inclusive_range",
reason = "recently added, follows RFC",
issue = "28237")]
@ -1741,7 +1738,9 @@ mod traits {
#[inline]
fn index(&self, index: ops::RangeToInclusive<usize>) -> &str {
self.index(0...index.end)
assert!(index.end != usize::max_value(),
"attempted to index str up to maximum usize");
self.index(.. index.end+1)
}
}
@ -1751,13 +1750,9 @@ mod traits {
impl ops::IndexMut<ops::RangeInclusive<usize>> for str {
#[inline]
fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut str {
match index {
ops::RangeInclusive::Empty { .. } => &mut self[0..0], // `&mut ""` doesn't work
ops::RangeInclusive::NonEmpty { end, .. } if end == usize::max_value() =>
panic!("attempted to index str up to maximum usize"),
ops::RangeInclusive::NonEmpty { start, end } =>
self.index_mut(start .. end+1)
}
assert!(index.end != usize::max_value(),
"attempted to index str up to maximum usize");
self.index_mut(index.start .. index.end+1)
}
}
#[unstable(feature = "inclusive_range",
@ -1766,7 +1761,9 @@ mod traits {
impl ops::IndexMut<ops::RangeToInclusive<usize>> for str {
#[inline]
fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut str {
self.index_mut(0...index.end)
assert!(index.end != usize::max_value(),
"attempted to index str up to maximum usize");
self.index_mut(.. index.end+1)
}
}
@ -1948,45 +1945,27 @@ mod traits {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.get(slice)
(self.start..self.end+1).get(slice)
}
#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.get_mut(slice)
(self.start..self.end+1).get_mut(slice)
}
#[inline]
unsafe fn get_unchecked(self, slice: &str) -> &Self::Output {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.get_unchecked(slice)
(self.start..self.end+1).get_unchecked(slice)
}
#[inline]
unsafe fn get_unchecked_mut(self, slice: &mut str) -> &mut Self::Output {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.get_unchecked_mut(slice)
(self.start..self.end+1).get_unchecked_mut(slice)
}
#[inline]
fn index(self, slice: &str) -> &Self::Output {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.index(slice)
(self.start..self.end+1).index(slice)
}
#[inline]
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
match self {
ops::RangeInclusive::Empty { .. } => 0..0,
ops::RangeInclusive::NonEmpty { start, end } => start..end+1,
}.index_mut(slice)
(self.start..self.end+1).index_mut(slice)
}
}

View file

@ -22,6 +22,7 @@
#![feature(fmt_internals)]
#![feature(iterator_step_by)]
#![feature(i128_type)]
#![feature(inclusive_range)]
#![feature(iter_rfind)]
#![feature(libc)]
#![feature(nonzero)]

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::ops::{Range, RangeFull, RangeFrom, RangeTo};
use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive};
// Test the Range structs without the syntactic sugar.
@ -47,3 +47,24 @@ fn test_full_range() {
// Not much to test.
let _ = RangeFull;
}
#[test]
fn test_range_inclusive() {
let mut r = RangeInclusive { start: 1i8, end: 2 };
assert_eq!(r.next(), Some(1));
assert_eq!(r.next(), Some(2));
assert_eq!(r.next(), None);
r = RangeInclusive { start: 127i8, end: 127 };
assert_eq!(r.next(), Some(127));
assert_eq!(r.next(), None);
r = RangeInclusive { start: -128i8, end: -128 };
assert_eq!(r.next_back(), Some(-128));
assert_eq!(r.next_back(), None);
// degenerate
r = RangeInclusive { start: 1, end: -1 };
assert_eq!(r.size_hint(), (0, Some(0)));
assert_eq!(r.next(), None);
}

View file

@ -1934,13 +1934,13 @@ impl<'a> LoweringContext<'a> {
ExprKind::Range(ref e1, ref e2, lims) => {
use syntax::ast::RangeLimits::*;
let (path, variant) = match (e1, e2, lims) {
(&None, &None, HalfOpen) => ("RangeFull", None),
(&Some(..), &None, HalfOpen) => ("RangeFrom", None),
(&None, &Some(..), HalfOpen) => ("RangeTo", None),
(&Some(..), &Some(..), HalfOpen) => ("Range", None),
(&None, &Some(..), Closed) => ("RangeToInclusive", None),
(&Some(..), &Some(..), Closed) => ("RangeInclusive", Some("NonEmpty")),
let path = match (e1, e2, lims) {
(&None, &None, HalfOpen) => "RangeFull",
(&Some(..), &None, HalfOpen) => "RangeFrom",
(&None, &Some(..), HalfOpen) => "RangeTo",
(&Some(..), &Some(..), HalfOpen) => "Range",
(&None, &Some(..), Closed) => "RangeToInclusive",
(&Some(..), &Some(..), Closed) => "RangeInclusive",
(_, &None, Closed) =>
panic!(self.diagnostic().span_fatal(
e.span, "inclusive range with no end")),
@ -1957,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
let is_unit = fields.is_empty();
let unstable_span = self.allow_internal_unstable("...", e.span);
let struct_path =
iter::once("ops").chain(iter::once(path)).chain(variant)
iter::once("ops").chain(iter::once(path))
.collect::<Vec<_>>();
let struct_path = self.std_path(unstable_span, &struct_path, is_unit);
let struct_path = hir::QPath::Resolved(None, P(struct_path));

View file

@ -118,8 +118,7 @@ const BUG_REPORT_URL: &'static str = "https://github.com/rust-lang/rust/blob/mas
fn abort_msg(err_count: usize) -> String {
match err_count {
0 => "aborting with no errors (maybe a bug?)".to_owned(),
1 => "aborting due to previous error".to_owned(),
e => format!("aborting due to {} previous errors", e),
_ => "aborting due to previous error(s)".to_owned(),
}
}

View file

@ -501,10 +501,7 @@ impl Handler {
return;
}
1 => s = "aborting due to previous error".to_string(),
_ => {
s = format!("aborting due to {} previous errors", self.err_count.get());
}
_ => s = "aborting due to previous error(s)".to_string(),
}
panic!(self.fatal(&s));

View file

@ -247,7 +247,9 @@ impl OsString {
self.inner.shrink_to_fit()
}
/// Converts this `OsString` into a boxed `OsStr`.
/// Converts this `OsString` into a boxed [`OsStr`].
///
/// [`OsStr`]: struct.OsStr.html
///
/// # Examples
///
@ -482,12 +484,13 @@ impl OsStr {
/// Returns the length of this `OsStr`.
///
/// Note that this does **not** return the number of bytes in this string
/// as, for example, OS strings on Windows are encoded as a list of `u16`
/// as, for example, OS strings on Windows are encoded as a list of [`u16`]
/// rather than a list of bytes. This number is simply useful for passing to
/// other methods like [`OsString::with_capacity`] to avoid reallocations.
///
/// See `OsStr` introduction for more information about encoding.
///
/// [`u16`]: ../primitive.u16.html
/// [`OsString::with_capacity`]: struct.OsString.html#method.with_capacity
///
/// # Examples
@ -506,7 +509,10 @@ impl OsStr {
self.inner.inner.len()
}
/// Converts a `Box<OsStr>` into an `OsString` without copying or allocating.
/// Converts a [`Box`]`<OsStr>` into an [`OsString`] without copying or allocating.
///
/// [`Box`]: ../boxed/struct.Box.html
/// [`OsString`]: struct.OsString.html
#[unstable(feature = "into_boxed_os_str", issue = "40380")]
pub fn into_os_string(self: Box<OsStr>) -> OsString {
let inner: Box<Slice> = unsafe { mem::transmute(self) };

View file

@ -35,6 +35,8 @@ fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {
use sys_common;
use sys_common::thread_info;
use thread::Thread;
#[cfg(not(feature = "backtrace"))]
use mem;
sys::init();
@ -53,9 +55,12 @@ fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {
sys::args::init(argc, argv);
// Let's run some code!
#[cfg(feature = "backtrace")]
let res = panic::catch_unwind(|| {
::sys_common::backtrace::__rust_begin_short_backtrace(main)
});
#[cfg(not(feature = "backtrace"))]
let res = panic::catch_unwind(mem::transmute::<_, fn()>(main));
sys_common::cleanup();
res.is_err()
};

View file

@ -1,29 +1,12 @@
/* Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Dmitry Vyukov.
*/
// Copyright 2017 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.
//! A mostly lock-free multi-producer, single consumer queue.
//!

View file

@ -1,31 +1,12 @@
/* Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Dmitry Vyukov.
*/
// http://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue
// Copyright 2017 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.
//! A single-producer single-consumer concurrent queue
//!
@ -33,6 +14,8 @@
//! concurrently between two threads. This data structure is safe to use and
//! enforces the semantics that there is one pusher and one popper.
// http://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue
use alloc::boxed::Box;
use core::ptr;
use core::cell::UnsafeCell;

View file

@ -64,3 +64,8 @@ pub unsafe fn set(key: Key, value: *mut u8) {
pub unsafe fn destroy(key: Key) {
keys().remove(&key);
}
#[inline]
pub fn requires_synchronized_create() -> bool {
false
}

View file

@ -359,9 +359,12 @@ impl Builder {
}
unsafe {
thread_info::set(imp::guard::current(), their_thread);
#[cfg(feature = "backtrace")]
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
::sys_common::backtrace::__rust_begin_short_backtrace(f)
}));
#[cfg(not(feature = "backtrace"))]
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
*their_packet.get() = Some(try_result);
}
};
@ -394,6 +397,26 @@ impl Builder {
/// want to specify the stack size or the name of the thread, use this API
/// instead.
///
/// As you can see in the signature of `spawn` there are two constraints on
/// both the closure given to `spawn` and its return value, let's explain them:
///
/// - The `'static` constraint means that the closure and its return value
/// must have a lifetime of the whole program execution. The reason for this
/// is that threads can `detach` and outlive the lifetime they have been
/// created in.
/// Indeed if the thread, and by extension its return value, can outlive their
/// caller, we need to make sure that they will be valid afterwards, and since
/// we *can't* know when it will return we need to have them valid as long as
/// possible, that is until the end of the program, hence the `'static`
/// lifetime.
/// - The [`Send`] constraint is because the closure will need to be passed
/// *by value* from the thread where it is spawned to the new thread. Its
/// return value will need to be passed from the new thread to the thread
/// where it is `join`ed.
/// As a reminder, the [`Send`] marker trait, expresses that it is safe to be
/// passed from thread to thread. [`Sync`] expresses that it is safe to have a
/// reference be passed from thread to thread.
///
/// # Panics
///
/// Panics if the OS fails to create a thread; use [`Builder::spawn`]
@ -460,6 +483,8 @@ impl Builder {
/// [`panic`]: ../../std/macro.panic.html
/// [`Builder::spawn`]: ../../std/thread/struct.Builder.html#method.spawn
/// [`Builder`]: ../../std/thread/struct.Builder.html
/// [`Send`]: ../../std/marker/trait.Send.html
/// [`Sync`]: ../../std/marker/trait.Sync.html
#[stable(feature = "rust1", since = "1.0.0")]
pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static

View file

@ -320,7 +320,7 @@ impl Attribute {
pub fn parse<'a, T, F>(&self, sess: &'a ParseSess, mut f: F) -> PResult<'a, T>
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
{
let mut parser = Parser::new(sess, self.tokens.clone(), None, false);
let mut parser = Parser::new(sess, self.tokens.clone(), None, false, false);
let result = f(&mut parser)?;
if parser.token != token::Eof {
parser.unexpected()?;

View file

@ -418,9 +418,13 @@ fn inner_parse_loop(sess: &ParseSess,
Success(())
}
pub fn parse(sess: &ParseSess, tts: TokenStream, ms: &[TokenTree], directory: Option<Directory>)
pub fn parse(sess: &ParseSess,
tts: TokenStream,
ms: &[TokenTree],
directory: Option<Directory>,
recurse_into_modules: bool)
-> NamedParseResult {
let mut parser = Parser::new(sess, tts, directory, true);
let mut parser = Parser::new(sess, tts, directory, recurse_into_modules, true);
let mut cur_eis = SmallVector::one(initial_matcher_pos(ms.to_owned(), parser.span.lo));
let mut next_eis = Vec::new(); // or proceed normally

View file

@ -121,7 +121,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
path: cx.current_expansion.module.directory.clone(),
ownership: cx.current_expansion.directory_ownership,
};
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), false);
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false);
p.root_module_name = cx.current_expansion.module.mod_path.last()
.map(|id| id.name.as_str().to_string());
@ -192,7 +192,7 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, def: &ast::Item)
ast::ItemKind::MacroDef(ref body) => body.clone().into(),
_ => unreachable!(),
};
let argument_map = match parse(sess, body, &argument_gram, None) {
let argument_map = match parse(sess, body, &argument_gram, None, true) {
Success(m) => m,
Failure(sp, tok) => {
let s = parse_failure_msg(tok);

View file

@ -238,7 +238,7 @@ pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) {
Some(&(ascii_char, ascii_name)) => {
let msg =
format!("unicode character '{}' ({}) looks much like '{}' ({}), but it's not",
format!("unicode character '{}' ({}) looks like '{}' ({}), but it's not",
ch, u_name, ascii_char, ascii_name);
err.span_help(span, &msg);
},

View file

@ -149,7 +149,9 @@ pub fn parse_stream_from_source_str(name: String, source: String, sess: &ParseSe
// Create a new parser from a source string
pub fn new_parser_from_source_str(sess: &ParseSess, name: String, source: String)
-> Parser {
filemap_to_parser(sess, sess.codemap().new_filemap(name, source))
let mut parser = filemap_to_parser(sess, sess.codemap().new_filemap(name, source));
parser.recurse_into_file_modules = false;
parser
}
/// Create a new parser, handling errors as appropriate
@ -218,7 +220,7 @@ pub fn filemap_to_stream(sess: &ParseSess, filemap: Rc<FileMap>) -> TokenStream
/// Given stream and the `ParseSess`, produce a parser
pub fn stream_to_parser(sess: &ParseSess, stream: TokenStream) -> Parser {
Parser::new(sess, stream, None, false)
Parser::new(sess, stream, None, true, false)
}
/// Parse a string representing a character literal into its final form.
@ -1032,4 +1034,23 @@ mod tests {
Err(_) => panic!("could not get snippet"),
}
}
// This tests that when parsing a string (rather than a file) we don't try
// and read in a file for a module declaration and just parse a stub.
// See `recurse_into_file_modules` in the parser.
#[test]
fn out_of_line_mod() {
let sess = ParseSess::new(FilePathMapping::empty());
let item = parse_item_from_source_str(
"foo".to_owned(),
"mod foo { struct S; mod this_does_not_exist; }".to_owned(),
&sess,
).unwrap().unwrap();
if let ast::ItemKind::Mod(ref m) = item.node {
assert!(m.items.len() == 2);
} else {
panic!();
}
}
}

View file

@ -179,6 +179,8 @@ pub struct Parser<'a> {
pub obsolete_set: HashSet<ObsoleteSyntax>,
/// Used to determine the path to externally loaded source files
pub directory: Directory,
/// Whether to parse sub-modules in other files.
pub recurse_into_file_modules: bool,
/// Name of the root module this parser originated from. If `None`, then the
/// name is not known. This does not change while the parser is descending
/// into modules, and sub-parsers have new values for this name.
@ -190,6 +192,7 @@ pub struct Parser<'a> {
pub cfg_mods: bool,
}
struct TokenCursor {
frame: TokenCursorFrame,
stack: Vec<TokenCursorFrame>,
@ -439,6 +442,7 @@ impl<'a> Parser<'a> {
pub fn new(sess: &'a ParseSess,
tokens: TokenStream,
directory: Option<Directory>,
recurse_into_file_modules: bool,
desugar_doc_comments: bool)
-> Self {
let mut parser = Parser {
@ -450,6 +454,7 @@ impl<'a> Parser<'a> {
prev_token_kind: PrevTokenKind::Other,
restrictions: Restrictions::empty(),
obsolete_set: HashSet::new(),
recurse_into_file_modules: recurse_into_file_modules,
directory: Directory { path: PathBuf::new(), ownership: DirectoryOwnership::Owned },
root_module_name: None,
expected_tokens: Vec::new(),
@ -467,12 +472,14 @@ impl<'a> Parser<'a> {
let tok = parser.next_tok();
parser.token = tok.tok;
parser.span = tok.sp;
if let Some(directory) = directory {
parser.directory = directory;
} else if parser.span != syntax_pos::DUMMY_SP {
parser.directory.path = PathBuf::from(sess.codemap().span_to_filename(parser.span));
parser.directory.path.pop();
}
parser.process_potential_macro_variable();
parser
}
@ -3921,6 +3928,7 @@ impl<'a> Parser<'a> {
mem::replace(&mut self.directory.ownership, DirectoryOwnership::UnownedViaBlock);
let item = self.parse_item_(attrs.clone(), false, true)?;
self.directory.ownership = old_directory_ownership;
match item {
Some(i) => Stmt {
id: ast::DUMMY_NODE_ID,
@ -5254,7 +5262,7 @@ impl<'a> Parser<'a> {
let id = self.parse_ident()?;
if self.check(&token::Semi) {
self.bump();
if in_cfg {
if in_cfg && self.recurse_into_file_modules {
// This mod is in an external file. Let's go get it!
let ModulePathSuccess { path, directory_ownership, warn } =
self.submod_path(id, &outer_attrs, id_span)?;
@ -5281,10 +5289,12 @@ impl<'a> Parser<'a> {
} else {
let old_directory = self.directory.clone();
self.push_directory(id, &outer_attrs);
self.expect(&token::OpenDelim(token::Brace))?;
let mod_inner_lo = self.span;
let attrs = self.parse_inner_attributes()?;
let module = self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)?;
self.directory = old_directory;
Ok((id, ItemKind::Mod(module), Some(attrs)))
}
@ -5347,7 +5357,8 @@ impl<'a> Parser<'a> {
fn submod_path(&mut self,
id: ast::Ident,
outer_attrs: &[ast::Attribute],
id_sp: Span) -> PResult<'a, ModulePathSuccess> {
id_sp: Span)
-> PResult<'a, ModulePathSuccess> {
if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) {
return Ok(ModulePathSuccess {
directory_ownership: match path.file_name().and_then(|s| s.to_str()) {

View file

@ -109,7 +109,7 @@ impl TokenTree {
path: cx.current_expansion.module.directory.clone(),
ownership: cx.current_expansion.directory_ownership,
};
macro_parser::parse(cx.parse_sess(), tts, mtch, Some(directory))
macro_parser::parse(cx.parse_sess(), tts, mtch, Some(directory), true)
}
/// Check if this TokenTree is equal to the other, regardless of span information.

View file

@ -9,7 +9,6 @@
// except according to those terms.
// aux-build:attr_proc_macro.rs
// gate-test-proc_macro
#![feature(use_extern_macros)]
extern crate attr_proc_macro;
@ -21,4 +20,4 @@ struct Foo;
fn main() {
let _ = Foo;
}
}

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// gate-test-global_asm
global_asm!(""); //~ ERROR `global_asm!` is not stable
fn main() {}

View file

@ -9,10 +9,9 @@
// except according to those terms.
// compile-flags: -Z parse-only
// ignore-tidy-linelength
fn main() {
let y = 0;
//~^ ERROR unknown start of token: \u{37e}
//~^^ HELP unicode character ';' (Greek Question Mark) looks much like ';' (Semicolon), but it's not
//~^^ HELP unicode character ';' (Greek Question Mark) looks like ';' (Semicolon), but it's not
}

View file

@ -82,7 +82,7 @@ pub fn main() {
short.next();
assert_eq!(long.size_hint(), (255, Some(255)));
assert_eq!(short.size_hint(), (0, Some(0)));
assert_eq!(short, RangeInclusive::Empty { at: 42 });
assert_eq!(short, 1...0);
assert_eq!(long.len(), 255);
assert_eq!(short.len(), 0);
@ -97,28 +97,28 @@ pub fn main() {
for i in 3...251 {
assert_eq!(long.next(), Some(i));
}
assert_eq!(long, RangeInclusive::Empty { at: 251 });
assert_eq!(long, 1...0);
// check underflow
let mut narrow = 1...0;
assert_eq!(narrow.next_back(), None);
assert_eq!(narrow, RangeInclusive::Empty { at: 0 });
assert_eq!(narrow, 1...0);
let mut zero = 0u8...0;
assert_eq!(zero.next_back(), Some(0));
assert_eq!(zero.next_back(), None);
assert_eq!(zero, RangeInclusive::Empty { at: 0 });
assert_eq!(zero, 1...0);
let mut high = 255u8...255;
assert_eq!(high.next_back(), Some(255));
assert_eq!(high.next_back(), None);
assert_eq!(high, RangeInclusive::Empty { at: 255 });
assert_eq!(high, 1...0);
// what happens if you have a nonsense range?
let mut nonsense = 10...5;
assert_eq!(nonsense.next(), None);
assert_eq!(nonsense, RangeInclusive::Empty { at: 10 });
assert_eq!(nonsense, 10...5);
// output
assert_eq!(format!("{:?}", 0...10), "0...10");
assert_eq!(format!("{:?}", ...10), "...10");
assert_eq!(format!("{:?}", long), "[empty range @ 251]");
assert_eq!(format!("{:?}", long), "1...0");
}

View file

@ -6,5 +6,5 @@ error[E0507]: cannot move out of captured outer variable in an `Fn` closure
15 | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^ cannot move out of captured outer variable in an `Fn` closure
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0507]: cannot move out of captured outer variable in an `Fn` closure
21 | y.into_iter();
| ^ cannot move out of captured outer variable in an `Fn` closure
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -46,5 +46,5 @@ error[E0004]: non-exhaustive patterns: `Some(B)`, `Some(C)`, `Some(D)` and 2 mor
49 | match Some(A) {
| ^^^^^^^ patterns `Some(B)`, `Some(C)`, `Some(D)` and 2 more not covered
error: aborting due to 8 previous errors
error: aborting due to previous error(s)

View file

@ -22,5 +22,5 @@ error: expected token: `,`
|
= note: this error originates in a macro outside of the current crate
error: aborting due to 3 previous errors
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error[E0592]: duplicate definitions with name `f`
15 | impl C { fn f() {} }
| --------- other definition for `f`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`,
17 | unsafe impl Send for &'static Foo { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable local variable `x` as mutable
100 | let y = &mut x;
| ^ cannot borrow mutably
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -8,5 +8,5 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
101 | }
| - first borrow ends here
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error: cannot apply unary operator `!` to type `&'static str`
|
= note: this error originates in a macro outside of the current crate
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0499]: cannot borrow `v` as mutable more than once at a time
| | second mutable borrow occurs here
| first mutable borrow occurs here
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -25,5 +25,5 @@ error[E0592]: duplicate definitions with name `baz`
43 | fn baz(&self) {}
| ---------------- other definition for `baz`
error: aborting due to 3 previous errors
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
| | hint: to prevent move, use `ref _s` or `ref mut _s`
| cannot move out of here
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error[E0425]: cannot find value `bar` in this scope
14 | \tbar;
| \t^^^ not found in this scope
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error: invalid ABI: expected one of [cdecl, stdcall, fastcall, vectorcall, aapcs
11 | extern "路濫狼á́́" fn foo() {}
| ^^^^^^^^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -15,5 +15,5 @@ help: consider removing this semicolon:
14 | x + 1;
| ^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -11,5 +11,5 @@ error[E0276]: impl has stricter requirements than trait
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #37166 <https://github.com/rust-lang/rust/issues/37166>
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ error[E0276]: impl has stricter requirements than trait
22 | | }
| |_____^ impl has extra requirement `'a: 'b`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0276]: impl has stricter requirements than trait
22 | fn foo() where 'a: 'b { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `'a: 'b`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -11,5 +11,5 @@ error[E0276]: impl has stricter requirements than trait
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #37166 <https://github.com/rust-lang/rust/issues/37166>
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ error[E0053]: method `b` has an incompatible type for trait
= note: expected type `fn(&E, F) -> F`
found type `fn(&E, G) -> G`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0276]: impl has stricter requirements than trait
25 | fn b<F: Sync, G>(&self, _x: F) -> F { panic!() } //~ ERROR E0276
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `F: std::marker::Sync`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -61,5 +61,5 @@ error[E0276]: impl has stricter requirements than trait
76 | fn method<G: Getter<usize>>(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `G: Getter<usize>`
error: aborting due to 7 previous errors
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ error[E0276]: impl has stricter requirements than trait
26 | | }
| |_____^ impl has extra requirement `U: Iterator<B>`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error: invalid reference to argument `0` (no arguments given)
|
= note: this error originates in a macro outside of the current crate
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -22,5 +22,5 @@ error[E0178]: expected a path on the left-hand side of `+`, not `fn() -> Foo`
17 | z: fn() -> Foo + 'a,
| ^^^^^^^^^^^^^^^^ perhaps you forgot parentheses?
error: aborting due to 4 previous errors
error: aborting due to previous error(s)

View file

@ -8,5 +8,5 @@ error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
<Bar as Foo<i32>>
<Bar as Foo<u8>>
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -11,5 +11,5 @@ error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
<Bar as Foo<u8>>
and 2 others
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -15,5 +15,5 @@ error: cannot borrow immutable argument `self` as mutable
23 | (&mut self).bar();
| ^^^^ cannot borrow mutably
error: aborting due to 2 previous errors
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable argument `self` as mutable
| try removing `&mut` here
| cannot reborrow mutably
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable local variable `key` as mutable
| try removing `&mut` here
| cannot reborrow mutably
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -22,5 +22,5 @@ error: cannot assign to immutable field `s.x`
30 | s.x += 1;
| ^^^^^^^^ cannot mutably borrow immutable field
error: aborting due to 3 previous errors
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error: no field `baz` on type `Foo`
17 | f.baz;
| ^^^ did you mean `bar`?
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error: no field `zz` on type `Foo`
17 | f.zz;
| ^^ unknown field
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable local variable `x` as mutable
| try removing `&mut` here
| cannot reborrow mutably
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ error[E0432]: unresolved import `Foo1`
13 | use Foo1;
| ^^^^ no `Foo1` in the root
error: aborting due to 2 previous errors
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error[E0389]: cannot borrow data mutably in a `&` reference
27 | self.s.push('x');
| ^^^^^^ assignment into an immutable reference
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable borrowed content `*self.s` as mutable
17 | self.s.push('x');
| ^^^^^^ cannot borrow as mutable
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error: cannot borrow immutable borrowed content `*self.s` as mutable
17 | self.s.push('x');
| ^^^^^^ cannot borrow as mutable
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error[E0389]: cannot borrow data mutably in a `&` reference
16 | f.s.push('x');
| ^^^ assignment into an immutable reference
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -96,5 +96,5 @@ error: cannot assign to immutable borrowed content `*x.0`
58 | *x.0 = 1;
| ^^^^^^^^ cannot borrow as mutable
error: aborting due to 12 previous errors
error: aborting due to previous error(s)

View file

@ -39,5 +39,5 @@ error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
and 2 others
= note: required by `Foo::bar`
error: aborting due to 3 previous errors
error: aborting due to previous error(s)

View file

@ -64,5 +64,5 @@ error[E0038]: the trait `X` cannot be made into an object
|
= note: method `xxx` has no receiver
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -30,5 +30,5 @@ error: chained comparison operators require parentheses
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments
error: aborting due to 4 previous errors
error: aborting due to previous error(s)

View file

@ -4,5 +4,5 @@ error: cannot borrow immutable borrowed content `*buf` as mutable
13 | buf.iter_mut();
| ^^^ cannot borrow as mutable
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error: `~` can not be used as a unary operator
|
= help: use `!` instead of `~` if you meant to perform bitwise negation
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -17,5 +17,5 @@ error[E0275]: overflow evaluating the requirement `K: std::marker::Send`
= note: required because it appears within the type `A`
= note: required by `is_send`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -19,5 +19,5 @@ error[E0308]: mismatched types
= note: expected type `&Bottom`
found type `&Top`
error: aborting due to 3 previous errors
error: aborting due to previous error(s)

View file

@ -18,5 +18,5 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object
|
= note: the trait cannot require that `Self : Sized`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -42,5 +42,5 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to 4 previous errors
error: aborting due to previous error(s)

View file

@ -20,5 +20,5 @@ error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attri
43 | | }
| |_^
error: aborting due to 2 previous errors
error: aborting due to previous error(s)

View file

@ -42,5 +42,5 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to 4 previous errors
error: aborting due to previous error(s)

View file

@ -42,5 +42,5 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created
error: aborting due to 4 previous errors
error: aborting due to previous error(s)

View file

@ -16,5 +16,5 @@ error: invalid format string: unmatched `}` found
= note: if you intended to print `}`, you can escape it using `}}`
= note: this error originates in a macro outside of the current crate
error: aborting due to 2 previous errors
error: aborting due to previous error(s)

View file

@ -8,5 +8,5 @@ error[E0382]: use of moved value: `debug_dump_dict`
|
= help: closure was moved because it only implements `FnOnce`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -51,5 +51,5 @@ error[E0308]: mismatched types
= note: expected type `impl Foo` (i32)
found type `impl Foo` (u32)
error: aborting due to 6 previous errors
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ note: maybe move this module `$DIR/auxiliary/foo/bar.rs` to its own directory vi
11 | pub mod baz;
| ^^^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -8,5 +8,5 @@ error: reached the type-length limit while instantiating `<T as Foo><(&(&(&(&(&(
|
= note: consider adding a `#![type_length_limit="2097152"]` attribute to your crate
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0507]: cannot move out of indexed content
| help: consider using a reference instead `&f.v[0]`
| cannot move out of indexed content
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -7,5 +7,5 @@ error[E0507]: cannot move out of indexed content
| | ...and here (use `ref b` or `ref mut b`)
| hint: to prevent move, use `ref a` or `ref mut a`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -8,5 +8,5 @@ error: no method named `f` found for type `{integer}` in the current scope
note: candidate #1 is defined in the trait `issue_41652_b::Tr`
= help: to disambiguate the method call, write `issue_41652_b::Tr::f(3)` instead
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -19,5 +19,5 @@ note: ...but the borrowed content is only valid for the anonymous lifetime #1 de
13 | | }
| |_^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error[E0106]: missing lifetime specifier
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -21,5 +21,5 @@ note: ...does not necessarily outlive the lifetime 'a as defined on the function
17 | | }
| |_^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -21,5 +21,5 @@ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the f
17 | | }
| |_^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -31,5 +31,5 @@ note: ...so that expression is assignable (expected Ref<'b, _>, found Ref<'_, _>
17 | x.push(z);
| ^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -33,5 +33,5 @@ note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i
16 | let a: &mut Vec<Ref<i32>> = x;
| ^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -33,5 +33,5 @@ note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i
16 | let a: &mut Vec<Ref<i32>> = x;
| ^
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -10,5 +10,5 @@ error: borrowed value does not live long enough
|
= note: consider using a `let` binding to increase its lifetime
error: aborting due to previous error
error: aborting due to previous error(s)

View file

@ -6,5 +6,5 @@ error: variable `_InappropriateCamelCasing` should have a snake case name such a
|
= note: `-D non-snake-case` implied by `-D bad-style`
error: aborting due to previous error
error: aborting due to previous error(s)

Some files were not shown because too many files have changed in this diff Show more