diff options
author | Aleksey Kladov <[email protected]> | 2021-05-23 21:31:59 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-05-25 15:49:59 +0100 |
commit | 5c9f31d4c28478b4373e6cf5ec155745c840ee3f (patch) | |
tree | 6d105121d271c7532170875feafaadcd7ad500ba /crates/hir_def/src/nameres/tests/diagnostics.rs | |
parent | b7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2 (diff) |
internal: move diagnostics to hir
The idea here is to eventually get rid of `dyn Diagnostic` and
`DiagnosticSink` infrastructure altogether, and just have a `enum
hir::Diagnostic` instead.
The problem with `dyn Diagnostic` is that it is defined in the lowest
level of the stack (hir_expand), but is used by the highest level (ide).
As a first step, we free hir_expand and hir_def from `dyn Diagnostic`
and kick the can up to `hir_ty`, as an intermediate state. The plan is
then to move DiagnosticSink similarly to the hir crate, and, as final
third step, remove its usage from the ide.
One currently unsolved problem is testing. You can notice that the test
which checks precise diagnostic ranges, unresolved_import_in_use_tree,
was moved to the ide layer. Logically, only IDE should have the infra to
render a specific range.
At the same time, the range is determined with the data produced in
hir_def and hir crates, so this layering is rather unfortunate. Working
on hir_def shouldn't require compiling `ide` for testing.
Diffstat (limited to 'crates/hir_def/src/nameres/tests/diagnostics.rs')
-rw-r--r-- | crates/hir_def/src/nameres/tests/diagnostics.rs | 57 |
1 files changed, 15 insertions, 42 deletions
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs index 75147d973..ec6670952 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs | |||
@@ -18,7 +18,7 @@ fn unresolved_import() { | |||
18 | r" | 18 | r" |
19 | use does_exist; | 19 | use does_exist; |
20 | use does_not_exist; | 20 | use does_not_exist; |
21 | //^^^^^^^^^^^^^^ unresolved import | 21 | //^^^^^^^^^^^^^^^^^^^ UnresolvedImport |
22 | 22 | ||
23 | mod does_exist {} | 23 | mod does_exist {} |
24 | ", | 24 | ", |
@@ -26,40 +26,13 @@ fn unresolved_import() { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | #[test] | 28 | #[test] |
29 | fn unresolved_import_in_use_tree() { | ||
30 | // Only the relevant part of a nested `use` item should be highlighted. | ||
31 | check_diagnostics( | ||
32 | r" | ||
33 | use does_exist::{Exists, DoesntExist}; | ||
34 | //^^^^^^^^^^^ unresolved import | ||
35 | |||
36 | use {does_not_exist::*, does_exist}; | ||
37 | //^^^^^^^^^^^^^^^^^ unresolved import | ||
38 | |||
39 | use does_not_exist::{ | ||
40 | a, | ||
41 | //^ unresolved import | ||
42 | b, | ||
43 | //^ unresolved import | ||
44 | c, | ||
45 | //^ unresolved import | ||
46 | }; | ||
47 | |||
48 | mod does_exist { | ||
49 | pub struct Exists; | ||
50 | } | ||
51 | ", | ||
52 | ); | ||
53 | } | ||
54 | |||
55 | #[test] | ||
56 | fn unresolved_extern_crate() { | 29 | fn unresolved_extern_crate() { |
57 | check_diagnostics( | 30 | check_diagnostics( |
58 | r" | 31 | r" |
59 | //- /main.rs crate:main deps:core | 32 | //- /main.rs crate:main deps:core |
60 | extern crate core; | 33 | extern crate core; |
61 | extern crate doesnotexist; | 34 | extern crate doesnotexist; |
62 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | 35 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ UnresolvedExternCrate |
63 | //- /lib.rs crate:core | 36 | //- /lib.rs crate:core |
64 | ", | 37 | ", |
65 | ); | 38 | ); |
@@ -72,7 +45,7 @@ fn extern_crate_self_as() { | |||
72 | r" | 45 | r" |
73 | //- /lib.rs | 46 | //- /lib.rs |
74 | extern crate doesnotexist; | 47 | extern crate doesnotexist; |
75 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | 48 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ UnresolvedExternCrate |
76 | // Should not error. | 49 | // Should not error. |
77 | extern crate self as foo; | 50 | extern crate self as foo; |
78 | struct Foo; | 51 | struct Foo; |
@@ -88,18 +61,18 @@ fn dedup_unresolved_import_from_unresolved_crate() { | |||
88 | //- /main.rs crate:main | 61 | //- /main.rs crate:main |
89 | mod a { | 62 | mod a { |
90 | extern crate doesnotexist; | 63 | extern crate doesnotexist; |
91 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | 64 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ UnresolvedExternCrate |
92 | 65 | ||
93 | // Should not error, since we already errored for the missing crate. | 66 | // Should not error, since we already errored for the missing crate. |
94 | use doesnotexist::{self, bla, *}; | 67 | use doesnotexist::{self, bla, *}; |
95 | 68 | ||
96 | use crate::doesnotexist; | 69 | use crate::doesnotexist; |
97 | //^^^^^^^^^^^^^^^^^^^ unresolved import | 70 | //^^^^^^^^^^^^^^^^^^^^^^^^ UnresolvedImport |
98 | } | 71 | } |
99 | 72 | ||
100 | mod m { | 73 | mod m { |
101 | use super::doesnotexist; | 74 | use super::doesnotexist; |
102 | //^^^^^^^^^^^^^^^^^^^ unresolved import | 75 | //^^^^^^^^^^^^^^^^^^^^^^^^ UnresolvedImport |
103 | } | 76 | } |
104 | ", | 77 | ", |
105 | ); | 78 | ); |
@@ -112,7 +85,7 @@ fn unresolved_module() { | |||
112 | //- /lib.rs | 85 | //- /lib.rs |
113 | mod foo; | 86 | mod foo; |
114 | mod bar; | 87 | mod bar; |
115 | //^^^^^^^^ unresolved module | 88 | //^^^^^^^^ UnresolvedModule |
116 | mod baz {} | 89 | mod baz {} |
117 | //- /foo.rs | 90 | //- /foo.rs |
118 | ", | 91 | ", |
@@ -127,16 +100,16 @@ fn inactive_item() { | |||
127 | r#" | 100 | r#" |
128 | //- /lib.rs | 101 | //- /lib.rs |
129 | #[cfg(no)] pub fn f() {} | 102 | #[cfg(no)] pub fn f() {} |
130 | //^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled | 103 | //^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
131 | 104 | ||
132 | #[cfg(no)] #[cfg(no2)] mod m; | 105 | #[cfg(no)] #[cfg(no2)] mod m; |
133 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no and no2 are disabled | 106 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
134 | 107 | ||
135 | #[cfg(all(not(a), b))] enum E {} | 108 | #[cfg(all(not(a), b))] enum E {} |
136 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: b is disabled | 109 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
137 | 110 | ||
138 | #[cfg(feature = "std")] use std; | 111 | #[cfg(feature = "std")] use std; |
139 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: feature = "std" is disabled | 112 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
140 | "#, | 113 | "#, |
141 | ); | 114 | ); |
142 | } | 115 | } |
@@ -149,14 +122,14 @@ fn inactive_via_cfg_attr() { | |||
149 | r#" | 122 | r#" |
150 | //- /lib.rs | 123 | //- /lib.rs |
151 | #[cfg_attr(not(never), cfg(no))] fn f() {} | 124 | #[cfg_attr(not(never), cfg(no))] fn f() {} |
152 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled | 125 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
153 | 126 | ||
154 | #[cfg_attr(not(never), cfg(not(no)))] fn f() {} | 127 | #[cfg_attr(not(never), cfg(not(no)))] fn f() {} |
155 | 128 | ||
156 | #[cfg_attr(never, cfg(no))] fn g() {} | 129 | #[cfg_attr(never, cfg(no))] fn g() {} |
157 | 130 | ||
158 | #[cfg_attr(not(never), inline, cfg(no))] fn h() {} | 131 | #[cfg_attr(not(never), inline, cfg(no))] fn h() {} |
159 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ code is inactive due to #[cfg] directives: no is disabled | 132 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode |
160 | "#, | 133 | "#, |
161 | ); | 134 | ); |
162 | } | 135 | } |
@@ -170,7 +143,7 @@ fn unresolved_legacy_scope_macro() { | |||
170 | 143 | ||
171 | m!(); | 144 | m!(); |
172 | m2!(); | 145 | m2!(); |
173 | //^^^^^^ unresolved macro `self::m2!` | 146 | //^^^^^^ UnresolvedMacroCall |
174 | "#, | 147 | "#, |
175 | ); | 148 | ); |
176 | } | 149 | } |
@@ -187,7 +160,7 @@ fn unresolved_module_scope_macro() { | |||
187 | 160 | ||
188 | self::m!(); | 161 | self::m!(); |
189 | self::m2!(); | 162 | self::m2!(); |
190 | //^^^^^^^^^^^^ unresolved macro `self::m2!` | 163 | //^^^^^^^^^^^^ UnresolvedMacroCall |
191 | "#, | 164 | "#, |
192 | ); | 165 | ); |
193 | } | 166 | } |