Skip to content

Commit 718bc0e

Browse files
committed
Tweak the lint and add a Miri test
1 parent b47ee18 commit 718bc0e

3 files changed

Lines changed: 101 additions & 1 deletion

File tree

compiler/rustc_lint/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,6 @@ pub(crate) struct MalformedOnConstAttrLint {
39563956
#[note("this method was used to add checks to the `Eq` derive macro")]
39573957
pub(crate) struct EqInternalMethodImplemented;
39583958

3959-
#[derive(LintDiagnostic)]
3959+
#[derive(Diagnostic)]
39603960
#[diag("this function could have the attribute #[rustc_panic_entrypoint]")]
39613961
pub(crate) struct MissingPanicEntrypoint;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that when we call a function with #[rustc_panic_entrypoint], we encounter an abort and do
2+
// not actually execute the function. Immediate-aborting panics are implemented by a rewrite of such
3+
// functions, so this tests that the rewrite works with Miri.
4+
5+
//@compile-flags: -Cpanic=immediate-abort -Zunstable-options
6+
7+
#![feature(rustc_attrs)]
8+
9+
fn main() {
10+
panic_entrypoint();
11+
}
12+
13+
#[rustc_panic_entrypoint]
14+
fn panic_entrypoint() {
15+
println!("Hello!");
16+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
error: the crate `core` was compiled with a panic strategy which is incompatible with `immediate-abort`
2+
3+
4+
Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
5+
6+
thread 'rustc' ($TID) panicked at src/tools/miri/src/diagnostics.rs:LL:CC:
7+
assertion failed: !span.is_dummy()
8+
stack backtrace:
9+
0: __rustc::rust_begin_unwind
10+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:LL:CC
11+
1: core::panicking::panic_fmt
12+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panicking.rs:LL:CC
13+
2: core::panicking::panic
14+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panicking.rs:LL:CC
15+
3: miri::diagnostics::report_msg
16+
at ./src/diagnostics.rs:LL:CC
17+
4: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine> as miri::diagnostics::EvalContextExt>::handle_ice
18+
at ./src/diagnostics.rs:LL:CC
19+
5: miri::eval::eval_entry::{closure#1}
20+
at ./src/eval.rs:LL:CC
21+
6: <core::result::Result<rustc_middle::mir::interpret::error::InterpResult<!>, alloc::boxed::Box<dyn core::any::Any + core::marker::Send>>>::unwrap_or_else
22+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/result.rs:LL:CC
23+
7: miri::eval::eval_entry
24+
at ./src/eval.rs:LL:CC
25+
8: <miri::MiriCompilerCalls as rustc_driver_impl::Callbacks>::after_analysis
26+
at ./src/bin/miri.rs:LL:CC
27+
9: rustc_driver_impl::run_compiler::{closure#0}::{closure#2}
28+
at /home/ben/rust/compiler/rustc_driver_impl/src/lib.rs:LL:CC
29+
10: rustc_interface::passes::create_and_enter_global_ctxt::{closure#2}
30+
at /home/ben/rust/compiler/rustc_interface/src/passes.rs:LL:CC
31+
11: <rustc_middle::ty::context::GlobalCtxt>::enter::{closure#1}
32+
at /home/ben/rust/compiler/rustc_middle/src/ty/context.rs:LL:CC
33+
12: rustc_middle::ty::context::tls::enter_context::{closure#0}
34+
at /home/ben/rust/compiler/rustc_middle/src/ty/context/tls.rs:LL:CC
35+
13: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::try_with
36+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:LL:CC
37+
14: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with
38+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/thread/local.rs:LL:CC
39+
15: rustc_middle::ty::context::tls::enter_context
40+
at /home/ben/rust/compiler/rustc_middle/src/ty/context/tls.rs:LL:CC
41+
16: <rustc_middle::ty::context::GlobalCtxt>::enter
42+
at /home/ben/rust/compiler/rustc_middle/src/ty/context.rs:LL:CC
43+
17: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt
44+
at /home/ben/rust/compiler/rustc_middle/src/ty/context.rs:LL:CC
45+
18: rustc_interface::passes::create_and_enter_global_ctxt
46+
at /home/ben/rust/compiler/rustc_interface/src/passes.rs:LL:CC
47+
19: rustc_driver_impl::run_compiler::{closure#0}
48+
at /home/ben/rust/compiler/rustc_driver_impl/src/lib.rs:LL:CC
49+
20: rustc_interface::interface::run_compiler::{closure#1}::{closure#0}
50+
at /home/ben/rust/compiler/rustc_interface/src/interface.rs:LL:CC
51+
21: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
52+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/core/src/panic/unwind_safe.rs:LL:CC
53+
22: std::panicking::catch_unwind::do_call
54+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:LL:CC
55+
23: std::panicking::catch_unwind
56+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panicking.rs:LL:CC
57+
24: std::panic::catch_unwind
58+
at /rustc/9b1f8ff42d110b0ca138116745be921df5dc97e7/library/std/src/panic.rs:LL:CC
59+
25: rustc_interface::interface::run_compiler::{closure#1}
60+
at /home/ben/rust/compiler/rustc_interface/src/interface.rs:LL:CC
61+
26: rustc_interface::util::run_in_thread_pool_with_globals::{closure#0}
62+
at /home/ben/rust/compiler/rustc_interface/src/util.rs:LL:CC
63+
27: rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure#0}
64+
at /home/ben/rust/compiler/rustc_interface/src/util.rs:LL:CC
65+
28: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set
66+
at CARGO_REGISTRY/.../lib.rs:LL:CC
67+
29: rustc_span::create_session_globals_then
68+
at /home/ben/rust/compiler/rustc_span/src/lib.rs:LL:CC
69+
30: rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}
70+
at /home/ben/rust/compiler/rustc_interface/src/util.rs:LL:CC
71+
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
72+
73+
error: the compiler unexpectedly panicked. This is a bug
74+
75+
note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly
76+
77+
note: rustc 1.95.0-dev running on x86_64-unknown-linux-gnu
78+
79+
note: compiler flags: -Z ui-testing -C panic=immediate-abort -Z unstable-options
80+
81+
query stack during panic:
82+
end of query stack
83+
error: aborting due to 1 previous error
84+

0 commit comments

Comments
 (0)