Don't allow negative unsigned literals
This commit is contained in:
parent
5e5567993d
commit
a7ce15d361
1 changed files with 5 additions and 1 deletions
|
|
@ -55,7 +55,11 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||
let bytes = data as &[u8];
|
||||
ty::ValTree::from_raw_bytes(tcx, bytes)
|
||||
}
|
||||
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
|
||||
(ast::LitKind::Int(n, _), ty::Uint(_)) if !neg => {
|
||||
let scalar_int = trunc(n.get());
|
||||
ty::ValTree::from_scalar_int(scalar_int)
|
||||
}
|
||||
(ast::LitKind::Int(n, _), ty::Int(_)) => {
|
||||
let scalar_int =
|
||||
trunc(if neg { (n.get() as i128).overflowing_neg().0 as u128 } else { n.get() });
|
||||
ty::ValTree::from_scalar_int(scalar_int)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue