mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
ItemTree: Use more boxed slices
This commit is contained in:
parent
abdba92334
commit
94169ee504
4 changed files with 22 additions and 15 deletions
|
@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ pub struct Function {
|
|||
pub generic_params: GenericParamsId,
|
||||
pub has_self_param: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub params: Vec<TypeRef>,
|
||||
pub params: Box<[TypeRef]>,
|
||||
pub ret_type: TypeRef,
|
||||
pub ast_id: FileAstId<ast::FnDef>,
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ pub struct Trait {
|
|||
pub visibility: RawVisibilityId,
|
||||
pub generic_params: GenericParamsId,
|
||||
pub auto: bool,
|
||||
pub items: Vec<AssocItem>,
|
||||
pub items: Box<[AssocItem]>,
|
||||
pub ast_id: FileAstId<ast::TraitDef>,
|
||||
}
|
||||
|
||||
|
@ -515,7 +515,7 @@ pub struct Impl {
|
|||
pub target_trait: Option<TypeRef>,
|
||||
pub target_type: TypeRef,
|
||||
pub is_negative: bool,
|
||||
pub items: Vec<AssocItem>,
|
||||
pub items: Box<[AssocItem]>,
|
||||
pub ast_id: FileAstId<ast::ImplDef>,
|
||||
}
|
||||
|
||||
|
@ -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<TypeBound>,
|
||||
pub bounds: Box<[TypeBound]>,
|
||||
pub generic_params: GenericParamsId,
|
||||
pub type_ref: Option<TypeRef>,
|
||||
pub ast_id: FileAstId<ast::TypeAliasDef>,
|
||||
|
@ -541,7 +541,7 @@ pub struct Mod {
|
|||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum ModKind {
|
||||
/// `mod m { ... }`
|
||||
Inline { items: Vec<ModItem> },
|
||||
Inline { items: Box<[ModItem]> },
|
||||
|
||||
/// `mod m;`
|
||||
Outline {},
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue