@@ -3025,6 +3025,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3025
3025
_ if ty:: type_is_trait ( t_1) => { } ,
3026
3026
3027
3027
_ => {
3028
+ let t_1 = structurally_resolved_type ( fcx, e. span , t_1) ;
3029
+ let t_e = structurally_resolved_type ( fcx, e. span , t_e) ;
3030
+
3028
3031
if ty:: type_is_nil ( t_e) {
3029
3032
fcx. type_error_message ( expr. span , |actual| {
3030
3033
format ! ( "cast from nil: `{}` as `{}`" ,
@@ -3039,21 +3042,14 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3039
3042
} , t_e, None ) ;
3040
3043
}
3041
3044
3042
- let t1 = structurally_resolved_type ( fcx, e. span , t_1) ;
3043
- let te = structurally_resolved_type ( fcx, e. span , t_e) ;
3044
- let t_1_is_scalar = type_is_scalar ( fcx, expr. span , t_1) ;
3045
- let t_1_is_char = type_is_char ( fcx, expr. span , t_1) ;
3046
- let t_1_is_bare_fn = type_is_bare_fn ( fcx, expr. span , t_1) ;
3047
- let t_1_is_float = type_is_floating_point ( fcx,
3048
- expr. span ,
3049
- t_1) ;
3045
+ let t_1_is_scalar = ty:: type_is_scalar ( t_1) ;
3046
+ let t_1_is_char = ty:: type_is_char ( t_1) ;
3047
+ let t_1_is_bare_fn = ty:: type_is_bare_fn ( t_1) ;
3048
+ let t_1_is_float = ty:: type_is_floating_point ( t_1) ;
3050
3049
3051
3050
// casts to scalars other than `char` and `bare fn` are trivial
3052
- let t_1_is_trivial = t_1_is_scalar &&
3053
- !t_1_is_char && !t_1_is_bare_fn;
3054
-
3055
- if type_is_c_like_enum ( fcx, expr. span , t_e) &&
3056
- t_1_is_trivial {
3051
+ let t_1_is_trivial = t_1_is_scalar && !t_1_is_char && !t_1_is_bare_fn;
3052
+ if ty:: type_is_c_like_enum ( fcx. tcx ( ) , t_e) && t_1_is_trivial {
3057
3053
if t_1_is_float {
3058
3054
fcx. type_error_message ( expr. span , |actual| {
3059
3055
format ! ( "illegal cast; cast through an \
@@ -3064,22 +3060,20 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3064
3060
}
3065
3061
// casts from C-like enums are allowed
3066
3062
} else if t_1_is_char {
3067
- let te = fcx. infcx ( ) . resolve_type_vars_if_possible ( te ) ;
3068
- if ty:: get ( te ) . sty != ty:: ty_uint ( ast:: TyU8 ) {
3063
+ let t_e = fcx. infcx ( ) . resolve_type_vars_if_possible ( t_e ) ;
3064
+ if ty:: get ( t_e ) . sty != ty:: ty_uint ( ast:: TyU8 ) {
3069
3065
fcx. type_error_message ( expr. span , |actual| {
3070
3066
format ! ( "only `u8` can be cast as \
3071
3067
`char`, not `{}`", actual)
3072
3068
} , t_e, None ) ;
3073
3069
}
3074
- } else if ty:: get ( t1 ) . sty == ty:: ty_bool {
3070
+ } else if ty:: get ( t_1 ) . sty == ty:: ty_bool {
3075
3071
fcx. tcx ( )
3076
3072
. sess
3077
3073
. span_err ( expr. span ,
3078
3074
"cannot cast as `bool`, compare with \
3079
3075
zero instead") ;
3080
- } else if type_is_region_ptr ( fcx, expr. span , t_e) &&
3081
- type_is_unsafe_ptr ( fcx, expr. span , t_1) {
3082
-
3076
+ } else if ty:: type_is_region_ptr ( t_e) && ty:: type_is_unsafe_ptr ( t_1) {
3083
3077
fn is_vec ( t : ty:: t ) -> bool {
3084
3078
match ty:: get ( t) . sty {
3085
3079
ty:: ty_vec( ..) => true ,
@@ -3112,7 +3106,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3112
3106
3113
3107
/* this cast is only allowed from &[T] to *T or
3114
3108
&T to *T. */
3115
- match ( & ty:: get ( te ) . sty , & ty:: get ( t_1) . sty ) {
3109
+ match ( & ty:: get ( t_e ) . sty , & ty:: get ( t_1) . sty ) {
3116
3110
( & ty:: ty_rptr( _, ty:: mt { ty : mt1, mutbl : ast:: MutImmutable } ) ,
3117
3111
& ty:: ty_ptr( ty:: mt { ty : mt2, mutbl : ast:: MutImmutable } ) )
3118
3112
if types_compatible ( fcx, e. span , mt1, mt2) => {
@@ -3122,8 +3116,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
3122
3116
demand:: coerce ( fcx, e. span , t_1, & * * e) ;
3123
3117
}
3124
3118
}
3125
- } else if !( type_is_scalar ( fcx, expr. span , t_e)
3126
- && t_1_is_trivial) {
3119
+ } else if !( ty:: type_is_scalar ( t_e) && t_1_is_trivial) {
3127
3120
/*
3128
3121
If more type combinations should be supported than are
3129
3122
supported here, then file an enhancement issue and
@@ -4205,41 +4198,6 @@ pub fn type_is_uint(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
4205
4198
return ty:: type_is_uint ( typ_s) ;
4206
4199
}
4207
4200
4208
- pub fn type_is_scalar ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4209
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4210
- return ty:: type_is_scalar ( typ_s) ;
4211
- }
4212
-
4213
- pub fn type_is_char ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4214
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4215
- return ty:: type_is_char ( typ_s) ;
4216
- }
4217
-
4218
- pub fn type_is_bare_fn ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4219
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4220
- return ty:: type_is_bare_fn ( typ_s) ;
4221
- }
4222
-
4223
- pub fn type_is_floating_point ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4224
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4225
- return ty:: type_is_floating_point ( typ_s) ;
4226
- }
4227
-
4228
- pub fn type_is_unsafe_ptr ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4229
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4230
- return ty:: type_is_unsafe_ptr ( typ_s) ;
4231
- }
4232
-
4233
- pub fn type_is_region_ptr ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4234
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4235
- return ty:: type_is_region_ptr ( typ_s) ;
4236
- }
4237
-
4238
- pub fn type_is_c_like_enum ( fcx : & FnCtxt , sp : Span , typ : ty:: t ) -> bool {
4239
- let typ_s = structurally_resolved_type ( fcx, sp, typ) ;
4240
- return ty:: type_is_c_like_enum ( fcx. ccx . tcx , typ_s) ;
4241
- }
4242
-
4243
4201
pub fn ast_expr_vstore_to_ty ( fcx : & FnCtxt ,
4244
4202
e : & ast:: Expr ,
4245
4203
v : ast:: ExprVstore ,
0 commit comments