about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2023-09-29 19:17:55 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2023-09-29 23:04:33 +0200
commit854cdff9722e275496d15d8a89aa55ee32e753cb (patch)
tree0a095a8c530d10b8fb2d76dc36bdaf015f863cf3 /src
parent085acd02d4abaf2ccaf629134caa83cfe23283c8 (diff)
downloadrust-854cdff9722e275496d15d8a89aa55ee32e753cb.tar.gz
rust-854cdff9722e275496d15d8a89aa55ee32e753cb.zip
rustdoc: simplify sugared_async_return_type
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/types.rs35
1 files changed, 9 insertions, 26 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index f5251f50b7a..1d8fa2e636e 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -1604,14 +1604,16 @@ impl Type {
     ///
     /// This function will panic if the return type does not match the expected sugaring for async
     /// functions.
-    pub(crate) fn sugared_async_return_type(&self) -> Type {
-        if let Type::ImplTrait(v) = self &&
-            let [GenericBound::TraitBound(PolyTrait { trait_, .. }, _ )] = &v[..]
+    pub(crate) fn sugared_async_return_type(self) -> Type {
+        if let Type::ImplTrait(mut v) = self
+            && let Some(GenericBound::TraitBound(PolyTrait { mut trait_, .. }, _ )) = v.pop()
+            && let Some(segment) = trait_.segments.pop()
+            && let GenericArgs::AngleBracketed { mut bindings, .. } = segment.args
+            && let Some(binding) = bindings.pop()
+            && let TypeBindingKind::Equality { term } = binding.kind
+            && let Term::Type(ty) = term
         {
-            let bindings = trait_.bindings().unwrap();
-            let ret_ty = bindings[0].term();
-            let ty = ret_ty.ty().expect("unexpected constant in async fn return term");
-            ty.clone()
+            ty
         } else {
             panic!("unexpected async fn return type")
         }
@@ -2189,16 +2191,6 @@ impl Path {
             }
         })
     }
-
-    pub(crate) fn bindings(&self) -> Option<&[TypeBinding]> {
-        self.segments.last().and_then(|seg| {
-            if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args {
-                Some(&**bindings)
-            } else {
-                None
-            }
-        })
-    }
 }
 
 #[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -2478,15 +2470,6 @@ pub(crate) enum TypeBindingKind {
     Constraint { bounds: Vec<GenericBound> },
 }
 
-impl TypeBinding {
-    pub(crate) fn term(&self) -> &Term {
-        match self.kind {
-            TypeBindingKind::Equality { ref term } => term,
-            _ => panic!("expected equality type binding for parenthesized generic args"),
-        }
-    }
-}
-
 /// The type, lifetime, or constant that a private type alias's parameter should be
 /// replaced with when expanding a use of that type alias.
 ///