1
1
use 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 } ;
6
3
use rustc_lint:: LateContext ;
7
4
use rustc_middle:: ty:: { cast:: CastKind , Ty } ;
8
5
use rustc_span:: DUMMY_SP ;
9
6
10
7
// check if the component types of the transmuted collection and the result have different ABI,
11
8
// 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 {
13
14
if let Ok ( from) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , from)
14
15
&& let Ok ( to) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , to)
15
16
&& 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>(
32
33
from_ty : Ty < ' tcx > ,
33
34
to_ty : Ty < ' tcx > ,
34
35
) -> bool {
35
- use CastKind :: { AddrPtrCast , ArrayPtrCast , FnPtrAddrCast , FnPtrPtrCast , PtrAddrCast , PtrPtrCast } ;
36
+ use CastKind :: {
37
+ AddrPtrCast , ArrayPtrCast , FnPtrAddrCast , FnPtrPtrCast , PtrAddrCast , PtrPtrCast ,
38
+ } ;
36
39
matches ! (
37
40
check_cast( cx, e, from_ty, to_ty) ,
38
41
Some ( PtrPtrCast | PtrAddrCast | AddrPtrCast | ArrayPtrCast | FnPtrPtrCast | FnPtrAddrCast )
@@ -43,20 +46,22 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
43
46
/// the cast. In certain cases, including some invalid casts from array references
44
47
/// to pointers, this may cause additional errors to be emitted and/or ICE error
45
48
/// 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 > {
47
55
let hir_id = e. hir_id ;
48
56
let local_def_id = hir_id. owner . def_id ;
49
57
50
58
Inherited :: build ( cx. tcx , local_def_id) . enter ( |inherited| {
51
59
let fn_ctxt = FnCtxt :: new ( & inherited, cx. param_env , hir_id) ;
52
60
53
61
// 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" ) ;
58
63
59
- if let CastCheckResult :: Deferred ( check) = cast:: check_cast (
64
+ if let Ok ( check) = cast:: CastCheck :: new (
60
65
& fn_ctxt, e, from_ty, to_ty,
61
66
// We won't show any error to the user, so we don't care what the span is here.
62
67
DUMMY_SP , DUMMY_SP ,
0 commit comments