Repository: rust-lang/rust-analyzer
Pull request #18361 (2024-10-21 14:59:20)

fix: Fix token downmapping failing for include! inputs
Supercedes https://github.com/rust-lang/rust-analyzer/pull/18325

Fixes https://github.com/rust-lang/rust-analyzer/pull/18325
Fixes https://github.com/rust-lang/rust-analyzer/issues/18313
Fixes https://github.com/rust-lang/rust-analyzer/issues/18314


Patch:
diff --git a/crates/hir-def/src/visibility.rs b/crates/hir-def/src/visibility.rs
index 3aeb88047a..11d91513f1 100644
--- a/crates/hir-def/src/visibility.rs
+++ b/crates/hir-def/src/visibility.rs
@@ -139,11 +139,13 @@ impl Visibility {
         let def_map_block = def_map.block_id();
         loop {
             match (to_module.block, def_map_block) {
-                // `to_module` is not a block, so there is no parent def map to use.
+                // to_module is not a block, so there is no parent def map to use
                 (None, _) => (),
-                // `to_module` is at `def_map`'s block, no need to move further.
                 (Some(a), Some(b)) if a == b => {
                     cov_mark::hit!(is_visible_from_same_block_def_map);
+                    if let Some(parent) = def_map.parent() {
+                        to_module = parent;
+                    }
                 }
                 _ => {
                     if let Some(parent) = to_module.def_map(db).parent() {
diff --git a/crates/hir-expand/src/builtin/fn_macro.rs b/crates/hir-expand/src/builtin/fn_macro.rs
index d04225b872..4894c7a931 100644
--- a/crates/hir-expand/src/builtin/fn_macro.rs
+++ b/crates/hir-expand/src/builtin/fn_macro.rs
@@ -5,19 +5,20 @@ use cfg::CfgExpr;
 use either::Either;
 use intern::{sym, Symbol};
 use mbe::{expect_fragment, DelimiterKind};
-use span::{Edition, EditionedFileId, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
+use span::{Edition, EditionedFileId, Span};
 use stdx::format_to;
 use syntax::{
     format_smolstr,
     unescape::{unescape_byte, unescape_char, unescape_unicode, Mode},
 };
-use syntax_bridge::parse_to_token_tree;
+use syntax_bridge::syntax_node_to_token_tree;
 
 use crate::{
     builtin::quote::{dollar_crate, quote},
     db::ExpandDatabase,
     hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt},
     name,
+    span_map::SpanMap,
     tt::{self, DelimSpan},
     ExpandError, ExpandResult, HirFileIdExt, Lookup as _, MacroCallId,
 };
@@ -739,18 +740,14 @@ fn include_expand(
             return ExpandResult::new(tt::Subtree::empty(DelimSpan { open: span, close: span }), e)
         }
     };
-    match parse_to_token_tree(
-        file_id.edition(),
-        SpanAnchor { file_id, ast_id: ROOT_ERASED_FILE_AST_ID },
-        SyntaxContextId::ROOT,
-        &db.file_text(file_id.file_id()),
-    ) {
-        Some(it) => ExpandResult::ok(it),
-        None => ExpandResult::new(
-            tt::Subtree::empty(DelimSpan { open: span, close: span }),
-            ExpandError::other(span, "failed to parse included file"),
-        ),
-    }
+    let span_map = db.real_span_map(file_id);
+    // FIXME: Parse errors
+    ExpandResult::ok(syntax_node_to_token_tree(
+        &db.parse(file_id).syntax_node(),
+        SpanMap::RealSpanMap(span_map),
+        span,
+        syntax_bridge::DocCommentDesugarMode::ProcMacro,
+    ))
 }
 
 pub fn include_input_to_file_id(
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index b27f1fbb5d..3eac33ce99 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -892,29 +892,8 @@ impl<'db> SemanticsImpl<'db> {
         f: &mut dyn FnMut(InFile<SyntaxToken>, SyntaxContextId) -> ControlFlow<T>,
     ) -> Option<T> {
         let _p = tracing::info_span!("descend_into_macros_impl").entered();
-        let (sa, span, file_id) = token
-            .parent()
-            .and_then(|parent| {
-                self.analyze_impl(InRealFile::new(file_id, &parent).into(), None, false)
-            })
-            .and_then(|sa| {
-                let file_id = sa.file_id.file_id()?;
-                Some((
-                    sa,
-                    self.db.real_span_map(file_id).span_for_range(token.text_range()),
-                    HirFileId::from(file_id),
-                ))
-            })?;
 
-        let mut m_cache = self.macro_call_cache.borrow_mut();
-        let def_map = sa.resolver.def_map();
-
-        // A stack of tokens to process, along with the file they came from
-        // These are tracked to know which macro calls we still have to look into
-        // the tokens themselves aren't that interesting as the span that is being used to map
-        // things down never changes.
-        let mut stack: Vec<(_, SmallVec<[_; 2]>)> =
-            vec![(file_id, smallvec![(token, SyntaxContextId::ROOT)])];
+        let span = self.db.real_span_map(file_id).span_for_range(token.text_range());
 
         // Process the expansion of a call, pushing all tokens with our span in the expansion back onto our stack
         let process_expansion_for_token = |stack: &mut Vec<_>, macro_file| {
@@ -926,7 +905,6 @@ impl<'db> SemanticsImpl<'db> {
                         .map(SmallVec::<[_; 2]>::from_iter),
                 )
             })?;
-
             // we have found a mapping for the token if the vec is non-empty
             let res = mapped_tokens.is_empty().not().then_some(());
             // requeue the tokens we got from mapping our current token down
@@ -934,6 +912,33 @@ impl<'db> SemanticsImpl<'db> {
             res
         };
 
+        // A stack of tokens to process, along with the file they came from
+        // These are tracked to know which macro calls we still have to look into
+        // the tokens themselves aren't that interesting as the span that is being used to map
+        // things down never changes.
+        let mut stack: Vec<(_, SmallVec<[_; 2]>)> = vec![];
+        let include = self.s2d_cache.borrow_mut().get_or_insert_include_for(self.db, file_id);
+        match include {
+            Some(include) => {
+                // include! inputs are always from real files, so they only need to be handled once upfront
+                process_expansion_for_token(&mut stack, include)?;
+            }
+            None => {
+                stack.push((file_id.into(), smallvec![(token, SyntaxContextId::ROOT)]));
+            }
+        }
+
+        let (file_id, tokens) = stack.first()?;
+        // make sure we pick the token in the expanded include if we encountered an include,
+        // otherwise we'll get the wrong semantics
+        let sa =
+            tokens.first()?.0.parent().and_then(|parent| {
+                self.analyze_impl(InFile::new(*file_id, &parent), None, false)
+            })?;
+
+        let mut m_cache = self.macro_call_cache.borrow_mut();
+        let def_map = sa.resolver.def_map();
+
         // Filters out all tokens that contain the given range (usually the macro call), any such
         // token is redundant as the corresponding macro call has already been processed
         let filter_duplicates = |tokens: &mut SmallVec<_>, range: TextRange| {
@@ -1011,6 +1016,7 @@ impl<'db> SemanticsImpl<'db> {
                                         ) {
                                         call.as_macro_file()
                                     } else {
+                                        // FIXME: This is wrong, the SourceAnalyzer might be invalid here
                                         sa.expand(self.db, mcall.as_ref())?
                                     };
                                     m_cache.insert(mcall, it);
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs
index fd6d52d6c9..389778b44e 100644
--- a/crates/hir/src/semantics/source_to_def.rs
+++ b/crates/hir/src/semantics/source_to_def.rs
@@ -104,7 +104,7 @@ use hir_expand::{
 };
 use rustc_hash::FxHashMap;
 use smallvec::SmallVec;
-use span::{FileId, MacroFileId};
+use span::{EditionedFileId, FileId, MacroFileId};
 use stdx::impl_from;
 use syntax::{
     ast::{self, HasName},
@@ -118,9 +118,27 @@ pub(super) struct SourceToDefCache {
     pub(super) dynmap_cache: FxHashMap<(ChildContainer, HirFileId), DynMap>,
     expansion_info_cache: FxHashMap<MacroFileId, ExpansionInfo>,
     pub(super) file_to_def_cache: FxHashMap<FileId, SmallVec<[ModuleId; 1]>>,
+    pub(super) included_file_cache: FxHashMap<EditionedFileId, Option<MacroFileId>>,
 }
 
 impl SourceToDefCache {
+    pub(super) fn get_or_insert_include_for(
+        &mut self,
+        db: &dyn HirDatabase,
+        file: EditionedFileId,
+    ) -> Option<MacroFileId> {
+        if let Some(&m) = self.included_file_cache.get(&file) {
+            return m;
+        }
+        self.included_file_cache.insert(file, None);
+        for &crate_id in db.relevant_crates(file.into()).iter() {
+            db.include_macro_invoc(crate_id).iter().for_each(|&(macro_call_id, file_id)| {
+                self.included_file_cache.insert(file_id, Some(MacroFileId { macro_call_id }));
+            });
+        }
+        self.included_file_cache.get(&file).copied().flatten()
+    }
+
     pub(super) fn get_or_insert_expansion(
         &mut self,
         sema: &SemanticsImpl<'_>,
@@ -163,9 +181,13 @@ impl SourceToDefCtx<'_, '_> {
                             .include_macro_invoc(crate_id)
                             .iter()
                             .filter(|&&(_, file_id)| file_id == file)
-                            .flat_map(|(call, _)| {
+                            .flat_map(|&(macro_call_id, file_id)| {
+                                self.cache
+                                    .included_file_cache
+                                    .insert(file_id, Some(MacroFileId { macro_call_id }));
                                 modules(
-                                    call.lookup(self.db.upcast())
+                                    macro_call_id
+                                        .lookup(self.db.upcast())
                                         .kind
                                         .file_id()
                                         .original_file(self.db.upcast())
diff --git a/crates/ide-assists/src/handlers/unwrap_result_return_type.rs b/crates/ide-assists/src/handlers/unwrap_result_return_type.rs
new file mode 100644
index 0000000000..a1987247cb
--- /dev/null
+++ b/crates/ide-assists/src/handlers/unwrap_result_return_type.rs
@@ -0,0 +1,1115 @@
+use ide_db::{
+    famous_defs::FamousDefs,
+    syntax_helpers::node_ext::{for_each_tail_expr, walk_expr},
+};
+use itertools::Itertools;
+use syntax::{
+    ast::{self, Expr, HasGenericArgs},
+    match_ast, AstNode, NodeOrToken, SyntaxKind, TextRange,
+};
+
+use crate::{AssistContext, AssistId, AssistKind, Assists};
+
+// Assist: unwrap_result_return_type
+//
+// Unwrap the function's return type.
+//
+// ```
+// # //- minicore: result
+// fn foo() -> Result<i32>$0 { Ok(42i32) }
+// ```
+// ->
+// ```
+// fn foo() -> i32 { 42i32 }
+// ```
+pub(crate) fn unwrap_result_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
+    let ret_type = ctx.find_node_at_offset::<ast::RetType>()?;
+    let parent = ret_type.syntax().parent()?;
+    let body = match_ast! {
+        match parent {
+            ast::Fn(func) => func.body()?,
+            ast::ClosureExpr(closure) => match closure.body()? {
+                Expr::BlockExpr(block) => block,
+                // closures require a block when a return type is specified
+                _ => return None,
+            },
+            _ => return None,
+        }
+    };
+
+    let type_ref = &ret_type.ty()?;
+    let Some(hir::Adt::Enum(ret_enum)) = ctx.sema.resolve_type(type_ref)?.as_adt() else {
+        return None;
+    };
+    let result_enum =
+        FamousDefs(&ctx.sema, ctx.sema.scope(type_ref.syntax())?.krate()).core_result_Result()?;
+    if ret_enum != result_enum {
+        return None;
+    }
+
+    let ok_type = unwrap_result_type(type_ref)?;
+
+    acc.add(
+        AssistId("unwrap_result_return_type", AssistKind::RefactorRewrite),
+        "Unwrap Result return type",
+        type_ref.syntax().text_range(),
+        |builder| {
+            let body = ast::Expr::BlockExpr(body);
+
+            let mut exprs_to_unwrap = Vec::new();
+            let tail_cb = &mut |e: &_| tail_cb_impl(&mut exprs_to_unwrap, e);
+            walk_expr(&body, &mut |expr| {
+                if let Expr::ReturnExpr(ret_expr) = expr {
+                    if let Some(ret_expr_arg) = &ret_expr.expr() {
+                        for_each_tail_expr(ret_expr_arg, tail_cb);
+                    }
+                }
+            });
+            for_each_tail_expr(&body, tail_cb);
+
+            let is_unit_type = is_unit_type(&ok_type);
+            if is_unit_type {
+                let mut text_range = ret_type.syntax().text_range();
+
+                if let Some(NodeOrToken::Token(token)) = ret_type.syntax().next_sibling_or_token() {
+                    if token.kind() == SyntaxKind::WHITESPACE {
+                        text_range = TextRange::new(text_range.start(), token.text_range().end());
+                    }
+                }
+
+                builder.delete(text_range);
+            } else {
+                builder.replace(type_ref.syntax().text_range(), ok_type.syntax().text());
+            }
+
+            for ret_expr_arg in exprs_to_unwrap {
+                let ret_expr_str = ret_expr_arg.to_string();
+                if ret_expr_str.starts_with("Ok(") || ret_expr_str.starts_with("Err(") {
+                    let arg_list = ret_expr_arg.syntax().children().find_map(ast::ArgList::cast);
+                    if let Some(arg_list) = arg_list {
+                        if is_unit_type {
+                            match ret_expr_arg.syntax().prev_sibling_or_token() {
+                                // Useful to delete the entire line without leaving trailing whitespaces
+                                Some(whitespace) => {
+                                    let new_range = TextRange::new(
+                                        whitespace.text_range().start(),
+                                        ret_expr_arg.syntax().text_range().end(),
+                                    );
+                                    builder.delete(new_range);
+                                }
+                                None => {
+                                    builder.delete(ret_expr_arg.syntax().text_range());
+                                }
+                            }
+                        } else {
+                            builder.replace(
+                                ret_expr_arg.syntax().text_range(),
+                                arg_list.args().join(", "),
+                            );
+                        }
+                    }
+                }
+            }
+        },
+    )
+}
+
+fn tail_cb_impl(acc: &mut Vec<ast::Expr>, e: &ast::Expr) {
+    match e {
+        Expr::BreakExpr(break_expr) => {
+            if let Some(break_expr_arg) = break_expr.expr() {
+                for_each_tail_expr(&break_expr_arg, &mut |e| tail_cb_impl(acc, e))
+            }
+        }
+        Expr::ReturnExpr(_) => {
+            // all return expressions have already been handled by the walk loop
+        }
+        e => acc.push(e.clone()),
+    }
+}
+
+// Tries to extract `T` from `Result<T, E>`.
+fn unwrap_result_type(ty: &ast::Type) -> Option<ast::Type> {
+    let ast::Type::PathType(path_ty) = ty else {
+        return None;
+    };
+    let path = path_ty.path()?;
+    let segment = path.first_segment()?;
+    let generic_arg_list = segment.generic_arg_list()?;
+    let generic_args: Vec<_> = generic_arg_list.generic_args().collect();
+    let ast::GenericArg::TypeArg(ok_type) = generic_args.first()? else {
+        return None;
+    };
+    ok_type.ty()
+}
+
+fn is_unit_type(ty: &ast::Type) -> bool {
+    let ast::Type::TupleType(tuple) = ty else { return false };
+    tuple.fields().next().is_none()
+}
+
+#[cfg(test)]
+mod tests {
+    use crate::tests::{check_assist, check_assist_not_applicable};
+
+    use super::*;
+
+    #[test]
+    fn unwrap_result_return_type_simple() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i3$02> {
+    let test = "test";
+    return Ok(42i32);
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    let test = "test";
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_unit_type() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<(), Box<dyn Error$0>> {
+    Ok(())
+}
+"#,
+            r#"
+fn foo() {
+}
+"#,
+        );
+
+        // Unformatted return type
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<(), Box<dyn Error$0>>{
+    Ok(())
+}
+"#,
+            r#"
+fn foo() {
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_ending_with_parent() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32, Box<dyn Error$0>> {
+    if true {
+        Ok(42)
+    } else {
+        foo()
+    }
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    if true {
+        42
+    } else {
+        foo()
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_return_type_break_split_tail() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i3$02, String> {
+    loop {
+        break if true {
+            Ok(1)
+        } else {
+            Ok(0)
+        };
+    }
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    loop {
+        break if true {
+            1
+        } else {
+            0
+        };
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_closure() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> Result<i32$0> {
+        let test = "test";
+        return Ok(42i32);
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> i32 {
+        let test = "test";
+        return 42i32;
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_return_type_bad_cursor() {
+        check_assist_not_applicable(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> i32 {
+    let test = "test";$0
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_return_type_bad_cursor_closure() {
+        check_assist_not_applicable(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> i32 {
+        let test = "test";$0
+        return 42i32;
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_closure_non_block() {
+        check_assist_not_applicable(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() { || -> i$032 3; }
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_return_type_already_not_result_std() {
+        check_assist_not_applicable(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let test = "test";
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_return_type_already_not_result_closure() {
+        check_assist_not_applicable(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> i32$0 {
+        let test = "test";
+        return 42i32;
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() ->$0 Result<i32> {
+    let test = "test";
+    Ok(42i32)
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    let test = "test";
+    42i32
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_closure() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() {
+    || ->$0 Result<i32, String> {
+        let test = "test";
+        Ok(42i32)
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> i32 {
+        let test = "test";
+        42i32
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_only() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> { Ok(42i32) }
+"#,
+            r#"
+fn foo() -> i32 { 42i32 }
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_block_like() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32>$0 {
+    if true {
+        Ok(42i32)
+    } else {
+        Ok(24i32)
+    }
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    if true {
+        42i32
+    } else {
+        24i32
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_without_block_closure() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> Result<i32, String>$0 {
+        if true {
+            Ok(42i32)
+        } else {
+            Ok(24i32)
+        }
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> i32 {
+        if true {
+            42i32
+        } else {
+            24i32
+        }
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_nested_if() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32>$0 {
+    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
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_await() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+async fn foo() -> Result<i$032> {
+    if true {
+        if false {
+            Ok(1.await)
+        } else {
+            Ok(2.await)
+        }
+    } else {
+        Ok(24i32.await)
+    }
+}
+"#,
+            r#"
+async fn foo() -> i32 {
+    if true {
+        if false {
+            1.await
+        } else {
+            2.await
+        }
+    } else {
+        24i32.await
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_array() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<[i32; 3]$0> { Ok([1, 2, 3]) }
+"#,
+            r#"
+fn foo() -> [i32; 3] { [1, 2, 3] }
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_cast() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -$0> Result<i32> {
+    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
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_block_like_match() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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,
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_loop_with_tail() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_loop_in_let_stmt() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_block_like_match_return_expr() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32>$0 {
+    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
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_block_like_match_deeper() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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
+        },
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_tail_block_like_early_return() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    let test = "test";
+    if test == "test" {
+        return Ok(24i32);
+    }
+    Ok(53i32)
+}
+"#,
+            r#"
+fn foo() -> i32 {
+    let test = "test";
+    if test == "test" {
+        return 24i32;
+    }
+    53i32
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_in_tail_position() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(num: i32) -> $0Result<i32, String> {
+    return Ok(num)
+}
+"#,
+            r#"
+fn foo(num: i32) -> i32 {
+    return num
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_closure() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u32$0> {
+    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
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u32$0> {
+    let true_closure = || {
+        return true;
+    };
+    if the_field < 5 {
+        let mut i = 0;
+
+
+        if true_closure() {
+            return Ok(99);
+        } else {
+            return Ok(0);
+        }
+    }
+    let t = None;
+
+    Ok(t.unwrap_or_else(|| 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;
+        }
+    }
+    let t = None;
+
+    t.unwrap_or_else(|| the_field)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_simple_with_weird_forms() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0> {
+    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;
+    }
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u32$0> {
+    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
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u32$0> {
+    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) -> u32 {
+    if the_field < 5 {
+        let mut i = 0;
+        match i {
+            5 => return 99,
+            _ => return 0,
+        }
+    }
+    the_field
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u32$0> {
+    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
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) -> Result<u3$02> {
+    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
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn unwrap_result_return_type_nested_type() {
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result, option
+fn foo() -> Result<Option<i32$0>, ()> {
+    Ok(Some(42))
+}
+"#,
+            r#"
+fn foo() -> Option<i32> {
+    Some(42)
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result, option
+fn foo() -> Result<Option<Result<i32$0, ()>>, ()> {
+    Ok(None)
+}
+"#,
+            r#"
+fn foo() -> Option<Result<i32, ()>> {
+    None
+}
+"#,
+        );
+
+        check_assist(
+            unwrap_result_return_type,
+            r#"
+//- minicore: result, option, iterators
+fn foo() -> Result<impl Iterator<Item = i32>$0, ()> {
+    Ok(Some(42).into_iter())
+}
+"#,
+            r#"
+fn foo() -> impl Iterator<Item = i32> {
+    Some(42).into_iter()
+}
+"#,
+        );
+    }
+}
diff --git a/crates/ide-assists/src/handlers/unwrap_return_type.rs b/crates/ide-assists/src/handlers/unwrap_return_type.rs
deleted file mode 100644
index 64d5e2c9b8..0000000000
--- a/crates/ide-assists/src/handlers/unwrap_return_type.rs
+++ /dev/null
@@ -1,2229 +0,0 @@
-use ide_db::{
-    famous_defs::FamousDefs,
-    syntax_helpers::node_ext::{for_each_tail_expr, walk_expr},
-};
-use itertools::Itertools;
-use syntax::{
-    ast::{self, Expr, HasGenericArgs},
-    match_ast, AstNode, NodeOrToken, SyntaxKind, TextRange,
-};
-
-use crate::{AssistContext, AssistId, AssistKind, Assists};
-
-// Assist: unwrap_option_return_type
-//
-// Unwrap the function's return type.
-//
-// ```
-// # //- minicore: option
-// fn foo() -> Option<i32>$0 { Some(42i32) }
-// ```
-// ->
-// ```
-// fn foo() -> i32 { 42i32 }
-// ```
-
-// Assist: unwrap_result_return_type
-//
-// Unwrap the function's return type.
-//
-// ```
-// # //- minicore: result
-// fn foo() -> Result<i32>$0 { Ok(42i32) }
-// ```
-// ->
-// ```
-// fn foo() -> i32 { 42i32 }
-// ```
-
-pub(crate) fn unwrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
-    let ret_type = ctx.find_node_at_offset::<ast::RetType>()?;
-    let parent = ret_type.syntax().parent()?;
-    let body = match_ast! {
-        match parent {
-            ast::Fn(func) => func.body()?,
-            ast::ClosureExpr(closure) => match closure.body()? {
-                Expr::BlockExpr(block) => block,
-                // closures require a block when a return type is specified
-                _ => return None,
-            },
-            _ => return None,
-        }
-    };
-
-    let type_ref = &ret_type.ty()?;
-    let Some(hir::Adt::Enum(ret_enum)) = ctx.sema.resolve_type(type_ref)?.as_adt() else {
-        return None;
-    };
-
-    let famous_defs = FamousDefs(&ctx.sema, ctx.sema.scope(type_ref.syntax())?.krate());
-
-    let kind = UnwrapperKind::ALL
-        .iter()
-        .find(|k| matches!(k.core_type(&famous_defs), Some(core_type) if ret_enum == core_type))?;
-
-    let happy_type = extract_wrapped_type(type_ref)?;
-
-    acc.add(kind.assist_id(), kind.label(), type_ref.syntax().text_range(), |builder| {
-        let body = ast::Expr::BlockExpr(body);
-
-        let mut exprs_to_unwrap = Vec::new();
-        let tail_cb = &mut |e: &_| tail_cb_impl(&mut exprs_to_unwrap, e);
-        walk_expr(&body, &mut |expr| {
-            if let Expr::ReturnExpr(ret_expr) = expr {
-                if let Some(ret_expr_arg) = &ret_expr.expr() {
-                    for_each_tail_expr(ret_expr_arg, tail_cb);
-                }
-            }
-        });
-        for_each_tail_expr(&body, tail_cb);
-
-        let is_unit_type = is_unit_type(&happy_type);
-        if is_unit_type {
-            let mut text_range = ret_type.syntax().text_range();
-
-            if let Some(NodeOrToken::Token(token)) = ret_type.syntax().next_sibling_or_token() {
-                if token.kind() == SyntaxKind::WHITESPACE {
-                    text_range = TextRange::new(text_range.start(), token.text_range().end());
-                }
-            }
-
-            builder.delete(text_range);
-        } else {
-            builder.replace(type_ref.syntax().text_range(), happy_type.syntax().text());
-        }
-
-        for ret_expr_arg in exprs_to_unwrap {
-            let ret_expr_str = ret_expr_arg.to_string();
-
-            let needs_replacing = match kind {
-                UnwrapperKind::Option => ret_expr_str.starts_with("Some("),
-                UnwrapperKind::Result => {
-                    ret_expr_str.starts_with("Ok(") || ret_expr_str.starts_with("Err(")
-                }
-            };
-
-            if needs_replacing {
-                let arg_list = ret_expr_arg.syntax().children().find_map(ast::ArgList::cast);
-                if let Some(arg_list) = arg_list {
-                    if is_unit_type {
-                        match ret_expr_arg.syntax().prev_sibling_or_token() {
-                            // Useful to delete the entire line without leaving trailing whitespaces
-                            Some(whitespace) => {
-                                let new_range = TextRange::new(
-                                    whitespace.text_range().start(),
-                                    ret_expr_arg.syntax().text_range().end(),
-                                );
-                                builder.delete(new_range);
-                            }
-                            None => {
-                                builder.delete(ret_expr_arg.syntax().text_range());
-                            }
-                        }
-                    } else {
-                        builder.replace(
-                            ret_expr_arg.syntax().text_range(),
-                            arg_list.args().join(", "),
-                        );
-                    }
-                }
-            } else if matches!(kind, UnwrapperKind::Option if ret_expr_str == "None") {
-                builder.replace(ret_expr_arg.syntax().text_range(), "()");
-            }
-        }
-    })
-}
-
-enum UnwrapperKind {
-    Option,
-    Result,
-}
-
-impl UnwrapperKind {
-    const ALL: &'static [UnwrapperKind] = &[UnwrapperKind::Option, UnwrapperKind::Result];
-
-    fn assist_id(&self) -> AssistId {
-        let s = match self {
-            UnwrapperKind::Option => "unwrap_option_return_type",
-            UnwrapperKind::Result => "unwrap_result_return_type",
-        };
-
-        AssistId(s, AssistKind::RefactorRewrite)
-    }
-
-    fn label(&self) -> &'static str {
-        match self {
-            UnwrapperKind::Option => "Unwrap Option return type",
-            UnwrapperKind::Result => "Unwrap Result return type",
-        }
-    }
-
-    fn core_type(&self, famous_defs: &FamousDefs<'_, '_>) -> Option<hir::Enum> {
-        match self {
-            UnwrapperKind::Option => famous_defs.core_option_Option(),
-            UnwrapperKind::Result => famous_defs.core_result_Result(),
-        }
-    }
-}
-
-fn tail_cb_impl(acc: &mut Vec<ast::Expr>, e: &ast::Expr) {
-    match e {
-        Expr::BreakExpr(break_expr) => {
-            if let Some(break_expr_arg) = break_expr.expr() {
-                for_each_tail_expr(&break_expr_arg, &mut |e| tail_cb_impl(acc, e))
-            }
-        }
-        Expr::ReturnExpr(_) => {
-            // all return expressions have already been handled by the walk loop
-        }
-        e => acc.push(e.clone()),
-    }
-}
-
-// Tries to extract `T` from `Option<T>` or `Result<T, E>`.
-fn extract_wrapped_type(ty: &ast::Type) -> Option<ast::Type> {
-    let ast::Type::PathType(path_ty) = ty else {
-        return None;
-    };
-    let path = path_ty.path()?;
-    let segment = path.first_segment()?;
-    let generic_arg_list = segment.generic_arg_list()?;
-    let generic_args: Vec<_> = generic_arg_list.generic_args().collect();
-    let ast::GenericArg::TypeArg(happy_type) = generic_args.first()? else {
-        return None;
-    };
-    happy_type.ty()
-}
-
-fn is_unit_type(ty: &ast::Type) -> bool {
-    let ast::Type::TupleType(tuple) = ty else { return false };
-    tuple.fields().next().is_none()
-}
-
-#[cfg(test)]
-mod tests {
-    use crate::tests::{check_assist_by_label, check_assist_not_applicable_by_label};
-
-    use super::*;
-
-    #[test]
-    fn unwrap_option_return_type_simple() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i3$02> {
-    let test = "test";
-    return Some(42i32);
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_unit_type() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<()$0> {
-    Some(())
-}
-"#,
-            r#"
-fn foo() {
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        // Unformatted return type
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<()$0>{
-    Some(())
-}
-"#,
-            r#"
-fn foo() {
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_none() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i3$02> {
-    if true {
-        Some(42)
-    } else {
-        None
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        42
-    } else {
-        ()
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_ending_with_parent() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i3$02> {
-    if true {
-        Some(42)
-    } else {
-        foo()
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        42
-    } else {
-        foo()
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_break_split_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i3$02> {
-    loop {
-        break if true {
-            Some(1)
-        } else {
-            Some(0)
-        };
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    loop {
-        break if true {
-            1
-        } else {
-            0
-        };
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> Option<i32$0> {
-        let test = "test";
-        return Some(42i32);
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_return_type_bad_cursor() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32 {
-    let test = "test";$0
-    return 42i32;
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_return_type_bad_cursor_closure() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> i32 {
-        let test = "test";$0
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_closure_non_block() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() { || -> i$032 3; }
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_return_type_already_not_option_std() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_return_type_already_not_option_closure() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> i32$0 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() ->$0 Option<i32> {
-    let test = "test";
-    Some(42i32)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    42i32
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || ->$0 Option<i32> {
-        let test = "test";
-        Some(42i32)
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        let test = "test";
-        42i32
-    };
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_only() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> { Some(42i32) }
-"#,
-            r#"
-fn foo() -> i32 { 42i32 }
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_block_like() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32>$0 {
-    if true {
-        Some(42i32)
-    } else {
-        Some(24i32)
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        42i32
-    } else {
-        24i32
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_without_block_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> Option<i32>$0 {
-        if true {
-            Some(42i32)
-        } else {
-            Some(24i32)
-        }
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        if true {
-            42i32
-        } else {
-            24i32
-        }
-    };
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_nested_if() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32>$0 {
-    if true {
-        if false {
-            Some(1)
-        } else {
-            Some(2)
-        }
-    } else {
-        Some(24i32)
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        if false {
-            1
-        } else {
-            2
-        }
-    } else {
-        24i32
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_await() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-async fn foo() -> Option<i$032> {
-    if true {
-        if false {
-            Some(1.await)
-        } else {
-            Some(2.await)
-        }
-    } else {
-        Some(24i32.await)
-    }
-}
-"#,
-            r#"
-async fn foo() -> i32 {
-    if true {
-        if false {
-            1.await
-        } else {
-            2.await
-        }
-    } else {
-        24i32.await
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_array() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<[i32; 3]$0> { Some([1, 2, 3]) }
-"#,
-            r#"
-fn foo() -> [i32; 3] { [1, 2, 3] }
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_cast() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -$0> Option<i32> {
-    if true {
-        if false {
-            Some(1 as i32)
-        } else {
-            Some(2 as i32)
-        }
-    } else {
-        Some(24 as i32)
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        if false {
-            1 as i32
-        } else {
-            2 as i32
-        }
-    } else {
-        24 as i32
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_block_like_match() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let my_var = 5;
-    match my_var {
-        5 => Some(42i32),
-        _ => Some(24i32),
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let my_var = 5;
-    match my_var {
-        5 => 42i32,
-        _ => 24i32,
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_loop_with_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    Some(my_var)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    my_var
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_loop_in_let_stmt() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let my_var = let x = loop {
-        break 1;
-    };
-    Some(my_var)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let my_var = let x = loop {
-        break 1;
-    };
-    my_var
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_block_like_match_return_expr() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32>$0 {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return Some(24i32),
-    };
-    Some(res)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return 24i32,
-    };
-    res
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return Some(24i32);
-    };
-    Some(res)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return 24i32;
-    };
-    res
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_block_like_match_deeper() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let my_var = 5;
-    match my_var {
-        5 => {
-            if true {
-                Some(42i32)
-            } else {
-                Some(25i32)
-            }
-        },
-        _ => {
-            let test = "test";
-            if test == "test" {
-                return Some(bar());
-            }
-            Some(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
-        },
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_tail_block_like_early_return() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let test = "test";
-    if test == "test" {
-        return Some(24i32);
-    }
-    Some(53i32)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    53i32
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_in_tail_position() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(num: i32) -> $0Option<i32> {
-    return Some(num)
-}
-"#,
-            r#"
-fn foo(num: i32) -> i32 {
-    return num
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u32$0> {
-    let true_closure = || { return true; };
-    if the_field < 5 {
-        let mut i = 0;
-        if true_closure() {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    Some(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
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u32$0> {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    let t = None;
-
-    Some(t.unwrap_or_else(|| 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;
-        }
-    }
-    let t = None;
-
-    t.unwrap_or_else(|| the_field)
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_simple_with_weird_forms() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let test = "test";
-    if test == "test" {
-        return Some(24i32);
-    }
-    let mut i = 0;
-    loop {
-        if i == 1 {
-            break Some(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;
-    }
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u32$0> {
-    if the_field < 5 {
-        let mut i = 0;
-        loop {
-            if i > 5 {
-                return Some(55u32);
-            }
-            i += 3;
-        }
-        match i {
-            5 => return Some(99),
-            _ => return Some(0),
-        };
-    }
-    Some(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
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u32$0> {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return Some(99),
-            _ => return Some(0),
-        }
-    }
-    Some(the_field)
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> u32 {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return 99,
-            _ => return 0,
-        }
-    }
-    the_field
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u32$0> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Some(99)
-        } else {
-            return Some(0)
-        }
-    }
-    Some(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
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> Option<u3$02> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    Some(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
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_option_return_type_nested_type() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option, result
-fn foo() -> Option<Result<i32$0, ()>> {
-    Some(Ok(42))
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ()> {
-    Ok(42)
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option, result
-fn foo() -> Option<Result<Option<i32$0>, ()>> {
-    Some(Err())
-}
-"#,
-            r#"
-fn foo() -> Result<Option<i32>, ()> {
-    Err()
-}
-"#,
-            "Unwrap Option return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: option, result, iterators
-fn foo() -> Option<impl Iterator<Item = i32>$0> {
-    Some(Some(42).into_iter())
-}
-"#,
-            r#"
-fn foo() -> impl Iterator<Item = i32> {
-    Some(42).into_iter()
-}
-"#,
-            "Unwrap Option return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i3$02> {
-    let test = "test";
-    return Ok(42i32);
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_unit_type() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<(), Box<dyn Error$0>> {
-    Ok(())
-}
-"#,
-            r#"
-fn foo() {
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        // Unformatted return type
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<(), Box<dyn Error$0>>{
-    Ok(())
-}
-"#,
-            r#"
-fn foo() {
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_ending_with_parent() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32, Box<dyn Error$0>> {
-    if true {
-        Ok(42)
-    } else {
-        foo()
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        42
-    } else {
-        foo()
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_break_split_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i3$02, String> {
-    loop {
-        break if true {
-            Ok(1)
-        } else {
-            Ok(0)
-        };
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    loop {
-        break if true {
-            1
-        } else {
-            0
-        };
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> Result<i32$0> {
-        let test = "test";
-        return Ok(42i32);
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_return_type_bad_cursor() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32 {
-    let test = "test";$0
-    return 42i32;
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_return_type_bad_cursor_closure() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> i32 {
-        let test = "test";$0
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_closure_non_block() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() { || -> i$032 3; }
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_return_type_already_not_result_std() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_return_type_already_not_result_closure() {
-        check_assist_not_applicable_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> i32$0 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() ->$0 Result<i32> {
-    let test = "test";
-    Ok(42i32)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    42i32
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || ->$0 Result<i32, String> {
-        let test = "test";
-        Ok(42i32)
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        let test = "test";
-        42i32
-    };
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_only() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> { Ok(42i32) }
-"#,
-            r#"
-fn foo() -> i32 { 42i32 }
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_block_like() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32>$0 {
-    if true {
-        Ok(42i32)
-    } else {
-        Ok(24i32)
-    }
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    if true {
-        42i32
-    } else {
-        24i32
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_without_block_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> Result<i32, String>$0 {
-        if true {
-            Ok(42i32)
-        } else {
-            Ok(24i32)
-        }
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> i32 {
-        if true {
-            42i32
-        } else {
-            24i32
-        }
-    };
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_nested_if() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32>$0 {
-    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
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_await() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-async fn foo() -> Result<i$032> {
-    if true {
-        if false {
-            Ok(1.await)
-        } else {
-            Ok(2.await)
-        }
-    } else {
-        Ok(24i32.await)
-    }
-}
-"#,
-            r#"
-async fn foo() -> i32 {
-    if true {
-        if false {
-            1.await
-        } else {
-            2.await
-        }
-    } else {
-        24i32.await
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_array() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<[i32; 3]$0> { Ok([1, 2, 3]) }
-"#,
-            r#"
-fn foo() -> [i32; 3] { [1, 2, 3] }
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_cast() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -$0> Result<i32> {
-    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
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_block_like_match() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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,
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_loop_with_tail() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_loop_in_let_stmt() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_block_like_match_return_expr() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32>$0 {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_block_like_match_deeper() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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
-        },
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_tail_block_like_early_return() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    let test = "test";
-    if test == "test" {
-        return Ok(24i32);
-    }
-    Ok(53i32)
-}
-"#,
-            r#"
-fn foo() -> i32 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    53i32
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_in_tail_position() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(num: i32) -> $0Result<i32, String> {
-    return Ok(num)
-}
-"#,
-            r#"
-fn foo(num: i32) -> i32 {
-    return num
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_closure() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u32$0> {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return Ok(99);
-        } else {
-            return Ok(0);
-        }
-    }
-    let t = None;
-
-    Ok(t.unwrap_or_else(|| 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;
-        }
-    }
-    let t = None;
-
-    t.unwrap_or_else(|| the_field)
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_simple_with_weird_forms() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0> {
-    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;
-    }
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u32$0> {
-    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) -> u32 {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return 99,
-            _ => return 0,
-        }
-    }
-    the_field
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u32$0> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> Result<u3$02> {
-    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
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-
-    #[test]
-    fn unwrap_result_return_type_nested_type() {
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result, option
-fn foo() -> Result<Option<i32$0>, ()> {
-    Ok(Some(42))
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    Some(42)
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result, option
-fn foo() -> Result<Option<Result<i32$0, ()>>, ()> {
-    Ok(None)
-}
-"#,
-            r#"
-fn foo() -> Option<Result<i32, ()>> {
-    None
-}
-"#,
-            "Unwrap Result return type",
-        );
-
-        check_assist_by_label(
-            unwrap_return_type,
-            r#"
-//- minicore: result, option, iterators
-fn foo() -> Result<impl Iterator<Item = i32>$0, ()> {
-    Ok(Some(42).into_iter())
-}
-"#,
-            r#"
-fn foo() -> impl Iterator<Item = i32> {
-    Some(42).into_iter()
-}
-"#,
-            "Unwrap Result return type",
-        );
-    }
-}
diff --git a/crates/ide-assists/src/handlers/wrap_return_type.rs b/crates/ide-assists/src/handlers/wrap_return_type.rs
deleted file mode 100644
index 2d918a5b1c..0000000000
--- a/crates/ide-assists/src/handlers/wrap_return_type.rs
+++ /dev/null
@@ -1,2457 +0,0 @@
-use std::iter;
-
-use hir::HasSource;
-use ide_db::{
-    assists::GroupLabel,
-    famous_defs::FamousDefs,
-    syntax_helpers::node_ext::{for_each_tail_expr, walk_expr},
-};
-use itertools::Itertools;
-use syntax::{
-    ast::{self, make, Expr, HasGenericParams},
-    match_ast, ted, AstNode, ToSmolStr,
-};
-
-use crate::{AssistContext, AssistId, AssistKind, Assists};
-
-// Assist: wrap_return_type_in_option
-//
-// Wrap the function's return type into Option.
-//
-// ```
-// # //- minicore: option
-// fn foo() -> i32$0 { 42i32 }
-// ```
-// ->
-// ```
-// fn foo() -> Option<i32> { Some(42i32) }
-// ```
-
-// Assist: wrap_return_type_in_result
-//
-// Wrap the function's return type into Result.
-//
-// ```
-// # //- minicore: result
-// fn foo() -> i32$0 { 42i32 }
-// ```
-// ->
-// ```
-// fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
-// ```
-
-pub(crate) fn wrap_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
-    let ret_type = ctx.find_node_at_offset::<ast::RetType>()?;
-    let parent = ret_type.syntax().parent()?;
-    let body = match_ast! {
-        match parent {
-            ast::Fn(func) => func.body()?,
-            ast::ClosureExpr(closure) => match closure.body()? {
-                Expr::BlockExpr(block) => block,
-                // closures require a block when a return type is specified
-                _ => return None,
-            },
-            _ => return None,
-        }
-    };
-
-    let type_ref = &ret_type.ty()?;
-    let ty = ctx.sema.resolve_type(type_ref)?.as_adt();
-    let famous_defs = FamousDefs(&ctx.sema, ctx.sema.scope(type_ref.syntax())?.krate());
-
-    for kind in WrapperKind::ALL {
-        let Some(core_wrapper) = kind.core_type(&famous_defs) else {
-            continue;
-        };
-
-        if matches!(ty, Some(hir::Adt::Enum(ret_type)) if ret_type == core_wrapper) {
-            // The return type is already wrapped
-            cov_mark::hit!(wrap_return_type_simple_return_type_already_wrapped);
-            continue;
-        }
-
-        acc.add_group(
-            &GroupLabel("Wrap return type in...".into()),
-            kind.assist_id(),
-            kind.label(),
-            type_ref.syntax().text_range(),
-            |edit| {
-                let alias = wrapper_alias(ctx, &core_wrapper, type_ref, kind.symbol());
-                let new_return_ty =
-                    alias.unwrap_or_else(|| kind.wrap_type(type_ref)).clone_for_update();
-
-                let body = edit.make_mut(ast::Expr::BlockExpr(body.clone()));
-
-                let mut exprs_to_wrap = Vec::new();
-                let tail_cb = &mut |e: &_| tail_cb_impl(&mut exprs_to_wrap, e);
-                walk_expr(&body, &mut |expr| {
-                    if let Expr::ReturnExpr(ret_expr) = expr {
-                        if let Some(ret_expr_arg) = &ret_expr.expr() {
-                            for_each_tail_expr(ret_expr_arg, tail_cb);
-                        }
-                    }
-                });
-                for_each_tail_expr(&body, tail_cb);
-
-                for ret_expr_arg in exprs_to_wrap {
-                    let happy_wrapped = make::expr_call(
-                        make::expr_path(make::ext::ident_path(kind.happy_ident())),
-                        make::arg_list(iter::once(ret_expr_arg.clone())),
-                    )
-                    .clone_for_update();
-                    ted::replace(ret_expr_arg.syntax(), happy_wrapped.syntax());
-                }
-
-                let old_return_ty = edit.make_mut(type_ref.clone());
-                ted::replace(old_return_ty.syntax(), new_return_ty.syntax());
-
-                if let WrapperKind::Result = kind {
-                    // Add a placeholder snippet at the first generic argument that doesn't equal the return type.
-                    // This is normally the error type, but that may not be the case when we inserted a type alias.
-                    let args =
-                        new_return_ty.syntax().descendants().find_map(ast::GenericArgList::cast);
-                    let error_type_arg = args.and_then(|list| {
-                        list.generic_args().find(|arg| match arg {
-                            ast::GenericArg::TypeArg(_) => {
-                                arg.syntax().text() != type_ref.syntax().text()
-                            }
-                            ast::GenericArg::LifetimeArg(_) => false,
-                            _ => true,
-                        })
-                    });
-                    if let Some(error_type_arg) = error_type_arg {
-                        if let Some(cap) = ctx.config.snippet_cap {
-                            edit.add_placeholder_snippet(cap, error_type_arg);
-                        }
-                    }
-                }
-            },
-        );
-    }
-
-    Some(())
-}
-
-enum WrapperKind {
-    Option,
-    Result,
-}
-
-impl WrapperKind {
-    const ALL: &'static [WrapperKind] = &[WrapperKind::Option, WrapperKind::Result];
-
-    fn assist_id(&self) -> AssistId {
-        let s = match self {
-            WrapperKind::Option => "wrap_return_type_in_option",
-            WrapperKind::Result => "wrap_return_type_in_result",
-        };
-
-        AssistId(s, AssistKind::RefactorRewrite)
-    }
-
-    fn label(&self) -> &'static str {
-        match self {
-            WrapperKind::Option => "Wrap return type in Option",
-            WrapperKind::Result => "Wrap return type in Result",
-        }
-    }
-
-    fn happy_ident(&self) -> &'static str {
-        match self {
-            WrapperKind::Option => "Some",
-            WrapperKind::Result => "Ok",
-        }
-    }
-
-    fn core_type(&self, famous_defs: &FamousDefs<'_, '_>) -> Option<hir::Enum> {
-        match self {
-            WrapperKind::Option => famous_defs.core_option_Option(),
-            WrapperKind::Result => famous_defs.core_result_Result(),
-        }
-    }
-
-    fn symbol(&self) -> hir::Symbol {
-        match self {
-            WrapperKind::Option => hir::sym::Option.clone(),
-            WrapperKind::Result => hir::sym::Result.clone(),
-        }
-    }
-
-    fn wrap_type(&self, type_ref: &ast::Type) -> ast::Type {
-        match self {
-            WrapperKind::Option => make::ext::ty_option(type_ref.clone()),
-            WrapperKind::Result => make::ext::ty_result(type_ref.clone(), make::ty_placeholder()),
-        }
-    }
-}
-
-// Try to find an wrapper type alias in the current scope (shadowing the default).
-fn wrapper_alias(
-    ctx: &AssistContext<'_>,
-    core_wrapper: &hir::Enum,
-    ret_type: &ast::Type,
-    wrapper: hir::Symbol,
-) -> Option<ast::Type> {
-    let wrapper_path = hir::ModPath::from_segments(
-        hir::PathKind::Plain,
-        iter::once(hir::Name::new_symbol_root(wrapper)),
-    );
-
-    ctx.sema.resolve_mod_path(ret_type.syntax(), &wrapper_path).and_then(|def| {
-        def.filter_map(|def| match def.as_module_def()? {
-            hir::ModuleDef::TypeAlias(alias) => {
-                let enum_ty = alias.ty(ctx.db()).as_adt()?.as_enum()?;
-                (&enum_ty == core_wrapper).then_some(alias)
-            }
-            _ => None,
-        })
-        .find_map(|alias| {
-            let mut inserted_ret_type = false;
-            let generic_params = alias
-                .source(ctx.db())?
-                .value
-                .generic_param_list()?
-                .generic_params()
-                .map(|param| match param {
-                    // Replace the very first type parameter with the functions return type.
-                    ast::GenericParam::TypeParam(_) if !inserted_ret_type => {
-                        inserted_ret_type = true;
-                        ret_type.to_smolstr()
-                    }
-                    ast::GenericParam::LifetimeParam(_) => make::lifetime("'_").to_smolstr(),
-                    _ => make::ty_placeholder().to_smolstr(),
-                })
-                .join(", ");
-
-            let name = alias.name(ctx.db());
-            let name = name.as_str();
-            Some(make::ty(&format!("{name}<{generic_params}>")))
-        })
-    })
-}
-
-fn tail_cb_impl(acc: &mut Vec<ast::Expr>, e: &ast::Expr) {
-    match e {
-        Expr::BreakExpr(break_expr) => {
-            if let Some(break_expr_arg) = break_expr.expr() {
-                for_each_tail_expr(&break_expr_arg, &mut |e| tail_cb_impl(acc, e))
-            }
-        }
-        Expr::ReturnExpr(_) => {
-            // all return expressions have already been handled by the walk loop
-        }
-        e => acc.push(e.clone()),
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use crate::tests::{check_assist_by_label, check_assist_not_applicable_by_label};
-
-    use super::*;
-
-    #[test]
-    fn wrap_return_type_in_option_simple() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i3$02 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let test = "test";
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_break_split_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i3$02 {
-    loop {
-        break if true {
-            1
-        } else {
-            0
-        };
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    loop {
-        break if true {
-            Some(1)
-        } else {
-            Some(0)
-        };
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> i32$0 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Option<i32> {
-        let test = "test";
-        return Some(42i32);
-    };
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_return_type_bad_cursor() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32 {
-    let test = "test";$0
-    return 42i32;
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_return_type_bad_cursor_closure() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> i32 {
-        let test = "test";$0
-        return 42i32;
-    };
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_closure_non_block() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() { || -> i$032 3; }
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_return_type_already_option_std() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> core::option::Option<i32$0> {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_return_type_already_option() {
-        cov_mark::check!(wrap_return_type_simple_return_type_already_wrapped);
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> Option<i32$0> {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_return_type_already_option_closure() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> Option<i32$0, String> {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_cursor() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> $0i32 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let test = "test";
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() ->$0 i32 {
-    let test = "test";
-    42i32
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let test = "test";
-    Some(42i32)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || ->$0 i32 {
-        let test = "test";
-        42i32
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Option<i32> {
-        let test = "test";
-        Some(42i32)
-    };
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_only() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 { 42i32 }
-"#,
-            r#"
-fn foo() -> Option<i32> { Some(42i32) }
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_block_like() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    if true {
-        42i32
-    } else {
-        24i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    if true {
-        Some(42i32)
-    } else {
-        Some(24i32)
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_without_block_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() {
-    || -> i32$0 {
-        if true {
-            42i32
-        } else {
-            24i32
-        }
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Option<i32> {
-        if true {
-            Some(42i32)
-        } else {
-            Some(24i32)
-        }
-    };
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_nested_if() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    if true {
-        if false {
-            1
-        } else {
-            2
-        }
-    } else {
-        24i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    if true {
-        if false {
-            Some(1)
-        } else {
-            Some(2)
-        }
-    } else {
-        Some(24i32)
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_await() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-async fn foo() -> i$032 {
-    if true {
-        if false {
-            1.await
-        } else {
-            2.await
-        }
-    } else {
-        24i32.await
-    }
-}
-"#,
-            r#"
-async fn foo() -> Option<i32> {
-    if true {
-        if false {
-            Some(1.await)
-        } else {
-            Some(2.await)
-        }
-    } else {
-        Some(24i32.await)
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_array() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> [i32;$0 3] { [1, 2, 3] }
-"#,
-            r#"
-fn foo() -> Option<[i32; 3]> { Some([1, 2, 3]) }
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_cast() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -$0> i32 {
-    if true {
-        if false {
-            1 as i32
-        } else {
-            2 as i32
-        }
-    } else {
-        24 as i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    if true {
-        if false {
-            Some(1 as i32)
-        } else {
-            Some(2 as i32)
-        }
-    } else {
-        Some(24 as i32)
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_block_like_match() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let my_var = 5;
-    match my_var {
-        5 => 42i32,
-        _ => 24i32,
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let my_var = 5;
-    match my_var {
-        5 => Some(42i32),
-        _ => Some(24i32),
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_loop_with_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    my_var
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    Some(my_var)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_loop_in_let_stmt() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let my_var = let x = loop {
-        break 1;
-    };
-    my_var
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let my_var = let x = loop {
-        break 1;
-    };
-    Some(my_var)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_block_like_match_return_expr() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return 24i32,
-    };
-    res
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return Some(24i32),
-    };
-    Some(res)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return 24i32;
-    };
-    res
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return Some(24i32);
-    };
-    Some(res)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_block_like_match_deeper() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    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() -> Option<i32> {
-    let my_var = 5;
-    match my_var {
-        5 => {
-            if true {
-                Some(42i32)
-            } else {
-                Some(25i32)
-            }
-        },
-        _ => {
-            let test = "test";
-            if test == "test" {
-                return Some(bar());
-            }
-            Some(53i32)
-        },
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_tail_block_like_early_return() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i$032 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    53i32
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let test = "test";
-    if test == "test" {
-        return Some(24i32);
-    }
-    Some(53i32)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_in_option_tail_position() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(num: i32) -> $0i32 {
-    return num
-}
-"#,
-            r#"
-fn foo(num: i32) -> Option<i32> {
-    return Some(num)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) ->$0 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) -> Option<u32> {
-    let true_closure = || { return true; };
-    if the_field < 5 {
-        let mut i = 0;
-        if true_closure() {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    Some(the_field)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> u32$0 {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return 99;
-        } else {
-            return 0;
-        }
-    }
-    let t = None;
-
-    t.unwrap_or_else(|| the_field)
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Option<u32> {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    let t = None;
-
-    Some(t.unwrap_or_else(|| the_field))
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_option_simple_with_weird_forms() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i32$0 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    let mut i = 0;
-    loop {
-        if i == 1 {
-            break 55;
-        }
-        i += 1;
-    }
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    let test = "test";
-    if test == "test" {
-        return Some(24i32);
-    }
-    let mut i = 0;
-    loop {
-        if i == 1 {
-            break Some(55);
-        }
-        i += 1;
-    }
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> u32$0 {
-    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) -> Option<u32> {
-    if the_field < 5 {
-        let mut i = 0;
-        loop {
-            if i > 5 {
-                return Some(55u32);
-            }
-            i += 3;
-        }
-        match i {
-            5 => return Some(99),
-            _ => return Some(0),
-        };
-    }
-    Some(the_field)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> u3$02 {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return 99,
-            _ => return 0,
-        }
-    }
-    the_field
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Option<u32> {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return Some(99),
-            _ => return Some(0),
-        }
-    }
-    Some(the_field)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> u32$0 {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return 99
-        } else {
-            return 0
-        }
-    }
-    the_field
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Option<u32> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Some(99)
-        } else {
-            return Some(0)
-        }
-    }
-    Some(the_field)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo(the_field: u32) -> $0u32 {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return 99;
-        } else {
-            return 0;
-        }
-    }
-    the_field
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Option<u32> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Some(99);
-        } else {
-            return Some(0);
-        }
-    }
-    Some(the_field)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_option_type() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-type Option<T> = core::option::Option<T>;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-type Option<T> = core::option::Option<T>;
-
-fn foo() -> Option<i32> {
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-type Option2<T> = core::option::Option<T>;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-type Option2<T> = core::option::Option<T>;
-
-fn foo() -> Option<i32> {
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_imported_local_option_type() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-mod some_module {
-    pub type Option<T> = core::option::Option<T>;
-}
-
-use some_module::Option;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-mod some_module {
-    pub type Option<T> = core::option::Option<T>;
-}
-
-use some_module::Option;
-
-fn foo() -> Option<i32> {
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-mod some_module {
-    pub type Option<T> = core::option::Option<T>;
-}
-
-use some_module::*;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-mod some_module {
-    pub type Option<T> = core::option::Option<T>;
-}
-
-use some_module::*;
-
-fn foo() -> Option<i32> {
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_option_type_from_function_body() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-fn foo() -> i3$02 {
-    type Option<T> = core::option::Option<T>;
-    0
-}
-"#,
-            r#"
-fn foo() -> Option<i32> {
-    type Option<T> = core::option::Option<T>;
-    Some(0)
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_option_type_already_using_alias() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: option
-pub type Option<T> = core::option::Option<T>;
-
-fn foo() -> Option<i3$02> {
-    return Some(42i32);
-}
-"#,
-            WrapperKind::Option.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i3$02 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let test = "test";
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_break_split_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i3$02 {
-    loop {
-        break if true {
-            1
-        } else {
-            0
-        };
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    loop {
-        break if true {
-            Ok(1)
-        } else {
-            Ok(0)
-        };
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> i32$0 {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Result<i32, ${0:_}> {
-        let test = "test";
-        return Ok(42i32);
-    };
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_return_type_bad_cursor() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32 {
-    let test = "test";$0
-    return 42i32;
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> i32 {
-        let test = "test";$0
-        return 42i32;
-    };
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_closure_non_block() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() { || -> i$032 3; }
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_return_type_already_result_std() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> core::result::Result<i32$0, String> {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_return_type_already_result() {
-        cov_mark::check!(wrap_return_type_simple_return_type_already_wrapped);
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> Result<i32$0, String> {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_return_type_already_result_closure() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> Result<i32$0, String> {
-        let test = "test";
-        return 42i32;
-    };
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_cursor() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> $0i32 {
-    let test = "test";
-    return 42i32;
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let test = "test";
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() ->$0 i32 {
-    let test = "test";
-    42i32
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let test = "test";
-    Ok(42i32)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || ->$0 i32 {
-        let test = "test";
-        42i32
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Result<i32, ${0:_}> {
-        let test = "test";
-        Ok(42i32)
-    };
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_only() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 { 42i32 }
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_block_like() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    if true {
-        42i32
-    } else {
-        24i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    if true {
-        Ok(42i32)
-    } else {
-        Ok(24i32)
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_without_block_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() {
-    || -> i32$0 {
-        if true {
-            42i32
-        } else {
-            24i32
-        }
-    };
-}
-"#,
-            r#"
-fn foo() {
-    || -> Result<i32, ${0:_}> {
-        if true {
-            Ok(42i32)
-        } else {
-            Ok(24i32)
-        }
-    };
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_nested_if() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    if true {
-        if false {
-            1
-        } else {
-            2
-        }
-    } else {
-        24i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    if true {
-        if false {
-            Ok(1)
-        } else {
-            Ok(2)
-        }
-    } else {
-        Ok(24i32)
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_await() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-async fn foo() -> i$032 {
-    if true {
-        if false {
-            1.await
-        } else {
-            2.await
-        }
-    } else {
-        24i32.await
-    }
-}
-"#,
-            r#"
-async fn foo() -> Result<i32, ${0:_}> {
-    if true {
-        if false {
-            Ok(1.await)
-        } else {
-            Ok(2.await)
-        }
-    } else {
-        Ok(24i32.await)
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_array() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> [i32;$0 3] { [1, 2, 3] }
-"#,
-            r#"
-fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_cast() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -$0> i32 {
-    if true {
-        if false {
-            1 as i32
-        } else {
-            2 as i32
-        }
-    } else {
-        24 as i32
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    if true {
-        if false {
-            Ok(1 as i32)
-        } else {
-            Ok(2 as i32)
-        }
-    } else {
-        Ok(24 as i32)
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_block_like_match() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let my_var = 5;
-    match my_var {
-        5 => 42i32,
-        _ => 24i32,
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let my_var = 5;
-    match my_var {
-        5 => Ok(42i32),
-        _ => Ok(24i32),
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_loop_with_tail() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    my_var
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let my_var = 5;
-    loop {
-        println!("test");
-        5
-    }
-    Ok(my_var)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let my_var = let x = loop {
-        break 1;
-    };
-    my_var
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let my_var = let x = loop {
-        break 1;
-    };
-    Ok(my_var)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return 24i32,
-    };
-    res
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let my_var = 5;
-    let res = match my_var {
-        5 => 42i32,
-        _ => return Ok(24i32),
-    };
-    Ok(res)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return 24i32;
-    };
-    res
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let my_var = 5;
-    let res = if my_var == 5 {
-        42i32
-    } else {
-        return Ok(24i32);
-    };
-    Ok(res)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    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<i32, ${0:_}> {
-    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)
-        },
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i$032 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    53i32
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let test = "test";
-    if test == "test" {
-        return Ok(24i32);
-    }
-    Ok(53i32)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_in_result_tail_position() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(num: i32) -> $0i32 {
-    return num
-}
-"#,
-            r#"
-fn foo(num: i32) -> Result<i32, ${0:_}> {
-    return Ok(num)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_closure() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) ->$0 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<u32, ${0:_}> {
-    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)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> u32$0 {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return 99;
-        } else {
-            return 0;
-        }
-    }
-    let t = None;
-
-    t.unwrap_or_else(|| the_field)
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Result<u32, ${0:_}> {
-    let true_closure = || {
-        return true;
-    };
-    if the_field < 5 {
-        let mut i = 0;
-
-
-        if true_closure() {
-            return Ok(99);
-        } else {
-            return Ok(0);
-        }
-    }
-    let t = None;
-
-    Ok(t.unwrap_or_else(|| the_field))
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_result_simple_with_weird_forms() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i32$0 {
-    let test = "test";
-    if test == "test" {
-        return 24i32;
-    }
-    let mut i = 0;
-    loop {
-        if i == 1 {
-            break 55;
-        }
-        i += 1;
-    }
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    let test = "test";
-    if test == "test" {
-        return Ok(24i32);
-    }
-    let mut i = 0;
-    loop {
-        if i == 1 {
-            break Ok(55);
-        }
-        i += 1;
-    }
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> u32$0 {
-    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<u32, ${0:_}> {
-    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)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> u3$02 {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return 99,
-            _ => return 0,
-        }
-    }
-    the_field
-}
-"#,
-            r#"
-fn foo(the_field: u32) -> Result<u32, ${0:_}> {
-    if the_field < 5 {
-        let mut i = 0;
-        match i {
-            5 => return Ok(99),
-            _ => return Ok(0),
-        }
-    }
-    Ok(the_field)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> u32$0 {
-    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<u32, ${0:_}> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Ok(99)
-        } else {
-            return Ok(0)
-        }
-    }
-    Ok(the_field)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo(the_field: u32) -> $0u32 {
-    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<u32, ${0:_}> {
-    if the_field < 5 {
-        let mut i = 0;
-        if i == 5 {
-            return Ok(99);
-        } else {
-            return Ok(0);
-        }
-    }
-    Ok(the_field)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_result_type() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result<T> = core::result::Result<T, ()>;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-type Result<T> = core::result::Result<T, ()>;
-
-fn foo() -> Result<i32> {
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result2<T> = core::result::Result<T, ()>;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-type Result2<T> = core::result::Result<T, ()>;
-
-fn foo() -> Result<i32, ${0:_}> {
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_imported_local_result_type() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-mod some_module {
-    pub type Result<T> = core::result::Result<T, ()>;
-}
-
-use some_module::Result;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-mod some_module {
-    pub type Result<T> = core::result::Result<T, ()>;
-}
-
-use some_module::Result;
-
-fn foo() -> Result<i32> {
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-mod some_module {
-    pub type Result<T> = core::result::Result<T, ()>;
-}
-
-use some_module::*;
-
-fn foo() -> i3$02 {
-    return 42i32;
-}
-"#,
-            r#"
-mod some_module {
-    pub type Result<T> = core::result::Result<T, ()>;
-}
-
-use some_module::*;
-
-fn foo() -> Result<i32> {
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_result_type_from_function_body() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-fn foo() -> i3$02 {
-    type Result<T> = core::result::Result<T, ()>;
-    0
-}
-"#,
-            r#"
-fn foo() -> Result<i32, ${0:_}> {
-    type Result<T> = core::result::Result<T, ()>;
-    Ok(0)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_result_type_already_using_alias() {
-        check_assist_not_applicable_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-pub type Result<T> = core::result::Result<T, ()>;
-
-fn foo() -> Result<i3$02> {
-    return Ok(42i32);
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-    }
-
-    #[test]
-    fn wrap_return_type_in_local_result_type_multiple_generics() {
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result<T, E> = core::result::Result<T, E>;
-
-fn foo() -> i3$02 {
-    0
-}
-"#,
-            r#"
-type Result<T, E> = core::result::Result<T, E>;
-
-fn foo() -> Result<i32, ${0:_}> {
-    Ok(0)
-}
-"#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result<T, E> = core::result::Result<Foo<T, E>, ()>;
-
-fn foo() -> i3$02 {
-    0
-}
-            "#,
-            r#"
-type Result<T, E> = core::result::Result<Foo<T, E>, ()>;
-
-fn foo() -> Result<i32, ${0:_}> {
-    Ok(0)
-}
-            "#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result<'a, T, E> = core::result::Result<Foo<T, E>, &'a ()>;
-
-fn foo() -> i3$02 {
-    0
-}
-            "#,
-            r#"
-type Result<'a, T, E> = core::result::Result<Foo<T, E>, &'a ()>;
-
-fn foo() -> Result<'_, i32, ${0:_}> {
-    Ok(0)
-}
-            "#,
-            WrapperKind::Result.label(),
-        );
-
-        check_assist_by_label(
-            wrap_return_type,
-            r#"
-//- minicore: result
-type Result<T, const N: usize> = core::result::Result<Foo<T>, Bar<N>>;
-
-fn foo() -> i3$02 {
-    0
-}
-            "#,
-            r#"
-type Result<T, const N: usize> = core::result::Result<Foo<T>, Bar<N>>;
-
-fn foo() -> Result<i32, ${0:_}> {
-    Ok(0)
-}
-            "#,
-            WrapperKind::Result.label(),
-        );
-    }
-}
diff --git a/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs b/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs
new file mode 100644
index 0000000000..8f0e9b4fe0
--- /dev/null
+++ b/crates/ide-assists/src/handlers/wrap_return_type_in_result.rs
@@ -0,0 +1,1268 @@
+use std::iter;
+
+use hir::HasSource;
+use ide_db::{
+    famous_defs::FamousDefs,
+    syntax_helpers::node_ext::{for_each_tail_expr, walk_expr},
+};
+use itertools::Itertools;
+use syntax::{
+    ast::{self, make, Expr, HasGenericParams},
+    match_ast, ted, AstNode, ToSmolStr,
+};
+
+use crate::{AssistContext, AssistId, AssistKind, Assists};
+
+// Assist: wrap_return_type_in_result
+//
+// Wrap the function's return type into Result.
+//
+// ```
+// # //- minicore: result
+// fn foo() -> i32$0 { 42i32 }
+// ```
+// ->
+// ```
+// fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
+// ```
+pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
+    let ret_type = ctx.find_node_at_offset::<ast::RetType>()?;
+    let parent = ret_type.syntax().parent()?;
+    let body = match_ast! {
+        match parent {
+            ast::Fn(func) => func.body()?,
+            ast::ClosureExpr(closure) => match closure.body()? {
+                Expr::BlockExpr(block) => block,
+                // closures require a block when a return type is specified
+                _ => return None,
+            },
+            _ => return None,
+        }
+    };
+
+    let type_ref = &ret_type.ty()?;
+    let core_result =
+        FamousDefs(&ctx.sema, ctx.sema.scope(type_ref.syntax())?.krate()).core_result_Result()?;
+
+    let ty = ctx.sema.resolve_type(type_ref)?.as_adt();
+    if matches!(ty, Some(hir::Adt::Enum(ret_type)) if ret_type == core_result) {
+        // The return type is already wrapped in a Result
+        cov_mark::hit!(wrap_return_type_in_result_simple_return_type_already_result);
+        return None;
+    }
+
+    acc.add(
+        AssistId("wrap_return_type_in_result", AssistKind::RefactorRewrite),
+        "Wrap return type in Result",
+        type_ref.syntax().text_range(),
+        |edit| {
+            let new_result_ty = result_type(ctx, &core_result, type_ref).clone_for_update();
+            let body = edit.make_mut(ast::Expr::BlockExpr(body));
+
+            let mut exprs_to_wrap = Vec::new();
+            let tail_cb = &mut |e: &_| tail_cb_impl(&mut exprs_to_wrap, e);
+            walk_expr(&body, &mut |expr| {
+                if let Expr::ReturnExpr(ret_expr) = expr {
+                    if let Some(ret_expr_arg) = &ret_expr.expr() {
+                        for_each_tail_expr(ret_expr_arg, tail_cb);
+                    }
+                }
+            });
+            for_each_tail_expr(&body, tail_cb);
+
+            for ret_expr_arg in exprs_to_wrap {
+                let ok_wrapped = make::expr_call(
+                    make::expr_path(make::ext::ident_path("Ok")),
+                    make::arg_list(iter::once(ret_expr_arg.clone())),
+                )
+                .clone_for_update();
+                ted::replace(ret_expr_arg.syntax(), ok_wrapped.syntax());
+            }
+
+            let old_result_ty = edit.make_mut(type_ref.clone());
+            ted::replace(old_result_ty.syntax(), new_result_ty.syntax());
+
+            // Add a placeholder snippet at the first generic argument that doesn't equal the return type.
+            // This is normally the error type, but that may not be the case when we inserted a type alias.
+            let args = new_result_ty.syntax().descendants().find_map(ast::GenericArgList::cast);
+            let error_type_arg = args.and_then(|list| {
+                list.generic_args().find(|arg| match arg {
+                    ast::GenericArg::TypeArg(_) => arg.syntax().text() != type_ref.syntax().text(),
+                    ast::GenericArg::LifetimeArg(_) => false,
+                    _ => true,
+                })
+            });
+            if let Some(error_type_arg) = error_type_arg {
+                if let Some(cap) = ctx.config.snippet_cap {
+                    edit.add_placeholder_snippet(cap, error_type_arg);
+                }
+            }
+        },
+    )
+}
+
+fn result_type(
+    ctx: &AssistContext<'_>,
+    core_result: &hir::Enum,
+    ret_type: &ast::Type,
+) -> ast::Type {
+    // Try to find a Result<T, ...> type alias in the current scope (shadowing the default).
+    let result_path = hir::ModPath::from_segments(
+        hir::PathKind::Plain,
+        iter::once(hir::Name::new_symbol_root(hir::sym::Result.clone())),
+    );
+    let alias = ctx.sema.resolve_mod_path(ret_type.syntax(), &result_path).and_then(|def| {
+        def.filter_map(|def| match def.as_module_def()? {
+            hir::ModuleDef::TypeAlias(alias) => {
+                let enum_ty = alias.ty(ctx.db()).as_adt()?.as_enum()?;
+                (&enum_ty == core_result).then_some(alias)
+            }
+            _ => None,
+        })
+        .find_map(|alias| {
+            let mut inserted_ret_type = false;
+            let generic_params = alias
+                .source(ctx.db())?
+                .value
+                .generic_param_list()?
+                .generic_params()
+                .map(|param| match param {
+                    // Replace the very first type parameter with the functions return type.
+                    ast::GenericParam::TypeParam(_) if !inserted_ret_type => {
+                        inserted_ret_type = true;
+                        ret_type.to_smolstr()
+                    }
+                    ast::GenericParam::LifetimeParam(_) => make::lifetime("'_").to_smolstr(),
+                    _ => make::ty_placeholder().to_smolstr(),
+                })
+                .join(", ");
+
+            let name = alias.name(ctx.db());
+            let name = name.as_str();
+            Some(make::ty(&format!("{name}<{generic_params}>")))
+        })
+    });
+    // If there is no applicable alias in scope use the default Result type.
+    alias.unwrap_or_else(|| make::ext::ty_result(ret_type.clone(), make::ty_placeholder()))
+}
+
+fn tail_cb_impl(acc: &mut Vec<ast::Expr>, e: &ast::Expr) {
+    match e {
+        Expr::BreakExpr(break_expr) => {
+            if let Some(break_expr_arg) = break_expr.expr() {
+                for_each_tail_expr(&break_expr_arg, &mut |e| tail_cb_impl(acc, e))
+            }
+        }
+        Expr::ReturnExpr(_) => {
+            // all return expressions have already been handled by the walk loop
+        }
+        e => acc.push(e.clone()),
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use crate::tests::{check_assist, check_assist_not_applicable};
+
+    use super::*;
+
+    #[test]
+    fn wrap_return_type_in_result_simple() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i3$02 {
+    let test = "test";
+    return 42i32;
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let test = "test";
+    return Ok(42i32);
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_break_split_tail() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i3$02 {
+    loop {
+        break if true {
+            1
+        } else {
+            0
+        };
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    loop {
+        break if true {
+            Ok(1)
+        } else {
+            Ok(0)
+        };
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_closure() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> i32$0 {
+        let test = "test";
+        return 42i32;
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> Result<i32, ${0:_}> {
+        let test = "test";
+        return Ok(42i32);
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_return_type_bad_cursor() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32 {
+    let test = "test";$0
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> i32 {
+        let test = "test";$0
+        return 42i32;
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_closure_non_block() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() { || -> i$032 3; }
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_return_type_already_result_std() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> core::result::Result<i32$0, String> {
+    let test = "test";
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_return_type_already_result() {
+        cov_mark::check!(wrap_return_type_in_result_simple_return_type_already_result);
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> Result<i32$0, String> {
+    let test = "test";
+    return 42i32;
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_return_type_already_result_closure() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> Result<i32$0, String> {
+        let test = "test";
+        return 42i32;
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_cursor() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> $0i32 {
+    let test = "test";
+    return 42i32;
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let test = "test";
+    return Ok(42i32);
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() ->$0 i32 {
+    let test = "test";
+    42i32
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let test = "test";
+    Ok(42i32)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_closure() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() {
+    || ->$0 i32 {
+        let test = "test";
+        42i32
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> Result<i32, ${0:_}> {
+        let test = "test";
+        Ok(42i32)
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_only() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 { 42i32 }
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_block_like() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    if true {
+        42i32
+    } else {
+        24i32
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    if true {
+        Ok(42i32)
+    } else {
+        Ok(24i32)
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_without_block_closure() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() {
+    || -> i32$0 {
+        if true {
+            42i32
+        } else {
+            24i32
+        }
+    };
+}
+"#,
+            r#"
+fn foo() {
+    || -> Result<i32, ${0:_}> {
+        if true {
+            Ok(42i32)
+        } else {
+            Ok(24i32)
+        }
+    };
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_nested_if() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    if true {
+        if false {
+            1
+        } else {
+            2
+        }
+    } else {
+        24i32
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    if true {
+        if false {
+            Ok(1)
+        } else {
+            Ok(2)
+        }
+    } else {
+        Ok(24i32)
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_await() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+async fn foo() -> i$032 {
+    if true {
+        if false {
+            1.await
+        } else {
+            2.await
+        }
+    } else {
+        24i32.await
+    }
+}
+"#,
+            r#"
+async fn foo() -> Result<i32, ${0:_}> {
+    if true {
+        if false {
+            Ok(1.await)
+        } else {
+            Ok(2.await)
+        }
+    } else {
+        Ok(24i32.await)
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_array() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> [i32;$0 3] { [1, 2, 3] }
+"#,
+            r#"
+fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_cast() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -$0> i32 {
+    if true {
+        if false {
+            1 as i32
+        } else {
+            2 as i32
+        }
+    } else {
+        24 as i32
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    if true {
+        if false {
+            Ok(1 as i32)
+        } else {
+            Ok(2 as i32)
+        }
+    } else {
+        Ok(24 as i32)
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_block_like_match() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let my_var = 5;
+    match my_var {
+        5 => 42i32,
+        _ => 24i32,
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let my_var = 5;
+    match my_var {
+        5 => Ok(42i32),
+        _ => Ok(24i32),
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_loop_with_tail() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let my_var = 5;
+    loop {
+        println!("test");
+        5
+    }
+    my_var
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let my_var = 5;
+    loop {
+        println!("test");
+        5
+    }
+    Ok(my_var)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let my_var = let x = loop {
+        break 1;
+    };
+    my_var
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let my_var = let x = loop {
+        break 1;
+    };
+    Ok(my_var)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let my_var = 5;
+    let res = match my_var {
+        5 => 42i32,
+        _ => return 24i32,
+    };
+    res
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let my_var = 5;
+    let res = match my_var {
+        5 => 42i32,
+        _ => return Ok(24i32),
+    };
+    Ok(res)
+}
+"#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let my_var = 5;
+    let res = if my_var == 5 {
+        42i32
+    } else {
+        return 24i32;
+    };
+    res
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let my_var = 5;
+    let res = if my_var == 5 {
+        42i32
+    } else {
+        return Ok(24i32);
+    };
+    Ok(res)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    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<i32, ${0:_}> {
+    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)
+        },
+    }
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i$032 {
+    let test = "test";
+    if test == "test" {
+        return 24i32;
+    }
+    53i32
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    let test = "test";
+    if test == "test" {
+        return Ok(24i32);
+    }
+    Ok(53i32)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_in_tail_position() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo(num: i32) -> $0i32 {
+    return num
+}
+"#,
+            r#"
+fn foo(num: i32) -> Result<i32, ${0:_}> {
+    return Ok(num)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_closure() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo(the_field: u32) ->$0 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<u32, ${0:_}> {
+    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#"
+//- minicore: result
+fn foo(the_field: u32) -> u32$0 {
+    let true_closure = || {
+        return true;
+    };
+    if the_field < 5 {
+        let mut i = 0;
+
+
+        if true_closure() {
+            return 99;
+        } else {
+            return 0;
+        }
+    }
+    let t = None;
+
+    t.unwrap_or_else(|| the_field)
+}
+"#,
+            r#"
+fn foo(the_field: u32) -> Result<u32, ${0:_}> {
+    let true_closure = || {
+        return true;
+    };
+    if the_field < 5 {
+        let mut i = 0;
+
+
+        if true_closure() {
+            return Ok(99);
+        } else {
+            return Ok(0);
+        }
+    }
+    let t = None;
+
+    Ok(t.unwrap_or_else(|| the_field))
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_result_simple_with_weird_forms() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i32$0 {
+    let test = "test";
+    if test == "test" {
+        return 24i32;
+    }
+    let mut i = 0;
+    loop {
+        if i == 1 {
+            break 55;
+        }
+        i += 1;
+    }
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    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#"
+//- minicore: result
+fn foo(the_field: u32) -> u32$0 {
+    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<u32, ${0:_}> {
+    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#"
+//- minicore: result
+fn foo(the_field: u32) -> u3$02 {
+    if the_field < 5 {
+        let mut i = 0;
+        match i {
+            5 => return 99,
+            _ => return 0,
+        }
+    }
+    the_field
+}
+"#,
+            r#"
+fn foo(the_field: u32) -> Result<u32, ${0:_}> {
+    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#"
+//- minicore: result
+fn foo(the_field: u32) -> u32$0 {
+    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<u32, ${0:_}> {
+    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#"
+//- minicore: result
+fn foo(the_field: u32) -> $0u32 {
+    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<u32, ${0:_}> {
+    if the_field < 5 {
+        let mut i = 0;
+        if i == 5 {
+            return Ok(99);
+        } else {
+            return Ok(0);
+        }
+    }
+    Ok(the_field)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_local_result_type() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result<T> = core::result::Result<T, ()>;
+
+fn foo() -> i3$02 {
+    return 42i32;
+}
+"#,
+            r#"
+type Result<T> = core::result::Result<T, ()>;
+
+fn foo() -> Result<i32> {
+    return Ok(42i32);
+}
+"#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result2<T> = core::result::Result<T, ()>;
+
+fn foo() -> i3$02 {
+    return 42i32;
+}
+"#,
+            r#"
+type Result2<T> = core::result::Result<T, ()>;
+
+fn foo() -> Result<i32, ${0:_}> {
+    return Ok(42i32);
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_imported_local_result_type() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+mod some_module {
+    pub type Result<T> = core::result::Result<T, ()>;
+}
+
+use some_module::Result;
+
+fn foo() -> i3$02 {
+    return 42i32;
+}
+"#,
+            r#"
+mod some_module {
+    pub type Result<T> = core::result::Result<T, ()>;
+}
+
+use some_module::Result;
+
+fn foo() -> Result<i32> {
+    return Ok(42i32);
+}
+"#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+mod some_module {
+    pub type Result<T> = core::result::Result<T, ()>;
+}
+
+use some_module::*;
+
+fn foo() -> i3$02 {
+    return 42i32;
+}
+"#,
+            r#"
+mod some_module {
+    pub type Result<T> = core::result::Result<T, ()>;
+}
+
+use some_module::*;
+
+fn foo() -> Result<i32> {
+    return Ok(42i32);
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_local_result_type_from_function_body() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+fn foo() -> i3$02 {
+    type Result<T> = core::result::Result<T, ()>;
+    0
+}
+"#,
+            r#"
+fn foo() -> Result<i32, ${0:_}> {
+    type Result<T> = core::result::Result<T, ()>;
+    Ok(0)
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_local_result_type_already_using_alias() {
+        check_assist_not_applicable(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+pub type Result<T> = core::result::Result<T, ()>;
+
+fn foo() -> Result<i3$02> {
+    return Ok(42i32);
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn wrap_return_type_in_local_result_type_multiple_generics() {
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result<T, E> = core::result::Result<T, E>;
+
+fn foo() -> i3$02 {
+    0
+}
+"#,
+            r#"
+type Result<T, E> = core::result::Result<T, E>;
+
+fn foo() -> Result<i32, ${0:_}> {
+    Ok(0)
+}
+"#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result<T, E> = core::result::Result<Foo<T, E>, ()>;
+
+fn foo() -> i3$02 {
+    0
+}
+            "#,
+            r#"
+type Result<T, E> = core::result::Result<Foo<T, E>, ()>;
+
+fn foo() -> Result<i32, ${0:_}> {
+    Ok(0)
+}
+            "#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result<'a, T, E> = core::result::Result<Foo<T, E>, &'a ()>;
+
+fn foo() -> i3$02 {
+    0
+}
+            "#,
+            r#"
+type Result<'a, T, E> = core::result::Result<Foo<T, E>, &'a ()>;
+
+fn foo() -> Result<'_, i32, ${0:_}> {
+    Ok(0)
+}
+            "#,
+        );
+
+        check_assist(
+            wrap_return_type_in_result,
+            r#"
+//- minicore: result
+type Result<T, const N: usize> = core::result::Result<Foo<T>, Bar<N>>;
+
+fn foo() -> i3$02 {
+    0
+}
+            "#,
+            r#"
+type Result<T, const N: usize> = core::result::Result<Foo<T>, Bar<N>>;
+
+fn foo() -> Result<i32, ${0:_}> {
+    Ok(0)
+}
+            "#,
+        );
+    }
+}
diff --git a/crates/ide-assists/src/lib.rs b/crates/ide-assists/src/lib.rs
index 22620816d5..c98655b423 100644
--- a/crates/ide-assists/src/lib.rs
+++ b/crates/ide-assists/src/lib.rs
@@ -223,9 +223,9 @@ mod handlers {
     mod unnecessary_async;
     mod unqualify_method_call;
     mod unwrap_block;
-    mod unwrap_return_type;
+    mod unwrap_result_return_type;
     mod unwrap_tuple;
-    mod wrap_return_type;
+    mod wrap_return_type_in_result;
     mod wrap_unwrap_cfg_attr;
 
     pub(crate) fn all() -> &'static [Handler] {
@@ -355,10 +355,10 @@ mod handlers {
             unmerge_use::unmerge_use,
             unnecessary_async::unnecessary_async,
             unwrap_block::unwrap_block,
-            unwrap_return_type::unwrap_return_type,
+            unwrap_result_return_type::unwrap_result_return_type,
             unwrap_tuple::unwrap_tuple,
             unqualify_method_call::unqualify_method_call,
-            wrap_return_type::wrap_return_type,
+            wrap_return_type_in_result::wrap_return_type_in_result,
             wrap_unwrap_cfg_attr::wrap_unwrap_cfg_attr,
 
             // These are manually sorted for better priorities. By default,
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index c61b2ba84f..4cbcb6ed05 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -497,6 +497,44 @@ fn func_in_include() {
  //^^^^^^^^^^^^^^^
 }
 
+fn foo() {
+    func_in_include$0();
+}
+"#,
+        );
+    }
+
+    #[test]
+    fn goto_def_in_included_file_inside_mod() {
+        check(
+            r#"
+//- minicore:include
+//- /main.rs
+mod a {
+    include!("b.rs");
+}
+//- /b.rs
+fn func_in_include() {
+ //^^^^^^^^^^^^^^^
+}
+fn foo() {
+    func_in_include$0();
+}
+"#,
+        );
+
+        check(
+            r#"
+//- minicore:include
+//- /main.rs
+mod a {
+    include!("a.rs");
+}
+//- /a.rs
+fn func_in_include() {
+ //^^^^^^^^^^^^^^^
+}
+
 fn foo() {
     func_in_include$0();
 }
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 64d717f88d..e7cb8a253f 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -2750,4 +2750,25 @@ impl Foo {
             "#]],
         );
     }
+
+    #[test]
+    fn goto_ref_on_included_file() {
+        check(
+            r#"
+//- minicore:include
+//- /lib.rs
+include!("foo.rs");
+fn howdy() {
+    let _ = FOO;
+}
+//- /foo.rs
+const FOO$0: i32 = 0;
+"#,
+            expect![[r#"
+                FOO Const FileId(1) 0..19 6..9
+
+                FileId(0) 45..48
+            "#]],
+        );
+    }
 }
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs
index ed4894f9b9..11b79e4e0e 100644
--- a/crates/syntax/src/ptr.rs
+++ b/crates/syntax/src/ptr.rs
@@ -27,7 +27,7 @@ pub struct AstPtr<N: AstNode> {
     _ty: PhantomData<fn() -> N>,
 }
 
-impl<N: AstNode + std::fmt::Debug> std::fmt::Debug for AstPtr<N> {
+impl<N: AstNode> std::fmt::Debug for AstPtr<N> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         f.debug_tuple("AstPtr").field(&self.raw).finish()
     }
diff --git a/editors/code/package.json b/editors/code/package.json
index e55eceff78..70bb5f2447 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -349,11 +349,6 @@
                         "markdownDescription": "Whether to show the test explorer.",
                         "default": false,
                         "type": "boolean"
-                    },
-                    "rust-analyzer.initializeStopped": {
-                        "markdownDescription": "Do not start rust-analyzer server when the extension is activated.",
-                        "default": false,
-                        "type": "boolean"
                     }
                 }
             },
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 67bc72f1e1..abb4099f9f 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -330,10 +330,6 @@ export class Config {
     get statusBarClickAction() {
         return this.get<string>("statusBar.clickAction");
     }
-
-    get initializeStopped() {
-        return this.get<boolean>("initializeStopped");
-    }
 }
 
 export function prepareVSCodeConfig<T>(resp: T): T {
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index fdf43f66f9..0ddc5619e9 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -107,14 +107,7 @@ async function activateServer(ctx: Ctx): Promise<RustAnalyzerExtensionApi> {
         initializeDebugSessionTrackingAndRebuild(ctx);
     }
 
-    if (ctx.config.initializeStopped) {
-        ctx.setServerStatus({
-            health: "stopped",
-        });
-    } else {
-        await ctx.start();
-    }
-
+    await ctx.start();
     return ctx;
 }
 


Test patch:
diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs
index 933d45d750..48e12a8107 100644
--- a/crates/ide-assists/src/tests/generated.rs
+++ b/crates/ide-assists/src/tests/generated.rs
@@ -3264,20 +3264,6 @@ fn foo() {
     )
 }
 
-#[test]
-fn doctest_unwrap_option_return_type() {
-    check_doc_test(
-        "unwrap_option_return_type",
-        r#####"
-//- minicore: option
-fn foo() -> Option<i32>$0 { Some(42i32) }
-"#####,
-        r#####"
-fn foo() -> i32 { 42i32 }
-"#####,
-    )
-}
-
 #[test]
 fn doctest_unwrap_result_return_type() {
     check_doc_test(
@@ -3311,20 +3297,6 @@ fn main() {
     )
 }
 
-#[test]
-fn doctest_wrap_return_type_in_option() {
-    check_doc_test(
-        "wrap_return_type_in_option",
-        r#####"
-//- minicore: option
-fn foo() -> i32$0 { 42i32 }
-"#####,
-        r#####"
-fn foo() -> Option<i32> { Some(42i32) }
-"#####,
-    )
-}
-
 #[test]
 fn doctest_wrap_return_type_in_result() {
     check_doc_test(
diff --git a/crates/ide-completion/src/tests/pattern.rs b/crates/ide-completion/src/tests/pattern.rs
index a5eb0369b1..bd3e7c72bc 100644
--- a/crates/ide-completion/src/tests/pattern.rs
+++ b/crates/ide-completion/src/tests/pattern.rs
@@ -923,21 +923,3 @@ fn foo() {
         "#]],
     );
 }
-
-#[test]
-fn private_item_in_module_in_function_body() {
-    check_empty(
-        r#"
-fn main() {
-    mod foo {
-        struct Private;
-        pub struct Public;
-    }
-    foo::$0
-}
-"#,
-        expect![[r#"
-            st Public Public
-        "#]],
-    );
-}