@@ -87,21 +87,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
87
87
}
88
88
89
89
fn 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 )
105
91
}
106
92
107
93
/// Same as `typeck` but `inspect` is invoked on evaluation of each root obligation.
@@ -113,15 +99,13 @@ pub fn inspect_typeck<'tcx>(
113
99
def_id : LocalDefId ,
114
100
inspect : ObligationInspector < ' tcx > ,
115
101
) -> & ' 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) )
118
103
}
119
104
120
- #[ instrument( level = "debug" , skip( tcx, fallback , inspector) , ret) ]
105
+ #[ instrument( level = "debug" , skip( tcx, inspector) , ret) ]
121
106
fn typeck_with_fallback < ' tcx > (
122
107
tcx : TyCtxt < ' tcx > ,
123
108
def_id : LocalDefId ,
124
- fallback : impl Fn ( ) -> Ty < ' tcx > + ' tcx ,
125
109
inspector : Option < ObligationInspector < ' tcx > > ,
126
110
) -> & ' tcx ty:: TypeckResults < ' tcx > {
127
111
// Closures' typeck results come from their outermost function,
@@ -151,6 +135,10 @@ fn typeck_with_fallback<'tcx>(
151
135
152
136
if let Some ( hir:: FnSig { header, decl, .. } ) = node. fn_sig ( ) {
153
137
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.
154
142
fcx. lowerer ( ) . lower_fn_ty ( id, header. safety , header. abi , decl, None , None )
155
143
} else {
156
144
tcx. fn_sig ( def_id) . instantiate_identity ( )
@@ -164,8 +152,19 @@ fn typeck_with_fallback<'tcx>(
164
152
165
153
check_fn ( & mut fcx, fn_sig, None , decl, def_id, body, tcx. features ( ) . unsized_fn_params ( ) ) ;
166
154
} 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
+ } ;
169
168
170
169
let expected_type = fcx. normalize ( body. value . span , expected_type) ;
171
170
@@ -506,5 +505,5 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
506
505
507
506
pub fn provide ( providers : & mut Providers ) {
508
507
method:: provide ( providers) ;
509
- * providers = Providers { typeck, diagnostic_only_typeck , used_trait_imports, ..* providers } ;
508
+ * providers = Providers { typeck, used_trait_imports, ..* providers } ;
510
509
}
0 commit comments