diff options
| author | Gary Guo <gary@garyguo.net> | 2021-10-19 06:42:44 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2021-10-19 06:43:33 +0100 |
| commit | 7dbd5bb0bd655abe3f4de232f9ccb50db3843d42 (patch) | |
| tree | 03d43dcb536014a61dcd5bf651edb590230d9237 | |
| parent | cd8b56f528631b128f36605b28ae06e36377dc68 (diff) | |
| download | rust-7dbd5bb0bd655abe3f4de232f9ccb50db3843d42.tar.gz rust-7dbd5bb0bd655abe3f4de232f9ccb50db3843d42.zip | |
Fix issue 90038
| -rw-r--r-- | compiler/rustc_target/src/abi/mod.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/enum-discriminant/issue-90038.rs | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 61607159208..a57ad8f2bbd 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -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| { diff --git a/src/test/ui/enum-discriminant/issue-90038.rs b/src/test/ui/enum-discriminant/issue-90038.rs new file mode 100644 index 00000000000..5e98eccd9b5 --- /dev/null +++ b/src/test/ui/enum-discriminant/issue-90038.rs @@ -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!(), + } +} |
