diff options
| author | bors <bors@rust-lang.org> | 2020-06-16 14:58:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-06-16 14:58:14 +0000 |
| commit | a647c0cd68bdd0f15081019f0b21bc31ae23f072 (patch) | |
| tree | 2e5ec96c4bbeedd4a6951c61505e2dd517037b21 | |
| parent | 435f97cec1f0d7de95a0b80e95f295ab444b2fce (diff) | |
| parent | b4dd6a0dc43f85d9fcd9cfaf45a5c5d854ee13ae (diff) | |
| download | rust-a647c0cd68bdd0f15081019f0b21bc31ae23f072.tar.gz rust-a647c0cd68bdd0f15081019f0b21bc31ae23f072.zip | |
Auto merge of #73402 - Dylan-DPC:rollup-8udzpfu, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #73237 (Check for overflow in DroplessArena and align returned memory) - #73339 (Don't run generator transform when there's a TyErr) - #73372 (Re-order correctly the sections in the sidebar) - #73373 (Use track caller for bug! macro) - #73380 (Add more info to `x.py build --help` on default value for `-j JOBS`.) - #73381 (Fix typo in docs of std::mem) - #73389 (Use `Ipv4Addr::from<[u8; 4]>` when possible) - #73400 (Fix forge-platform-support URL) Failed merges: r? @ghost
| -rw-r--r-- | RELEASES.md | 2 | ||||
| -rw-r--r-- | src/bootstrap/flags.rs | 7 | ||||
| -rw-r--r-- | src/libcore/mem/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/panic.rs | 9 | ||||
| -rw-r--r-- | src/libcore/panicking.rs | 3 | ||||
| -rw-r--r-- | src/librustc_arena/lib.rs | 72 | ||||
| -rw-r--r-- | src/librustc_middle/macros.rs | 18 | ||||
| -rw-r--r-- | src/librustc_middle/ty/context.rs | 3 | ||||
| -rw-r--r-- | src/librustc_middle/ty/list.rs | 2 | ||||
| -rw-r--r-- | src/librustc_middle/util/bug.rs | 21 | ||||
| -rw-r--r-- | src/librustc_mir/transform/generator.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 4 | ||||
| -rw-r--r-- | src/libstd/panicking.rs | 13 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/net.rs | 10 |
14 files changed, 87 insertions, 85 deletions
diff --git a/RELEASES.md b/RELEASES.md index 3ae3417a9b4..006682f5059 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -912,7 +912,7 @@ Compatibility Notes [`Duration::mul_f32`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.mul_f32 [`Duration::mul_f64`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.mul_f64 [`any::type_name`]: https://doc.rust-lang.org/std/any/fn.type_name.html -[forge-platform-support]: https://forge.rust-lang.org/platform-support.html +[forge-platform-support]: https://forge.rust-lang.org/release/platform-support.html [pipeline-internals]: https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199 Version 1.37.0 (2019-08-15) diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index cfaa43f3970..37261153574 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -149,7 +149,12 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`", "N", ); opts.optopt("", "src", "path to the root of the rust checkout", "DIR"); - opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS"); + let j_msg = format!( + "number of jobs to run in parallel; \ + defaults to {} (this host's logical CPU count)", + num_cpus::get() + ); + opts.optopt("j", "jobs", &j_msg, "JOBS"); opts.optflag("h", "help", "print this help message"); opts.optopt( "", diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index d1f5cb44913..8bce980cadd 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -129,7 +129,7 @@ pub use crate::intrinsics::transmute; /// erring on the side of (double-)dropping. /// /// Also, `ManuallyDrop` prevents us from having to "touch" `v` after transferring the -/// ownership to `s` - the final step of interacting with `v` to dispoe of it without +/// ownership to `s` — the final step of interacting with `v` to dispose of it without /// running its destructor is entirely avoided. /// /// [drop]: fn.drop.html diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index 1ffd493d813..c7009b76e81 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -39,8 +39,7 @@ pub struct PanicInfo<'a> { impl<'a> PanicInfo<'a> { #[unstable( feature = "panic_internals", - reason = "internal details of the implementation of the `panic!` \ - and related macros", + reason = "internal details of the implementation of the `panic!` and related macros", issue = "none" )] #[doc(hidden)] @@ -55,8 +54,7 @@ impl<'a> PanicInfo<'a> { #[unstable( feature = "panic_internals", - reason = "internal details of the implementation of the `panic!` \ - and related macros", + reason = "internal details of the implementation of the `panic!` and related macros", issue = "none" )] #[doc(hidden)] @@ -244,8 +242,7 @@ impl<'a> Location<'a> { impl<'a> Location<'a> { #![unstable( feature = "panic_internals", - reason = "internal details of the implementation of the `panic!` \ - and related macros", + reason = "internal details of the implementation of the `panic!` and related macros", issue = "none" )] #[doc(hidden)] diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs index 3ed5e65e11c..766c69a5f94 100644 --- a/src/libcore/panicking.rs +++ b/src/libcore/panicking.rs @@ -22,8 +22,7 @@ #![allow(dead_code, missing_docs)] #![unstable( feature = "core_panic", - reason = "internal details of the implementation of the `panic!` \ - and related macros", + reason = "internal details of the implementation of the `panic!` and related macros", issue = "none" )] diff --git a/src/librustc_arena/lib.rs b/src/librustc_arena/lib.rs index 4a2a0de0e21..66c31cbebcc 100644 --- a/src/librustc_arena/lib.rs +++ b/src/librustc_arena/lib.rs @@ -333,13 +333,6 @@ impl Default for DroplessArena { } impl DroplessArena { - #[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); - assert!(self.ptr <= self.end); - } - #[inline(never)] #[cold] fn grow(&self, additional: usize) { @@ -370,22 +363,42 @@ impl DroplessArena { } } + /// Allocates a byte slice with specified size and alignment from the + /// current memory chunk. Returns `None` if there is no free space left to + /// satisfy the request. #[inline] - pub fn alloc_raw(&self, bytes: usize, align: usize) -> &mut [u8] { - unsafe { - assert!(bytes != 0); - - self.align(align); + fn alloc_raw_without_grow(&self, bytes: usize, align: usize) -> Option<*mut u8> { + let ptr = self.ptr.get() as usize; + let end = self.end.get() as usize; + // The allocation request fits into the current chunk iff: + // + // let aligned = align_to(ptr, align); + // ptr <= aligned && aligned + bytes <= end + // + // Except that we work with fixed width integers and need to be careful + // about potential overflow in the calcuation. If the overflow does + // happen, then we definitely don't have enough free and need to grow + // the arena. + let aligned = ptr.checked_add(align - 1)? & !(align - 1); + let new_ptr = aligned.checked_add(bytes)?; + if new_ptr <= end { + self.ptr.set(new_ptr as *mut u8); + Some(aligned as *mut u8) + } else { + None + } + } - let future_end = intrinsics::arith_offset(self.ptr.get(), bytes as isize); - if (future_end as *mut u8) > self.end.get() { - self.grow(bytes); + #[inline] + pub fn alloc_raw(&self, bytes: usize, align: usize) -> *mut u8 { + assert!(bytes != 0); + loop { + if let Some(a) = self.alloc_raw_without_grow(bytes, align) { + break a; } - - let ptr = self.ptr.get(); - // Set the pointer past ourselves - self.ptr.set(intrinsics::arith_offset(self.ptr.get(), bytes as isize) as *mut u8); - slice::from_raw_parts_mut(ptr, bytes) + // No free space left. Allocate a new chunk to satisfy the request. + // On failure the grow will panic or abort. + self.grow(bytes); } } @@ -393,7 +406,7 @@ impl DroplessArena { pub fn alloc<T>(&self, object: T) -> &mut T { assert!(!mem::needs_drop::<T>()); - let mem = self.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T; + let mem = self.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut T; unsafe { // Write into uninitialized memory. @@ -418,13 +431,11 @@ impl DroplessArena { assert!(mem::size_of::<T>() != 0); assert!(!slice.is_empty()); - let mem = self.alloc_raw(slice.len() * mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ - as *mut T; + let mem = self.alloc_raw(slice.len() * mem::size_of::<T>(), mem::align_of::<T>()) as *mut T; unsafe { - let arena_slice = slice::from_raw_parts_mut(mem, slice.len()); - arena_slice.copy_from_slice(slice); - arena_slice + mem.copy_from_nonoverlapping(slice.as_ptr(), slice.len()); + slice::from_raw_parts_mut(mem, slice.len()) } } @@ -467,7 +478,7 @@ impl DroplessArena { return &mut []; } let size = len.checked_mul(mem::size_of::<T>()).unwrap(); - let mem = self.alloc_raw(size, mem::align_of::<T>()) as *mut _ as *mut T; + let mem = self.alloc_raw(size, mem::align_of::<T>()) as *mut T; unsafe { self.write_from_iter(iter, len, mem) } } (_, _) => { @@ -482,7 +493,7 @@ impl DroplessArena { let len = vec.len(); let start_ptr = self .alloc_raw(len * mem::size_of::<T>(), mem::align_of::<T>()) - as *mut _ as *mut T; + as *mut T; vec.as_ptr().copy_to_nonoverlapping(start_ptr, len); vec.set_len(0); slice::from_raw_parts_mut(start_ptr, len) @@ -526,8 +537,7 @@ pub struct DropArena { impl DropArena { #[inline] pub unsafe fn alloc<T>(&self, object: T) -> &mut T { - let mem = - self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T; + let mem = self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut T; // Write into uninitialized memory. ptr::write(mem, object); let result = &mut *mem; @@ -550,7 +560,7 @@ impl DropArena { let start_ptr = self .arena .alloc_raw(len.checked_mul(mem::size_of::<T>()).unwrap(), mem::align_of::<T>()) - as *mut _ as *mut T; + as *mut T; let mut destructors = self.destructors.borrow_mut(); // Reserve space for the destructors so we can't panic while adding them diff --git a/src/librustc_middle/macros.rs b/src/librustc_middle/macros.rs index 88ddd96eec8..a5482b7bdcf 100644 --- a/src/librustc_middle/macros.rs +++ b/src/librustc_middle/macros.rs @@ -1,16 +1,20 @@ #[macro_export] macro_rules! bug { - () => ( bug!("impossible case reached") ); - ($($message:tt)*) => ({ - $crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*)) - }) + () => ( $crate::bug!("impossible case reached") ); + ($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) }); + ($msg:expr,) => ({ $crate::bug!($msg) }); + ($fmt:expr, $($arg:tt)+) => ({ + $crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+)) + }); } #[macro_export] macro_rules! span_bug { - ($span:expr, $($message:tt)*) => ({ - $crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*)) - }) + ($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) }); + ($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) }); + ($span:expr, $fmt:expr, $($arg:tt)+) => ({ + $crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+)) + }); } /////////////////////////////////////////////////////////////////////////// diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d5be3508d2d..de2e1046f1c 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -189,8 +189,7 @@ fn validate_hir_id_for_typeck_tables( if hir_id.owner != hir_owner { ty::tls::with(|tcx| { bug!( - "node {} with HirId::owner {:?} cannot be placed in \ - TypeckTables with hir_owner {:?}", + "node {} with HirId::owner {:?} cannot be placed in TypeckTables with hir_owner {:?}", tcx.hir().node_to_string(hir_id), hir_id.owner, hir_owner diff --git a/src/librustc_middle/ty/list.rs b/src/librustc_middle/ty/list.rs index 161783bb370..76c72e4c260 100644 --- a/src/librustc_middle/ty/list.rs +++ b/src/librustc_middle/ty/list.rs @@ -55,7 +55,7 @@ impl<T: Copy> List<T> { .dropless .alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>())); unsafe { - let result = &mut *(mem.as_mut_ptr() as *mut List<T>); + let result = &mut *(mem as *mut List<T>); // Write the length result.len = slice.len(); diff --git a/src/librustc_middle/util/bug.rs b/src/librustc_middle/util/bug.rs index 54cd8a29f94..9c3a97d8332 100644 --- a/src/librustc_middle/util/bug.rs +++ b/src/librustc_middle/util/bug.rs @@ -3,34 +3,31 @@ use crate::ty::{tls, TyCtxt}; use rustc_span::{MultiSpan, Span}; use std::fmt; +use std::panic::Location; #[cold] #[inline(never)] -pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! { +#[track_caller] +pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! { // this wrapper mostly exists so I don't have to write a fully // qualified path of None::<Span> inside the bug!() macro definition - opt_span_bug_fmt(file, line, None::<Span>, args); + opt_span_bug_fmt(None::<Span>, args, Location::caller()); } #[cold] #[inline(never)] -pub fn span_bug_fmt<S: Into<MultiSpan>>( - file: &'static str, - line: u32, - span: S, - args: fmt::Arguments<'_>, -) -> ! { - opt_span_bug_fmt(file, line, Some(span), args); +#[track_caller] +pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! { + opt_span_bug_fmt(Some(span), args, Location::caller()); } fn opt_span_bug_fmt<S: Into<MultiSpan>>( - file: &'static str, - line: u32, span: Option<S>, args: fmt::Arguments<'_>, + location: &Location<'_>, ) -> ! { tls::with_opt(move |tcx| { - let msg = format!("{}:{}: {}", file, line, args); + let msg = format!("{}: {}", location, args); match (tcx, span) { (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg), (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg), diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 25b6a51d91b..acadb5385c9 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -1222,7 +1222,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform { movability == hir::Movability::Movable, ) } - _ => bug!(), + _ => { + tcx.sess + .delay_span_bug(body.span, &format!("unexpected generator type {}", gen_ty)); + return; + } }; // Compute GeneratorState<yield_ty, return_ty> diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 07631093edd..1681b73d0c2 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -4338,6 +4338,8 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) { } } + sidebar.push_str(&sidebar_assoc_items(it)); + sidebar.push_str("<a class=\"sidebar-title\" href=\"#implementors\">Implementors</a>"); if t.auto { sidebar.push_str( @@ -4346,8 +4348,6 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) { ); } - sidebar.push_str(&sidebar_assoc_items(it)); - write!(buf, "<div class=\"block items\">{}</div>", sidebar) } diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 6a120f930ab..d22ac1d5385 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -201,8 +201,7 @@ fn default_hook(info: &PanicInfo<'_>) { if FIRST_PANIC.swap(false, Ordering::SeqCst) { let _ = writeln!( err, - "note: run with `RUST_BACKTRACE=1` \ - environment variable to display a backtrace" + "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace" ); } } @@ -454,10 +453,7 @@ fn rust_panic_with_hook( // process real quickly as we don't want to try calling it again as it'll // probably just panic again. if panics > 2 { - util::dumb_print(format_args!( - "thread panicked while processing \ - panic. aborting.\n" - )); + util::dumb_print(format_args!("thread panicked while processing panic. aborting.\n")); intrinsics::abort() } @@ -489,10 +485,7 @@ fn rust_panic_with_hook( // have limited options. Currently our preference is to // just abort. In the future we may consider resuming // unwinding or otherwise exiting the thread cleanly. - util::dumb_print(format_args!( - "thread panicked while panicking. \ - aborting.\n" - )); + util::dumb_print(format_args!("thread panicked while panicking. aborting.\n")); intrinsics::abort() } diff --git a/src/libstd/sys/hermit/net.rs b/src/libstd/sys/hermit/net.rs index 9e588c4265a..8a788a9265f 100644 --- a/src/libstd/sys/hermit/net.rs +++ b/src/libstd/sys/hermit/net.rs @@ -147,10 +147,7 @@ impl TcpStream { .map_err(|_| io::Error::new(ErrorKind::Other, "peer_addr failed"))?; let saddr = match ipaddr { - Ipv4(ref addr) => SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])), - port, - ), + Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port), Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port), _ => { return Err(io::Error::new(ErrorKind::Other, "peer_addr failed")); @@ -227,10 +224,7 @@ impl TcpListener { let (handle, ipaddr, port) = abi::tcplistener::accept(self.0.port()) .map_err(|_| io::Error::new(ErrorKind::Other, "accept failed"))?; let saddr = match ipaddr { - Ipv4(ref addr) => SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(addr.0[0], addr.0[1], addr.0[2], addr.0[3])), - port, - ), + Ipv4(ref addr) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(addr.0)), port), Ipv6(ref addr) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(addr.0)), port), _ => { return Err(io::Error::new(ErrorKind::Other, "accept failed")); |
