@@ -40,7 +40,7 @@ impl InferenceContext<'_> {
40
40
}
41
41
42
42
fn resolve_value_path ( & mut self , path : & Path , id : ExprOrPatId ) -> Option < ValuePathResolution > {
43
- let ( value, self_subst) = self . resolve_value_path_inner ( path, id) ?;
43
+ let ( value, self_subst) = self . resolve_value_path_inner ( path, id, false ) ?;
44
44
45
45
let value_def: ValueTyDefId = match value {
46
46
ValueNs :: FunctionId ( it) => it. into ( ) ,
@@ -152,6 +152,7 @@ impl InferenceContext<'_> {
152
152
& mut self ,
153
153
path : & Path ,
154
154
id : ExprOrPatId ,
155
+ no_diagnostics : bool ,
155
156
) -> Option < ( ValueNs , Option < chalk_ir:: Substitution < Interner > > ) > {
156
157
// Don't use `self.make_ty()` here as we need `orig_ns`.
157
158
let mut ctx = TyLoweringContext :: new (
@@ -162,7 +163,11 @@ impl InferenceContext<'_> {
162
163
& self . diagnostics ,
163
164
InferenceTyDiagnosticSource :: Body ,
164
165
) ;
165
- let mut path_ctx = ctx. at_path ( path, id) ;
166
+ let mut path_ctx = if no_diagnostics {
167
+ ctx. at_path_forget_diagnostics ( path)
168
+ } else {
169
+ ctx. at_path ( path, id)
170
+ } ;
166
171
let ( value, self_subst) = if let Some ( type_ref) = path. type_anchor ( ) {
167
172
let last = path. segments ( ) . last ( ) ?;
168
173
@@ -172,7 +177,7 @@ impl InferenceContext<'_> {
172
177
173
178
path_ctx. ignore_last_segment ( ) ;
174
179
let ( ty, _) = path_ctx. lower_ty_relative_path ( ty, orig_ns) ;
175
- drop ( ctx) ;
180
+ drop_ctx ( ctx, no_diagnostics ) ;
176
181
let ty = self . table . insert_type_vars ( ty) ;
177
182
let ty = self . table . normalize_associated_types_in ( ty) ;
178
183
self . resolve_ty_assoc_item ( ty, last. name , id) . map ( |( it, substs) | ( it, Some ( substs) ) ) ?
@@ -183,7 +188,7 @@ impl InferenceContext<'_> {
183
188
184
189
match value_or_partial {
185
190
ResolveValueResult :: ValueNs ( it, _) => {
186
- drop ( ctx) ;
191
+ drop_ctx ( ctx, no_diagnostics ) ;
187
192
( it, None )
188
193
}
189
194
ResolveValueResult :: Partial ( def, remaining_index, _) => {
@@ -202,7 +207,7 @@ impl InferenceContext<'_> {
202
207
let self_ty = self . table . new_type_var ( ) ;
203
208
let trait_ref =
204
209
path_ctx. lower_trait_ref_from_resolved_path ( trait_, self_ty) ;
205
- drop ( ctx) ;
210
+ drop_ctx ( ctx, no_diagnostics ) ;
206
211
self . resolve_trait_assoc_item ( trait_ref, last_segment, id)
207
212
}
208
213
( def, _) => {
@@ -212,7 +217,7 @@ impl InferenceContext<'_> {
212
217
// as Iterator>::Item::default`)
213
218
path_ctx. ignore_last_segment ( ) ;
214
219
let ( ty, _) = path_ctx. lower_partly_resolved_path ( def, true ) ;
215
- drop ( ctx) ;
220
+ drop_ctx ( ctx, no_diagnostics ) ;
216
221
if ty. is_unknown ( ) {
217
222
return None ;
218
223
}
@@ -227,7 +232,14 @@ impl InferenceContext<'_> {
227
232
}
228
233
}
229
234
} ;
230
- Some ( ( value, self_subst) )
235
+ return Some ( ( value, self_subst) ) ;
236
+
237
+ #[ inline]
238
+ fn drop_ctx ( mut ctx : TyLoweringContext < ' _ > , no_diagnostics : bool ) {
239
+ if no_diagnostics {
240
+ ctx. forget_diagnostics ( ) ;
241
+ }
242
+ }
231
243
}
232
244
233
245
fn add_required_obligations_for_value_path ( & mut self , def : GenericDefId , subst : & Substitution ) {
0 commit comments