From a40e390860987a23f9b899abc5947f1525d3709c Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 11 Aug 2019 15:00:37 +0100 Subject: Check type rather than just name in ok-wrapping diagnostic. Add test for handling generic functions (which currently fails) --- crates/ra_ide_api/src/diagnostics.rs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crates/ra_ide_api') 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 @@ -281,6 +281,43 @@ fn div(x: i32, y: i32) -> Result { check_apply_diagnostic_fix_for_target_file("/main.rs", before, after); } + #[test] + fn test_wrap_return_type_handles_generic_functions() { + let before = r#" + //- /main.rs + use std::{default::Default, result::Result::{self, Ok, Err}}; + + fn div(x: i32) -> Result { + if x == 0 { + return Err(7); + } + T::default() + } + + //- /std/lib.rs + pub mod result { + pub enum Result { Ok(T), Err(E) } + } + pub mod default { + pub trait Default { + fn default() -> Self; + } + } + "#; +// The formatting here is a bit odd due to how the parse_fixture function works in test_utils - +// it strips empty lines and leading whitespace. The important part of this test is that the final +// `x / y` expr is now wrapped in `Ok(..)` + let after = r#"use std::{default::Default, result::Result::{self, Ok, Err}}; +fn div(x: i32) -> Result { + if x == 0 { + return Err(7); + } + Ok(T::default()) +} +"#; + check_apply_diagnostic_fix_for_target_file("/main.rs", before, after); + } + #[test] fn test_wrap_return_type_handles_type_aliases() { let before = r#" -- cgit v1.2.3