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