-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make assignments to Copy
union fields safe
#42083
Conversation
src/librustc/middle/effect.rs
Outdated
let field_ty = self.tables.expr_ty_adjusted(lhs); | ||
let owner_def_id = self.tcx.hir.body_owner_def_id(self.body_id); | ||
let param_env = self.tcx.parameter_environment(owner_def_id); | ||
if field_ty.moves_by_default(self.tcx, ¶m_env, field.span) { |
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.
Is there a way to query "current parameter environment" or "current body id" without keeping them in the visitor, like I did here?
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.
Not at present.
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 what I would rather do is to have a loop over all the bodies and instantiate a distinct visitor per body, with just the appropriate tables etc. This visitor would have to walk up to find out contextual information though (since closures, at least, inherit their "unsafety" from their parents at present.))
I think @nikomatsakis is out today, but we'll make sure he gets around to this in the near future! |
ping @nikomatsakis, are you back from PTO? have some more reviews! |
@bors r+ |
📌 Commit 59b65b3 has been approved by |
…akis Make assignments to `Copy` union fields safe This is an accompanying PR to PR rust-lang#42068 stabilizing FFI unions. This was first proposed in rust-lang#32836 (comment), see subsequent comments as well. Assignments to `Copy` union fields do not read any data from the union and are [equivalent](rust-lang#32836 (comment)) to whole union assignments, which are safe, so they should be safe as well. This removes a significant number of "false positive" unsafe blocks, in code dealing with FFI unions in particular. It desirable to make this change now, together with stabilization of FFI unions, because now it affecfts only unstable code, but later it will cause warnings/errors caused by `unused_unsafe` lint in stable code. cc rust-lang#32836 r? @nikomatsakis
…akis Make assignments to `Copy` union fields safe This is an accompanying PR to PR rust-lang#42068 stabilizing FFI unions. This was first proposed in rust-lang#32836 (comment), see subsequent comments as well. Assignments to `Copy` union fields do not read any data from the union and are [equivalent](rust-lang#32836 (comment)) to whole union assignments, which are safe, so they should be safe as well. This removes a significant number of "false positive" unsafe blocks, in code dealing with FFI unions in particular. It desirable to make this change now, together with stabilization of FFI unions, because now it affecfts only unstable code, but later it will cause warnings/errors caused by `unused_unsafe` lint in stable code. cc rust-lang#32836 r? @nikomatsakis
I suspect that this will fail at some point, the previous rollup failed with, which looks suspiciously like it comes from this PR; possibly a conflict with another PR that landed -- I seem to recall @nikomatsakis landing something that renamed
|
@bors r- |
Rebased. |
📌 Commit fa13cd3 has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit fa13cd3 has been approved by |
Make assignments to `Copy` union fields safe This is an accompanying PR to PR #42068 stabilizing FFI unions. This was first proposed in #32836 (comment), see subsequent comments as well. Assignments to `Copy` union fields do not read any data from the union and are [equivalent](#32836 (comment)) to whole union assignments, which are safe, so they should be safe as well. This removes a significant number of "false positive" unsafe blocks, in code dealing with FFI unions in particular. It desirable to make this change now, together with stabilization of FFI unions, because now it affecfts only unstable code, but later it will cause warnings/errors caused by `unused_unsafe` lint in stable code. cc #32836 r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Stabilize unions with `Copy` fields and no destructor What else is needed: - [x] Documentation (rust-lang/reference#57). - [x] Making assignments to `Copy` union fields safe (#42083). - [ ] Backport? (The "stabilization decision" is from [Apr 13](#32836 (comment)), it's just this PR is late.) cc #32836 r? @nikomatsakis
This is an accompanying PR to PR #42068 stabilizing FFI unions.
This was first proposed in #32836 (comment), see subsequent comments as well.
Assignments to
Copy
union fields do not read any data from the union and are equivalent to whole union assignments, which are safe, so they should be safe as well. This removes a significant number of "false positive" unsafe blocks, in code dealing with FFI unions in particular.It desirable to make this change now, together with stabilization of FFI unions, because now it affecfts only unstable code, but later it will cause warnings/errors caused by
unused_unsafe
lint in stable code.cc #32836
r? @nikomatsakis