-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closures always implement FnOnce
in new solver
#109739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closures always implement FnOnce
in new solver
#109739
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
r? @lcnr 😁 |
a11086f
to
177997e
Compare
@bors r=lcnr rollup (new solver) |
…-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 😸)
…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
We should process
[closure]: FnOnce(Tys...) -> Ty
obligations before fallback and closure analysis. We can do this by taking advantage of the fact thatFnOnce
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 😸)