Bug
In compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs:421-424, the niche discriminant range is computed using valid_range.start.min(valid_range.end) and .max(). WrappingRange can have start > end to represent a wrapping range (e.g., start=200, end=100 means {200..=255, 0..=100}).
Using .min()/.max() converts wrapping range (200, 100) into contiguous range (100, 200), which is the complement of the intended range. The CPP-like debuginfo path emits these as DISCR_BEGIN/DISCR_END for NatVis's is_in_range function, which already handles wrapping correctly. After min/max, the active variant determination is inverted.
Impact
For niche-encoded enums with wrapping valid ranges on MSVC targets (CPP-like debuginfo), the debugger identifies the wrong active variant. Currently latent because wrapping niche ranges are rare with current Rust types, but could manifest with more complex niche optimization.
Fix
Use valid_range.start and valid_range.end directly instead of .min()/.max(), preserving the wrapping semantics that NatVis already handles.
Bug
In
compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs:421-424, the niche discriminant range is computed usingvalid_range.start.min(valid_range.end)and.max().WrappingRangecan havestart > endto represent a wrapping range (e.g.,start=200, end=100means{200..=255, 0..=100}).Using
.min()/.max()converts wrapping range(200, 100)into contiguous range(100, 200), which is the complement of the intended range. The CPP-like debuginfo path emits these asDISCR_BEGIN/DISCR_ENDfor NatVis'sis_in_rangefunction, which already handles wrapping correctly. After min/max, the active variant determination is inverted.Impact
For niche-encoded enums with wrapping valid ranges on MSVC targets (CPP-like debuginfo), the debugger identifies the wrong active variant. Currently latent because wrapping niche ranges are rare with current Rust types, but could manifest with more complex niche optimization.
Fix
Use
valid_range.startandvalid_range.enddirectly instead of.min()/.max(), preserving the wrapping semantics that NatVis already handles.