Skip to content

Commit e063518

Browse files
committed
Auto merge of #50968 - kennytm:rollup, r=kennytm
Rollup of 15 pull requests Successful merges: - #50846 (Add E0665) - #50849 (CheckLoopVisitor: also visit closure arguments) - #50863 (Make `[T]::len` and `str::len` const fn) - #50875 (rustdoc: use "short form" doc(cfg) printing even when combined with other conditionals) - #50913 (Fix typo in cell.rs) - #50914 (Issue #50636: Improve error diagnostic with missing commas after struct fields.) - #50931 (Inline `try_get`.) - #50932 (Optimize seen Predicate filtering.) - #50945 (Stabilize feature from_ref) - #50946 (rustc: Fix procedural macros generating lifetime tokens) - #50947 (rustdoc: set tab width in rust source blocks) - #50952 (Add the 2018 edition of the book to doc.rust-lang.org) - #50958 (Micro-optimization on PR#50697) - #50961 (Fix FileCheck finding with MSVC) - #50963 (Right-size the `VecDeque` in `coerce_unsized`.) Failed merges:
2 parents 9f80ea3 + 0c4d337 commit e063518

File tree

29 files changed

+349
-67
lines changed

29 files changed

+349
-67
lines changed

src/bootstrap/doc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ impl Step for TheBook {
272272
name: INTERNER.intern_string(format!("{}/second-edition", name)),
273273
});
274274

275+
// build book 2018 edition
276+
builder.ensure(Rustbook {
277+
target,
278+
name: INTERNER.intern_string(format!("{}/2018-edition", name)),
279+
});
280+
275281
// build the version info page and CSS
276282
builder.ensure(Standalone {
277283
compiler,

src/bootstrap/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,20 @@ impl Build {
592592
Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target))
593593
} else {
594594
let base = self.llvm_out(self.config.build).join("build");
595-
let exe = exe("FileCheck", &*target);
596-
if !self.config.ninja && self.config.build.contains("msvc") {
597-
base.join("Release/bin").join(exe)
595+
let base = if !self.config.ninja && self.config.build.contains("msvc") {
596+
if self.config.llvm_optimize {
597+
if self.config.llvm_release_debuginfo {
598+
base.join("RelWithDebInfo")
599+
} else {
600+
base.join("Release")
601+
}
602+
} else {
603+
base.join("Debug")
604+
}
598605
} else {
599-
base.join("bin").join(exe)
600-
}
606+
base
607+
};
608+
base.join("bin").join(exe("FileCheck", &*target))
601609
}
602610
}
603611

src/doc/book

Submodule book updated 110 files

src/liballoc/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
119119
pub use core::slice::{RSplit, RSplitMut};
120120
#[stable(feature = "rust1", since = "1.0.0")]
121121
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
122-
#[unstable(feature = "from_ref", issue = "45703")]
123-
pub use core::slice::{from_ref, from_ref_mut};
122+
#[stable(feature = "from_ref", since = "1.28.0")]
123+
pub use core::slice::{from_ref, from_mut};
124124
#[unstable(feature = "slice_get_slice", issue = "35729")]
125125
pub use core::slice::SliceIndex;
126126
#[unstable(feature = "exact_chunks", issue = "47115")]

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
12571257
/// To assist with proper design, the following scenarios are explicitly declared legal
12581258
/// for single-threaded code:
12591259
///
1260-
/// 1. A `&T` reference can be released to safe code and there it can co-exit with other `&T`
1260+
/// 1. A `&T` reference can be released to safe code and there it can co-exist with other `&T`
12611261
/// references, but not with a `&mut T`
12621262
///
12631263
/// 2. A `&mut T` reference may be released to safe code provided neither other `&mut T` nor `&T`

src/libcore/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
#![feature(powerpc_target_feature)]
120120
#![feature(mips_target_feature)]
121121
#![feature(aarch64_target_feature)]
122+
#![feature(const_slice_len)]
123+
#![feature(const_str_as_bytes)]
124+
#![feature(const_str_len)]
122125

123126
#[prelude_import]
124127
#[allow(unused)]

src/libcore/slice/mod.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ mod rotate;
5959
mod sort;
6060

6161
#[repr(C)]
62-
struct Repr<T> {
63-
pub data: *const T,
64-
pub len: usize,
62+
union Repr<'a, T: 'a> {
63+
rust: &'a [T],
64+
rust_mut: &'a mut [T],
65+
raw: FatPtr<T>,
66+
}
67+
68+
#[repr(C)]
69+
struct FatPtr<T> {
70+
data: *const T,
71+
len: usize,
6572
}
6673

6774
//
@@ -119,9 +126,10 @@ impl<T> [T] {
119126
/// ```
120127
#[stable(feature = "rust1", since = "1.0.0")]
121128
#[inline]
122-
pub fn len(&self) -> usize {
129+
#[rustc_const_unstable(feature = "const_slice_len")]
130+
pub const fn len(&self) -> usize {
123131
unsafe {
124-
mem::transmute::<&[T], Repr<T>>(self).len
132+
Repr { rust: self }.raw.len
125133
}
126134
}
127135

@@ -135,7 +143,8 @@ impl<T> [T] {
135143
/// ```
136144
#[stable(feature = "rust1", since = "1.0.0")]
137145
#[inline]
138-
pub fn is_empty(&self) -> bool {
146+
#[rustc_const_unstable(feature = "const_slice_len")]
147+
pub const fn is_empty(&self) -> bool {
139148
self.len() == 0
140149
}
141150

@@ -418,7 +427,8 @@ impl<T> [T] {
418427
/// ```
419428
#[stable(feature = "rust1", since = "1.0.0")]
420429
#[inline]
421-
pub fn as_ptr(&self) -> *const T {
430+
#[rustc_const_unstable(feature = "const_slice_as_ptr")]
431+
pub const fn as_ptr(&self) -> *const T {
422432
self as *const [T] as *const T
423433
}
424434

@@ -3856,8 +3866,8 @@ unsafe impl<'a, T> TrustedRandomAccess for ExactChunksMut<'a, T> {
38563866
/// ```
38573867
#[inline]
38583868
#[stable(feature = "rust1", since = "1.0.0")]
3859-
pub unsafe fn from_raw_parts<'a, T>(p: *const T, len: usize) -> &'a [T] {
3860-
mem::transmute(Repr { data: p, len: len })
3869+
pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
3870+
Repr { raw: FatPtr { data, len } }.rust
38613871
}
38623872

38633873
/// Performs the same functionality as `from_raw_parts`, except that a mutable
@@ -3869,21 +3879,21 @@ pub unsafe fn from_raw_parts<'a, T>(p: *const T, len: usize) -> &'a [T] {
38693879
/// `from_raw_parts`.
38703880
#[inline]
38713881
#[stable(feature = "rust1", since = "1.0.0")]
3872-
pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] {
3873-
mem::transmute(Repr { data: p, len: len })
3882+
pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
3883+
Repr { raw: FatPtr { data, len} }.rust_mut
38743884
}
38753885

38763886
/// Converts a reference to T into a slice of length 1 (without copying).
3877-
#[unstable(feature = "from_ref", issue = "45703")]
3887+
#[stable(feature = "from_ref", since = "1.28.0")]
38783888
pub fn from_ref<T>(s: &T) -> &[T] {
38793889
unsafe {
38803890
from_raw_parts(s, 1)
38813891
}
38823892
}
38833893

38843894
/// Converts a reference to T into a slice of length 1 (without copying).
3885-
#[unstable(feature = "from_ref", issue = "45703")]
3886-
pub fn from_ref_mut<T>(s: &mut T) -> &mut [T] {
3895+
#[stable(feature = "from_ref", since = "1.28.0")]
3896+
pub fn from_mut<T>(s: &mut T) -> &mut [T] {
38873897
unsafe {
38883898
from_raw_parts_mut(s, 1)
38893899
}

src/libcore/str/mod.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,8 @@ impl str {
21662166
/// ```
21672167
#[stable(feature = "rust1", since = "1.0.0")]
21682168
#[inline]
2169-
pub fn len(&self) -> usize {
2169+
#[rustc_const_unstable(feature = "const_str_len")]
2170+
pub const fn len(&self) -> usize {
21702171
self.as_bytes().len()
21712172
}
21722173

@@ -2185,7 +2186,8 @@ impl str {
21852186
/// ```
21862187
#[inline]
21872188
#[stable(feature = "rust1", since = "1.0.0")]
2188-
pub fn is_empty(&self) -> bool {
2189+
#[rustc_const_unstable(feature = "const_str_len")]
2190+
pub const fn is_empty(&self) -> bool {
21892191
self.len() == 0
21902192
}
21912193

@@ -2242,8 +2244,15 @@ impl str {
22422244
/// ```
22432245
#[stable(feature = "rust1", since = "1.0.0")]
22442246
#[inline(always)]
2245-
pub fn as_bytes(&self) -> &[u8] {
2246-
unsafe { &*(self as *const str as *const [u8]) }
2247+
#[rustc_const_unstable(feature="const_str_as_bytes")]
2248+
pub const fn as_bytes(&self) -> &[u8] {
2249+
unsafe {
2250+
union Slices<'a> {
2251+
str: &'a str,
2252+
slice: &'a [u8],
2253+
}
2254+
Slices { str: self }.slice
2255+
}
22472256
}
22482257

22492258
/// Converts a mutable string slice to a mutable byte slice. To convert the
@@ -2303,7 +2312,8 @@ impl str {
23032312
/// ```
23042313
#[stable(feature = "rust1", since = "1.0.0")]
23052314
#[inline]
2306-
pub fn as_ptr(&self) -> *const u8 {
2315+
#[rustc_const_unstable(feature = "const_str_as_ptr")]
2316+
pub const fn as_ptr(&self) -> *const u8 {
23072317
self as *const str as *const u8
23082318
}
23092319

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl<'tcx> TerminatorKind<'tcx> {
948948
Drop { target: ref mut t, unwind: Some(ref mut u), .. } |
949949
Assert { target: ref mut t, cleanup: Some(ref mut u), .. } |
950950
FalseUnwind { real_target: ref mut t, unwind: Some(ref mut u) } => {
951-
Some(t).into_iter().chain(slice::from_ref_mut(u))
951+
Some(t).into_iter().chain(slice::from_mut(u))
952952
}
953953
SwitchInt { ref mut targets, .. } => {
954954
None.into_iter().chain(&mut targets[..])

src/librustc/traits/select.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -3356,13 +3356,28 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
33563356
predicate: predicate.value
33573357
}))
33583358
}).collect();
3359+
33593360
// We are performing deduplication here to avoid exponential blowups
33603361
// (#38528) from happening, but the real cause of the duplication is
33613362
// unknown. What we know is that the deduplication avoids exponential
3362-
// amount of predicates being propogated when processing deeply nested
3363+
// amount of predicates being propagated when processing deeply nested
33633364
// types.
3364-
let mut seen = FxHashSet();
3365-
predicates.retain(|i| seen.insert(i.clone()));
3365+
//
3366+
// This code is hot enough that it's worth avoiding the allocation
3367+
// required for the FxHashSet when possible. Special-casing lengths 0,
3368+
// 1 and 2 covers roughly 75--80% of the cases.
3369+
if predicates.len() <= 1 {
3370+
// No possibility of duplicates.
3371+
} else if predicates.len() == 2 {
3372+
// Only two elements. Drop the second if they are equal.
3373+
if predicates[0] == predicates[1] {
3374+
predicates.truncate(1);
3375+
}
3376+
} else {
3377+
// Three or more elements. Use a general deduplication process.
3378+
let mut seen = FxHashSet();
3379+
predicates.retain(|i| seen.insert(i.clone()));
3380+
}
33663381
self.infcx().plug_leaks(skol_map, snapshot, predicates)
33673382
}
33683383
}

src/librustc/ty/maps/plumbing.rs

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
105105
/// start executing the query, or it returns with the result of the query.
106106
/// If the query is executing elsewhere, this will wait for it.
107107
/// If the query panicked, this will silently panic.
108+
///
109+
/// This function is inlined because that results in a noticeable speedup
110+
/// for some compile-time benchmarks.
111+
#[inline(always)]
108112
pub(super) fn try_get(
109113
tcx: TyCtxt<'a, 'tcx, '_>,
110114
span: Span,

src/librustc_mir/borrow_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18531853
for index in ii {
18541854
if flow_state.ever_inits.contains(index) {
18551855
self.used_mut.insert(*local);
1856+
break;
18561857
}
18571858
}
18581859
}

src/librustc_passes/loops.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
8282
hir::ExprLoop(ref b, _, source) => {
8383
self.with_context(Loop(LoopKind::Loop(source)), |v| v.visit_block(&b));
8484
}
85-
hir::ExprClosure(.., b, _, _) => {
85+
hir::ExprClosure(_, ref function_decl, b, _, _) => {
86+
self.visit_fn_decl(&function_decl);
8687
self.with_context(Closure, |v| v.visit_nested_body(b));
8788
}
8889
hir::ExprBlock(ref b, Some(_label)) => {

src/librustc_typeck/check/coercion.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
537537

538538
let mut selcx = traits::SelectionContext::new(self);
539539

540-
// Use a FIFO queue for this custom fulfillment procedure.
541-
let mut queue = VecDeque::new();
540+
// Use a FIFO queue for this custom fulfillment procedure. (The maximum
541+
// length is almost always 1.)
542+
let mut queue = VecDeque::with_capacity(1);
542543

543544
// Create an obligation for `Source: CoerceUnsized<Target>`.
544545
let cause = ObligationCause::misc(self.cause.span, self.body_id);

0 commit comments

Comments
 (0)