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_assists/src/handlers/add_explicit_type.rs | 16 ++++++++-------- crates/ra_assists/src/handlers/generate_new.rs | 9 ++------- .../ra_assists/src/handlers/introduce_named_lifetime.rs | 4 ++-- 3 files changed, 12 insertions(+), 17 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index 39a5321d1..e69f0a89b 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs @@ -1,6 +1,6 @@ use hir::HirDisplay; use ra_syntax::{ - ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, + ast::{self, AstNode, LetStmt, NameOwner}, TextRange, }; @@ -22,11 +22,11 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // ``` pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let stmt = ctx.find_node_at_offset::()?; - let module = ctx.sema.scope(stmt.syntax()).module()?; - let expr = stmt.initializer()?; + let let_stmt = ctx.find_node_at_offset::()?; + let module = ctx.sema.scope(let_stmt.syntax()).module()?; + let expr = let_stmt.initializer()?; // Must be a binding - let pat = match stmt.pat()? { + let pat = match let_stmt.pat()? { ast::Pat::BindPat(bind_pat) => bind_pat, _ => return None, }; @@ -34,8 +34,8 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio // The binding must have a name let name = pat.name()?; let name_range = name.syntax().text_range(); - let stmt_range = stmt.syntax().text_range(); - let eq_range = stmt.eq_token()?.text_range(); + let stmt_range = let_stmt.syntax().text_range(); + let eq_range = let_stmt.eq_token()?.text_range(); // Assist should only be applicable if cursor is between 'let' and '=' let let_range = TextRange::new(stmt_range.start(), eq_range.start()); let cursor_in_range = let_range.contains_range(ctx.frange.range); @@ -44,7 +44,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio } // Assist not applicable if the type has already been specified // and it has no placeholders - let ascribed_ty = stmt.ascribed_type(); + let ascribed_ty = let_stmt.ty(); if let Some(ty) = &ascribed_ty { if ty.syntax().descendants().find_map(ast::PlaceholderType::cast).is_none() { return None; diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index 3c67749ee..b84aa24b6 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -1,9 +1,6 @@ use hir::Adt; use ra_syntax::{ - ast::{ - self, AstNode, GenericParamsOwner, NameOwner, StructKind, TypeAscriptionOwner, - VisibilityOwner, - }, + ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, T, }; use stdx::{format_to, SepBy}; @@ -54,9 +51,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let params = field_list .fields() - .filter_map(|f| { - Some(format!("{}: {}", f.name()?.syntax(), f.ascribed_type()?.syntax())) - }) + .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) .sep_by(", "); let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 92a1a5925..c3134f64d 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, + ast::{self, GenericParamsOwner, NameOwner}, AstNode, SyntaxKind, TextRange, TextSize, }; use rustc_hash::FxHashSet; @@ -67,7 +67,7 @@ fn generate_fn_def_assist( // otherwise, if there's a single reference parameter without a named liftime, use that let fn_params_without_lifetime: Vec<_> = param_list .params() - .filter_map(|param| match param.ascribed_type() { + .filter_map(|param| match param.ty() { Some(ast::TypeRef::ReferenceType(ascribed_type)) if ascribed_type.lifetime_token() == None => { -- cgit v1.2.3