Skip to content

Commit bb723f2

Browse files
committed
Introduce VarBindingIntroduction.
1 parent c70a55b commit bb723f2

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,9 @@ pub struct VarBindingForm<'tcx> {
926926
pub opt_match_place: Option<(Option<Place<'tcx>>, Span)>,
927927
/// The span of the pattern in which this variable was bound.
928928
pub pat_span: Span,
929-
/// For each introduction place, record here the span and whether this was a shorthand pattern.
930-
pub introductions: Vec<(Span, /* is_shorthand */ bool)>,
929+
/// A binding can be introduced multiple times, with or patterns:
930+
/// `Foo::A { x } | Foo::B { z: x }`. This stores information for each of those introductions.
931+
pub introductions: Vec<VarBindingIntroduction>,
931932
}
932933

933934
#[derive(Clone, Debug, TyEncodable, TyDecodable)]
@@ -940,6 +941,14 @@ pub enum BindingForm<'tcx> {
940941
RefForGuard,
941942
}
942943

944+
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
945+
pub struct VarBindingIntroduction {
946+
/// Where this additional introduction happened.
947+
pub span: Span,
948+
/// Is that introduction a shorthand struct pattern, i.e. `Foo { x }`.
949+
pub is_shorthand: bool,
950+
}
951+
943952
mod binding_form_impl {
944953
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
945954
use rustc_query_system::ich::StableHashingContext;

compiler/rustc_middle/src/thir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ pub enum PatKind<'tcx> {
798798
/// (The same binding can occur multiple times in different branches of
799799
/// an or-pattern, but only one of them will be primary.)
800800
is_primary: bool,
801+
/// Is this binding a shorthand struct pattern, i.e. `Foo { a }`?
801802
is_shorthand: bool,
802803
},
803804

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
841841
}
842842
let local_info = self.local_decls[local_id].local_info.as_mut().unwrap_crate_local();
843843
if let LocalInfo::User(BindingForm::Var(var_info)) = &mut **local_info {
844-
var_info.introductions.push((span, is_shorthand));
844+
var_info.introductions.push(VarBindingIntroduction { span, is_shorthand });
845845
}
846846
Place::from(local_id)
847847
}

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10451045
opt_ty_info: param.ty_span,
10461046
opt_match_place: Some((None, span)),
10471047
pat_span: span,
1048-
introductions: vec![(span, false)],
1048+
introductions: vec![VarBindingIntroduction {
1049+
span,
1050+
is_shorthand: false,
1051+
}],
10491052
}))
10501053
};
10511054
self.var_indices.insert(var, LocalsForNode::One(local));

0 commit comments

Comments
 (0)