about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2021-10-30 21:26:38 -0700
committerNoah Lev <camelidcamel@gmail.com>2021-10-31 10:19:18 -0700
commitbbc58e8ccc5d590c80f3fa07f8fe5cb2f3813aaa (patch)
tree3630d80c3c9c4d5e113ccf25eaa6dbe62890e387 /src
parenteeb2a6203b9b7072d088fbc5339f4c8311e57097 (diff)
downloadrust-bbc58e8ccc5d590c80f3fa07f8fe5cb2f3813aaa.tar.gz
rust-bbc58e8ccc5d590c80f3fa07f8fe5cb2f3813aaa.zip
Reduce rightward drift
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/mod.rs152
-rw-r--r--src/librustdoc/lib.rs1
2 files changed, 75 insertions, 78 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 3adc067005b..508407144c2 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1215,96 +1215,92 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
 }
 
 fn maybe_expand_private_type_alias(cx: &mut DocContext<'_>, path: &hir::Path<'_>) -> Option<Type> {
-    let mut alias = None;
-    if let Res::Def(DefKind::TyAlias, def_id) = path.res {
-        // Substitute private type aliases
-        if let Some(def_id) = def_id.as_local() {
-            let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
-            if !cx.cache.access_levels.is_exported(def_id.to_def_id()) {
-                alias = Some(&cx.tcx.hir().expect_item(hir_id).kind);
-            }
-        }
+    let Res::Def(DefKind::TyAlias, def_id) = path.res else { return None };
+    // Substitute private type aliases
+    let Some(def_id) = def_id.as_local() else { return None };
+    let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
+    let alias = if !cx.cache.access_levels.is_exported(def_id.to_def_id()) {
+        &cx.tcx.hir().expect_item(hir_id).kind
+    } else {
+        return None;
     };
+    let hir::ItemKind::TyAlias(ty, generics) = alias else { return None };
 
-    if let Some(&hir::ItemKind::TyAlias(ref ty, ref generics)) = alias {
-        let provided_params = &path.segments.last().expect("segments were empty");
-        let mut ty_substs = FxHashMap::default();
-        let mut lt_substs = FxHashMap::default();
-        let mut ct_substs = FxHashMap::default();
-        let generic_args = provided_params.args();
-        {
-            let mut indices: hir::GenericParamCount = Default::default();
-            for param in generics.params.iter() {
-                match param.kind {
-                    hir::GenericParamKind::Lifetime { .. } => {
-                        let mut j = 0;
-                        let lifetime = generic_args.args.iter().find_map(|arg| match arg {
-                            hir::GenericArg::Lifetime(lt) => {
-                                if indices.lifetimes == j {
-                                    return Some(lt);
-                                }
-                                j += 1;
-                                None
-                            }
-                            _ => None,
-                        });
-                        if let Some(lt) = lifetime.cloned() {
-                            let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
-                            let cleaned = if !lt.is_elided() {
-                                lt.clean(cx)
-                            } else {
-                                self::types::Lifetime::elided()
-                            };
-                            lt_substs.insert(lt_def_id.to_def_id(), cleaned);
+    let provided_params = &path.segments.last().expect("segments were empty");
+    let mut ty_substs = FxHashMap::default();
+    let mut lt_substs = FxHashMap::default();
+    let mut ct_substs = FxHashMap::default();
+    let generic_args = provided_params.args();
+
+    let mut indices: hir::GenericParamCount = Default::default();
+    for param in generics.params.iter() {
+        match param.kind {
+            hir::GenericParamKind::Lifetime { .. } => {
+                let mut j = 0;
+                let lifetime = generic_args.args.iter().find_map(|arg| match arg {
+                    hir::GenericArg::Lifetime(lt) => {
+                        if indices.lifetimes == j {
+                            return Some(lt);
                         }
-                        indices.lifetimes += 1;
+                        j += 1;
+                        None
                     }
-                    hir::GenericParamKind::Type { ref default, .. } => {
-                        let ty_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
-                        let mut j = 0;
-                        let type_ = generic_args.args.iter().find_map(|arg| match arg {
-                            hir::GenericArg::Type(ty) => {
-                                if indices.types == j {
-                                    return Some(ty);
-                                }
-                                j += 1;
-                                None
-                            }
-                            _ => None,
-                        });
-                        if let Some(ty) = type_ {
-                            ty_substs.insert(ty_param_def_id.to_def_id(), ty.clean(cx));
-                        } else if let Some(default) = *default {
-                            ty_substs.insert(ty_param_def_id.to_def_id(), default.clean(cx));
+                    _ => None,
+                });
+                if let Some(lt) = lifetime.cloned() {
+                    let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
+                    let cleaned = if !lt.is_elided() {
+                        lt.clean(cx)
+                    } else {
+                        self::types::Lifetime::elided()
+                    };
+                    lt_substs.insert(lt_def_id.to_def_id(), cleaned);
+                }
+                indices.lifetimes += 1;
+            }
+            hir::GenericParamKind::Type { ref default, .. } => {
+                let ty_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
+                let mut j = 0;
+                let type_ = generic_args.args.iter().find_map(|arg| match arg {
+                    hir::GenericArg::Type(ty) => {
+                        if indices.types == j {
+                            return Some(ty);
                         }
-                        indices.types += 1;
+                        j += 1;
+                        None
                     }
-                    hir::GenericParamKind::Const { .. } => {
-                        let const_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
-                        let mut j = 0;
-                        let const_ = generic_args.args.iter().find_map(|arg| match arg {
-                            hir::GenericArg::Const(ct) => {
-                                if indices.consts == j {
-                                    return Some(ct);
-                                }
-                                j += 1;
-                                None
-                            }
-                            _ => None,
-                        });
-                        if let Some(ct) = const_ {
-                            ct_substs.insert(const_param_def_id.to_def_id(), ct.clean(cx));
+                    _ => None,
+                });
+                if let Some(ty) = type_ {
+                    ty_substs.insert(ty_param_def_id.to_def_id(), ty.clean(cx));
+                } else if let Some(default) = *default {
+                    ty_substs.insert(ty_param_def_id.to_def_id(), default.clean(cx));
+                }
+                indices.types += 1;
+            }
+            hir::GenericParamKind::Const { .. } => {
+                let const_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
+                let mut j = 0;
+                let const_ = generic_args.args.iter().find_map(|arg| match arg {
+                    hir::GenericArg::Const(ct) => {
+                        if indices.consts == j {
+                            return Some(ct);
                         }
-                        // FIXME(const_generics_defaults)
-                        indices.consts += 1;
+                        j += 1;
+                        None
                     }
+                    _ => None,
+                });
+                if let Some(ct) = const_ {
+                    ct_substs.insert(const_param_def_id.to_def_id(), ct.clean(cx));
                 }
+                // FIXME(const_generics_defaults)
+                indices.consts += 1;
             }
         }
-        Some(cx.enter_alias(ty_substs, lt_substs, ct_substs, |cx| ty.clean(cx)))
-    } else {
-        None
     }
+
+    Some(cx.enter_alias(ty_substs, lt_substs, ct_substs, |cx| ty.clean(cx)))
 }
 
 impl Clean<Type> for hir::Ty<'_> {
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index b50fbf58bae..8dceb2ec92a 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -9,6 +9,7 @@
 #![feature(control_flow_enum)]
 #![feature(box_syntax)]
 #![feature(in_band_lifetimes)]
+#![feature(let_else)]
 #![feature(nll)]
 #![feature(test)]
 #![feature(crate_visibility_modifier)]