Skip to content

Commit 3176239

Browse files
authored
Rollup merge of rust-lang#55474 - oli-obk:const_eval_promoted, r=RalfJung
Fix validation false positive Fixes rust-lang#55454 r? @RalfJung
2 parents 0cf957d + 3e9d7e8 commit 3176239

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ pub fn const_eval_provider<'a, 'tcx>(
576576
key.param_env.reveal = Reveal::UserFacing;
577577
match tcx.const_eval(key) {
578578
// try again with reveal all as requested
579-
Err(ErrorHandled::TooGeneric) => {},
579+
Err(ErrorHandled::TooGeneric) => {
580+
// Promoteds should never be "too generic" when getting evaluated.
581+
// They either don't get evaluated, or we are in a monomorphic context
582+
assert!(key.value.promoted.is_none());
583+
},
580584
// dedupliate calls
581585
other => return other,
582586
}

src/librustc_mir/interpret/validity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
303303
let (lo, hi) = layout.valid_range.clone().into_inner();
304304
let max_hi = u128::max_value() >> (128 - size.bits()); // as big as the size fits
305305
assert!(hi <= max_hi);
306-
if lo == 0 && hi == max_hi {
306+
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
307+
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
307308
// Nothing to check
308309
return Ok(());
309310
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/issues/55454
2+
// compile-pass
3+
4+
struct This<T>(T);
5+
6+
const C: This<Option<&i32>> = This(Some(&1));
7+
8+
fn main() {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/issues/55454
2+
// compile-pass
3+
4+
#[derive(PartialEq)]
5+
struct This<T>(T);
6+
7+
fn main() {
8+
This(Some(&1)) == This(Some(&1));
9+
}

0 commit comments

Comments
 (0)