add test case showing how previous attempt was unsound

This commit is contained in:
Niko Matsakis 2018-08-06 12:17:39 +02:00
parent 67c96edce6
commit 3b4ed18d1c
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,29 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Regression test for a bug in #52713: this was an optimization for
// computing liveness that wound up accidentally causing the program
// below to be accepted.
#![feature(nll)]
fn foo<'a>(x: &'a mut u32) -> u32 {
let mut x = 22;
let y = &x;
if false {
return x;
}
x += 1; //~ ERROR
println!("{}", y);
return 0;
}
fn main() { }

View file

@ -0,0 +1,14 @@
error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/issue-52713-bug.rs:24:5
|
LL | let y = &x;
| -- borrow of `x` occurs here
...
LL | x += 1; //~ ERROR
| ^^^^^^ assignment to borrowed `x` occurs here
LL | println!("{}", y);
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0506`.