diff options
Diffstat (limited to 'crates/hir_def/src/nameres/tests')
-rw-r--r-- | crates/hir_def/src/nameres/tests/diagnostics.rs | 118 |
1 files changed, 0 insertions, 118 deletions
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 5a088b6e5..000000000 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | use base_db::fixture::WithFixture; | ||
2 | |||
3 | use crate::test_db::TestDB; | ||
4 | |||
5 | fn check_diagnostics(ra_fixture: &str) { | ||
6 | let db: TestDB = TestDB::with_files(ra_fixture); | ||
7 | db.check_diagnostics(); | ||
8 | } | ||
9 | |||
10 | fn check_no_diagnostics(ra_fixture: &str) { | ||
11 | let db: TestDB = TestDB::with_files(ra_fixture); | ||
12 | db.check_no_diagnostics(); | ||
13 | } | ||
14 | |||
15 | #[test] | ||
16 | fn inactive_item() { | ||
17 | // Additional tests in `cfg` crate. This only tests disabled cfgs. | ||
18 | |||
19 | check_diagnostics( | ||
20 | r#" | ||
21 | //- /lib.rs | ||
22 | #[cfg(no)] pub fn f() {} | ||
23 | //^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
24 | |||
25 | #[cfg(no)] #[cfg(no2)] mod m; | ||
26 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
27 | |||
28 | #[cfg(all(not(a), b))] enum E {} | ||
29 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
30 | |||
31 | #[cfg(feature = "std")] use std; | ||
32 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
33 | "#, | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | /// Tests that `cfg` attributes behind `cfg_attr` is handled properly. | ||
38 | #[test] | ||
39 | fn inactive_via_cfg_attr() { | ||
40 | cov_mark::check!(cfg_attr_active); | ||
41 | check_diagnostics( | ||
42 | r#" | ||
43 | //- /lib.rs | ||
44 | #[cfg_attr(not(never), cfg(no))] fn f() {} | ||
45 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
46 | |||
47 | #[cfg_attr(not(never), cfg(not(no)))] fn f() {} | ||
48 | |||
49 | #[cfg_attr(never, cfg(no))] fn g() {} | ||
50 | |||
51 | #[cfg_attr(not(never), inline, cfg(no))] fn h() {} | ||
52 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnconfiguredCode | ||
53 | "#, | ||
54 | ); | ||
55 | } | ||
56 | |||
57 | #[test] | ||
58 | fn builtin_macro_fails_expansion() { | ||
59 | check_diagnostics( | ||
60 | r#" | ||
61 | //- /lib.rs | ||
62 | #[rustc_builtin_macro] | ||
63 | macro_rules! include { () => {} } | ||
64 | |||
65 | include!("doesntexist"); | ||
66 | //^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `doesntexist` | ||
67 | "#, | ||
68 | ); | ||
69 | } | ||
70 | |||
71 | #[test] | ||
72 | fn include_macro_should_allow_empty_content() { | ||
73 | check_no_diagnostics( | ||
74 | r#" | ||
75 | //- /lib.rs | ||
76 | #[rustc_builtin_macro] | ||
77 | macro_rules! include { () => {} } | ||
78 | |||
79 | include!("bar.rs"); | ||
80 | //- /bar.rs | ||
81 | // empty | ||
82 | "#, | ||
83 | ); | ||
84 | } | ||
85 | |||
86 | #[test] | ||
87 | fn good_out_dir_diagnostic() { | ||
88 | check_diagnostics( | ||
89 | r#" | ||
90 | #[rustc_builtin_macro] | ||
91 | macro_rules! include { () => {} } | ||
92 | #[rustc_builtin_macro] | ||
93 | macro_rules! env { () => {} } | ||
94 | #[rustc_builtin_macro] | ||
95 | macro_rules! concat { () => {} } | ||
96 | |||
97 | include!(concat!(env!("OUT_DIR"), "/out.rs")); | ||
98 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "run build scripts" to fix | ||
99 | "#, | ||
100 | ); | ||
101 | } | ||
102 | |||
103 | #[test] | ||
104 | fn register_attr_and_tool() { | ||
105 | cov_mark::check!(register_attr); | ||
106 | cov_mark::check!(register_tool); | ||
107 | check_no_diagnostics( | ||
108 | r#" | ||
109 | #![register_tool(tool)] | ||
110 | #![register_attr(attr)] | ||
111 | |||
112 | #[tool::path] | ||
113 | #[attr] | ||
114 | struct S; | ||
115 | "#, | ||
116 | ); | ||
117 | // NB: we don't currently emit diagnostics here | ||
118 | } | ||