Skip to content

Detect existing turbofish on method calls to suppress useless suggestion#153751

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
arferreira:fix-useless-e0284-suggestion
Mar 12, 2026
Merged

Detect existing turbofish on method calls to suppress useless suggestion#153751
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
arferreira:fix-useless-e0284-suggestion

Conversation

@arferreira
Copy link
Contributor

@arferreira arferreira commented Mar 12, 2026

expr_inferred_arg_iter hardcoded have_turbofish: false for MethodCall expressions, while the Path case properly checked for existing type arguments via segment.args. This meant the "consider specifying the generic arguments" suggestion always fired on method calls, even when the user already had a turbofish, producing a suggestion that just rewrote user syntax into fully qualified form without resolving anything.

Fixes #153732.

cc @eggyal

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2026

Some changes occurred in need_type_info.rs

cc @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@eggyal eggyal left a comment

Choose a reason for hiding this comment

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

With the failing test blessed, I think this is fine.

However, it would be even nicer if, when a turbofish is already present, the diagnostic pointed at the uninferred generic within it...

View changes since this review

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

I think we should change the diagnostics to instead consider the individual generic args if they are explicitly provided and point at them, but that's for a separate PR

View changes since this review

@lcnr
Copy link
Contributor

lcnr commented Mar 12, 2026

r=me after CI

@bors delegate+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 12, 2026

✌️ @arferreira, you can now approve this pull request!

If @lcnr told you to "r=me" after making some further change, then please make that change and post @bors r=lcnr.

@lcnr
Copy link
Contributor

lcnr commented Mar 12, 2026

r? lcnr

@rustbot rustbot assigned lcnr and unassigned chenyukang Mar 12, 2026
@arferreira
Copy link
Contributor Author

@bors r=lcnr

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 12, 2026

📌 Commit 6e954d3 has been approved by lcnr

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 12, 2026
--> $DIR/useless-turbofish-suggestion.rs:19:7
|
LL | S.f::<u32, _>(42);
| ^ cannot infer type of the type parameter `B` declared on the method `f`

This comment was marked as duplicate.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 12, 2026
…stion, r=lcnr

Detect existing turbofish on method calls to suppress useless suggestion

`expr_inferred_arg_iter` hardcoded `have_turbofish: false` for `MethodCall` expressions, while the `Path` case properly checked for existing type arguments via `segment.args`. This meant the "consider specifying the generic arguments" suggestion always fired on method calls, even when the user already had a turbofish, producing a suggestion that just rewrote user syntax into fully qualified form without resolving anything.

Fixes rust-lang#153732.

cc @eggyal
rust-bors bot pushed a commit that referenced this pull request Mar 12, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #153751 (Detect existing turbofish on method calls to suppress useless suggestion)
 - #153780 (Remove `MTLock`)
 - #151194 (Fix wrong suggestion for returning async closure)
 - #151572 (Fix Hexagon ABI calling convention for small aggregates)
 - #153725 (Fix that `./x test --no-doc` actually keeps the same behaviour for backwards compatability)
rust-bors bot pushed a commit that referenced this pull request Mar 12, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #153705 (Always generate generics in delegation that match trait in trait impl scenario)
 - #153751 (Detect existing turbofish on method calls to suppress useless suggestion)
 - #153780 (Remove `MTLock`)
 - #151572 (Fix Hexagon ABI calling convention for small aggregates)
 - #153725 (Fix that `./x test --no-doc` actually keeps the same behaviour for backwards compatability)
@rust-bors rust-bors bot merged commit e52df29 into rust-lang:main Mar 12, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 12, 2026
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Mar 16, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#153705 (Always generate generics in delegation that match trait in trait impl scenario)
 - rust-lang/rust#153751 (Detect existing turbofish on method calls to suppress useless suggestion)
 - rust-lang/rust#153780 (Remove `MTLock`)
 - rust-lang/rust#151572 (Fix Hexagon ABI calling convention for small aggregates)
 - rust-lang/rust#153725 (Fix that `./x test --no-doc` actually keeps the same behaviour for backwards compatability)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 17, 2026
…ent, r=Kivooeo,eggyal

Point turbofish inference errors at the uninferred generic arg

Follow-up to rust-lang#153751.

When a method call has a turbofish with an uninferred generic argument, point the diagnostic span at the specific `_` that couldn't be inferred instead of the method name.

Before:
```rust
LL |     S.f::<u32, _>(42);
   |       ^ cannot infer type of the type parameter `B`
```

After:
```rust
LL |     S.f::<u32, _>(42);
   |                ^ cannot infer type of the type parameter `B`
```

Path expressions (`None::<_>`, `foo::<_>()`) are not handled yet, that's a separate code path.

cc @eggyal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E0284] suggestion is useless

7 participants