about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2023-01-19 20:26:01 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2023-01-19 20:26:01 +0100
commit8b80bc1bf4719270a9b4bf8f4cc682bb18a574c7 (patch)
treeedcea190373c947f56360776e60d84baae9af0be
parent286a632e725826bb13f6710f188f4ed1af0d50cf (diff)
downloadrust-8b80bc1bf4719270a9b4bf8f4cc682bb18a574c7.tar.gz
rust-8b80bc1bf4719270a9b4bf8f4cc682bb18a574c7.zip
Revert "Improve code readability"
This reverts commit eb93d1bedeab64c6f5d661df6a309a5b8a9273ca.
-rw-r--r--src/librustdoc/html/render/write_shared.rs2
-rw-r--r--src/librustdoc/visit_ast.rs36
2 files changed, 15 insertions, 23 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index ca3e9916487..bc8badad38e 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -138,7 +138,7 @@ pub(super) fn write_shared(
         Ok((ret, krates))
     }
 
-    /// Read a file and return all lines that match the <code>"{crate}":{data},\ </code> format,
+    /// Read a file and return all lines that match the <code>"{crate}":{data},\</code> format,
     /// and return a tuple `(Vec<DataString>, Vec<CrateNameString>)`.
     ///
     /// This forms the payload of files that look like this:
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index c5aaae7a908..a8fc85a3ee1 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -187,16 +187,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
         ret
     }
 
-    #[inline]
-    fn add_to_current_mod(
-        &mut self,
-        item: &'tcx hir::Item<'_>,
-        renamed: Option<Symbol>,
-        parent_id: Option<hir::HirId>,
-    ) {
-        self.modules.last_mut().unwrap().items.push((item, renamed, parent_id))
-    }
-
     fn visit_item_inner(
         &mut self,
         item: &'tcx hir::Item<'_>,
@@ -257,7 +247,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                         }
                     }
 
-                    self.add_to_current_mod(item, renamed, parent_id);
+                    self.modules.last_mut().unwrap().items.push((item, renamed, parent_id));
                 }
             }
             hir::ItemKind::Macro(ref macro_def, _) => {
@@ -277,7 +267,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
                 let nonexported = !self.cx.tcx.has_attr(def_id, sym::macro_export);
 
                 if is_macro_2_0 || nonexported || self.inlining {
-                    self.add_to_current_mod(item, renamed, None);
+                    self.modules.last_mut().unwrap().items.push((item, renamed, None));
                 }
             }
             hir::ItemKind::Mod(ref m) => {
@@ -293,20 +283,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
             | hir::ItemKind::Static(..)
             | hir::ItemKind::Trait(..)
             | hir::ItemKind::TraitAlias(..) => {
-                self.add_to_current_mod(item, renamed, parent_id);
+                self.modules.last_mut().unwrap().items.push((item, renamed, parent_id))
             }
             hir::ItemKind::Const(..) => {
                 // Underscore constants do not correspond to a nameable item and
                 // so are never useful in documentation.
                 if name != kw::Underscore {
-                    self.add_to_current_mod(item, renamed, parent_id);
+                    self.modules.last_mut().unwrap().items.push((item, renamed, parent_id));
                 }
             }
             hir::ItemKind::Impl(impl_) => {
                 // Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
                 // them up regardless of where they're located.
                 if !self.inlining && impl_.of_trait.is_none() {
-                    self.add_to_current_mod(item, None, None);
+                    self.modules.last_mut().unwrap().items.push((item, None, None));
                 }
             }
         }
@@ -343,13 +333,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
         // macro in the same module.
         let mut inserted = FxHashSet::default();
         for export in self.cx.tcx.module_reexports(CRATE_DEF_ID).unwrap_or(&[]) {
-            if let Res::Def(DefKind::Macro(_), def_id) = export.res &&
-                let Some(local_def_id) = def_id.as_local() &&
-                self.cx.tcx.has_attr(def_id, sym::macro_export) &&
-                inserted.insert(def_id)
-            {
-                    let item = self.cx.tcx.hir().expect_item(local_def_id);
-                    top_level_module.items.push((item, None, None));
+            if let Res::Def(DefKind::Macro(_), def_id) = export.res {
+                if let Some(local_def_id) = def_id.as_local() {
+                    if self.cx.tcx.has_attr(def_id, sym::macro_export) {
+                        if inserted.insert(def_id) {
+                            let item = self.cx.tcx.hir().expect_item(local_def_id);
+                            top_level_module.items.push((item, None, None));
+                        }
+                    }
+                }
             }
         }