diff options
| author | mojave2 <chenchen145@huawei.com> | 2023-09-17 19:44:25 +0800 |
|---|---|---|
| committer | mojave2 <chenchen145@huawei.com> | 2023-09-17 19:44:25 +0800 |
| commit | 3665a4102bce2cd6b09a7aea1b405cc640e076d8 (patch) | |
| tree | 281c57e5c9ddbee9242c3c87ece4c13a7c90c5cf | |
| parent | f54275f20fb4aa20e28e6f082fac8cfc044965a4 (diff) | |
| download | rust-3665a4102bce2cd6b09a7aea1b405cc640e076d8.tar.gz rust-3665a4102bce2cd6b09a7aea1b405cc640e076d8.zip | |
fix ICE by `u64::try_from(<u128>)`
| -rw-r--r-- | clippy_lints/src/casts/cast_possible_truncation.rs | 2 | ||||
| -rw-r--r-- | tests/ui/cast.rs | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 84b99ad5c24..f99a51e2b88 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -44,7 +44,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b .unwrap_or(u64::max_value()) .min(apply_reductions(cx, nbits, left, signed)), BinOpKind::Shr => apply_reductions(cx, nbits, left, signed) - .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).expect("shift too high"))), + .saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())), _ => nbits, }, ExprKind::MethodCall(method, left, [right], _) => { diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index d0a092093f3..1ca18170f8a 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -361,3 +361,7 @@ fn avoid_subtract_overflow(q: u32) { //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; } + +fn issue11426() { + (&42u8 >> 0xa9008fb6c9d81e42_0e25730562a601c8_u128) as usize; +} |
