Skip to content

Commit 5c07dba

Browse files
Preserve all spans for closure captures, not just one
This is important for the "convert closure to fn" assist, as it needs to find and modify the places the captures are used.
1 parent c04480a commit 5c07dba

File tree

4 files changed

+448
-174
lines changed

4 files changed

+448
-174
lines changed

crates/hir-ty/src/infer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,8 @@ 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+
current_capture_span_stack: Vec<MirSpan>,
556559
current_closure: Option<ClosureId>,
557560
/// Stores the list of closure ids that need to be analyzed before this closure. See the
558561
/// comment on `InferenceContext::sort_closures`
@@ -629,6 +632,7 @@ impl<'a> InferenceContext<'a> {
629632
breakables: Vec::new(),
630633
deferred_cast_checks: Vec::new(),
631634
current_captures: Vec::new(),
635+
current_capture_span_stack: Vec::new(),
632636
current_closure: None,
633637
deferred_closures: FxHashMap::default(),
634638
closure_dependencies: FxHashMap::default(),

0 commit comments

Comments
 (0)