diff options
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 164 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 51 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/tests.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/visibility.rs | 21 |
5 files changed, 90 insertions, 152 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 697fde3d2..921253c42 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -2,23 +2,16 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::{ | 5 | use hir_expand::{name::Name, InFile}; |
6 | hygiene::Hygiene, | ||
7 | name::{name, AsName, Name}, | ||
8 | InFile, | ||
9 | }; | ||
10 | use ra_prof::profile; | 6 | use ra_prof::profile; |
11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, TypeBoundsOwner, VisibilityOwner}; | 7 | use ra_syntax::ast; |
12 | 8 | ||
13 | use crate::{ | 9 | use crate::{ |
14 | attr::Attrs, | 10 | attr::Attrs, |
15 | body::Expander, | 11 | body::Expander, |
16 | body::LowerCtx, | ||
17 | db::DefDatabase, | 12 | db::DefDatabase, |
18 | item_tree::{AssocItem, ItemTreeId, ModItem}, | 13 | item_tree::{AssocItem, ItemTreeId, ModItem}, |
19 | path::{path, AssociatedTypeBinding, GenericArgs, Path}, | 14 | type_ref::{TypeBound, TypeRef}, |
20 | src::HasSource, | ||
21 | type_ref::{Mutability, TypeBound, TypeRef}, | ||
22 | visibility::RawVisibility, | 15 | visibility::RawVisibility, |
23 | AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, | 16 | AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, |
24 | Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, | 17 | Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
@@ -40,82 +33,27 @@ pub struct FunctionData { | |||
40 | impl FunctionData { | 33 | impl FunctionData { |
41 | pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc<FunctionData> { | 34 | pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc<FunctionData> { |
42 | let loc = func.lookup(db); | 35 | let loc = func.lookup(db); |
43 | let src = loc.source(db); | 36 | let item_tree = db.item_tree(loc.id.file_id); |
44 | let ctx = LowerCtx::new(db, src.file_id); | 37 | let func = &item_tree[loc.id.value]; |
45 | let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 38 | |
46 | let mut params = Vec::new(); | 39 | Arc::new(FunctionData { |
47 | let mut has_self_param = false; | 40 | name: func.name.clone(), |
48 | if let Some(param_list) = src.value.param_list() { | 41 | params: func.params.clone(), |
49 | if let Some(self_param) = param_list.self_param() { | 42 | ret_type: func.ret_type.clone(), |
50 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 43 | attrs: func.attrs.clone(), |
51 | TypeRef::from_ast(&ctx, type_ref) | 44 | has_self_param: func.has_self_param, |
52 | } else { | 45 | is_unsafe: func.is_unsafe, |
53 | let self_type = TypeRef::Path(name![Self].into()); | 46 | visibility: func.visibility.clone(), |
54 | match self_param.kind() { | 47 | }) |
55 | ast::SelfParamKind::Owned => self_type, | ||
56 | ast::SelfParamKind::Ref => { | ||
57 | TypeRef::Reference(Box::new(self_type), Mutability::Shared) | ||
58 | } | ||
59 | ast::SelfParamKind::MutRef => { | ||
60 | TypeRef::Reference(Box::new(self_type), Mutability::Mut) | ||
61 | } | ||
62 | } | ||
63 | }; | ||
64 | params.push(self_type); | ||
65 | has_self_param = true; | ||
66 | } | ||
67 | for param in param_list.params() { | ||
68 | let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); | ||
69 | params.push(type_ref); | ||
70 | } | ||
71 | } | ||
72 | let attrs = Attrs::new(&src.value, &Hygiene::new(db.upcast(), src.file_id)); | ||
73 | |||
74 | let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) { | ||
75 | TypeRef::from_ast(&ctx, type_ref) | ||
76 | } else { | ||
77 | TypeRef::unit() | ||
78 | }; | ||
79 | |||
80 | let ret_type = if src.value.async_token().is_some() { | ||
81 | let future_impl = desugar_future_path(ret_type); | ||
82 | let ty_bound = TypeBound::Path(future_impl); | ||
83 | TypeRef::ImplTrait(vec![ty_bound]) | ||
84 | } else { | ||
85 | ret_type | ||
86 | }; | ||
87 | |||
88 | let is_unsafe = src.value.unsafe_token().is_some(); | ||
89 | |||
90 | let vis_default = RawVisibility::default_for_container(loc.container); | ||
91 | let visibility = | ||
92 | RawVisibility::from_ast_with_default(db, vis_default, src.map(|s| s.visibility())); | ||
93 | |||
94 | let sig = | ||
95 | FunctionData { name, params, ret_type, has_self_param, is_unsafe, visibility, attrs }; | ||
96 | Arc::new(sig) | ||
97 | } | 48 | } |
98 | } | 49 | } |
99 | 50 | ||
100 | fn desugar_future_path(orig: TypeRef) -> Path { | ||
101 | let path = path![core::future::Future]; | ||
102 | let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect(); | ||
103 | let mut last = GenericArgs::empty(); | ||
104 | last.bindings.push(AssociatedTypeBinding { | ||
105 | name: name![Output], | ||
106 | type_ref: Some(orig), | ||
107 | bounds: Vec::new(), | ||
108 | }); | ||
109 | generic_args.push(Some(Arc::new(last))); | ||
110 | |||
111 | Path::from_known_path(path, generic_args) | ||
112 | } | ||
113 | |||
114 | #[derive(Debug, Clone, PartialEq, Eq)] | 51 | #[derive(Debug, Clone, PartialEq, Eq)] |
115 | pub struct TypeAliasData { | 52 | pub struct TypeAliasData { |
116 | pub name: Name, | 53 | pub name: Name, |
117 | pub type_ref: Option<TypeRef>, | 54 | pub type_ref: Option<TypeRef>, |
118 | pub visibility: RawVisibility, | 55 | pub visibility: RawVisibility, |
56 | /// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl). | ||
119 | pub bounds: Vec<TypeBound>, | 57 | pub bounds: Vec<TypeBound>, |
120 | } | 58 | } |
121 | 59 | ||
@@ -125,22 +63,15 @@ impl TypeAliasData { | |||
125 | typ: TypeAliasId, | 63 | typ: TypeAliasId, |
126 | ) -> Arc<TypeAliasData> { | 64 | ) -> Arc<TypeAliasData> { |
127 | let loc = typ.lookup(db); | 65 | let loc = typ.lookup(db); |
128 | let node = loc.source(db); | 66 | let item_tree = db.item_tree(loc.id.file_id); |
129 | let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); | 67 | let typ = &item_tree[loc.id.value]; |
130 | let lower_ctx = LowerCtx::new(db, node.file_id); | 68 | |
131 | let type_ref = node.value.type_ref().map(|it| TypeRef::from_ast(&lower_ctx, it)); | 69 | Arc::new(TypeAliasData { |
132 | let vis_default = RawVisibility::default_for_container(loc.container); | 70 | name: typ.name.clone(), |
133 | let visibility = RawVisibility::from_ast_with_default( | 71 | type_ref: typ.type_ref.clone(), |
134 | db, | 72 | visibility: typ.visibility.clone(), |
135 | vis_default, | 73 | bounds: typ.bounds.clone(), |
136 | node.as_ref().map(|n| n.visibility()), | 74 | }) |
137 | ); | ||
138 | let bounds = if let Some(bound_list) = node.value.type_bound_list() { | ||
139 | bound_list.bounds().map(|it| TypeBound::from_ast(&lower_ctx, it)).collect() | ||
140 | } else { | ||
141 | Vec::new() | ||
142 | }; | ||
143 | Arc::new(TypeAliasData { name, type_ref, visibility, bounds }) | ||
144 | } | 75 | } |
145 | } | 76 | } |
146 | 77 | ||
@@ -238,22 +169,14 @@ pub struct ConstData { | |||
238 | impl ConstData { | 169 | impl ConstData { |
239 | pub(crate) fn const_data_query(db: &dyn DefDatabase, konst: ConstId) -> Arc<ConstData> { | 170 | pub(crate) fn const_data_query(db: &dyn DefDatabase, konst: ConstId) -> Arc<ConstData> { |
240 | let loc = konst.lookup(db); | 171 | let loc = konst.lookup(db); |
241 | let node = loc.source(db); | 172 | let item_tree = db.item_tree(loc.id.file_id); |
242 | let vis_default = RawVisibility::default_for_container(loc.container); | 173 | let konst = &item_tree[loc.id.value]; |
243 | Arc::new(ConstData::new(db, vis_default, node)) | ||
244 | } | ||
245 | 174 | ||
246 | fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>( | 175 | Arc::new(ConstData { |
247 | db: &dyn DefDatabase, | 176 | name: konst.name.clone(), |
248 | vis_default: RawVisibility, | 177 | type_ref: konst.type_ref.clone(), |
249 | node: InFile<N>, | 178 | visibility: konst.visibility.clone(), |
250 | ) -> ConstData { | 179 | }) |
251 | let ctx = LowerCtx::new(db, node.file_id); | ||
252 | let name = node.value.name().map(|n| n.as_name()); | ||
253 | let type_ref = TypeRef::from_ast_opt(&ctx, node.value.ascribed_type()); | ||
254 | let visibility = | ||
255 | RawVisibility::from_ast_with_default(db, vis_default, node.map(|n| n.visibility())); | ||
256 | ConstData { name, type_ref, visibility } | ||
257 | } | 180 | } |
258 | } | 181 | } |
259 | 182 | ||
@@ -267,19 +190,16 @@ pub struct StaticData { | |||
267 | 190 | ||
268 | impl StaticData { | 191 | impl StaticData { |
269 | pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<StaticData> { | 192 | pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<StaticData> { |
270 | let node = konst.lookup(db).source(db); | 193 | let node = konst.lookup(db); |
271 | let ctx = LowerCtx::new(db, node.file_id); | 194 | let item_tree = db.item_tree(node.id.file_id); |
272 | 195 | let statik = &item_tree[node.id.value]; | |
273 | let name = node.value.name().map(|n| n.as_name()); | 196 | |
274 | let type_ref = TypeRef::from_ast_opt(&ctx, node.value.ascribed_type()); | 197 | Arc::new(StaticData { |
275 | let mutable = node.value.mut_token().is_some(); | 198 | name: Some(statik.name.clone()), |
276 | let visibility = RawVisibility::from_ast_with_default( | 199 | type_ref: statik.type_ref.clone(), |
277 | db, | 200 | visibility: statik.visibility.clone(), |
278 | RawVisibility::private(), | 201 | mutable: statik.mutable, |
279 | node.map(|n| n.visibility()), | 202 | }) |
280 | ); | ||
281 | |||
282 | Arc::new(StaticData { name, type_ref, visibility, mutable }) | ||
283 | } | 203 | } |
284 | } | 204 | } |
285 | 205 | ||
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 9a5dd701e..c35d63295 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs | |||
@@ -349,6 +349,7 @@ pub struct Function { | |||
349 | pub visibility: RawVisibility, | 349 | pub visibility: RawVisibility, |
350 | pub generic_params: GenericParams, | 350 | pub generic_params: GenericParams, |
351 | pub has_self_param: bool, | 351 | pub has_self_param: bool, |
352 | pub is_unsafe: bool, | ||
352 | pub params: Vec<TypeRef>, | 353 | pub params: Vec<TypeRef>, |
353 | pub ret_type: TypeRef, | 354 | pub ret_type: TypeRef, |
354 | pub ast_id: FileAstId<ast::FnDef>, | 355 | pub ast_id: FileAstId<ast::FnDef>, |
@@ -408,6 +409,7 @@ pub struct Const { | |||
408 | pub struct Static { | 409 | pub struct Static { |
409 | pub name: Name, | 410 | pub name: Name, |
410 | pub visibility: RawVisibility, | 411 | pub visibility: RawVisibility, |
412 | pub mutable: bool, | ||
411 | pub type_ref: TypeRef, | 413 | pub type_ref: TypeRef, |
412 | pub ast_id: FileAstId<ast::StaticDef>, | 414 | pub ast_id: FileAstId<ast::StaticDef>, |
413 | } | 415 | } |
@@ -436,6 +438,8 @@ pub struct Impl { | |||
436 | pub struct TypeAlias { | 438 | pub struct TypeAlias { |
437 | pub name: Name, | 439 | pub name: Name, |
438 | pub visibility: RawVisibility, | 440 | pub visibility: RawVisibility, |
441 | /// Bounds on the type alias itself. Only valid in trait declarations, eg. `type Assoc: Copy;`. | ||
442 | pub bounds: Vec<TypeBound>, | ||
439 | pub generic_params: GenericParams, | 443 | pub generic_params: GenericParams, |
440 | pub type_ref: Option<TypeRef>, | 444 | pub type_ref: Option<TypeRef>, |
441 | pub ast_id: FileAstId<ast::TypeAliasDef>, | 445 | pub ast_id: FileAstId<ast::TypeAliasDef>, |
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index f2b8a9418..42af8bb5e 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs | |||
@@ -36,6 +36,7 @@ pub(super) struct Ctx { | |||
36 | source_ast_id_map: Arc<AstIdMap>, | 36 | source_ast_id_map: Arc<AstIdMap>, |
37 | body_ctx: crate::body::LowerCtx, | 37 | body_ctx: crate::body::LowerCtx, |
38 | inner_items: Vec<ModItem>, | 38 | inner_items: Vec<ModItem>, |
39 | forced_visibility: Option<RawVisibility>, | ||
39 | } | 40 | } |
40 | 41 | ||
41 | impl Ctx { | 42 | impl Ctx { |
@@ -47,6 +48,7 @@ impl Ctx { | |||
47 | source_ast_id_map: db.ast_id_map(file), | 48 | source_ast_id_map: db.ast_id_map(file), |
48 | body_ctx: crate::body::LowerCtx::new(db, file), | 49 | body_ctx: crate::body::LowerCtx::new(db, file), |
49 | inner_items: Vec::new(), | 50 | inner_items: Vec::new(), |
51 | forced_visibility: None, | ||
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
@@ -117,6 +119,7 @@ impl Ctx { | |||
117 | } | 119 | } |
118 | 120 | ||
119 | fn collect_inner_items(&mut self, container: &SyntaxNode) { | 121 | fn collect_inner_items(&mut self, container: &SyntaxNode) { |
122 | let forced_vis = self.forced_visibility.take(); | ||
120 | let mut inner_items = mem::replace(&mut self.tree.inner_items, FxHashMap::default()); | 123 | let mut inner_items = mem::replace(&mut self.tree.inner_items, FxHashMap::default()); |
121 | inner_items.extend( | 124 | inner_items.extend( |
122 | container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| { | 125 | container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| { |
@@ -125,6 +128,7 @@ impl Ctx { | |||
125 | }), | 128 | }), |
126 | ); | 129 | ); |
127 | self.tree.inner_items = inner_items; | 130 | self.tree.inner_items = inner_items; |
131 | self.forced_visibility = forced_vis; | ||
128 | } | 132 | } |
129 | 133 | ||
130 | fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> { | 134 | fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> { |
@@ -304,6 +308,7 @@ impl Ctx { | |||
304 | visibility, | 308 | visibility, |
305 | generic_params: GenericParams::default(), | 309 | generic_params: GenericParams::default(), |
306 | has_self_param, | 310 | has_self_param, |
311 | is_unsafe: func.unsafe_token().is_some(), | ||
307 | params, | 312 | params, |
308 | ret_type, | 313 | ret_type, |
309 | ast_id, | 314 | ast_id, |
@@ -320,9 +325,10 @@ impl Ctx { | |||
320 | let name = type_alias.name()?.as_name(); | 325 | let name = type_alias.name()?.as_name(); |
321 | let type_ref = type_alias.type_ref().map(|it| self.lower_type_ref(&it)); | 326 | let type_ref = type_alias.type_ref().map(|it| self.lower_type_ref(&it)); |
322 | let visibility = self.lower_visibility(type_alias); | 327 | let visibility = self.lower_visibility(type_alias); |
328 | let bounds = self.lower_type_bounds(type_alias); | ||
323 | let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias); | 329 | let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias); |
324 | let ast_id = self.source_ast_id_map.ast_id(type_alias); | 330 | let ast_id = self.source_ast_id_map.ast_id(type_alias); |
325 | let res = TypeAlias { name, visibility, generic_params, type_ref, ast_id }; | 331 | let res = TypeAlias { name, visibility, bounds, generic_params, type_ref, ast_id }; |
326 | Some(id(self.tree.type_aliases.alloc(res))) | 332 | Some(id(self.tree.type_aliases.alloc(res))) |
327 | } | 333 | } |
328 | 334 | ||
@@ -330,8 +336,9 @@ impl Ctx { | |||
330 | let name = static_.name()?.as_name(); | 336 | let name = static_.name()?.as_name(); |
331 | let type_ref = self.lower_type_ref_opt(static_.ascribed_type()); | 337 | let type_ref = self.lower_type_ref_opt(static_.ascribed_type()); |
332 | let visibility = self.lower_visibility(static_); | 338 | let visibility = self.lower_visibility(static_); |
339 | let mutable = static_.mut_token().is_some(); | ||
333 | let ast_id = self.source_ast_id_map.ast_id(static_); | 340 | let ast_id = self.source_ast_id_map.ast_id(static_); |
334 | let res = Static { name, visibility, type_ref, ast_id }; | 341 | let res = Static { name, visibility, mutable, type_ref, ast_id }; |
335 | Some(id(self.tree.statics.alloc(res))) | 342 | Some(id(self.tree.statics.alloc(res))) |
336 | } | 343 | } |
337 | 344 | ||
@@ -376,12 +383,14 @@ impl Ctx { | |||
376 | let generic_params = self.lower_generic_params(GenericsOwner::Trait(trait_def), trait_def); | 383 | let generic_params = self.lower_generic_params(GenericsOwner::Trait(trait_def), trait_def); |
377 | let auto = trait_def.auto_token().is_some(); | 384 | let auto = trait_def.auto_token().is_some(); |
378 | let items = trait_def.item_list().map(|list| { | 385 | let items = trait_def.item_list().map(|list| { |
379 | list.items() | 386 | self.with_inherited_visibility(visibility.clone(), |this| { |
380 | .flat_map(|item| { | 387 | list.items() |
381 | self.collect_inner_items(item.syntax()); | 388 | .flat_map(|item| { |
382 | self.lower_assoc_item(&item) | 389 | this.collect_inner_items(item.syntax()); |
383 | }) | 390 | this.lower_assoc_item(&item) |
384 | .collect() | 391 | }) |
392 | .collect() | ||
393 | }) | ||
385 | }); | 394 | }); |
386 | let ast_id = self.source_ast_id_map.ast_id(trait_def); | 395 | let ast_id = self.source_ast_id_map.ast_id(trait_def); |
387 | let res = Trait { | 396 | let res = Trait { |
@@ -549,11 +558,23 @@ impl Ctx { | |||
549 | generics | 558 | generics |
550 | } | 559 | } |
551 | 560 | ||
561 | fn lower_type_bounds(&mut self, node: &impl ast::TypeBoundsOwner) -> Vec<TypeBound> { | ||
562 | if let Some(bound_list) = node.type_bound_list() { | ||
563 | bound_list.bounds().map(|it| TypeBound::from_ast(&self.body_ctx, it)).collect() | ||
564 | } else { | ||
565 | Vec::new() | ||
566 | } | ||
567 | } | ||
568 | |||
552 | fn lower_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { | 569 | fn lower_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { |
553 | Attrs::new(item, &self.hygiene) | 570 | Attrs::new(item, &self.hygiene) |
554 | } | 571 | } |
555 | fn lower_visibility(&self, item: &impl ast::VisibilityOwner) -> RawVisibility { | 572 | fn lower_visibility(&self, item: &impl ast::VisibilityOwner) -> RawVisibility { |
556 | RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene) | 573 | if let Some(vis) = self.forced_visibility.as_ref() { |
574 | vis.clone() | ||
575 | } else { | ||
576 | RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene) | ||
577 | } | ||
557 | } | 578 | } |
558 | fn lower_type_ref(&self, type_ref: &ast::TypeRef) -> TypeRef { | 579 | fn lower_type_ref(&self, type_ref: &ast::TypeRef) -> TypeRef { |
559 | TypeRef::from_ast(&self.body_ctx, type_ref.clone()) | 580 | TypeRef::from_ast(&self.body_ctx, type_ref.clone()) |
@@ -562,6 +583,18 @@ impl Ctx { | |||
562 | TypeRef::from_ast_opt(&self.body_ctx, type_ref) | 583 | TypeRef::from_ast_opt(&self.body_ctx, type_ref) |
563 | } | 584 | } |
564 | 585 | ||
586 | /// Forces the visibility `vis` to be used for all items lowered during execution of `f`. | ||
587 | fn with_inherited_visibility<R>( | ||
588 | &mut self, | ||
589 | vis: RawVisibility, | ||
590 | f: impl FnOnce(&mut Self) -> R, | ||
591 | ) -> R { | ||
592 | let old = mem::replace(&mut self.forced_visibility, Some(vis)); | ||
593 | let res = f(self); | ||
594 | self.forced_visibility = old; | ||
595 | res | ||
596 | } | ||
597 | |||
565 | fn next_field_idx(&self) -> Idx<Field> { | 598 | fn next_field_idx(&self) -> Idx<Field> { |
566 | Idx::from_raw(RawId::from(self.tree.fields.len() as u32)) | 599 | Idx::from_raw(RawId::from(self.tree.fields.len() as u32)) |
567 | } | 600 | } |
diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index b60e6cbb0..1db1ce7a9 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs | |||
@@ -204,7 +204,7 @@ Impl { generic_params: GenericParams { types: Arena { len: 0, data: [] }, where_ | |||
204 | 204 | ||
205 | inner items: | 205 | inner items: |
206 | FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2): | 206 | FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2): |
207 | - Function { name: Name(Text("end")), attrs: Attrs { entries: None }, visibility: Module(ModPath { kind: Super(0), segments: [] }), generic_params: GenericParams { types: Arena { len: 1, data: [TypeParamData { name: Some(Name(Text("W"))), default: None, provenance: TypeParamList }] }, where_predicates: [WherePredicate { target: TypeRef(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("W"))] }, generic_args: [None] })), bound: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Write"))] }, generic_args: [None] }) }] }, has_self_param: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } | 207 | - Function { name: Name(Text("end")), attrs: Attrs { entries: None }, visibility: Module(ModPath { kind: Super(0), segments: [] }), generic_params: GenericParams { types: Arena { len: 1, data: [TypeParamData { name: Some(Name(Text("W"))), default: None, provenance: TypeParamList }] }, where_predicates: [WherePredicate { target: TypeRef(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("W"))] }, generic_args: [None] })), bound: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Write"))] }, generic_args: [None] }) }] }, has_self_param: false, is_unsafe: false, params: [], ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) } |
208 | "###); | 208 | "###); |
209 | } | 209 | } |
210 | 210 | ||
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs index 1482d3be0..8136cb50c 100644 --- a/crates/ra_hir_def/src/visibility.rs +++ b/crates/ra_hir_def/src/visibility.rs | |||
@@ -6,7 +6,7 @@ use ra_syntax::ast; | |||
6 | use crate::{ | 6 | use crate::{ |
7 | db::DefDatabase, | 7 | db::DefDatabase, |
8 | path::{ModPath, PathKind}, | 8 | path::{ModPath, PathKind}, |
9 | AssocContainerId, ModuleId, | 9 | ModuleId, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | /// Visibility of an item, not yet resolved. | 12 | /// Visibility of an item, not yet resolved. |
@@ -25,25 +25,6 @@ impl RawVisibility { | |||
25 | RawVisibility::Module(path) | 25 | RawVisibility::Module(path) |
26 | } | 26 | } |
27 | 27 | ||
28 | pub(crate) fn default_for_container(container_id: AssocContainerId) -> Self { | ||
29 | match container_id { | ||
30 | AssocContainerId::TraitId(_) => RawVisibility::Public, | ||
31 | _ => RawVisibility::private(), | ||
32 | } | ||
33 | } | ||
34 | |||
35 | pub(crate) fn from_ast_with_default( | ||
36 | db: &dyn DefDatabase, | ||
37 | default: RawVisibility, | ||
38 | node: InFile<Option<ast::Visibility>>, | ||
39 | ) -> RawVisibility { | ||
40 | Self::from_ast_with_hygiene_and_default( | ||
41 | node.value, | ||
42 | default, | ||
43 | &Hygiene::new(db.upcast(), node.file_id), | ||
44 | ) | ||
45 | } | ||
46 | |||
47 | pub(crate) fn from_ast( | 28 | pub(crate) fn from_ast( |
48 | db: &dyn DefDatabase, | 29 | db: &dyn DefDatabase, |
49 | node: InFile<Option<ast::Visibility>>, | 30 | node: InFile<Option<ast::Visibility>>, |