-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Consider (https://godbolt.org/z/x39GzMKz4):
#[repr(packed)]
#[derive(PartialEq)]
pub struct Packed(i32);
enum Y {
Foo { id: Packed, },
Bar(i32)
}
fn pred(_: &i32) -> bool {
return true;
}
fn f(x: Y) {
match &x {
Y::Foo { id: Packed(4), .. } => {},
Y::Bar(s) if pred(s) => {},
_ => {}
}
}
This results in an error:
error[E0793]: reference to packed field is unaligned
--> <source>:14:11
|
14 | match &x {
| ^^
|
I don’t really know what the problem is here, but it might be the match on the id
field in the first match arm that triggers the error. Moving Packed(4)
into a local variable works, but if I declare it as a const
variable instead the error resurfaces. Alternatively, removing the Y::Bar
match arm for some reason also makes the error go away.
This currently errors on nightly and some testing on godbolt shows that this code results in an error since Rust 1.62. Before that, we still get the same diagnostic; it’s just treated as a warning instead.
Metadata
Metadata
Assignees
Labels
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.