summaryrefslogtreecommitdiff
path: root/ops/lib.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-05-12 20:22:42 +0200
committerGitHub <noreply@github.com>2022-05-12 20:22:42 +0200
commitf18d0539b141f808ca9baa44674756fadbe884be (patch)
tree0f384ce69bbb5b164b48b306879bca48d2a7599d /ops/lib.rs
parentc6063e390a0a005f14051493a50ab7db9fc02373 (diff)
cleanup(ops): simpler is_unit_result() (#14586)
Rough token-string matching is robust enough and much easier to grok
Diffstat (limited to 'ops/lib.rs')
-rw-r--r--ops/lib.rs23
1 files changed, 2 insertions, 21 deletions
diff --git a/ops/lib.rs b/ops/lib.rs
index c190a1c4d..bfc949af7 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -365,27 +365,8 @@ fn is_result(ty: impl ToTokens) -> bool {
}
/// Detects if a type is of the form Result<(), Err>
-fn is_unit_result(ty: &syn::Type) -> bool {
- let path = match ty {
- syn::Type::Path(ref path) => path,
- _ => return false,
- };
-
- let maybe_result = path.path.segments.first().expect("Invalid return type.");
- if maybe_result.ident != "Result" {
- return false;
- }
- assert!(!maybe_result.arguments.is_empty());
-
- let args = match &maybe_result.arguments {
- syn::PathArguments::AngleBracketed(args) => args,
- _ => unreachable!(),
- };
-
- match args.args.first().unwrap() {
- syn::GenericArgument::Type(syn::Type::Tuple(ty)) => ty.elems.is_empty(),
- _ => false,
- }
+fn is_unit_result(ty: impl ToTokens) -> bool {
+ is_result(&ty) && tokens(&ty).contains("Result < ()")
}
fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool {