-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Show impl for RefCell, Ref & RefMut #14811
Conversation
This is an interesting direction to take because it means that |
I was trying to stick to the idea that the |
let x = RefCell::new(1);
let y = x.borrow_mut();
// this will fail, due to the `y` mutable borrow stopping
// any other borrow/borrow_mut.
println!("{}", x); |
This would also fail for the same reasons: let mut x = 75u;
let y = &mut x;
println!("{}", x); |
Your example code, @forticulous, does not fail (you can try to run it). @huonw explained why this type is fallible. |
I did just run it on rust-lang.org
|
Note that it is a compilation error, not a runtime error. |
The RefCell version fails at runtime. The type is design as a way to get around the hard limits of |
That's the whole idea of |
Here's maybe a better example (though this would also be my fault) let mut x = Rc::new(75u);
let y = x.make_unique();
println!("{}", x);
error: cannot borrow `x` as immutable because it is also borrowed as mutable |
Yep, that's the idea of I would be very happy to merge |
Yeah, it seems like when you choose to use I can cut out the |
Updated with just |
Show impl for RefCell and friends
feat: Render hover actions for closure captures and sig Also special cases closures for ranged type hover to render the closure hover instead
Show impl for RefCell and friends