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

Fixed incorrect usage of 'Borrowing'. #10167

Merged
merged 1 commit into from
Oct 31, 2013
Merged

Conversation

brian-dawn
Copy link
Contributor

To keep consistency with the word "borrowing" I suppose an alternate way to write this could be "Having an object borrow an immutable pointer freezes it and prevents mutation".

@emberian
Copy link
Member

I don't think it was incorrect. The borrow/loan metaphor has it that you create a loan by borrowing. The borrowed object has no say in the matter. I think the current phrasing is fine.

@brian-dawn
Copy link
Contributor Author

By incorrect usage I mean that in English you cannot "borrow to" someone, you "borrow from" and "lend to". When I read these docs my brain inserted "from" and ignored that it said "to" because I had read "borrowing" which led to confusion.

bors added a commit that referenced this pull request Oct 31, 2013
To keep consistency with the word "borrowing" I suppose an alternate way to write this could be "Having an object borrow an immutable pointer freezes it and prevents mutation".
@bors bors closed this Oct 31, 2013
@bors bors merged commit 986fb3c into rust-lang:master Oct 31, 2013
@huonw
Copy link
Member

huonw commented Oct 31, 2013

... I feel like this is incorrect. The action of borrowing a pointer to an object is external (i.e. &x is going to the object x and borrowing a reference, where as lending would be something like x.lend_reference(|ptr| { /* use ptr */ })).

@huonw
Copy link
Member

huonw commented Oct 31, 2013

I guess changing it to "Borrowing an immutable reference from an object" would be ok, but I don't think that quite captures the behaviour like "borrowing an immutable reference to an object" does. I think the confusion here is because the "to" is attached to the "pointer", i.e. it is what the pointer points to, not associated with the word "borrowing".

One could even phrase it as "Borrowing an immutable reference (which points to some object) freezes that object".

@huonw
Copy link
Member

huonw commented Oct 31, 2013

To put it another way, with the lending wording, it sounds like the immutable reference is being placed in some object, and somehow that makes that object immutable, which is false. Specifically, it makes it sound like the following is the behaviour of &:

struct Foo<'self> { x: Option<&'self int> }

let mut x = 1;
let mut y = Foo { x: None };
y.x = Some(&x); // `y` is frozen, but `x` isn't.

whereas the opposite is true, only x is frozen in the above code.

@brian-dawn
Copy link
Contributor Author

I didn't mean to start a big discussion on this matter, but if someone was confused by the language of the tutorial (like the "to" being attached to the pointer, which I'm still not sure I understand) wouldn't that imply that maybe the language was wrong?

I don't know Rust well enough to ascertain what the best method of saying it is, but I still feel like "borrowing [...] to" is not very obvious, nor is it correct English. What does it mean? "lending to" or "borrowing from" because it feels like there is a mistake there, and as a newbie I had to try to decode what it meant grammatically. Documentation should never have to be interpreted in such a way.

I guess I am confused why "lending" implies anything different than "borrowing" considering they mean the same thing you just choose one based on the direction, to vs from. If I am misunderstanding my apologies.

@huonw
Copy link
Member

huonw commented Nov 1, 2013

I agree 100% that it should be changed; I just don't think this change is correct, especially since it makes it more confusing about what exactly is getting frozen (is the the place that is storing the reference, or the thing that the reference points to?).

Maybe it could be changed to "If one takes an immutable reference to an object, then that object is frozen and mutation is prevented." which removes the lending/borrowing confusion.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 12, 2023
…or` loop.

Reading the documentation for the lint, one could expect that the lint works in all cases that `X == Y`. This is false.

While the lint was updated, the documentation wasn't.

More information about the `N..N` problem in rust-lang#5689 and rust-lang#5628
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 12, 2023
…dswij

[rust-lang#10167] Clarify that the lint only works if x eq. y in a `for` loop.

Reading the documentation for the lint, one could expect that the lint works in all cases that `X == Y`. This is false.

While the lint was updated, the documentation wasn't.

More information about the `N..N` problem in rust-lang#5689 and rust-lang#5628

---

Fixes rust-lang#10167
changelog: [`reversed_empty_ranges`]: Update and clarify documentation
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.

4 participants