Adds test for NLL problem case 2: issue 92038

This commit is contained in:
Reuben Cruise
2026-04-14 12:11:02 +01:00
parent 2ace98429b
commit 134aa1bafa
2 changed files with 33 additions and 0 deletions
@@ -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`.
@@ -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
}