diff options
| author | bors <bors@rust-lang.org> | 2020-03-11 13:05:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-03-11 13:05:52 +0000 |
| commit | c20d7eecbc0928b57da8fe30b2ef8528e2bdd5be (patch) | |
| tree | e8f110a9249dbcf8ce290bda1b3c7702488247fa /src/libcore | |
| parent | 303d8aff6092709edd4dbd35b1c88e9aa40bf6d8 (diff) | |
| parent | a77206fa4a35e7926fb4404bd167b06e342b7626 (diff) | |
| download | rust-c20d7eecbc0928b57da8fe30b2ef8528e2bdd5be.tar.gz rust-c20d7eecbc0928b57da8fe30b2ef8528e2bdd5be.zip | |
Auto merge of #69919 - Centril:rollup-fxo33zs, r=Centril
Rollup of 8 pull requests Successful merges: - #66472 (--show-coverage json) - #69603 (tidy: replace `make check` with `./x.py test` in documentation) - #69760 (Improve expression & attribute parsing) - #69828 (fix memory leak when vec::IntoIter panics during drop) - #69850 (panic_bounds_check: use caller_location, like PanicFnLangItem) - #69876 (Add long error explanation for E0739) - #69888 ([Miri] Use a session variable instead of checking for an env var always) - #69893 (librustc_codegen_llvm: Use slices instead of 0-terminated strings) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/macros/mod.rs | 21 | ||||
| -rw-r--r-- | src/libcore/panicking.rs | 30 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs index 76e58f0cc62..04af5b5f768 100644 --- a/src/libcore/macros/mod.rs +++ b/src/libcore/macros/mod.rs @@ -1,3 +1,4 @@ +#[cfg(bootstrap)] #[doc(include = "panic.md")] #[macro_export] #[allow_internal_unstable(core_panic, track_caller)] @@ -20,6 +21,26 @@ macro_rules! panic { ); } +#[cfg(not(bootstrap))] +#[doc(include = "panic.md")] +#[macro_export] +#[allow_internal_unstable(core_panic, track_caller)] +#[stable(feature = "core", since = "1.6.0")] +macro_rules! panic { + () => ( + $crate::panic!("explicit panic") + ); + ($msg:expr) => ( + $crate::panicking::panic($msg) + ); + ($msg:expr,) => ( + $crate::panic!($msg) + ); + ($fmt:expr, $($arg:tt)+) => ( + $crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+)) + ); +} + /// Asserts that two expressions are equal to each other (using [`PartialEq`]). /// /// On panic, this macro will print the values of the expressions with their diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs index 61b764f2d62..3587f3f0ebf 100644 --- a/src/libcore/panicking.rs +++ b/src/libcore/panicking.rs @@ -32,6 +32,7 @@ use crate::fmt; use crate::panic::{Location, PanicInfo}; +/// The underlying implementation of libcore's `panic!` macro when no formatting is used. #[cold] // never inline unless panic_immediate_abort to avoid code // bloat at the call sites as much as possible @@ -49,9 +50,28 @@ pub fn panic(expr: &str) -> ! { // truncation and padding (even though none is used here). Using // Arguments::new_v1 may allow the compiler to omit Formatter::pad from the // output binary, saving up to a few kilobytes. - panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller()) + #[cfg(not(bootstrap))] + panic_fmt(fmt::Arguments::new_v1(&[expr], &[])); + #[cfg(bootstrap)] + panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller()); } +#[cfg(not(bootstrap))] +#[cold] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[track_caller] +#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access +fn panic_bounds_check(index: usize, len: usize) -> ! { + if cfg!(feature = "panic_immediate_abort") { + unsafe { super::intrinsics::abort() } + } + + panic!("index out of bounds: the len is {} but the index is {}", len, index) +} + +// For bootstrap, we need a variant with the old argument order, and a corresponding +// `panic_fmt`. +#[cfg(bootstrap)] #[cold] #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] #[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access @@ -66,10 +86,12 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! { ) } +/// The underlying implementation of libcore's `panic!` macro when formatting is used. #[cold] #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] #[cfg_attr(feature = "panic_immediate_abort", inline)] -pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! { +#[cfg_attr(not(bootstrap), track_caller)] +pub fn panic_fmt(fmt: fmt::Arguments<'_>, #[cfg(bootstrap)] location: &Location<'_>) -> ! { if cfg!(feature = "panic_immediate_abort") { unsafe { super::intrinsics::abort() } } @@ -81,6 +103,10 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! { fn panic_impl(pi: &PanicInfo<'_>) -> !; } + #[cfg(bootstrap)] let pi = PanicInfo::internal_constructor(Some(&fmt), location); + #[cfg(not(bootstrap))] + let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller()); + unsafe { panic_impl(&pi) } } |
