Skip to content

Commit 28ee282

Browse files
committed
Introduce VarBindingIntroduction.
1 parent 66c263a commit 28ee282

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

891892
#[derive(Clone, Debug, TyEncodable, TyDecodable)]
@@ -898,6 +899,14 @@ pub enum BindingForm<'tcx> {
898899
RefForGuard,
899900
}
900901

902+
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
903+
pub struct VarBindingIntroduction {
904+
/// Where this additional introduction happened.
905+
pub span: Span,
906+
/// Is that introduction a shorthand struct pattern, i.e. `Foo { x }`.
907+
pub is_shorthand: bool,
908+
}
909+
901910
mod binding_form_impl {
902911
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
903912
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
@@ -1068,7 +1068,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10681068
opt_ty_info: param.ty_span,
10691069
opt_match_place: Some((None, span)),
10701070
pat_span: span,
1071-
introductions: vec![(span, false)],
1071+
introductions: vec![VarBindingIntroduction {
1072+
span,
1073+
is_shorthand: false,
1074+
}],
10721075
}))
10731076
};
10741077
self.var_indices.insert(var, LocalsForNode::One(local));

0 commit comments

Comments
 (0)