aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/change_return_type_to_result.rs30
1 files changed, 28 insertions, 2 deletions
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 c6baa0a57..12572936a 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
@@ -22,8 +22,12 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
22 let fn_def = ret_type.syntax().parent().and_then(ast::FnDef::cast)?; 22 let fn_def = ret_type.syntax().parent().and_then(ast::FnDef::cast)?;
23 23
24 let type_ref = &ret_type.type_ref()?; 24 let type_ref = &ret_type.type_ref()?;
25 if type_ref.syntax().text().to_string().starts_with("Result<") { 25 let ret_type_str = type_ref.syntax().text().to_string();
26 return None; 26 let first_part_ret_type = ret_type_str.splitn(2, '<').next();
27 if let Some(ret_type_first_part) = first_part_ret_type {
28 if ret_type_first_part.ends_with("Result") {
29 return None;
30 }
27 } 31 }
28 32
29 let block_expr = &fn_def.body()?; 33 let block_expr = &fn_def.body()?;
@@ -297,6 +301,28 @@ mod tests {
297 } 301 }
298 302
299 #[test] 303 #[test]
304 fn change_return_type_to_result_simple_return_type_already_result_std() {
305 check_assist_not_applicable(
306 change_return_type_to_result,
307 r#"fn foo() -> std::result::Result<i32<|>, String> {
308 let test = "test";
309 return 42i32;
310 }"#,
311 );
312 }
313
314 #[test]
315 fn change_return_type_to_result_simple_return_type_already_result() {
316 check_assist_not_applicable(
317 change_return_type_to_result,
318 r#"fn foo() -> Result<i32<|>, String> {
319 let test = "test";
320 return 42i32;
321 }"#,
322 );
323 }
324
325 #[test]
300 fn change_return_type_to_result_simple_with_cursor() { 326 fn change_return_type_to_result_simple_with_cursor() {
301 check_assist( 327 check_assist(
302 change_return_type_to_result, 328 change_return_type_to_result,