@@ -40,7 +40,7 @@ impl InferenceContext<'_> {
4040 }
4141
4242 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 ) ?;
4444
4545 let value_def: ValueTyDefId = match value {
4646 ValueNs :: FunctionId ( it) => it. into ( ) ,
@@ -152,6 +152,7 @@ impl InferenceContext<'_> {
152152 & mut self ,
153153 path : & Path ,
154154 id : ExprOrPatId ,
155+ no_diagnostics : bool ,
155156 ) -> Option < ( ValueNs , Option < chalk_ir:: Substitution < Interner > > ) > {
156157 // Don't use `self.make_ty()` here as we need `orig_ns`.
157158 let mut ctx = TyLoweringContext :: new (
@@ -162,7 +163,11 @@ impl InferenceContext<'_> {
162163 & self . diagnostics ,
163164 InferenceTyDiagnosticSource :: Body ,
164165 ) ;
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+ } ;
166171 let ( value, self_subst) = if let Some ( type_ref) = path. type_anchor ( ) {
167172 let last = path. segments ( ) . last ( ) ?;
168173
@@ -172,7 +177,7 @@ impl InferenceContext<'_> {
172177
173178 path_ctx. ignore_last_segment ( ) ;
174179 let ( ty, _) = path_ctx. lower_ty_relative_path ( ty, orig_ns) ;
175- drop ( ctx) ;
180+ drop_ctx ( ctx, no_diagnostics ) ;
176181 let ty = self . table . insert_type_vars ( ty) ;
177182 let ty = self . table . normalize_associated_types_in ( ty) ;
178183 self . resolve_ty_assoc_item ( ty, last. name , id) . map ( |( it, substs) | ( it, Some ( substs) ) ) ?
@@ -183,7 +188,7 @@ impl InferenceContext<'_> {
183188
184189 match value_or_partial {
185190 ResolveValueResult :: ValueNs ( it, _) => {
186- drop ( ctx) ;
191+ drop_ctx ( ctx, no_diagnostics ) ;
187192 ( it, None )
188193 }
189194 ResolveValueResult :: Partial ( def, remaining_index, _) => {
@@ -202,7 +207,7 @@ impl InferenceContext<'_> {
202207 let self_ty = self . table . new_type_var ( ) ;
203208 let trait_ref =
204209 path_ctx. lower_trait_ref_from_resolved_path ( trait_, self_ty) ;
205- drop ( ctx) ;
210+ drop_ctx ( ctx, no_diagnostics ) ;
206211 self . resolve_trait_assoc_item ( trait_ref, last_segment, id)
207212 }
208213 ( def, _) => {
@@ -212,7 +217,7 @@ impl InferenceContext<'_> {
212217 // as Iterator>::Item::default`)
213218 path_ctx. ignore_last_segment ( ) ;
214219 let ( ty, _) = path_ctx. lower_partly_resolved_path ( def, true ) ;
215- drop ( ctx) ;
220+ drop_ctx ( ctx, no_diagnostics ) ;
216221 if ty. is_unknown ( ) {
217222 return None ;
218223 }
@@ -227,7 +232,14 @@ impl InferenceContext<'_> {
227232 }
228233 }
229234 } ;
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+ }
231243 }
232244
233245 fn add_required_obligations_for_value_path ( & mut self , def : GenericDefId , subst : & Substitution ) {
0 commit comments