Closures always implement FnOnce in new solver#109739
Merged
bors merged 1 commit intorust-lang:masterfrom Mar 31, 2023
Merged
Conversation
Collaborator
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
lcnr
reviewed
Mar 30, 2023
Comment on lines
217
to
230
Contributor
There was a problem hiding this comment.
Suggested change
| Some(closure_kind) => { | |
| // If the closure's kind doesn't extend the goal kind, | |
| // then the closure doesn't implement the trait. | |
| if !closure_kind.extends(goal_kind) { | |
| return Err(NoSolution); | |
| } | |
| } | |
| // Closure kind is not yet determined | |
| None => { | |
| // All closures implement `FnOnce` | |
| if goal_kind != ty::ClosureKind::FnOnce { | |
| // Otherwise, if we don't know the `ClosureKind`, ambiguity. | |
| return Ok(None); | |
| } | |
| } | |
| // If the closure's kind doesn't extend the goal kind, | |
| // then the closure doesn't implement the trait. | |
| Some(closure_kind) => { | |
| if !closure_kind.extends(goal_kind) { | |
| return Err(NoSolution); | |
| } | |
| } | |
| // Closure kind is not yet determined, so we return ambiguity unless | |
| // the expected kind is `FnOnce` as that is always implemented. | |
| None => { | |
| if goal_kind != ty::ClosureKind::FnOnce { | |
| return Ok(None); | |
| } | |
| } |
style nit: having these kinds of nested comments imo makes the code more verbose and harder to read. Can't explain it well but I guess part of the issue is that I have to switch between reading the comment, and reading the actual source.
r=me with or without this nit applied
Contributor
|
r? @lcnr 😁 |
a11086f to
177997e
Compare
Contributor
Author
|
@bors r=lcnr rollup (new solver) |
Collaborator
Dylan-DPC
added a commit
to Dylan-DPC/rust
that referenced
this pull request
Mar 30, 2023
…-fnonce, r=lcnr Closures always implement `FnOnce` in new solver We should process `[closure]: FnOnce(Tys...) -> Ty` obligations *before* fallback and closure analysis. We can do this by taking advantage of the fact that `FnOnce` is always implemented by closures, even before we definitely know the closure kind. Fixes compiler-errors/next-solver-hir-issues#15 r? `@oli-obk` (trying to spread the reviewer load for new trait solver prs, and this one is pretty self-contained, though feel free to reassign 😸)
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 30, 2023
…mpiler-errors Rollup of 6 pull requests Successful merges: - rust-lang#109347 (Skip no_mangle if the item has no name.) - rust-lang#109522 (Implement current_dll_path for AIX) - rust-lang#109679 (Freshen normalizes-to hack goal RHS in the evaluate loop) - rust-lang#109704 (resolve: Minor improvements to effective visibilities) - rust-lang#109739 (Closures always implement `FnOnce` in new solver) - rust-lang#109758 (Parallel compiler cleanups) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We should process
[closure]: FnOnce(Tys...) -> Tyobligations before fallback and closure analysis. We can do this by taking advantage of the fact thatFnOnceis always implemented by closures, even before we definitely know the closure kind.Fixes compiler-errors/next-solver-hir-issues#15
r? @oli-obk (trying to spread the reviewer load for new trait solver prs, and this one is pretty self-contained, though feel free to reassign 😸)