@@ -642,7 +642,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
642
642
tcx. ensure ( ) . generics_of ( def_id) ;
643
643
tcx. ensure ( ) . type_of ( def_id) ;
644
644
tcx. ensure ( ) . predicates_of ( def_id) ;
645
- if !is_suggestable_infer_ty ( ty ) {
645
+ if !ty . is_suggestable_infer_ty ( ) {
646
646
let mut visitor = HirPlaceholderCollector :: default ( ) ;
647
647
visitor. visit_item ( it) ;
648
648
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) {
674
674
hir:: TraitItemKind :: Const ( ty, body_id) => {
675
675
tcx. ensure ( ) . type_of ( def_id) ;
676
676
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 ( ) )
678
678
{
679
679
// Account for `const C: _;`.
680
680
let mut visitor = HirPlaceholderCollector :: default ( ) ;
@@ -726,7 +726,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
726
726
}
727
727
hir:: ImplItemKind :: Const ( ty, _) => {
728
728
// Account for `const T: _ = ..;`
729
- if !is_suggestable_infer_ty ( ty ) {
729
+ if !ty . is_suggestable_infer_ty ( ) {
730
730
let mut visitor = HirPlaceholderCollector :: default ( ) ;
731
731
visitor. visit_impl_item ( impl_item) ;
732
732
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 {
1054
1054
}
1055
1055
}
1056
1056
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
-
1099
1057
#[ instrument( level = "debug" , skip( tcx) ) ]
1100
1058
fn fn_sig ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: EarlyBinder < ty:: PolyFnSig < ' _ > > {
1101
1059
use rustc_hir:: Node :: * ;
@@ -1188,7 +1146,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
1188
1146
) -> ty:: PolyFnSig < ' tcx > {
1189
1147
let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
1190
1148
1191
- match get_infer_ret_ty ( & sig. decl . output ) {
1149
+ match sig. decl . output . get_infer_ret_ty ( ) {
1192
1150
Some ( ty) => {
1193
1151
let fn_sig = tcx. typeck ( def_id) . liberated_fn_sigs ( ) [ hir_id] ;
1194
1152
// Typeck doesn't expect erased regions to be returned from `type_of`.
0 commit comments