diff --git a/crates/ra_assists/src/handlers/change_return_type_to_result.rs b/crates/ra_assists/src/handlers/change_return_type_to_result.rs index c6baa0a57c6..855baf1870a 100644 --- a/crates/ra_assists/src/handlers/change_return_type_to_result.rs +++ b/crates/ra_assists/src/handlers/change_return_type_to_result.rs @@ -4,6 +4,7 @@ use ra_syntax::{ }; use crate::{AssistContext, AssistId, Assists}; +use test_utils::mark; // Assist: change_return_type_to_result // @@ -22,8 +23,13 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex let fn_def = ret_type.syntax().parent().and_then(ast::FnDef::cast)?; let type_ref = &ret_type.type_ref()?; - if type_ref.syntax().text().to_string().starts_with("Result<") { - return None; + let ret_type_str = type_ref.syntax().text().to_string(); + let first_part_ret_type = ret_type_str.splitn(2, '<').next(); + if let Some(ret_type_first_part) = first_part_ret_type { + if ret_type_first_part.ends_with("Result") { + mark::hit!(change_return_type_to_result_simple_return_type_already_result); + return None; + } } let block_expr = &fn_def.body()?; @@ -296,6 +302,29 @@ mod tests { ); } + #[test] + fn change_return_type_to_result_simple_return_type_already_result_std() { + check_assist_not_applicable( + change_return_type_to_result, + r#"fn foo() -> std::result::Result, String> { + let test = "test"; + return 42i32; + }"#, + ); + } + + #[test] + fn change_return_type_to_result_simple_return_type_already_result() { + mark::check!(change_return_type_to_result_simple_return_type_already_result); + check_assist_not_applicable( + change_return_type_to_result, + r#"fn foo() -> Result, String> { + let test = "test"; + return 42i32; + }"#, + ); + } + #[test] fn change_return_type_to_result_simple_with_cursor() { check_assist(