-
Notifications
You must be signed in to change notification settings - Fork 13.3k
MIR-borrowck: paths off of statics should not be borrow-checked #45129
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
Comments
I'm taking a look at this. |
Example test: struct Foo { x: usize }
static mut SFOO : Foo = Foo{x: 23 };
impl Foo {
fn x(&mut self) -> &mut usize { &mut self.x }
}
fn main() {
unsafe {
let x = SFOO.x();
SFOO.x += 1; // ?
*x += 1;
}
} This does indeed pass (for better or worse...) in AST-based borrowck. |
I think we should at least warn about this scenario. We could do this by looking at the borrow path during the access checks to see if it was a borrow of a static. |
After some discussion on gitter, decided that we should leave warning for later consideration, and just match AST borrowck in this case for now. This is not a bug fix to AST-borrowck, no need to deviate right now. |
Note for those reading this bug in future: the example test written in above comment is actually UB, because it is creating two simultaneous |
Paths off of statics should not be borrow-checked, as they already require
unsafe
. But currently MIR-borrowck is flagging errors for them, while AST-borrowck lets them through without complaint.(Spawned off of #44985 (review))
The text was updated successfully, but these errors were encountered: