@@ -322,7 +322,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
322322 err. span_suggestion (
323323 self . span ,
324324 "compare with zero instead" ,
325- format ! ( "{} != 0" , snippet ) ,
325+ format ! ( "{snippet } != 0" ) ,
326326 Applicability :: MachineApplicable ,
327327 ) ;
328328 }
@@ -373,8 +373,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
373373 let mut sugg = None ;
374374 let mut sugg_mutref = false ;
375375 if let ty:: Ref ( reg, cast_ty, mutbl) = * self . cast_ty . kind ( ) {
376- if let ty:: RawPtr ( TypeAndMut { ty : expr_ty, .. } ) = * self . expr_ty . kind ( ) {
377- if fcx
376+ if let ty:: RawPtr ( TypeAndMut { ty : expr_ty, .. } ) = * self . expr_ty . kind ( )
377+ && fcx
378378 . try_coerce (
379379 self . expr ,
380380 fcx. tcx . mk_ref (
@@ -386,27 +386,25 @@ impl<'a, 'tcx> CastCheck<'tcx> {
386386 None ,
387387 )
388388 . is_ok ( )
389- {
390- sugg = Some ( ( format ! ( "&{}*" , mutbl. prefix_str( ) ) , cast_ty == expr_ty) ) ;
391- }
392- } else if let ty:: Ref ( expr_reg, expr_ty, expr_mutbl) = * self . expr_ty . kind ( ) {
393- if expr_mutbl == Mutability :: Not
394- && mutbl == Mutability :: Mut
395- && fcx
396- . try_coerce (
397- self . expr ,
398- fcx. tcx . mk_ref (
399- expr_reg,
400- TypeAndMut { ty : expr_ty, mutbl : Mutability :: Mut } ,
401- ) ,
402- self . cast_ty ,
403- AllowTwoPhase :: No ,
404- None ,
405- )
406- . is_ok ( )
407- {
408- sugg_mutref = true ;
409- }
389+ {
390+ sugg = Some ( ( format ! ( "&{}*" , mutbl. prefix_str( ) ) , cast_ty == expr_ty) ) ;
391+ } else if let ty:: Ref ( expr_reg, expr_ty, expr_mutbl) = * self . expr_ty . kind ( )
392+ && expr_mutbl == Mutability :: Not
393+ && mutbl == Mutability :: Mut
394+ && fcx
395+ . try_coerce (
396+ self . expr ,
397+ fcx. tcx . mk_ref (
398+ expr_reg,
399+ TypeAndMut { ty : expr_ty, mutbl : Mutability :: Mut } ,
400+ ) ,
401+ self . cast_ty ,
402+ AllowTwoPhase :: No ,
403+ None ,
404+ )
405+ . is_ok ( )
406+ {
407+ sugg_mutref = true ;
410408 }
411409
412410 if !sugg_mutref
@@ -423,8 +421,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
423421 {
424422 sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
425423 }
426- } else if let ty:: RawPtr ( TypeAndMut { mutbl, .. } ) = * self . cast_ty . kind ( ) {
427- if fcx
424+ } else if let ty:: RawPtr ( TypeAndMut { mutbl, .. } ) = * self . cast_ty . kind ( )
425+ && fcx
428426 . try_coerce (
429427 self . expr ,
430428 fcx. tcx . mk_ref (
@@ -436,9 +434,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
436434 None ,
437435 )
438436 . is_ok ( )
439- {
440- sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
441- }
437+ {
438+ sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
442439 }
443440 if sugg_mutref {
444441 err. span_label ( self . span , "invalid cast" ) ;
@@ -483,28 +480,28 @@ impl<'a, 'tcx> CastCheck<'tcx> {
483480 ) {
484481 let mut label = true ;
485482 // Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion:
486- if let Ok ( snippet) = fcx. tcx . sess . source_map ( ) . span_to_snippet ( self . expr_span ) {
487- if let Some ( from_trait) = fcx. tcx . get_diagnostic_item ( sym:: From ) {
488- let ty = fcx . resolve_vars_if_possible ( self . cast_ty ) ;
489- // Erase regions to avoid panic in `prove_value` when calling
490- // `type_implements_trait`.
491- let ty = fcx . tcx . erase_regions ( ty ) ;
492- let expr_ty = fcx. resolve_vars_if_possible ( self . expr_ty ) ;
493- let expr_ty = fcx. tcx . erase_regions ( expr_ty) ;
494- let ty_params = fcx. tcx . mk_substs_trait ( expr_ty, & [ ] ) ;
495- if fcx
496- . infcx
497- . type_implements_trait ( from_trait , ty , ty_params , fcx . param_env )
498- . must_apply_modulo_regions ( )
499- {
500- label = false ;
501- err . span_suggestion (
502- self . span ,
503- "consider using the `From` trait instead" ,
504- format ! ( "{}::from({})" , self . cast_ty , snippet ) ,
505- Applicability :: MaybeIncorrect ,
506- ) ;
507- }
483+ if let Ok ( snippet) = fcx. tcx . sess . source_map ( ) . span_to_snippet ( self . expr_span )
484+ && let Some ( from_trait) = fcx. tcx . get_diagnostic_item ( sym:: From )
485+ {
486+ let ty = fcx . resolve_vars_if_possible ( self . cast_ty ) ;
487+ // Erase regions to avoid panic in `prove_value` when calling
488+ // `type_implements_trait`.
489+ let ty = fcx. tcx . erase_regions ( ty ) ;
490+ let expr_ty = fcx. resolve_vars_if_possible ( self . expr_ty ) ;
491+ let expr_ty = fcx. tcx . erase_regions ( expr_ty) ;
492+ let ty_params = fcx. tcx . mk_substs_trait ( expr_ty , & [ ] ) ;
493+ if fcx
494+ . infcx
495+ . type_implements_trait ( from_trait , ty , ty_params , fcx . param_env )
496+ . must_apply_modulo_regions ( )
497+ {
498+ label = false ;
499+ err . span_suggestion (
500+ self . span ,
501+ "consider using the `From` trait instead" ,
502+ format ! ( "{}::from({})" , self . cast_ty , snippet ) ,
503+ Applicability :: MaybeIncorrect ,
504+ ) ;
508505 }
509506 }
510507 let msg = "an `as` expression can only be used to convert between primitive \
@@ -627,10 +624,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
627624 }
628625 }
629626 } else {
630- let msg = & format ! (
631- "consider using an implicit coercion to `&{}{}` instead" ,
632- mtstr, tstr
633- ) ;
627+ let msg =
628+ & format ! ( "consider using an implicit coercion to `&{mtstr}{tstr}` instead" ) ;
634629 err. span_help ( self . span , msg) ;
635630 }
636631 }
@@ -640,14 +635,14 @@ impl<'a, 'tcx> CastCheck<'tcx> {
640635 err. span_suggestion (
641636 self . cast_span ,
642637 "you can cast to a `Box` instead" ,
643- format ! ( "Box<{}>" , s ) ,
638+ format ! ( "Box<{s }>" ) ,
644639 Applicability :: MachineApplicable ,
645640 ) ;
646641 }
647642 Err ( _) => {
648643 err. span_help (
649644 self . cast_span ,
650- & format ! ( "you might have meant `Box<{}>`" , tstr ) ,
645+ & format ! ( "you might have meant `Box<{tstr }>`" ) ,
651646 ) ;
652647 }
653648 }
@@ -678,8 +673,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
678673 ) )
679674 . help ( & format ! (
680675 "cast can be replaced by coercion; this might \
681- require {}a temporary variable",
682- type_asc_or
676+ require {type_asc_or}a temporary variable"
683677 ) )
684678 . emit ( ) ;
685679 } ) ;
@@ -969,21 +963,21 @@ impl<'a, 'tcx> CastCheck<'tcx> {
969963 }
970964
971965 fn cenum_impl_drop_lint ( & self , fcx : & FnCtxt < ' a , ' tcx > ) {
972- if let ty:: Adt ( d, _) = self . expr_ty . kind ( ) {
973- if d. has_dtor ( fcx. tcx ) {
974- fcx . tcx . struct_span_lint_hir (
975- lint :: builtin :: CENUM_IMPL_DROP_CAST ,
976- self . expr . hir_id ,
977- self . span ,
978- |err| {
979- err. build ( & format ! (
980- "cannot cast enum `{}` into integer `{}` because it implements `Drop`" ,
981- self . expr_ty , self . cast_ty
982- ) )
983- . emit ( ) ;
984- } ,
985- ) ;
986- }
966+ if let ty:: Adt ( d, _) = self . expr_ty . kind ( )
967+ && d. has_dtor ( fcx. tcx )
968+ {
969+ fcx . tcx . struct_span_lint_hir (
970+ lint :: builtin :: CENUM_IMPL_DROP_CAST ,
971+ self . expr . hir_id ,
972+ self . span ,
973+ | err| {
974+ err . build ( & format ! (
975+ "cannot cast enum `{}` into integer `{}` because it implements `Drop`" ,
976+ self . expr_ty , self . cast_ty
977+ ) )
978+ . emit ( ) ;
979+ } ,
980+ ) ;
987981 }
988982 }
989983
@@ -1007,7 +1001,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
10071001 err. span_suggestion (
10081002 self . span ,
10091003 msg,
1010- format ! ( "({}).addr(){}" , snippet , scalar_cast ) ,
1004+ format ! ( "({snippet }).addr(){scalar_cast}" ) ,
10111005 Applicability :: MaybeIncorrect
10121006 ) ;
10131007 } else {
@@ -1038,7 +1032,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
10381032 err. span_suggestion (
10391033 self . span ,
10401034 msg,
1041- format ! ( "(...).with_addr({})" , snippet ) ,
1035+ format ! ( "(...).with_addr({snippet })" ) ,
10421036 Applicability :: HasPlaceholders ,
10431037 ) ;
10441038 } else {
0 commit comments