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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0502]: cannot borrow `one` as immutable because it is also borrowed as mutable
--> $DIR/location-insensitive-constraints-issue-70044.rs:22:20
|
LL | let mut y = &mut one;
| -------- mutable borrow occurs here
...
LL | println!("{}", one);
| ^^^ immutable borrow occurs here
LL | println!("{}", zero);
| ---- mutable borrow later used here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0502`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This test is taken from https://github.com/rust-lang/rust/issues/70044.
// This test demonstrates how NLL's outlives constraints are flow-insensitive,
// and are wrongly expected to hold outside the inner scope.

//@ ignore-compare-mode-polonius (explicit revisions)
//@ revisions: nll polonius legacy
//@ [polonius] check-pass
//@ [polonius] compile-flags: -Z polonius=next
//@ [legacy] check-pass
//@ [legacy] compile-flags: -Z polonius=legacy

fn main() {
let mut zero = &mut 0;
let mut one = 1;

{
let mut _r = &mut zero;
let mut y = &mut one;
_r = &mut y;
}

println!("{}", one); //[nll]~ ERROR: cannot borrow `one` as immutable
println!("{}", zero);
}
16 changes: 16 additions & 0 deletions tests/ui/nll/polonius/nll-problem-case-2-issue-92038.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0499]: cannot borrow `*a` as mutable more than once at a time
--> $DIR/nll-problem-case-2-issue-92038.rs:16:26
|
LL | fn reborrow(a: &mut u8) -> &mut u8 {
| - let's call the lifetime of this reference `'1`
LL | let b = &mut *a;
| ------- first mutable borrow occurs here
LL | if true { b } else { a }
| ---------------------^--
| | |
| | second mutable borrow occurs here
| returning this value requires that `*a` is borrowed for `'1`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0499`.
17 changes: 17 additions & 0 deletions tests/ui/nll/polonius/nll-problem-case-2-issue-92038.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![crate_type = "lib"]

// This test demonstrates a shortcoming of NLL known as problem case #2
// https://rust-lang.github.io/rfcs/2094-nll.html#problem-case-2-conditional-control-flow
// This MCVE is copied from https://github.com/rust-lang/rust/issues/92038.

//@ ignore-compare-mode-polonius (explicit revisions)
//@ revisions: nll polonius legacy
//@ [polonius] check-pass
//@ [polonius] compile-flags: -Z polonius=next
//@ [legacy] check-pass
//@ [legacy] compile-flags: -Z polonius=legacy

fn reborrow(a: &mut u8) -> &mut u8 {
let b = &mut *a;
if true { b } else { a } //[nll]~ ERROR: cannot borrow `*a` as mutable more than once at a time
}
Loading