Skip to content

Commit

Permalink
add test case showing how previous attempt was unsound
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Aug 6, 2018
1 parent 67c96ed commit 3b4ed18
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/ui/borrowck/issue-52713-bug.rs
@@ -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() { }
14 changes: 14 additions & 0 deletions src/test/ui/borrowck/issue-52713-bug.stderr
@@ -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`.

0 comments on commit 3b4ed18

Please sign in to comment.