Skip to content

Commit 4022591

Browse files
committed
Auto merge of #11517 - mojave2:issue-11426, r=Alexendoo
fix ICE by `u64::try_from(<u128>)` changelog: Fix the ICE in [`cast_possible_truncation`], when the `Shr` bits is larger than `u64::MAX` fix #11426
2 parents ea16f81 + 3665a41 commit 4022591

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

clippy_lints/src/casts/cast_possible_truncation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
4444
.unwrap_or(u64::max_value())
4545
.min(apply_reductions(cx, nbits, left, signed)),
4646
BinOpKind::Shr => apply_reductions(cx, nbits, left, signed)
47-
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).expect("shift too high"))),
47+
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())),
4848
_ => nbits,
4949
},
5050
ExprKind::MethodCall(method, left, [right], _) => {

tests/ui/cast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,7 @@ fn avoid_subtract_overflow(q: u32) {
361361
//~^ ERROR: casting `u32` to `u8` may truncate the value
362362
c as usize;
363363
}
364+
365+
fn issue11426() {
366+
(&42u8 >> 0xa9008fb6c9d81e42_0e25730562a601c8_u128) as usize;
367+
}

0 commit comments

Comments
 (0)