Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test case showing how previous attempt was unsound
- Loading branch information
1 parent
67c96ed
commit 3b4ed18
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |