aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs2
-rw-r--r--crates/ra_hir_def/src/body.rs2
-rw-r--r--crates/ra_hir_def/src/data.rs15
-rw-r--r--crates/ra_hir_def/src/docs.rs5
-rw-r--r--crates/ra_hir_def/src/lib.rs15
-rw-r--r--crates/ra_hir_def/src/nameres.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs7
-rw-r--r--crates/ra_hir_def/src/path.rs13
-rw-r--r--crates/ra_hir_def/src/per_ns.rs10
-rw-r--r--crates/ra_hir_def/src/resolver.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs8
12 files changed, 44 insertions, 39 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 905bb5bcb..b3e2ff1c2 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -1037,7 +1037,7 @@ impl From<PerNs> for ScopeDef {
1037 .or_else(|| def.take_values()) 1037 .or_else(|| def.take_values())
1038 .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into())) 1038 .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into()))
1039 .or_else(|| { 1039 .or_else(|| {
1040 def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into())) 1040 def.take_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into()))
1041 }) 1041 })
1042 .unwrap_or(ScopeDef::Unknown) 1042 .unwrap_or(ScopeDef::Unknown)
1043 } 1043 }
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 1589085b5..c06997cf1 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -82,7 +82,7 @@ impl Expander {
82 } 82 }
83 83
84 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 84 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
85 self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() 85 self.crate_def_map.resolve_path(db, self.module.module_id, path).0.take_macros()
86 } 86 }
87} 87}
88 88
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 81a8ec18d..68bea34df 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -200,18 +200,17 @@ pub struct ConstData {
200impl ConstData { 200impl ConstData {
201 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> { 201 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> {
202 let node = konst.lookup(db).source(db).value; 202 let node = konst.lookup(db).source(db).value;
203 const_data_for(&node) 203 Arc::new(ConstData::new(&node))
204 } 204 }
205 205
206 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { 206 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> {
207 let node = konst.lookup(db).source(db).value; 207 let node = konst.lookup(db).source(db).value;
208 const_data_for(&node) 208 Arc::new(ConstData::new(&node))
209 } 209 }
210}
211 210
212fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { 211 fn new<N: NameOwner + TypeAscriptionOwner>(node: &N) -> ConstData {
213 let name = node.name().map(|n| n.as_name()); 212 let name = node.name().map(|n| n.as_name());
214 let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); 213 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
215 let sig = ConstData { name, type_ref }; 214 ConstData { name, type_ref }
216 Arc::new(sig) 215 }
217} 216}
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 225511428..90a8627bc 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -1,4 +1,7 @@
1//! FIXME: write short doc here 1//! Defines hir documentation.
2//!
3//! This really shouldn't exist, instead, we should deshugar doc comments into attributes, see
4//! https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102
2 5
3use std::sync::Arc; 6use std::sync::Arc;
4 7
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index f60feb5fa..f63c3dd64 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -8,20 +8,23 @@
8//! actually true. 8//! actually true.
9 9
10pub mod db; 10pub mod db;
11
11pub mod attr; 12pub mod attr;
12pub mod path; 13pub mod path;
13pub mod type_ref; 14pub mod type_ref;
14pub mod builtin_type; 15pub mod builtin_type;
15pub mod adt;
16pub mod diagnostics; 16pub mod diagnostics;
17pub mod expr; 17pub mod per_ns;
18pub mod body; 18
19pub mod generics; 19pub mod adt;
20pub mod resolver;
21pub mod data; 20pub mod data;
21pub mod generics;
22pub mod lang_item; 22pub mod lang_item;
23pub mod docs; 23pub mod docs;
24pub mod per_ns; 24
25pub mod expr;
26pub mod body;
27pub mod resolver;
25 28
26mod trace; 29mod trace;
27mod nameres; 30mod nameres;
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index f6cf59c5f..5919771b0 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -169,7 +169,7 @@ impl ModuleScope {
169 pub fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a { 169 pub fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
170 self.items 170 self.items
171 .iter() 171 .iter()
172 .filter_map(|(name, res)| res.def.get_macros().map(|macro_| (name, macro_))) 172 .filter_map(|(name, res)| res.def.take_macros().map(|macro_| (name, macro_)))
173 } 173 }
174 174
175 /// Iterate over all legacy textual scoped macros visable at the end of the module 175 /// Iterate over all legacy textual scoped macros visable at the end of the module
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 7a5f90327..df01a20e1 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -476,7 +476,7 @@ where
476 path, 476 path,
477 ); 477 );
478 478
479 if let Some(def) = resolved_res.resolved_def.get_macros() { 479 if let Some(def) = resolved_res.resolved_def.take_macros() {
480 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id }); 480 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id });
481 resolved.push((*module_id, call_id, def)); 481 resolved.push((*module_id, call_id, def));
482 res = ReachedFixedPoint::No; 482 res = ReachedFixedPoint::No;
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 198578753..2ec84f2cc 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -1,4 +1,9 @@
1//! FIXME: write short doc here 1//! Lowers syntax tree of a rust file into a raw representation of containing
2//! items, *without* attaching them to a module structure.
3//!
4//! That is, raw items don't have semantics, just as syntax, but, unlike syntax,
5//! they don't change with trivial source code edits, making them a great tool
6//! for building salsa recomputation firewalls.
2 7
3use std::{ops::Index, sync::Arc}; 8use std::{ops::Index, sync::Arc};
4 9
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 626ebffdc..7b2723d57 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! A desugared representation of paths like `crate::foo` or `<Type as Trait>::bar`.
2 2
3use std::{iter, sync::Arc}; 3use std::{iter, sync::Arc};
4 4
@@ -66,7 +66,7 @@ pub enum PathKind {
66 66
67impl Path { 67impl Path {
68 /// Calls `cb` with all paths, represented by this use item. 68 /// Calls `cb` with all paths, represented by this use item.
69 pub fn expand_use_item( 69 pub(crate) fn expand_use_item(
70 item_src: Source<ast::UseItem>, 70 item_src: Source<ast::UseItem>,
71 hygiene: &Hygiene, 71 hygiene: &Hygiene,
72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), 72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
@@ -76,7 +76,10 @@ impl Path {
76 } 76 }
77 } 77 }
78 78
79 pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> Path { 79 pub(crate) fn from_simple_segments(
80 kind: PathKind,
81 segments: impl IntoIterator<Item = Name>,
82 ) -> Path {
80 Path { 83 Path {
81 kind, 84 kind,
82 segments: segments 85 segments: segments
@@ -94,7 +97,7 @@ impl Path {
94 97
95 /// Converts an `ast::Path` to `Path`. Works with use trees. 98 /// Converts an `ast::Path` to `Path`. Works with use trees.
96 /// It correctly handles `$crate` based path from macro call. 99 /// It correctly handles `$crate` based path from macro call.
97 pub fn from_src(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> { 100 pub(crate) fn from_src(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> {
98 let mut kind = PathKind::Plain; 101 let mut kind = PathKind::Plain;
99 let mut segments = Vec::new(); 102 let mut segments = Vec::new();
100 loop { 103 loop {
@@ -227,7 +230,7 @@ impl Path {
227} 230}
228 231
229impl GenericArgs { 232impl GenericArgs {
230 pub fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> { 233 pub(crate) fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> {
231 let mut args = Vec::new(); 234 let mut args = Vec::new();
232 for type_arg in node.type_args() { 235 for type_arg in node.type_args() {
233 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); 236 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref());
diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs
index 717ed1ef9..06ef6c9fc 100644
--- a/crates/ra_hir_def/src/per_ns.rs
+++ b/crates/ra_hir_def/src/per_ns.rs
@@ -44,10 +44,6 @@ impl PerNs {
44 self.types.is_none() && self.values.is_none() && self.macros.is_none() 44 self.types.is_none() && self.values.is_none() && self.macros.is_none()
45 } 45 }
46 46
47 pub fn is_all(&self) -> bool {
48 self.types.is_some() && self.values.is_some() && self.macros.is_some()
49 }
50
51 pub fn take_types(self) -> Option<ModuleDefId> { 47 pub fn take_types(self) -> Option<ModuleDefId> {
52 self.types 48 self.types
53 } 49 }
@@ -56,14 +52,10 @@ impl PerNs {
56 self.values 52 self.values
57 } 53 }
58 54
59 pub fn get_macros(&self) -> Option<MacroDefId> { 55 pub fn take_macros(self) -> Option<MacroDefId> {
60 self.macros 56 self.macros
61 } 57 }
62 58
63 pub fn only_macros(&self) -> PerNs {
64 PerNs { types: None, values: None, macros: self.macros }
65 }
66
67 pub fn or(self, other: PerNs) -> PerNs { 59 pub fn or(self, other: PerNs) -> PerNs {
68 PerNs { 60 PerNs {
69 types: self.types.or(other.types), 61 types: self.types.or(other.types),
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 4ff0a091b..7182b8a4d 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -308,7 +308,7 @@ impl Resolver {
308 308
309 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 309 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
310 let (item_map, module) = self.module()?; 310 let (item_map, module) = self.module()?;
311 item_map.resolve_path(db, module, path).0.get_macros() 311 item_map.resolve_path(db, module, path).0.take_macros()
312 } 312 }
313 313
314 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 314 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 8af061116..5f10e9a88 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -64,7 +64,7 @@ pub enum TypeBound {
64 64
65impl TypeRef { 65impl TypeRef {
66 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 66 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
67 pub fn from_ast(node: ast::TypeRef) -> Self { 67 pub(crate) fn from_ast(node: ast::TypeRef) -> Self {
68 match node { 68 match node {
69 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), 69 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
70 ast::TypeRef::TupleType(inner) => { 70 ast::TypeRef::TupleType(inner) => {
@@ -113,7 +113,7 @@ impl TypeRef {
113 } 113 }
114 } 114 }
115 115
116 pub fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { 116 pub(crate) fn from_ast_opt(node: Option<ast::TypeRef>) -> Self {
117 if let Some(node) = node { 117 if let Some(node) = node {
118 TypeRef::from_ast(node) 118 TypeRef::from_ast(node)
119 } else { 119 } else {
@@ -121,7 +121,7 @@ impl TypeRef {
121 } 121 }
122 } 122 }
123 123
124 pub fn unit() -> TypeRef { 124 pub(crate) fn unit() -> TypeRef {
125 TypeRef::Tuple(Vec::new()) 125 TypeRef::Tuple(Vec::new())
126 } 126 }
127} 127}
@@ -135,7 +135,7 @@ pub(crate) fn type_bounds_from_ast(type_bounds_opt: Option<ast::TypeBoundList>)
135} 135}
136 136
137impl TypeBound { 137impl TypeBound {
138 pub fn from_ast(node: ast::TypeBound) -> Self { 138 pub(crate) fn from_ast(node: ast::TypeBound) -> Self {
139 match node.kind() { 139 match node.kind() {
140 ast::TypeBoundKind::PathType(path_type) => { 140 ast::TypeBoundKind::PathType(path_type) => {
141 let path = match path_type.path() { 141 let path = match path_type.path() {