-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Allow &raw [mut | const]
for union field in safe
#141469
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
base: master
Are you sure you want to change the base?
Conversation
Failed to set assignee to
|
cc @RalfJung |
&raw [mut | const]
for union field in safe
Uh, the unsafety checker is not actually code I know very well, sorry. |
The macros just expand to |
This comment has been minimized.
This comment has been minimized.
I will debug this later today but this is very weird |
b006128
to
43892d3
Compare
This comment has been minimized.
This comment has been minimized.
b60d3ff
to
fc03435
Compare
This comment has been minimized.
This comment has been minimized.
9ccf35d
to
cde9fa0
Compare
@rustbot ready |
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.
As was brought up in the zulip thread, there should probably be a test for raw borrowing a union field in a closure capture like || &raw u2.a
or so. Iirc the question there was whether the closure captures u2
(which would be fine), or u2.a
(which would itself still be unsafe as its a read, be it a borrow or move/copy).
rust-analyzer has its own unsafety check here: https://github.com/rust-lang/rust/blob/46264e6dfd8f0bacae05c520b4617e054d6ef990/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs with tests living here https://github.com/rust-lang/rust/blob/46264e6dfd8f0bacae05c520b4617e054d6ef990/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs If you can look into that together with this PR that would be appreciated, but if not that's also okay (iirc you can't really run specific tests for r-a in the rust repo yet, correct me if I am wrong @jieyouxu) |
In current state this is not emitting error, but, I'm unsure if it should, this is pretty tricky quesiton I have no answer for, this is actually my first interaction with unions :)
Sure! I will check it, would it be better to open PR (if I found a way to fix this or just issue if not) in RA's repo? |
It would probably be easier to work in the rust-analyzer repo directly yes |
I will try to found out what exactly closure captures later today, I guess that MIR or HIR could show me this information |
@lcnr @compiler-errors do you know the intended spec for closure captures around unions? We never do field capturing there, do we? |
Well, if I get this right, this capturing all union bb0: {
_1 = U { a: const 42_i32 };
_3 = &_1;
_2 = {closure@/Users/meow/projects/wtf/src/main.rs:10:13: 10:15} { u: move _3 };
return;
} |
We truncate precise captures of union fields to the whole union here: rust/compiler/rustc_hir_typeck/src/upvar.rs Lines 2155 to 2157 in 95a2212
|
@compiler-errors, hope you dont mind the ping! the needs-fcp label is a bit unclear to me, because it feels like we are waiting for something, but im not sure what exactly id really appreaciate it if you could clarify this when you have a momemtn |
You're not wrong. I haven't hooked up main r-a tests yet because I'm waiting for the staging changes (the stage 0 redesign) to avoid making that effort more complicated. |
Hi @compiler-errors, I think this is ready for another review (or perhaps to start a T-lang FCP?) when you get a chance. Thanks! |
This comment has been minimized.
This comment has been minimized.
1ae2d38
to
c49cf70
Compare
This comment has been minimized.
This comment has been minimized.
c49cf70
to
630e9c0
Compare
The Miri subtree was changed cc @rust-lang/miri This PR modifies If appropriate, please update |
630e9c0
to
9e9ec8d
Compare
9e9ec8d
to
49ba112
Compare
@@ -25,7 +25,7 @@ impl<T, const N: usize> RawSmallVec<T, N> { | |||
} | |||
|
|||
const fn as_mut_ptr_inline(&mut self) -> *mut T { | |||
(unsafe { &raw mut self.inline }) as *mut T | |||
&raw mut self.inline as *mut T | |||
} | |||
|
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.
changed because it is not an unsafe operation anymore
fixes #141264
r? @Veykril
Unresolved questions:
&raw
context) (Allow&raw [mut | const]
for union field rust-analyzer#19867)addr_of!
andaddr_of_mut!
as well? In current version they both (&raw
andaddr_of!
) are allowed (They are the same)