From 94169ee504bf1a5e59530c1ab1f5f5550ae45914 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 16:07:02 +0200 Subject: ItemTree: Use more boxed slices --- crates/ra_hir_def/src/data.rs | 4 ++-- crates/ra_hir_def/src/item_tree.rs | 10 +++++----- crates/ra_hir_def/src/item_tree/lower.rs | 15 +++++++++++---- crates/ra_hir_def/src/item_tree/tests.rs | 8 ++++---- 4 files changed, 22 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 5ca331380..f9e5701db 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -38,7 +38,7 @@ impl FunctionData { Arc::new(FunctionData { name: func.name.clone(), - params: func.params.clone(), + params: func.params.to_vec(), ret_type: func.ret_type.clone(), attrs: item_tree.attrs(loc.id.value.into()).clone(), has_self_param: func.has_self_param, @@ -70,7 +70,7 @@ impl TypeAliasData { name: typ.name.clone(), type_ref: typ.type_ref.clone(), visibility: item_tree[typ.visibility].clone(), - bounds: typ.bounds.clone(), + bounds: typ.bounds.to_vec(), }) } } diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 9e1fd904f..5155b6111 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -438,7 +438,7 @@ pub struct Function { pub generic_params: GenericParamsId, pub has_self_param: bool, pub is_unsafe: bool, - pub params: Vec, + pub params: Box<[TypeRef]>, pub ret_type: TypeRef, pub ast_id: FileAstId, } @@ -505,7 +505,7 @@ pub struct Trait { pub visibility: RawVisibilityId, pub generic_params: GenericParamsId, pub auto: bool, - pub items: Vec, + pub items: Box<[AssocItem]>, pub ast_id: FileAstId, } @@ -515,7 +515,7 @@ pub struct Impl { pub target_trait: Option, pub target_type: TypeRef, pub is_negative: bool, - pub items: Vec, + pub items: Box<[AssocItem]>, pub ast_id: FileAstId, } @@ -524,7 +524,7 @@ pub struct TypeAlias { pub name: Name, pub visibility: RawVisibilityId, /// Bounds on the type alias itself. Only valid in trait declarations, eg. `type Assoc: Copy;`. - pub bounds: Vec, + pub bounds: Box<[TypeBound]>, pub generic_params: GenericParamsId, pub type_ref: Option, pub ast_id: FileAstId, @@ -541,7 +541,7 @@ pub struct Mod { #[derive(Debug, Clone, Eq, PartialEq)] pub enum ModKind { /// `mod m { ... }` - Inline { items: Vec }, + Inline { items: Box<[ModItem]> }, /// `mod m;` Outline {}, diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index b1847a6cb..6e31266a2 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -325,7 +325,7 @@ impl Ctx { generic_params: GenericParamsId::EMPTY, has_self_param, is_unsafe: func.unsafe_token().is_some(), - params, + params: params.into_boxed_slice(), ret_type, ast_id, }; @@ -344,7 +344,14 @@ impl Ctx { let bounds = self.lower_type_bounds(type_alias); let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias); let ast_id = self.source_ast_id_map.ast_id(type_alias); - let res = TypeAlias { name, visibility, bounds, generic_params, type_ref, ast_id }; + let res = TypeAlias { + name, + visibility, + bounds: bounds.into_boxed_slice(), + generic_params, + type_ref, + ast_id, + }; Some(id(self.data().type_aliases.alloc(res))) } @@ -384,7 +391,7 @@ impl Ctx { }) .unwrap_or_else(|| { mark::hit!(name_res_works_for_broken_modules); - Vec::new() + Box::new([]) as Box<[_]> }), } }; @@ -552,7 +559,7 @@ impl Ctx { GenericsOwner::Function(func) => { generics.fill(&self.body_ctx, sm, node); // lower `impl Trait` in arguments - for param in &func.params { + for param in &*func.params { generics.fill_implicit_impl_trait_args(param); } } diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index b72f0f47b..cd4c8a199 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -31,7 +31,7 @@ fn test_inner_items(ra_fixture: &str) { ModItem::TypeAlias(it) => tree.source(&db, InFile::new(file_id, it)).into(), ModItem::Mod(it) => { if let ModKind::Inline { items } = &tree[it].kind { - worklist.extend(items); + worklist.extend(&**items); } tree.source(&db, InFile::new(file_id, it)).into() } @@ -125,14 +125,14 @@ fn fmt_mod_item(out: &mut String, tree: &ItemTree, item: ModItem) { } ModItem::Trait(it) => { format_to!(out, "{:?}", tree[it]); - for item in &tree[it].items { + for item in &*tree[it].items { fmt_mod_item(&mut children, tree, ModItem::from(*item)); format_to!(children, "\n"); } } ModItem::Impl(it) => { format_to!(out, "{:?}", tree[it]); - for item in &tree[it].items { + for item in &*tree[it].items { fmt_mod_item(&mut children, tree, ModItem::from(*item)); format_to!(children, "\n"); } @@ -144,7 +144,7 @@ fn fmt_mod_item(out: &mut String, tree: &ItemTree, item: ModItem) { format_to!(out, "{:?}", tree[it]); match &tree[it].kind { ModKind::Inline { items } => { - for item in items { + for item in &**items { fmt_mod_item(&mut children, tree, *item); format_to!(children, "\n"); } -- cgit v1.2.3