11use rustc_hir:: Expr ;
2- use rustc_hir_analysis:: check:: {
3- cast:: { self , CastCheckResult } ,
4- FnCtxt , Inherited ,
5- } ;
2+ use rustc_hir_analysis:: check:: { cast, FnCtxt , Inherited } ;
63use rustc_lint:: LateContext ;
74use rustc_middle:: ty:: { cast:: CastKind , Ty } ;
85use rustc_span:: DUMMY_SP ;
96
107// check if the component types of the transmuted collection and the result have different ABI,
118// size or alignment
12- pub ( super ) fn is_layout_incompatible < ' tcx > ( cx : & LateContext < ' tcx > , from : Ty < ' tcx > , to : Ty < ' tcx > ) -> bool {
9+ pub ( super ) fn is_layout_incompatible < ' tcx > (
10+ cx : & LateContext < ' tcx > ,
11+ from : Ty < ' tcx > ,
12+ to : Ty < ' tcx > ,
13+ ) -> bool {
1314 if let Ok ( from) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , from)
1415 && let Ok ( to) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , to)
1516 && let Ok ( from_layout) = cx. tcx . layout_of ( cx. param_env . and ( from) )
@@ -32,7 +33,9 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
3233 from_ty : Ty < ' tcx > ,
3334 to_ty : Ty < ' tcx > ,
3435) -> bool {
35- use CastKind :: { AddrPtrCast , ArrayPtrCast , FnPtrAddrCast , FnPtrPtrCast , PtrAddrCast , PtrPtrCast } ;
36+ use CastKind :: {
37+ AddrPtrCast , ArrayPtrCast , FnPtrAddrCast , FnPtrPtrCast , PtrAddrCast , PtrPtrCast ,
38+ } ;
3639 matches ! (
3740 check_cast( cx, e, from_ty, to_ty) ,
3841 Some ( PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast )
@@ -43,20 +46,22 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
4346/// the cast. In certain cases, including some invalid casts from array references
4447/// to pointers, this may cause additional errors to be emitted and/or ICE error
4548/// messages. This function will panic if that occurs.
46- fn check_cast < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > , from_ty : Ty < ' tcx > , to_ty : Ty < ' tcx > ) -> Option < CastKind > {
49+ fn check_cast < ' tcx > (
50+ cx : & LateContext < ' tcx > ,
51+ e : & ' tcx Expr < ' _ > ,
52+ from_ty : Ty < ' tcx > ,
53+ to_ty : Ty < ' tcx > ,
54+ ) -> Option < CastKind > {
4755 let hir_id = e. hir_id ;
4856 let local_def_id = hir_id. owner . def_id ;
4957
5058 Inherited :: build ( cx. tcx , local_def_id) . enter ( |inherited| {
5159 let fn_ctxt = FnCtxt :: new ( & inherited, cx. param_env , hir_id) ;
5260
5361 // If we already have errors, we can't be sure we can pointer cast.
54- assert ! (
55- !fn_ctxt. errors_reported_since_creation( ) ,
56- "Newly created FnCtxt contained errors"
57- ) ;
62+ assert ! ( !fn_ctxt. errors_reported_since_creation( ) , "Newly created FnCtxt contained errors" ) ;
5863
59- if let CastCheckResult :: Deferred ( check) = cast:: check_cast (
64+ if let Ok ( check) = cast:: CastCheck :: new (
6065 & fn_ctxt, e, from_ty, to_ty,
6166 // We won't show any error to the user, so we don't care what the span is here.
6267 DUMMY_SP , DUMMY_SP ,
0 commit comments