Skip to content

Reborrow of borrowed value #55248

Closed
Closed
@sander2

Description

@sander2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions