Skip to content

Commit 7608eb7

Browse files
committed
Auto merge of #159343 - jackh726:enable-polonius-alpha, r=lqd,Kobzol
Enable polonius alpha on nightly See [rust-lang/compiler-team#](rust-lang/compiler-team#1015) The first commit here adds an `-Zpolonius=nll` argument for tests and so people can disable alpha on nightly.
2 parents 87212ce + a9836a4 commit 7608eb7

87 files changed

Lines changed: 178 additions & 125 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_session/src/config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,10 +3599,9 @@ impl PatchableFunctionEntry {
35993599

36003600
/// `-Zpolonius` values, enabling the borrow checker polonius analysis, and which version: legacy,
36013601
/// or future prototype.
3602-
#[derive(Clone, Copy, PartialEq, Hash, Debug, Default)]
3602+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
36033603
pub enum Polonius {
3604-
/// The default value: disabled.
3605-
#[default]
3604+
/// Polonius is disabled, only use NLL.
36063605
Off,
36073606

36083607
/// Legacy version, using datalog and the `polonius-engine` crate. Historical value for `-Zpolonius`.
@@ -3612,6 +3611,12 @@ pub enum Polonius {
36123611
Next,
36133612
}
36143613

3614+
impl Default for Polonius {
3615+
fn default() -> Self {
3616+
if option_env!("CFG_DEFAULT_POLONIUS_NEXT").is_some() { Self::Next } else { Self::Off }
3617+
}
3618+
}
3619+
36153620
impl Polonius {
36163621
/// Returns whether the legacy version of polonius is enabled
36173622
pub fn is_legacy_enabled(&self) -> bool {

compiler/rustc_session/src/options.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ mod desc {
891891
components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
892892
pub(crate) const parse_linker_features: &str =
893893
"a list of enabled (`+` prefix) and disabled (`-` prefix) features: `lld`";
894-
pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
894+
pub(crate) const parse_polonius: &str =
895+
"either no value or one of `legacy` (the default), `off`, or `next`";
895896
pub(crate) const parse_annotate_moves: &str =
896897
"either a boolean (`yes`, `no`, `on`, `off`, etc.), or a size limit in bytes";
897898
pub(crate) const parse_stack_protector: &str =
@@ -985,6 +986,10 @@ pub mod parse {
985986
*slot = Polonius::Next;
986987
true
987988
}
989+
Some("off") | Some("no") => {
990+
*slot = Polonius::Off;
991+
true
992+
}
988993
_ => false,
989994
}
990995
}

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,12 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
13691369
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
13701370
}
13711371

1372+
let nightly = builder.config.channel == "nightly" || builder.config.channel == "dev";
1373+
if nightly {
1374+
// We want to enable Polonius Alpha by default on nighty
1375+
cargo.env("CFG_DEFAULT_POLONIUS_NEXT", "1");
1376+
}
1377+
13721378
// These conditionals represent a tension between three forces:
13731379
// - For non-check builds, we need to define some LLVM-related environment
13741380
// variables, requiring LLVM to have been built.

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-for-swap.edition2015.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
33
|
44
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
55
| -- `x` is borrowed here

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-for-swap.edition2024.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
33
|
44
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
55
| -- `x` is borrowed here

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-for-swap.polonius_alpha.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
33
|
44
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
55
| -- `x` is borrowed here

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-for-swap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//@ ignore-compare-mode-polonius (explicit revisions)
33
//@ [edition2015] edition: 2015
44
//@ [edition2024] edition: 2024
5+
//@ [edition2015] compile-flags: -Zpolonius=off
6+
//@ [edition2024] compile-flags: -Zpolonius=off
57
//@ [polonius_alpha] edition: 2024
68
//@ [polonius_alpha] compile-flags: -Zpolonius=next
79

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-in-type-arg-for-swap.edition2015.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
33
|
44
LL | h.hide(&mut res).swap(h.hide(&mut &x));
55
| -- `x` is borrowed here

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-in-type-arg-for-swap.edition2024.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
33
|
44
LL | h.hide(&mut res).swap(h.hide(&mut &x));
55
| -- `x` is borrowed here

tests/ui/borrowck/alias-liveness/gat-hide-lifetime-in-type-arg-for-swap.polonius_alpha.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `x`
2-
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
2+
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
33
|
44
LL | h.hide(&mut res).swap(h.hide(&mut &x));
55
| -- `x` is borrowed here

0 commit comments

Comments
 (0)