Skip to content

keep the use<..> bound in the refining_impl_trait suggestion - #162575

Open
Albab-Hasan wants to merge 1 commit into
rust-lang:mainfrom
Albab-Hasan:refine-suggestion-precise-capturing
Open

Albab-Hasan wants to merge 1 commit into
rust-lang:mainfrom
Albab-Hasan:refine-suggestion-precise-capturing

Conversation

@Albab-Hasan

@Albab-Hasan Albab-Hasan commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

the suggestion formats the traits RPITIT and Display doesnt print use<..> so impl use<Self> + Send renders as impl std::marker::Send. applying it makes the impl capture the elided &self lifetime which doesnt compile. new helper re emits the capture list when the trait dropped a lifetime.

one note. no existing baselines were re blessed so the new test is the only in tree coverage of an undercapturing RPITIT.

fixes #141047

r? @davidtwco

@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 Sep 10, 2026

@davidtwco davidtwco left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM w/ comments applied

View changes since this review

Comment thread compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs Outdated

// An `async fn` suggestion replaces the desugared `Future` output rather than an opaque, so
// there is no `use<..>` bound to carry over.
let mut precise_capturing = None;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

precise_capturing is an unintuitive name for this variable - perhaps maybe_use_bounds_for_impl

@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 Sep 23, 2026
@rustbot

rustbot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

the lint suggested a return type built only from the trait bounds, so the precise capturing list was dropped. applying the suggestion then captured every lifetime in scope and failed to compile with "return type captures more lifetimes than trait definition".

the suggestion now carries the capture list over, written in terms of the impl generics. a use<..> bound is only added when the trait opaque leaves out one of the method late bound lifetimes, since everything else already has to be listed in the trait.

fixes rust-lang#141047
@Albab-Hasan
Albab-Hasan force-pushed the refine-suggestion-precise-capturing branch from 1ab55f3 to 9cc3014 Compare September 26, 2026 11:34
@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 26, 2026
@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

apologies for the delay and thanks for the approval

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refining_impl_trait: The suggested fix does not yet take precise capturing into account.

4 participants