Skip to content

Commit b466623

Browse files
committed
Add panic=immediate-abort support to Cargo
1 parent 9191c77 commit b466623

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ fn build_base_args(
13051305
// flag to pass to rustc, so register that here. Eventually this flag
13061306
// will simply not be needed when the behavior is stabilized in the Rust
13071307
// compiler itself.
1308-
if *panic == PanicStrategy::Abort {
1308+
if *panic == PanicStrategy::Abort || *panic == PanicStrategy::ImmediateAbort {
13091309
cmd.arg("-Z").arg("panic-abort-tests");
13101310
}
13111311
} else if test {

src/cargo/core/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ features! {
579579

580580
/// Allows use of multiple build scripts.
581581
(unstable, multiple_build_scripts, "", "reference/unstable.html#multiple-build-scripts"),
582+
583+
/// Allows use of panic="immediate-abort".
584+
(unstable, panic_immediate_abort, "", "reference/unstable.html#panic-immediate-abort"),
582585
}
583586

584587
/// Status and metadata for a single unstable feature.

src/cargo/core/profiles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
561561
profile.panic = match panic.as_str() {
562562
"unwind" => PanicStrategy::Unwind,
563563
"abort" => PanicStrategy::Abort,
564+
"immediate-abort" => PanicStrategy::ImmediateAbort,
564565
// This should be validated in TomlProfile::validate
565566
_ => panic!("Unexpected panic setting `{}`", panic),
566567
};
@@ -876,13 +877,15 @@ impl serde::ser::Serialize for Lto {
876877
pub enum PanicStrategy {
877878
Unwind,
878879
Abort,
880+
ImmediateAbort,
879881
}
880882

881883
impl fmt::Display for PanicStrategy {
882884
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
883885
match *self {
884886
PanicStrategy::Unwind => "unwind",
885887
PanicStrategy::Abort => "abort",
888+
PanicStrategy::ImmediateAbort => "immediate-abort",
886889
}
887890
.fmt(f)
888891
}

src/doc/src/reference/unstable.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Each new feature described below should explain how to use it.
9595
* [target-applies-to-host](#target-applies-to-host) --- Alters whether certain flags will be passed to host build targets.
9696
* [gc](#gc) --- Global cache garbage collection.
9797
* [open-namespaces](#open-namespaces) --- Allow multiple packages to participate in the same API namespace
98+
* [panic-immediate-abort](#panic-immediate-abort) --- Passes `-Cpanic=immediate-abort` to the compiler.
9899
* rustdoc
99100
* [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
100101
* [scrape-examples](#scrape-examples) --- Shows examples within documentation.
@@ -1670,6 +1671,23 @@ cargo-features = ["open-namespaces"]
16701671
# ...
16711672
```
16721673

1674+
## panic-immediate-abort
1675+
1676+
* Tracking Issue: [#0000](https://github.com/rust-lang/cargo/issues/0000)
1677+
1678+
Allow use of the ImmediateAbort panic strategy in a Cargo profile
1679+
1680+
This can be enabled like so:
1681+
```toml
1682+
cargo-features = ["immediate-abort"]
1683+
1684+
[package]
1685+
# ...
1686+
1687+
[profile.release]
1688+
panic = "immediate-abort"
1689+
```
1690+
16731691
## `[lints.cargo]`
16741692

16751693
* Tracking Issue: [#12235](https://github.com/rust-lang/cargo/issues/12235)

0 commit comments

Comments
 (0)