@@ -655,8 +655,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
655
655
fn ty_kind_suggestion ( & self , ty : Ty < ' tcx > ) -> Option < String > {
656
656
// Keep in sync with `rustc_hir_analysis/src/check/mod.rs:ty_kind_suggestion`.
657
657
// FIXME: deduplicate the above.
658
+ let tcx = self . infcx . tcx ;
658
659
let implements_default = |ty| {
659
- let Some ( default_trait) = self . infcx . tcx . get_diagnostic_item ( sym:: Default ) else {
660
+ let Some ( default_trait) = tcx. get_diagnostic_item ( sym:: Default ) else {
660
661
return false ;
661
662
} ;
662
663
self . infcx
@@ -671,9 +672,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
671
672
ty:: Int ( _) | ty:: Uint ( _) => "42" . into ( ) ,
672
673
ty:: Float ( _) => "3.14159" . into ( ) ,
673
674
ty:: Slice ( _) => "[]" . to_string ( ) ,
674
- ty:: Adt ( def, _) if Some ( def. did ( ) ) == self . infcx . tcx . get_diagnostic_item ( sym:: Vec ) => {
675
+ ty:: Adt ( def, _) if Some ( def. did ( ) ) == tcx. get_diagnostic_item ( sym:: Vec ) => {
675
676
"vec![]" . to_string ( )
676
677
}
678
+ ty:: Adt ( def, _) if Some ( def. did ( ) ) == tcx. get_diagnostic_item ( sym:: String ) => {
679
+ "String::new()" . to_string ( )
680
+ }
681
+ ty:: Adt ( def, args) if def. is_box ( ) => {
682
+ format ! ( "Box::new({})" , self . ty_kind_suggestion( args[ 0 ] . expect_ty( ) ) ?)
683
+ }
684
+ ty:: Adt ( def, _) if Some ( def. did ( ) ) == tcx. get_diagnostic_item ( sym:: Option ) => {
685
+ "None" . to_string ( )
686
+ }
687
+ ty:: Adt ( def, args) if Some ( def. did ( ) ) == tcx. get_diagnostic_item ( sym:: Result ) => {
688
+ format ! ( "Ok({})" , self . ty_kind_suggestion( args[ 0 ] . expect_ty( ) ) ?)
689
+ }
677
690
ty:: Adt ( _, _) if implements_default ( ty) => "Default::default()" . to_string ( ) ,
678
691
ty:: Ref ( _, ty, mutability) => {
679
692
if let ( ty:: Str , hir:: Mutability :: Not ) = ( ty. kind ( ) , mutability) {
@@ -688,7 +701,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
688
701
ty:: Array ( ty, len) => format ! (
689
702
"[{}; {}]" ,
690
703
self . ty_kind_suggestion( * ty) ?,
691
- len. eval_target_usize( self . infcx . tcx, ty:: ParamEnv :: reveal_all( ) ) ,
704
+ len. eval_target_usize( tcx, ty:: ParamEnv :: reveal_all( ) ) ,
692
705
) ,
693
706
ty:: Tuple ( tys) => format ! (
694
707
"({})" ,
0 commit comments