Skip to content
Draft
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
13 changes: 9 additions & 4 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3423,11 +3423,10 @@ impl PatchableFunctionEntry {

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

/// Legacy version, using datalog and the `polonius-engine` crate. Historical value for `-Zpolonius`.
Legacy,
Expand All @@ -3436,6 +3435,12 @@ pub enum Polonius {
Next,
}

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

impl Polonius {
/// Returns whether the legacy version of polonius is enabled
pub fn is_legacy_enabled(&self) -> bool {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ mod desc {
components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
pub(crate) const parse_linker_features: &str =
"a list of enabled (`+` prefix) and disabled (`-` prefix) features: `lld`";
pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
pub(crate) const parse_polonius: &str =
"either no value or one of `legacy` (the default), `nll`, or `next`";
pub(crate) const parse_annotate_moves: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc.), or a size limit in bytes";
pub(crate) const parse_stack_protector: &str =
Expand Down Expand Up @@ -942,6 +943,10 @@ pub mod parse {
*slot = Polonius::Next;
true
}
Some("nll") => {
*slot = Polonius::NLL;
true
}
_ => false,
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,12 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
}

let nightly = builder.config.channel == "nightly" || builder.config.channel == "dev";
if nightly {
// We want to enable Polonius Alpha by default on nighty
cargo.env("CFG_DEFAULT_POLONIUS_NEXT", "1");
}

// These conditionals represent a tension between three forces:
// - For non-check builds, we need to define some LLVM-related environment
// variables, requiring LLVM to have been built.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-for-swap.rs:35:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | h.hide(&mut res).swap(h.hide(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | h.hide(&mut res).swap(h.hide(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/gat-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | h.hide(&mut res).swap(h.hide(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `t` as mutable more than once at a time
--> $DIR/gat-outlives-env.rs:49:13
--> $DIR/gat-outlives-env.rs:51:13
|
LL | let a = t.changes(static_unit);
| - first mutable borrow occurs here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `t` as mutable more than once at a time
--> $DIR/gat-outlives-env.rs:49:13
--> $DIR/gat-outlives-env.rs:51:13
|
LL | let a = t.changes(static_unit);
| - first mutable borrow occurs here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `t` as mutable more than once at a time
--> $DIR/gat-outlives-env.rs:49:13
--> $DIR/gat-outlives-env.rs:51:13
|
LL | let a = t.changes(static_unit);
| - first mutable borrow occurs here
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/borrowck/alias-liveness/gat-outlives-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0506]: cannot assign to `cluster` because it is borrowed
--> $DIR/gat-outlives-implied.rs:19:9
--> $DIR/gat-outlives-implied.rs:20:9
|
LL | let changes = self.changes(&cluster);
| -------- `cluster` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0506]: cannot assign to `cluster` because it is borrowed
--> $DIR/gat-outlives-implied.rs:19:9
--> $DIR/gat-outlives-implied.rs:20:9
|
LL | let changes = self.changes(&cluster);
| -------- `cluster` is borrowed here
Expand Down
1 change: 1 addition & 0 deletions tests/ui/borrowck/alias-liveness/gat-outlives-implied.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ revisions: edition2024 polonius_alpha
//@ ignore-compare-mode-polonius (explicit revisions)
//@ edition: 2024
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] compile-flags: -Zpolonius=next

// Tests that liveness for regions in associated types considers outlives
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/rpit-hide-lifetime-for-swap.rs:36:5
--> $DIR/rpit-hide-lifetime-for-swap.rs:38:5
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
| -- -------------- opaque type defined here
Expand All @@ -14,7 +14,7 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + use<'
| ++++++++++++++++

error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/rpit-hide-lifetime-for-swap.rs:53:5
--> $DIR/rpit-hide-lifetime-for-swap.rs:55:5
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
| -- -------------- opaque type defined here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpit-hide-lifetime-for-swap.rs:44:5
--> $DIR/rpit-hide-lifetime-for-swap.rs:46:5
|
LL | hide_ref(&mut res).swap(hide_ref(&mut &x));
| -- `x` is borrowed here
LL | res
| ^^^ returns a value referencing data owned by the current function

error[E0597]: `x` does not live long enough
--> $DIR/rpit-hide-lifetime-for-swap.rs:60:38
--> $DIR/rpit-hide-lifetime-for-swap.rs:62:38
|
LL | let x = [1, 2, 3];
| - binding `x` declared here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpit-hide-lifetime-for-swap.rs:44:5
--> $DIR/rpit-hide-lifetime-for-swap.rs:46:5
|
LL | hide_ref(&mut res).swap(hide_ref(&mut &x));
| -- `x` is borrowed here
LL | res
| ^^^ returns a value referencing data owned by the current function

error[E0597]: `x` does not live long enough
--> $DIR/rpit-hide-lifetime-for-swap.rs:60:38
--> $DIR/rpit-hide-lifetime-for-swap.rs:62:38
|
LL | let x = [1, 2, 3];
| - binding `x` declared here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | hide(&lock, &mut res).swap(hide(&lock, &mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | hide(&lock, &mut res).swap(hide(&lock, &mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:33:5
--> $DIR/rpit-hide-lifetime-in-type-arg-for-swap.rs:35:5
|
LL | hide(&lock, &mut res).swap(hide(&lock, &mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpitit-hide-lifetime-for-swap.rs:31:5
--> $DIR/rpitit-hide-lifetime-for-swap.rs:33:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpitit-hide-lifetime-for-swap.rs:31:5
--> $DIR/rpitit-hide-lifetime-for-swap.rs:33:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing local variable `x`
--> $DIR/rpitit-hide-lifetime-for-swap.rs:31:5
--> $DIR/rpitit-hide-lifetime-for-swap.rs:33:5
|
LL | h.hide_ref(&mut res).swap(h.hide_ref(&mut &x));
| -- `x` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ ignore-compare-mode-polonius (explicit revisions)
//@ [edition2015] edition: 2015
//@ [edition2024] edition: 2024
//@ [edition2015] compile-flags: -Zpolonius=nll
//@ [edition2024] compile-flags: -Zpolonius=nll
//@ [polonius_alpha] edition: 2024
//@ [polonius_alpha] compile-flags: -Zpolonius=next

Expand Down
32 changes: 16 additions & 16 deletions tests/ui/drop/dropck-normalize-errors.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>`
--> $DIR/dropck-normalize-errors.rs:19:28
--> $DIR/dropck-normalize-errors.rs:20:28
|
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
--> $DIR/dropck-normalize-errors.rs:14:1
--> $DIR/dropck-normalize-errors.rs:15:1
|
LL | struct NonImplementedStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:11:1
--> $DIR/dropck-normalize-errors.rs:12:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `BDecoder`
--> $DIR/dropck-normalize-errors.rs:30:12
--> $DIR/dropck-normalize-errors.rs:31:12
|
LL | pub struct BDecoder {
| ^^^^^^^^
note: required because it appears within the type `ADecoder<'a>`
--> $DIR/dropck-normalize-errors.rs:16:12
--> $DIR/dropck-normalize-errors.rs:17:12
|
LL | pub struct ADecoder<'a> {
| ^^^^^^^^
= note: the return type of a function must have a statically known size

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder`
--> $DIR/dropck-normalize-errors.rs:27:20
--> $DIR/dropck-normalize-errors.rs:28:20
|
LL | type Decoder = BDecoder;
| ^^^^^^^^ unsatisfied trait bound
|
help: within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
--> $DIR/dropck-normalize-errors.rs:14:1
--> $DIR/dropck-normalize-errors.rs:15:1
|
LL | struct NonImplementedStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:11:1
--> $DIR/dropck-normalize-errors.rs:12:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `BDecoder`
--> $DIR/dropck-normalize-errors.rs:30:12
--> $DIR/dropck-normalize-errors.rs:31:12
|
LL | pub struct BDecoder {
| ^^^^^^^^
note: required by a bound in `Decode::Decoder`
--> $DIR/dropck-normalize-errors.rs:8:5
--> $DIR/dropck-normalize-errors.rs:9:5
|
LL | type Decoder;
| ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder`
Expand All @@ -58,35 +58,35 @@ LL | type Decoder: ?Sized;
| ++++++++

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
--> $DIR/dropck-normalize-errors.rs:31:22
--> $DIR/dropck-normalize-errors.rs:32:22
|
LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
--> $DIR/dropck-normalize-errors.rs:14:1
--> $DIR/dropck-normalize-errors.rs:15:1
|
LL | struct NonImplementedStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:11:1
--> $DIR/dropck-normalize-errors.rs:12:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
--> $DIR/dropck-normalize-errors.rs:19:28
--> $DIR/dropck-normalize-errors.rs:20:28
|
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
--> $DIR/dropck-normalize-errors.rs:14:1
--> $DIR/dropck-normalize-errors.rs:15:1
|
LL | struct NonImplementedStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: this trait has no implementations, consider adding one
--> $DIR/dropck-normalize-errors.rs:11:1
--> $DIR/dropck-normalize-errors.rs:12:1
|
LL | trait NonImplementedTrait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Loading
Loading