From 2e2642efccd5855e4158b01a006e7884a96982bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:51:43 +0200 Subject: Remove TypeAscriptionOwner --- crates/ra_ide/src/display/short_label.rs | 14 +++++++------- crates/ra_ide/src/file_structure.rs | 28 +++++++++------------------- crates/ra_ide/src/inlay_hints.rs | 6 +++--- crates/ra_ide/src/references/rename.rs | 5 +++-- 4 files changed, 22 insertions(+), 31 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index c600908a4..bddf1bd47 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; +use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use stdx::format_to; pub(crate) trait ShortLabel { @@ -55,19 +55,19 @@ impl ShortLabel for ast::TypeAlias { impl ShortLabel for ast::Const { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "const ") + short_label_from_ty(self, self.ty(), "const ") } } impl ShortLabel for ast::Static { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "static ") + short_label_from_ty(self, self.ty(), "static ") } } impl ShortLabel for ast::RecordField { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "") + short_label_from_ty(self, self.ty(), "") } } @@ -77,13 +77,13 @@ impl ShortLabel for ast::Variant { } } -fn short_label_from_ascribed_node(node: &T, prefix: &str) -> Option +fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option where - T: NameOwner + VisibilityOwner + TypeAscriptionOwner, + T: NameOwner + VisibilityOwner, { let mut buf = short_label_from_node(node, prefix)?; - if let Some(type_ref) = node.ascribed_type() { + if let Some(type_ref) = ty { format_to!(buf, ": {}", type_ref.syntax()); } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 7d378f2d0..22cf8637a 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, AttrsOwner, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, + ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, }; @@ -52,18 +52,11 @@ pub fn file_structure(file: &SourceFile) -> Vec { fn structure_node(node: &SyntaxNode) -> Option { fn decl(node: N) -> Option { - decl_with_detail(node, None) - } - - fn decl_with_ascription( - node: N, - ) -> Option { - let ty = node.ascribed_type(); - decl_with_type_ref(node, ty) + decl_with_detail(&node, None) } fn decl_with_type_ref( - node: N, + node: &N, type_ref: Option, ) -> Option { let detail = type_ref.map(|type_ref| { @@ -75,7 +68,7 @@ fn structure_node(node: &SyntaxNode) -> Option { } fn decl_with_detail( - node: N, + node: &N, detail: Option, ) -> Option { let name = node.name()?; @@ -124,7 +117,7 @@ fn structure_node(node: &SyntaxNode) -> Option { collapse_ws(ret_type.syntax(), &mut detail); } - decl_with_detail(it, Some(detail)) + decl_with_detail(&it, Some(detail)) }, ast::Struct(it) => decl(it), ast::Union(it) => decl(it), @@ -132,13 +125,10 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Variant(it) => decl(it), ast::Trait(it) => decl(it), ast::Module(it) => decl(it), - ast::TypeAlias(it) => { - let ty = it.type_ref(); - decl_with_type_ref(it, ty) - }, - ast::RecordField(it) => decl_with_ascription(it), - ast::Const(it) => decl_with_ascription(it), - ast::Static(it) => decl_with_ascription(it), + ast::TypeAlias(it) => decl_with_type_ref(&it, it.type_ref()), + ast::RecordField(it) => decl_with_type_ref(&it, it.ty()), + ast::Const(it) => decl_with_type_ref(&it, it.ty()), + ast::Static(it) => decl_with_type_ref(&it, it.ty()), ast::Impl(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 714ba6bd9..4bbbcd258 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -2,7 +2,7 @@ use hir::{Adt, Callable, HirDisplay, Semantics, Type}; use ra_ide_db::RootDatabase; use ra_prof::profile; use ra_syntax::{ - ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, + ast::{self, ArgListOwner, AstNode}, match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, }; use stdx::to_lower_snake_case; @@ -230,10 +230,10 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ match_ast! { match node { ast::LetStmt(it) => { - return it.ascribed_type().is_some() + return it.ty().is_some() }, ast::Param(it) => { - return it.ascribed_type().is_some() + return it.ty().is_some() }, ast::MatchArm(_it) => { return pat_is_enum_variant(db, bind_pat, pat_ty); diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index d330109f1..31654bf79 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -7,7 +7,8 @@ use ra_ide_db::{ RootDatabase, }; use ra_syntax::{ - algo::find_node_at_offset, ast, ast::NameOwner, ast::TypeAscriptionOwner, + algo::find_node_at_offset, + ast::{self, NameOwner}, lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, }; use ra_text_edit::TextEdit; @@ -155,7 +156,7 @@ fn rename_to_self( return None; // method already has self param } let first_param = params.params().next()?; - let mutable = match first_param.ascribed_type() { + let mutable = match first_param.ty() { Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(), _ => return None, // not renaming other types }; -- cgit v1.2.3