diff options
-rw-r--r-- | crates/ra_hir_def/src/visibility.rs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs index a90ba7376..ad3f09981 100644 --- a/crates/ra_hir_def/src/visibility.rs +++ b/crates/ra_hir_def/src/visibility.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | //! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`). | 1 | //! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`). |
2 | 2 | ||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir_expand::{hygiene::Hygiene, InFile}; | 3 | use hir_expand::{hygiene::Hygiene, InFile}; |
6 | use ra_syntax::ast; | 4 | use ra_syntax::ast; |
7 | 5 | ||
@@ -14,20 +12,17 @@ use crate::{ | |||
14 | /// Visibility of an item, not yet resolved. | 12 | /// Visibility of an item, not yet resolved. |
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 13 | #[derive(Debug, Clone, PartialEq, Eq)] |
16 | pub enum RawVisibility { | 14 | pub enum RawVisibility { |
17 | // FIXME: We could avoid the allocation in many cases by special-casing | ||
18 | // pub(crate), pub(super) and private. Alternatively, `ModPath` could be | ||
19 | // made to contain an Arc<[Segment]> instead of a Vec? | ||
20 | /// `pub(in module)`, `pub(crate)` or `pub(super)`. Also private, which is | 15 | /// `pub(in module)`, `pub(crate)` or `pub(super)`. Also private, which is |
21 | /// equivalent to `pub(self)`. | 16 | /// equivalent to `pub(self)`. |
22 | Module(Arc<ModPath>), | 17 | Module(ModPath), |
23 | /// `pub`. | 18 | /// `pub`. |
24 | Public, | 19 | Public, |
25 | } | 20 | } |
26 | 21 | ||
27 | impl RawVisibility { | 22 | impl RawVisibility { |
28 | fn private() -> RawVisibility { | 23 | const fn private() -> RawVisibility { |
29 | let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() }; | 24 | let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() }; |
30 | RawVisibility::Module(Arc::new(path)) | 25 | RawVisibility::Module(path) |
31 | } | 26 | } |
32 | 27 | ||
33 | pub(crate) fn from_ast( | 28 | pub(crate) fn from_ast( |
@@ -52,15 +47,15 @@ impl RawVisibility { | |||
52 | None => return RawVisibility::private(), | 47 | None => return RawVisibility::private(), |
53 | Some(path) => path, | 48 | Some(path) => path, |
54 | }; | 49 | }; |
55 | RawVisibility::Module(Arc::new(path)) | 50 | RawVisibility::Module(path) |
56 | } | 51 | } |
57 | ast::VisibilityKind::PubCrate => { | 52 | ast::VisibilityKind::PubCrate => { |
58 | let path = ModPath { kind: PathKind::Crate, segments: Vec::new() }; | 53 | let path = ModPath { kind: PathKind::Crate, segments: Vec::new() }; |
59 | RawVisibility::Module(Arc::new(path)) | 54 | RawVisibility::Module(path) |
60 | } | 55 | } |
61 | ast::VisibilityKind::PubSuper => { | 56 | ast::VisibilityKind::PubSuper => { |
62 | let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; | 57 | let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; |
63 | RawVisibility::Module(Arc::new(path)) | 58 | RawVisibility::Module(path) |
64 | } | 59 | } |
65 | ast::VisibilityKind::Pub => RawVisibility::Public, | 60 | ast::VisibilityKind::Pub => RawVisibility::Public, |
66 | } | 61 | } |