Skip to content

Commit 8feae12

Browse files
committed
Enable the lint in std
1 parent e528318 commit 8feae12

10 files changed

Lines changed: 22 additions & 16 deletions

File tree

library/std/src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ fn default_alloc_error_hook(layout: Layout) {
420420
#[doc(hidden)]
421421
#[alloc_error_handler]
422422
#[unstable(feature = "alloc_internals", issue = "none")]
423+
#[allow(missing_panic_entrypoint)]
423424
pub fn rust_oom(layout: Layout) -> ! {
424425
crate::sys::backtrace::__rust_end_short_backtrace(|| {
425426
let hook = HOOK.load(Ordering::Acquire);

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
#![deny(unsafe_op_in_unsafe_fn)]
250250
#![allow(rustdoc::redundant_explicit_links)]
251251
#![warn(rustdoc::unescaped_backticks)]
252+
#![warn(missing_panic_entrypoint)]
252253
// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
253254
#![deny(ffi_unwind_calls)]
254255
// std may use features in a platform-specific way

library/std/src/panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
387387
/// }
388388
/// ```
389389
#[stable(feature = "resume_unwind", since = "1.9.0")]
390+
#[allow(missing_panic_entrypoint)]
390391
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
391392
panicking::resume_unwind(payload)
392393
}

library/std/src/panicking.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ unsafe extern "Rust" {
7171
/// with our panic count.
7272
#[cfg(not(test))]
7373
#[rustc_std_internal_symbol]
74+
#[allow(missing_panic_entrypoint)]
7475
extern "C" fn __rust_drop_panic() -> ! {
7576
rtabort!("Rust panics must be rethrown");
7677
}
@@ -79,6 +80,7 @@ extern "C" fn __rust_drop_panic() -> ! {
7980
/// object which does not correspond to a Rust panic.
8081
#[cfg(not(test))]
8182
#[rustc_std_internal_symbol]
83+
#[allow(missing_panic_entrypoint)]
8284
extern "C" fn __rust_foreign_exception() -> ! {
8385
rtabort!("Rust cannot catch foreign exceptions");
8486
}
@@ -619,6 +621,7 @@ pub fn panicking() -> bool {
619621
/// Entry point of panics from the core crate (`panic_impl` lang item).
620622
#[cfg(not(any(test, doctest)))]
621623
#[panic_handler]
624+
#[allow(missing_panic_entrypoint)]
622625
pub fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
623626
struct FormatStringPayload<'a> {
624627
inner: &'a core::panic::PanicMessage<'a>,
@@ -711,17 +714,14 @@ pub fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
711714
#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
712715
#[cfg_attr(not(any(test, doctest)), lang = "begin_panic")]
713716
// lang item for CTFE panic support
714-
// never inline unless panic=immediate-abort to avoid code
715-
// bloat at the call sites as much as possible
716-
#[cfg_attr(not(panic = "immediate-abort"), inline(never), cold, optimize(size))]
717-
#[cfg_attr(panic = "immediate-abort", inline)]
717+
// never inline to avoid code bloat at the call sites as much as possible
718+
#[cold]
719+
#[inline(never)]
720+
#[optimize(size)]
718721
#[track_caller]
719722
#[rustc_do_not_const_check] // hooked by const-eval
723+
#[rustc_panic_entrypoint]
720724
pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
721-
if cfg!(panic = "immediate-abort") {
722-
intrinsics::abort()
723-
}
724-
725725
struct Payload<A> {
726726
inner: Option<A>,
727727
}
@@ -784,6 +784,7 @@ fn payload_as_str(payload: &dyn Any) -> &str {
784784
/// panics, panic hooks, and finally dispatching to the panic runtime to either
785785
/// abort or unwind.
786786
#[optimize(size)]
787+
#[allow(missing_panic_entrypoint)]
787788
fn panic_with_hook(
788789
payload: &mut dyn PanicPayload,
789790
location: &Location<'_>,
@@ -853,6 +854,7 @@ fn panic_with_hook(
853854
/// This is the entry point for `resume_unwind`.
854855
/// It just forwards the payload to the panic runtime.
855856
#[cfg_attr(panic = "immediate-abort", inline)]
857+
#[allow(missing_panic_entrypoint)]
856858
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
857859
panic_count::increase(false);
858860

@@ -881,14 +883,8 @@ pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
881883
/// on which to slap yer breakpoints.
882884
#[inline(never)]
883885
#[cfg_attr(not(test), rustc_std_internal_symbol)]
884-
#[cfg(not(panic = "immediate-abort"))]
886+
#[rustc_panic_entrypoint]
885887
fn rust_panic(msg: &mut dyn PanicPayload) -> ! {
886888
let code = unsafe { __rust_start_panic(msg) };
887889
rtabort!("failed to initiate panic, error {code}")
888890
}
889-
890-
#[cfg_attr(not(test), rustc_std_internal_symbol)]
891-
#[cfg(panic = "immediate-abort")]
892-
fn rust_panic(_: &mut dyn PanicPayload) -> ! {
893-
crate::intrinsics::abort();
894-
}

library/std/src/process.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,7 @@ impl ExitCode {
21602160
/// }
21612161
/// ```
21622162
#[unstable(feature = "exitcode_exit_method", issue = "97100")]
2163+
#[allow(missing_panic_entrypoint)]
21632164
pub fn exit_process(self) -> ! {
21642165
exit(self.to_i32())
21652166
}
@@ -2462,6 +2463,7 @@ impl Child {
24622463
/// [C-exit]: https://en.cppreference.com/w/c/program/exit
24632464
#[stable(feature = "rust1", since = "1.0.0")]
24642465
#[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")]
2466+
#[allow(missing_panic_entrypoint)]
24652467
pub fn exit(code: i32) -> ! {
24662468
crate::rt::cleanup();
24672469
crate::sys::os::exit(code)
@@ -2529,6 +2531,7 @@ pub fn exit(code: i32) -> ! {
25292531
#[cold]
25302532
#[cfg_attr(not(test), rustc_diagnostic_item = "process_abort")]
25312533
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2534+
#[allow(missing_panic_entrypoint)]
25322535
pub fn abort() -> ! {
25332536
crate::sys::abort_internal();
25342537
}

library/std/src/sync/lazy_lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
406406

407407
#[cold]
408408
#[inline(never)]
409+
#[rustc_panic_entrypoint]
409410
fn panic_poisoned() -> ! {
410411
panic!("LazyLock instance has previously been poisoned")
411412
}

library/std/src/sys/pal/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
358358
// stdlib doesn't use libc stdio buffering. In a typical Rust program, which
359359
// does not use C stdio, even a buggy libc::abort() is, in fact, safe.
360360
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
361+
#[allow(missing_panic_entrypoint)]
361362
pub fn abort_internal() -> ! {
362363
unsafe { libc::abort() }
363364
}

library/std/src/sys/pal/unix/os.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ pub fn home_dir() -> Option<PathBuf> {
663663
}
664664
}
665665

666+
#[allow(missing_panic_entrypoint)]
666667
pub fn exit(code: i32) -> ! {
667668
crate::sys::exit_guard::unique_thread_exit();
668669
unsafe { libc::exit(code as c_int) }

library/std/src/thread/id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl ThreadId {
3434
// Generate a new unique thread ID.
3535
pub(crate) fn new() -> ThreadId {
3636
#[cold]
37+
#[rustc_panic_entrypoint]
3738
fn exhausted() -> ! {
3839
panic!("failed to generate unique thread ID: bitspace exhausted")
3940
}

library/std/src/thread/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ impl fmt::Display for AccessError {
428428
impl Error for AccessError {}
429429

430430
// This ensures the panicking code is outlined from `with` for `LocalKey`.
431-
#[cfg_attr(not(panic = "immediate-abort"), inline(never))]
432431
#[track_caller]
433432
#[cold]
433+
#[rustc_panic_entrypoint]
434434
fn panic_access_error(err: AccessError) -> ! {
435435
panic!("cannot access a Thread Local Storage value during or after destruction: {err:?}")
436436
}

0 commit comments

Comments
 (0)