Skip to content

Commit a0ad661

Browse files
committed
Rollup merge of rust-lang#37056 - Mark-Simulacrum:fix-bool-comparison, r=bluss
Add comparison operators to boolean const eval. I think it might be worth adding tests here, but since I don't know how or where to do that, I have not done so yet. Willing to do so if asked and given an explanation as to how. Fixes rust-lang#37047.
2 parents 5ac7f4f + f9c73ad commit a0ad661

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/librustc_const_eval/eval.rs

+4
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
732732
hir::BiBitOr => a | b,
733733
hir::BiEq => a == b,
734734
hir::BiNe => a != b,
735+
hir::BiLt => a < b,
736+
hir::BiLe => a <= b,
737+
hir::BiGe => a >= b,
738+
hir::BiGt => a > b,
735739
_ => signal!(e, InvalidOpForBools(op.node)),
736740
})
737741
}

src/test/run-pass/const-err.rs

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ const X: *const u8 = b"" as _;
1717
fn main() {
1818
let _ = ((-1 as i8) << 8 - 1) as f32;
1919
let _ = 0u8 as char;
20+
let _ = true > false;
21+
let _ = true >= false;
22+
let _ = true < false;
23+
let _ = true >= false;
2024
}

0 commit comments

Comments
 (0)