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

Guide: specify that both shared and mutable borrows can be re-lent. #17992

Merged
merged 1 commit into from
Oct 14, 2014

Conversation

jkleint
Copy link

@jkleint jkleint commented Oct 13, 2014

@steveklabnik, you can re-lend both mutable and immutable borrows, and the rules for returning them are the same, no?

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon.

@steveklabnik
Copy link
Member

Hmmmm. I guess this is true. I thought you could only lend out a borrow immutably, but I guess if you have a mutable borrow, you can also lend it out mutably, once.

Can someone else review this too, please?

@Gankra
Copy link
Contributor

Gankra commented Oct 13, 2014

Definitely more accurate to me. This is the mechanism that allows calling &mut self methods from &mut self methods. It's not exactly obscure or rare. It's quite important!

@jkleint
Copy link
Author

jkleint commented Oct 13, 2014

Does this illustrate it?

fn borrow_mut(x: &mut int) {
    *x += 1;
    second_hand_mut(x);
}

fn second_hand_mut(x: &mut int) {
    *x += 2;
}

fn main() {
    let mut x = 5i;
    borrow_mut(&mut x);
    println!("{}", x);      // Prints 8
}

@alexcrichton
Copy link
Member

@steveklabnik yeah you should be able to pass along mutable borrows (as @jkleint showed), are you ok with the wording?

@steveklabnik
Copy link
Member

Yeah, after coming back to it, all seems well. Thank you!

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 13, 2014
@bors bors merged commit ed7d1be into rust-lang:master Oct 14, 2014
@jkleint jkleint deleted the guide-double-borrow branch October 15, 2014 01:10
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 29, 2024
internal: Avoid newlines in fetch errors

Most logs lines don't have newlines, ensure fetch errors follow this pattern. This makes it easier to see which log line is associated with the error.

Before:

    2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError:
    rust-analyzer failed to discover workspace

After:

    2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError: rust-analyzer failed to discover workspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants