Skip to content

Commit 3927b5a

Browse files
authored
Merge pull request #23493 from A4-Tacks/no-lifetime-turbofish
fix: assist do not add lifetime only turbofish
2 parents fbb8e34 + 4a626a8 commit 3927b5a

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_turbo_fish.rs‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_, '_>) ->
7878
Definition::Function(it) => it,
7979
_ => return None,
8080
};
81-
let generics = hir::GenericDef::Function(fun).params(ctx.sema.db);
81+
let generics = hir::GenericDef::Function(fun)
82+
.params(ctx.sema.db)
83+
.into_iter()
84+
.filter(|param| {
85+
matches!(param, hir::GenericParam::TypeParam(_) | hir::GenericParam::ConstParam(_))
86+
})
87+
.collect::<Vec<_>>();
8288
if generics.is_empty() {
8389
cov_mark::hit!(add_turbo_fish_non_generic);
8490
return None;
@@ -128,13 +134,6 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_, '_>) ->
128134
}
129135
}
130136

131-
let number_of_arguments = generics
132-
.iter()
133-
.filter(|param| {
134-
matches!(param, hir::GenericParam::TypeParam(_) | hir::GenericParam::ConstParam(_))
135-
})
136-
.count();
137-
138137
acc.add(
139138
AssistId::refactor_rewrite("add_turbo_fish"),
140139
"Add `::<>`",
@@ -146,7 +145,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_, '_>) ->
146145
Either::Right(it) => builder.make_editor(it.syntax()),
147146
};
148147

149-
let fish_head = get_fish_head(editor.make(), number_of_arguments);
148+
let fish_head = get_fish_head(editor.make(), generics.len());
150149

151150
match turbofish_target {
152151
Either::Left(path_segment) => {
@@ -316,14 +315,23 @@ fn main() {
316315

317316
#[test]
318317
fn add_turbo_fish_non_generic() {
319-
cov_mark::check!(add_turbo_fish_non_generic);
318+
cov_mark::check_count!(add_turbo_fish_non_generic, 2);
320319
check_assist_not_applicable(
321320
add_turbo_fish,
322321
r#"
323322
fn make() -> () {}
324323
fn main() {
325324
make$0();
326325
}
326+
"#,
327+
);
328+
check_assist_not_applicable(
329+
add_turbo_fish,
330+
r#"
331+
fn make<'a>() {}
332+
fn main() {
333+
make$0();
334+
}
327335
"#,
328336
);
329337
}

0 commit comments

Comments
 (0)