aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 16:41:04 +0100
committerAleksey Kladov <[email protected]>2021-06-13 16:41:04 +0100
commit00303284b5cc3a82e32dc3ecbbcfeb2f99de6818 (patch)
tree685e3f21289eaeb25df597413528f25c6239813f /crates/hir_def
parent1e4aaee7bbc1d56698e70158aa35f578422623d9 (diff)
internal: refactor macro error
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/body/tests.rs88
-rw-r--r--crates/hir_def/src/nameres/tests.rs1
-rw-r--r--crates/hir_def/src/nameres/tests/diagnostics.rs76
3 files changed, 0 insertions, 165 deletions
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index 075dcc6d2..0dccabcfd 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -89,67 +89,6 @@ mod m {
89} 89}
90 90
91#[test] 91#[test]
92fn macro_diag_builtin() {
93 check_diagnostics(
94 r#"
95#[rustc_builtin_macro]
96macro_rules! env {}
97
98#[rustc_builtin_macro]
99macro_rules! include {}
100
101#[rustc_builtin_macro]
102macro_rules! compile_error {}
103
104#[rustc_builtin_macro]
105macro_rules! format_args {
106 () => {}
107}
108
109fn f() {
110 // Test a handful of built-in (eager) macros:
111
112 include!(invalid);
113 //^^^^^^^^^^^^^^^^^ could not convert tokens
114 include!("does not exist");
115 //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `does not exist`
116
117 env!(invalid);
118 //^^^^^^^^^^^^^ could not convert tokens
119
120 env!("OUT_DIR");
121 //^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix
122
123 compile_error!("compile_error works");
124 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ compile_error works
125
126 // Lazy:
127
128 format_args!();
129 //^^^^^^^^^^^^^^ no rule matches input tokens
130}
131 "#,
132 );
133}
134
135#[test]
136fn macro_rules_diag() {
137 check_diagnostics(
138 r#"
139macro_rules! m {
140 () => {};
141}
142fn f() {
143 m!();
144
145 m!(hi);
146 //^^^^^^ leftover tokens
147}
148 "#,
149 );
150}
151
152#[test]
153fn unresolved_macro_diag() { 92fn unresolved_macro_diag() {
154 check_diagnostics( 93 check_diagnostics(
155 r#" 94 r#"
@@ -161,30 +100,3 @@ fn f() {
161 ); 100 );
162} 101}
163 102
164#[test]
165fn dollar_crate_in_builtin_macro() {
166 check_diagnostics(
167 r#"
168#[macro_export]
169#[rustc_builtin_macro]
170macro_rules! format_args {}
171
172#[macro_export]
173macro_rules! arg {
174 () => {}
175}
176
177#[macro_export]
178macro_rules! outer {
179 () => {
180 $crate::format_args!( "", $crate::arg!(1) )
181 };
182}
183
184fn f() {
185 outer!();
186 //^^^^^^^^ leftover tokens
187}
188 "#,
189 )
190}
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs
index 58c01354a..cf43f2a96 100644
--- a/crates/hir_def/src/nameres/tests.rs
+++ b/crates/hir_def/src/nameres/tests.rs
@@ -2,7 +2,6 @@ mod globs;
2mod incremental; 2mod incremental;
3mod macros; 3mod macros;
4mod mod_resolution; 4mod mod_resolution;
5mod diagnostics;
6mod primitives; 5mod primitives;
7 6
8use std::sync::Arc; 7use std::sync::Arc;
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs
deleted file mode 100644
index f1ee03d4d..000000000
--- a/crates/hir_def/src/nameres/tests/diagnostics.rs
+++ /dev/null
@@ -1,76 +0,0 @@
1use base_db::fixture::WithFixture;
2
3use crate::test_db::TestDB;
4
5fn check_diagnostics(ra_fixture: &str) {
6 let db: TestDB = TestDB::with_files(ra_fixture);
7 db.check_diagnostics();
8}
9
10fn check_no_diagnostics(ra_fixture: &str) {
11 let db: TestDB = TestDB::with_files(ra_fixture);
12 db.check_no_diagnostics();
13}
14
15#[test]
16fn builtin_macro_fails_expansion() {
17 check_diagnostics(
18 r#"
19 //- /lib.rs
20 #[rustc_builtin_macro]
21 macro_rules! include { () => {} }
22
23 include!("doesntexist");
24 //^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `doesntexist`
25 "#,
26 );
27}
28
29#[test]
30fn include_macro_should_allow_empty_content() {
31 check_no_diagnostics(
32 r#"
33 //- /lib.rs
34 #[rustc_builtin_macro]
35 macro_rules! include { () => {} }
36
37 include!("bar.rs");
38 //- /bar.rs
39 // empty
40 "#,
41 );
42}
43
44#[test]
45fn good_out_dir_diagnostic() {
46 check_diagnostics(
47 r#"
48 #[rustc_builtin_macro]
49 macro_rules! include { () => {} }
50 #[rustc_builtin_macro]
51 macro_rules! env { () => {} }
52 #[rustc_builtin_macro]
53 macro_rules! concat { () => {} }
54
55 include!(concat!(env!("OUT_DIR"), "/out.rs"));
56 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix
57 "#,
58 );
59}
60
61#[test]
62fn register_attr_and_tool() {
63 cov_mark::check!(register_attr);
64 cov_mark::check!(register_tool);
65 check_no_diagnostics(
66 r#"
67#![register_tool(tool)]
68#![register_attr(attr)]
69
70#[tool::path]
71#[attr]
72struct S;
73 "#,
74 );
75 // NB: we don't currently emit diagnostics here
76}