Skip to content

Commit d45ed75

Browse files
committed
Auto merge of rust-lang#90040 - nbdd0121:issue-90038, r=oli-obk
Fix wrong niche calculation when 2+ niches are placed at the start When the niche is at the start, existing code incorrectly uses 1 instead of count for subtraction. Fix rust-lang#90038 `@rustbot` label: T-compiler
2 parents 2f22e63 + 7dbd5bb commit d45ed75

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/rustc_target/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ impl Niche {
11171117
// In practice this means that enums with `count > 1` are unlikely to claim niche zero, since they have to fit perfectly.
11181118
// If niche zero is already reserved, the selection of bounds are of little interest.
11191119
let move_start = |v: WrappingRange| {
1120-
let start = v.start.wrapping_sub(1) & max_value;
1120+
let start = v.start.wrapping_sub(count) & max_value;
11211121
Some((start, Scalar { value, valid_range: v.with_start(start) }))
11221122
};
11231123
let move_end = |v: WrappingRange| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
#[repr(u32)]
4+
pub enum Foo {
5+
// Greater than or equal to 2
6+
A = 2,
7+
}
8+
9+
pub enum Bar {
10+
A(Foo),
11+
// More than two const variants
12+
B,
13+
C,
14+
}
15+
16+
fn main() {
17+
match Bar::A(Foo::A) {
18+
Bar::A(_) => (),
19+
_ => unreachable!(),
20+
}
21+
}

0 commit comments

Comments
 (0)