depot/third_party/nixpkgs/pkgs/development/tools/rust/rust-analyzer/no-option-zip.patch
Default email 1693fb2285 Project import generated by Copybara.
GitOrigin-RevId: 420f89ceb267b461eed5d025b6c3c0e57703cc5c
2020-10-07 11:15:18 +02:00

52 lines
2.5 KiB
Diff

diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs
index fe33cee53..2184a4154 100644
--- a/crates/assists/src/handlers/merge_imports.rs
+++ b/crates/assists/src/handlers/merge_imports.rs
@@ -32,7 +32,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
let (merged, to_delete) =
next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| {
- try_merge_imports(&use_item, &use_item2, MergeBehaviour::Full).zip(Some(use_item2))
+ Some((try_merge_imports(&use_item, &use_item2, MergeBehaviour::Full)?, use_item2))
})?;
rewriter.replace_ast(&use_item, &merged);
@@ -44,7 +44,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
} else {
let (merged, to_delete) =
next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| {
- try_merge_trees(&tree, &use_tree, MergeBehaviour::Full).zip(Some(use_tree))
+ Some((try_merge_trees(&tree, &use_tree, MergeBehaviour::Full)?, use_tree))
})?;
rewriter.replace_ast(&tree, &merged);
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs
index f6025c99a..f9bd31cf3 100644
--- a/crates/assists/src/utils/insert_use.rs
+++ b/crates/assists/src/utils/insert_use.rs
@@ -274,7 +274,7 @@ fn common_prefix(lhs: &ast::Path, rhs: &ast::Path) -> Option<(ast::Path, ast::Pa
}
res = Some((lhs_curr.clone(), rhs_curr.clone()));
- match lhs_curr.parent_path().zip(rhs_curr.parent_path()) {
+ match zip(lhs_curr.parent_path(), rhs_curr.parent_path()) {
Some((lhs, rhs)) => {
lhs_curr = lhs;
rhs_curr = rhs;
@@ -452,7 +452,7 @@ fn find_insert_position(
let path_node_iter = scope
.as_syntax_node()
.children()
- .filter_map(|node| ast::Use::cast(node.clone()).zip(Some(node)))
+ .filter_map(|node| Some((ast::Use::cast(node.clone())?, node)))
.flat_map(|(use_, node)| {
let tree = use_.use_tree()?;
let path = tree.path()?;
@@ -989,3 +989,7 @@ use foo::bar::baz::Qux;",
assert_eq!(result.map(|u| u.to_string()), None);
}
}
+
+fn zip<T, U>(x: Option<T>, y: Option<U>) -> Option<(T, U)> {
+ Some((x?, y?))
+}