aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/diagnostics.rs
diff options
context:
space:
mode:
authorPhil Ellison <[email protected]>2019-08-11 13:47:33 +0100
committerAleksey Kladov <[email protected]>2019-08-25 10:55:55 +0100
commit62c2002e2b21b3a74a4e2205ccc40fa93f722b34 (patch)
treed0cce1d3a5b5e9002c8bf377a63f5b28fcc3b80b /crates/ra_ide_api/src/diagnostics.rs
parentd025016f92866a932729394c22603b615cb458df (diff)
Add test that ok-wrapping handles type aliases
Diffstat (limited to 'crates/ra_ide_api/src/diagnostics.rs')
-rw-r--r--crates/ra_ide_api/src/diagnostics.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs
index 84d2b7fb1..5e25991c6 100644
--- a/crates/ra_ide_api/src/diagnostics.rs
+++ b/crates/ra_ide_api/src/diagnostics.rs
@@ -282,6 +282,44 @@ fn div(x: i32, y: i32) -> Result<i32, String> {
282 } 282 }
283 283
284 #[test] 284 #[test]
285 fn test_wrap_return_type_handles_type_aliases() {
286 let before = r#"
287 //- /main.rs
288 use std::{string::String, result::Result::{self, Ok, Err}};
289
290 type MyResult<T> = Result<T, String>;
291
292 fn div(x: i32, y: i32) -> MyResult<i32> {
293 if y == 0 {
294 return Err("div by zero".into());
295 }
296 x / y
297 }
298
299 //- /std/lib.rs
300 pub mod string {
301 pub struct String { }
302 }
303 pub mod result {
304 pub enum Result<T, E> { Ok(T), Err(E) }
305 }
306 "#;
307// The formatting here is a bit odd due to how the parse_fixture function works in test_utils -
308// it strips empty lines and leading whitespace. The important part of this test is that the final
309// `x / y` expr is now wrapped in `Ok(..)`
310 let after = r#"use std::{string::String, result::Result::{self, Ok, Err}};
311type MyResult<T> = Result<T, String>;
312fn div(x: i32, y: i32) -> MyResult<i32> {
313 if y == 0 {
314 return Err("div by zero".into());
315 }
316 Ok(x / y)
317}
318"#;
319 check_apply_diagnostic_fix_for_target_file("/main.rs", before, after);
320 }
321
322 #[test]
285 fn test_wrap_return_type_not_applicable() { 323 fn test_wrap_return_type_not_applicable() {
286 let content = r#" 324 let content = r#"
287 //- /main.rs 325 //- /main.rs