diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/body/tests.rs | 41 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 4 |
2 files changed, 33 insertions, 12 deletions
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index de77d5fc9..2e5d0a01e 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs | |||
@@ -6,18 +6,24 @@ use crate::{test_db::TestDB, ModuleDefId}; | |||
6 | use super::*; | 6 | use super::*; |
7 | 7 | ||
8 | fn lower(ra_fixture: &str) -> Arc<Body> { | 8 | fn lower(ra_fixture: &str) -> Arc<Body> { |
9 | let (db, file_id) = crate::test_db::TestDB::with_single_file(ra_fixture); | 9 | let db = crate::test_db::TestDB::with_files(ra_fixture); |
10 | 10 | ||
11 | let krate = db.crate_graph().iter().next().unwrap(); | 11 | let krate = db.crate_graph().iter().next().unwrap(); |
12 | let def_map = db.crate_def_map(krate); | 12 | let def_map = db.crate_def_map(krate); |
13 | let module = def_map.modules_for_file(file_id).next().unwrap(); | 13 | let mut fn_def = None; |
14 | let module = &def_map[module]; | 14 | 'outer: for (_, module) in def_map.modules() { |
15 | let fn_def = match module.scope.declarations().next().unwrap() { | 15 | for decl in module.scope.declarations() { |
16 | ModuleDefId::FunctionId(it) => it, | 16 | match decl { |
17 | _ => panic!(), | 17 | ModuleDefId::FunctionId(it) => { |
18 | }; | 18 | fn_def = Some(it); |
19 | break 'outer; | ||
20 | } | ||
21 | _ => {} | ||
22 | } | ||
23 | } | ||
24 | } | ||
19 | 25 | ||
20 | db.body(fn_def.into()) | 26 | db.body(fn_def.unwrap().into()) |
21 | } | 27 | } |
22 | 28 | ||
23 | fn check_diagnostics(ra_fixture: &str) { | 29 | fn check_diagnostics(ra_fixture: &str) { |
@@ -42,6 +48,25 @@ fn main() { n_nuple!(1,2,3); } | |||
42 | } | 48 | } |
43 | 49 | ||
44 | #[test] | 50 | #[test] |
51 | fn macro_resolve() { | ||
52 | // Regression test for a path resolution bug introduced with inner item handling. | ||
53 | lower( | ||
54 | r" | ||
55 | macro_rules! vec { | ||
56 | () => { () }; | ||
57 | ($elem:expr; $n:expr) => { () }; | ||
58 | ($($x:expr),+ $(,)?) => { () }; | ||
59 | } | ||
60 | mod m { | ||
61 | fn outer() { | ||
62 | let _ = vec![FileSet::default(); self.len()]; | ||
63 | } | ||
64 | } | ||
65 | ", | ||
66 | ); | ||
67 | } | ||
68 | |||
69 | #[test] | ||
45 | fn cfg_diagnostics() { | 70 | fn cfg_diagnostics() { |
46 | check_diagnostics( | 71 | check_diagnostics( |
47 | r" | 72 | r" |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 61cbbbc8f..ce470fc3b 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -37,7 +37,6 @@ pub(super) struct Ctx { | |||
37 | file: HirFileId, | 37 | file: HirFileId, |
38 | source_ast_id_map: Arc<AstIdMap>, | 38 | source_ast_id_map: Arc<AstIdMap>, |
39 | body_ctx: crate::body::LowerCtx, | 39 | body_ctx: crate::body::LowerCtx, |
40 | inner_items: Vec<ModItem>, | ||
41 | forced_visibility: Option<RawVisibilityId>, | 40 | forced_visibility: Option<RawVisibilityId>, |
42 | } | 41 | } |
43 | 42 | ||
@@ -49,7 +48,6 @@ impl Ctx { | |||
49 | file, | 48 | file, |
50 | source_ast_id_map: db.ast_id_map(file), | 49 | source_ast_id_map: db.ast_id_map(file), |
51 | body_ctx: crate::body::LowerCtx::new(db, file), | 50 | body_ctx: crate::body::LowerCtx::new(db, file), |
52 | inner_items: Vec::new(), | ||
53 | forced_visibility: None, | 51 | forced_visibility: None, |
54 | } | 52 | } |
55 | } | 53 | } |
@@ -73,8 +71,6 @@ impl Ctx { | |||
73 | } | 71 | } |
74 | 72 | ||
75 | fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> { | 73 | fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> { |
76 | assert!(inner || self.inner_items.is_empty()); | ||
77 | |||
78 | // Collect inner items for 1-to-1-lowered items. | 74 | // Collect inner items for 1-to-1-lowered items. |
79 | match item { | 75 | match item { |
80 | ast::Item::Struct(_) | 76 | ast::Item::Struct(_) |