Skip to content
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
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3647,11 +3647,14 @@ pub enum Polonius {

impl Default for Polonius {
fn default() -> Self {
if option_env!("CFG_DEFAULT_POLONIUS_NEXT").is_some() { Self::Next } else { Self::Off }
Self::DEFAULT
}
}

impl Polonius {
pub(crate) const DEFAULT: Self =
if option_env!("CFG_DEFAULT_POLONIUS_NEXT").is_some() { Self::Next } else { Self::Off };

/// Returns whether the legacy version of polonius is enabled
pub fn is_legacy_enabled(&self) -> bool {
matches!(self, Polonius::Legacy)
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ macro_rules! options {
$( { TARGET_MODIFIER: $tmod_variant:ident } )?
$( { MITIGATION: $mitigation_variant:ident } )?
,
$desc:literal
$desc:expr
$(, removed: $removed:ident )?
),
)*
Expand Down Expand Up @@ -2350,6 +2350,12 @@ options! {
// - src/doc/rustc/src/codegen-options/index.md
}

const POLONIUS_HELP: &str = match Polonius::DEFAULT {
Polonius::Off => "enable polonius-based borrow-checker (default: no)",
Polonius::Next => "enable polonius-based borrow-checker (default: next)",
Polonius::Legacy => panic!("Polonius::Legacy is not a valid default value"),
};

options! {
UnstableOptions, UnstableOptionsTargetModifiers, Z_OPTIONS, dbopts, "Z", "unstable",

Expand Down Expand Up @@ -2750,7 +2756,7 @@ options! {
`vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers
Example: `-Zpointer-authentication=+calls,-init-fini`."),
polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED],
"enable polonius-based borrow-checker (default: no)"),
POLONIUS_HELP),
pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
"a single extra argument to prepend the linker invocation (can be used several times)"),
pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/rustc-help/polonius-help-stable.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Z polonius=val -- enable polonius-based borrow-checker (default: no)
1 change: 1 addition & 0 deletions tests/run-make/rustc-help/polonius-help.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Z polonius=val -- enable polonius-based borrow-checker (default: next)
15 changes: 15 additions & 0 deletions tests/run-make/rustc-help/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use run_make_support::{bare_rustc, diff, similar};
fn main() {
// `rustc --help`
let help = bare_rustc().arg("--help").run().stdout_utf8();

diff().expected_file("help.stdout").actual_text("(rustc --help)", &help).run();

// `rustc` should be the same as `rustc --help`
Expand All @@ -22,6 +23,20 @@ fn main() {
// Check that all help options can be invoked at once
let codegen_help = bare_rustc().arg("-Chelp").run().stdout_utf8();
let unstable_help = bare_rustc().arg("-Zhelp").run().stdout_utf8();

let polonius_help =
format!("{}\n", unstable_help.lines().find(|line| line.contains("polonius=val")).unwrap());
let version = bare_rustc().arg("--version").run().stdout_utf8();
let expected_file = if version.contains("-nightly") || version.contains("-dev") {
"polonius-help.stdout"
} else {
"polonius-help-stable.stdout"
};
diff()
.expected_file(expected_file)
.actual_text("rustc -Zhelp (polonius)", &polonius_help)
.run();

let lints_help = bare_rustc().arg("-Whelp").run().stdout_utf8();
let expected_all = format!("{help}{codegen_help}{unstable_help}{lints_help}");
let all_help = bare_rustc().args(["--help", "-Chelp", "-Zhelp", "-Whelp"]).run().stdout_utf8();
Expand Down
Loading