Skip to content

RefCell value lifetime check error #35008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paomian opened this issue Jul 24, 2016 · 3 comments
Closed

RefCell value lifetime check error #35008

paomian opened this issue Jul 24, 2016 · 3 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@paomian
Copy link

paomian commented Jul 24, 2016

when I use RefCell like after code.

use std::cell::RefCell;

fn test() -> bool {
    let a = RefCell::new(5);
    *a.borrow_mut() < 6    //error
    //return *a.borrow_mut() < 6;   // ok
}
fn main() {
    test();
}

https://is.gd/T8Wmps
will trigger a compile error

error: `a` does not live long enough
 --> <anon>:5:6
  |
5 |     *a.borrow_mut() < 6    // error
  |      ^
  |
note: reference must be valid for the destruction scope surrounding block at 3:18...
 --> <anon>:3:19
  |
3 | fn test() -> bool {
  |                   ^
note: ...but borrowed value is only valid for the block suffix following statement 0 at 4:28
 --> <anon>:4:29
  |
4 |     let a = RefCell::new(5);
  |                             ^

error: aborting due to previous error
rustc --version --verbose
rustc 1.12.0-nightly (936bfea94 2016-07-20)
binary: rustc
commit-hash: 936bfea94b800551c972e5689ae7da86d3d601de
commit-date: 2016-07-20
host: x86_64-apple-darwin
release: 1.12.0-nightly

cargo --version --verbose
cargo 0.13.0-nightly (664125b 2016-07-19)

MacOS EI Capitan 10.11.6
@Aatch Aatch changed the title RefCell value lifetime check error ? RefCell value lifetime check error Jul 25, 2016
@Aatch
Copy link
Contributor

Aatch commented Jul 25, 2016

Looks like it's related to #31723. Not quite the same issue, but likely the same cause.

@Aatch Aatch added the A-lifetimes Area: Lifetimes / regions label Jul 25, 2016
@paomian
Copy link
Author

paomian commented Jul 25, 2016

This issue is seem to related to #31723 ,but not same completely.so I can not know whether or not it is same issue.

@Mark-Simulacrum
Copy link
Member

I think this is #21114, closing in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

3 participants