Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when using panic-strategy abort for proc-macro crates #106678

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/interface.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ interface_rustc_error_unexpected_annotation =
interface_failed_writing_file =
failed to write file {$path}: {$error}"
interface_proc_macro_crate_panic_abort =
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
eholk marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions compiler/rustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rustc_plugin_impl = { path = "../rustc_plugin_impl" }
rustc_privacy = { path = "../rustc_privacy" }
rustc_query_impl = { path = "../rustc_query_impl" }
rustc_resolve = { path = "../rustc_resolve" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_interface/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ pub struct FailedWritingFile<'a> {
pub path: &'a Path,
pub error: io::Error,
}

#[derive(Diagnostic)]
#[diag(interface_proc_macro_crate_panic_abort)]
pub struct ProcMacroCratePanicAbort;
8 changes: 7 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::errors::{
CantEmitMIR, EmojiIdentifier, ErrorWritingDependencies, FerrisIdentifier,
GeneratedFileConflictsWithDirectory, InputFileWouldBeOverWritten, MixedBinCrate,
MixedProcMacroCrate, OutDirError, ProcMacroDocWithoutArg, TempsDirError,
MixedProcMacroCrate, OutDirError, ProcMacroCratePanicAbort, ProcMacroDocWithoutArg,
TempsDirError,
};
use crate::interface::{Compiler, Result};
use crate::proc_macro_decls;
Expand Down Expand Up @@ -36,6 +37,7 @@ use rustc_session::search_paths::PathKind;
use rustc_session::{Limit, Session};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::FileName;
use rustc_target::spec::PanicStrategy;
use rustc_trait_selection::traits;

use std::any::Any;
Expand Down Expand Up @@ -380,6 +382,10 @@ pub fn configure_and_expand(
}
}

if is_proc_macro_crate && sess.panic_strategy() == PanicStrategy::Abort {
sess.emit_warning(ProcMacroCratePanicAbort);
}

// For backwards compatibility, we don't try to run proc macro injection
// if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
// specified. This should only affect users who manually invoke 'rustdoc', as
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/proc-macro/panic-abort.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// error-pattern: building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
// compile-flags: --crate-type proc-macro -Cpanic=abort
// force-host
// check-pass
4 changes: 4 additions & 0 deletions tests/ui/proc-macro/panic-abort.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
warning: building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic

warning: 1 warning emitted