Skip to content

feat: Implement thin-arrow completion in fn return position#21012

Merged
ChayimFriedman2 merged 4 commits intorust-lang:masterfrom
A4-Tacks:comp-ret-type-arrow
Apr 6, 2026
Merged

feat: Implement thin-arrow completion in fn return position#21012
ChayimFriedman2 merged 4 commits intorust-lang:masterfrom
A4-Tacks:comp-ret-type-arrow

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented Nov 10, 2025

Very cool feature that can quickly complete simple return types

Close #20885

Example

fn foo() u$0

Before this PR

kw where

After this PR

bt u32 (adds ->) u32
kw where
...
fn foo() -> u32

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 10, 2025
@A4-Tacks A4-Tacks force-pushed the comp-ret-type-arrow branch from 75387d9 to e7bc867 Compare November 10, 2025 13:24
@A4-Tacks A4-Tacks mentioned this pull request Nov 19, 2025
41 tasks
@A4-Tacks
Copy link
Copy Markdown
Member Author

r? @ChayimFriedman2

Comment thread crates/ide-completion/src/context.rs Outdated
Comment on lines +121 to +127
match ret_type.ty() {
Some(ast::Type::PathType(path_ty)) => {
path_ty.path().is_some_and(|path| path.as_single_name_ref().is_some())
}
Some(_) => false,
None => true,
}
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.

Why is this? Is there a problem completing an arrow on e.g. fn foo() bar::baz| {}?

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.

Usually, arrows are completed when input bar

Moreover, when completing foo::bar, the range is bar instead of foo::bar, so adding arrows before requires TextEdit, which is a bit troublesome

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.

You can add the arrow after the ).

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.

So this requires TextEdit, but using TextEdit seems to be a good solution as well

fn x() u$0
"#,
expect![[r#"
en Enum Enum
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.

IMO we should visibly render the -> in the label.

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.

This is difficult to complete, the editor needs to make the matching skip the arrow

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.

Did you mean to comment on my other comment?

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.

No

fo
foo
^^

Better than this:

fo
-> foo
   ^^

Some editors do not even support such completion

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 label can be whatever we want.

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.

But the editor will use the current input to match the label, and the strange prefix makes it difficult to match

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.

CompletionItem::lookup can control the filtering.

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.

Another question, if the label has an arrow, it can sometimes be strange:

mod foo {}
fn bar() foo::bar$0 {}

Outputs label -> bar, but complete bar, this is a bit counterintuitive

Perhaps you can refer to auto import, outputs label bar(adds ->)

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, that's better.

@A4-Tacks A4-Tacks changed the title Implement thin-arrow completion in fn return position feat: Implement thin-arrow completion in fn return position Apr 6, 2026
A4-Tacks added 4 commits April 6, 2026 19:05
Very cool feature that can quickly complete simple return types

Example
---
```rust
fn foo() u$0
```

**Before this PR**

```text
kw where
```

**After this PR**

```text
bt u32 (adds ->) u32
kw where
...
```

```rust
fn foo() -> u32
```
@A4-Tacks A4-Tacks force-pushed the comp-ret-type-arrow branch from fdc2bee to 1569397 Compare April 6, 2026 11:08
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 6, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@A4-Tacks A4-Tacks requested a review from ChayimFriedman2 April 6, 2026 11:23
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 6, 2026
Merged via the queue into rust-lang:master with commit 09ae159 Apr 6, 2026
17 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2026
@A4-Tacks A4-Tacks deleted the comp-ret-type-arrow branch April 7, 2026 06:33
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.

Complete thin-arrow on function return position

3 participants