Added test for #46472

This commit is contained in:
David Wood 2017-12-10 17:00:20 +00:00
parent d78e8a730a
commit 15b8fbdfb3
No known key found for this signature in database
GPG Key ID: 01760B4F9F53F154
4 changed files with 65 additions and 1 deletions

View File

@ -324,6 +324,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
borrows: &Borrows<'cx, 'gcx, 'tcx>
) {
let end_span = borrows.opt_region_end_span(&borrow.region);
let scope_tree = borrows.scope_tree();
let root_place = self.prefixes(&borrow.place, PrefixSet::All).last().unwrap();
match root_place {
@ -359,7 +360,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
borrow_span, &format!("`{}`", description), Origin::Mir);
err.span_label(borrow_span, "does not live long enough");
err.span_label(drop_span, "borrowed value only lives until here");
err.note("borrowed value must be valid for the static lifetime...");
self.tcx.note_and_explain_region(scope_tree, &mut err,
"borrowed value must be valid for ",
borrow.region, "...");
err.emit();
},
None => {

View File

@ -160,6 +160,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
pub fn borrows(&self) -> &IndexVec<BorrowIndex, BorrowData<'tcx>> { &self.borrows }
pub fn scope_tree(&self) -> &Rc<region::ScopeTree> { &self.scope_tree }
pub fn location(&self, idx: BorrowIndex) -> &Location {
&self.borrows[idx].location
}

View File

@ -0,0 +1,19 @@
// Copyright 2016 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.
// compile-flags: -Z emit-end-regions -Z borrowck=compare
fn bar<'a>() -> &'a mut u32 {
&mut 4
//~^ ERROR borrowed value does not live long enough (Ast) [E0597]
//~| ERROR borrowed value does not live long enough (Mir) [E0597]
}
fn main() { }

View File

@ -0,0 +1,40 @@
error[E0597]: borrowed value does not live long enough (Ast)
--> $DIR/issue-46472.rs:14:10
|
14 | &mut 4
| ^ does not live long enough
...
17 | }
| - temporary value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:1...
--> $DIR/issue-46472.rs:13:1
|
13 | / fn bar<'a>() -> &'a mut u32 {
14 | | &mut 4
15 | | //~^ ERROR borrowed value does not live long enough (Ast) [E0597]
16 | | //~| ERROR borrowed value does not live long enough (Mir) [E0597]
17 | | }
| |_^
error[E0597]: borrowed value does not live long enough (Mir)
--> $DIR/issue-46472.rs:14:10
|
14 | &mut 4
| ^ does not live long enough
...
17 | }
| - temporary value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 13:1...
--> $DIR/issue-46472.rs:13:1
|
13 | / fn bar<'a>() -> &'a mut u32 {
14 | | &mut 4
15 | | //~^ ERROR borrowed value does not live long enough (Ast) [E0597]
16 | | //~| ERROR borrowed value does not live long enough (Mir) [E0597]
17 | | }
| |_^
error: aborting due to 2 previous errors