Skip to content
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

Reborrow of borrowed value #55248

Closed
sander2 opened this issue Oct 21, 2018 · 2 comments
Closed

Reborrow of borrowed value #55248

sander2 opened this issue Oct 21, 2018 · 2 comments
Labels
fixed-by-NLL Bugs fixed, but only when NLL is enabled.

Comments

@sander2
Copy link

sander2 commented Oct 21, 2018

I think the code below should not be allowed by the compiler, but it is. Here, even though arg is mutably borrowed, we are allowed to make a copy (reborrow) of it. Why is this the case? As the comment shows, a read of arg is invalid, so why isn't a reborrow? I had a discussion about this on the IRC, but I would like a second opinion, as I'm still not convinced the behavior is consistent. The only difference I see between a reborrow let b = &*arg and a copy let c = arg is the lifetimes of the resulting borrows. But I don't see why that would make the first valid but not the second..

fn f(mut arg: & bool) {
  let a = & mut arg; 
  let b = &*arg; // allowed 
 // this would not be allowed: let c = arg;
}

Tested on 1.29.2.

@matthewjasper matthewjasper added the fixed-by-NLL Bugs fixed, but only when NLL is enabled. label Oct 21, 2018
@matthewjasper
Copy link
Contributor

Duplicate of #38899, it's fixed by NLL (although there has to be a later use of a to get an error)

@sander2
Copy link
Author

sander2 commented Oct 21, 2018

Ah alright, glad to know this is known bug. Sorry for the duplicate.

@sander2 sander2 closed this as completed Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-by-NLL Bugs fixed, but only when NLL is enabled.
Projects
None yet
Development

No branches or pull requests

2 participants