mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Simplify
This commit is contained in:
parent
26dd0c4e5b
commit
fbdcb49d48
3 changed files with 9 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use ast::make;
|
||||||
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, VisibilityOwner},
|
ast::{self, VisibilityOwner},
|
||||||
ted::{self, Position},
|
ted::{self, Position},
|
||||||
|
@ -42,9 +44,9 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
||||||
"Unmerge use",
|
"Unmerge use",
|
||||||
target,
|
target,
|
||||||
|builder| {
|
|builder| {
|
||||||
let new_use = ast::make::use_(
|
let new_use = make::use_(
|
||||||
use_.visibility(),
|
use_.visibility(),
|
||||||
ast::make::use_tree(
|
make::use_tree(
|
||||||
path,
|
path,
|
||||||
tree.use_tree_list(),
|
tree.use_tree_list(),
|
||||||
tree.rename(),
|
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<ast::Path> {
|
fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> {
|
||||||
let mut paths = tree
|
let paths = tree
|
||||||
.syntax()
|
.syntax()
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.take_while(|n| n.kind() != SyntaxKind::USE_KW)
|
.take_while(|n| n.kind() != SyntaxKind::USE)
|
||||||
.filter_map(ast::UseTree::cast)
|
.filter_map(ast::UseTree::cast)
|
||||||
.filter_map(|t| t.path());
|
.filter_map(|t| t.path());
|
||||||
|
|
||||||
let mut final_path = paths.next()?;
|
let final_path = paths.fold1(|prev, next| make::path_concat(next, prev))?;
|
||||||
for path in paths {
|
|
||||||
final_path = ast::make::path_concat(path, final_path)
|
|
||||||
}
|
|
||||||
if final_path.segment().map_or(false, |it| it.self_token().is_some()) {
|
if final_path.segment().map_or(false, |it| it.self_token().is_some()) {
|
||||||
final_path.qualifier()
|
final_path.qualifier()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
// Wrap the function's return type into Result.
|
// Wrap the function's return type into Result.
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
|
// # //- minicore: result
|
||||||
// fn foo() -> i32$0 { 42i32 }
|
// fn foo() -> i32$0 { 42i32 }
|
||||||
// ```
|
// ```
|
||||||
// ->
|
// ->
|
||||||
|
|
|
@ -1600,6 +1600,7 @@ fn doctest_wrap_return_type_in_result() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
"wrap_return_type_in_result",
|
"wrap_return_type_in_result",
|
||||||
r#####"
|
r#####"
|
||||||
|
//- minicore: result
|
||||||
fn foo() -> i32$0 { 42i32 }
|
fn foo() -> i32$0 { 42i32 }
|
||||||
"#####,
|
"#####,
|
||||||
r#####"
|
r#####"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue