Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #73387

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
591584e
Add tests for 'impl Default for [T; N]'
MikailBag May 26, 2020
3313bf6
Skip leak test on targets without panic=unwind
MikailBag May 28, 2020
bbb3321
Ensure std benchmarks get tested.
ehuss Jun 8, 2020
4ff1678
lint: normalize projections using opaque types
davidtwco Jun 12, 2020
4004bf1
Don't run generator transform when there's a TyErr
jonas-schievink Jun 14, 2020
d3ca6fd
Enable static-pie for the x86_64-unknown-linux-musl target
haraldh Jun 15, 2020
64a6de2
Join mutiple lines if it is more readable
tesuji Jun 15, 2020
9e51008
Complete the std::time documentation to warn about the inconsistencie…
poliorcetics Jun 15, 2020
b67bdb5
Re-order correctly the sections in the sidebar
GuillaumeGomez Jun 15, 2020
fe7456c
Use track caller for bug! macro
tesuji Jun 15, 2020
71c54db
Fix typo in docs of std::mem
ratijas Jun 15, 2020
118bf06
Rollup merge of #70740 - haraldh:static-pie, r=petrochenkov
Dylan-DPC Jun 15, 2020
63f52f2
Rollup merge of #72628 - MikailBag:array-default-tests, r=shepmaster
Dylan-DPC Jun 15, 2020
d5c8654
Rollup merge of #72836 - poliorcetics:std-time-os-specificities, r=sh…
Dylan-DPC Jun 15, 2020
00315da
Rollup merge of #73142 - ehuss:std-benches, r=dtolnay
Dylan-DPC Jun 15, 2020
9618aae
Rollup merge of #73287 - davidtwco:issue-73251-opaque-types-in-projec…
Dylan-DPC Jun 15, 2020
39345c2
Rollup merge of #73339 - jonas-schievink:unbug, r=estebank
Dylan-DPC Jun 15, 2020
ec1844d
Rollup merge of #73372 - GuillaumeGomez:re-order-sidebar-sections, r=…
Dylan-DPC Jun 15, 2020
d365be7
Rollup merge of #73373 - lzutao:bug-trackcaller, r=Amanieu
Dylan-DPC Jun 15, 2020
ac97474
Rollup merge of #73381 - ratijas:fix-typo-std-mem, r=jonas-schievink
Dylan-DPC Jun 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/liballoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ path = "../liballoc/tests/lib.rs"
[[bench]]
name = "collectionsbenches"
path = "../liballoc/benches/lib.rs"
test = true

[[bench]]
name = "vec_deque_append_bench"
Expand Down
1 change: 1 addition & 0 deletions src/libcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ path = "../libcore/tests/lib.rs"
[[bench]]
name = "corebenches"
path = "../libcore/benches/lib.rs"
test = true

[dev-dependencies]
rand = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/libcore/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)]

Expand Down
49 changes: 49 additions & 0 deletions src/libcore/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,52 @@ fn iterator_drops() {
}
assert_eq!(i.get(), 5);
}

// This test does not work on targets without panic=unwind support.
// To work around this problem, test is marked is should_panic, so it will
// be automagically skipped on unsuitable targets, such as
// wasm32-unknown-unkown.
//
// It means that we use panic for indicating success.
#[test]
#[should_panic(expected = "test succeeded")]
fn array_default_impl_avoids_leaks_on_panic() {
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
static COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Debug)]
struct Bomb(usize);

impl Default for Bomb {
fn default() -> Bomb {
if COUNTER.load(Relaxed) == 3 {
panic!("bomb limit exceeded");
}

COUNTER.fetch_add(1, Relaxed);
Bomb(COUNTER.load(Relaxed))
}
}

impl Drop for Bomb {
fn drop(&mut self) {
COUNTER.fetch_sub(1, Relaxed);
}
}

let res = std::panic::catch_unwind(|| <[Bomb; 5]>::default());
let panic_msg = match res {
Ok(_) => unreachable!(),
Err(p) => p.downcast::<&'static str>().unwrap(),
};
assert_eq!(*panic_msg, "bomb limit exceeded");
// check that all bombs are successfully dropped
assert_eq!(COUNTER.load(Relaxed), 0);
panic!("test succeeded")
}

#[test]
fn empty_array_is_always_default() {
struct DoesNotImplDefault;

let _arr = <[DoesNotImplDefault; 0]>::default();
}
27 changes: 19 additions & 8 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,22 +927,33 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
use rustc_middle::ty::TypeFoldable;

struct ProhibitOpaqueTypes<'tcx> {
struct ProhibitOpaqueTypes<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
ty: Option<Ty<'tcx>>,
};

impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'tcx> {
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
if let ty::Opaque(..) = ty.kind {
self.ty = Some(ty);
true
} else {
ty.super_visit_with(self)
match ty.kind {
ty::Opaque(..) => {
self.ty = Some(ty);
true
}
// Consider opaque types within projections FFI-safe if they do not normalize
// to more opaque types.
ty::Projection(..) => {
let ty = self.cx.tcx.normalize_erasing_regions(self.cx.param_env, ty);

// If `ty` is a opaque type directly then `super_visit_with` won't invoke
// this function again.
if ty.has_opaque_types() { self.visit_ty(ty) } else { false }
}
_ => ty.super_visit_with(self),
}
}
}

let mut visitor = ProhibitOpaqueTypes { ty: None };
let mut visitor = ProhibitOpaqueTypes { cx: self.cx, ty: None };
ty.visit_with(&mut visitor);
if let Some(ty) = visitor.ty {
self.emit_ffi_unsafe_type_lint(ty, sp, "opaque types have no C equivalent", None);
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_middle/macros.rs
Original file line number Diff line number Diff line change
@@ -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)+))
});
}

///////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions src/librustc_middle/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/x86_64_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> TargetResult {
base.max_atomic_width = Some(64);
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
base.stack_probes = true;
base.static_position_independent_executables = true;

Ok(Target {
llvm_target: "x86_64-unknown-linux-musl".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ std_detect_dlsym_getauxval = []
threads = 125
# Maximum heap size
heap_size = 0x8000000

[[bench]]
name = "stdbenches"
path = "benches/lib.rs"
test = true
13 changes: 3 additions & 10 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down
15 changes: 15 additions & 0 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ pub use core::time::Duration;
/// }
/// ```
///
/// # OS-specific behaviors
///
/// An `Instant` is a wrapper around system-specific types and it may behave
/// differently depending on the underlying operating system. For example,
/// the following snippet is fine on Linux but panics on macOS:
///
/// ```no_run
/// use std::time::{Instant, Duration};
///
/// let now = Instant::now();
/// let max_nanoseconds = u64::MAX / 1_000_000_000;
/// let duration = Duration::new(max_nanoseconds, 0);
/// println!("{:?}", now + duration);
/// ```
///
/// # Underlying System calls
/// Currently, the following system calls are being used to get the current time using `now()`:
///
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-make/static-pie/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-include ../../run-make-fulldeps/tools.mk

# only-x86_64-unknown-linux-musl

# How to manually run this
# $ ./x.py test --target x86_64-unknown-linux-musl src/test/run-make/static-pie

all:
$(RUSTC) --target $(TARGET) -C target-feature=+crt-static test-aslr.rs
# Check that no dynamic interpreter is set
! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP
# Check that we have a dynamic executable
readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC
# Check for address space layout randomization
$(call RUN,test-aslr) --test-aslr
Loading