Remove Ord
from ClosureKind
Using `Ord` to accomplish a meaning of subset relationship can be hard to read. The existing uses for that are easily replaced with a `match`, and in my opinion, more readable without needing to resorting to comments to explain the intention.
This commit is contained in:
parent
09bc67b915
commit
7e1969ac13
4 changed files with 42 additions and 28 deletions
|
@ -7,6 +7,7 @@ use rustc_middle::ty::GenericArgsRef;
|
|||
use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::sym;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_type_ir::ClosureKind;
|
||||
use traits::{translate_args, Reveal};
|
||||
|
||||
use crate::errors::UnexpectedFnPtrAssociatedItem;
|
||||
|
@ -296,23 +297,25 @@ fn resolve_associated_item<'tcx>(
|
|||
{
|
||||
match *rcvr_args.type_at(0).kind() {
|
||||
ty::CoroutineClosure(coroutine_closure_def_id, args) => {
|
||||
// If we're computing `AsyncFnOnce`/`AsyncFnMut` for a by-ref closure,
|
||||
// or `AsyncFnOnce` for a by-mut closure, then construct a new body that
|
||||
// has the right return types.
|
||||
//
|
||||
// Specifically, `AsyncFnMut` for a by-ref coroutine-closure just needs
|
||||
// to have its input and output types fixed (`&mut self` and returning
|
||||
// `i16` coroutine kind).
|
||||
if target_kind > args.as_coroutine_closure().kind() {
|
||||
Some(Instance {
|
||||
def: ty::InstanceDef::ConstructCoroutineInClosureShim {
|
||||
coroutine_closure_def_id,
|
||||
target_kind,
|
||||
},
|
||||
args,
|
||||
})
|
||||
} else {
|
||||
Some(Instance::new(coroutine_closure_def_id, args))
|
||||
match (target_kind, args.as_coroutine_closure().kind()) {
|
||||
(ClosureKind::FnOnce | ClosureKind::FnMut, ClosureKind::Fn)
|
||||
| (ClosureKind::FnOnce, ClosureKind::FnMut) => {
|
||||
// If we're computing `AsyncFnOnce`/`AsyncFnMut` for a by-ref closure,
|
||||
// or `AsyncFnOnce` for a by-mut closure, then construct a new body that
|
||||
// has the right return types.
|
||||
//
|
||||
// Specifically, `AsyncFnMut` for a by-ref coroutine-closure just needs
|
||||
// to have its input and output types fixed (`&mut self` and returning
|
||||
// `i16` coroutine kind).
|
||||
Some(Instance {
|
||||
def: ty::InstanceDef::ConstructCoroutineInClosureShim {
|
||||
coroutine_closure_def_id,
|
||||
target_kind,
|
||||
},
|
||||
args,
|
||||
})
|
||||
}
|
||||
_ => Some(Instance::new(coroutine_closure_def_id, args)),
|
||||
}
|
||||
}
|
||||
ty::Closure(closure_def_id, args) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue