Skip to content

Commit bb86748

Browse files
committedJun 10, 2020
Auto merge of #73190 - Dylan-DPC:rollup-9wbyh4y, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #72417 (Remove `RawVec::reserve_in_place`.) - #73098 (Add Item::is_fake for rustdoc) - #73122 (Resolve E0584 conflict) - #73123 (Clean up E0647 explanation) - #73133 (Enforce unwind invariants) - #73148 (Fix a typo (size of the size)) - #73149 (typo: awailable -> available) - #73161 (Add mailmap entry) Failed merges: r? @ghost
·
1.89.01.46.0
2 parents 2835224 + 74380d7 commit bb86748

File tree

15 files changed

+172
-168
lines changed

15 files changed

+172
-168
lines changed
 

‎.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ Tim Chevalier <chevalier@alum.wellesley.edu> <catamorphism@gmail.com>
266266
Tim JIANG <p90eri@gmail.com>
267267
Tim Joseph Dumol <tim@timdumol.com>
268268
Torsten Weber <TorstenWeber12@gmail.com> <torstenweber12@gmail.com>
269+
Trevor Spiteri <tspiteri@ieee.org> <trevor.spiteri@um.edu.mt>
269270
Ty Overby <ty@pre-alpha.com>
270271
Ulrik Sverdrup <bluss@users.noreply.github.com> bluss <bluss@users.noreply.github.com>
271272
Ulrik Sverdrup <bluss@users.noreply.github.com> bluss <bluss>

‎src/doc/unstable-book/src/compiler-flags/report-time.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Available options:
2222

2323
```sh
2424
--report-time [plain|colored]
25-
Show execution time of each test. Awailable values:
25+
Show execution time of each test. Available values:
2626
plain = do not colorize the execution time (default);
2727
colored = colorize output according to the `color`
2828
parameter value;

‎src/liballoc/raw_vec.rs

Lines changed: 36 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::ptr::{NonNull, Unique};
99
use core::slice;
1010

1111
use crate::alloc::{
12-
handle_alloc_error, AllocErr,
12+
handle_alloc_error,
1313
AllocInit::{self, *},
1414
AllocRef, Global, Layout,
1515
ReallocPlacement::{self, *},
@@ -235,13 +235,13 @@ impl<T, A: AllocRef> RawVec<T, A> {
235235
}
236236
}
237237

238-
/// Ensures that the buffer contains at least enough space to hold
239-
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
240-
/// enough capacity, will reallocate enough space plus comfortable slack
241-
/// space to get amortized `O(1)` behavior. Will limit this behavior
242-
/// if it would needlessly cause itself to panic.
238+
/// Ensures that the buffer contains at least enough space to hold `len +
239+
/// additional` elements. If it doesn't already have enough capacity, will
240+
/// reallocate enough space plus comfortable slack space to get amortized
241+
/// `O(1)` behavior. Will limit this behavior if it would needlessly cause
242+
/// itself to panic.
243243
///
244-
/// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate
244+
/// If `len` exceeds `self.capacity()`, this may fail to actually allocate
245245
/// the requested space. This is not really unsafe, but the unsafe
246246
/// code *you* write that relies on the behavior of this function may break.
247247
///
@@ -287,64 +287,32 @@ impl<T, A: AllocRef> RawVec<T, A> {
287287
/// # vector.push_all(&[1, 3, 5, 7, 9]);
288288
/// # }
289289
/// ```
290-
pub fn reserve(&mut self, used_capacity: usize, needed_extra_capacity: usize) {
291-
match self.try_reserve(used_capacity, needed_extra_capacity) {
290+
pub fn reserve(&mut self, len: usize, additional: usize) {
291+
match self.try_reserve(len, additional) {
292292
Err(CapacityOverflow) => capacity_overflow(),
293293
Err(AllocError { layout, .. }) => handle_alloc_error(layout),
294294
Ok(()) => { /* yay */ }
295295
}
296296
}
297297

298298
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
299-
pub fn try_reserve(
300-
&mut self,
301-
used_capacity: usize,
302-
needed_extra_capacity: usize,
303-
) -> Result<(), TryReserveError> {
304-
if self.needs_to_grow(used_capacity, needed_extra_capacity) {
305-
self.grow_amortized(used_capacity, needed_extra_capacity, MayMove)
299+
pub fn try_reserve(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
300+
if self.needs_to_grow(len, additional) {
301+
self.grow_amortized(len, additional)
306302
} else {
307303
Ok(())
308304
}
309305
}
310306

311-
/// Attempts to ensure that the buffer contains at least enough space to hold
312-
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
313-
/// enough capacity, will reallocate in place enough space plus comfortable slack
314-
/// space to get amortized `O(1)` behavior. Will limit this behaviour
315-
/// if it would needlessly cause itself to panic.
307+
/// Ensures that the buffer contains at least enough space to hold `len +
308+
/// additional` elements. If it doesn't already, will reallocate the
309+
/// minimum possible amount of memory necessary. Generally this will be
310+
/// exactly the amount of memory necessary, but in principle the allocator
311+
/// is free to give back more than we asked for.
316312
///
317-
/// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate
318-
/// the requested space. This is not really unsafe, but the unsafe
319-
/// code *you* write that relies on the behavior of this function may break.
320-
///
321-
/// Returns `true` if the reallocation attempt has succeeded.
322-
///
323-
/// # Panics
324-
///
325-
/// * Panics if the requested capacity exceeds `usize::MAX` bytes.
326-
/// * Panics on 32-bit platforms if the requested capacity exceeds
327-
/// `isize::MAX` bytes.
328-
pub fn reserve_in_place(&mut self, used_capacity: usize, needed_extra_capacity: usize) -> bool {
329-
// This is more readable than putting this in one line:
330-
// `!self.needs_to_grow(...) || self.grow(...).is_ok()`
331-
if self.needs_to_grow(used_capacity, needed_extra_capacity) {
332-
self.grow_amortized(used_capacity, needed_extra_capacity, InPlace).is_ok()
333-
} else {
334-
true
335-
}
336-
}
337-
338-
/// Ensures that the buffer contains at least enough space to hold
339-
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
340-
/// will reallocate the minimum possible amount of memory necessary.
341-
/// Generally this will be exactly the amount of memory necessary,
342-
/// but in principle the allocator is free to give back more than what
343-
/// we asked for.
344-
///
345-
/// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate
346-
/// the requested space. This is not really unsafe, but the unsafe
347-
/// code *you* write that relies on the behavior of this function may break.
313+
/// If `len` exceeds `self.capacity()`, this may fail to actually allocate
314+
/// the requested space. This is not really unsafe, but the unsafe code
315+
/// *you* write that relies on the behavior of this function may break.
348316
///
349317
/// # Panics
350318
///
@@ -355,8 +323,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
355323
/// # Aborts
356324
///
357325
/// Aborts on OOM.
358-
pub fn reserve_exact(&mut self, used_capacity: usize, needed_extra_capacity: usize) {
359-
match self.try_reserve_exact(used_capacity, needed_extra_capacity) {
326+
pub fn reserve_exact(&mut self, len: usize, additional: usize) {
327+
match self.try_reserve_exact(len, additional) {
360328
Err(CapacityOverflow) => capacity_overflow(),
361329
Err(AllocError { layout, .. }) => handle_alloc_error(layout),
362330
Ok(()) => { /* yay */ }
@@ -366,14 +334,10 @@ impl<T, A: AllocRef> RawVec<T, A> {
366334
/// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
367335
pub fn try_reserve_exact(
368336
&mut self,
369-
used_capacity: usize,
370-
needed_extra_capacity: usize,
337+
len: usize,
338+
additional: usize,
371339
) -> Result<(), TryReserveError> {
372-
if self.needs_to_grow(used_capacity, needed_extra_capacity) {
373-
self.grow_exact(used_capacity, needed_extra_capacity)
374-
} else {
375-
Ok(())
376-
}
340+
if self.needs_to_grow(len, additional) { self.grow_exact(len, additional) } else { Ok(()) }
377341
}
378342

379343
/// Shrinks the allocation down to the specified amount. If the given amount
@@ -398,8 +362,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
398362
impl<T, A: AllocRef> RawVec<T, A> {
399363
/// Returns if the buffer needs to grow to fulfill the needed extra capacity.
400364
/// Mainly used to make inlining reserve-calls possible without inlining `grow`.
401-
fn needs_to_grow(&self, used_capacity: usize, needed_extra_capacity: usize) -> bool {
402-
needed_extra_capacity > self.capacity().wrapping_sub(used_capacity)
365+
fn needs_to_grow(&self, len: usize, additional: usize) -> bool {
366+
additional > self.capacity().wrapping_sub(len)
403367
}
404368

405369
fn capacity_from_bytes(excess: usize) -> usize {
@@ -419,14 +383,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
419383
// so that all of the code that depends on `T` is within it, while as much
420384
// of the code that doesn't depend on `T` as possible is in functions that
421385
// are non-generic over `T`.
422-
fn grow_amortized(
423-
&mut self,
424-
used_capacity: usize,
425-
needed_extra_capacity: usize,
426-
placement: ReallocPlacement,
427-
) -> Result<(), TryReserveError> {
386+
fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
428387
// This is ensured by the calling contexts.
429-
debug_assert!(needed_extra_capacity > 0);
388+
debug_assert!(additional > 0);
430389

431390
if mem::size_of::<T>() == 0 {
432391
// Since we return a capacity of `usize::MAX` when `elem_size` is
@@ -435,8 +394,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
435394
}
436395

437396
// Nothing we can really do about these checks, sadly.
438-
let required_cap =
439-
used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
397+
let required_cap = len.checked_add(additional).ok_or(CapacityOverflow)?;
440398

441399
// This guarantees exponential growth. The doubling cannot overflow
442400
// because `cap <= isize::MAX` and the type of `cap` is `usize`.
@@ -461,30 +419,26 @@ impl<T, A: AllocRef> RawVec<T, A> {
461419
let new_layout = Layout::array::<T>(cap);
462420

463421
// `finish_grow` is non-generic over `T`.
464-
let memory = finish_grow(new_layout, placement, self.current_memory(), &mut self.alloc)?;
422+
let memory = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
465423
self.set_memory(memory);
466424
Ok(())
467425
}
468426

469427
// The constraints on this method are much the same as those on
470428
// `grow_amortized`, but this method is usually instantiated less often so
471429
// it's less critical.
472-
fn grow_exact(
473-
&mut self,
474-
used_capacity: usize,
475-
needed_extra_capacity: usize,
476-
) -> Result<(), TryReserveError> {
430+
fn grow_exact(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
477431
if mem::size_of::<T>() == 0 {
478432
// Since we return a capacity of `usize::MAX` when the type size is
479433
// 0, getting to here necessarily means the `RawVec` is overfull.
480434
return Err(CapacityOverflow);
481435
}
482436

483-
let cap = used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
437+
let cap = len.checked_add(additional).ok_or(CapacityOverflow)?;
484438
let new_layout = Layout::array::<T>(cap);
485439

486440
// `finish_grow` is non-generic over `T`.
487-
let memory = finish_grow(new_layout, MayMove, self.current_memory(), &mut self.alloc)?;
441+
let memory = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
488442
self.set_memory(memory);
489443
Ok(())
490444
}
@@ -518,7 +472,6 @@ impl<T, A: AllocRef> RawVec<T, A> {
518472
// much smaller than the number of `T` types.)
519473
fn finish_grow<A>(
520474
new_layout: Result<Layout, LayoutErr>,
521-
placement: ReallocPlacement,
522475
current_memory: Option<(NonNull<u8>, Layout)>,
523476
alloc: &mut A,
524477
) -> Result<MemoryBlock, TryReserveError>
@@ -532,12 +485,9 @@ where
532485

533486
let memory = if let Some((ptr, old_layout)) = current_memory {
534487
debug_assert_eq!(old_layout.align(), new_layout.align());
535-
unsafe { alloc.grow(ptr, old_layout, new_layout.size(), placement, Uninitialized) }
488+
unsafe { alloc.grow(ptr, old_layout, new_layout.size(), MayMove, Uninitialized) }
536489
} else {
537-
match placement {
538-
MayMove => alloc.alloc(new_layout, Uninitialized),
539-
InPlace => Err(AllocErr),
540-
}
490+
alloc.alloc(new_layout, Uninitialized)
541491
}
542492
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?;
543493

‎src/liballoc/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,12 +2977,12 @@ impl<T> Drain<'_, T> {
29772977
}
29782978

29792979
/// Makes room for inserting more elements before the tail.
2980-
unsafe fn move_tail(&mut self, extra_capacity: usize) {
2980+
unsafe fn move_tail(&mut self, additional: usize) {
29812981
let vec = self.vec.as_mut();
2982-
let used_capacity = self.tail_start + self.tail_len;
2983-
vec.buf.reserve(used_capacity, extra_capacity);
2982+
let len = self.tail_start + self.tail_len;
2983+
vec.buf.reserve(len, additional);
29842984

2985-
let new_tail_start = self.tail_start + extra_capacity;
2985+
let new_tail_start = self.tail_start + additional;
29862986
let src = vec.as_ptr().add(self.tail_start);
29872987
let dst = vec.as_mut_ptr().add(new_tail_start);
29882988
ptr::copy(src, dst, self.tail_len);

‎src/libcore/slice/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<T> [T] {
409409
/// The returned range is half-open, which means that the end pointer
410410
/// points *one past* the last element of the slice. This way, an empty
411411
/// slice is represented by two equal pointers, and the difference between
412-
/// the two pointers represents the size of the size.
412+
/// the two pointers represents the size of the slice.
413413
///
414414
/// See [`as_ptr`] for warnings on using these pointers. The end pointer
415415
/// requires extra caution, as it does not point to a valid element in the
@@ -464,7 +464,7 @@ impl<T> [T] {
464464
/// The returned range is half-open, which means that the end pointer
465465
/// points *one past* the last element of the slice. This way, an empty
466466
/// slice is represented by two equal pointers, and the difference between
467-
/// the two pointers represents the size of the size.
467+
/// the two pointers represents the size of the slice.
468468
///
469469
/// See [`as_mut_ptr`] for warnings on using these pointers. The end
470470
/// pointer requires extra caution, as it does not point to a valid element

‎src/librustc_arena/lib.rs

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ impl<T> TypedArena<T> {
146146
}
147147

148148
#[inline]
149-
fn can_allocate(&self, len: usize) -> bool {
150-
let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize;
151-
let at_least_bytes = len.checked_mul(mem::size_of::<T>()).unwrap();
152-
available_capacity_bytes >= at_least_bytes
149+
fn can_allocate(&self, additional: usize) -> bool {
150+
let available_bytes = self.end.get() as usize - self.ptr.get() as usize;
151+
let additional_bytes = additional.checked_mul(mem::size_of::<T>()).unwrap();
152+
available_bytes >= additional_bytes
153153
}
154154

155155
/// Ensures there's enough space in the current chunk to fit `len` objects.
156156
#[inline]
157-
fn ensure_capacity(&self, len: usize) {
158-
if !self.can_allocate(len) {
159-
self.grow(len);
160-
debug_assert!(self.can_allocate(len));
157+
fn ensure_capacity(&self, additional: usize) {
158+
if !self.can_allocate(additional) {
159+
self.grow(additional);
160+
debug_assert!(self.can_allocate(additional));
161161
}
162162
}
163163

@@ -214,36 +214,31 @@ impl<T> TypedArena<T> {
214214
/// Grows the arena.
215215
#[inline(never)]
216216
#[cold]
217-
fn grow(&self, n: usize) {
217+
fn grow(&self, additional: usize) {
218218
unsafe {
219-
// We need the element size in to convert chunk sizes (ranging from
219+
// We need the element size to convert chunk sizes (ranging from
220220
// PAGE to HUGE_PAGE bytes) to element counts.
221221
let elem_size = cmp::max(1, mem::size_of::<T>());
222222
let mut chunks = self.chunks.borrow_mut();
223-
let (chunk, mut new_capacity);
223+
let mut new_cap;
224224
if let Some(last_chunk) = chunks.last_mut() {
225225
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
226-
let currently_used_cap = used_bytes / mem::size_of::<T>();
227-
last_chunk.entries = currently_used_cap;
228-
if last_chunk.storage.reserve_in_place(currently_used_cap, n) {
229-
self.end.set(last_chunk.end());
230-
return;
231-
} else {
232-
// If the previous chunk's capacity is less than HUGE_PAGE
233-
// bytes, then this chunk will be least double the previous
234-
// chunk's size.
235-
new_capacity = last_chunk.storage.capacity();
236-
if new_capacity < HUGE_PAGE / elem_size {
237-
new_capacity = new_capacity.checked_mul(2).unwrap();
238-
}
226+
last_chunk.entries = used_bytes / mem::size_of::<T>();
227+
228+
// If the previous chunk's capacity is less than HUGE_PAGE
229+
// bytes, then this chunk will be least double the previous
230+
// chunk's size.
231+
new_cap = last_chunk.storage.capacity();
232+
if new_cap < HUGE_PAGE / elem_size {
233+
new_cap = new_cap.checked_mul(2).unwrap();
239234
}
240235
} else {
241-
new_capacity = PAGE / elem_size;
236+
new_cap = PAGE / elem_size;
242237
}
243-
// Also ensure that this chunk can fit `n`.
244-
new_capacity = cmp::max(n, new_capacity);
238+
// Also ensure that this chunk can fit `additional`.
239+
new_cap = cmp::max(additional, new_cap);
245240

246-
chunk = TypedArenaChunk::<T>::new(new_capacity);
241+
let chunk = TypedArenaChunk::<T>::new(new_cap);
247242
self.ptr.set(chunk.start());
248243
self.end.set(chunk.end());
249244
chunks.push(chunk);
@@ -347,31 +342,28 @@ impl DroplessArena {
347342

348343
#[inline(never)]
349344
#[cold]
350-
fn grow(&self, needed_bytes: usize) {
345+
fn grow(&self, additional: usize) {
351346
unsafe {
352347
let mut chunks = self.chunks.borrow_mut();
353-
let (chunk, mut new_capacity);
348+
let mut new_cap;
354349
if let Some(last_chunk) = chunks.last_mut() {
355-
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
356-
if last_chunk.storage.reserve_in_place(used_bytes, needed_bytes) {
357-
self.end.set(last_chunk.end());
358-
return;
359-
} else {
360-
// If the previous chunk's capacity is less than HUGE_PAGE
361-
// bytes, then this chunk will be least double the previous
362-
// chunk's size.
363-
new_capacity = last_chunk.storage.capacity();
364-
if new_capacity < HUGE_PAGE {
365-
new_capacity = new_capacity.checked_mul(2).unwrap();
366-
}
350+
// There is no need to update `last_chunk.entries` because that
351+
// field isn't used by `DroplessArena`.
352+
353+
// If the previous chunk's capacity is less than HUGE_PAGE
354+
// bytes, then this chunk will be least double the previous
355+
// chunk's size.
356+
new_cap = last_chunk.storage.capacity();
357+
if new_cap < HUGE_PAGE {
358+
new_cap = new_cap.checked_mul(2).unwrap();
367359
}
368360
} else {
369-
new_capacity = PAGE;
361+
new_cap = PAGE;
370362
}
371-
// Also ensure that this chunk can fit `needed_bytes`.
372-
new_capacity = cmp::max(needed_bytes, new_capacity);
363+
// Also ensure that this chunk can fit `additional`.
364+
new_cap = cmp::max(additional, new_cap);
373365

374-
chunk = TypedArenaChunk::<u8>::new(new_capacity);
366+
let chunk = TypedArenaChunk::<u8>::new(new_cap);
375367
self.ptr.set(chunk.start());
376368
self.end.set(chunk.end());
377369
chunks.push(chunk);
@@ -386,7 +378,7 @@ impl DroplessArena {
386378
self.align(align);
387379

388380
let future_end = intrinsics::arith_offset(self.ptr.get(), bytes as isize);
389-
if (future_end as *mut u8) >= self.end.get() {
381+
if (future_end as *mut u8) > self.end.get() {
390382
self.grow(bytes);
391383
}
392384

‎src/librustc_error_codes/error_codes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ E0753: include_str!("./error_codes/E0753.md"),
439439
E0754: include_str!("./error_codes/E0754.md"),
440440
E0758: include_str!("./error_codes/E0758.md"),
441441
E0760: include_str!("./error_codes/E0760.md"),
442+
E0761: include_str!("./error_codes/E0761.md"),
442443
;
443444
// E0006, // merged with E0005
444445
// E0008, // cannot bind by-move into a pattern guard

‎src/librustc_error_codes/error_codes/E0583.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A file wasn't found for an out-of-line module.
22

33
Erroneous code example:
44

5-
```ignore (compile_fail not working here; see Issue #43707)
5+
```compile_fail,E0583
66
mod file_that_doesnt_exist; // error: file not found for module
77
88
fn main() {}

‎src/librustc_error_codes/error_codes/E0647.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
It is not possible to define `start` with a where clause.
1+
The `start` function was defined with a where clause.
2+
23
Erroneous code example:
34

45
```compile_fail,E0647
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Multiple candidate files were found for an out-of-line module.
2+
3+
Erroneous code example:
4+
5+
```rust
6+
// file: ambiguous_module/mod.rs
7+
8+
fn foo() {}
9+
```
10+
11+
```rust
12+
// file: ambiguous_module.rs
13+
14+
fn foo() {}
15+
```
16+
17+
```ignore (multiple source files required for compile_fail)
18+
mod ambiguous_module; // error: file for module `ambiguous_module`
19+
// found at both ambiguous_module.rs and
20+
// ambiguous_module.rs/mod.rs
21+
22+
fn main() {}
23+
```
24+
25+
Please remove this ambiguity by deleting/renaming one of the candidate files.

‎src/librustc_expand/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn default_submod_path<'a>(
291291
let mut err = struct_span_err!(
292292
sess.span_diagnostic,
293293
span,
294-
E0584,
294+
E0761,
295295
"file for module `{}` found at both {} and {}",
296296
mod_name,
297297
default_path_str,

‎src/librustc_mir/transform/validate.rs

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ use rustc_middle::{
1111
};
1212
use rustc_span::def_id::DefId;
1313

14+
#[derive(Copy, Clone, Debug)]
15+
enum EdgeKind {
16+
Unwind,
17+
Normal,
18+
}
19+
1420
pub struct Validator {
1521
/// Describes at which point in the pipeline this validation is happening.
1622
pub when: String,
@@ -49,8 +55,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
4955
);
5056
}
5157

52-
fn check_bb(&self, location: Location, bb: BasicBlock) {
53-
if self.body.basic_blocks().get(bb).is_none() {
58+
fn check_edge(&self, location: Location, bb: BasicBlock, edge_kind: EdgeKind) {
59+
if let Some(bb) = self.body.basic_blocks().get(bb) {
60+
let src = self.body.basic_blocks().get(location.block).unwrap();
61+
match (src.is_cleanup, bb.is_cleanup, edge_kind) {
62+
// Non-cleanup blocks can jump to non-cleanup blocks along non-unwind edges
63+
(false, false, EdgeKind::Normal)
64+
// Non-cleanup blocks can jump to cleanup blocks along unwind edges
65+
| (false, true, EdgeKind::Unwind)
66+
// Cleanup blocks can jump to cleanup blocks along non-unwind edges
67+
| (true, true, EdgeKind::Normal) => {}
68+
// All other jumps are invalid
69+
_ => {
70+
self.fail(
71+
location,
72+
format!(
73+
"{:?} edge to {:?} violates unwind invariants (cleanup {:?} -> {:?})",
74+
edge_kind,
75+
bb,
76+
src.is_cleanup,
77+
bb.is_cleanup,
78+
)
79+
)
80+
}
81+
}
82+
} else {
5483
self.fail(location, format!("encountered jump to invalid basic block {:?}", bb))
5584
}
5685
}
@@ -92,7 +121,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
92121
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
93122
match &terminator.kind {
94123
TerminatorKind::Goto { target } => {
95-
self.check_bb(location, *target);
124+
self.check_edge(location, *target, EdgeKind::Normal);
96125
}
97126
TerminatorKind::SwitchInt { targets, values, .. } => {
98127
if targets.len() != values.len() + 1 {
@@ -106,19 +135,19 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
106135
);
107136
}
108137
for target in targets {
109-
self.check_bb(location, *target);
138+
self.check_edge(location, *target, EdgeKind::Normal);
110139
}
111140
}
112141
TerminatorKind::Drop { target, unwind, .. } => {
113-
self.check_bb(location, *target);
142+
self.check_edge(location, *target, EdgeKind::Normal);
114143
if let Some(unwind) = unwind {
115-
self.check_bb(location, *unwind);
144+
self.check_edge(location, *unwind, EdgeKind::Unwind);
116145
}
117146
}
118147
TerminatorKind::DropAndReplace { target, unwind, .. } => {
119-
self.check_bb(location, *target);
148+
self.check_edge(location, *target, EdgeKind::Normal);
120149
if let Some(unwind) = unwind {
121-
self.check_bb(location, *unwind);
150+
self.check_edge(location, *unwind, EdgeKind::Unwind);
122151
}
123152
}
124153
TerminatorKind::Call { func, destination, cleanup, .. } => {
@@ -131,10 +160,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
131160
),
132161
}
133162
if let Some((_, target)) = destination {
134-
self.check_bb(location, *target);
163+
self.check_edge(location, *target, EdgeKind::Normal);
135164
}
136165
if let Some(cleanup) = cleanup {
137-
self.check_bb(location, *cleanup);
166+
self.check_edge(location, *cleanup, EdgeKind::Unwind);
138167
}
139168
}
140169
TerminatorKind::Assert { cond, target, cleanup, .. } => {
@@ -148,30 +177,30 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
148177
),
149178
);
150179
}
151-
self.check_bb(location, *target);
180+
self.check_edge(location, *target, EdgeKind::Normal);
152181
if let Some(cleanup) = cleanup {
153-
self.check_bb(location, *cleanup);
182+
self.check_edge(location, *cleanup, EdgeKind::Unwind);
154183
}
155184
}
156185
TerminatorKind::Yield { resume, drop, .. } => {
157-
self.check_bb(location, *resume);
186+
self.check_edge(location, *resume, EdgeKind::Normal);
158187
if let Some(drop) = drop {
159-
self.check_bb(location, *drop);
188+
self.check_edge(location, *drop, EdgeKind::Normal);
160189
}
161190
}
162191
TerminatorKind::FalseEdge { real_target, imaginary_target } => {
163-
self.check_bb(location, *real_target);
164-
self.check_bb(location, *imaginary_target);
192+
self.check_edge(location, *real_target, EdgeKind::Normal);
193+
self.check_edge(location, *imaginary_target, EdgeKind::Normal);
165194
}
166195
TerminatorKind::FalseUnwind { real_target, unwind } => {
167-
self.check_bb(location, *real_target);
196+
self.check_edge(location, *real_target, EdgeKind::Normal);
168197
if let Some(unwind) = unwind {
169-
self.check_bb(location, *unwind);
198+
self.check_edge(location, *unwind, EdgeKind::Unwind);
170199
}
171200
}
172201
TerminatorKind::InlineAsm { destination, .. } => {
173202
if let Some(destination) = destination {
174-
self.check_bb(location, *destination);
203+
self.check_edge(location, *destination, EdgeKind::Normal);
175204
}
176205
}
177206
// Nothing to validate for these.

‎src/librustdoc/clean/types.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ pub struct Item {
8585

8686
impl fmt::Debug for Item {
8787
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
88-
let fake = MAX_DEF_ID.with(|m| {
89-
m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false)
90-
});
88+
let fake = self.is_fake();
9189
let def_id: &dyn fmt::Debug = if fake { &"**FAKE**" } else { &self.def_id };
9290

9391
fmt.debug_struct("Item")
@@ -238,6 +236,13 @@ impl Item {
238236
_ => false,
239237
}
240238
}
239+
240+
/// See comments on next_def_id
241+
pub fn is_fake(&self) -> bool {
242+
MAX_DEF_ID.with(|m| {
243+
m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false)
244+
})
245+
}
241246
}
242247

243248
#[derive(Clone, Debug)]

‎src/libtest/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn optgroups() -> getopts::Options {
115115
.optflagopt(
116116
"",
117117
"report-time",
118-
"Show execution time of each test. Awailable values:
118+
"Show execution time of each test. Available values:
119119
plain = do not colorize the execution time (default);
120120
colored = colorize output according to the `color` parameter value;
121121

‎src/test/ui/mod/mod_file_disambig.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0584]: file for module `mod_file_disambig_aux` found at both mod_file_disambig_aux.rs and mod_file_disambig_aux/mod.rs
1+
error[E0761]: file for module `mod_file_disambig_aux` found at both mod_file_disambig_aux.rs and mod_file_disambig_aux/mod.rs
22
--> $DIR/mod_file_disambig.rs:1:1
33
|
44
LL | mod mod_file_disambig_aux;
@@ -14,5 +14,5 @@ LL | assert_eq!(mod_file_aux::bar(), 10);
1414

1515
error: aborting due to 2 previous errors
1616

17-
Some errors have detailed explanations: E0433, E0584.
17+
Some errors have detailed explanations: E0433, E0761.
1818
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)
Please sign in to comment.