@@ -635,31 +635,18 @@ impl<'a, 'tcx> CastCheck<'tcx> {
635635 }
636636
637637 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 )
642640 } else {
643- ( "" , lint:: builtin:: TRIVIAL_CASTS )
641+ ( false , lint:: builtin:: TRIVIAL_CASTS )
644642 } ;
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 (
646646 lint,
647647 self . expr . hir_id ,
648648 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 } ,
663650 ) ;
664651 }
665652
0 commit comments