about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2023-02-15 11:30:14 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2023-02-15 12:00:03 +0100
commit86fd5a1b44afe71888b1d4e62373a6a6a8fc2cbd (patch)
tree92d9f49cdba1035d6825ba6a1223d703c206731f /src/librustdoc/html
parent9bb6e60d1f1360234aae90c97964c0fa5524f141 (diff)
downloadrust-86fd5a1b44afe71888b1d4e62373a6a6a8fc2cbd.tar.gz
rust-86fd5a1b44afe71888b1d4e62373a6a6a8fc2cbd.zip
Use more let chain
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/format.rs8
-rw-r--r--src/librustdoc/html/highlight.rs6
-rw-r--r--src/librustdoc/html/render/context.rs14
-rw-r--r--src/librustdoc/html/render/mod.rs52
4 files changed, 36 insertions, 44 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 8a7a8ea5fd1..fd0fcdbd4ab 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -709,11 +709,9 @@ pub(crate) fn href_with_root_path(
             }
         }
     };
-    if !is_remote {
-        if let Some(root_path) = root_path {
-            let root = root_path.trim_end_matches('/');
-            url_parts.push_front(root);
-        }
+    if !is_remote && let Some(root_path) = root_path {
+        let root = root_path.trim_end_matches('/');
+        url_parts.push_front(root);
     }
     debug!(?url_parts);
     match shortty {
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index 3c10eb524d7..2c9fc4e3ca3 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -466,10 +466,8 @@ impl<'a> PeekIter<'a> {
     }
     /// Returns the next item after the current one. It doesn't interfere with `peek_next` output.
     fn peek(&mut self) -> Option<&(TokenKind, &'a str)> {
-        if self.stored.is_empty() {
-            if let Some(next) = self.iter.next() {
-                self.stored.push_back(next);
-            }
+        if self.stored.is_empty() && let Some(next) = self.iter.next() {
+            self.stored.push_back(next);
         }
         self.stored.front()
     }
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 6762fba9275..5e4a595627b 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -705,14 +705,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
             shared.fs.write(scrape_examples_help_file, v)?;
         }
 
-        if let Some(ref redirections) = shared.redirections {
-            if !redirections.borrow().is_empty() {
-                let redirect_map_path =
-                    self.dst.join(crate_name.as_str()).join("redirect-map.json");
-                let paths = serde_json::to_string(&*redirections.borrow()).unwrap();
-                shared.ensure_dir(&self.dst.join(crate_name.as_str()))?;
-                shared.fs.write(redirect_map_path, paths)?;
-            }
+        if let Some(ref redirections) = shared.redirections && !redirections.borrow().is_empty() {
+            let redirect_map_path =
+                self.dst.join(crate_name.as_str()).join("redirect-map.json");
+            let paths = serde_json::to_string(&*redirections.borrow()).unwrap();
+            shared.ensure_dir(&self.dst.join(crate_name.as_str()))?;
+            shared.fs.write(redirect_map_path, paths)?;
         }
 
         // No need for it anymore.
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 2086faf78ac..e6a040d02e5 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -2225,14 +2225,13 @@ fn sidebar_deref_methods(
         })
     {
         debug!("found target, real_target: {:?} {:?}", target, real_target);
-        if let Some(did) = target.def_id(c) {
-            if let Some(type_did) = impl_.inner_impl().for_.def_id(c) {
-                // `impl Deref<Target = S> for S`
-                if did == type_did || !derefs.insert(did) {
-                    // Avoid infinite cycles
-                    return;
-                }
-            }
+        if let Some(did) = target.def_id(c) &&
+            let Some(type_did) = impl_.inner_impl().for_.def_id(c) &&
+            // `impl Deref<Target = S> for S`
+            (did == type_did || !derefs.insert(did))
+        {
+            // Avoid infinite cycles
+            return;
         }
         let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
         let inner_impl = target
@@ -2266,25 +2265,24 @@ fn sidebar_deref_methods(
         }
 
         // Recurse into any further impls that might exist for `target`
-        if let Some(target_did) = target.def_id(c) {
-            if let Some(target_impls) = c.impls.get(&target_did) {
-                if let Some(target_deref_impl) = target_impls.iter().find(|i| {
-                    i.inner_impl()
-                        .trait_
-                        .as_ref()
-                        .map(|t| Some(t.def_id()) == cx.tcx().lang_items().deref_trait())
-                        .unwrap_or(false)
-                }) {
-                    sidebar_deref_methods(
-                        cx,
-                        out,
-                        target_deref_impl,
-                        target_impls,
-                        derefs,
-                        used_links,
-                    );
-                }
-            }
+        if let Some(target_did) = target.def_id(c) &&
+            let Some(target_impls) = c.impls.get(&target_did) &&
+            let Some(target_deref_impl) = target_impls.iter().find(|i| {
+                i.inner_impl()
+                    .trait_
+                    .as_ref()
+                    .map(|t| Some(t.def_id()) == cx.tcx().lang_items().deref_trait())
+                    .unwrap_or(false)
+            })
+        {
+            sidebar_deref_methods(
+                cx,
+                out,
+                target_deref_impl,
+                target_impls,
+                derefs,
+                used_links,
+            );
         }
     }
 }