Skip to content

Allow &raw [mut | const] for union field #19867

Merged
Veykril merged 1 commit into
rust-lang:masterfrom
Kivooeo:unsafegate
Sep 28, 2025
Merged

Allow &raw [mut | const] for union field #19867
Veykril merged 1 commit into
rust-lang:masterfrom
Kivooeo:unsafegate

Conversation

@Kivooeo

@Kivooeo Kivooeo commented May 26, 2025

Copy link
Copy Markdown
Member

follow up rust-lang/rust#141469

i didn’t test it locally, just relying on the tests for now. also not really familiar with rust-analyzer code, but tried my best

if there’s anything that can be improved, feel free to point it out

r? @Veykril

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2025
@Kivooeo
Kivooeo force-pushed the unsafegate branch 5 times, most recently from bb653dd to 85227f4 Compare May 26, 2025 12:35

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should wait with this until the rust-lang/rust PR is merged, or at least the FCP completes.

Comment thread crates/hir-ty/src/diagnostics/unsafe_check.rs Outdated
@Kivooeo

Kivooeo commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

I decided to stick with separate methods because of I dont know how to rewrite this without recursion, and, I believe, it should be fine like this (not inlined) even if we used this methods just for this single case

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I feel like it'll be better (and more performant) if we'll just unconditionally call walk_field_chain_for_raw_ptr().

Comment thread crates/ide-diagnostics/src/handlers/missing_unsafe.rs Outdated
@Kivooeo

Kivooeo commented Sep 20, 2025

Copy link
Copy Markdown
Member Author

@rustbot ready

@Veykril
Veykril enabled auto-merge September 28, 2025 11:54
@Veykril
Veykril added this pull request to the merge queue Sep 28, 2025
Merged via the queue into rust-lang:master with commit 5c0b555 Sep 28, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 28, 2025
…iler-errors

Allow `&raw [mut | const]` for union field in safe code

fixes rust-lang#141264

r? `@Veykril`

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 28, 2025
…iler-errors

Allow `&raw [mut | const]` for union field in safe code

fixes rust-lang#141264

r? ``@Veykril``

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
rust-timer added a commit to rust-lang/rust that referenced this pull request Sep 28, 2025
Rollup merge of #141469 - Kivooeo:remove-usnsafegate, r=compiler-errors

Allow `&raw [mut | const]` for union field in safe code

fixes #141264

r? ``@Veykril``

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
github-actions Bot pushed a commit to rust-lang/miri that referenced this pull request Sep 29, 2025
Allow `&raw [mut | const]` for union field in safe code

fixes rust-lang/rust#141264

r? ``@Veykril``

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
@lnicola

lnicola commented Sep 30, 2025

Copy link
Copy Markdown
Member

changelog fix (first contribution) allow &raw [mut | const] for union fields in safe code

Kobzol pushed a commit to Kobzol/rustc_codegen_gcc that referenced this pull request Dec 21, 2025
Allow `&raw [mut | const]` for union field in safe code

fixes rust-lang/rust#141264

r? ``@Veykril``

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants