diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2024-03-09 21:16:18 +0800 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2024-03-09 21:16:43 +0800 |
| commit | 7e1969ac13b94694bb6c9315dcecdc6b0ee344ad (patch) | |
| tree | 15594d8127a5c4e4b4160e042b1e40e506ff4a8b /compiler/rustc_ty_utils/src/instance.rs | |
| parent | 09bc67b9158392361780e779d32997f14cc75c39 (diff) | |
| download | rust-7e1969ac13b94694bb6c9315dcecdc6b0ee344ad.tar.gz rust-7e1969ac13b94694bb6c9315dcecdc6b0ee344ad.zip | |
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.
Diffstat (limited to 'compiler/rustc_ty_utils/src/instance.rs')
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 381681fb1f4..2816bcc888b 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -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) => { |
