Skip to content

point at closure return expression in non-FnOnce E0271 errors - #159839

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Albab-Hasan:e0271-point-closure-return-span
Aug 11, 2026
Merged

point at closure return expression in non-FnOnce E0271 errors#159839
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Albab-Hasan:e0271-point-closure-return-span

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

when a closure literal is passed as a function argument and E0271 fires for a projection that isnt FnOnceOutput. the error now points at the closures return expression and labels the closure declaration with "this closure". mirroring the existing FnOnce handling in maybe_detailed_projection_msg. which cant recover the closure from self_ty alone.

fixes #42390

r? @estebank

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 24, 2026
when a closure literal is passed as a function argument and E0271 fires
for a projection that isnt FnOnceOutput, the error now points at the
closures return expression and labels the closure declaration with
"this closure", mirroring the existing FnOnce handling in
maybe_detailed_projection_msg, which cant recover the closure from
self_ty alone.

fixes rust-lang#42390
@Albab-Hasan
Albab-Hasan force-pushed the e0271-point-closure-return-span branch from 6c955fa to 475f867 Compare July 24, 2026 13:34
@rustbot

rustbot commented Jul 24, 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

@estebank hello, just wanted to follow up on the pr. sorry if this is bothering you

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned jieyouxu and unassigned estebank Aug 6, 2026
@jieyouxu

jieyouxu commented Aug 9, 2026

Copy link
Copy Markdown
Member

@rustbot reroll (bandwidth)

@rustbot rustbot assigned oli-obk and unassigned jieyouxu Aug 9, 2026

@oli-obk oli-obk 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.

Comment on lines 18 to 22
LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^ types differ
| |
| ---- -------- ^^^^^^^^^^^^^^^ types differ
| | |
| | this closure
| required by a bound introduced by this call

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.

in this case the issue is the closure argument, not the return type. While the failure was a projection failure, this is just noise after the main trait goal erroroed above already.

The error doesn't really get better or worse here, but we should somehow avoid emitting two errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the review!

want me to take a follow up for the duplicate error? happy to look at suppressing the projection one when the closure signature already failed.

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.

That would be ideal, if it can be done cleanly.

@rust-bors

rust-bors Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 475f867 has been approved by oli-obk

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 Aug 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 11, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #156338 (Implement derives for Reborrow and CoerceShared)
 - #158083 (Fix perf regression in `Read::read_to_end` on short reads due to not checking if the cursor has initialized bytes)
 - #160829 (bootstrap: Make `main.rs` a stub that calls into the library crate)
 - #159839 (point at closure return expression in non-`FnOnce` E0271 errors)
 - #160775 (interpret: treat pattern and unsafe-binder as ABI-transparent)
@rust-bors
rust-bors Bot merged commit 46541dc into rust-lang:main Aug 11, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 11, 2026
rust-timer added a commit that referenced this pull request Aug 11, 2026
Rollup merge of #159839 - Albab-Hasan:e0271-point-closure-return-span, r=oli-obk

point at closure return expression in non-`FnOnce` E0271 errors

when a closure literal is passed as a function argument and E0271 fires for a projection that isnt `FnOnceOutput`. the error now points at the closures return expression and labels the closure declaration with "this closure". mirroring the existing FnOnce handling in `maybe_detailed_projection_msg`. which cant recover the closure from `self_ty` alone.

fixes #42390

r? @estebank
@estebank

Copy link
Copy Markdown
Contributor

hello, just wanted to follow up on the pr. sorry if this is bothering you

No bother, I've been traveling these past few weeks. Glad it got reviewed already regardless.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

hello, just wanted to follow up on the pr. sorry if this is bothering you

No bother, I've been traveling these past few weeks. Glad it got reviewed already regardless.

i thought i annoyed you with all those prs lol. mb

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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add span to E0271 errors pointing at the "found" associated type bound

5 participants