Uh oh!
There was an error while loading. Please reload this page.
Handle const-checks for &mut outside of HasMutInterior - #66654
Conversation
rust-highfive
commented
Nov 23, 2019
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb (although I'd like to work on this a bit more, it's not quite ready) |
&mut outside of HasMutInterior&mut outside of HasMutInteriorba0ce7e to
b40d0bdComparebors
commented
Nov 23, 2019
☔ The latest upstream changes (presumably #66640) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
(btw, a doc comment on these methods would be great)
There was a problem hiding this comment.
Can we delay_span_bug just in case?
Centril
commented
Nov 23, 2019
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
I thought this was resolved by simply not having any qualifs on &Cell::new(42).
&T is always Freeze + Copy, regardless of T, so no qualif bits need to be set.
The only reason they were before was for promotion, which is why we split promotion into its own check.
There was a problem hiding this comment.
I think you're right. This means I can clean up a lot more!
c93bb56 to
639aeecComparerust-highfive
commented
Nov 26, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
bors
commented
Nov 27, 2019
☔ The latest upstream changes (presumably #66677) made this pull request unmergeable. Please resolve the merge conflicts. |
639aeec to
4c1f3b1CompareNow, `derived_from_illegal_borrow` is also applied to reborrows, so we don't show the user a useless error message.
4c1f3b1 to
7f35ab6CompareNow that #66640 has been merged, the const-checker treats borrows of a @matthewjasper I'm not quite sure why #66587 didn't cause this test to change. How do I check that |
matthewjasper
commented
Nov 27, 2019
I believe it didn't change in that PR because we don't special case reborrows in |
matthewjasper
commented
Nov 27, 2019
The |
This error code is never emitted, and the contents of this test are identical to that of `E0017.rs`.
7f35ab6 to
7673400Comparerust-highfive
commented
Nov 27, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
They now look the same in the MIR after rust-lang#66587.
This checks `static mut` as well for E0017, and blesses tests now that we emit an error for a mut deref.
7673400 to
846be82Compare@eddyb I had to make a few changes in |
| if let LocalInfo::StaticRef { .. } = decl.local_info { | ||
| return None; | ||
| } | ||
| } |
There was a problem hiding this comment.
@matthewjasper isn't this supposed to use a helper method?
There was a problem hiding this comment.
Yes, there's body.local_decls[local].is_ref_to_static
| | Rvalue::Ref(_, BorrowKind::Shared, ref place) | ||
| | Rvalue::Ref(_, BorrowKind::Shallow, ref place) | ||
| if matches!(place.base, PlaceBase::Static(_)) | ||
| => {} |
There was a problem hiding this comment.
Does this make sense anymore, with the static changes?
There was a problem hiding this comment.
No, this shouldn't be reachable, since the only PlaceBase::Statics are promoted. This maybe should be bug!() for now.
eddyb
commented
Nov 28, 2019
r? @matthewjasper for all the |
matthewjasper
commented
Dec 2, 2019
@bors r=eddyb,matthewjasper |
bors
commented
Dec 2, 2019
📌 Commit ccb4eed has been approved by |
…eddyb,matthewjasper Handle const-checks for `&mut` outside of `HasMutInterior` Addresses [this comment](rust-lang#64470 (comment)). Const-checking relied on `HasMutInterior` to forbid `&mut` in a const context. This was strange because all we needed to do was look for an `Rvalue::Ref` with a certain `BorrowKind`, whereas the `Qualif` traits are specifically meant to get the qualifs for a *value*. This PR removes that logic from `HasMutInterior` and moves it into `check_consts::Validator`. As a result, we can now properly handle qualifications for `static`s, which had to be ignored previously since you can e.g. borrow a static `Cell` from another `static`. We also remove the `derived_from_illegal_borrow` logic, since it is no longer necessary; we give good errors for subsequent reborrows/borrows of illegal borrows.
Rollup of 5 pull requests Successful merges: - #66245 (Conditional compilation for sanitizers) - #66654 (Handle const-checks for `&mut` outside of `HasMutInterior`) - #66822 (libunwind_panic: adjust miri panic hack) - #66827 (handle diverging functions forwarding their return place) - #66834 (rustbuild fixes) Failed merges: r? @ghost
Addresses this comment.
Const-checking relied on
HasMutInteriorto forbid&mutin a const context. This was strange because all we needed to do was look for anRvalue::Refwith a certainBorrowKind, whereas theQualiftraits are specifically meant to get the qualifs for a value. This PR removes that logic fromHasMutInteriorand moves it intocheck_consts::Validator.As a result, we can now properly handle qualifications for
statics, which had to be ignored previously since you can e.g. borrow a staticCellfrom anotherstatic. We also remove thederived_from_illegal_borrowlogic, since it is no longer necessary; we give good errors for subsequent reborrows/borrows of illegal borrows.