mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Cleanup imports
This commit is contained in:
parent
7ae247f03c
commit
d08232b10d
1 changed files with 9 additions and 6 deletions
|
@ -1,8 +1,11 @@
|
||||||
use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists};
|
use ra_syntax::{
|
||||||
use ast::{NameOwner, ParamList, TypeAscriptionOwner, TypeParamList, TypeRef};
|
ast::{self, NameOwner, TypeAscriptionOwner, TypeParamsOwner},
|
||||||
use ra_syntax::{ast, ast::TypeParamsOwner, AstNode, SyntaxKind, TextRange, TextSize};
|
AstNode, SyntaxKind, TextRange, TextSize,
|
||||||
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
|
use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists};
|
||||||
|
|
||||||
static ASSIST_NAME: &str = "change_lifetime_anon_to_named";
|
static ASSIST_NAME: &str = "change_lifetime_anon_to_named";
|
||||||
static ASSIST_LABEL: &str = "Give anonymous lifetime a name";
|
static ASSIST_LABEL: &str = "Give anonymous lifetime a name";
|
||||||
|
|
||||||
|
@ -52,7 +55,7 @@ fn generate_fn_def_assist(
|
||||||
fn_def: &ast::FnDef,
|
fn_def: &ast::FnDef,
|
||||||
lifetime_loc: TextRange,
|
lifetime_loc: TextRange,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let param_list: ParamList = fn_def.param_list()?;
|
let param_list: ast::ParamList = fn_def.param_list()?;
|
||||||
let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?;
|
let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?;
|
||||||
let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end();
|
let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end();
|
||||||
let self_param =
|
let self_param =
|
||||||
|
@ -67,7 +70,7 @@ fn generate_fn_def_assist(
|
||||||
let fn_params_without_lifetime: Vec<_> = param_list
|
let fn_params_without_lifetime: Vec<_> = param_list
|
||||||
.params()
|
.params()
|
||||||
.filter_map(|param| match param.ascribed_type() {
|
.filter_map(|param| match param.ascribed_type() {
|
||||||
Some(TypeRef::ReferenceType(ascribed_type))
|
Some(ast::TypeRef::ReferenceType(ascribed_type))
|
||||||
if ascribed_type.lifetime_token() == None =>
|
if ascribed_type.lifetime_token() == None =>
|
||||||
{
|
{
|
||||||
Some(ascribed_type.amp_token()?.text_range().end())
|
Some(ascribed_type.amp_token()?.text_range().end())
|
||||||
|
@ -106,7 +109,7 @@ fn generate_impl_def_assist(
|
||||||
/// Given a type parameter list, generate a unique lifetime parameter name
|
/// Given a type parameter list, generate a unique lifetime parameter name
|
||||||
/// which is not in the list
|
/// which is not in the list
|
||||||
fn generate_unique_lifetime_param_name(
|
fn generate_unique_lifetime_param_name(
|
||||||
existing_type_param_list: &Option<TypeParamList>,
|
existing_type_param_list: &Option<ast::TypeParamList>,
|
||||||
) -> Option<char> {
|
) -> Option<char> {
|
||||||
match existing_type_param_list {
|
match existing_type_param_list {
|
||||||
Some(type_params) => {
|
Some(type_params) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue