diff options
| author | Adam Perry <adam.n.perry@gmail.com> | 2019-12-07 08:37:08 -0800 |
|---|---|---|
| committer | Adam Perry <adam.n.perry@gmail.com> | 2020-01-04 10:02:17 -0800 |
| commit | eaccda009f5891c67e554b31cfad4a52738f9b91 (patch) | |
| tree | 8bfa146ae2a2e7210357d4956aab42213d8216ff /src/libstd | |
| parent | 1ed41b072093fe7cccd232f9a2964c5fb6ab9f60 (diff) | |
| download | rust-eaccda009f5891c67e554b31cfad4a52738f9b91.tar.gz rust-eaccda009f5891c67e554b31cfad4a52738f9b91.zip | |
core and std macros and panic internals use panic::Location::caller.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 18 | ||||
| -rw-r--r-- | src/libstd/panicking.rs | 24 |
3 files changed, 26 insertions, 17 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 930bf397bc4..23f82d7c211 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -306,6 +306,7 @@ #![feature(thread_local)] #![feature(toowned_clone_into)] #![feature(trace_macros)] +#![feature(track_caller)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(untagged_unions)] diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 11850a1b5fc..18fb0f87688 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -4,6 +4,7 @@ //! library. Each macro is available for use when linking against the standard //! library. +#[cfg(bootstrap)] #[doc(include = "../libcore/macros/panic.md")] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] @@ -19,8 +20,21 @@ macro_rules! panic { $crate::panic!($msg) }); ($fmt:expr, $($arg:tt)+) => ({ - $crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+), - &($crate::file!(), $crate::line!(), $crate::column!())) + $crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+)) + }); +} + +#[cfg(not(bootstrap))] +#[doc(include = "../libcore/macros/panic.md")] +#[macro_export] +#[stable(feature = "rust1", since = "1.0.0")] +#[allow_internal_unstable(libstd_sys_internals)] +macro_rules! panic { + () => ({ $crate::panic!("explicit panic") }); + ($msg:expr) => ({ $crate::rt::begin_panic($msg) }); + ($msg:expr,) => ({ $crate::panic!($msg) }); + ($fmt:expr, $($arg:tt)+) => ({ + $crate::rt::begin_panic_fmt(&$crate::format_args!($fmt, $($arg)+)) }); } diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 43230d7a2c7..e3ce7a33a6f 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -313,17 +313,15 @@ pub fn panicking() -> bool { #[cold] // If panic_immediate_abort, inline the abort call, // otherwise avoid inlining because of it is cold path. +#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)] #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] #[cfg_attr(feature = "panic_immediate_abort", inline)] -pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u32)) -> ! { +pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! { if cfg!(feature = "panic_immediate_abort") { unsafe { intrinsics::abort() } } - // Just package everything into a `PanicInfo` and continue like libcore panics. - let (file, line, col) = *file_line_col; - let location = Location::internal_constructor(file, line, col); - let info = PanicInfo::internal_constructor(Some(msg), &location); + let info = PanicInfo::internal_constructor(Some(msg), Location::caller()); begin_panic_handler(&info) } @@ -372,8 +370,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { let loc = info.location().unwrap(); // The current implementation always returns Some let msg = info.message().unwrap(); // The current implementation always returns Some - let file_line_col = (loc.file(), loc.line(), loc.column()); - rust_panic_with_hook(&mut PanicPayload::new(msg), info.message(), &file_line_col); + rust_panic_with_hook(&mut PanicPayload::new(msg), info.message(), loc); } /// This is the entry point of panicking for the non-format-string variants of @@ -386,7 +383,8 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { // bloat at the call sites as much as possible #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] #[cold] -pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! { +#[track_caller] +pub fn begin_panic<M: Any + Send>(msg: M, #[cfg(bootstrap)] _: &(&str, u32, u32)) -> ! { if cfg!(feature = "panic_immediate_abort") { unsafe { intrinsics::abort() } } @@ -397,8 +395,7 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3 // we do start doing this, then we should propagate this allocation to // be performed in the parent of this thread instead of the thread that's // panicking. - - rust_panic_with_hook(&mut PanicPayload::new(msg), None, file_line_col); + rust_panic_with_hook(&mut PanicPayload::new(msg), None, Location::caller()); struct PanicPayload<A> { inner: Option<A>, @@ -436,10 +433,8 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3 fn rust_panic_with_hook( payload: &mut dyn BoxMeUp, message: Option<&fmt::Arguments<'_>>, - file_line_col: &(&str, u32, u32), + location: &Location<'_>, ) -> ! { - let (file, line, col) = *file_line_col; - let panics = update_panic_count(1); // If this is the third nested call (e.g., panics == 2, this is 0-indexed), @@ -456,8 +451,7 @@ fn rust_panic_with_hook( } unsafe { - let location = Location::internal_constructor(file, line, col); - let mut info = PanicInfo::internal_constructor(message, &location); + let mut info = PanicInfo::internal_constructor(message, location); HOOK_LOCK.read(); match HOOK { // Some platforms (like wasm) know that printing to stderr won't ever actually |
