use hir::{known, AsAssocItem, Semantics};
use ide_db::{
- helpers::{for_each_tail_expr, FamousDefs},
+ helpers::{
+ for_each_tail_expr,
+ node_ext::{block_as_lone_tail, preorder_expr},
+ FamousDefs,
+ },
RootDatabase,
};
use itertools::Itertools;
use syntax::{
- ast::{self, edit::AstNodeEdit, make, ArgListOwner},
+ ast::{self, edit::AstNodeEdit, make, HasArgList},
ted, AstNode, SyntaxNode,
};
sema: &Semantics<RootDatabase>,
expr: &SyntaxNode,
) -> Option<(hir::Variant, hir::Variant)> {
- let fam = FamousDefs(&sema, sema.scope(expr).krate());
+ let fam = FamousDefs(sema, sema.scope(expr).krate());
let option_variants = fam.core_option_Option()?.variants(sema.db);
match &*option_variants {
&[variant0, variant1] => Some(if variant0.name(sema.db) == known::None {
expr: &ast::Expr,
) -> bool {
let mut invalid = false;
- expr.preorder(&mut |e| {
+ preorder_expr(expr, &mut |e| {
invalid |=
matches!(e, syntax::WalkEvent::Enter(ast::Expr::TryExpr(_) | ast::Expr::ReturnExpr(_)));
invalid
});
if !invalid {
- for_each_tail_expr(&expr, &mut |e| {
+ for_each_tail_expr(expr, &mut |e| {
if invalid {
return;
}
block: &ast::BlockExpr,
none_variant: hir::Variant,
) -> bool {
- block.as_lone_tail().and_then(|e| match e {
+ block_as_lone_tail(block).and_then(|e| match e {
ast::Expr::PathExpr(pat) => match sema.resolve_path(&pat.path()?)? {
hir::PathResolution::Def(hir::ModuleDef::Variant(v)) => Some(v),
_ => None,