Skip to content

Commit a647c0c

Browse files
committed
Auto merge of rust-lang#73402 - Dylan-DPC:rollup-8udzpfu, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#73237 (Check for overflow in DroplessArena and align returned memory) - rust-lang#73339 (Don't run generator transform when there's a TyErr) - rust-lang#73372 (Re-order correctly the sections in the sidebar) - rust-lang#73373 (Use track caller for bug! macro) - rust-lang#73380 (Add more info to `x.py build --help` on default value for `-j JOBS`.) - rust-lang#73381 (Fix typo in docs of std::mem) - rust-lang#73389 (Use `Ipv4Addr::from<[u8; 4]>` when possible) - rust-lang#73400 (Fix forge-platform-support URL) Failed merges: r? @ghost
2 parents 435f97c + b4dd6a0 commit a647c0c

File tree

14 files changed

+87
-85
lines changed

14 files changed

+87
-85
lines changed

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ Compatibility Notes
912912
[`Duration::mul_f32`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.mul_f32
913913
[`Duration::mul_f64`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.mul_f64
914914
[`any::type_name`]: https://doc.rust-lang.org/std/any/fn.type_name.html
915-
[forge-platform-support]: https://forge.rust-lang.org/platform-support.html
915+
[forge-platform-support]: https://forge.rust-lang.org/release/platform-support.html
916916
[pipeline-internals]: https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199
917917

918918
Version 1.37.0 (2019-08-15)

src/bootstrap/flags.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
149149
"N",
150150
);
151151
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
152-
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
152+
let j_msg = format!(
153+
"number of jobs to run in parallel; \
154+
defaults to {} (this host's logical CPU count)",
155+
num_cpus::get()
156+
);
157+
opts.optopt("j", "jobs", &j_msg, "JOBS");
153158
opts.optflag("h", "help", "print this help message");
154159
opts.optopt(
155160
"",

src/libcore/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub use crate::intrinsics::transmute;
129129
/// erring on the side of (double-)dropping.
130130
///
131131
/// Also, `ManuallyDrop` prevents us from having to "touch" `v` after transferring the
132-
/// ownership to `s` - the final step of interacting with `v` to dispoe of it without
132+
/// ownership to `s` the final step of interacting with `v` to dispose of it without
133133
/// running its destructor is entirely avoided.
134134
///
135135
/// [drop]: fn.drop.html

src/libcore/panic.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ pub struct PanicInfo<'a> {
3939
impl<'a> PanicInfo<'a> {
4040
#[unstable(
4141
feature = "panic_internals",
42-
reason = "internal details of the implementation of the `panic!` \
43-
and related macros",
42+
reason = "internal details of the implementation of the `panic!` and related macros",
4443
issue = "none"
4544
)]
4645
#[doc(hidden)]
@@ -55,8 +54,7 @@ impl<'a> PanicInfo<'a> {
5554

5655
#[unstable(
5756
feature = "panic_internals",
58-
reason = "internal details of the implementation of the `panic!` \
59-
and related macros",
57+
reason = "internal details of the implementation of the `panic!` and related macros",
6058
issue = "none"
6159
)]
6260
#[doc(hidden)]
@@ -244,8 +242,7 @@ impl<'a> Location<'a> {
244242
impl<'a> Location<'a> {
245243
#![unstable(
246244
feature = "panic_internals",
247-
reason = "internal details of the implementation of the `panic!` \
248-
and related macros",
245+
reason = "internal details of the implementation of the `panic!` and related macros",
249246
issue = "none"
250247
)]
251248
#[doc(hidden)]

src/libcore/panicking.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
#![allow(dead_code, missing_docs)]
2323
#![unstable(
2424
feature = "core_panic",
25-
reason = "internal details of the implementation of the `panic!` \
26-
and related macros",
25+
reason = "internal details of the implementation of the `panic!` and related macros",
2726
issue = "none"
2827
)]
2928

src/librustc_arena/lib.rs

+41-31
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,6 @@ impl Default for DroplessArena {
333333
}
334334

335335
impl DroplessArena {
336-
#[inline]
337-
fn align(&self, align: usize) {
338-
let final_address = ((self.ptr.get() as usize) + align - 1) & !(align - 1);
339-
self.ptr.set(final_address as *mut u8);
340-
assert!(self.ptr <= self.end);
341-
}
342-
343336
#[inline(never)]
344337
#[cold]
345338
fn grow(&self, additional: usize) {
@@ -370,30 +363,50 @@ impl DroplessArena {
370363
}
371364
}
372365

366+
/// Allocates a byte slice with specified size and alignment from the
367+
/// current memory chunk. Returns `None` if there is no free space left to
368+
/// satisfy the request.
373369
#[inline]
374-
pub fn alloc_raw(&self, bytes: usize, align: usize) -> &mut [u8] {
375-
unsafe {
376-
assert!(bytes != 0);
377-
378-
self.align(align);
370+
fn alloc_raw_without_grow(&self, bytes: usize, align: usize) -> Option<*mut u8> {
371+
let ptr = self.ptr.get() as usize;
372+
let end = self.end.get() as usize;
373+
// The allocation request fits into the current chunk iff:
374+
//
375+
// let aligned = align_to(ptr, align);
376+
// ptr <= aligned && aligned + bytes <= end
377+
//
378+
// Except that we work with fixed width integers and need to be careful
379+
// about potential overflow in the calcuation. If the overflow does
380+
// happen, then we definitely don't have enough free and need to grow
381+
// the arena.
382+
let aligned = ptr.checked_add(align - 1)? & !(align - 1);
383+
let new_ptr = aligned.checked_add(bytes)?;
384+
if new_ptr <= end {
385+
self.ptr.set(new_ptr as *mut u8);
386+
Some(aligned as *mut u8)
387+
} else {
388+
None
389+
}
390+
}
379391

380-
let future_end = intrinsics::arith_offset(self.ptr.get(), bytes as isize);
381-
if (future_end as *mut u8) > self.end.get() {
382-
self.grow(bytes);
392+
#[inline]
393+
pub fn alloc_raw(&self, bytes: usize, align: usize) -> *mut u8 {
394+
assert!(bytes != 0);
395+
loop {
396+
if let Some(a) = self.alloc_raw_without_grow(bytes, align) {
397+
break a;
383398
}
384-
385-
let ptr = self.ptr.get();
386-
// Set the pointer past ourselves
387-
self.ptr.set(intrinsics::arith_offset(self.ptr.get(), bytes as isize) as *mut u8);
388-
slice::from_raw_parts_mut(ptr, bytes)
399+
// No free space left. Allocate a new chunk to satisfy the request.
400+
// On failure the grow will panic or abort.
401+
self.grow(bytes);
389402
}
390403
}
391404

392405
#[inline]
393406
pub fn alloc<T>(&self, object: T) -> &mut T {
394407
assert!(!mem::needs_drop::<T>());
395408

396-
let mem = self.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T;
409+
let mem = self.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut T;
397410

398411
unsafe {
399412
// Write into uninitialized memory.
@@ -418,13 +431,11 @@ impl DroplessArena {
418431
assert!(mem::size_of::<T>() != 0);
419432
assert!(!slice.is_empty());
420433

421-
let mem = self.alloc_raw(slice.len() * mem::size_of::<T>(), mem::align_of::<T>()) as *mut _
422-
as *mut T;
434+
let mem = self.alloc_raw(slice.len() * mem::size_of::<T>(), mem::align_of::<T>()) as *mut T;
423435

424436
unsafe {
425-
let arena_slice = slice::from_raw_parts_mut(mem, slice.len());
426-
arena_slice.copy_from_slice(slice);
427-
arena_slice
437+
mem.copy_from_nonoverlapping(slice.as_ptr(), slice.len());
438+
slice::from_raw_parts_mut(mem, slice.len())
428439
}
429440
}
430441

@@ -467,7 +478,7 @@ impl DroplessArena {
467478
return &mut [];
468479
}
469480
let size = len.checked_mul(mem::size_of::<T>()).unwrap();
470-
let mem = self.alloc_raw(size, mem::align_of::<T>()) as *mut _ as *mut T;
481+
let mem = self.alloc_raw(size, mem::align_of::<T>()) as *mut T;
471482
unsafe { self.write_from_iter(iter, len, mem) }
472483
}
473484
(_, _) => {
@@ -482,7 +493,7 @@ impl DroplessArena {
482493
let len = vec.len();
483494
let start_ptr = self
484495
.alloc_raw(len * mem::size_of::<T>(), mem::align_of::<T>())
485-
as *mut _ as *mut T;
496+
as *mut T;
486497
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
487498
vec.set_len(0);
488499
slice::from_raw_parts_mut(start_ptr, len)
@@ -526,8 +537,7 @@ pub struct DropArena {
526537
impl DropArena {
527538
#[inline]
528539
pub unsafe fn alloc<T>(&self, object: T) -> &mut T {
529-
let mem =
530-
self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T;
540+
let mem = self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut T;
531541
// Write into uninitialized memory.
532542
ptr::write(mem, object);
533543
let result = &mut *mem;
@@ -550,7 +560,7 @@ impl DropArena {
550560
let start_ptr = self
551561
.arena
552562
.alloc_raw(len.checked_mul(mem::size_of::<T>()).unwrap(), mem::align_of::<T>())
553-
as *mut _ as *mut T;
563+
as *mut T;
554564

555565
let mut destructors = self.destructors.borrow_mut();
556566
// Reserve space for the destructors so we can't panic while adding them

src/librustc_middle/macros.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#[macro_export]
22
macro_rules! bug {
3-
() => ( bug!("impossible case reached") );
4-
($($message:tt)*) => ({
5-
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
6-
})
3+
() => ( $crate::bug!("impossible case reached") );
4+
($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) });
5+
($msg:expr,) => ({ $crate::bug!($msg) });
6+
($fmt:expr, $($arg:tt)+) => ({
7+
$crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+))
8+
});
79
}
810

911
#[macro_export]
1012
macro_rules! span_bug {
11-
($span:expr, $($message:tt)*) => ({
12-
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
13-
})
13+
($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
14+
($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) });
15+
($span:expr, $fmt:expr, $($arg:tt)+) => ({
16+
$crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+))
17+
});
1418
}
1519

1620
///////////////////////////////////////////////////////////////////////////

src/librustc_middle/ty/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ fn validate_hir_id_for_typeck_tables(
189189
if hir_id.owner != hir_owner {
190190
ty::tls::with(|tcx| {
191191
bug!(
192-
"node {} with HirId::owner {:?} cannot be placed in \
193-
TypeckTables with hir_owner {:?}",
192+
"node {} with HirId::owner {:?} cannot be placed in TypeckTables with hir_owner {:?}",
194193
tcx.hir().node_to_string(hir_id),
195194
hir_id.owner,
196195
hir_owner

src/librustc_middle/ty/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<T: Copy> List<T> {
5555
.dropless
5656
.alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>()));
5757
unsafe {
58-
let result = &mut *(mem.as_mut_ptr() as *mut List<T>);
58+
let result = &mut *(mem as *mut List<T>);
5959
// Write the length
6060
result.len = slice.len();
6161

src/librustc_middle/util/bug.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,31 @@
33
use crate::ty::{tls, TyCtxt};
44
use rustc_span::{MultiSpan, Span};
55
use std::fmt;
6+
use std::panic::Location;
67

78
#[cold]
89
#[inline(never)]
9-
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! {
10+
#[track_caller]
11+
pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! {
1012
// this wrapper mostly exists so I don't have to write a fully
1113
// qualified path of None::<Span> inside the bug!() macro definition
12-
opt_span_bug_fmt(file, line, None::<Span>, args);
14+
opt_span_bug_fmt(None::<Span>, args, Location::caller());
1315
}
1416

1517
#[cold]
1618
#[inline(never)]
17-
pub fn span_bug_fmt<S: Into<MultiSpan>>(
18-
file: &'static str,
19-
line: u32,
20-
span: S,
21-
args: fmt::Arguments<'_>,
22-
) -> ! {
23-
opt_span_bug_fmt(file, line, Some(span), args);
19+
#[track_caller]
20+
pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! {
21+
opt_span_bug_fmt(Some(span), args, Location::caller());
2422
}
2523

2624
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
27-
file: &'static str,
28-
line: u32,
2925
span: Option<S>,
3026
args: fmt::Arguments<'_>,
27+
location: &Location<'_>,
3128
) -> ! {
3229
tls::with_opt(move |tcx| {
33-
let msg = format!("{}:{}: {}", file, line, args);
30+
let msg = format!("{}: {}", location, args);
3431
match (tcx, span) {
3532
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
3633
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),

src/librustc_mir/transform/generator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
12221222
movability == hir::Movability::Movable,
12231223
)
12241224
}
1225-
_ => bug!(),
1225+
_ => {
1226+
tcx.sess
1227+
.delay_span_bug(body.span, &format!("unexpected generator type {}", gen_ty));
1228+
return;
1229+
}
12261230
};
12271231

12281232
// Compute GeneratorState<yield_ty, return_ty>

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,8 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
43384338
}
43394339
}
43404340

4341+
sidebar.push_str(&sidebar_assoc_items(it));
4342+
43414343
sidebar.push_str("<a class=\"sidebar-title\" href=\"#implementors\">Implementors</a>");
43424344
if t.auto {
43434345
sidebar.push_str(
@@ -4346,8 +4348,6 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
43464348
);
43474349
}
43484350

4349-
sidebar.push_str(&sidebar_assoc_items(it));
4350-
43514351
write!(buf, "<div class=\"block items\">{}</div>", sidebar)
43524352
}
43534353

src/libstd/panicking.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ fn default_hook(info: &PanicInfo<'_>) {
201201
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
202202
let _ = writeln!(
203203
err,
204-
"note: run with `RUST_BACKTRACE=1` \
205-
environment variable to display a backtrace"
204+
"note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"
206205
);
207206
}
208207
}
@@ -454,10 +453,7 @@ fn rust_panic_with_hook(
454453
// process real quickly as we don't want to try calling it again as it'll
455454
// probably just panic again.
456455
if panics > 2 {
457-
util::dumb_print(format_args!(
458-
"thread panicked while processing \
459-
panic. aborting.\n"
460-
));
456+
util::dumb_print(format_args!("thread panicked while processing panic. aborting.\n"));
461457
intrinsics::abort()
462458
}
463459

@@ -489,10 +485,7 @@ fn rust_panic_with_hook(
489485
// have limited options. Currently our preference is to
490486
// just abort. In the future we may consider resuming
491487
// unwinding or otherwise exiting the thread cleanly.
492-
util::dumb_print(format_args!(
493-
"thread panicked while panicking. \
494-
aborting.\n"
495-
));
488+
util::dumb_print(format_args!("thread panicked while panicking. aborting.\n"));
496489
intrinsics::abort()
497490
}
498491

src/libstd/sys/hermit/net.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ impl TcpStream {
147147
.map_err(|_| io::Error::new(ErrorKind::Other, "peer_addr failed"))?;
148148

149149
let saddr = match ipaddr {
150-
Ipv4(ref addr) => SocketAddr::new(
151-
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
152-
port,
153-
),
150+
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
154151
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
155152
_ => {
156153
return Err(io::Error::new(ErrorKind::Other, "peer_addr failed"));
@@ -227,10 +224,7 @@ impl TcpListener {
227224
let (handle, ipaddr, port) = abi::tcplistener::accept(self.0.port())
228225
.map_err(|_| io::Error::new(ErrorKind::Other, "accept failed"))?;
229226
let saddr = match ipaddr {
230-
Ipv4(ref addr) => SocketAddr::new(
231-
IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])),
232-
port,
233-
),
227+
Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port),
234228
Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port),
235229
_ => {
236230
return Err(io::Error::new(ErrorKind::Other, "accept failed"));

0 commit comments

Comments
 (0)