mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
HasGenericArgs syntax trait
This commit is contained in:
parent
6c8c49b01b
commit
c08d419fba
26 changed files with 83 additions and 41 deletions
|
@ -15,8 +15,8 @@ use span::AstIdMap;
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,
|
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasGenericArgs,
|
||||||
RangeItem, SlicePatComponents,
|
HasLoopBody, HasName, RangeItem, SlicePatComponents,
|
||||||
},
|
},
|
||||||
AstNode, AstPtr, AstToken as _, SyntaxNodePtr,
|
AstNode, AstPtr, AstToken as _, SyntaxNodePtr,
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ use hir_expand::{
|
||||||
AstId,
|
AstId,
|
||||||
};
|
};
|
||||||
use intern::Interned;
|
use intern::Interned;
|
||||||
use syntax::ast::{self, HasName, IsString};
|
use syntax::ast::{self, HasGenericArgs, HasName, IsString};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
||||||
|
|
|
@ -9,7 +9,7 @@ use hir_expand::{
|
||||||
name::{name, AsName},
|
name::{name, AsName},
|
||||||
};
|
};
|
||||||
use intern::Interned;
|
use intern::Interned;
|
||||||
use syntax::ast::{self, AstNode, HasTypeBounds};
|
use syntax::ast::{self, AstNode, HasGenericArgs, HasTypeBounds};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
path::{AssociatedTypeBinding, GenericArg, GenericArgs, ModPath, Path, PathKind},
|
path::{AssociatedTypeBinding, GenericArg, GenericArgs, ModPath, Path, PathKind},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use ide_db::defs::{Definition, NameRefClass};
|
use ide_db::defs::{Definition, NameRefClass};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, make, HasArgList},
|
ast::{self, make, HasArgList, HasGenericArgs},
|
||||||
ted, AstNode,
|
ted, AstNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use ide_db::{famous_defs::FamousDefs, traits::resolve_target_trait};
|
use ide_db::{famous_defs::FamousDefs, traits::resolve_target_trait};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, make, AstNode, HasName},
|
ast::{self, make, AstNode, HasGenericArgs, HasName},
|
||||||
ted,
|
ted,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use hir::ImportPathConfig;
|
use hir::ImportPathConfig;
|
||||||
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait};
|
use ide_db::{famous_defs::FamousDefs, helpers::mod_path_to_ast, traits::resolve_target_trait};
|
||||||
use syntax::ast::{self, AstNode, HasName};
|
use syntax::ast::{self, AstNode, HasGenericArgs, HasName};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use ide_db::syntax_helpers::node_ext::walk_ty;
|
use ide_db::syntax_helpers::node_ext::walk_ty;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, edit::IndentLevel, make, AstNode, HasGenericParams, HasName},
|
ast::{self, edit::IndentLevel, make, AstNode, HasGenericArgs, HasGenericParams, HasName},
|
||||||
ted,
|
ted,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,9 @@ use syntax::{
|
||||||
self,
|
self,
|
||||||
edit::{self, AstNodeEdit},
|
edit::{self, AstNodeEdit},
|
||||||
edit_in_place::AttrsOwnerEdit,
|
edit_in_place::AttrsOwnerEdit,
|
||||||
make, AssocItem, GenericArgList, GenericParamList, HasAttrs, HasGenericParams, HasName,
|
make, AssocItem, GenericArgList, GenericParamList, HasAttrs, HasGenericArgs,
|
||||||
HasTypeBounds, HasVisibility as astHasVisibility, Path, WherePred,
|
HasGenericParams, HasName, HasTypeBounds, HasVisibility as astHasVisibility, Path,
|
||||||
|
WherePred,
|
||||||
},
|
},
|
||||||
ted::{self, Position},
|
ted::{self, Position},
|
||||||
AstNode, NodeOrToken, SmolStr, SyntaxKind,
|
AstNode, NodeOrToken, SmolStr, SyntaxKind,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use itertools::Itertools;
|
||||||
use stdx::{format_to, to_lower_snake_case};
|
use stdx::{format_to, to_lower_snake_case};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::skip_whitespace_token,
|
algo::skip_whitespace_token,
|
||||||
ast::{self, edit::IndentLevel, HasDocComments, HasName},
|
ast::{self, edit::IndentLevel, HasDocComments, HasGenericArgs, HasName},
|
||||||
match_ast, AstNode, AstToken,
|
match_ast, AstNode, AstToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,9 @@ use ide_db::{
|
||||||
};
|
};
|
||||||
use itertools::{izip, Itertools};
|
use itertools::{izip, Itertools};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, edit::IndentLevel, edit_in_place::Indent, HasArgList, Pat, PathExpr},
|
ast::{
|
||||||
|
self, edit::IndentLevel, edit_in_place::Indent, HasArgList, HasGenericArgs, Pat, PathExpr,
|
||||||
|
},
|
||||||
ted, AstNode, NodeOrToken, SyntaxKind,
|
ted, AstNode, NodeOrToken, SyntaxKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use ide_db::{
|
||||||
helpers::mod_path_to_ast,
|
helpers::mod_path_to_ast,
|
||||||
imports::import_assets::{ImportCandidate, LocatedImport},
|
imports::import_assets::{ImportCandidate, LocatedImport},
|
||||||
};
|
};
|
||||||
|
use syntax::ast::HasGenericArgs;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast,
|
ast,
|
||||||
ast::{make, HasArgList},
|
ast::{make, HasArgList},
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ide_db::{
|
||||||
imports::insert_use::{insert_use, ImportScope},
|
imports::insert_use::{insert_use, ImportScope},
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, make},
|
ast::{self, make, HasGenericArgs},
|
||||||
match_ast, ted, AstNode, SyntaxNode,
|
match_ast, ted, AstNode, SyntaxNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use hir::HirDisplay;
|
use hir::HirDisplay;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{Expr, GenericArg, GenericArgList},
|
ast::{Expr, GenericArg, GenericArgList, HasGenericArgs, LetStmt, Type::InferType},
|
||||||
ast::{LetStmt, Type::InferType},
|
|
||||||
AstNode, TextRange,
|
AstNode, TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ide_db::{
|
||||||
famous_defs::FamousDefs,
|
famous_defs::FamousDefs,
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasVisibility},
|
ast::{self, HasGenericArgs, HasVisibility},
|
||||||
AstNode, NodeOrToken, SyntaxKind, SyntaxNode, SyntaxToken, TextRange,
|
AstNode, NodeOrToken, SyntaxKind, SyntaxNode, SyntaxToken, TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ide_db::{
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, Expr},
|
ast::{self, Expr, HasGenericArgs},
|
||||||
match_ast, AstNode, NodeOrToken, SyntaxKind, TextRange,
|
match_ast, AstNode, NodeOrToken, SyntaxKind, TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,10 @@ use ide_db::{active_parameter::ActiveParameter, RootDatabase};
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::{ancestors_at_offset, find_node_at_offset, non_trivia_sibling},
|
algo::{ancestors_at_offset, find_node_at_offset, non_trivia_sibling},
|
||||||
ast::{self, AttrKind, HasArgList, HasGenericParams, HasLoopBody, HasName, NameOrNameRef},
|
ast::{
|
||||||
|
self, AttrKind, HasArgList, HasGenericArgs, HasGenericParams, HasLoopBody, HasName,
|
||||||
|
NameOrNameRef,
|
||||||
|
},
|
||||||
match_ast, AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode,
|
match_ast, AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode,
|
||||||
SyntaxToken, TextRange, TextSize, T,
|
SyntaxToken, TextRange, TextSize, T,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use hir::{AsAssocItem, HirDisplay, ImportPathConfig, ModuleDef, SemanticsScope};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, make, AstNode},
|
ast::{self, make, AstNode, HasGenericArgs},
|
||||||
ted, SyntaxNode,
|
ted, SyntaxNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use hir::{ImportPathConfig, Semantics};
|
||||||
use ide_db::{base_db::FileRange, FxHashMap};
|
use ide_db::{base_db::FileRange, FxHashMap};
|
||||||
use std::{cell::Cell, iter::Peekable};
|
use std::{cell::Cell, iter::Peekable};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AstToken},
|
ast::{self, AstNode, AstToken, HasGenericArgs},
|
||||||
SmolStr, SyntaxElement, SyntaxElementChildren, SyntaxKind, SyntaxNode, SyntaxToken,
|
SmolStr, SyntaxElement, SyntaxElementChildren, SyntaxKind, SyntaxNode, SyntaxToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
use hir::AsAssocItem;
|
use hir::AsAssocItem;
|
||||||
use ide_db::{base_db::FilePosition, FxHashMap};
|
use ide_db::{base_db::FilePosition, FxHashMap};
|
||||||
use parsing::Placeholder;
|
use parsing::Placeholder;
|
||||||
use syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken};
|
use syntax::{
|
||||||
|
ast::{self, HasGenericArgs},
|
||||||
|
SmolStr, SyntaxKind, SyntaxNode, SyntaxToken,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{errors::error, parsing, SsrError};
|
use crate::{errors::error, parsing, SsrError};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use ide_db::{base_db::FileId, famous_defs::FamousDefs, RootDatabase};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, HasName},
|
ast::{self, AstNode, HasGenericArgs, HasName},
|
||||||
match_ast,
|
match_ast,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ pub use self::{
|
||||||
operators::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp},
|
operators::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp},
|
||||||
token_ext::{CommentKind, CommentPlacement, CommentShape, IsString, QuoteOffsets, Radix},
|
token_ext::{CommentKind, CommentPlacement, CommentShape, IsString, QuoteOffsets, Radix},
|
||||||
traits::{
|
traits::{
|
||||||
AttrDocCommentIter, DocCommentIter, HasArgList, HasAttrs, HasDocComments, HasGenericParams,
|
AttrDocCommentIter, DocCommentIter, HasArgList, HasAttrs, HasDocComments, HasGenericArgs,
|
||||||
HasLoopBody, HasModuleItem, HasName, HasTypeBounds, HasVisibility,
|
HasGenericParams, HasLoopBody, HasModuleItem, HasName, HasTypeBounds, HasVisibility,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,14 +149,17 @@ pub trait RangeItem {
|
||||||
mod support {
|
mod support {
|
||||||
use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken};
|
use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> {
|
pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> {
|
||||||
parent.children().find_map(N::cast)
|
parent.children().find_map(N::cast)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> {
|
pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> {
|
||||||
AstChildren::new(parent)
|
AstChildren::new(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {
|
pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {
|
||||||
parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind)
|
parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use parser::{SyntaxKind, T};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
algo::{self, neighbor},
|
algo::{self, neighbor},
|
||||||
ast::{self, edit::IndentLevel, make, HasGenericParams},
|
ast::{self, edit::IndentLevel, make, HasGenericArgs, HasGenericParams},
|
||||||
ted::{self, Position},
|
ted::{self, Position},
|
||||||
AstNode, AstToken, Direction, SyntaxElement,
|
AstNode, AstToken, Direction, SyntaxElement,
|
||||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||||
|
|
|
@ -78,10 +78,10 @@ impl AssocItemList {
|
||||||
pub struct AssocTypeArg {
|
pub struct AssocTypeArg {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
impl ast::HasGenericArgs for AssocTypeArg {}
|
||||||
impl ast::HasTypeBounds for AssocTypeArg {}
|
impl ast::HasTypeBounds for AssocTypeArg {}
|
||||||
impl AssocTypeArg {
|
impl AssocTypeArg {
|
||||||
pub fn const_arg(&self) -> Option<ConstArg> { support::child(&self.syntax) }
|
pub fn const_arg(&self) -> Option<ConstArg> { support::child(&self.syntax) }
|
||||||
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
|
||||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||||
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
|
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
|
||||||
pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
|
pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
|
||||||
|
@ -783,8 +783,8 @@ pub struct MethodCallExpr {
|
||||||
}
|
}
|
||||||
impl ast::HasArgList for MethodCallExpr {}
|
impl ast::HasArgList for MethodCallExpr {}
|
||||||
impl ast::HasAttrs for MethodCallExpr {}
|
impl ast::HasAttrs for MethodCallExpr {}
|
||||||
|
impl ast::HasGenericArgs for MethodCallExpr {}
|
||||||
impl MethodCallExpr {
|
impl MethodCallExpr {
|
||||||
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
|
||||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||||
pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
|
pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
|
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
|
||||||
|
@ -946,8 +946,8 @@ impl PathPat {
|
||||||
pub struct PathSegment {
|
pub struct PathSegment {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
|
impl ast::HasGenericArgs for PathSegment {}
|
||||||
impl PathSegment {
|
impl PathSegment {
|
||||||
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
|
||||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||||
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
|
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
|
||||||
pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
|
pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
|
||||||
|
@ -1763,6 +1763,12 @@ pub struct AnyHasDocComments {
|
||||||
}
|
}
|
||||||
impl ast::HasDocComments for AnyHasDocComments {}
|
impl ast::HasDocComments for AnyHasDocComments {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct AnyHasGenericArgs {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl ast::HasGenericArgs for AnyHasGenericArgs {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct AnyHasGenericParams {
|
pub struct AnyHasGenericParams {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
@ -4235,6 +4241,21 @@ impl AstNode for AnyHasDocComments {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
|
impl AnyHasGenericArgs {
|
||||||
|
#[inline]
|
||||||
|
pub fn new<T: ast::HasGenericArgs>(node: T) -> AnyHasGenericArgs {
|
||||||
|
AnyHasGenericArgs { syntax: node.syntax().clone() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl AstNode for AnyHasGenericArgs {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool {
|
||||||
|
matches!(kind, ASSOC_TYPE_ARG | METHOD_CALL_EXPR | PATH_SEGMENT)
|
||||||
|
}
|
||||||
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
|
Self::can_cast(syntax.kind()).then_some(AnyHasGenericArgs { syntax })
|
||||||
|
}
|
||||||
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
|
}
|
||||||
impl AnyHasGenericParams {
|
impl AnyHasGenericParams {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new<T: ast::HasGenericParams>(node: T) -> AnyHasGenericParams {
|
pub fn new<T: ast::HasGenericParams>(node: T) -> AnyHasGenericParams {
|
||||||
|
|
|
@ -10,7 +10,10 @@ use parser::SyntaxKind;
|
||||||
use rowan::{GreenNodeData, GreenTokenData};
|
use rowan::{GreenNodeData, GreenTokenData};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self, support, AstNode, AstToken, HasAttrs, HasGenericParams, HasName, SyntaxNode},
|
ast::{
|
||||||
|
self, support, AstNode, AstToken, HasAttrs, HasGenericArgs, HasGenericParams, HasName,
|
||||||
|
SyntaxNode,
|
||||||
|
},
|
||||||
ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
|
ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,11 @@ pub trait HasGenericParams: AstNode {
|
||||||
support::child(self.syntax())
|
support::child(self.syntax())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub trait HasGenericArgs: AstNode {
|
||||||
|
fn generic_arg_list(&self) -> Option<ast::GenericArgList> {
|
||||||
|
support::child(self.syntax())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait HasTypeBounds: AstNode {
|
pub trait HasTypeBounds: AstNode {
|
||||||
fn type_bound_list(&self) -> Option<ast::TypeBoundList> {
|
fn type_bound_list(&self) -> Option<ast::TypeBoundList> {
|
||||||
|
|
|
@ -797,20 +797,21 @@ fn extract_enums(ast: &mut AstSrc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_struct_traits(ast: &mut AstSrc) {
|
const TRAITS: &[(&str, &[&str])] = &[
|
||||||
let traits: &[(&str, &[&str])] = &[
|
("HasAttrs", &["attrs"]),
|
||||||
("HasAttrs", &["attrs"]),
|
("HasName", &["name"]),
|
||||||
("HasName", &["name"]),
|
("HasVisibility", &["visibility"]),
|
||||||
("HasVisibility", &["visibility"]),
|
("HasGenericParams", &["generic_param_list", "where_clause"]),
|
||||||
("HasGenericParams", &["generic_param_list", "where_clause"]),
|
("HasGenericArgs", &["generic_arg_list"]),
|
||||||
("HasTypeBounds", &["type_bound_list", "colon_token"]),
|
("HasTypeBounds", &["type_bound_list", "colon_token"]),
|
||||||
("HasModuleItem", &["items"]),
|
("HasModuleItem", &["items"]),
|
||||||
("HasLoopBody", &["label", "loop_body"]),
|
("HasLoopBody", &["label", "loop_body"]),
|
||||||
("HasArgList", &["arg_list"]),
|
("HasArgList", &["arg_list"]),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
fn extract_struct_traits(ast: &mut AstSrc) {
|
||||||
for node in &mut ast.nodes {
|
for node in &mut ast.nodes {
|
||||||
for (name, methods) in traits {
|
for (name, methods) in TRAITS {
|
||||||
extract_struct_trait(node, name, methods);
|
extract_struct_trait(node, name, methods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue