mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 01:28:18 +03:00
Adds test for NLL problem case 2: issue 92038
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user