Drop needless trait

This commit is contained in:
Aleksey Kladov 2020-04-09 23:02:10 +02:00
parent e07d3c94de
commit 0ed27c388a
4 changed files with 20 additions and 28 deletions

View file

@ -1,6 +1,9 @@
//! FIXME: write short doc here
use ra_syntax::{ast, match_ast, AstNode};
use ra_syntax::{
ast::{self, ModuleItemOwner},
match_ast, AstNode,
};
use rustc_hash::FxHashMap;
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
let mut params = FxHashMap::default();
for node in ctx.token.parent().ancestors() {
match_ast! {
let items = match_ast! {
match node {
ast::SourceFile(it) => process(it, &mut params),
ast::ItemList(it) => process(it, &mut params),
_ => (),
ast::SourceFile(it) => it.items(),
ast::ItemList(it) => it.items(),
_ => continue,
}
};
for item in items {
if let ast::ModuleItem::FnDef(func) = item {
func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
let text = param.syntax().text().to_string();
params.entry(text).or_insert((0, param)).0 += 1;
})
}
}
}
@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
.lookup_by(lookup)
.add_to(acc)
});
fn process<N: ast::FnDefOwner>(node: N, params: &mut FxHashMap<String, (u32, ast::Param)>) {
node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each(
|param| {
let text = param.syntax().text().to_string();
params.entry(text).or_insert((0, param)).0 += 1;
},
)
}
}
#[cfg(test)]

View file

@ -22,7 +22,6 @@ impl AstNode for SourceFile {
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl ast::ModuleItemOwner for SourceFile {}
impl ast::FnDefOwner for SourceFile {}
impl ast::AttrsOwner for SourceFile {}
impl SourceFile {
pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) }
@ -344,7 +343,6 @@ impl AstNode for ItemList {
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl ast::FnDefOwner for ItemList {}
impl ast::ModuleItemOwner for ItemList {}
impl ItemList {
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
@ -2512,7 +2510,6 @@ impl AstNode for MacroItems {
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl ast::ModuleItemOwner for MacroItems {}
impl ast::FnDefOwner for MacroItems {}
impl MacroItems {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MacroStmts {
@ -2548,7 +2545,6 @@ impl AstNode for ExternItemList {
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl ast::FnDefOwner for ExternItemList {}
impl ast::ModuleItemOwner for ExternItemList {}
impl ExternItemList {
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }

View file

@ -43,12 +43,6 @@ pub trait ArgListOwner: AstNode {
}
}
pub trait FnDefOwner: AstNode {
fn functions(&self) -> AstChildren<ast::FnDef> {
support::children(self.syntax())
}
}
pub trait ModuleItemOwner: AstNode {
fn items(&self) -> AstChildren<ast::ModuleItem> {
support::children(self.syntax())

View file

@ -298,7 +298,7 @@ macro_rules! ast_enums {
pub(crate) const AST_SRC: AstSrc = AstSrc {
nodes: &ast_nodes! {
struct SourceFile: ModuleItemOwner, FnDefOwner, AttrsOwner {
struct SourceFile: ModuleItemOwner, AttrsOwner {
modules: [Module],
}
@ -364,7 +364,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
Semi
}
struct ItemList: FnDefOwner, ModuleItemOwner {
struct ItemList: ModuleItemOwner {
LCurly,
impl_items: [ImplItem],
RCurly
@ -604,14 +604,14 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
struct LifetimeArg { Lifetime }
struct ConstArg { Literal, Eq, BlockExpr }
struct MacroItems: ModuleItemOwner, FnDefOwner { }
struct MacroItems: ModuleItemOwner{ }
struct MacroStmts {
statements: [Stmt],
Expr,
}
struct ExternItemList: FnDefOwner, ModuleItemOwner {
struct ExternItemList: ModuleItemOwner {
LCurly,
extern_items: [ExternItem],
RCurly