@@ -635,31 +635,18 @@ impl<'a, 'tcx> CastCheck<'tcx> {
635
635
}
636
636
637
637
fn trivial_cast_lint ( & self , fcx : & FnCtxt < ' a , ' tcx > ) {
638
- let t_cast = self . cast_ty ;
639
- let t_expr = self . expr_ty ;
640
- let ( adjective, lint) = if t_cast. is_numeric ( ) && t_expr. is_numeric ( ) {
641
- ( "numeric " , lint:: builtin:: TRIVIAL_NUMERIC_CASTS )
638
+ let ( numeric, lint) = if self . cast_ty . is_numeric ( ) && self . expr_ty . is_numeric ( ) {
639
+ ( true , lint:: builtin:: TRIVIAL_NUMERIC_CASTS )
642
640
} else {
643
- ( "" , lint:: builtin:: TRIVIAL_CASTS )
641
+ ( false , lint:: builtin:: TRIVIAL_CASTS )
644
642
} ;
645
- fcx. tcx . struct_span_lint_hir (
643
+ let expr_ty = fcx. resolve_vars_if_possible ( self . expr_ty ) ;
644
+ let cast_ty = fcx. resolve_vars_if_possible ( self . cast_ty ) ;
645
+ fcx. tcx . emit_spanned_lint (
646
646
lint,
647
647
self . expr . hir_id ,
648
648
self . span ,
649
- DelayDm ( || {
650
- format ! (
651
- "trivial {}cast: `{}` as `{}`" ,
652
- adjective,
653
- fcx. ty_to_string( t_expr) ,
654
- fcx. ty_to_string( t_cast)
655
- )
656
- } ) ,
657
- |lint| {
658
- lint. help (
659
- "cast can be replaced by coercion; this might \
660
- require a temporary variable",
661
- )
662
- } ,
649
+ errors:: TrivialCast { numeric, expr_ty, cast_ty } ,
663
650
) ;
664
651
}
665
652
0 commit comments