Skip to content

Commit 879cac4

Browse files
committed
minor: Remove dead code
1 parent 3427d36 commit 879cac4

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

crates/hir-def/src/body.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ pub struct Body {
271271
pub exprs: Arena<Expr>,
272272
pub pats: Arena<Pat>,
273273
pub bindings: Arena<Binding>,
274-
pub or_pats: FxHashMap<PatId, Arc<[PatId]>>,
275274
pub labels: Arena<Label>,
276275
/// The patterns for the function's parameters. While the parameter types are
277276
/// part of the function signature, the patterns are not (they don't change
@@ -410,18 +409,6 @@ impl Body {
410409
.map(move |&block| (block, db.block_def_map(block).expect("block ID without DefMap")))
411410
}
412411

413-
pub fn pattern_representative(&self, pat: PatId) -> PatId {
414-
self.or_pats.get(&pat).and_then(|pats| pats.first().copied()).unwrap_or(pat)
415-
}
416-
417-
/// Retrieves all ident patterns this pattern shares the ident with.
418-
pub fn ident_patterns_for<'slf>(&'slf self, pat: &'slf PatId) -> &'slf [PatId] {
419-
match self.or_pats.get(pat) {
420-
Some(pats) => pats,
421-
None => std::slice::from_ref(pat),
422-
}
423-
}
424-
425412
pub fn pretty_print(&self, db: &dyn DefDatabase, owner: DefWithBodyId) -> String {
426413
pretty::print_body_hir(db, self, owner)
427414
}
@@ -436,19 +423,9 @@ impl Body {
436423
}
437424

438425
fn shrink_to_fit(&mut self) {
439-
let Self {
440-
_c: _,
441-
body_expr: _,
442-
block_scopes,
443-
or_pats,
444-
exprs,
445-
labels,
446-
params,
447-
pats,
448-
bindings,
449-
} = self;
426+
let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
427+
self;
450428
block_scopes.shrink_to_fit();
451-
or_pats.shrink_to_fit();
452429
exprs.shrink_to_fit();
453430
labels.shrink_to_fit();
454431
params.shrink_to_fit();
@@ -464,7 +441,6 @@ impl Default for Body {
464441
exprs: Default::default(),
465442
pats: Default::default(),
466443
bindings: Default::default(),
467-
or_pats: Default::default(),
468444
labels: Default::default(),
469445
params: Default::default(),
470446
block_scopes: Default::default(),

crates/hir-def/src/body/lower.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ pub(super) fn lower(
9494
body_expr: dummy_expr_id(),
9595
block_scopes: Vec::new(),
9696
_c: Count::new(),
97-
or_pats: Default::default(),
9897
},
9998
expander,
100-
name_to_pat_grouping: Default::default(),
101-
is_lowering_inside_or_pat: false,
10299
is_lowering_assignee_expr: false,
103100
is_lowering_generator: false,
104101
}
@@ -111,9 +108,6 @@ struct ExprCollector<'a> {
111108
ast_id_map: Arc<AstIdMap>,
112109
body: Body,
113110
source_map: BodySourceMap,
114-
// a poor-mans union-find?
115-
name_to_pat_grouping: FxHashMap<Name, Vec<PatId>>,
116-
is_lowering_inside_or_pat: bool,
117111
is_lowering_assignee_expr: bool,
118112
is_lowering_generator: bool,
119113
}
@@ -824,13 +818,7 @@ impl ExprCollector<'_> {
824818
}
825819

826820
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
827-
let pat_id = self.collect_pat_(pat, &mut BindingList::default());
828-
for (_, pats) in self.name_to_pat_grouping.drain() {
829-
let pats = Arc::<[_]>::from(pats);
830-
self.body.or_pats.extend(pats.iter().map(|&pat| (pat, pats.clone())));
831-
}
832-
self.is_lowering_inside_or_pat = false;
833-
pat_id
821+
self.collect_pat_(pat, &mut BindingList::default())
834822
}
835823

836824
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
@@ -845,13 +833,13 @@ impl ExprCollector<'_> {
845833
ast::Pat::IdentPat(bp) => {
846834
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
847835

848-
let key = self.is_lowering_inside_or_pat.then(|| name.clone());
849836
let annotation =
850837
BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some());
851838
let subpat = bp.pat().map(|subpat| self.collect_pat_(subpat, binding_list));
852-
let (binding, pattern) = if annotation == BindingAnnotation::Unannotated
853-
&& subpat.is_none()
854-
{
839+
840+
let is_simple_ident_pat =
841+
annotation == BindingAnnotation::Unannotated && subpat.is_none();
842+
let (binding, pattern) = if is_simple_ident_pat {
855843
// This could also be a single-segment path pattern. To
856844
// decide that, we need to try resolving the name.
857845
let (resolved, _) = self.expander.def_map.resolve_path(
@@ -892,9 +880,6 @@ impl ExprCollector<'_> {
892880
if let Some(binding_id) = binding {
893881
self.add_definition_to_binding(binding_id, pat);
894882
}
895-
if let Some(key) = key {
896-
self.name_to_pat_grouping.entry(key).or_default().push(pat);
897-
}
898883
return pat;
899884
}
900885
ast::Pat::TupleStructPat(p) => {
@@ -914,7 +899,6 @@ impl ExprCollector<'_> {
914899
path.map(Pat::Path).unwrap_or(Pat::Missing)
915900
}
916901
ast::Pat::OrPat(p) => {
917-
self.is_lowering_inside_or_pat = true;
918902
let pats = p.pats().map(|p| self.collect_pat_(p, binding_list)).collect();
919903
Pat::Or(pats)
920904
}

crates/hir/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,10 +2501,6 @@ impl GenericDef {
25012501
}
25022502

25032503
/// A single local definition.
2504-
///
2505-
/// If the definition of this is part of a "MultiLocal", that is a local that has multiple declarations due to or-patterns
2506-
/// then this only references a single one of those.
2507-
/// To retrieve the other locals you should use [`Local::associated_locals`]
25082504
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
25092505
pub struct Local {
25102506
pub(crate) parent: DefWithBodyId,

0 commit comments

Comments
 (0)