mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Use TypeAscriptionOwner
This replaces places where we would use node + node.type_ref() with things that have an ascribed type, with using the TypeAscriptionOwner as the trait bound so we can simply pass the node.
This commit is contained in:
parent
6eb070d661
commit
52054e1140
2 changed files with 15 additions and 12 deletions
|
@ -2,7 +2,7 @@ use crate::TextRange;
|
|||
|
||||
use ra_syntax::{
|
||||
algo::visit::{visitor, Visitor},
|
||||
ast::{self, AttrsOwner, NameOwner, TypeParamsOwner},
|
||||
ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner},
|
||||
AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,12 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
|
|||
decl_with_detail(node, None)
|
||||
}
|
||||
|
||||
fn decl_with_ascription<N: NameOwner + AttrsOwner + TypeAscriptionOwner>(
|
||||
node: &N,
|
||||
) -> Option<StructureNode> {
|
||||
decl_with_type_ref(node, node.ascribed_type())
|
||||
}
|
||||
|
||||
fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
|
||||
node: &N,
|
||||
type_ref: Option<&ast::TypeRef>,
|
||||
|
@ -107,14 +113,14 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
|
|||
decl_with_detail(fn_def, Some(detail))
|
||||
})
|
||||
.visit(decl::<ast::StructDef>)
|
||||
.visit(|nfd: &ast::NamedFieldDef| decl_with_type_ref(nfd, nfd.type_ref()))
|
||||
.visit(decl::<ast::EnumDef>)
|
||||
.visit(decl::<ast::EnumVariant>)
|
||||
.visit(decl::<ast::TraitDef>)
|
||||
.visit(decl::<ast::Module>)
|
||||
.visit(|td: &ast::TypeAliasDef| decl_with_type_ref(td, td.type_ref()))
|
||||
.visit(|cd: &ast::ConstDef| decl_with_type_ref(cd, cd.type_ref()))
|
||||
.visit(|sd: &ast::StaticDef| decl_with_type_ref(sd, sd.type_ref()))
|
||||
.visit(decl_with_ascription::<ast::NamedFieldDef>)
|
||||
.visit(decl_with_ascription::<ast::ConstDef>)
|
||||
.visit(decl_with_ascription::<ast::StaticDef>)
|
||||
.visit(|im: &ast::ImplBlock| {
|
||||
let target_type = im.target_type()?;
|
||||
let target_trait = im.target_trait();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue