@@ -8,8 +8,8 @@ use rustc_errors::Applicability;
8
8
use rustc_hir:: { Expr , ExprKind , GenericArg , Mutability , QPath , TyKind , UnOp } ;
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
10
use rustc_middle:: ty:: { self , cast:: CastKind , Ty } ;
11
- use rustc_span:: DUMMY_SP ;
12
11
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12
+ use rustc_span:: DUMMY_SP ;
13
13
use rustc_typeck:: check:: { cast:: CastCheck , FnCtxt , Inherited } ;
14
14
use std:: borrow:: Cow ;
15
15
@@ -698,18 +698,16 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'
698
698
/// a transmute. In certain cases, including some invalid casts from array
699
699
/// references to pointers, this may cause additional errors to be emitted and/or
700
700
/// 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 {
702
707
use CastKind :: * ;
703
708
matches ! (
704
709
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 )
713
711
)
714
712
}
715
713
@@ -722,26 +720,18 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
722
720
let local_def_id = hir_id. owner ;
723
721
724
722
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) ;
730
724
731
725
// If we already have errors, we can't be sure we can pointer cast.
732
726
assert ! (
733
- !fn_ctxt. errors_reported_since_creation( ) ,
727
+ !fn_ctxt. errors_reported_since_creation( ) ,
734
728
"Newly created FnCtxt contained errors"
735
729
) ;
736
730
737
731
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,
742
733
// 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 ,
745
735
) {
746
736
let res = check. do_check ( & fn_ctxt) ;
747
737
0 commit comments