mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Auto merge of #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 #90038 `@rustbot` label: T-compiler
This commit is contained in:
commit
d45ed7502a
@ -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| {
|
||||
|
21
src/test/ui/enum-discriminant/issue-90038.rs
Normal file
21
src/test/ui/enum-discriminant/issue-90038.rs
Normal file
@ -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!(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user