point at closure return expression in non-FnOnce E0271 errors - #159839
Conversation
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
6c955fa to
475f867
Compare
|
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. |
|
@estebank hello, just wanted to follow up on the pr. sorry if this is bothering you |
|
@rustbot reroll |
|
@rustbot reroll (bandwidth) |
| LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0); | ||
| | ---- ^^^^^^^^^^^^^^^^^^^^^^^^ types differ | ||
| | | | ||
| | ---- -------- ^^^^^^^^^^^^^^^ types differ | ||
| | | | | ||
| | | this closure | ||
| | required by a bound introduced by this call |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That would be ideal, if it can be done cleanly.
…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)
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
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 |
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 inmaybe_detailed_projection_msg. which cant recover the closure fromself_tyalone.fixes #42390
r? @estebank