Introduce VarBindingIntroduction.

This commit is contained in:
Camille GILLOT
2025-06-21 12:44:19 +00:00
committed by Camille Gillot
parent 9df2003860
commit f2535764d4
4 changed files with 17 additions and 4 deletions

View File

@@ -882,8 +882,9 @@ pub struct VarBindingForm<'tcx> {
pub opt_match_place: Option<(Option<Place<'tcx>>, Span)>,
/// The span of the pattern in which this variable was bound.
pub pat_span: Span,
/// For each introduction place, record here the span and whether this was a shorthand pattern.
pub introductions: Vec<(Span, /* is_shorthand */ bool)>,
/// A binding can be introduced multiple times, with or patterns:
/// `Foo::A { x } | Foo::B { z: x }`. This stores information for each of those introductions.
pub introductions: Vec<VarBindingIntroduction>,
}
#[derive(Clone, Debug, TyEncodable, TyDecodable)]
@@ -896,6 +897,14 @@ pub enum BindingForm<'tcx> {
RefForGuard,
}
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub struct VarBindingIntroduction {
/// Where this additional introduction happened.
pub span: Span,
/// Is that introduction a shorthand struct pattern, i.e. `Foo { x }`.
pub is_shorthand: bool,
}
mod binding_form_impl {
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_query_system::ich::StableHashingContext;

View File

@@ -798,6 +798,7 @@ pub enum PatKind<'tcx> {
/// (The same binding can occur multiple times in different branches of
/// an or-pattern, but only one of them will be primary.)
is_primary: bool,
/// Is this binding a shorthand struct pattern, i.e. `Foo { a }`?
is_shorthand: bool,
},

View File

@@ -817,7 +817,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
let local_info = self.local_decls[local_id].local_info.as_mut().unwrap_crate_local();
if let LocalInfo::User(BindingForm::Var(var_info)) = &mut **local_info {
var_info.introductions.push((span, is_shorthand));
var_info.introductions.push(VarBindingIntroduction { span, is_shorthand });
}
Place::from(local_id)
}

View File

@@ -1054,7 +1054,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
opt_ty_info: param.ty_span,
opt_match_place: Some((None, span)),
pat_span: span,
introductions: vec![(span, false)],
introductions: vec![VarBindingIntroduction {
span,
is_shorthand: false,
}],
}))
};
self.var_indices.insert(var, LocalsForNode::One(local));