aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-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