Skip to content

Commit

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

Successful merges:

 - rust-lang#55011 (Add libstd Cargo feature "panic_immediate_abort")
 - rust-lang#55821 (Use sort_by_cached_key when the key function is not trivial/free)
 - rust-lang#56014 (add test for issue rust-lang#21335)
 - rust-lang#56131 (Assorted tweaks)
 - rust-lang#56214 (Implement chalk unification routines)
 - rust-lang#56216 (Add TryFrom<&[T]> for [T; $N] where T: Copy)
 - rust-lang#56268 (Reuse the `P` in `InvocationCollector::fold_{,opt_}expr`.)
 - rust-lang#56324 (Use raw_entry for more efficient interning)
 - rust-lang#56336 (Clean up and streamline the pretty-printer)
 - rust-lang#56337 (Fix const_fn ICE with non-const function pointer)
 - rust-lang#56339 (Remove not used option)
 - rust-lang#56341 (Rename conversion util; remove duplicate util in librustc_codegen_llvm.)
 - rust-lang#56349 (rustc 1.30.0's linker flavor inference is a non-backwards compat change to -Clinker)
 - rust-lang#56355 (Add inline attributes and add unit to CommonTypes)
 - rust-lang#56360 (Optimize local linkchecker program)
 - rust-lang#56364 (Fix panic with outlives in existential type)
 - rust-lang#56365 (Stabilize self_struct_ctor feature.)
 - rust-lang#56367 (Moved some feature gate tests to correct location)
 - rust-lang#56373 (Update books)
  • Loading branch information
bors committed Nov 30, 2018
2 parents d48ab69 + a6c4771 commit d09466c
Show file tree
Hide file tree
Showing 76 changed files with 1,908 additions and 856 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@
[submodule "src/doc/rustc-guide"]
path = src/doc/rustc-guide
url = https://github.com/rust-lang/rustc-guide.git
[submodule "src/doc/edition-guide"]
path = src/doc/edition-guide
url = https://github.com/rust-lang-nursery/edition-guide
1 change: 1 addition & 0 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ macro_rules! book {
book!(
Nomicon, "src/doc/nomicon", "nomicon";
Reference, "src/doc/reference", "reference";
EditionGuide, "src/doc/edition-guide", "edition-guide";
RustdocBook, "src/doc/rustdoc", "rustdoc";
RustcBook, "src/doc/rustc", "rustc";
RustByExample, "src/doc/rust-by-example", "rust-by-example";
Expand Down
1 change: 1 addition & 0 deletions src/doc/edition-guide
Submodule edition-guide added at ad8958
2 changes: 1 addition & 1 deletion src/doc/nomicon
33 changes: 0 additions & 33 deletions src/doc/unstable-book/src/language-features/self-struct-ctor.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ impl String {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
// This isn't done via collect::<Result<_, _>>() for performance reasons.
// FIXME: the function can be simplified again when #48994 is closed.
let mut ret = String::with_capacity(v.len());
for c in decode_utf16(v.iter().cloned()) {
if let Ok(c) = c {
Expand Down
2 changes: 2 additions & 0 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pub struct DroplessArena {
unsafe impl Send for DroplessArena {}

impl Default for DroplessArena {
#[inline]
fn default() -> DroplessArena {
DroplessArena {
ptr: Cell::new(0 as *mut u8),
Expand All @@ -319,6 +320,7 @@ impl DroplessArena {
false
}

#[inline]
fn align(&self, align: usize) {
let final_address = ((self.ptr.get() as usize) + align - 1) & !(align - 1);
self.ptr.set(final_address as *mut u8);
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ path = "../libcore/benches/lib.rs"

[dev-dependencies]
rand = "0.5"

[features]
# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = []
9 changes: 9 additions & 0 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ macro_rules! array_impls {
}
}

#[unstable(feature = "try_from", issue = "33417")]
impl<'a, T> TryFrom<&'a [T]> for [T; $N] where T: Copy {
type Error = TryFromSliceError;

fn try_from(slice: &[T]) -> Result<[T; $N], TryFromSliceError> {
<&Self>::try_from(slice).map(|r| *r)
}
}

#[unstable(feature = "try_from", issue = "33417")]
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
type Error = TryFromSliceError;
Expand Down
79 changes: 79 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,19 @@ big endian.
```
let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand All @@ -2008,6 +2021,19 @@ little endian.
```
let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand Down Expand Up @@ -2037,6 +2063,19 @@ let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"bi
", $le_bytes, "
});
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand Down Expand Up @@ -3614,6 +3653,7 @@ assert_eq!(3", stringify!($SelfT), ".checked_next_power_of_two(), Some(4));
assert_eq!(", stringify!($SelfT), "::max_value().checked_next_power_of_two(), None);",
$EndFeature, "
```"),
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn checked_next_power_of_two(self) -> Option<Self> {
self.one_less_than_next_power_of_two().checked_add(1)
Expand Down Expand Up @@ -3719,6 +3759,19 @@ big endian.
```
let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand All @@ -3738,6 +3791,19 @@ little endian.
```
let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand Down Expand Up @@ -3767,6 +3833,19 @@ let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"bi
", $le_bytes, "
});
assert_eq!(value, ", $swap_op, ");
```
When starting from a slice rather than an array, fallible conversion APIs can be used:
```
#![feature(try_from)]
use std::convert::TryInto;
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
*input = rest;
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_unstable(feature = "const_int_conversion")]
Expand Down
24 changes: 21 additions & 3 deletions src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@
use fmt;
use panic::{Location, PanicInfo};

#[cold] #[inline(never)] // this is the slow path, always
#[cold]
// never inline unless panic_immediate_abort to avoid code
// bloat at the call sites as much as possible
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
#[lang = "panic"]
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
if cfg!(feature = "panic_immediate_abort") {
unsafe { super::intrinsics::abort() }
}

// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
// reduce size overhead. The format_args! macro uses str's Display trait to
// write expr, which calls Formatter::pad, which must accommodate string
Expand All @@ -52,16 +59,27 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), &(file, line, col))
}

#[cold] #[inline(never)]
#[cold]
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
#[lang = "panic_bounds_check"]
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
index: usize, len: usize) -> ! {
if cfg!(feature = "panic_immediate_abort") {
unsafe { super::intrinsics::abort() }
}

panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
len, index), file_line_col)
}

#[cold] #[inline(never)]
#[cold]
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
if cfg!(feature = "panic_immediate_abort") {
unsafe { super::intrinsics::abort() }
}

// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
extern "Rust" {
Expand Down
16 changes: 0 additions & 16 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ use syntax::ast;
use syntax::ast::*;
use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
Expand Down Expand Up @@ -3628,7 +3627,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::PatKind::TupleStruct(
qpath,
pats.iter().map(|x| self.lower_pat(x)).collect(),
Expand All @@ -3643,7 +3641,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::PatKind::Path(qpath)
}
PatKind::Struct(ref path, ref fields, etc) => {
Expand Down Expand Up @@ -4039,7 +4036,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::ExprKind::Path(qpath)
}
ExprKind::Break(opt_label, ref opt_expr) => {
Expand Down Expand Up @@ -5102,18 +5098,6 @@ impl<'a> LoweringContext<'a> {
ThinVec::new()));
P(self.expr_call(e.span, from_err, hir_vec![e]))
}

fn check_self_struct_ctor_feature(&self, qp: &hir::QPath) {
if let hir::QPath::Resolved(_, ref p) = qp {
if p.segments.len() == 1 &&
p.segments[0].ident.name == keywords::SelfType.name() &&
!self.sess.features_untracked().self_struct_ctor {
emit_feature_err(&self.sess.parse_sess, "self_struct_ctor",
p.span, GateIssue::Language,
"`Self` struct constructors are unstable");
}
}
}
}

fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body>) -> Vec<hir::BodyId> {
Expand Down
Loading

0 comments on commit d09466c

Please sign in to comment.