diff options
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs b/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs index 999aec421..0fdbc63dd 100644 --- a/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs +++ b/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs | |||
@@ -1,8 +1,11 @@ | |||
1 | use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists}; | 1 | use ra_syntax::{ |
2 | use ast::{NameOwner, ParamList, TypeAscriptionOwner, TypeParamList, TypeRef}; | 2 | ast::{self, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, |
3 | use ra_syntax::{ast, ast::TypeParamsOwner, AstNode, SyntaxKind, TextRange, TextSize}; | 3 | AstNode, SyntaxKind, TextRange, TextSize, |
4 | }; | ||
4 | use rustc_hash::FxHashSet; | 5 | use rustc_hash::FxHashSet; |
5 | 6 | ||
7 | use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists}; | ||
8 | |||
6 | static ASSIST_NAME: &str = "change_lifetime_anon_to_named"; | 9 | static ASSIST_NAME: &str = "change_lifetime_anon_to_named"; |
7 | static ASSIST_LABEL: &str = "Give anonymous lifetime a name"; | 10 | static ASSIST_LABEL: &str = "Give anonymous lifetime a name"; |
8 | 11 | ||
@@ -52,7 +55,7 @@ fn generate_fn_def_assist( | |||
52 | fn_def: &ast::FnDef, | 55 | fn_def: &ast::FnDef, |
53 | lifetime_loc: TextRange, | 56 | lifetime_loc: TextRange, |
54 | ) -> Option<()> { | 57 | ) -> Option<()> { |
55 | let param_list: ParamList = fn_def.param_list()?; | 58 | let param_list: ast::ParamList = fn_def.param_list()?; |
56 | let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?; | 59 | let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?; |
57 | let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end(); | 60 | let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end(); |
58 | let self_param = | 61 | let self_param = |
@@ -67,7 +70,7 @@ fn generate_fn_def_assist( | |||
67 | let fn_params_without_lifetime: Vec<_> = param_list | 70 | let fn_params_without_lifetime: Vec<_> = param_list |
68 | .params() | 71 | .params() |
69 | .filter_map(|param| match param.ascribed_type() { | 72 | .filter_map(|param| match param.ascribed_type() { |
70 | Some(TypeRef::ReferenceType(ascribed_type)) | 73 | Some(ast::TypeRef::ReferenceType(ascribed_type)) |
71 | if ascribed_type.lifetime_token() == None => | 74 | if ascribed_type.lifetime_token() == None => |
72 | { | 75 | { |
73 | Some(ascribed_type.amp_token()?.text_range().end()) | 76 | Some(ascribed_type.amp_token()?.text_range().end()) |
@@ -106,7 +109,7 @@ fn generate_impl_def_assist( | |||
106 | /// Given a type parameter list, generate a unique lifetime parameter name | 109 | /// Given a type parameter list, generate a unique lifetime parameter name |
107 | /// which is not in the list | 110 | /// which is not in the list |
108 | fn generate_unique_lifetime_param_name( | 111 | fn generate_unique_lifetime_param_name( |
109 | existing_type_param_list: &Option<TypeParamList>, | 112 | existing_type_param_list: &Option<ast::TypeParamList>, |
110 | ) -> Option<char> { | 113 | ) -> Option<char> { |
111 | match existing_type_param_list { | 114 | match existing_type_param_list { |
112 | Some(type_params) => { | 115 | Some(type_params) => { |