@@ -8,6 +8,7 @@ use if_chain::if_chain;
88use rustc_ast:: { FloatTy , IntTy , LitFloatType , LitIntType , LitKind , UintTy } ;
99use rustc_errors:: { Applicability , DiagnosticBuilder } ;
1010use rustc_hir as hir;
11+ use rustc_hir:: def:: Res ;
1112use rustc_hir:: intravisit:: { walk_body, walk_expr, walk_ty, FnKind , NestedVisitorMap , Visitor } ;
1213use rustc_hir:: {
1314 BinOpKind , Block , Body , Expr , ExprKind , FnDecl , FnRetTy , FnSig , GenericArg , GenericBounds , GenericParamKind , HirId ,
@@ -1632,7 +1633,14 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
16321633 if expr. span . from_expansion ( ) {
16331634 return ;
16341635 }
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+ }
16361644 let ( cast_from, cast_to) = ( cx. typeck_results ( ) . expr_ty ( ex) , cx. typeck_results ( ) . expr_ty ( expr) ) ;
16371645 lint_fn_to_numeric_cast ( cx, expr, ex, cast_from, cast_to) ;
16381646 if let Some ( lit) = get_numeric_literal ( ex) {
0 commit comments