diff options
author | Phil Ellison <[email protected]> | 2019-08-11 15:00:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-25 10:55:56 +0100 |
commit | a40e390860987a23f9b899abc5947f1525d3709c (patch) | |
tree | 39aa52a99ce47d439ab92d0519681d4524240820 /crates/ra_ide_api | |
parent | 62c2002e2b21b3a74a4e2205ccc40fa93f722b34 (diff) |
Check type rather than just name in ok-wrapping diagnostic. Add test for handling generic functions (which currently fails)
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 5e25991c6..57454719c 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -282,6 +282,43 @@ fn div(x: i32, y: i32) -> Result<i32, String> { | |||
282 | } | 282 | } |
283 | 283 | ||
284 | #[test] | 284 | #[test] |
285 | fn test_wrap_return_type_handles_generic_functions() { | ||
286 | let before = r#" | ||
287 | //- /main.rs | ||
288 | use std::{default::Default, result::Result::{self, Ok, Err}}; | ||
289 | |||
290 | fn div<T: Default, i32>(x: i32) -> Result<T, i32> { | ||
291 | if x == 0 { | ||
292 | return Err(7); | ||
293 | } | ||
294 | T::default() | ||
295 | } | ||
296 | |||
297 | //- /std/lib.rs | ||
298 | pub mod result { | ||
299 | pub enum Result<T, E> { Ok(T), Err(E) } | ||
300 | } | ||
301 | pub mod default { | ||
302 | pub trait Default { | ||
303 | fn default() -> Self; | ||
304 | } | ||
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::{default::Default, result::Result::{self, Ok, Err}}; | ||
311 | fn div<T: Default>(x: i32) -> Result<T, i32> { | ||
312 | if x == 0 { | ||
313 | return Err(7); | ||
314 | } | ||
315 | Ok(T::default()) | ||
316 | } | ||
317 | "#; | ||
318 | check_apply_diagnostic_fix_for_target_file("/main.rs", before, after); | ||
319 | } | ||
320 | |||
321 | #[test] | ||
285 | fn test_wrap_return_type_handles_type_aliases() { | 322 | fn test_wrap_return_type_handles_type_aliases() { |
286 | let before = r#" | 323 | let before = r#" |
287 | //- /main.rs | 324 | //- /main.rs |