@@ -642,7 +642,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
642642 tcx. ensure ( ) . generics_of ( def_id) ;
643643 tcx. ensure ( ) . type_of ( def_id) ;
644644 tcx. ensure ( ) . predicates_of ( def_id) ;
645- if !is_suggestable_infer_ty ( ty ) {
645+ if !ty . is_suggestable_infer_ty ( ) {
646646 let mut visitor = HirPlaceholderCollector :: default ( ) ;
647647 visitor. visit_item ( it) ;
648648 placeholder_type_error ( tcx, None , visitor. 0 , false , None , it. kind . descr ( ) ) ;
@@ -674,7 +674,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
674674 hir:: TraitItemKind :: Const ( ty, body_id) => {
675675 tcx. ensure ( ) . type_of ( def_id) ;
676676 if !tcx. dcx ( ) . has_stashed_diagnostic ( ty. span , StashKey :: ItemNoType )
677- && !( is_suggestable_infer_ty ( ty ) && body_id. is_some ( ) )
677+ && !( ty . is_suggestable_infer_ty ( ) && body_id. is_some ( ) )
678678 {
679679 // Account for `const C: _;`.
680680 let mut visitor = HirPlaceholderCollector :: default ( ) ;
@@ -726,7 +726,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
726726 }
727727 hir:: ImplItemKind :: Const ( ty, _) => {
728728 // Account for `const T: _ = ..;`
729- if !is_suggestable_infer_ty ( ty ) {
729+ if !ty . is_suggestable_infer_ty ( ) {
730730 let mut visitor = HirPlaceholderCollector :: default ( ) ;
731731 visitor. visit_impl_item ( impl_item) ;
732732 placeholder_type_error ( tcx, None , visitor. 0 , false , None , "associated constant" ) ;
@@ -1054,48 +1054,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
10541054 }
10551055}
10561056
1057- fn are_suggestable_generic_args ( generic_args : & [ hir:: GenericArg < ' _ > ] ) -> bool {
1058- generic_args. iter ( ) . any ( |arg| match arg {
1059- hir:: GenericArg :: Type ( ty) => is_suggestable_infer_ty ( ty) ,
1060- hir:: GenericArg :: Infer ( _) => true ,
1061- _ => false ,
1062- } )
1063- }
1064-
1065- /// Whether `ty` is a type with `_` placeholders that can be inferred. Used in diagnostics only to
1066- /// use inference to provide suggestions for the appropriate type if possible.
1067- fn is_suggestable_infer_ty ( ty : & hir:: Ty < ' _ > ) -> bool {
1068- debug ! ( ?ty) ;
1069- use hir:: TyKind :: * ;
1070- match & ty. kind {
1071- Infer => true ,
1072- Slice ( ty) => is_suggestable_infer_ty ( ty) ,
1073- Array ( ty, length) => {
1074- is_suggestable_infer_ty ( ty) || matches ! ( length, hir:: ArrayLen :: Infer ( _, _) )
1075- }
1076- Tup ( tys) => tys. iter ( ) . any ( is_suggestable_infer_ty) ,
1077- Ptr ( mut_ty) | Ref ( _, mut_ty) => is_suggestable_infer_ty ( mut_ty. ty ) ,
1078- OpaqueDef ( _, generic_args, _) => are_suggestable_generic_args ( generic_args) ,
1079- Path ( hir:: QPath :: TypeRelative ( ty, segment) ) => {
1080- is_suggestable_infer_ty ( ty) || are_suggestable_generic_args ( segment. args ( ) . args )
1081- }
1082- Path ( hir:: QPath :: Resolved ( ty_opt, hir:: Path { segments, .. } ) ) => {
1083- ty_opt. is_some_and ( is_suggestable_infer_ty)
1084- || segments. iter ( ) . any ( |segment| are_suggestable_generic_args ( segment. args ( ) . args ) )
1085- }
1086- _ => false ,
1087- }
1088- }
1089-
1090- pub fn get_infer_ret_ty < ' hir > ( output : & ' hir hir:: FnRetTy < ' hir > ) -> Option < & ' hir hir:: Ty < ' hir > > {
1091- if let hir:: FnRetTy :: Return ( ty) = output {
1092- if is_suggestable_infer_ty ( ty) {
1093- return Some ( * ty) ;
1094- }
1095- }
1096- None
1097- }
1098-
10991057#[ instrument( level = "debug" , skip( tcx) ) ]
11001058fn fn_sig ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: EarlyBinder < ty:: PolyFnSig < ' _ > > {
11011059 use rustc_hir:: Node :: * ;
@@ -1188,7 +1146,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
11881146) -> ty:: PolyFnSig < ' tcx > {
11891147 let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
11901148
1191- match get_infer_ret_ty ( & sig. decl . output ) {
1149+ match sig. decl . output . get_infer_ret_ty ( ) {
11921150 Some ( ty) => {
11931151 let fn_sig = tcx. typeck ( def_id) . liberated_fn_sigs ( ) [ hir_id] ;
11941152 // Typeck doesn't expect erased regions to be returned from `type_of`.
0 commit comments