From 29bf6bed9b65691a54a72f83c6cf3be40ae558e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Nov 2020 13:07:18 +0100 Subject: [PATCH 1/3] More consistent naming --- ....rs => replace_derive_with_manual_impl.rs} | 105 ++++++++++-------- crates/assists/src/lib.rs | 4 +- crates/assists/src/tests/generated.rs | 42 +++---- xtask/tests/tidy.rs | 8 +- 4 files changed, 89 insertions(+), 70 deletions(-) rename crates/assists/src/handlers/{add_custom_impl.rs => replace_derive_with_manual_impl.rs} (74%) diff --git a/crates/assists/src/handlers/add_custom_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs similarity index 74% rename from crates/assists/src/handlers/add_custom_impl.rs rename to crates/assists/src/handlers/replace_derive_with_manual_impl.rs index c13493fd87..82625516c2 100644 --- a/crates/assists/src/handlers/add_custom_impl.rs +++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs @@ -16,24 +16,31 @@ use crate::{ AssistId, AssistKind, }; -// Assist: add_custom_impl +// Assist: replace_derive_with_manual_impl // -// Adds impl block for derived trait. +// Converts a `derive` impl into a manual one. // // ``` +// # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } // #[derive(Deb<|>ug, Display)] // struct S; // ``` // -> // ``` +// # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } // #[derive(Display)] // struct S; // // impl Debug for S { -// $0 +// fn fmt(&self, f: &mut Formatter) -> Result<()> { +// ${0:todo!()} +// } // } // ``` -pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn replace_derive_with_manual_impl( + acc: &mut Assists, + ctx: &AssistContext, +) -> Option<()> { let attr = ctx.find_node_at_offset::()?; let attr_name = attr @@ -90,43 +97,49 @@ fn add_assist( ) -> Option<()> { let target = attr.syntax().text_range(); let input = attr.token_tree()?; - let label = format!("Add custom impl `{}` for `{}`", trait_path, annotated_name); + let label = format!("Convert to manual `impl {} for {}`", trait_path, annotated_name); let trait_name = trait_path.segment().and_then(|seg| seg.name_ref())?; - acc.add(AssistId("add_custom_impl", AssistKind::Refactor), label, target, |builder| { - let impl_def_with_items = - impl_def_from_trait(&ctx.sema, annotated_name, trait_, trait_path); - update_attribute(builder, &input, &trait_name, &attr); - match (ctx.config.snippet_cap, impl_def_with_items) { - (None, _) => builder.insert( - insert_pos, - format!("\n\nimpl {} for {} {{\n\n}}", trait_path, annotated_name), - ), - (Some(cap), None) => builder.insert_snippet( - cap, - insert_pos, - format!("\n\nimpl {} for {} {{\n $0\n}}", trait_path, annotated_name), - ), - (Some(cap), Some((impl_def, first_assoc_item))) => { - let mut cursor = Cursor::Before(first_assoc_item.syntax()); - let placeholder; - if let ast::AssocItem::Fn(ref func) = first_assoc_item { - if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) { - if m.syntax().text() == "todo!()" { - placeholder = m; - cursor = Cursor::Replace(placeholder.syntax()); - } - } - } - - builder.insert_snippet( + acc.add( + AssistId("replace_derive_with_manual_impl", AssistKind::Refactor), + label, + target, + |builder| { + let impl_def_with_items = + impl_def_from_trait(&ctx.sema, annotated_name, trait_, trait_path); + update_attribute(builder, &input, &trait_name, &attr); + match (ctx.config.snippet_cap, impl_def_with_items) { + (None, _) => builder.insert( + insert_pos, + format!("\n\nimpl {} for {} {{\n\n}}", trait_path, annotated_name), + ), + (Some(cap), None) => builder.insert_snippet( cap, insert_pos, - format!("\n\n{}", render_snippet(cap, impl_def.syntax(), cursor)), - ) - } - }; - }) + format!("\n\nimpl {} for {} {{\n $0\n}}", trait_path, annotated_name), + ), + (Some(cap), Some((impl_def, first_assoc_item))) => { + let mut cursor = Cursor::Before(first_assoc_item.syntax()); + let placeholder; + if let ast::AssocItem::Fn(ref func) = first_assoc_item { + if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast) + { + if m.syntax().text() == "todo!()" { + placeholder = m; + cursor = Cursor::Replace(placeholder.syntax()); + } + } + } + + builder.insert_snippet( + cap, + insert_pos, + format!("\n\n{}", render_snippet(cap, impl_def.syntax(), cursor)), + ) + } + }; + }, + ) } fn impl_def_from_trait( @@ -192,7 +205,7 @@ mod tests { #[test] fn add_custom_impl_debug() { check_assist( - add_custom_impl, + replace_derive_with_manual_impl, " mod fmt { pub struct Error; @@ -233,7 +246,7 @@ impl fmt::Debug for Foo { #[test] fn add_custom_impl_all() { check_assist( - add_custom_impl, + replace_derive_with_manual_impl, " mod foo { pub trait Bar { @@ -282,7 +295,7 @@ impl foo::Bar for Foo { #[test] fn add_custom_impl_for_unique_input() { check_assist( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive(Debu<|>g)] struct Foo { @@ -304,7 +317,7 @@ impl Debug for Foo { #[test] fn add_custom_impl_for_with_visibility_modifier() { check_assist( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive(Debug<|>)] pub struct Foo { @@ -326,7 +339,7 @@ impl Debug for Foo { #[test] fn add_custom_impl_when_multiple_inputs() { check_assist( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive(Display, Debug<|>, Serialize)] struct Foo {} @@ -345,7 +358,7 @@ impl Debug for Foo { #[test] fn test_ignore_derive_macro_without_input() { check_assist_not_applicable( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive(<|>)] struct Foo {} @@ -356,7 +369,7 @@ struct Foo {} #[test] fn test_ignore_if_cursor_on_param() { check_assist_not_applicable( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive<|>(Debug)] struct Foo {} @@ -364,7 +377,7 @@ struct Foo {} ); check_assist_not_applicable( - add_custom_impl, + replace_derive_with_manual_impl, " #[derive(Debug)<|>] struct Foo {} @@ -375,7 +388,7 @@ struct Foo {} #[test] fn test_ignore_if_not_derive() { check_assist_not_applicable( - add_custom_impl, + replace_derive_with_manual_impl, " #[allow(non_camel_<|>case_types)] struct Foo {} diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index af88b34374..92f7641454 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs @@ -120,7 +120,6 @@ mod handlers { pub(crate) type Handler = fn(&mut Assists, &AssistContext) -> Option<()>; - mod add_custom_impl; mod add_explicit_type; mod add_missing_impl_members; mod add_turbo_fish; @@ -157,6 +156,7 @@ mod handlers { mod remove_mut; mod remove_unused_param; mod reorder_fields; + mod replace_derive_with_manual_impl; mod replace_if_let_with_match; mod replace_impl_trait_with_generic; mod replace_let_with_if_let; @@ -169,7 +169,6 @@ mod handlers { pub(crate) fn all() -> &'static [Handler] { &[ // These are alphabetic for the foolish consistency - add_custom_impl::add_custom_impl, add_explicit_type::add_explicit_type, add_turbo_fish::add_turbo_fish, apply_demorgan::apply_demorgan, @@ -208,6 +207,7 @@ mod handlers { remove_mut::remove_mut, remove_unused_param::remove_unused_param, reorder_fields::reorder_fields, + replace_derive_with_manual_impl::replace_derive_with_manual_impl, replace_if_let_with_match::replace_if_let_with_match, replace_impl_trait_with_generic::replace_impl_trait_with_generic, replace_let_with_if_let::replace_let_with_if_let, diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 168e1626ab..629788f055 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs @@ -2,25 +2,6 @@ use super::check_doc_test; -#[test] -fn doctest_add_custom_impl() { - check_doc_test( - "add_custom_impl", - r#####" -#[derive(Deb<|>ug, Display)] -struct S; -"#####, - r#####" -#[derive(Display)] -struct S; - -impl Debug for S { - $0 -} -"#####, - ) -} - #[test] fn doctest_add_explicit_type() { check_doc_test( @@ -831,6 +812,29 @@ const test: Foo = Foo {foo: 1, bar: 0} ) } +#[test] +fn doctest_replace_derive_with_manual_impl() { + check_doc_test( + "replace_derive_with_manual_impl", + r#####" +trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } +#[derive(Deb<|>ug, Display)] +struct S; +"#####, + r#####" +trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; } +#[derive(Display)] +struct S; + +impl Debug for S { + fn fmt(&self, f: &mut Formatter) -> Result<()> { + ${0:todo!()} + } +} +"#####, + ) +} + #[test] fn doctest_replace_if_let_with_match() { check_doc_test( diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 4c7db8405e..99652e76b6 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -214,9 +214,6 @@ fn check_todo(path: &Path, text: &str) { // This file itself obviously needs to use todo (<- like this!). "tests/cli.rs", // Some of our assists generate `todo!()`. - "tests/generated.rs", - "handlers/add_custom_impl.rs", - "handlers/add_missing_impl_members.rs", "handlers/add_turbo_fish.rs", "handlers/generate_function.rs", // To support generating `todo!()` in assists, we have `expr_todo()` in @@ -229,6 +226,11 @@ fn check_todo(path: &Path, text: &str) { return; } if text.contains("TODO") || text.contains("TOOD") || text.contains("todo!") { + // Generated by an assist + if text.contains("${0:todo!()}") { + return; + } + panic!( "\nTODO markers or todo! macros should not be committed to the master branch,\n\ use FIXME instead\n\ From 3cecf78488a40638c8f6ea8b9482080d4bfafca4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Nov 2020 13:18:40 +0100 Subject: [PATCH 2/3] More consistent naming --- ...esult.rs => wrap_return_type_in_result.rs} | 132 +++++++++--------- crates/assists/src/lib.rs | 4 +- crates/assists/src/tests/generated.rs | 26 ++-- 3 files changed, 81 insertions(+), 81 deletions(-) rename crates/assists/src/handlers/{change_return_type_to_result.rs => wrap_return_type_in_result.rs} (88%) diff --git a/crates/assists/src/handlers/change_return_type_to_result.rs b/crates/assists/src/handlers/wrap_return_type_in_result.rs similarity index 88% rename from crates/assists/src/handlers/change_return_type_to_result.rs rename to crates/assists/src/handlers/wrap_return_type_in_result.rs index 76f33a5b6d..e08981f89c 100644 --- a/crates/assists/src/handlers/change_return_type_to_result.rs +++ b/crates/assists/src/handlers/wrap_return_type_in_result.rs @@ -8,9 +8,9 @@ use test_utils::mark; use crate::{AssistContext, AssistId, AssistKind, Assists}; -// Assist: change_return_type_to_result +// Assist: wrap_return_type_in_result // -// Change the function's return type to Result. +// Wrap the function's return type into Result. // // ``` // fn foo() -> i32<|> { 42i32 } @@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // ``` // fn foo() -> Result { Ok(42i32) } // ``` -pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let ret_type = ctx.find_node_at_offset::()?; let parent = ret_type.syntax().parent()?; let block_expr = match_ast! { @@ -39,13 +39,13 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex 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); + mark::hit!(wrap_return_type_in_result_simple_return_type_already_result); return None; } } acc.add( - AssistId("change_return_type_to_result", AssistKind::RefactorRewrite), + AssistId("wrap_return_type_in_result", AssistKind::RefactorRewrite), "Wrap return type in Result", type_ref.syntax().text_range(), |builder| { @@ -278,9 +278,9 @@ mod tests { use super::*; #[test] - fn change_return_type_to_result_simple() { + fn wrap_return_type_in_result_simple() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i3<|>2 { let test = "test"; return 42i32; @@ -293,9 +293,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_closure() { + fn wrap_return_type_in_result_simple_closure() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -> i32<|> { let test = "test"; @@ -312,9 +312,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_return_type_bad_cursor() { + fn wrap_return_type_in_result_simple_return_type_bad_cursor() { check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32 { let test = "test";<|> return 42i32; @@ -323,9 +323,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_return_type_bad_cursor_closure() { + fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() { check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -> i32 { let test = "test";<|> @@ -336,9 +336,9 @@ mod tests { } #[test] - fn change_return_type_to_result_closure_non_block() { + fn wrap_return_type_in_result_closure_non_block() { check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -> i<|>32 3; }"#, @@ -346,9 +346,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_return_type_already_result_std() { + fn wrap_return_type_in_result_simple_return_type_already_result_std() { check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> std::result::Result, String> { let test = "test"; return 42i32; @@ -357,10 +357,10 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_return_type_already_result() { - mark::check!(change_return_type_to_result_simple_return_type_already_result); + fn wrap_return_type_in_result_simple_return_type_already_result() { + mark::check!(wrap_return_type_in_result_simple_return_type_already_result); check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> Result, String> { let test = "test"; return 42i32; @@ -369,9 +369,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_return_type_already_result_closure() { + fn wrap_return_type_in_result_simple_return_type_already_result_closure() { check_assist_not_applicable( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -> Result, String> { let test = "test"; @@ -382,9 +382,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_cursor() { + fn wrap_return_type_in_result_simple_with_cursor() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> <|>i32 { let test = "test"; return 42i32; @@ -397,9 +397,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail() { + fn wrap_return_type_in_result_simple_with_tail() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -><|> i32 { let test = "test"; 42i32 @@ -412,9 +412,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_closure() { + fn wrap_return_type_in_result_simple_with_tail_closure() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -><|> i32 { let test = "test"; @@ -431,9 +431,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_only() { + fn wrap_return_type_in_result_simple_with_tail_only() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { 42i32 }"#, @@ -444,9 +444,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_block_like() { + fn wrap_return_type_in_result_simple_with_tail_block_like() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { if true { 42i32 @@ -465,9 +465,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_without_block_closure() { + fn wrap_return_type_in_result_simple_without_block_closure() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() { || -> i32<|> { if true { @@ -490,9 +490,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_nested_if() { + fn wrap_return_type_in_result_simple_with_nested_if() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { if true { if false { @@ -519,9 +519,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_await() { + fn wrap_return_type_in_result_simple_with_await() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"async fn foo() -> i<|>32 { if true { if false { @@ -548,9 +548,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_array() { + fn wrap_return_type_in_result_simple_with_array() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> [i32;<|> 3] { [1, 2, 3] }"#, @@ -561,9 +561,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_cast() { + fn wrap_return_type_in_result_simple_with_cast() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -<|>> i32 { if true { if false { @@ -590,9 +590,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_block_like_match() { + fn wrap_return_type_in_result_simple_with_tail_block_like_match() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = 5; match my_var { @@ -611,9 +611,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_loop_with_tail() { + fn wrap_return_type_in_result_simple_with_loop_with_tail() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = 5; loop { @@ -636,9 +636,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_loop_in_let_stmt() { + fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = let x = loop { break 1; @@ -657,9 +657,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_block_like_match_return_expr() { + fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = 5; let res = match my_var { @@ -681,7 +681,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = 5; let res = if my_var == 5 { @@ -706,9 +706,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_block_like_match_deeper() { + fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let my_var = 5; match my_var { @@ -751,9 +751,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_tail_block_like_early_return() { + fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i<|>32 { let test = "test"; if test == "test" { @@ -772,9 +772,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_closure() { + fn wrap_return_type_in_result_simple_with_closure() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -><|> u32 { let true_closure = || { return true; @@ -812,7 +812,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -> u32<|> { let true_closure = || { return true; @@ -853,9 +853,9 @@ mod tests { } #[test] - fn change_return_type_to_result_simple_with_weird_forms() { + fn wrap_return_type_in_result_simple_with_weird_forms() { check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let test = "test"; if test == "test" { @@ -885,7 +885,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i32<|> { let test = "test"; if test == "test" { @@ -919,7 +919,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo() -> i3<|>2 { let test = "test"; let other = 5; @@ -961,7 +961,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -> u32<|> { if the_field < 5 { let mut i = 0; @@ -1001,7 +1001,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -> u3<|>2 { if the_field < 5 { let mut i = 0; @@ -1029,7 +1029,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -> u32<|> { if the_field < 5 { let mut i = 0; @@ -1059,7 +1059,7 @@ mod tests { ); check_assist( - change_return_type_to_result, + wrap_return_type_in_result, r#"fn foo(the_field: u32) -> <|>u32 { if the_field < 5 { let mut i = 0; diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index 92f7641454..e8d81b33d7 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs @@ -125,7 +125,6 @@ mod handlers { mod add_turbo_fish; mod apply_demorgan; mod auto_import; - mod change_return_type_to_result; mod change_visibility; mod convert_integer_literal; mod early_return; @@ -165,6 +164,7 @@ mod handlers { mod replace_unwrap_with_match; mod split_import; mod unwrap_block; + mod wrap_return_type_in_result; pub(crate) fn all() -> &'static [Handler] { &[ @@ -173,7 +173,6 @@ mod handlers { add_turbo_fish::add_turbo_fish, apply_demorgan::apply_demorgan, auto_import::auto_import, - change_return_type_to_result::change_return_type_to_result, change_visibility::change_visibility, convert_integer_literal::convert_integer_literal, early_return::convert_to_guarded_return, @@ -215,6 +214,7 @@ mod handlers { replace_unwrap_with_match::replace_unwrap_with_match, split_import::split_import, unwrap_block::unwrap_block, + wrap_return_type_in_result::wrap_return_type_in_result, // These are manually sorted for better priorities add_missing_impl_members::add_missing_impl_members, add_missing_impl_members::add_missing_default_members, diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 629788f055..dbf4f21aa5 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs @@ -158,19 +158,6 @@ pub mod std { pub mod collections { pub struct HashMap { } } } ) } -#[test] -fn doctest_change_return_type_to_result() { - check_doc_test( - "change_return_type_to_result", - r#####" -fn foo() -> i32<|> { 42i32 } -"#####, - r#####" -fn foo() -> Result { Ok(42i32) } -"#####, - ) -} - #[test] fn doctest_change_visibility() { check_doc_test( @@ -989,3 +976,16 @@ fn foo() { "#####, ) } + +#[test] +fn doctest_wrap_return_type_in_result() { + check_doc_test( + "wrap_return_type_in_result", + r#####" +fn foo() -> i32<|> { 42i32 } +"#####, + r#####" +fn foo() -> Result { Ok(42i32) } +"#####, + ) +} From d31ce3b16cbd23950197d8992720b431e19b6af1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Nov 2020 13:28:04 +0100 Subject: [PATCH 3/3] Use standard style for test code --- .../handlers/wrap_return_type_in_result.rs | 1203 +++++++++-------- 1 file changed, 635 insertions(+), 568 deletions(-) diff --git a/crates/assists/src/handlers/wrap_return_type_in_result.rs b/crates/assists/src/handlers/wrap_return_type_in_result.rs index e08981f89c..59e5debb13 100644 --- a/crates/assists/src/handlers/wrap_return_type_in_result.rs +++ b/crates/assists/src/handlers/wrap_return_type_in_result.rs @@ -281,14 +281,18 @@ mod tests { fn wrap_return_type_in_result_simple() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i3<|>2 { - let test = "test"; - return 42i32; - }"#, - r#"fn foo() -> Result { - let test = "test"; - return Ok(42i32); - }"#, + r#" +fn foo() -> i3<|>2 { + let test = "test"; + return 42i32; +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + return Ok(42i32); +} +"#, ); } @@ -296,18 +300,22 @@ mod tests { fn wrap_return_type_in_result_simple_closure() { check_assist( wrap_return_type_in_result, - r#"fn foo() { - || -> i32<|> { - let test = "test"; - return 42i32; - }; - }"#, - r#"fn foo() { - || -> Result { - let test = "test"; - return Ok(42i32); - }; - }"#, + r#" +fn foo() { + || -> i32<|> { + let test = "test"; + return 42i32; + }; +} +"#, + r#" +fn foo() { + || -> Result { + let test = "test"; + return Ok(42i32); + }; +} +"#, ); } @@ -315,10 +323,12 @@ mod tests { fn wrap_return_type_in_result_simple_return_type_bad_cursor() { check_assist_not_applicable( wrap_return_type_in_result, - r#"fn foo() -> i32 { - let test = "test";<|> - return 42i32; - }"#, + r#" +fn foo() -> i32 { + let test = "test";<|> + return 42i32; +} +"#, ); } @@ -326,33 +336,32 @@ mod tests { fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() { check_assist_not_applicable( wrap_return_type_in_result, - r#"fn foo() { - || -> i32 { - let test = "test";<|> - return 42i32; - }; - }"#, + r#" +fn foo() { + || -> i32 { + let test = "test";<|> + return 42i32; + }; +} +"#, ); } #[test] fn wrap_return_type_in_result_closure_non_block() { - check_assist_not_applicable( - wrap_return_type_in_result, - r#"fn foo() { - || -> i<|>32 3; - }"#, - ); + check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i<|>32 3; }"#); } #[test] fn wrap_return_type_in_result_simple_return_type_already_result_std() { check_assist_not_applicable( wrap_return_type_in_result, - r#"fn foo() -> std::result::Result, String> { - let test = "test"; - return 42i32; - }"#, + r#" +fn foo() -> std::result::Result, String> { + let test = "test"; + return 42i32; +} +"#, ); } @@ -361,10 +370,12 @@ mod tests { mark::check!(wrap_return_type_in_result_simple_return_type_already_result); check_assist_not_applicable( wrap_return_type_in_result, - r#"fn foo() -> Result, String> { - let test = "test"; - return 42i32; - }"#, + r#" +fn foo() -> Result, String> { + let test = "test"; + return 42i32; +} +"#, ); } @@ -372,12 +383,14 @@ mod tests { fn wrap_return_type_in_result_simple_return_type_already_result_closure() { check_assist_not_applicable( wrap_return_type_in_result, - r#"fn foo() { - || -> Result, String> { - let test = "test"; - return 42i32; - }; - }"#, + r#" +fn foo() { + || -> Result, String> { + let test = "test"; + return 42i32; + }; +} +"#, ); } @@ -385,14 +398,18 @@ mod tests { fn wrap_return_type_in_result_simple_with_cursor() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> <|>i32 { - let test = "test"; - return 42i32; - }"#, - r#"fn foo() -> Result { - let test = "test"; - return Ok(42i32); - }"#, + r#" +fn foo() -> <|>i32 { + let test = "test"; + return 42i32; +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + return Ok(42i32); +} +"#, ); } @@ -400,14 +417,18 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail() { check_assist( wrap_return_type_in_result, - r#"fn foo() -><|> i32 { - let test = "test"; - 42i32 - }"#, - r#"fn foo() -> Result { - let test = "test"; - Ok(42i32) - }"#, + r#" +fn foo() -><|> i32 { + let test = "test"; + 42i32 +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + Ok(42i32) +} +"#, ); } @@ -415,18 +436,22 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_closure() { check_assist( wrap_return_type_in_result, - r#"fn foo() { - || -><|> i32 { - let test = "test"; - 42i32 - }; - }"#, - r#"fn foo() { - || -> Result { - let test = "test"; - Ok(42i32) - }; - }"#, + r#" +fn foo() { + || -><|> i32 { + let test = "test"; + 42i32 + }; +} +"#, + r#" +fn foo() { + || -> Result { + let test = "test"; + Ok(42i32) + }; +} +"#, ); } @@ -434,12 +459,8 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_only() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - 42i32 - }"#, - r#"fn foo() -> Result { - Ok(42i32) - }"#, + r#"fn foo() -> i32<|> { 42i32 }"#, + r#"fn foo() -> Result { Ok(42i32) }"#, ); } @@ -447,20 +468,24 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_block_like() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - if true { - 42i32 - } else { - 24i32 - } - }"#, - r#"fn foo() -> Result { - if true { - Ok(42i32) - } else { - Ok(24i32) - } - }"#, + r#" +fn foo() -> i32<|> { + if true { + 42i32 + } else { + 24i32 + } +} +"#, + r#" +fn foo() -> Result { + if true { + Ok(42i32) + } else { + Ok(24i32) + } +} +"#, ); } @@ -468,24 +493,28 @@ mod tests { fn wrap_return_type_in_result_simple_without_block_closure() { check_assist( wrap_return_type_in_result, - r#"fn foo() { - || -> i32<|> { - if true { - 42i32 - } else { - 24i32 - } - }; - }"#, - r#"fn foo() { - || -> Result { - if true { - Ok(42i32) - } else { - Ok(24i32) - } - }; - }"#, + r#" +fn foo() { + || -> i32<|> { + if true { + 42i32 + } else { + 24i32 + } + }; +} +"#, + r#" +fn foo() { + || -> Result { + if true { + Ok(42i32) + } else { + Ok(24i32) + } + }; +} +"#, ); } @@ -493,28 +522,32 @@ mod tests { fn wrap_return_type_in_result_simple_with_nested_if() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - if true { - if false { - 1 - } else { - 2 - } - } else { - 24i32 - } - }"#, - r#"fn foo() -> Result { - if true { - if false { - Ok(1) - } else { - Ok(2) - } - } else { - Ok(24i32) - } - }"#, + r#" +fn foo() -> i32<|> { + if true { + if false { + 1 + } else { + 2 + } + } else { + 24i32 + } +} +"#, + r#" +fn foo() -> Result { + if true { + if false { + Ok(1) + } else { + Ok(2) + } + } else { + Ok(24i32) + } +} +"#, ); } @@ -522,28 +555,32 @@ mod tests { fn wrap_return_type_in_result_simple_with_await() { check_assist( wrap_return_type_in_result, - r#"async fn foo() -> i<|>32 { - if true { - if false { - 1.await - } else { - 2.await - } - } else { - 24i32.await - } - }"#, - r#"async fn foo() -> Result { - if true { - if false { - Ok(1.await) - } else { - Ok(2.await) - } - } else { - Ok(24i32.await) - } - }"#, + r#" +async fn foo() -> i<|>32 { + if true { + if false { + 1.await + } else { + 2.await + } + } else { + 24i32.await + } +} +"#, + r#" +async fn foo() -> Result { + if true { + if false { + Ok(1.await) + } else { + Ok(2.await) + } + } else { + Ok(24i32.await) + } +} +"#, ); } @@ -551,12 +588,8 @@ mod tests { fn wrap_return_type_in_result_simple_with_array() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> [i32;<|> 3] { - [1, 2, 3] - }"#, - r#"fn foo() -> Result<[i32; 3], ${0:_}> { - Ok([1, 2, 3]) - }"#, + r#"fn foo() -> [i32;<|> 3] { [1, 2, 3] }"#, + r#"fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }"#, ); } @@ -564,28 +597,32 @@ mod tests { fn wrap_return_type_in_result_simple_with_cast() { check_assist( wrap_return_type_in_result, - r#"fn foo() -<|>> i32 { - if true { - if false { - 1 as i32 - } else { - 2 as i32 - } - } else { - 24 as i32 - } - }"#, - r#"fn foo() -> Result { - if true { - if false { - Ok(1 as i32) - } else { - Ok(2 as i32) - } - } else { - Ok(24 as i32) - } - }"#, + r#" +fn foo() -<|>> i32 { + if true { + if false { + 1 as i32 + } else { + 2 as i32 + } + } else { + 24 as i32 + } +} +"#, + r#" +fn foo() -> Result { + if true { + if false { + Ok(1 as i32) + } else { + Ok(2 as i32) + } + } else { + Ok(24 as i32) + } +} +"#, ); } @@ -593,20 +630,24 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_block_like_match() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = 5; - match my_var { - 5 => 42i32, - _ => 24i32, - } - }"#, - r#"fn foo() -> Result { - let my_var = 5; - match my_var { - 5 => Ok(42i32), - _ => Ok(24i32), - } - }"#, + r#" +fn foo() -> i32<|> { + let my_var = 5; + match my_var { + 5 => 42i32, + _ => 24i32, + } +} +"#, + r#" +fn foo() -> Result { + let my_var = 5; + match my_var { + 5 => Ok(42i32), + _ => Ok(24i32), + } +} +"#, ); } @@ -614,24 +655,26 @@ mod tests { fn wrap_return_type_in_result_simple_with_loop_with_tail() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = 5; - loop { - println!("test"); - 5 - } - - my_var - }"#, - r#"fn foo() -> Result { - let my_var = 5; - loop { - println!("test"); - 5 - } - - Ok(my_var) - }"#, + r#" +fn foo() -> i32<|> { + let my_var = 5; + loop { + println!("test"); + 5 + } + my_var +} +"#, + r#" +fn foo() -> Result { + let my_var = 5; + loop { + println!("test"); + 5 + } + Ok(my_var) +} +"#, ); } @@ -639,20 +682,22 @@ mod tests { fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = let x = loop { - break 1; - }; - - my_var - }"#, - r#"fn foo() -> Result { - let my_var = let x = loop { - break 1; - }; - - Ok(my_var) - }"#, + r#" +fn foo() -> i32<|> { + let my_var = let x = loop { + break 1; + }; + my_var +} +"#, + r#" +fn foo() -> Result { + let my_var = let x = loop { + break 1; + }; + Ok(my_var) +} +"#, ); } @@ -660,48 +705,52 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = 5; - let res = match my_var { - 5 => 42i32, - _ => return 24i32, - }; - - res - }"#, - r#"fn foo() -> Result { - let my_var = 5; - let res = match my_var { - 5 => 42i32, - _ => return Ok(24i32), - }; - - Ok(res) - }"#, + r#" +fn foo() -> i32<|> { + let my_var = 5; + let res = match my_var { + 5 => 42i32, + _ => return 24i32, + }; + res +} +"#, + r#" +fn foo() -> Result { + let my_var = 5; + let res = match my_var { + 5 => 42i32, + _ => return Ok(24i32), + }; + Ok(res) +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = 5; - let res = if my_var == 5 { - 42i32 - } else { - return 24i32; - }; - - res - }"#, - r#"fn foo() -> Result { - let my_var = 5; - let res = if my_var == 5 { - 42i32 - } else { - return Ok(24i32); - }; - - Ok(res) - }"#, + r#" +fn foo() -> i32<|> { + let my_var = 5; + let res = if my_var == 5 { + 42i32 + } else { + return 24i32; + }; + res +} +"#, + r#" +fn foo() -> Result { + let my_var = 5; + let res = if my_var == 5 { + 42i32 + } else { + return Ok(24i32); + }; + Ok(res) +} +"#, ); } @@ -709,44 +758,48 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let my_var = 5; - match my_var { - 5 => { - if true { - 42i32 - } else { - 25i32 - } - }, - _ => { - let test = "test"; - if test == "test" { - return bar(); - } - 53i32 - }, - } - }"#, - r#"fn foo() -> Result { - let my_var = 5; - match my_var { - 5 => { - if true { - Ok(42i32) - } else { - Ok(25i32) - } - }, - _ => { - let test = "test"; - if test == "test" { - return Ok(bar()); - } - Ok(53i32) - }, - } - }"#, + r#" +fn foo() -> i32<|> { + let my_var = 5; + match my_var { + 5 => { + if true { + 42i32 + } else { + 25i32 + } + }, + _ => { + let test = "test"; + if test == "test" { + return bar(); + } + 53i32 + }, + } +} +"#, + r#" +fn foo() -> Result { + let my_var = 5; + match my_var { + 5 => { + if true { + Ok(42i32) + } else { + Ok(25i32) + } + }, + _ => { + let test = "test"; + if test == "test" { + return Ok(bar()); + } + Ok(53i32) + }, + } +} +"#, ); } @@ -754,20 +807,24 @@ mod tests { fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i<|>32 { - let test = "test"; - if test == "test" { - return 24i32; - } - 53i32 - }"#, - r#"fn foo() -> Result { - let test = "test"; - if test == "test" { - return Ok(24i32); - } - Ok(53i32) - }"#, + r#" +fn foo() -> i<|>32 { + let test = "test"; + if test == "test" { + return 24i32; + } + 53i32 +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + if test == "test" { + return Ok(24i32); + } + Ok(53i32) +} +"#, ); } @@ -775,45 +832,40 @@ mod tests { fn wrap_return_type_in_result_simple_with_closure() { check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -><|> u32 { - let true_closure = || { - return true; - }; - if the_field < 5 { - let mut i = 0; - - - if true_closure() { - return 99; - } else { - return 0; - } - } - - the_field - }"#, - r#"fn foo(the_field: u32) -> Result { - let true_closure = || { - return true; - }; - if the_field < 5 { - let mut i = 0; - - - if true_closure() { - return Ok(99); - } else { - return Ok(0); - } - } - - Ok(the_field) - }"#, + r#" +fn foo(the_field: u32) -><|> u32 { + let true_closure = || { return true; }; + if the_field < 5 { + let mut i = 0; + if true_closure() { + return 99; + } else { + return 0; + } + } + the_field +} +"#, + r#" +fn foo(the_field: u32) -> Result { + let true_closure = || { return true; }; + if the_field < 5 { + let mut i = 0; + if true_closure() { + return Ok(99); + } else { + return Ok(0); + } + } + Ok(the_field) +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -> u32<|> { + r#" + fn foo(the_field: u32) -> u32<|> { let true_closure = || { return true; }; @@ -830,8 +882,10 @@ mod tests { let t = None; t.unwrap_or_else(|| the_field) - }"#, - r#"fn foo(the_field: u32) -> Result { + } + "#, + r#" + fn foo(the_field: u32) -> Result { let true_closure = || { return true; }; @@ -848,7 +902,8 @@ mod tests { let t = None; Ok(t.unwrap_or_else(|| the_field)) - }"#, + } + "#, ); } @@ -856,236 +911,248 @@ mod tests { fn wrap_return_type_in_result_simple_with_weird_forms() { check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let test = "test"; - if test == "test" { - return 24i32; - } - let mut i = 0; - loop { - if i == 1 { - break 55; - } - i += 1; - } - }"#, - r#"fn foo() -> Result { - let test = "test"; - if test == "test" { - return Ok(24i32); - } - let mut i = 0; - loop { - if i == 1 { - break Ok(55); - } - i += 1; - } - }"#, + r#" +fn foo() -> i32<|> { + let test = "test"; + if test == "test" { + return 24i32; + } + let mut i = 0; + loop { + if i == 1 { + break 55; + } + i += 1; + } +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + if test == "test" { + return Ok(24i32); + } + let mut i = 0; + loop { + if i == 1 { + break Ok(55); + } + i += 1; + } +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo() -> i32<|> { - let test = "test"; - if test == "test" { - return 24i32; - } - let mut i = 0; - loop { - loop { - if i == 1 { - break 55; - } - i += 1; - } - } - }"#, - r#"fn foo() -> Result { - let test = "test"; - if test == "test" { - return Ok(24i32); - } - let mut i = 0; - loop { - loop { - if i == 1 { - break Ok(55); - } - i += 1; - } - } - }"#, + r#" +fn foo() -> i32<|> { + let test = "test"; + if test == "test" { + return 24i32; + } + let mut i = 0; + loop { + loop { + if i == 1 { + break 55; + } + i += 1; + } + } +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + if test == "test" { + return Ok(24i32); + } + let mut i = 0; + loop { + loop { + if i == 1 { + break Ok(55); + } + i += 1; + } + } +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo() -> i3<|>2 { - let test = "test"; - let other = 5; - if test == "test" { - let res = match other { - 5 => 43, - _ => return 56, - }; - } - let mut i = 0; - loop { - loop { - if i == 1 { - break 55; - } - i += 1; - } - } - }"#, - r#"fn foo() -> Result { - let test = "test"; - let other = 5; - if test == "test" { - let res = match other { - 5 => 43, - _ => return Ok(56), - }; - } - let mut i = 0; - loop { - loop { - if i == 1 { - break Ok(55); - } - i += 1; - } - } - }"#, + r#" +fn foo() -> i3<|>2 { + let test = "test"; + let other = 5; + if test == "test" { + let res = match other { + 5 => 43, + _ => return 56, + }; + } + let mut i = 0; + loop { + loop { + if i == 1 { + break 55; + } + i += 1; + } + } +} +"#, + r#" +fn foo() -> Result { + let test = "test"; + let other = 5; + if test == "test" { + let res = match other { + 5 => 43, + _ => return Ok(56), + }; + } + let mut i = 0; + loop { + loop { + if i == 1 { + break Ok(55); + } + i += 1; + } + } +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -> u32<|> { - if the_field < 5 { - let mut i = 0; - loop { - if i > 5 { - return 55u32; - } - i += 3; - } - - match i { - 5 => return 99, - _ => return 0, - }; - } - - the_field - }"#, - r#"fn foo(the_field: u32) -> Result { - if the_field < 5 { - let mut i = 0; - loop { - if i > 5 { - return Ok(55u32); - } - i += 3; - } - - match i { - 5 => return Ok(99), - _ => return Ok(0), - }; - } - - Ok(the_field) - }"#, + r#" +fn foo(the_field: u32) -> u32<|> { + if the_field < 5 { + let mut i = 0; + loop { + if i > 5 { + return 55u32; + } + i += 3; + } + match i { + 5 => return 99, + _ => return 0, + }; + } + the_field +} +"#, + r#" +fn foo(the_field: u32) -> Result { + if the_field < 5 { + let mut i = 0; + loop { + if i > 5 { + return Ok(55u32); + } + i += 3; + } + match i { + 5 => return Ok(99), + _ => return Ok(0), + }; + } + Ok(the_field) +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -> u3<|>2 { - if the_field < 5 { - let mut i = 0; - - match i { - 5 => return 99, - _ => return 0, - } - } - - the_field - }"#, - r#"fn foo(the_field: u32) -> Result { - if the_field < 5 { - let mut i = 0; - - match i { - 5 => return Ok(99), - _ => return Ok(0), - } - } - - Ok(the_field) - }"#, + r#" +fn foo(the_field: u32) -> u3<|>2 { + if the_field < 5 { + let mut i = 0; + match i { + 5 => return 99, + _ => return 0, + } + } + the_field +} +"#, + r#" +fn foo(the_field: u32) -> Result { + if the_field < 5 { + let mut i = 0; + match i { + 5 => return Ok(99), + _ => return Ok(0), + } + } + Ok(the_field) +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -> u32<|> { - if the_field < 5 { - let mut i = 0; - - if i == 5 { - return 99 - } else { - return 0 - } - } - - the_field - }"#, - r#"fn foo(the_field: u32) -> Result { - if the_field < 5 { - let mut i = 0; - - if i == 5 { - return Ok(99) - } else { - return Ok(0) - } - } - - Ok(the_field) - }"#, + r#" +fn foo(the_field: u32) -> u32<|> { + if the_field < 5 { + let mut i = 0; + if i == 5 { + return 99 + } else { + return 0 + } + } + the_field +} +"#, + r#" +fn foo(the_field: u32) -> Result { + if the_field < 5 { + let mut i = 0; + if i == 5 { + return Ok(99) + } else { + return Ok(0) + } + } + Ok(the_field) +} +"#, ); check_assist( wrap_return_type_in_result, - r#"fn foo(the_field: u32) -> <|>u32 { - if the_field < 5 { - let mut i = 0; - - if i == 5 { - return 99; - } else { - return 0; - } - } - - the_field - }"#, - r#"fn foo(the_field: u32) -> Result { - if the_field < 5 { - let mut i = 0; - - if i == 5 { - return Ok(99); - } else { - return Ok(0); - } - } - - Ok(the_field) - }"#, + r#" +fn foo(the_field: u32) -> <|>u32 { + if the_field < 5 { + let mut i = 0; + if i == 5 { + return 99; + } else { + return 0; + } + } + the_field +} +"#, + r#" +fn foo(the_field: u32) -> Result { + if the_field < 5 { + let mut i = 0; + if i == 5 { + return Ok(99); + } else { + return Ok(0); + } + } + Ok(the_field) +} +"#, ); } }