Skip to content

Commit e4d0104

Browse files
authored
Rollup merge of #106678 - Veykril:proc-macro-panic-abort, r=eholk
Warn when using panic-strategy abort for proc-macro crates See #82320, this simply warns for now as that seems like the best step that can be immediately taken (opposed to straight up rejecting or ignoring)
2 parents 57b371a + 549ece7 commit e4d0104

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

compiler/rustc_error_messages/locales/en-US/interface.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ interface_rustc_error_unexpected_annotation =
4141
4242
interface_failed_writing_file =
4343
failed to write file {$path}: {$error}"
44+
45+
interface_proc_macro_crate_panic_abort =
46+
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic

compiler/rustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rustc_plugin_impl = { path = "../rustc_plugin_impl" }
4545
rustc_privacy = { path = "../rustc_privacy" }
4646
rustc_query_impl = { path = "../rustc_query_impl" }
4747
rustc_resolve = { path = "../rustc_resolve" }
48+
rustc_target = { path = "../rustc_target" }
4849
rustc_trait_selection = { path = "../rustc_trait_selection" }
4950
rustc_ty_utils = { path = "../rustc_ty_utils" }
5051

compiler/rustc_interface/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ pub struct FailedWritingFile<'a> {
8787
pub path: &'a Path,
8888
pub error: io::Error,
8989
}
90+
91+
#[derive(Diagnostic)]
92+
#[diag(interface_proc_macro_crate_panic_abort)]
93+
pub struct ProcMacroCratePanicAbort;

compiler/rustc_interface/src/passes.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::errors::{
22
CantEmitMIR, EmojiIdentifier, ErrorWritingDependencies, FerrisIdentifier,
33
GeneratedFileConflictsWithDirectory, InputFileWouldBeOverWritten, MixedBinCrate,
4-
MixedProcMacroCrate, OutDirError, ProcMacroDocWithoutArg, TempsDirError,
4+
MixedProcMacroCrate, OutDirError, ProcMacroCratePanicAbort, ProcMacroDocWithoutArg,
5+
TempsDirError,
56
};
67
use crate::interface::{Compiler, Result};
78
use crate::proc_macro_decls;
@@ -36,6 +37,7 @@ use rustc_session::search_paths::PathKind;
3637
use rustc_session::{Limit, Session};
3738
use rustc_span::symbol::{sym, Symbol};
3839
use rustc_span::FileName;
40+
use rustc_target::spec::PanicStrategy;
3941
use rustc_trait_selection::traits;
4042

4143
use std::any::Any;
@@ -380,6 +382,10 @@ pub fn configure_and_expand(
380382
}
381383
}
382384

385+
if is_proc_macro_crate && sess.panic_strategy() == PanicStrategy::Abort {
386+
sess.emit_warning(ProcMacroCratePanicAbort);
387+
}
388+
383389
// For backwards compatibility, we don't try to run proc macro injection
384390
// if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
385391
// specified. This should only affect users who manually invoke 'rustdoc', as

tests/ui/proc-macro/panic-abort.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// error-pattern: building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
2+
// compile-flags: --crate-type proc-macro -Cpanic=abort
3+
// force-host
4+
// check-pass
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
warning: building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
2+
3+
warning: 1 warning emitted
4+

0 commit comments

Comments
 (0)