Skip to content

Commit defa4af

Browse files
committed
fixup! cast_possible_truncation: don't lint on valid constants
coauthor-by: [email protected]
1 parent 0b62380 commit defa4af

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

clippy_lints/src/casts/cast_possible_truncation.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use clippy_utils::source::snippet;
55
use clippy_utils::sugg::Sugg;
66
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
77
use rustc_errors::{Applicability, Diag, SuggestionStyle};
8+
use rustc_hir as hir;
89
use rustc_hir::def::{DefKind, Res};
9-
use rustc_hir::{BinOpKind, Expr, ExprKind};
10+
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
1011
use rustc_lint::LateContext;
1112
use rustc_middle::ty::{self, FloatTy, Ty};
1213
use rustc_span::symbol::sym;
@@ -80,7 +81,16 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
8081
nbits
8182
}
8283
},
83-
ExprKind::Path(ref _qpath) => get_constant_bits(cx, expr).unwrap_or(nbits),
84+
ExprKind::Path(QPath::Resolved(
85+
None,
86+
hir::Path {
87+
res: Res::Def(DefKind::Const | DefKind::AssocConst, _id),
88+
..
89+
},
90+
)) => {
91+
// `constant()` already checks if a const item is based on `cfg!`.
92+
get_constant_bits(cx, expr).unwrap_or(nbits)
93+
},
8494
// mem::size_of::<T>();
8595
ExprKind::Call(func, []) => {
8696
if let ExprKind::Path(ref func_qpath) = func.kind

0 commit comments

Comments
 (0)