better documentation of reborrowing
### tl;dr: Rust documentation is unclear on reborrowing, should explain details in the Reference As it stands, there is only one mention of "reborrowing" in the Reference, [in this section on raw pointers](https://doc.rust-lang.org/stable/reference/types/pointer.html#raw-pointers-const-and-mut). This only refers to reborrowing pointers, and not references, which is important in understanding how Rust handles mutable references (often implicitly reborrowing them instead of moving them). There is also [some documentation on implicit borrowing](https://doc.rust-lang.org/stable/reference/expressions.html?highlight=implicit,borrows#implicit-borrows), but again, this is sparse and does not cover reborrowing in the context of mutable references. A key example of the implicit borrowing which confused me is the following: ```rust fn main() { let mut x = vec![1, 2, 3]; let y = &mut x; let z: &mut Vec<i32> = y; z.push(4); y.push(5); } ``` This code compiles fine, and `x`, as expected, becomes `[1, 2, 3, 4, 5]`. Initially, this code was unclear to me, but I was able to understand how it worked learning about both reborrowing and non lexical lifetimes. However, along the way I became familiar with how little documentation there is on the former. Questions have come up on the topic frequently, like [this Reddit post](https://www.reddit.com/r/rust/comments/46qwjv/why_can_i_use_an_mut_reference_twice/) from 2016, [this post](https://users.rust-lang.org/t/mut-t-seems-to
Posted by soulwa on Apr 4, 2020, 8:57 PM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (EdTech)
Message limit 10000 team edition
[NEW] Data Tiering - Valkey as general data store not just in-memory data store
Info: No releases on google play for now
proposal: spec: sum types based on general interfaces
Users can't use IdPs outside of the ones enumerated by RPs
CLIP Training Code
Implement a Set primitive to complement Dictionary and Array
better documentation of reborrowing
better documentation of reborrowing
### tl;dr: Rust documentation is unclear on reborrowing, should explain details in the Reference As it stands, there is only one mention of "reborrowing" in the Reference, [in this section on raw pointers](https://doc.rust-lang.org/stable/reference/types/pointer.html#raw-pointers-const-and-mut). This only refers to reborrowing pointers, and not references, which is important in understanding how Rust handles mutable references (often implicitly reborrowing them instead of moving them). There is also [some documentation on implicit borrowing](https://doc.rust-lang.org/stable/reference/expressions.html?highlight=implicit,borrows#implicit-borrows), but again, this is sparse and does not cover reborrowing in the context of mutable references. A key example of the implicit borrowing which confused me is the following: ```rust fn main() { let mut x = vec![1, 2, 3]; let y = &mut x; let z: &mut Vec<i32> = y; z.push(4); y.push(5); } ``` This code compiles fine, and `x`, as expected, becomes `[1, 2, 3, 4, 5]`. Initially, this code was unclear to me, but I was able to understand how it worked learning about both reborrowing and non lexical lifetimes. However, along the way I became familiar with how little documentation there is on the former. Questions have come up on the topic frequently, like [this Reddit post](https://www.reddit.com/r/rust/comments/46qwjv/why_can_i_use_an_mut_reference_twice/) from 2016, [this post](https://users.rust-lang.org/t/mut-t-seems-to
Comments (0)
No comments yet. Start the discussion.