From 87171238c6c528c421f06de8cd7e41ed3b6ff57a Mon Sep 17 00:00:00 2001 From: oxalica Date: Tue, 16 Mar 2021 00:05:03 +0800 Subject: Use hir formatter more --- crates/hir_def/src/adt.rs | 10 +++++++++- crates/hir_def/src/data.rs | 12 +++++++++--- crates/hir_def/src/item_tree.rs | 4 +++- crates/hir_def/src/item_tree/lower.rs | 8 ++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs index efbde17d8..1b9bb8235 100644 --- a/crates/hir_def/src/adt.rs +++ b/crates/hir_def/src/adt.rs @@ -31,12 +31,14 @@ pub struct StructData { pub name: Name, pub variant_data: Arc, pub repr: Option, + pub visibility: RawVisibility, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct EnumData { pub name: Name, pub variants: Arena, + pub visibility: RawVisibility, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -102,6 +104,7 @@ impl StructData { name: strukt.name.clone(), variant_data: Arc::new(variant_data), repr, + visibility: item_tree[strukt.visibility].clone(), }) } pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc { @@ -118,6 +121,7 @@ impl StructData { name: union.name.clone(), variant_data: Arc::new(variant_data), repr, + visibility: item_tree[union.visibility].clone(), }) } } @@ -150,7 +154,11 @@ impl EnumData { } } - Arc::new(EnumData { name: enum_.name.clone(), variants }) + Arc::new(EnumData { + name: enum_.name.clone(), + variants, + visibility: item_tree[enum_.visibility].clone(), + }) } pub fn variant(&self, name: &Name) -> Option { diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index b09da0697..74a2194e5 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -87,7 +87,10 @@ impl TypeAliasData { pub struct TraitData { pub name: Name, pub items: Vec<(Name, AssocItemId)>, - pub auto: bool, + pub is_auto: bool, + pub is_unsafe: bool, + pub visibility: RawVisibility, + pub bounds: Box<[TypeBound]>, } impl TraitData { @@ -96,10 +99,13 @@ impl TraitData { let item_tree = db.item_tree(tr_loc.id.file_id); let tr_def = &item_tree[tr_loc.id.value]; let name = tr_def.name.clone(); - let auto = tr_def.auto; + let is_auto = tr_def.is_auto; + let is_unsafe = tr_def.is_unsafe; let module_id = tr_loc.container; let container = AssocContainerId::TraitId(tr); let mut expander = Expander::new(db, tr_loc.id.file_id, module_id); + let visibility = item_tree[tr_def.visibility].clone(); + let bounds = tr_def.bounds.clone(); let items = collect_items( db, @@ -111,7 +117,7 @@ impl TraitData { 100, ); - Arc::new(TraitData { name, items, auto }) + Arc::new(TraitData { name, items, is_auto, is_unsafe, visibility, bounds }) } pub fn associated_types(&self) -> impl Iterator + '_ { diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index d8f22d442..d63ac3df3 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -633,7 +633,9 @@ pub struct Trait { pub name: Name, pub visibility: RawVisibilityId, pub generic_params: GenericParamsId, - pub auto: bool, + pub is_auto: bool, + pub is_unsafe: bool, + pub bounds: Box<[TypeBound]>, pub items: Box<[AssocItem]>, pub ast_id: FileAstId, } diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 6b5438dc9..7e91b991d 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -500,7 +500,9 @@ impl Ctx { let visibility = self.lower_visibility(trait_def); let generic_params = self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); - let auto = trait_def.auto_token().is_some(); + let is_auto = trait_def.auto_token().is_some(); + let is_unsafe = trait_def.unsafe_token().is_some(); + let bounds = self.lower_type_bounds(trait_def); let items = trait_def.assoc_item_list().map(|list| { self.with_inherited_visibility(visibility, |this| { list.assoc_items() @@ -520,7 +522,9 @@ impl Ctx { name, visibility, generic_params, - auto, + is_auto, + is_unsafe, + bounds: bounds.into(), items: items.unwrap_or_default(), ast_id, }; -- cgit v1.2.3