Skip to content

Commit 336dee3

Browse files
committed
Remove some allocs
1 parent 1389069 commit 336dee3

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

crates/hir-ty/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,17 @@ pub enum ImplTraitId {
603603
}
604604
impl_intern_value_trivial!(ImplTraitId);
605605

606-
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
606+
#[derive(PartialEq, Eq, Debug, Hash)]
607607
pub struct ImplTraits {
608608
pub(crate) impl_traits: Arena<ImplTrait>,
609609
}
610610

611611
has_interner!(ImplTraits);
612612

613-
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
613+
#[derive(PartialEq, Eq, Debug, Hash)]
614614
pub struct ImplTrait {
615+
// FIXME: Should be Arc<[QuantifiedWhereClause]>, but the HasInterner impl for Arc is missing a
616+
// ?Sized bound
615617
pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>,
616618
}
617619

crates/hir-ty/src/lower.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'a> TyLoweringContext<'a> {
316316
// place even if we encounter more opaque types while
317317
// lowering the bounds
318318
let idx = opaque_type_data.borrow_mut().alloc(ImplTrait {
319-
bounds: crate::make_single_type_binders(Vec::new()),
319+
bounds: crate::make_single_type_binders(Vec::default()),
320320
});
321321
// We don't want to lower the bounds inside the binders
322322
// we're currently in, because they don't end up inside
@@ -1007,11 +1007,11 @@ impl<'a> TyLoweringContext<'a> {
10071007
self.substs_from_path_segment(segment, Some(resolved.into()), false, explicit_self_ty)
10081008
}
10091009

1010-
pub(crate) fn lower_where_predicate(
1011-
&self,
1012-
where_predicate: &WherePredicate,
1010+
pub(crate) fn lower_where_predicate<'b>(
1011+
&'b self,
1012+
where_predicate: &'b WherePredicate,
10131013
ignore_bindings: bool,
1014-
) -> impl Iterator<Item = QuantifiedWhereClause> {
1014+
) -> impl Iterator<Item = QuantifiedWhereClause> + 'b {
10151015
match where_predicate {
10161016
WherePredicate::ForLifetime { target, bound, .. }
10171017
| WherePredicate::TypeBound { target, bound } => {
@@ -1034,18 +1034,16 @@ impl<'a> TyLoweringContext<'a> {
10341034
.intern(Interner)
10351035
}
10361036
};
1037-
self.lower_type_bound(bound, self_ty, ignore_bindings)
1038-
.collect::<Vec<_>>()
1039-
.into_iter()
1037+
Either::Left(self.lower_type_bound(bound, self_ty, ignore_bindings))
10401038
}
1041-
WherePredicate::Lifetime { bound, target } => {
1042-
vec![crate::wrap_empty_binders(WhereClause::LifetimeOutlives(LifetimeOutlives {
1039+
WherePredicate::Lifetime { bound, target } => Either::Right(iter::once(
1040+
crate::wrap_empty_binders(WhereClause::LifetimeOutlives(LifetimeOutlives {
10431041
a: self.lower_lifetime(bound),
10441042
b: self.lower_lifetime(target),
1045-
}))]
1046-
.into_iter()
1047-
}
1043+
})),
1044+
)),
10481045
}
1046+
.into_iter()
10491047
}
10501048

10511049
pub(crate) fn lower_type_bound(
@@ -1380,8 +1378,8 @@ impl<'a> TyLoweringContext<'a> {
13801378
crate::wrap_empty_binders(clause)
13811379
});
13821380
predicates.extend(sized_clause);
1383-
predicates.shrink_to_fit();
13841381
}
1382+
predicates.shrink_to_fit();
13851383
predicates
13861384
});
13871385
ImplTrait { bounds: crate::make_single_type_binders(predicates) }

0 commit comments

Comments
 (0)