@@ -59,6 +59,7 @@ use crate::{
5959 generics:: Generics ,
6060 infer:: { coerce:: CoerceMany , unify:: InferenceTable } ,
6161 lower:: ImplTraitLoweringMode ,
62+ mir:: MirSpan ,
6263 to_assoc_type_id,
6364 traits:: FnTrait ,
6465 utils:: { InTypeConstIdMetadata , UnevaluatedConstEvaluatorFolder } ,
@@ -553,6 +554,12 @@ pub(crate) struct InferenceContext<'a> {
553554
554555 // fields related to closure capture
555556 current_captures : Vec < CapturedItemWithoutTy > ,
557+ /// A stack that has an entry for each projection in the current capture.
558+ ///
559+ /// For example, in `a.b.c`, we capture the spans of `a`, `a.b`, and `a.b.c`.
560+ /// We do that because sometimes we truncate projections (when a closure captures
561+ /// both `a.b` and `a.b.c`), and we want to provide accurate spans in this case.
562+ current_capture_span_stack : Vec < MirSpan > ,
556563 current_closure : Option < ClosureId > ,
557564 /// Stores the list of closure ids that need to be analyzed before this closure. See the
558565 /// comment on `InferenceContext::sort_closures`
@@ -634,6 +641,7 @@ impl<'a> InferenceContext<'a> {
634641 breakables : Vec :: new ( ) ,
635642 deferred_cast_checks : Vec :: new ( ) ,
636643 current_captures : Vec :: new ( ) ,
644+ current_capture_span_stack : Vec :: new ( ) ,
637645 current_closure : None ,
638646 deferred_closures : FxHashMap :: default ( ) ,
639647 closure_dependencies : FxHashMap :: default ( ) ,
0 commit comments