Skip to content

Commit

Permalink
Auto merge of #50807 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 17 pull requests

Successful merges:

 - #50170 (Implement From for more types on Cow)
 - #50638 (Don't unconditionally set CLOEXEC twice on every fd we open on Linux)
 - #50656 (Fix `fn main() -> impl Trait` for non-`Termination` trait)
 - #50669 (rustdoc: deprecate `#![doc(passes, plugins, no_default_passes)]`)
 - #50726 (read2: Use inner function instead of closure)
 - #50728 (Fix rustdoc panic with `impl Trait` in type parameters)
 - #50736 (env: remove unwrap in examples in favor of try op)
 - #50740 (Remove LazyBTreeMap.)
 - #50752 (Add missing error codes in libsyntax-ext asm)
 - #50779 (Make mutable_noalias and arg_align_attributes be tracked)
 - #50787 (Fix run-make wasm tests)
 - #50788 (Fix an ICE when casting a nonexistent const)
 - #50789 (Ensure libraries built in stage0 have unique metadata)
 - #50793 (tidy: Add a check for empty UI test files)
 - #50797 (fix a typo in signed-integer::from_str_radix())
 - #50808 (Stabilize num::NonZeroU*)
 - #50809 (GitHub: Stop treating Cargo.lock as a generated file.)

Failed merges:
  • Loading branch information
bors committed May 17, 2018
2 parents 4208bd5 + 3c261a4 commit b559710
Show file tree
Hide file tree
Showing 78 changed files with 589 additions and 361 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
src/etc/installer/gfx/* binary
*.woff binary
src/vendor/** -text
Cargo.lock -merge
Cargo.lock -merge linguist-generated=false
10 changes: 9 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,15 @@ impl<'a> Builder<'a> {

// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
// Force cargo to output binaries with disambiguating hashes in the name
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &self.config.channel);
let metadata = if compiler.stage == 0 {
// Treat stage0 like special channel, whether it's a normal prior-
// release rustc or a local rebuild with the same version, so we
// never mix these libraries by accident.
"bootstrap"
} else {
&self.config.channel
};
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata);

let stage;
if compiler.stage == 0 && self.local_rebuild {
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ test!(RunFailFullDepsPretty {
host: true
});

host_test!(RunMake {
default_test!(RunMake {
path: "src/test/run-make",
mode: "run-make",
suite: "run-make"
Expand Down Expand Up @@ -1041,7 +1041,7 @@ impl Step for Compiletest {

// Only pass correct values for these flags for the `run-make` suite as it
// requires that a C++ compiler was configured which isn't always the case.
if !builder.config.dry_run && mode == "run-make" {
if !builder.config.dry_run && suite == "run-make-fulldeps" {
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
cmd.arg("--cc").arg(builder.cc(target))
Expand All @@ -1054,13 +1054,13 @@ impl Step for Compiletest {
}
}
}
if mode == "run-make" && !builder.config.llvm_enabled {
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
builder.info(
&format!("Ignoring run-make test suite as they generally don't work without LLVM"));
return;
}

if mode != "run-make" {
if suite != "run-make-fulldeps" {
cmd.arg("--cc").arg("")
.arg("--cxx").arg("")
.arg("--cflags").arg("")
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
#![feature(lang_items)]
#![feature(libc)]
#![feature(needs_allocator)]
#![feature(nonzero)]
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(pin)]
Expand Down
8 changes: 8 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,14 @@ impl<'a> From<String> for Cow<'a, str> {
}
}

#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
impl<'a> From<&'a String> for Cow<'a, str> {
#[inline]
fn from(s: &'a String) -> Cow<'a, str> {
Cow::Borrowed(s.as_str())
}
}

#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
impl<'a> FromIterator<char> for Cow<'a, str> {
fn from_iter<I: IntoIterator<Item = char>>(it: I) -> Cow<'a, str> {
Expand Down
7 changes: 7 additions & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,13 @@ impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
}
}

#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
fn from(v: &'a Vec<T>) -> Cow<'a, [T]> {
Cow::Borrowed(v.as_slice())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub mod prelude;

pub mod intrinsics;
pub mod mem;
pub mod nonzero;
pub mod ptr;
pub mod hint;

Expand Down Expand Up @@ -221,6 +220,7 @@ pub mod heap {

// note: does not need to be public
mod iter_private;
mod nonzero;
mod tuple;
mod unit;

Expand Down
96 changes: 3 additions & 93 deletions src/libcore/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,13 @@
// except according to those terms.

//! Exposes the NonZero lang item which provides optimization hints.
#![unstable(feature = "nonzero", reason = "deprecated", issue = "49137")]
#![rustc_deprecated(reason = "use `std::ptr::NonNull` or `std::num::NonZero*` instead",
since = "1.26.0")]
#![allow(deprecated)]

use ops::CoerceUnsized;

/// Unsafe trait to indicate what types are usable with the NonZero struct
pub unsafe trait Zeroable {
/// Whether this value is zero
fn is_zero(&self) -> bool;
}

macro_rules! impl_zeroable_for_pointer_types {
( $( $Ptr: ty )+ ) => {
$(
/// For fat pointers to be considered "zero", only the "data" part needs to be null.
unsafe impl<T: ?Sized> Zeroable for $Ptr {
#[inline]
fn is_zero(&self) -> bool {
(*self).is_null()
}
}
)+
}
}

macro_rules! impl_zeroable_for_integer_types {
( $( $Int: ty )+ ) => {
$(
unsafe impl Zeroable for $Int {
#[inline]
fn is_zero(&self) -> bool {
*self == 0
}
}
)+
}
}

impl_zeroable_for_pointer_types! {
*const T
*mut T
}

impl_zeroable_for_integer_types! {
usize u8 u16 u32 u64 u128
isize i8 i16 i32 i64 i128
}

/// A wrapper type for raw pointers and integers that will never be
/// NULL or 0 that might allow certain optimizations.
#[lang = "non_zero"]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub struct NonZero<T: Zeroable>(pub(crate) T);

impl<T: Zeroable> NonZero<T> {
/// Creates an instance of NonZero with the provided value.
/// You must indeed ensure that the value is actually "non-zero".
#[inline]
pub const unsafe fn new_unchecked(inner: T) -> Self {
NonZero(inner)
}

/// Creates an instance of NonZero with the provided value.
#[inline]
pub fn new(inner: T) -> Option<Self> {
if inner.is_zero() {
None
} else {
Some(NonZero(inner))
}
}

/// Gets the inner value.
pub fn get(self) -> T {
self.0
}
}

impl<T: Zeroable+CoerceUnsized<U>, U: Zeroable> CoerceUnsized<NonZero<U>> for NonZero<T> {}

impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*mut T> {
fn from(reference: &'a mut T) -> Self {
NonZero(reference)
}
}

impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*const T> {
fn from(reference: &'a mut T) -> Self {
let ptr: *mut T = reference;
NonZero(ptr)
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub(crate) struct NonZero<T>(pub(crate) T);

impl<'a, T: ?Sized> From<&'a T> for NonZero<*const T> {
fn from(reference: &'a T) -> Self {
NonZero(reference)
}
}
impl<T: CoerceUnsized<U>, U> CoerceUnsized<NonZero<U>> for NonZero<T> {}
38 changes: 9 additions & 29 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ use convert::TryFrom;
use fmt;
use intrinsics;
use mem;
#[allow(deprecated)] use nonzero::NonZero;
use nonzero::NonZero;
use ops;
use str::FromStr;

macro_rules! impl_nonzero_fmt {
( #[$stability: meta] ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
( ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
$(
#[$stability]
#[allow(deprecated)]
#[stable(feature = "nonzero", since = "1.28.0")]
impl fmt::$Trait for $Ty {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -36,7 +35,7 @@ macro_rules! impl_nonzero_fmt {
}

macro_rules! nonzero_integers {
( #[$stability: meta] #[$deprecation: meta] $( $Ty: ident($Int: ty); )+ ) => {
( $( $Ty: ident($Int: ty); )+ ) => {
$(
/// An integer that is known not to equal zero.
///
Expand All @@ -47,27 +46,24 @@ macro_rules! nonzero_integers {
/// use std::mem::size_of;
/// assert_eq!(size_of::<Option<std::num::NonZeroU32>>(), size_of::<u32>());
/// ```
#[$stability]
#[$deprecation]
#[allow(deprecated)]
#[stable(feature = "nonzero", since = "1.28.0")]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct $Ty(NonZero<$Int>);

#[allow(deprecated)]
impl $Ty {
/// Create a non-zero without checking the value.
///
/// # Safety
///
/// The value must not be zero.
#[$stability]
#[stable(feature = "nonzero", since = "1.28.0")]
#[inline]
pub const unsafe fn new_unchecked(n: $Int) -> Self {
$Ty(NonZero(n))
}

/// Create a non-zero if the given value is not zero.
#[$stability]
#[stable(feature = "nonzero", since = "1.28.0")]
#[inline]
pub fn new(n: $Int) -> Option<Self> {
if n != 0 {
Expand All @@ -78,7 +74,7 @@ macro_rules! nonzero_integers {
}

/// Returns the value as a primitive type.
#[$stability]
#[stable(feature = "nonzero", since = "1.28.0")]
#[inline]
pub fn get(self) -> $Int {
self.0 .0
Expand All @@ -87,16 +83,13 @@ macro_rules! nonzero_integers {
}

impl_nonzero_fmt! {
#[$stability]
(Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
}
)+
}
}

nonzero_integers! {
#[unstable(feature = "nonzero", issue = "49137")]
#[allow(deprecated)] // Redundant, works around "error: inconsistent lockstep iteration"
NonZeroU8(u8);
NonZeroU16(u16);
NonZeroU32(u32);
Expand All @@ -105,19 +98,6 @@ nonzero_integers! {
NonZeroUsize(usize);
}

nonzero_integers! {
#[unstable(feature = "nonzero", issue = "49137")]
#[rustc_deprecated(since = "1.26.0", reason = "\
signed non-zero integers are considered for removal due to lack of known use cases. \
If you’re using them, please comment on https://github.com/rust-lang/rust/issues/49137")]
NonZeroI8(i8);
NonZeroI16(i16);
NonZeroI32(i32);
NonZeroI64(i64);
NonZeroI128(i128);
NonZeroIsize(isize);
}

/// Provides intentionally-wrapped arithmetic on `T`.
///
/// Operations like `+` on `u32` values is intended to never overflow,
Expand Down Expand Up @@ -252,7 +232,7 @@ depending on `radix`:
* `0-9`
* `a-z`
* `a-z`
* `A-Z`
# Panics
Expand Down
Loading

0 comments on commit b559710

Please sign in to comment.