Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #42952

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The tracking issue for this feature is: [#40872]

[#29599]: https://github.com/rust-lang/rust/issues/40872
[#40872]: https://github.com/rust-lang/rust/issues/40872

------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ pub unsafe trait Alloc {
{
let k = Layout::new::<T>();
if k.size() > 0 {
unsafe { self.alloc(k).map(|p|Unique::new(*p as *mut T)) }
unsafe { self.alloc(k).map(|p| Unique::new(p as *mut T)) }
} else {
Err(AllocErr::invalid_input("zero-sized type invalid for alloc_one"))
}
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![feature(sort_unstable)]
#![feature(test)]

extern crate rand;
extern crate test;

mod btree;
Expand Down
54 changes: 35 additions & 19 deletions src/liballoc/benches/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::{mem, ptr};
use std::__rand::{Rng, thread_rng};
use std::__rand::{thread_rng};
use std::mem;
use std::ptr;

use rand::{Rng, SeedableRng, XorShiftRng};
use test::{Bencher, black_box};

#[bench]
Expand Down Expand Up @@ -191,17 +193,17 @@ fn gen_descending(len: usize) -> Vec<u64> {
}

fn gen_random(len: usize) -> Vec<u64> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
rng.gen_iter::<u64>().take(len).collect()
}

fn gen_random_bytes(len: usize) -> Vec<u8> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
rng.gen_iter::<u8>().take(len).collect()
}

fn gen_mostly_ascending(len: usize) -> Vec<u64> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
let mut v = gen_ascending(len);
for _ in (0usize..).take_while(|x| x * x <= len) {
let x = rng.gen::<usize>() % len;
Expand All @@ -212,7 +214,7 @@ fn gen_mostly_ascending(len: usize) -> Vec<u64> {
}

fn gen_mostly_descending(len: usize) -> Vec<u64> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
let mut v = gen_descending(len);
for _ in (0usize..).take_while(|x| x * x <= len) {
let x = rng.gen::<usize>() % len;
Expand All @@ -223,7 +225,7 @@ fn gen_mostly_descending(len: usize) -> Vec<u64> {
}

fn gen_strings(len: usize) -> Vec<String> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
let mut v = vec![];
for _ in 0..len {
let n = rng.gen::<usize>() % 20 + 1;
Expand All @@ -233,26 +235,40 @@ fn gen_strings(len: usize) -> Vec<String> {
}

fn gen_big_random(len: usize) -> Vec<[u64; 16]> {
let mut rng = thread_rng();
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3]);
rng.gen_iter().map(|x| [x; 16]).take(len).collect()
}

macro_rules! sort {
($f:ident, $name:ident, $gen:expr, $len:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
b.iter(|| $gen($len).$f());
let v = $gen($len);
b.iter(|| v.clone().$f());
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
}

macro_rules! sort_strings {
($f:ident, $name:ident, $gen:expr, $len:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let v = $gen($len);
let v = v.iter().map(|s| &**s).collect::<Vec<&str>>();
b.iter(|| v.clone().$f());
b.bytes = $len * mem::size_of::<&str>() as u64;
}
}
}

macro_rules! sort_expensive {
($f:ident, $name:ident, $gen:expr, $len:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let v = $gen($len);
b.iter(|| {
let mut v = $gen($len);
let mut v = v.clone();
let mut count = 0;
v.$f(|a: &u64, b: &u64| {
count += 1;
Expand All @@ -263,38 +279,38 @@ macro_rules! sort_expensive {
});
black_box(count);
});
b.bytes = $len as u64 * mem::size_of::<u64>() as u64;
b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64;
}
}
}

sort!(sort, sort_small_ascending, gen_ascending, 10);
sort!(sort, sort_small_descending, gen_descending, 10);
sort!(sort, sort_small_random, gen_random, 10);
sort!(sort, sort_small_big_random, gen_big_random, 10);
sort!(sort, sort_small_big, gen_big_random, 10);
sort!(sort, sort_medium_random, gen_random, 100);
sort!(sort, sort_large_ascending, gen_ascending, 10000);
sort!(sort, sort_large_descending, gen_descending, 10000);
sort!(sort, sort_large_mostly_ascending, gen_mostly_ascending, 10000);
sort!(sort, sort_large_mostly_descending, gen_mostly_descending, 10000);
sort!(sort, sort_large_random, gen_random, 10000);
sort!(sort, sort_large_big_random, gen_big_random, 10000);
sort!(sort, sort_large_strings, gen_strings, 10000);
sort_expensive!(sort_by, sort_large_random_expensive, gen_random, 10000);
sort!(sort, sort_large_big, gen_big_random, 10000);
sort_strings!(sort, sort_large_strings, gen_strings, 10000);
sort_expensive!(sort_by, sort_large_expensive, gen_random, 10000);

sort!(sort_unstable, sort_unstable_small_ascending, gen_ascending, 10);
sort!(sort_unstable, sort_unstable_small_descending, gen_descending, 10);
sort!(sort_unstable, sort_unstable_small_random, gen_random, 10);
sort!(sort_unstable, sort_unstable_small_big_random, gen_big_random, 10);
sort!(sort_unstable, sort_unstable_small_big, gen_big_random, 10);
sort!(sort_unstable, sort_unstable_medium_random, gen_random, 100);
sort!(sort_unstable, sort_unstable_large_ascending, gen_ascending, 10000);
sort!(sort_unstable, sort_unstable_large_descending, gen_descending, 10000);
sort!(sort_unstable, sort_unstable_large_mostly_ascending, gen_mostly_ascending, 10000);
sort!(sort_unstable, sort_unstable_large_mostly_descending, gen_mostly_descending, 10000);
sort!(sort_unstable, sort_unstable_large_random, gen_random, 10000);
sort!(sort_unstable, sort_unstable_large_big_random, gen_big_random, 10000);
sort!(sort_unstable, sort_unstable_large_strings, gen_strings, 10000);
sort_expensive!(sort_unstable_by, sort_unstable_large_random_expensive, gen_random, 10000);
sort!(sort_unstable, sort_unstable_large_big, gen_big_random, 10000);
sort_strings!(sort_unstable, sort_unstable_large_strings, gen_strings, 10000);
sort_expensive!(sort_unstable_by, sort_unstable_large_expensive, gen_random, 10000);

macro_rules! reverse {
($name:ident, $ty:ty, $f:expr) => {
Expand Down
8 changes: 3 additions & 5 deletions src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,10 @@ pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};

use string;

/// The format function takes a precompiled format string and a list of
/// arguments, to return the resulting formatted string.
/// The `format` function takes an `Arguments` struct and returns the resulting
/// formatted string.
///
/// # Arguments
///
/// * args - a structure of arguments generated via the `format_args!` macro.
/// The `Arguments` instance can be created with the `format_args!` macro.
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)

impl<T> Drop for MergeHole<T> {
fn drop(&mut self) {
// `T` is not a zero-sized type, so it's okay to divide by it's size.
// `T` is not a zero-sized type, so it's okay to divide by its size.
let len = (self.end as usize - self.start as usize) / mem::size_of::<T>();
unsafe { ptr::copy_nonoverlapping(self.start, self.dest, len); }
}
Expand Down Expand Up @@ -1908,7 +1908,7 @@ fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
// if `Some(r)` is returned, that means `runs[r]` and `runs[r + 1]` must be merged next. If the
// algorithm should continue building a new run instead, `None` is returned.
//
// TimSort is infamous for it's buggy implementations, as described here:
// TimSort is infamous for its buggy implementations, as described here:
// http://envisage-project.eu/timsort-specification-and-verification/
//
// The gist of the story is: we must enforce the invariants on the top four runs on the stack.
Expand Down
50 changes: 38 additions & 12 deletions src/liballoc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,44 @@ fn test_sort() {
let mut rng = thread_rng();

for len in (2..25).chain(500..510) {
for _ in 0..100 {
let mut v: Vec<_> = rng.gen_iter::<i32>().take(len).collect();
let mut v1 = v.clone();

v.sort();
assert!(v.windows(2).all(|w| w[0] <= w[1]));

v1.sort_by(|a, b| a.cmp(b));
assert!(v1.windows(2).all(|w| w[0] <= w[1]));

v1.sort_by(|a, b| b.cmp(a));
assert!(v1.windows(2).all(|w| w[0] >= w[1]));
for &modulus in &[5, 10, 100, 1000] {
for _ in 0..10 {
let orig: Vec<_> = rng.gen_iter::<i32>()
.map(|x| x % modulus)
.take(len)
.collect();

// Sort in default order.
let mut v = orig.clone();
v.sort();
assert!(v.windows(2).all(|w| w[0] <= w[1]));

// Sort in ascending order.
let mut v = orig.clone();
v.sort_by(|a, b| a.cmp(b));
assert!(v.windows(2).all(|w| w[0] <= w[1]));

// Sort in descending order.
let mut v = orig.clone();
v.sort_by(|a, b| b.cmp(a));
assert!(v.windows(2).all(|w| w[0] >= w[1]));

// Sort with many pre-sorted runs.
let mut v = orig.clone();
v.sort();
v.reverse();
for _ in 0..5 {
let a = rng.gen::<usize>() % len;
let b = rng.gen::<usize>() % len;
if a < b {
v[a..b].reverse();
} else {
v.swap(a, b);
}
}
v.sort();
assert!(v.windows(2).all(|w| w[0] <= w[1]));
}
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,11 @@ pub trait UpperExp {
fn fmt(&self, f: &mut Formatter) -> Result;
}

/// The `write` function takes an output stream, a precompiled format string,
/// and a list of arguments. The arguments will be formatted according to the
/// specified format string into the output stream provided.
/// The `write` function takes an output stream, and an `Arguments` struct
/// that can be precompiled with the `format_args!` macro.
///
/// # Arguments
///
/// * output - the buffer to write output to
/// * args - the precompiled arguments generated by `format_args!`
/// The arguments will be formatted according to the specified format string
/// into the output stream provided.
///
/// # Examples
///
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
let exp_path = self.tcx.item_path_str(did1);
let found_path = self.tcx.item_path_str(did2);
let exp_abs_path = self.tcx.absolute_item_path_str(did1);
let found_abs_path = self.tcx.absolute_item_path_str(did2);
// We compare strings because DefPath can be different
// for imported and non-imported crates
if exp_path == found_path {
if exp_path == found_path
|| exp_abs_path == found_abs_path {
let crate_name = self.tcx.sess.cstore.crate_name(did1.krate);
err.span_note(sp, &format!("Perhaps two different versions \
of crate `{}` are being used?",
Expand Down
39 changes: 30 additions & 9 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,29 @@ impl OpenOptions {
/// # Errors
///
/// This function will return an error under a number of different
/// circumstances, to include but not limited to:
///
/// * Opening a file that does not exist without setting `create` or
/// `create_new`.
/// * Attempting to open a file with access that the user lacks
/// permissions for
/// * Filesystem-level errors (full disk, etc)
/// * Invalid combinations of open options (truncate without write access,
/// no access mode set, etc)
/// circumstances. Some of these error conditions are listed here, together
/// with their [`ErrorKind`]. The mapping to [`ErrorKind`]s is not part of
/// the compatiblity contract of the function, especially the `Other` kind
/// might change to more specific kinds in the future.
///
/// * [`NotFound`]: The specified file does not exist and neither `create`
/// or `create_new` is set.
/// * [`NotFound`]: One of the directory components of the file path does
/// not exist.
/// * [`PermissionDenied`]: The user lacks permission to get the specified
/// access rights for the file.
/// * [`PermissionDenied`]: The user lacks permission to open one of the
/// directory components of the specified path.
/// * [`AlreadyExists`]: `create_new` was specified and the file already
/// exists.
/// * [`InvalidInput`]: Invalid combinations of open options (truncate
/// without write access, no access mode set, etc.).
/// * [`Other`]: One of the directory components of the specified file path
/// was not, in fact, a directory.
/// * [`Other`]: Filesystem-level errors: full disk, write permission
/// requested on a read-only file system, exceeded disk quota, too many
/// open files, too long filename, too many symbolic links in the
/// specified path (Unix-like systems only), etc.
///
/// # Examples
///
Expand All @@ -670,6 +684,13 @@ impl OpenOptions {
///
/// let file = OpenOptions::new().open("foo.txt");
/// ```
///
/// [`ErrorKind`]: ../io/enum.ErrorKind.html
/// [`AlreadyExists`]: ../io/enum.ErrorKind.html#variant.AlreadyExists
/// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput
/// [`NotFound`]: ../io/enum.ErrorKind.html#variant.NotFound
/// [`Other`]: ../io/enum.ErrorKind.html#variant.Other
/// [`PermissionDenied`]: ../io/enum.ErrorKind.html#variant.PermissionDenied
#[stable(feature = "rust1", since = "1.0.0")]
pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> {
self._open(path.as_ref())
Expand Down
19 changes: 19 additions & 0 deletions src/test/run-make/type-mismatch-same-crate-name/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-include ../tools.mk

all:
# compile two different versions of crateA
$(RUSTC) --crate-type=rlib crateA.rs -C metadata=-1 -C extra-filename=-1
$(RUSTC) --crate-type=rlib crateA.rs -C metadata=-2 -C extra-filename=-2
# make crateB depend on version 1 of crateA
$(RUSTC) --crate-type=rlib crateB.rs --extern crateA=$(TMPDIR)/libcrateA-1.rlib
# make crateC depend on version 2 of crateA
$(RUSTC) crateC.rs --extern crateA=$(TMPDIR)/libcrateA-2.rlib 2>&1 | \
grep -z \
"mismatched types.*\
crateB::try_foo(foo2);.*\
expected struct \`crateA::foo::Foo\`, found struct \`crateA::Foo\`.*\
different versions of crate \`crateA\`.*\
mismatched types.*\
crateB::try_bar(bar2);.*\
expected trait \`crateA::bar::Bar\`, found trait \`crateA::Bar\`.*\
different versions of crate \`crateA\`"
26 changes: 26 additions & 0 deletions src/test/run-make/type-mismatch-same-crate-name/crateA.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.

mod foo {
pub struct Foo;
}

mod bar {
pub trait Bar{}

pub fn bar() -> Box<Bar> {
unimplemented!()
}
}

// This makes the publicly accessible path
// differ from the internal one.
pub use foo::Foo;
pub use bar::{Bar, bar};
Loading