aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-21 15:28:40 +0000
committerGitHub <[email protected]>2021-01-21 15:28:40 +0000
commit47a70aadcedbcf28ad6d1ea59b77bf0e11493de0 (patch)
treee5f494422dacc1a6bcae2b696d06f937b64d9163 /crates/hir_def/src/nameres/tests
parent323138f32ea74cfe9f5381e9e170cf87e7592818 (diff)
parentec4a1dc297eb90dde4c22c682a35606aaa50b4d4 (diff)
Merge #7375
7375: Add support for running name resolution in block expressions r=jonas-schievink a=jonas-schievink This adds a `block_def_map` query that runs the name resolution algorithm on a block expression, and returns a `DefMap` that stores links to the parent `DefMap` (either the containing block or the crate-level `DefMap`). Blocks with no inner items return the parent's `DefMap` as-is, to avoid creating unnecessarily long `DefMap` chains. Path resolution is updated to recurse into the parent `DefMap` after looking up a path in the original `DefMap`. I've added a few new tests for this, but outside of those this isn't used yet. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres/tests')
-rw-r--r--crates/hir_def/src/nameres/tests/block.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/tests/block.rs b/crates/hir_def/src/nameres/tests/block.rs
new file mode 100644
index 000000000..ab7ec9d62
--- /dev/null
+++ b/crates/hir_def/src/nameres/tests/block.rs
@@ -0,0 +1,72 @@
1use super::*;
2
3#[test]
4fn inner_item_smoke() {
5 check_at(
6 r#"
7//- /lib.rs
8struct inner {}
9fn outer() {
10 $0
11 fn inner() {}
12}
13"#,
14 expect![[r#"
15 block scope
16 inner: v
17 crate
18 inner: t
19 outer: v
20 "#]],
21 );
22}
23
24#[test]
25fn use_from_crate() {
26 check_at(
27 r#"
28//- /lib.rs
29struct Struct;
30fn outer() {
31 use Struct;
32 use crate::Struct as CrateStruct;
33 use self::Struct as SelfStruct;
34 $0
35}
36"#,
37 expect![[r#"
38 block scope
39 CrateStruct: t v
40 SelfStruct: t v
41 Struct: t v
42 crate
43 Struct: t v
44 outer: v
45 "#]],
46 );
47}
48
49#[test]
50fn merge_namespaces() {
51 check_at(
52 r#"
53//- /lib.rs
54struct name {}
55fn outer() {
56 fn name() {}
57
58 use name as imported; // should import both `name`s
59
60 $0
61}
62"#,
63 expect![[r#"
64 block scope
65 imported: t v
66 name: v
67 crate
68 name: t
69 outer: v
70 "#]],
71 );
72}