From e0c7ce8417d9c6b5b7aaa0a3337d8872ce9ea7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 29 Jan 2020 22:34:52 +0200 Subject: Allow add_explicit_type to replace a placeholder type --- crates/ra_assists/src/assists/add_explicit_type.rs | 54 +++++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index 38a351a54..2443d5541 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs @@ -1,7 +1,7 @@ use hir::{db::HirDatabase, HirDisplay}; use ra_syntax::{ - ast::{self, AstNode, LetStmt, NameOwner}, - TextRange, T, + ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, + TextRange, }; use crate::{Assist, AssistCtx, AssistId}; @@ -34,17 +34,21 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option: _ = 1; }", + "fn f() { let a<|>: i32 = 1; }", + ); + } + + #[test] + fn add_explicit_type_works_for_nested_underscore() { + check_assist( + add_explicit_type, + r#" + enum Option { + Some(T), + None + } + + fn f() { + let a<|>: Option<_> = Option::Some(1); + }"#, + r#" + enum Option { + Some(T), + None + } + + fn f() { + let a<|>: Option = Option::Some(1); + }"#, + ); + } + #[test] fn add_explicit_type_works_for_macro_call() { check_assist( -- cgit v1.2.3