Skip to content

Commit a3a436e

Browse files
committed
Introduce VarBindingIntroduction.
1 parent fcdf963 commit a3a436e

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
@@ -882,8 +882,9 @@ pub struct VarBindingForm<'tcx> {
882882
pub opt_match_place: Option<(Option<Place<'tcx>>, Span)>,
883883
/// The span of the pattern in which this variable was bound.
884884
pub pat_span: Span,
885-
/// For each introduction place, record here the span and whether this was a shorthand pattern.
886-
pub introductions: Vec<(Span, /* is_shorthand */ bool)>,
885+
/// A binding can be introduced multiple times, with or patterns:
886+
/// `Foo::A { x } | Foo::B { z: x }`. This stores information for each of those introductions.
887+
pub introductions: Vec<VarBindingIntroduction>,
887888
}
888889

889890
#[derive(Clone, Debug, TyEncodable, TyDecodable)]
@@ -896,6 +897,14 @@ pub enum BindingForm<'tcx> {
896897
RefForGuard,
897898
}
898899

900+
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
901+
pub struct VarBindingIntroduction {
902+
/// Where this additional introduction happened.
903+
pub span: Span,
904+
/// Is that introduction a shorthand struct pattern, i.e. `Foo { x }`.
905+
pub is_shorthand: bool,
906+
}
907+
899908
mod binding_form_impl {
900909
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
901910
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
@@ -817,7 +817,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
817817
}
818818
let local_info = self.local_decls[local_id].local_info.as_mut().unwrap_crate_local();
819819
if let LocalInfo::User(BindingForm::Var(var_info)) = &mut **local_info {
820-
var_info.introductions.push((span, is_shorthand));
820+
var_info.introductions.push(VarBindingIntroduction { span, is_shorthand });
821821
}
822822
Place::from(local_id)
823823
}

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10541054
opt_ty_info: param.ty_span,
10551055
opt_match_place: Some((None, span)),
10561056
pat_span: span,
1057-
introductions: vec![(span, false)],
1057+
introductions: vec![VarBindingIntroduction {
1058+
span,
1059+
is_shorthand: false,
1060+
}],
10581061
}))
10591062
};
10601063
self.var_indices.insert(var, LocalsForNode::One(local));

0 commit comments

Comments
 (0)