@@ -122,20 +122,21 @@ impl<'tcx> CastCheck<'tcx> {
122122 CastError :: NeedViaInt |
123123 CastError :: NeedViaUsize => {
124124 fcx. type_error_message ( self . span , |actual| {
125- format ! ( "illegal cast; cast through {} first: `{}` as `{}`" ,
126- match e {
127- CastError :: NeedViaPtr => "a raw pointer" ,
128- CastError :: NeedViaInt => "an integer" ,
129- CastError :: NeedViaUsize => "a usize" ,
130- _ => unreachable!( )
131- } ,
125+ format ! ( "casting `{}` as `{}` is invalid" ,
132126 actual,
133127 fcx. infcx( ) . ty_to_string( self . cast_ty) )
134- } , self . expr_ty , None )
128+ } , self . expr_ty , None ) ;
129+ fcx. ccx . tcx . sess . fileline_help ( self . span ,
130+ & format ! ( "cast through {} first" , match e {
131+ CastError :: NeedViaPtr => "a raw pointer" ,
132+ CastError :: NeedViaInt => "an integer" ,
133+ CastError :: NeedViaUsize => "a usize" ,
134+ _ => unreachable!( )
135+ } ) ) ;
135136 }
136137 CastError :: CastToBool => {
137- span_err ! ( fcx. tcx( ) . sess, self . span, E0054 ,
138- "cannot cast as `bool`, compare with zero instead") ;
138+ span_err ! ( fcx. tcx( ) . sess, self . span, E0054 , "cannot cast as `bool`" ) ;
139+ fcx . ccx . tcx . sess . fileline_help ( self . span , " compare with zero instead") ;
139140 }
140141 CastError :: CastToChar => {
141142 fcx. type_error_message ( self . span , |actual| {
@@ -151,17 +152,18 @@ impl<'tcx> CastCheck<'tcx> {
151152 }
152153 CastError :: IllegalCast => {
153154 fcx. type_error_message ( self . span , |actual| {
154- format ! ( "illegal cast: `{}` as `{}`" ,
155+ format ! ( "casting `{}` as `{}` is invalid " ,
155156 actual,
156157 fcx. infcx( ) . ty_to_string( self . cast_ty) )
157158 } , self . expr_ty , None ) ;
158159 }
159160 CastError :: DifferingKinds => {
160161 fcx. type_error_message ( self . span , |actual| {
161- format ! ( "illegal cast: `{}` as `{}`; vtable kinds may not match " ,
162+ format ! ( "casting `{}` as `{}` is invalid " ,
162163 actual,
163164 fcx. infcx( ) . ty_to_string( self . cast_ty) )
164165 } , self . expr_ty , None ) ;
166+ fcx. ccx . tcx . sess . fileline_note ( self . span , "vtable kinds may not match" ) ;
165167 }
166168 }
167169 }
@@ -285,7 +287,7 @@ impl<'tcx> CastCheck<'tcx> {
285287 return Ok ( CastKind :: PtrPtrCast ) ;
286288 }
287289
288- // sized -> unsized? report illegal cast (don't complain about vtable kinds)
290+ // sized -> unsized? report invalid cast (don't complain about vtable kinds)
289291 if fcx. type_is_known_to_be_sized ( m_expr. ty , self . span ) {
290292 return Err ( CastError :: IllegalCast ) ;
291293 }
0 commit comments