@@ -8,8 +8,8 @@ use rustc_errors::Applicability;
88use rustc_hir:: { Expr , ExprKind , GenericArg , Mutability , QPath , TyKind , UnOp } ;
99use rustc_lint:: { LateContext , LateLintPass } ;
1010use rustc_middle:: ty:: { self , cast:: CastKind , Ty } ;
11- use rustc_span:: DUMMY_SP ;
1211use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12+ use rustc_span:: DUMMY_SP ;
1313use rustc_typeck:: check:: { cast:: CastCheck , FnCtxt , Inherited } ;
1414use std:: borrow:: Cow ;
1515
@@ -698,18 +698,16 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'
698698/// a transmute. In certain cases, including some invalid casts from array
699699/// references to pointers, this may cause additional errors to be emitted and/or
700700/// ICE error messages. This function will panic if that occurs.
701- fn can_be_expressed_as_pointer_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> bool {
701+ fn can_be_expressed_as_pointer_cast < ' tcx > (
702+ cx : & LateContext < ' tcx > ,
703+ e : & ' tcx Expr < ' _ > ,
704+ from_ty : Ty < ' tcx > ,
705+ to_ty : Ty < ' tcx > ,
706+ ) -> bool {
702707 use CastKind :: * ;
703708 matches ! (
704709 check_cast( cx, e, from_ty, to_ty) ,
705- Some (
706- PtrPtrCast
707- | PtrAddrCast
708- | AddrPtrCast
709- | ArrayPtrCast
710- | FnPtrPtrCast
711- | FnPtrAddrCast
712- )
710+ Some ( PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast )
713711 )
714712}
715713
@@ -722,26 +720,18 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
722720 let local_def_id = hir_id. owner ;
723721
724722 Inherited :: build ( cx. tcx , local_def_id) . enter ( |inherited| {
725- let fn_ctxt = FnCtxt :: new (
726- & inherited,
727- cx. param_env ,
728- hir_id
729- ) ;
723+ let fn_ctxt = FnCtxt :: new ( & inherited, cx. param_env , hir_id) ;
730724
731725 // If we already have errors, we can't be sure we can pointer cast.
732726 assert ! (
733- !fn_ctxt. errors_reported_since_creation( ) ,
727+ !fn_ctxt. errors_reported_since_creation( ) ,
734728 "Newly created FnCtxt contained errors"
735729 ) ;
736730
737731 if let Ok ( check) = CastCheck :: new (
738- & fn_ctxt,
739- e,
740- from_ty,
741- to_ty,
732+ & fn_ctxt, e, from_ty, to_ty,
742733 // We won't show any error to the user, so we don't care what the span is here.
743- DUMMY_SP ,
744- DUMMY_SP ,
734+ DUMMY_SP , DUMMY_SP ,
745735 ) {
746736 let res = check. do_check ( & fn_ctxt) ;
747737
0 commit comments