-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Unsafe &mut using RefCell #18566
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Nominating for P-high, this is an obvious soundness issue. |
Minimized: #![feature(tuple_indexing)]
struct MyPtr<'a>(&'a mut uint);
impl<'a> Deref<uint> for MyPtr<'a> {
fn deref<'b>(&'b self) -> &'b uint { self.0 }
}
trait Tr {
fn poke(&self, s: &mut uint);
}
impl Tr for uint {
fn poke(&self, s: &mut uint) {
println!("{}", self);
*s = 2;
println!("{}", self);
}
}
fn main() {
let s = &mut 1u;
MyPtr(s).poke(s);
} It seems that deref doesn't properly create a borrow (I didn't manage to use this to create a regionck violation). The bug remains if I use DerefMut and test takes an |
This is a regression. It errors properly in Rust 0.12 |
I get an error using the latest master. |
believed fixed, needs test. |
Reopening because the test has not yet landed. 😄 |
Oh. My mistake. |
Now it's time to close. 😄 |
minor: Sync from downstream
The following code will compile and run (and fail an assertion), when it should not compile:
Notably, this version properly produces a compile error, recognizing the existing immutable borrow:
The text was updated successfully, but these errors were encountered: