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