@@ -8,6 +8,7 @@ use if_chain::if_chain;
8
8
use rustc_ast:: { FloatTy , IntTy , LitFloatType , LitIntType , LitKind , UintTy } ;
9
9
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
10
10
use rustc_hir as hir;
11
+ use rustc_hir:: def:: Res ;
11
12
use rustc_hir:: intravisit:: { walk_body, walk_expr, walk_ty, FnKind , NestedVisitorMap , Visitor } ;
12
13
use rustc_hir:: {
13
14
BinOpKind , Block , Body , Expr , ExprKind , FnDecl , FnRetTy , FnSig , GenericArg , GenericBounds , GenericParamKind , HirId ,
@@ -1632,7 +1633,14 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
1632
1633
if expr. span . from_expansion ( ) {
1633
1634
return ;
1634
1635
}
1635
- if let ExprKind :: Cast ( ref ex, _) = expr. kind {
1636
+ if let ExprKind :: Cast ( ref ex, cast_to) = expr. kind {
1637
+ if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = cast_to. kind {
1638
+ if let Res :: Def ( _, def_id) = path. res {
1639
+ if cx. tcx . has_attr ( def_id, sym:: cfg) || cx. tcx . has_attr ( def_id, sym:: cfg_attr) {
1640
+ return ;
1641
+ }
1642
+ }
1643
+ }
1636
1644
let ( cast_from, cast_to) = ( cx. typeck_results ( ) . expr_ty ( ex) , cx. typeck_results ( ) . expr_ty ( expr) ) ;
1637
1645
lint_fn_to_numeric_cast ( cx, expr, ex, cast_from, cast_to) ;
1638
1646
if let Some ( lit) = get_numeric_literal ( ex) {
0 commit comments