-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add a static analysis that prevents references to inner mutability only in the trailing expression of a constant #80373
Conversation
This comment has been minimized.
This comment has been minimized.
065f347
to
3519ee3
Compare
This comment has been minimized.
This comment has been minimized.
3519ee3
to
73eb959
Compare
This comment has been minimized.
This comment has been minimized.
nevermind, this scheme can't work. Rewriting the |
…k multiple levels of qualification
…ly in the trailing expression of a constant
73eb959
to
b27158d
Compare
cc @felix91gr @camelid (do we need a dataflow working group? 😆 ) I rewrote the |
@@ -33,7 +33,7 @@ pub trait DebugWithContext<C>: Eq + fmt::Debug { | |||
} | |||
|
|||
write!(f, "\u{001f}-")?; | |||
self.fmt_with(ctxt, f) | |||
old.fmt_with(ctxt, f) |
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 a drive-by bugfix
/// The dataflow result type. If it's just qualified/not qualified, then | ||
/// you can just use a `()` (most qualifs do that). But if you need more state, use a | ||
/// custom enum. | ||
type Result: SetChoice + std::fmt::Debug = (); |
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 think I would prefer to use a marker ZST that is individual to each qualif (or even just use the type implementing Qualif
), but since that is a refactoring not necessary for this PR, I think we should not do it here.
pub enum HasMutInteriorBehindRefState { | ||
Yes, | ||
/// As long as we haven't encountered a reference yet, we use this state | ||
/// which is equivalent to the `HasMutInterior` qualif. |
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.
in a follow up PR we can check whether we can get rid of HasMutInterior
and only run this qualif
This comment has been minimized.
This comment has been minimized.
…e, r=RalfJung Allow references to interior mutable data behind a feature gate supercedes rust-lang#80373 by simply not checking for interior mutability on borrows of locals that have `StorageDead` and thus can never be leaked to the final value of the constant tracking issue: rust-lang#80384 r? `@RalfJung`
r? @RalfJung
I also added a feature gate at the same time so we can disable the old check that prevented
I believe we can use the same scheme for mutable references.