@@ -655,8 +655,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
655655 fn ty_kind_suggestion ( & self , ty : Ty < ' tcx > ) -> Option < String > {
656656 // Keep in sync with `rustc_hir_analysis/src/check/mod.rs:ty_kind_suggestion`.
657657 // FIXME: deduplicate the above.
658+ let tcx = self . infcx . tcx ;
658659 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 {
660661 return false ;
661662 } ;
662663 self . infcx
@@ -671,9 +672,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
671672 ty:: Int ( _) | ty:: Uint ( _) => "42" . into ( ) ,
672673 ty:: Float ( _) => "3.14159" . into ( ) ,
673674 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 ) => {
675676 "vec![]" . to_string ( )
676677 }
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+ }
677690 ty:: Adt ( _, _) if implements_default ( ty) => "Default::default()" . to_string ( ) ,
678691 ty:: Ref ( _, ty, mutability) => {
679692 if let ( ty:: Str , hir:: Mutability :: Not ) = ( ty. kind ( ) , mutability) {
@@ -688,7 +701,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
688701 ty:: Array ( ty, len) => format ! (
689702 "[{}; {}]" ,
690703 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( ) ) ,
692705 ) ,
693706 ty:: Tuple ( tys) => format ! (
694707 "({})" ,
0 commit comments