2017-01-14 11:59:10 -06:00
|
|
|
// 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.
|
|
|
|
|
2017-11-16 18:08:34 -06:00
|
|
|
// revisions: ast mir
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]compile-flags: -Z borrowck=mir
|
2017-11-16 18:08:34 -06:00
|
|
|
|
2018-04-09 04:28:00 -05:00
|
|
|
// FIXME(#49821) -- No tip about using a let binding
|
|
|
|
|
2017-01-14 11:59:10 -06:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut r = 0;
|
|
|
|
let s = 0;
|
|
|
|
let x = RefCell::new((&mut r,s));
|
|
|
|
|
|
|
|
let val: &_ = x.borrow().0;
|
2017-11-16 18:08:34 -06:00
|
|
|
//[ast]~^ ERROR borrowed value does not live long enough [E0597]
|
|
|
|
//[ast]~| NOTE temporary value dropped here while still borrowed
|
2017-12-14 11:57:34 -06:00
|
|
|
//[ast]~| NOTE temporary value does not live long enough
|
2017-11-16 18:08:34 -06:00
|
|
|
//[ast]~| NOTE consider using a `let` binding to increase its lifetime
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]~^^^^^ ERROR borrowed value does not live long enough [E0597]
|
2017-12-14 11:57:34 -06:00
|
|
|
//[mir]~| NOTE temporary value does not live long enough
|
2018-04-09 04:28:00 -05:00
|
|
|
//[mir]~| NOTE temporary value only lives until here
|
2018-09-09 13:43:46 -05:00
|
|
|
//[mir]~| NOTE consider using a `let` binding to create a longer lived value
|
2017-01-14 11:59:10 -06:00
|
|
|
println!("{}", val);
|
2018-04-09 04:28:00 -05:00
|
|
|
//[mir]~^ borrow later used here
|
2017-01-14 11:59:10 -06:00
|
|
|
}
|
2017-11-16 18:08:34 -06:00
|
|
|
//[ast]~^ NOTE temporary value needs to live until here
|