Skip to content

Commit d09466c

Browse files
committed
Auto merge of #56381 - kennytm:rollup, r=kennytm
Rollup of 19 pull requests Successful merges: - #55011 (Add libstd Cargo feature "panic_immediate_abort") - #55821 (Use sort_by_cached_key when the key function is not trivial/free) - #56014 (add test for issue #21335) - #56131 (Assorted tweaks) - #56214 (Implement chalk unification routines) - #56216 (Add TryFrom<&[T]> for [T; $N] where T: Copy) - #56268 (Reuse the `P` in `InvocationCollector::fold_{,opt_}expr`.) - #56324 (Use raw_entry for more efficient interning) - #56336 (Clean up and streamline the pretty-printer) - #56337 (Fix const_fn ICE with non-const function pointer) - #56339 (Remove not used option) - #56341 (Rename conversion util; remove duplicate util in librustc_codegen_llvm.) - #56349 (rustc 1.30.0's linker flavor inference is a non-backwards compat change to -Clinker) - #56355 (Add inline attributes and add unit to CommonTypes) - #56360 (Optimize local linkchecker program) - #56364 (Fix panic with outlives in existential type) - #56365 (Stabilize self_struct_ctor feature.) - #56367 (Moved some feature gate tests to correct location) - #56373 (Update books)
2 parents d48ab69 + a6c4771 commit d09466c

File tree

76 files changed

+1908
-856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1908
-856
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@
6565
[submodule "src/doc/rustc-guide"]
6666
path = src/doc/rustc-guide
6767
url = https://github.com/rust-lang/rustc-guide.git
68+
[submodule "src/doc/edition-guide"]
69+
path = src/doc/edition-guide
70+
url = https://github.com/rust-lang-nursery/edition-guide

src/bootstrap/doc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ macro_rules! book {
7070
book!(
7171
Nomicon, "src/doc/nomicon", "nomicon";
7272
Reference, "src/doc/reference", "reference";
73+
EditionGuide, "src/doc/edition-guide", "edition-guide";
7374
RustdocBook, "src/doc/rustdoc", "rustdoc";
7475
RustcBook, "src/doc/rustc", "rustc";
7576
RustByExample, "src/doc/rust-by-example", "rust-by-example";

src/doc/edition-guide

Submodule edition-guide added at ad89586

src/doc/nomicon

src/doc/unstable-book/src/language-features/self-struct-ctor.md

-33
This file was deleted.

src/liballoc/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ impl String {
618618
/// ```
619619
#[stable(feature = "rust1", since = "1.0.0")]
620620
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
621+
// This isn't done via collect::<Result<_, _>>() for performance reasons.
622+
// FIXME: the function can be simplified again when #48994 is closed.
621623
let mut ret = String::with_capacity(v.len());
622624
for c in decode_utf16(v.iter().cloned()) {
623625
if let Ok(c) = c {

src/libarena/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub struct DroplessArena {
298298
unsafe impl Send for DroplessArena {}
299299

300300
impl Default for DroplessArena {
301+
#[inline]
301302
fn default() -> DroplessArena {
302303
DroplessArena {
303304
ptr: Cell::new(0 as *mut u8),
@@ -319,6 +320,7 @@ impl DroplessArena {
319320
false
320321
}
321322

323+
#[inline]
322324
fn align(&self, align: usize) {
323325
let final_address = ((self.ptr.get() as usize) + align - 1) & !(align - 1);
324326
self.ptr.set(final_address as *mut u8);

src/libcore/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ path = "../libcore/benches/lib.rs"
2121

2222
[dev-dependencies]
2323
rand = "0.5"
24+
25+
[features]
26+
# Make panics and failed asserts immediately abort without formatting any message
27+
panic_immediate_abort = []

src/libcore/array.rs

+9
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ macro_rules! array_impls {
148148
}
149149
}
150150

151+
#[unstable(feature = "try_from", issue = "33417")]
152+
impl<'a, T> TryFrom<&'a [T]> for [T; $N] where T: Copy {
153+
type Error = TryFromSliceError;
154+
155+
fn try_from(slice: &[T]) -> Result<[T; $N], TryFromSliceError> {
156+
<&Self>::try_from(slice).map(|r| *r)
157+
}
158+
}
159+
151160
#[unstable(feature = "try_from", issue = "33417")]
152161
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
153162
type Error = TryFromSliceError;

src/libcore/num/mod.rs

+79
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,19 @@ big endian.
19891989
```
19901990
let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
19911991
assert_eq!(value, ", $swap_op, ");
1992+
```
1993+
1994+
When starting from a slice rather than an array, fallible conversion APIs can be used:
1995+
1996+
```
1997+
#![feature(try_from)]
1998+
use std::convert::TryInto;
1999+
2000+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
2001+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
2002+
*input = rest;
2003+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
2004+
}
19922005
```"),
19932006
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
19942007
#[rustc_const_unstable(feature = "const_int_conversion")]
@@ -2008,6 +2021,19 @@ little endian.
20082021
```
20092022
let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
20102023
assert_eq!(value, ", $swap_op, ");
2024+
```
2025+
2026+
When starting from a slice rather than an array, fallible conversion APIs can be used:
2027+
2028+
```
2029+
#![feature(try_from)]
2030+
use std::convert::TryInto;
2031+
2032+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
2033+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
2034+
*input = rest;
2035+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
2036+
}
20112037
```"),
20122038
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
20132039
#[rustc_const_unstable(feature = "const_int_conversion")]
@@ -2037,6 +2063,19 @@ let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"bi
20372063
", $le_bytes, "
20382064
});
20392065
assert_eq!(value, ", $swap_op, ");
2066+
```
2067+
2068+
When starting from a slice rather than an array, fallible conversion APIs can be used:
2069+
2070+
```
2071+
#![feature(try_from)]
2072+
use std::convert::TryInto;
2073+
2074+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
2075+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
2076+
*input = rest;
2077+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
2078+
}
20402079
```"),
20412080
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
20422081
#[rustc_const_unstable(feature = "const_int_conversion")]
@@ -3614,6 +3653,7 @@ assert_eq!(3", stringify!($SelfT), ".checked_next_power_of_two(), Some(4));
36143653
assert_eq!(", stringify!($SelfT), "::max_value().checked_next_power_of_two(), None);",
36153654
$EndFeature, "
36163655
```"),
3656+
#[inline]
36173657
#[stable(feature = "rust1", since = "1.0.0")]
36183658
pub fn checked_next_power_of_two(self) -> Option<Self> {
36193659
self.one_less_than_next_power_of_two().checked_add(1)
@@ -3719,6 +3759,19 @@ big endian.
37193759
```
37203760
let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
37213761
assert_eq!(value, ", $swap_op, ");
3762+
```
3763+
3764+
When starting from a slice rather than an array, fallible conversion APIs can be used:
3765+
3766+
```
3767+
#![feature(try_from)]
3768+
use std::convert::TryInto;
3769+
3770+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
3771+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
3772+
*input = rest;
3773+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
3774+
}
37223775
```"),
37233776
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
37243777
#[rustc_const_unstable(feature = "const_int_conversion")]
@@ -3738,6 +3791,19 @@ little endian.
37383791
```
37393792
let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
37403793
assert_eq!(value, ", $swap_op, ");
3794+
```
3795+
3796+
When starting from a slice rather than an array, fallible conversion APIs can be used:
3797+
3798+
```
3799+
#![feature(try_from)]
3800+
use std::convert::TryInto;
3801+
3802+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
3803+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
3804+
*input = rest;
3805+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
3806+
}
37413807
```"),
37423808
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
37433809
#[rustc_const_unstable(feature = "const_int_conversion")]
@@ -3767,6 +3833,19 @@ let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"bi
37673833
", $le_bytes, "
37683834
});
37693835
assert_eq!(value, ", $swap_op, ");
3836+
```
3837+
3838+
When starting from a slice rather than an array, fallible conversion APIs can be used:
3839+
3840+
```
3841+
#![feature(try_from)]
3842+
use std::convert::TryInto;
3843+
3844+
fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {
3845+
let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());
3846+
*input = rest;
3847+
", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())
3848+
}
37703849
```"),
37713850
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
37723851
#[rustc_const_unstable(feature = "const_int_conversion")]

src/libcore/panicking.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@
3939
use fmt;
4040
use panic::{Location, PanicInfo};
4141

42-
#[cold] #[inline(never)] // this is the slow path, always
42+
#[cold]
43+
// never inline unless panic_immediate_abort to avoid code
44+
// bloat at the call sites as much as possible
45+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
4346
#[lang = "panic"]
4447
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
48+
if cfg!(feature = "panic_immediate_abort") {
49+
unsafe { super::intrinsics::abort() }
50+
}
51+
4552
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
4653
// reduce size overhead. The format_args! macro uses str's Display trait to
4754
// write expr, which calls Formatter::pad, which must accommodate string
@@ -52,16 +59,27 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
5259
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), &(file, line, col))
5360
}
5461

55-
#[cold] #[inline(never)]
62+
#[cold]
63+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
5664
#[lang = "panic_bounds_check"]
5765
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
5866
index: usize, len: usize) -> ! {
67+
if cfg!(feature = "panic_immediate_abort") {
68+
unsafe { super::intrinsics::abort() }
69+
}
70+
5971
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
6072
len, index), file_line_col)
6173
}
6274

63-
#[cold] #[inline(never)]
75+
#[cold]
76+
#[cfg_attr(not(feature="panic_immediate_abort"),inline(never))]
77+
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
6478
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
79+
if cfg!(feature = "panic_immediate_abort") {
80+
unsafe { super::intrinsics::abort() }
81+
}
82+
6583
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
6684
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
6785
extern "Rust" {

src/librustc/hir/lowering.rs

-16
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use syntax::ast;
6767
use syntax::ast::*;
6868
use syntax::errors;
6969
use syntax::ext::hygiene::{Mark, SyntaxContext};
70-
use syntax::feature_gate::{emit_feature_err, GateIssue};
7170
use syntax::print::pprust;
7271
use syntax::ptr::P;
7372
use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
@@ -3628,7 +3627,6 @@ impl<'a> LoweringContext<'a> {
36283627
ParamMode::Optional,
36293628
ImplTraitContext::disallowed(),
36303629
);
3631-
self.check_self_struct_ctor_feature(&qpath);
36323630
hir::PatKind::TupleStruct(
36333631
qpath,
36343632
pats.iter().map(|x| self.lower_pat(x)).collect(),
@@ -3643,7 +3641,6 @@ impl<'a> LoweringContext<'a> {
36433641
ParamMode::Optional,
36443642
ImplTraitContext::disallowed(),
36453643
);
3646-
self.check_self_struct_ctor_feature(&qpath);
36473644
hir::PatKind::Path(qpath)
36483645
}
36493646
PatKind::Struct(ref path, ref fields, etc) => {
@@ -4039,7 +4036,6 @@ impl<'a> LoweringContext<'a> {
40394036
ParamMode::Optional,
40404037
ImplTraitContext::disallowed(),
40414038
);
4042-
self.check_self_struct_ctor_feature(&qpath);
40434039
hir::ExprKind::Path(qpath)
40444040
}
40454041
ExprKind::Break(opt_label, ref opt_expr) => {
@@ -5102,18 +5098,6 @@ impl<'a> LoweringContext<'a> {
51025098
ThinVec::new()));
51035099
P(self.expr_call(e.span, from_err, hir_vec![e]))
51045100
}
5105-
5106-
fn check_self_struct_ctor_feature(&self, qp: &hir::QPath) {
5107-
if let hir::QPath::Resolved(_, ref p) = qp {
5108-
if p.segments.len() == 1 &&
5109-
p.segments[0].ident.name == keywords::SelfType.name() &&
5110-
!self.sess.features_untracked().self_struct_ctor {
5111-
emit_feature_err(&self.sess.parse_sess, "self_struct_ctor",
5112-
p.span, GateIssue::Language,
5113-
"`Self` struct constructors are unstable");
5114-
}
5115-
}
5116-
}
51175101
}
51185102

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

0 commit comments

Comments
 (0)