Skip to content

feat: complete turbofish when fn can't infer param - #23473

Merged
A4-Tacks merged 5 commits into
rust-lang:masterfrom
A4-Tacks:comp-fn-turbofish
Oct 5, 2026
Merged

A4-Tacks merged 5 commits into
rust-lang:masterfrom
A4-Tacks:comp-fn-turbofish

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Oct 4, 2026

Copy link
Copy Markdown
Member

Calculate simple cases to avoid performance waste as much as possible

Example

fn main() {
    size_of$0
}

Before this PR

fn main() {
    size_of()
}

After this PR

fn main() {
    size_of::<$1>()
}

Example
---
```rust
fn main() {
    size_of$0
}
```

**Before this PR**

```rust
fn main() {
    size_of()
}
```

**After this PR**

```rust
fn main() {
    size_of::<$1>()
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is really cool but I think there should be a config for that.

View changes since this review


if let Some((cap, (self_param, params))) = complete_call_parens {
let with_type_param = || {
let gen_params = hir::GenericDef::Function(func).type_or_const_params(db);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accounts for impl Traits which cannot be turbofished.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's no problem, because params.is_empty()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, right, but then why only when there are no params?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It's very simple, otherwise it's complex
  2. If the params is not empty, it is difficult to predict whether the user wants to complete generics or params first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it'll have to check if the parameters contain the generic params. Which is possible but harder.

(2) isn't really a problem IMO, any order will be good.

@A4-Tacks

A4-Tacks commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

The idea is really cool but I think there should be a config for that.

Currently, the implementation covers unambiguous cases, perhaps without the need for config?

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Oct 5, 2026
@ChayimFriedman2
ChayimFriedman2 removed this pull request from the merge queue due to a manual request Oct 5, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Currently, the implementation covers unambiguous cases, perhaps without the need for config?

People don't like it when we mess with what they're used to. I believe every major change to IDE feature requires config.

@ChayimFriedman2 ChayimFriedman2 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo then LGTM.

View changes since this review

Comment thread crates/rust-analyzer/src/config.rs Outdated
/// Term search fuel in "units of work" for autocompletion (Defaults to 1000).
completion_termSearch_fuel: usize = 1000,

/// Complete turbofish (`::<>`) at the call site (if needs).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Complete turbofish (`::<>`) at the call site (if needs).
/// Complete turbofish (`::<>`) at the call site (if needed).

@A4-Tacks
A4-Tacks enabled auto-merge October 5, 2026 16:24
@A4-Tacks
A4-Tacks added this pull request to the merge queue Oct 5, 2026
Merged via the queue into rust-lang:master with commit f28b8c8 Oct 5, 2026
21 checks passed
@A4-Tacks
A4-Tacks deleted the comp-fn-turbofish branch October 5, 2026 16:39
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants