-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Remove allowing static_mut_refs lint #131439
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,8 +288,6 @@ cfg_if::cfg_if! { | |
} | ||
} | ||
|
||
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint | ||
#[allow(static_mut_refs)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check whether the library builds on stage 2? This should definitely still trigger the lint here since we haven't (afaict?) changed anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found no reference used in this function's body, so I removed it and just try to build on stage 2 on my linux device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried
|
||
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { | ||
use core::intrinsics::atomic_store_seqcst; | ||
|
||
|
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 feel like neither of these fixes the underlying issue that we likely shouldn't be using a static mut here... It just side-steps the lint by using raw pointers which for some reason we don't lint on.
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.
You are right. But I didn't see other ways to implement this. And we can guarantee that using raw pointers here is correct, right?
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.
We don't lint against raw pointers because that's often what we're trying to push people toward (among other options). We lint against references because it's easier to get that wrong without realizing. E.g., it's fine to have aliasing pointers to some data as long as you're careful to not race the accesses, but it's never fine to have aliasing live mutable references. But taking potentially long-lived references to mutable statics makes it really easy to do that accidentally.
To make this particular case safer, I'd probably move
STACK_TRACE
into thatlet stack = unsafe { .. }
block. Then it can't be directly accessed later while the reference to it via that slice is live, which is the main danger.Probably I'd also expect this function to be
unsafe extern "C" fn ..
since there's a safety requirement here that must be upheld by callers (the function is not reentrant). Not sure if there's some practical reason preventing that here.Assuming that safety invariant is upheld, the use of
static mut
here, as revised, seems fine to me in the context of what we were trying to achieve as a lang matter. This is plausibly the kind of use case that argues against deprecatingstatic mut
entirely (see #53639).