Skip to content

Commit a7ce15d

Browse files
committed
Don't allow negative unsigned literals
1 parent 5e55679 commit a7ce15d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/rustc_mir_build/src/thir/constant.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ pub(crate) fn lit_to_const<'tcx>(
5555
let bytes = data as &[u8];
5656
ty::ValTree::from_raw_bytes(tcx, bytes)
5757
}
58-
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
58+
(ast::LitKind::Int(n, _), ty::Uint(_)) if !neg => {
59+
let scalar_int = trunc(n.get());
60+
ty::ValTree::from_scalar_int(scalar_int)
61+
}
62+
(ast::LitKind::Int(n, _), ty::Int(_)) => {
5963
let scalar_int =
6064
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() });
6165
ty::ValTree::from_scalar_int(scalar_int)

0 commit comments

Comments
 (0)