@@ -87,21 +87,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
8787}
8888
8989fn typeck < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> & ' tcx ty:: TypeckResults < ' tcx > {
90- let fallback = move || tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) ;
91- typeck_with_fallback ( tcx, def_id, fallback, None )
92- }
93-
94- /// Used only to get `TypeckResults` for type inference during error recovery.
95- /// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors.
96- fn diagnostic_only_typeck < ' tcx > (
97- tcx : TyCtxt < ' tcx > ,
98- def_id : LocalDefId ,
99- ) -> & ' tcx ty:: TypeckResults < ' tcx > {
100- let fallback = move || {
101- let span = tcx. hir ( ) . span ( tcx. local_def_id_to_hir_id ( def_id) ) ;
102- Ty :: new_error_with_message ( tcx, span, "diagnostic only typeck table used" )
103- } ;
104- typeck_with_fallback ( tcx, def_id, fallback, None )
90+ typeck_with_fallback ( tcx, def_id, None )
10591}
10692
10793/// Same as `typeck` but `inspect` is invoked on evaluation of each root obligation.
@@ -113,15 +99,13 @@ pub fn inspect_typeck<'tcx>(
11399 def_id : LocalDefId ,
114100 inspect : ObligationInspector < ' tcx > ,
115101) -> & ' tcx ty:: TypeckResults < ' tcx > {
116- let fallback = move || tcx. type_of ( def_id. to_def_id ( ) ) . instantiate_identity ( ) ;
117- typeck_with_fallback ( tcx, def_id, fallback, Some ( inspect) )
102+ typeck_with_fallback ( tcx, def_id, Some ( inspect) )
118103}
119104
120- #[ instrument( level = "debug" , skip( tcx, fallback , inspector) , ret) ]
105+ #[ instrument( level = "debug" , skip( tcx, inspector) , ret) ]
121106fn typeck_with_fallback < ' tcx > (
122107 tcx : TyCtxt < ' tcx > ,
123108 def_id : LocalDefId ,
124- fallback : impl Fn ( ) -> Ty < ' tcx > + ' tcx ,
125109 inspector : Option < ObligationInspector < ' tcx > > ,
126110) -> & ' tcx ty:: TypeckResults < ' tcx > {
127111 // Closures' typeck results come from their outermost function,
@@ -151,6 +135,10 @@ fn typeck_with_fallback<'tcx>(
151135
152136 if let Some ( hir:: FnSig { header, decl, .. } ) = node. fn_sig ( ) {
153137 let fn_sig = if decl. output . is_suggestable_infer_ty ( ) . is_some ( ) {
138+ // In the case that we're recovering `fn() -> W<_>` or some other return
139+ // type that has an infer in it, lower the type directly so that it'll
140+ // be correctly filled with infer. We'll use this inference to provide
141+ // a suggestion later on.
154142 fcx. lowerer ( ) . lower_fn_ty ( id, header. safety , header. abi , decl, None , None )
155143 } else {
156144 tcx. fn_sig ( def_id) . instantiate_identity ( )
@@ -164,8 +152,19 @@ fn typeck_with_fallback<'tcx>(
164152
165153 check_fn ( & mut fcx, fn_sig, None , decl, def_id, body, tcx. features ( ) . unsized_fn_params ( ) ) ;
166154 } else {
167- let expected_type = infer_type_if_missing ( & fcx, node) ;
168- let expected_type = expected_type. unwrap_or_else ( fallback) ;
155+ let expected_type = if let Some ( infer_ty) = infer_type_if_missing ( & fcx, node) {
156+ infer_ty
157+ } else if let Some ( ty) = node. ty ( )
158+ && ty. is_suggestable_infer_ty ( )
159+ {
160+ // In the case that we're recovering `const X: [T; _]` or some other
161+ // type that has an infer in it, lower the type directly so that it'll
162+ // be correctly filled with infer. We'll use this inference to provide
163+ // a suggestion later on.
164+ fcx. lowerer ( ) . lower_ty ( ty)
165+ } else {
166+ tcx. type_of ( def_id) . instantiate_identity ( )
167+ } ;
169168
170169 let expected_type = fcx. normalize ( body. value . span , expected_type) ;
171170
@@ -506,5 +505,5 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
506505
507506pub fn provide ( providers : & mut Providers ) {
508507 method:: provide ( providers) ;
509- * providers = Providers { typeck, diagnostic_only_typeck , used_trait_imports, ..* providers } ;
508+ * providers = Providers { typeck, used_trait_imports, ..* providers } ;
510509}
0 commit comments