Skip to content

Do not suggest borrowing enclosing calls for nested where-clause obligations#155219

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
nataliakokoromyti:fix-155088-borrow-suggestion-v2
Apr 24, 2026
Merged

Do not suggest borrowing enclosing calls for nested where-clause obligations#155219
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
nataliakokoromyti:fix-155088-borrow-suggestion-v2

Conversation

@nataliakokoromyti
Copy link
Copy Markdown
Contributor

@nataliakokoromyti nataliakokoromyti commented Apr 13, 2026

In #155088, the compiler was blaming the whole call expr instead of the value that actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type, and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix #155088

@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 Apr 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
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, types
  • compiler, types expanded to 69 candidates
  • Random selection from 12 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JohnTitor
Copy link
Copy Markdown
Member

Could you squash commits into one and reword the PR title & commit message more descriptive, like Do not suggest borrowing enclosing calls for nested where-clause obligations? Otherwise LGTM

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 18, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@nataliakokoromyti nataliakokoromyti force-pushed the fix-155088-borrow-suggestion-v2 branch from 98950d8 to 9064d17 Compare April 18, 2026 17:51
@nataliakokoromyti nataliakokoromyti changed the title Fix 155088 borrow suggestion v2 Do not suggest borrowing enclosing calls for nested where-clause obligations Apr 18, 2026
Copy link
Copy Markdown
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

Thank you! @bors r+ rollup

View changes since this review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 24, 2026

📌 Commit 9064d17 has been approved by JohnTitor

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 24, 2026
…w-suggestion-v2, r=JohnTitor

Do not suggest borrowing enclosing calls for nested where-clause obligations

In rust-lang#155088, the compiler was blaming the whole call expr instead of the value that  actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type,  and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix rust-lang#155088
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 24, 2026
…w-suggestion-v2, r=JohnTitor

Do not suggest borrowing enclosing calls for nested where-clause obligations

In rust-lang#155088, the compiler was blaming the whole call expr instead of the value that  actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type,  and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix rust-lang#155088
rust-bors Bot pushed a commit that referenced this pull request Apr 24, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #149452 (Refactor out common code into a `IndexItem::new` constructor)
 - #155621 (Document #[diagnostic::on_move] in the unstable book.)
 - #155635 (delegation: rename `Self` generic param to `This` in recursive delegations)
 - #155730 (Some cleanups around per parent disambiguators)
 - #153537 (rustc_codegen_ssa: Define ELF flag value for sparc-unknown-linux-gnu)
 - #155219 (Do not suggest borrowing enclosing calls for nested where-clause obligations)
 - #155408 (rustdoc: Fix Managarm C Library name in cfg pretty printer)
 - #155571 (Enable AddressSanitizer on arm-unknown-linux-gnueabihf and armv7-unknown-linux-gnueabihf)
 - #155713 (test: Add a regression test for Apple platforms aborting on `free`)
 - #155723 (Fix tier level for 5 thumb bare-metal ARM targets)
 - #155735 (Fix typo by removing extra 'to')
 - #155736 (Remove `AllVariants` workaround for rust-analyzer)
rust-bors Bot pushed a commit that referenced this pull request Apr 24, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #149452 (Refactor out common code into a `IndexItem::new` constructor)
 - #155621 (Document #[diagnostic::on_move] in the unstable book.)
 - #155635 (delegation: rename `Self` generic param to `This` in recursive delegations)
 - #155730 (Some cleanups around per parent disambiguators)
 - #153537 (rustc_codegen_ssa: Define ELF flag value for sparc-unknown-linux-gnu)
 - #155219 (Do not suggest borrowing enclosing calls for nested where-clause obligations)
 - #155408 (rustdoc: Fix Managarm C Library name in cfg pretty printer)
 - #155571 (Enable AddressSanitizer on arm-unknown-linux-gnueabihf and armv7-unknown-linux-gnueabihf)
 - #155713 (test: Add a regression test for Apple platforms aborting on `free`)
 - #155723 (Fix tier level for 5 thumb bare-metal ARM targets)
 - #155735 (Fix typo by removing extra 'to')
 - #155736 (Remove `AllVariants` workaround for rust-analyzer)
@rust-bors rust-bors Bot merged commit a51a163 into rust-lang:main Apr 24, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 24, 2026
rust-timer added a commit that referenced this pull request Apr 24, 2026
Rollup merge of #155219 - nataliakokoromyti:fix-155088-borrow-suggestion-v2, r=JohnTitor

Do not suggest borrowing enclosing calls for nested where-clause obligations

In #155088, the compiler was blaming the whole call expr instead of the value that  actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type,  and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix #155088
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.

Wrong "consider borrowing here" suggestion with impl IntoIterator<Item = impl Borrow<str>>

4 participants