diff options
author | Aleksey Kladov <[email protected]> | 2020-07-14 15:43:39 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-14 15:44:20 +0100 |
commit | b9070cc64e0767d2a8bde5084a61f46e2e804f5b (patch) | |
tree | 11eff9785ddae6ac25b9b74543fb36180bd20d82 /crates/ra_hir_ty/src/diagnostics | |
parent | 5a25cc28204c6d02a5108b13568ec71914f096a5 (diff) |
Refactor the test of diagnostic tests
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/expr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/match_check.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/unsafe_check.rs | 50 |
3 files changed, 52 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs index 277ace180..91caedc3d 100644 --- a/crates/ra_hir_ty/src/diagnostics/expr.rs +++ b/crates/ra_hir_ty/src/diagnostics/expr.rs | |||
@@ -376,7 +376,7 @@ pub fn record_pattern_missing_fields( | |||
376 | 376 | ||
377 | #[cfg(test)] | 377 | #[cfg(test)] |
378 | mod tests { | 378 | mod tests { |
379 | use crate::diagnostics::check_diagnostics; | 379 | use crate::diagnostics::tests::check_diagnostics; |
380 | 380 | ||
381 | #[test] | 381 | #[test] |
382 | fn simple_free_fn_zero() { | 382 | fn simple_free_fn_zero() { |
diff --git a/crates/ra_hir_ty/src/diagnostics/match_check.rs b/crates/ra_hir_ty/src/diagnostics/match_check.rs index 95f272811..507edcb7d 100644 --- a/crates/ra_hir_ty/src/diagnostics/match_check.rs +++ b/crates/ra_hir_ty/src/diagnostics/match_check.rs | |||
@@ -837,7 +837,7 @@ fn enum_variant_matches(cx: &MatchCheckCtx, pat_id: PatId, enum_variant_id: Enum | |||
837 | 837 | ||
838 | #[cfg(test)] | 838 | #[cfg(test)] |
839 | mod tests { | 839 | mod tests { |
840 | use crate::diagnostics::check_diagnostics; | 840 | use crate::diagnostics::tests::check_diagnostics; |
841 | 841 | ||
842 | #[test] | 842 | #[test] |
843 | fn empty_tuple() { | 843 | fn empty_tuple() { |
diff --git a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs index b8ff95ee1..9e4ed9a8b 100644 --- a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -121,3 +121,53 @@ fn walk_unsafe( | |||
121 | walk_unsafe(unsafe_exprs, db, infer, body, child, inside_unsafe_block); | 121 | walk_unsafe(unsafe_exprs, db, infer, body, child, inside_unsafe_block); |
122 | }); | 122 | }); |
123 | } | 123 | } |
124 | |||
125 | #[cfg(test)] | ||
126 | mod tests { | ||
127 | use crate::diagnostics::tests::check_diagnostics; | ||
128 | |||
129 | #[test] | ||
130 | fn missing_unsafe_diagnostic_with_raw_ptr() { | ||
131 | check_diagnostics( | ||
132 | r#" | ||
133 | fn main() { | ||
134 | let x = &5 as *const usize; | ||
135 | unsafe { let y = *x; } | ||
136 | let z = *x; | ||
137 | } //^^ This operation is unsafe and requires an unsafe function or block | ||
138 | "#, | ||
139 | ) | ||
140 | } | ||
141 | |||
142 | #[test] | ||
143 | fn missing_unsafe_diagnostic_with_unsafe_call() { | ||
144 | check_diagnostics( | ||
145 | r#" | ||
146 | struct HasUnsafe; | ||
147 | |||
148 | impl HasUnsafe { | ||
149 | unsafe fn unsafe_fn(&self) { | ||
150 | let x = &5 as *const usize; | ||
151 | let y = *x; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | unsafe fn unsafe_fn() { | ||
156 | let x = &5 as *const usize; | ||
157 | let y = *x; | ||
158 | } | ||
159 | |||
160 | fn main() { | ||
161 | unsafe_fn(); | ||
162 | //^^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block | ||
163 | HasUnsafe.unsafe_fn(); | ||
164 | //^^^^^^^^^^^^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block | ||
165 | unsafe { | ||
166 | unsafe_fn(); | ||
167 | HasUnsafe.unsafe_fn(); | ||
168 | } | ||
169 | } | ||
170 | "#, | ||
171 | ); | ||
172 | } | ||
173 | } | ||