Skip to content
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

Fix wrong niche calculation when 2+ niches are placed at the start #90040

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ impl Niche {
// In practice this means that enums with `count > 1` are unlikely to claim niche zero, since they have to fit perfectly.
// If niche zero is already reserved, the selection of bounds are of little interest.
let move_start = |v: WrappingRange| {
let start = v.start.wrapping_sub(1) & max_value;
let start = v.start.wrapping_sub(count) & max_value;
Some((start, Scalar { value, valid_range: v.with_start(start) }))
};
let move_end = |v: WrappingRange| {
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/enum-discriminant/issue-90038.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass

#[repr(u32)]
pub enum Foo {
// Greater than or equal to 2
A = 2,
}

pub enum Bar {
A(Foo),
// More than two const variants
B,
C,
}

fn main() {
match Bar::A(Foo::A) {
Bar::A(_) => (),
_ => unreachable!(),
}
}