diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index e02ac2c2f3..d55c189d4e 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -218,6 +218,7 @@ impl GenericParams { GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => FileId(!0).into(), }; + generics.shrink_to_fit(); (generics, InFile::new(file_id, sm)) } @@ -371,6 +372,14 @@ impl GenericParams { }); } + pub(crate) fn shrink_to_fit(&mut self) { + let Self { consts, lifetimes, types, where_predicates } = self; + consts.shrink_to_fit(); + lifetimes.shrink_to_fit(); + types.shrink_to_fit(); + where_predicates.shrink_to_fit(); + } + pub fn find_type_by_name(&self, name: &Name) -> Option { self.types .iter() diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index ab7ad83102..0c8112ddab 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -739,6 +739,7 @@ impl Ctx { } } + generics.shrink_to_fit(); self.data().generics.alloc(generics) }