Skip to content

Commit 98aaca3

Browse files
committed
Tweak the lint and add a Miri test
1 parent a700f93 commit 98aaca3

4 files changed

Lines changed: 65 additions & 9 deletions

File tree

compiler/rustc_lint/src/lints.rs

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

3977-
#[derive(LintDiagnostic)]
3977+
#[derive(Diagnostic)]
39783978
#[diag("this function could have the attribute #[rustc_panic_entrypoint]")]
39793979
pub(crate) struct MissingPanicEntrypoint;

src/tools/miri/src/eval.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,16 @@ pub fn create_ecx<'tcx>(
288288
MiriMachine::new(config, layout_cx, genmc_ctx),
289289
);
290290

291-
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
292-
let sentinel =
293-
helpers::try_resolve_path(tcx, &["core", "ascii", "escape_default"], Namespace::ValueNS);
294-
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
295-
tcx.dcx().fatal(
296-
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing.\n\
297-
Note that directly invoking the `miri` binary is not supported; please use `cargo miri` instead."
298-
);
291+
if !rustc_hir::find_attr!(tcx, crate, NoCore(..)) {
292+
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
293+
let sentinel =
294+
helpers::try_resolve_path(tcx, &["core", "ascii", "escape_default"], Namespace::ValueNS);
295+
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
296+
tcx.dcx().fatal(
297+
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing.\n\
298+
Note that directly invoking the `miri` binary is not supported; please use `cargo miri` instead."
299+
);
300+
}
299301
}
300302

301303
// Compute argc and argv from `config.args`.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 --target=x86_64-unknown-none
6+
7+
#![no_std]
8+
#![no_core]
9+
#![no_main]
10+
#![feature(rustc_attrs, no_core, lang_items, intrinsics)]
11+
#![allow(internal_features)]
12+
13+
#[lang = "pointee_sized"]
14+
#[diagnostic::on_unimplemented(
15+
message = "values of type `{Self}` may or may not have a size",
16+
label = "may or may not have a known size"
17+
)]
18+
pub trait PointeeSized {}
19+
20+
#[lang = "meta_sized"]
21+
#[diagnostic::on_unimplemented(
22+
message = "the size for values of type `{Self}` cannot be known",
23+
label = "doesn't have a known size"
24+
)]
25+
pub trait MetaSized: PointeeSized {}
26+
27+
#[lang = "sized"]
28+
#[diagnostic::on_unimplemented(
29+
message = "the size for values of type `{Self}` cannot be known at compilation time",
30+
label = "doesn't have a size known at compile-time"
31+
)]
32+
pub trait Sized: MetaSized {}
33+
34+
#[rustc_nounwind]
35+
#[rustc_intrinsic]
36+
#[lang = "abort_intrinsic"]
37+
fn abort() -> !;
38+
39+
#[no_mangle]
40+
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
41+
panic_entrypoint(); //~ ERROR: abnormal termination: the program aborted execution
42+
0
43+
}
44+
45+
#[rustc_panic_entrypoint]
46+
fn panic_entrypoint() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: abnormal termination: the program aborted execution
2+
--> tests/fail/immediate-abort.rs:LL:CC
3+
|
4+
LL | panic_entrypoint();
5+
| ^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)