diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/scope.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir_def/src/find_path.rs | 105 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/marks.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/globs.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/macros.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower/lower_use.rs | 4 |
14 files changed, 111 insertions, 112 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 443b057ab..e08d62dd6 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -15,7 +15,7 @@ use ra_syntax::{ | |||
15 | }, | 15 | }, |
16 | AstNode, AstPtr, | 16 | AstNode, AstPtr, |
17 | }; | 17 | }; |
18 | use test_utils::tested_by; | 18 | use test_utils::mark; |
19 | 19 | ||
20 | use crate::{ | 20 | use crate::{ |
21 | adt::StructKind, | 21 | adt::StructKind, |
@@ -60,13 +60,10 @@ pub(super) fn lower( | |||
60 | params: Option<ast::ParamList>, | 60 | params: Option<ast::ParamList>, |
61 | body: Option<ast::Expr>, | 61 | body: Option<ast::Expr>, |
62 | ) -> (Body, BodySourceMap) { | 62 | ) -> (Body, BodySourceMap) { |
63 | let ctx = LowerCtx::new(db, expander.current_file_id.clone()); | ||
64 | |||
65 | ExprCollector { | 63 | ExprCollector { |
66 | db, | 64 | db, |
67 | def, | 65 | def, |
68 | expander, | 66 | expander, |
69 | ctx, | ||
70 | source_map: BodySourceMap::default(), | 67 | source_map: BodySourceMap::default(), |
71 | body: Body { | 68 | body: Body { |
72 | exprs: Arena::default(), | 69 | exprs: Arena::default(), |
@@ -83,7 +80,6 @@ struct ExprCollector<'a> { | |||
83 | db: &'a dyn DefDatabase, | 80 | db: &'a dyn DefDatabase, |
84 | def: DefWithBodyId, | 81 | def: DefWithBodyId, |
85 | expander: Expander, | 82 | expander: Expander, |
86 | ctx: LowerCtx, | ||
87 | body: Body, | 83 | body: Body, |
88 | source_map: BodySourceMap, | 84 | source_map: BodySourceMap, |
89 | } | 85 | } |
@@ -122,6 +118,10 @@ impl ExprCollector<'_> { | |||
122 | (self.body, self.source_map) | 118 | (self.body, self.source_map) |
123 | } | 119 | } |
124 | 120 | ||
121 | fn ctx(&self) -> LowerCtx { | ||
122 | LowerCtx::new(self.db, self.expander.current_file_id) | ||
123 | } | ||
124 | |||
125 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 125 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
126 | let src = self.expander.to_source(ptr); | 126 | let src = self.expander.to_source(ptr); |
127 | let id = self.make_expr(expr, Ok(src.clone())); | 127 | let id = self.make_expr(expr, Ok(src.clone())); |
@@ -226,7 +226,7 @@ impl ExprCollector<'_> { | |||
226 | None => self.collect_expr_opt(condition.expr()), | 226 | None => self.collect_expr_opt(condition.expr()), |
227 | // if let -- desugar to match | 227 | // if let -- desugar to match |
228 | Some(pat) => { | 228 | Some(pat) => { |
229 | tested_by!(infer_resolve_while_let); | 229 | mark::hit!(infer_resolve_while_let); |
230 | let pat = self.collect_pat(pat); | 230 | let pat = self.collect_pat(pat); |
231 | let match_expr = self.collect_expr_opt(condition.expr()); | 231 | let match_expr = self.collect_expr_opt(condition.expr()); |
232 | let placeholder_pat = self.missing_pat(); | 232 | let placeholder_pat = self.missing_pat(); |
@@ -268,7 +268,7 @@ impl ExprCollector<'_> { | |||
268 | }; | 268 | }; |
269 | let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 269 | let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
270 | let generic_args = | 270 | let generic_args = |
271 | e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx, it)); | 271 | e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it)); |
272 | self.alloc_expr( | 272 | self.alloc_expr( |
273 | Expr::MethodCall { receiver, method_name, args, generic_args }, | 273 | Expr::MethodCall { receiver, method_name, args, generic_args }, |
274 | syntax_ptr, | 274 | syntax_ptr, |
@@ -373,7 +373,7 @@ impl ExprCollector<'_> { | |||
373 | } | 373 | } |
374 | ast::Expr::CastExpr(e) => { | 374 | ast::Expr::CastExpr(e) => { |
375 | let expr = self.collect_expr_opt(e.expr()); | 375 | let expr = self.collect_expr_opt(e.expr()); |
376 | let type_ref = TypeRef::from_ast_opt(&self.ctx, e.type_ref()); | 376 | let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); |
377 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) | 377 | self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) |
378 | } | 378 | } |
379 | ast::Expr::RefExpr(e) => { | 379 | ast::Expr::RefExpr(e) => { |
@@ -396,7 +396,7 @@ impl ExprCollector<'_> { | |||
396 | for param in pl.params() { | 396 | for param in pl.params() { |
397 | let pat = self.collect_pat_opt(param.pat()); | 397 | let pat = self.collect_pat_opt(param.pat()); |
398 | let type_ref = | 398 | let type_ref = |
399 | param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it)); | 399 | param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); |
400 | args.push(pat); | 400 | args.push(pat); |
401 | arg_types.push(type_ref); | 401 | arg_types.push(type_ref); |
402 | } | 402 | } |
@@ -404,7 +404,7 @@ impl ExprCollector<'_> { | |||
404 | let ret_type = e | 404 | let ret_type = e |
405 | .ret_type() | 405 | .ret_type() |
406 | .and_then(|r| r.type_ref()) | 406 | .and_then(|r| r.type_ref()) |
407 | .map(|it| TypeRef::from_ast(&self.ctx, it)); | 407 | .map(|it| TypeRef::from_ast(&self.ctx(), it)); |
408 | let body = self.collect_expr_opt(e.body()); | 408 | let body = self.collect_expr_opt(e.body()); |
409 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) | 409 | self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) |
410 | } | 410 | } |
@@ -507,7 +507,8 @@ impl ExprCollector<'_> { | |||
507 | .map(|s| match s { | 507 | .map(|s| match s { |
508 | ast::Stmt::LetStmt(stmt) => { | 508 | ast::Stmt::LetStmt(stmt) => { |
509 | let pat = self.collect_pat_opt(stmt.pat()); | 509 | let pat = self.collect_pat_opt(stmt.pat()); |
510 | let type_ref = stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it)); | 510 | let type_ref = |
511 | stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx(), it)); | ||
511 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); | 512 | let initializer = stmt.initializer().map(|e| self.collect_expr(e)); |
512 | Statement::Let { pat, type_ref, initializer } | 513 | Statement::Let { pat, type_ref, initializer } |
513 | } | 514 | } |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 86f953c80..09e92b74e 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -174,7 +174,7 @@ mod tests { | |||
174 | use hir_expand::{name::AsName, InFile}; | 174 | use hir_expand::{name::AsName, InFile}; |
175 | use ra_db::{fixture::WithFixture, FileId, SourceDatabase}; | 175 | use ra_db::{fixture::WithFixture, FileId, SourceDatabase}; |
176 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; | 176 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
177 | use test_utils::{assert_eq_text, covers, extract_offset}; | 177 | use test_utils::{assert_eq_text, extract_offset, mark}; |
178 | 178 | ||
179 | use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; | 179 | use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; |
180 | 180 | ||
@@ -388,7 +388,7 @@ mod tests { | |||
388 | 388 | ||
389 | #[test] | 389 | #[test] |
390 | fn while_let_desugaring() { | 390 | fn while_let_desugaring() { |
391 | covers!(infer_resolve_while_let); | 391 | mark::check!(infer_resolve_while_let); |
392 | do_check_local_name( | 392 | do_check_local_name( |
393 | r#" | 393 | r#" |
394 | fn test() { | 394 | fn test() { |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e665ab45d..945a0025e 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Defines database & queries for name resolution. | 1 | //! Defines database & queries for name resolution. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_expand::{db::AstDatabase, HirFileId}; | 4 | use hir_expand::{db::AstDatabase, name::Name, HirFileId}; |
5 | use ra_db::{salsa, CrateId, SourceDatabase, Upcast}; | 5 | use ra_db::{salsa, CrateId, SourceDatabase, Upcast}; |
6 | use ra_prof::profile; | 6 | use ra_prof::profile; |
7 | use ra_syntax::SmolStr; | 7 | use ra_syntax::SmolStr; |
@@ -12,9 +12,13 @@ use crate::{ | |||
12 | body::{scope::ExprScopes, Body, BodySourceMap}, | 12 | body::{scope::ExprScopes, Body, BodySourceMap}, |
13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, | 13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, |
14 | docs::Documentation, | 14 | docs::Documentation, |
15 | find_path, | ||
15 | generics::GenericParams, | 16 | generics::GenericParams, |
17 | item_scope::ItemInNs, | ||
16 | lang_item::{LangItemTarget, LangItems}, | 18 | lang_item::{LangItemTarget, LangItems}, |
17 | nameres::{raw::RawItems, CrateDefMap}, | 19 | nameres::{raw::RawItems, CrateDefMap}, |
20 | path::ModPath, | ||
21 | visibility::Visibility, | ||
18 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, | 22 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, |
19 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, | 23 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, |
20 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, | 24 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, |
@@ -108,6 +112,16 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | |||
108 | // Remove this query completely, in favor of `Attrs::docs` method | 112 | // Remove this query completely, in favor of `Attrs::docs` method |
109 | #[salsa::invoke(Documentation::documentation_query)] | 113 | #[salsa::invoke(Documentation::documentation_query)] |
110 | fn documentation(&self, def: AttrDefId) -> Option<Documentation>; | 114 | fn documentation(&self, def: AttrDefId) -> Option<Documentation>; |
115 | |||
116 | #[salsa::invoke(find_path::importable_locations_of_query)] | ||
117 | fn importable_locations_of( | ||
118 | &self, | ||
119 | item: ItemInNs, | ||
120 | krate: CrateId, | ||
121 | ) -> Arc<[(ModuleId, Name, Visibility)]>; | ||
122 | |||
123 | #[salsa::invoke(find_path::find_path_inner_query)] | ||
124 | fn find_path_inner(&self, item: ItemInNs, from: ModuleId, max_len: usize) -> Option<ModPath>; | ||
111 | } | 125 | } |
112 | 126 | ||
113 | fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { | 127 | fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { |
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 70dcb03e6..4db798473 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs | |||
@@ -1,5 +1,11 @@ | |||
1 | //! An algorithm to find a path to refer to a certain item. | 1 | //! An algorithm to find a path to refer to a certain item. |
2 | 2 | ||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir_expand::name::{known, AsName, Name}; | ||
6 | use ra_prof::profile; | ||
7 | use test_utils::mark; | ||
8 | |||
3 | use crate::{ | 9 | use crate::{ |
4 | db::DefDatabase, | 10 | db::DefDatabase, |
5 | item_scope::ItemInNs, | 11 | item_scope::ItemInNs, |
@@ -7,25 +13,28 @@ use crate::{ | |||
7 | visibility::Visibility, | 13 | visibility::Visibility, |
8 | CrateId, ModuleDefId, ModuleId, | 14 | CrateId, ModuleDefId, ModuleId, |
9 | }; | 15 | }; |
10 | use hir_expand::name::{known, AsName, Name}; | 16 | |
11 | use test_utils::tested_by; | 17 | // FIXME: handle local items |
18 | |||
19 | /// Find a path that can be used to refer to a certain item. This can depend on | ||
20 | /// *from where* you're referring to the item, hence the `from` parameter. | ||
21 | pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { | ||
22 | let _p = profile("find_path"); | ||
23 | db.find_path_inner(item, from, MAX_PATH_LEN) | ||
24 | } | ||
12 | 25 | ||
13 | const MAX_PATH_LEN: usize = 15; | 26 | const MAX_PATH_LEN: usize = 15; |
14 | 27 | ||
15 | impl ModPath { | 28 | impl ModPath { |
16 | fn starts_with_std(&self) -> bool { | 29 | fn starts_with_std(&self) -> bool { |
17 | self.segments.first().filter(|&first_segment| first_segment == &known::std).is_some() | 30 | self.segments.first() == Some(&known::std) |
18 | } | 31 | } |
19 | 32 | ||
20 | // When std library is present, paths starting with `std::` | 33 | // When std library is present, paths starting with `std::` |
21 | // should be preferred over paths starting with `core::` and `alloc::` | 34 | // should be preferred over paths starting with `core::` and `alloc::` |
22 | fn can_start_with_std(&self) -> bool { | 35 | fn can_start_with_std(&self) -> bool { |
23 | self.segments | 36 | let first_segment = self.segments.first(); |
24 | .first() | 37 | first_segment == Some(&known::alloc) || first_segment == Some(&known::core) |
25 | .filter(|&first_segment| { | ||
26 | first_segment == &known::alloc || first_segment == &known::core | ||
27 | }) | ||
28 | .is_some() | ||
29 | } | 38 | } |
30 | 39 | ||
31 | fn len(&self) -> usize { | 40 | fn len(&self) -> usize { |
@@ -40,15 +49,7 @@ impl ModPath { | |||
40 | } | 49 | } |
41 | } | 50 | } |
42 | 51 | ||
43 | // FIXME: handle local items | 52 | pub(crate) fn find_path_inner_query( |
44 | |||
45 | /// Find a path that can be used to refer to a certain item. This can depend on | ||
46 | /// *from where* you're referring to the item, hence the `from` parameter. | ||
47 | pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { | ||
48 | find_path_inner(db, item, from, MAX_PATH_LEN) | ||
49 | } | ||
50 | |||
51 | fn find_path_inner( | ||
52 | db: &dyn DefDatabase, | 53 | db: &dyn DefDatabase, |
53 | item: ItemInNs, | 54 | item: ItemInNs, |
54 | from: ModuleId, | 55 | from: ModuleId, |
@@ -139,8 +140,7 @@ fn find_path_inner( | |||
139 | let mut best_path = None; | 140 | let mut best_path = None; |
140 | let mut best_path_len = max_len; | 141 | let mut best_path_len = max_len; |
141 | for (module_id, name) in importable_locations { | 142 | for (module_id, name) in importable_locations { |
142 | let mut path = match find_path_inner( | 143 | let mut path = match db.find_path_inner( |
143 | db, | ||
144 | ItemInNs::Types(ModuleDefId::ModuleId(module_id)), | 144 | ItemInNs::Types(ModuleDefId::ModuleId(module_id)), |
145 | from, | 145 | from, |
146 | best_path_len - 1, | 146 | best_path_len - 1, |
@@ -163,17 +163,19 @@ fn find_path_inner( | |||
163 | 163 | ||
164 | fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath { | 164 | fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath { |
165 | if old_path.starts_with_std() && new_path.can_start_with_std() { | 165 | if old_path.starts_with_std() && new_path.can_start_with_std() { |
166 | tested_by!(prefer_std_paths); | ||
167 | if prefer_no_std { | 166 | if prefer_no_std { |
167 | mark::hit!(prefer_no_std_paths); | ||
168 | new_path | 168 | new_path |
169 | } else { | 169 | } else { |
170 | mark::hit!(prefer_std_paths); | ||
170 | old_path | 171 | old_path |
171 | } | 172 | } |
172 | } else if new_path.starts_with_std() && old_path.can_start_with_std() { | 173 | } else if new_path.starts_with_std() && old_path.can_start_with_std() { |
173 | tested_by!(prefer_std_paths); | ||
174 | if prefer_no_std { | 174 | if prefer_no_std { |
175 | mark::hit!(prefer_no_std_paths); | ||
175 | old_path | 176 | old_path |
176 | } else { | 177 | } else { |
178 | mark::hit!(prefer_std_paths); | ||
177 | new_path | 179 | new_path |
178 | } | 180 | } |
179 | } else if new_path.len() < old_path.len() { | 181 | } else if new_path.len() < old_path.len() { |
@@ -198,7 +200,7 @@ fn find_importable_locations( | |||
198 | .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id)) | 200 | .chain(crate_graph[from.krate].dependencies.iter().map(|dep| dep.crate_id)) |
199 | { | 201 | { |
200 | result.extend( | 202 | result.extend( |
201 | importable_locations_in_crate(db, item, krate) | 203 | db.importable_locations_of(item, krate) |
202 | .iter() | 204 | .iter() |
203 | .filter(|(_, _, vis)| vis.is_visible_from(db, from)) | 205 | .filter(|(_, _, vis)| vis.is_visible_from(db, from)) |
204 | .map(|(m, n, _)| (*m, n.clone())), | 206 | .map(|(m, n, _)| (*m, n.clone())), |
@@ -213,11 +215,12 @@ fn find_importable_locations( | |||
213 | /// | 215 | /// |
214 | /// Note that the crate doesn't need to be the one in which the item is defined; | 216 | /// Note that the crate doesn't need to be the one in which the item is defined; |
215 | /// it might be re-exported in other crates. | 217 | /// it might be re-exported in other crates. |
216 | fn importable_locations_in_crate( | 218 | pub(crate) fn importable_locations_of_query( |
217 | db: &dyn DefDatabase, | 219 | db: &dyn DefDatabase, |
218 | item: ItemInNs, | 220 | item: ItemInNs, |
219 | krate: CrateId, | 221 | krate: CrateId, |
220 | ) -> Vec<(ModuleId, Name, Visibility)> { | 222 | ) -> Arc<[(ModuleId, Name, Visibility)]> { |
223 | let _p = profile("importable_locations_of_query"); | ||
221 | let def_map = db.crate_def_map(krate); | 224 | let def_map = db.crate_def_map(krate); |
222 | let mut result = Vec::new(); | 225 | let mut result = Vec::new(); |
223 | for (local_id, data) in def_map.modules.iter() { | 226 | for (local_id, data) in def_map.modules.iter() { |
@@ -243,17 +246,20 @@ fn importable_locations_in_crate( | |||
243 | result.push((ModuleId { krate, local_id }, name.clone(), vis)); | 246 | result.push((ModuleId { krate, local_id }, name.clone(), vis)); |
244 | } | 247 | } |
245 | } | 248 | } |
246 | result | 249 | |
250 | Arc::from(result) | ||
247 | } | 251 | } |
248 | 252 | ||
249 | #[cfg(test)] | 253 | #[cfg(test)] |
250 | mod tests { | 254 | mod tests { |
251 | use super::*; | ||
252 | use crate::test_db::TestDB; | ||
253 | use hir_expand::hygiene::Hygiene; | 255 | use hir_expand::hygiene::Hygiene; |
254 | use ra_db::fixture::WithFixture; | 256 | use ra_db::fixture::WithFixture; |
255 | use ra_syntax::ast::AstNode; | 257 | use ra_syntax::ast::AstNode; |
256 | use test_utils::covers; | 258 | use test_utils::mark; |
259 | |||
260 | use crate::test_db::TestDB; | ||
261 | |||
262 | use super::*; | ||
257 | 263 | ||
258 | /// `code` needs to contain a cursor marker; checks that `find_path` for the | 264 | /// `code` needs to contain a cursor marker; checks that `find_path` for the |
259 | /// item the `path` refers to returns that same path when called from the | 265 | /// item the `path` refers to returns that same path when called from the |
@@ -508,7 +514,7 @@ mod tests { | |||
508 | 514 | ||
509 | #[test] | 515 | #[test] |
510 | fn prefer_std_paths_over_alloc() { | 516 | fn prefer_std_paths_over_alloc() { |
511 | covers!(prefer_std_paths); | 517 | mark::check!(prefer_std_paths); |
512 | let code = r#" | 518 | let code = r#" |
513 | //- /main.rs crate:main deps:alloc,std | 519 | //- /main.rs crate:main deps:alloc,std |
514 | <|> | 520 | <|> |
@@ -527,51 +533,50 @@ mod tests { | |||
527 | } | 533 | } |
528 | 534 | ||
529 | #[test] | 535 | #[test] |
530 | fn prefer_alloc_paths_over_std() { | 536 | fn prefer_core_paths_over_std() { |
531 | covers!(prefer_std_paths); | 537 | mark::check!(prefer_no_std_paths); |
532 | let code = r#" | 538 | let code = r#" |
533 | //- /main.rs crate:main deps:alloc,std | 539 | //- /main.rs crate:main deps:core,std |
534 | #![no_std] | 540 | #![no_std] |
535 | 541 | ||
536 | <|> | 542 | <|> |
537 | 543 | ||
538 | //- /std.rs crate:std deps:alloc | 544 | //- /std.rs crate:std deps:core |
539 | 545 | ||
540 | pub mod sync { | 546 | pub mod fmt { |
541 | pub use alloc::sync::Arc; | 547 | pub use core::fmt::Error; |
542 | } | 548 | } |
543 | 549 | ||
544 | //- /zzz.rs crate:alloc | 550 | //- /zzz.rs crate:core |
545 | 551 | ||
546 | pub mod sync { | 552 | pub mod fmt { |
547 | pub struct Arc; | 553 | pub struct Error; |
548 | } | 554 | } |
549 | "#; | 555 | "#; |
550 | check_found_path(code, "alloc::sync::Arc"); | 556 | check_found_path(code, "core::fmt::Error"); |
551 | } | 557 | } |
552 | 558 | ||
553 | #[test] | 559 | #[test] |
554 | fn prefer_core_paths_over_std() { | 560 | fn prefer_alloc_paths_over_std() { |
555 | covers!(prefer_std_paths); | ||
556 | let code = r#" | 561 | let code = r#" |
557 | //- /main.rs crate:main deps:core,std | 562 | //- /main.rs crate:main deps:alloc,std |
558 | #![no_std] | 563 | #![no_std] |
559 | 564 | ||
560 | <|> | 565 | <|> |
561 | 566 | ||
562 | //- /std.rs crate:std deps:core | 567 | //- /std.rs crate:std deps:alloc |
563 | 568 | ||
564 | pub mod fmt { | 569 | pub mod sync { |
565 | pub use core::fmt::Error; | 570 | pub use alloc::sync::Arc; |
566 | } | 571 | } |
567 | 572 | ||
568 | //- /zzz.rs crate:core | 573 | //- /zzz.rs crate:alloc |
569 | 574 | ||
570 | pub mod fmt { | 575 | pub mod sync { |
571 | pub struct Error; | 576 | pub struct Arc; |
572 | } | 577 | } |
573 | "#; | 578 | "#; |
574 | check_found_path(code, "core::fmt::Error"); | 579 | check_found_path(code, "alloc::sync::Arc"); |
575 | } | 580 | } |
576 | 581 | ||
577 | #[test] | 582 | #[test] |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 518772e8a..5325a2760 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -46,8 +46,6 @@ pub mod find_path; | |||
46 | 46 | ||
47 | #[cfg(test)] | 47 | #[cfg(test)] |
48 | mod test_db; | 48 | mod test_db; |
49 | #[cfg(test)] | ||
50 | mod marks; | ||
51 | 49 | ||
52 | use std::hash::Hash; | 50 | use std::hash::Hash; |
53 | 51 | ||
diff --git a/crates/ra_hir_def/src/marks.rs b/crates/ra_hir_def/src/marks.rs deleted file mode 100644 index daa49d5f1..000000000 --- a/crates/ra_hir_def/src/marks.rs +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | //! See test_utils/src/marks.rs | ||
2 | |||
3 | test_utils::marks!( | ||
4 | bogus_paths | ||
5 | name_res_works_for_broken_modules | ||
6 | can_import_enum_variant | ||
7 | glob_enum | ||
8 | glob_enum_group | ||
9 | glob_across_crates | ||
10 | std_prelude | ||
11 | macro_rules_from_other_crates_are_visible_with_macro_use | ||
12 | prelude_is_macro_use | ||
13 | macro_dollar_crate_self | ||
14 | macro_dollar_crate_other | ||
15 | infer_resolve_while_let | ||
16 | prefer_std_paths | ||
17 | ); | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index db994122a..353a31ad4 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -14,7 +14,7 @@ use ra_cfg::CfgOptions; | |||
14 | use ra_db::{CrateId, FileId, ProcMacroId}; | 14 | use ra_db::{CrateId, FileId, ProcMacroId}; |
15 | use ra_syntax::ast; | 15 | use ra_syntax::ast; |
16 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
17 | use test_utils::tested_by; | 17 | use test_utils::mark; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | attr::Attrs, | 20 | attr::Attrs, |
@@ -302,7 +302,7 @@ impl DefCollector<'_> { | |||
302 | ); | 302 | ); |
303 | 303 | ||
304 | if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { | 304 | if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { |
305 | tested_by!(macro_rules_from_other_crates_are_visible_with_macro_use); | 305 | mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); |
306 | self.import_all_macros_exported(current_module_id, m.krate); | 306 | self.import_all_macros_exported(current_module_id, m.krate); |
307 | } | 307 | } |
308 | } | 308 | } |
@@ -412,10 +412,10 @@ impl DefCollector<'_> { | |||
412 | match def.take_types() { | 412 | match def.take_types() { |
413 | Some(ModuleDefId::ModuleId(m)) => { | 413 | Some(ModuleDefId::ModuleId(m)) => { |
414 | if import.is_prelude { | 414 | if import.is_prelude { |
415 | tested_by!(std_prelude); | 415 | mark::hit!(std_prelude); |
416 | self.def_map.prelude = Some(m); | 416 | self.def_map.prelude = Some(m); |
417 | } else if m.krate != self.def_map.krate { | 417 | } else if m.krate != self.def_map.krate { |
418 | tested_by!(glob_across_crates); | 418 | mark::hit!(glob_across_crates); |
419 | // glob import from other crate => we can just import everything once | 419 | // glob import from other crate => we can just import everything once |
420 | let item_map = self.db.crate_def_map(m.krate); | 420 | let item_map = self.db.crate_def_map(m.krate); |
421 | let scope = &item_map[m.local_id].scope; | 421 | let scope = &item_map[m.local_id].scope; |
@@ -461,7 +461,7 @@ impl DefCollector<'_> { | |||
461 | } | 461 | } |
462 | } | 462 | } |
463 | Some(ModuleDefId::AdtId(AdtId::EnumId(e))) => { | 463 | Some(ModuleDefId::AdtId(AdtId::EnumId(e))) => { |
464 | tested_by!(glob_enum); | 464 | mark::hit!(glob_enum); |
465 | // glob import from enum => just import all the variants | 465 | // glob import from enum => just import all the variants |
466 | 466 | ||
467 | // XXX: urgh, so this works by accident! Here, we look at | 467 | // XXX: urgh, so this works by accident! Here, we look at |
@@ -510,7 +510,7 @@ impl DefCollector<'_> { | |||
510 | 510 | ||
511 | self.update(module_id, &[(name, def)], vis); | 511 | self.update(module_id, &[(name, def)], vis); |
512 | } | 512 | } |
513 | None => tested_by!(bogus_paths), | 513 | None => mark::hit!(bogus_paths), |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
@@ -683,7 +683,7 @@ impl ModCollector<'_, '_> { | |||
683 | // Prelude module is always considered to be `#[macro_use]`. | 683 | // Prelude module is always considered to be `#[macro_use]`. |
684 | if let Some(prelude_module) = self.def_collector.def_map.prelude { | 684 | if let Some(prelude_module) = self.def_collector.def_map.prelude { |
685 | if prelude_module.krate != self.def_collector.def_map.krate { | 685 | if prelude_module.krate != self.def_collector.def_map.krate { |
686 | tested_by!(prelude_is_macro_use); | 686 | mark::hit!(prelude_is_macro_use); |
687 | self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate); | 687 | self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate); |
688 | } | 688 | } |
689 | } | 689 | } |
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 35a0a0c98..19692e70c 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs | |||
@@ -14,7 +14,7 @@ use std::iter::successors; | |||
14 | 14 | ||
15 | use hir_expand::name::Name; | 15 | use hir_expand::name::Name; |
16 | use ra_db::Edition; | 16 | use ra_db::Edition; |
17 | use test_utils::tested_by; | 17 | use test_utils::mark; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | db::DefDatabase, | 20 | db::DefDatabase, |
@@ -108,7 +108,7 @@ impl CrateDefMap { | |||
108 | let mut curr_per_ns: PerNs = match path.kind { | 108 | let mut curr_per_ns: PerNs = match path.kind { |
109 | PathKind::DollarCrate(krate) => { | 109 | PathKind::DollarCrate(krate) => { |
110 | if krate == self.krate { | 110 | if krate == self.krate { |
111 | tested_by!(macro_dollar_crate_self); | 111 | mark::hit!(macro_dollar_crate_self); |
112 | PerNs::types( | 112 | PerNs::types( |
113 | ModuleId { krate: self.krate, local_id: self.root }.into(), | 113 | ModuleId { krate: self.krate, local_id: self.root }.into(), |
114 | Visibility::Public, | 114 | Visibility::Public, |
@@ -116,7 +116,7 @@ impl CrateDefMap { | |||
116 | } else { | 116 | } else { |
117 | let def_map = db.crate_def_map(krate); | 117 | let def_map = db.crate_def_map(krate); |
118 | let module = ModuleId { krate, local_id: def_map.root }; | 118 | let module = ModuleId { krate, local_id: def_map.root }; |
119 | tested_by!(macro_dollar_crate_other); | 119 | mark::hit!(macro_dollar_crate_other); |
120 | PerNs::types(module.into(), Visibility::Public) | 120 | PerNs::types(module.into(), Visibility::Public) |
121 | } | 121 | } |
122 | } | 122 | } |
@@ -221,7 +221,7 @@ impl CrateDefMap { | |||
221 | } | 221 | } |
222 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { | 222 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { |
223 | // enum variant | 223 | // enum variant |
224 | tested_by!(can_import_enum_variant); | 224 | mark::hit!(can_import_enum_variant); |
225 | let enum_data = db.enum_data(e); | 225 | let enum_data = db.enum_data(e); |
226 | match enum_data.variant(&segment) { | 226 | match enum_data.variant(&segment) { |
227 | Some(local_id) => { | 227 | Some(local_id) => { |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index f2716a295..4e628b14d 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -18,7 +18,7 @@ use ra_syntax::{ | |||
18 | ast::{self, AttrsOwner, NameOwner, VisibilityOwner}, | 18 | ast::{self, AttrsOwner, NameOwner, VisibilityOwner}, |
19 | AstNode, | 19 | AstNode, |
20 | }; | 20 | }; |
21 | use test_utils::tested_by; | 21 | use test_utils::mark; |
22 | 22 | ||
23 | use crate::{ | 23 | use crate::{ |
24 | attr::Attrs, | 24 | attr::Attrs, |
@@ -346,7 +346,7 @@ impl RawItemsCollector { | |||
346 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 346 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
347 | return; | 347 | return; |
348 | } | 348 | } |
349 | tested_by!(name_res_works_for_broken_modules); | 349 | mark::hit!(name_res_works_for_broken_modules); |
350 | } | 350 | } |
351 | 351 | ||
352 | fn add_use_item(&mut self, current_module: Option<Idx<ModuleData>>, use_item: ast::UseItem) { | 352 | fn add_use_item(&mut self, current_module: Option<Idx<ModuleData>>, use_item: ast::UseItem) { |
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 1b66c1aac..05cd0297d 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs | |||
@@ -8,7 +8,7 @@ use std::sync::Arc; | |||
8 | 8 | ||
9 | use insta::assert_snapshot; | 9 | use insta::assert_snapshot; |
10 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 10 | use ra_db::{fixture::WithFixture, SourceDatabase}; |
11 | use test_utils::covers; | 11 | use test_utils::mark; |
12 | 12 | ||
13 | use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; | 13 | use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; |
14 | 14 | ||
@@ -132,7 +132,7 @@ fn crate_def_map_fn_mod_same_name() { | |||
132 | 132 | ||
133 | #[test] | 133 | #[test] |
134 | fn bogus_paths() { | 134 | fn bogus_paths() { |
135 | covers!(bogus_paths); | 135 | mark::check!(bogus_paths); |
136 | let map = def_map( | 136 | let map = def_map( |
137 | " | 137 | " |
138 | //- /lib.rs | 138 | //- /lib.rs |
@@ -247,7 +247,7 @@ fn re_exports() { | |||
247 | 247 | ||
248 | #[test] | 248 | #[test] |
249 | fn std_prelude() { | 249 | fn std_prelude() { |
250 | covers!(std_prelude); | 250 | mark::check!(std_prelude); |
251 | let map = def_map( | 251 | let map = def_map( |
252 | " | 252 | " |
253 | //- /main.rs crate:main deps:test_crate | 253 | //- /main.rs crate:main deps:test_crate |
@@ -271,7 +271,7 @@ fn std_prelude() { | |||
271 | 271 | ||
272 | #[test] | 272 | #[test] |
273 | fn can_import_enum_variant() { | 273 | fn can_import_enum_variant() { |
274 | covers!(can_import_enum_variant); | 274 | mark::check!(can_import_enum_variant); |
275 | let map = def_map( | 275 | let map = def_map( |
276 | " | 276 | " |
277 | //- /lib.rs | 277 | //- /lib.rs |
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index ee8df3a26..2b12c0daa 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs | |||
@@ -152,7 +152,7 @@ fn glob_privacy_2() { | |||
152 | 152 | ||
153 | #[test] | 153 | #[test] |
154 | fn glob_across_crates() { | 154 | fn glob_across_crates() { |
155 | covers!(glob_across_crates); | 155 | mark::check!(glob_across_crates); |
156 | let map = def_map( | 156 | let map = def_map( |
157 | r" | 157 | r" |
158 | //- /main.rs crate:main deps:test_crate | 158 | //- /main.rs crate:main deps:test_crate |
@@ -171,7 +171,6 @@ fn glob_across_crates() { | |||
171 | 171 | ||
172 | #[test] | 172 | #[test] |
173 | fn glob_privacy_across_crates() { | 173 | fn glob_privacy_across_crates() { |
174 | covers!(glob_across_crates); | ||
175 | let map = def_map( | 174 | let map = def_map( |
176 | r" | 175 | r" |
177 | //- /main.rs crate:main deps:test_crate | 176 | //- /main.rs crate:main deps:test_crate |
@@ -191,7 +190,7 @@ fn glob_privacy_across_crates() { | |||
191 | 190 | ||
192 | #[test] | 191 | #[test] |
193 | fn glob_enum() { | 192 | fn glob_enum() { |
194 | covers!(glob_enum); | 193 | mark::check!(glob_enum); |
195 | let map = def_map( | 194 | let map = def_map( |
196 | " | 195 | " |
197 | //- /lib.rs | 196 | //- /lib.rs |
@@ -212,7 +211,7 @@ fn glob_enum() { | |||
212 | 211 | ||
213 | #[test] | 212 | #[test] |
214 | fn glob_enum_group() { | 213 | fn glob_enum_group() { |
215 | covers!(glob_enum_group); | 214 | mark::check!(glob_enum_group); |
216 | let map = def_map( | 215 | let map = def_map( |
217 | r" | 216 | r" |
218 | //- /lib.rs | 217 | //- /lib.rs |
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs index 40289e3ca..84480d9f6 100644 --- a/crates/ra_hir_def/src/nameres/tests/macros.rs +++ b/crates/ra_hir_def/src/nameres/tests/macros.rs | |||
@@ -212,7 +212,7 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() { | |||
212 | 212 | ||
213 | #[test] | 213 | #[test] |
214 | fn macro_rules_from_other_crates_are_visible_with_macro_use() { | 214 | fn macro_rules_from_other_crates_are_visible_with_macro_use() { |
215 | covers!(macro_rules_from_other_crates_are_visible_with_macro_use); | 215 | mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); |
216 | let map = def_map( | 216 | let map = def_map( |
217 | " | 217 | " |
218 | //- /main.rs crate:main deps:foo | 218 | //- /main.rs crate:main deps:foo |
@@ -262,7 +262,7 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { | |||
262 | 262 | ||
263 | #[test] | 263 | #[test] |
264 | fn prelude_is_macro_use() { | 264 | fn prelude_is_macro_use() { |
265 | covers!(prelude_is_macro_use); | 265 | mark::check!(prelude_is_macro_use); |
266 | let map = def_map( | 266 | let map = def_map( |
267 | " | 267 | " |
268 | //- /main.rs crate:main deps:foo | 268 | //- /main.rs crate:main deps:foo |
@@ -544,8 +544,7 @@ fn path_qualified_macros() { | |||
544 | 544 | ||
545 | #[test] | 545 | #[test] |
546 | fn macro_dollar_crate_is_correct_in_item() { | 546 | fn macro_dollar_crate_is_correct_in_item() { |
547 | covers!(macro_dollar_crate_self); | 547 | mark::check!(macro_dollar_crate_self); |
548 | covers!(macro_dollar_crate_other); | ||
549 | let map = def_map( | 548 | let map = def_map( |
550 | " | 549 | " |
551 | //- /main.rs crate:main deps:foo | 550 | //- /main.rs crate:main deps:foo |
@@ -603,7 +602,7 @@ fn macro_dollar_crate_is_correct_in_item() { | |||
603 | 602 | ||
604 | #[test] | 603 | #[test] |
605 | fn macro_dollar_crate_is_correct_in_indirect_deps() { | 604 | fn macro_dollar_crate_is_correct_in_indirect_deps() { |
606 | covers!(macro_dollar_crate_other); | 605 | mark::check!(macro_dollar_crate_other); |
607 | // From std | 606 | // From std |
608 | let map = def_map( | 607 | let map = def_map( |
609 | r#" | 608 | r#" |
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index 37fcdfb8c..b43b294ca 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -2,7 +2,7 @@ use super::*; | |||
2 | 2 | ||
3 | #[test] | 3 | #[test] |
4 | fn name_res_works_for_broken_modules() { | 4 | fn name_res_works_for_broken_modules() { |
5 | covers!(name_res_works_for_broken_modules); | 5 | mark::check!(name_res_works_for_broken_modules); |
6 | let map = def_map( | 6 | let map = def_map( |
7 | r" | 7 | r" |
8 | //- /lib.rs | 8 | //- /lib.rs |
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index 5b6854b0f..7cc655487 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs | |||
@@ -6,7 +6,7 @@ use std::iter; | |||
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_expand::{hygiene::Hygiene, name::AsName}; | 7 | use hir_expand::{hygiene::Hygiene, name::AsName}; |
8 | use ra_syntax::ast::{self, NameOwner}; | 8 | use ra_syntax::ast::{self, NameOwner}; |
9 | use test_utils::tested_by; | 9 | use test_utils::mark; |
10 | 10 | ||
11 | use crate::path::{ImportAlias, ModPath, PathKind}; | 11 | use crate::path::{ImportAlias, ModPath, PathKind}; |
12 | 12 | ||
@@ -54,7 +54,7 @@ pub(crate) fn lower_use_tree( | |||
54 | // FIXME: report errors somewhere | 54 | // FIXME: report errors somewhere |
55 | // We get here if we do | 55 | // We get here if we do |
56 | } else if is_glob { | 56 | } else if is_glob { |
57 | tested_by!(glob_enum_group); | 57 | mark::hit!(glob_enum_group); |
58 | if let Some(prefix) = prefix { | 58 | if let Some(prefix) = prefix { |
59 | cb(prefix, &tree, is_glob, None) | 59 | cb(prefix, &tree, is_glob, None) |
60 | } | 60 | } |