Skip to content

2021 edition: Unsafe block not detected when accessing a union field inside a closure #87378

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

Closed
lazytype opened this issue Jul 22, 2021 · 2 comments · Fixed by #87469
Closed
Assignees
Labels
A-edition-2021 Area: The 2021 edition C-bug Category: This is a bug.

Comments

@lazytype
Copy link

lazytype commented Jul 22, 2021

Code

I tried this code:

union Union {
    value: u64,
}

fn main() {
    let u = Union { value: 42 };
    
    || {
       unsafe { u.value }
    };
}

I expected to see this happen: no error

Instead, this happened: error[E0133]: access to union field is unsafe and requires unsafe function or block

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=091d060959b30415131533f2e6d93f71

Version it worked on

rustc 1.55.0-nightly 2018 edition
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=091d060959b30415131533f2e6d93f71

Version with regression

rustc 1.55.0-nightly 2021 edition
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=091d060959b30415131533f2e6d93f71

@lazytype lazytype added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jul 22, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 22, 2021
@wesleywiser wesleywiser added the A-edition-2021 Area: The 2021 edition label Jul 22, 2021
@jyn514 jyn514 removed the regression-untriaged Untriaged performance or correctness regression. label Jul 22, 2021
@jyn514 jyn514 changed the title Unsafe block not detected when accessing a union field inside a closure 2021 edition: Unsafe block not detected when accessing a union field inside a closure Jul 22, 2021
@nikomatsakis
Copy link
Contributor

cc @rust-lang/wg-rfc-2229

@arora-aman
Copy link
Member

@rustbot claim

@jyn514 jyn514 removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 23, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 26, 2021
2229: Don't capture preicese paths on top of a union

- Accessing fields of a union require unsafe block
- As part of 2229 we don't allow precision where we need an unsafe block
to capture.

Fixes: rust-lang#87378

r? `@nikomatsakis`
@bors bors closed this as completed in 75edcd9 Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2021 Area: The 2021 edition C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants