-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Stop generating an intermediate deref when taking references to statics #77020
Conversation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bad. We no longer catch this pre-monomorphization even though it has&mut
. You'll need to handle this case somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but I see no way to distinguish this from the &mut STDERR_BUFFER_SPACE
that we'd see for just let x = STDERR_BUFFER_SPACE
without going all the way to having custom Rvalue
s for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's always the HIR const-checker I guess 😆. I haven't got around to removing it yet.
As written, this PR allows stuff like let x = &mut STATIC_MUT
in a const-context on stable, so you'll need to handle it somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately
struct Foo {
field: *mut i32
}
static mut FOO: Foo = Foo {
field: &mut [42] as *mut [i32] as *mut i32,
};
is stable, so I can't just ban mutable references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yea, I gottaa figure something out how to not expose it even more...
That's a very different issue that the last PR with a similar title (#76982)? I am somewhat confused. I assume this is supposed to resolve #74840? Also could you describe at a high level what the approach to solving #74840 is, compared to #76982? That would be easier than trying to reverse engineer that from the PR.^^ |
I'm trying to get rid of our reliance on the This is not related to #74840 anymore, as that issue is now solely about making uninhabited extern types forbidden via a future incompat lint. This PR takes |
I have explored the design space around We're in a fairly good sweet spot with these That said, we can still do the active PR once mutable references and dereferencing becomes legal in statics |
Okay, I opened #77096 for the problems the current static handling is causing. |
r? @RalfJung @ecstatic-morse
So... the motivation for this change was to make things less fragile. There's still work to be done if we really want to go all the way to having more
Rvalue
s for different ways to interact with statics and fully stop relying on metadata of locals for soundness.fixes #54366