From fbdcb49d483bb305f9abc7bb23a1d096ccd0481b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 2 Jul 2021 23:52:43 +0200 Subject: [PATCH] Simplify --- crates/ide_assists/src/handlers/unmerge_use.rs | 15 +++++++-------- .../src/handlers/wrap_return_type_in_result.rs | 1 + crates/ide_assists/src/tests/generated.rs | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/ide_assists/src/handlers/unmerge_use.rs b/crates/ide_assists/src/handlers/unmerge_use.rs index 14e862cd0b1..57773e95e15 100644 --- a/crates/ide_assists/src/handlers/unmerge_use.rs +++ b/crates/ide_assists/src/handlers/unmerge_use.rs @@ -1,3 +1,5 @@ +use ast::make; +use itertools::Itertools; use syntax::{ ast::{self, VisibilityOwner}, ted::{self, Position}, @@ -42,9 +44,9 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()> "Unmerge use", target, |builder| { - let new_use = ast::make::use_( + let new_use = make::use_( use_.visibility(), - ast::make::use_tree( + make::use_tree( path, tree.use_tree_list(), tree.rename(), @@ -62,17 +64,14 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } fn resolve_full_path(tree: &ast::UseTree) -> Option { - let mut paths = tree + let paths = tree .syntax() .ancestors() - .take_while(|n| n.kind() != SyntaxKind::USE_KW) + .take_while(|n| n.kind() != SyntaxKind::USE) .filter_map(ast::UseTree::cast) .filter_map(|t| t.path()); - let mut final_path = paths.next()?; - for path in paths { - final_path = ast::make::path_concat(path, final_path) - } + let final_path = paths.fold1(|prev, next| make::path_concat(next, prev))?; if final_path.segment().map_or(false, |it| it.self_token().is_some()) { final_path.qualifier() } else { 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 index ae582dc7ecb..7977434e1ae 100644 --- a/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs +++ b/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs @@ -13,6 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // Wrap the function's return type into Result. // // ``` +// # //- minicore: result // fn foo() -> i32$0 { 42i32 } // ``` // -> diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 1509c3c6339..c3c21317345 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs @@ -1600,6 +1600,7 @@ fn doctest_wrap_return_type_in_result() { check_doc_test( "wrap_return_type_in_result", r#####" +//- minicore: result fn foo() -> i32$0 { 42i32 } "#####, r#####"