]> git.lizzy.rs Git - rust.git/commitdiff
Put clean::Trait extra information into a new struct to make it more coherent
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 12 Feb 2021 13:33:32 +0000 (14:33 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 23 Feb 2021 20:58:16 +0000 (21:58 +0100)
src/librustdoc/clean/inline.rs
src/librustdoc/clean/types.rs
src/librustdoc/core.rs
src/librustdoc/fold.rs
src/librustdoc/formats/cache.rs
src/librustdoc/html/render/mod.rs
src/librustdoc/json/mod.rs

index 519ec7216e3866ed7de0d721508b9b9098b4de1d..51cdcd74147d538a5fd67c630d59b043f86905b0 100644 (file)
@@ -624,8 +624,12 @@ fn separate_supertrait_bounds(
     debug!("record_extern_trait: {:?}", did);
     let trait_ = build_external_trait(cx, did);
 
-    cx.external_traits
-        .borrow_mut()
-        .insert(did, (trait_, clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight)));
+    cx.external_traits.borrow_mut().insert(
+        did,
+        clean::TraitWithExtraInfo {
+            trait_,
+            is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
+        },
+    );
     cx.active_extern_traits.remove(&did);
 }
index 0289ee9afb77b0965334584e5142fa9e2f3e6bca..51bef344e6722a80186032cfedec372e67e528d3 100644 (file)
     crate primitives: Vec<(DefId, PrimitiveType)>,
     // These are later on moved into `CACHEKEY`, leaving the map empty.
     // Only here so that they can be filtered through the rustdoc passes.
-    crate external_traits: Rc<RefCell<FxHashMap<DefId, (Trait, bool)>>>,
+    crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
     crate masked_crates: FxHashSet<CrateNum>,
     crate collapsed: bool,
 }
 
+/// This struct is used to wrap additional information added by rustdoc on a `trait` item.
+#[derive(Clone, Debug)]
+crate struct TraitWithExtraInfo {
+    crate trait_: Trait,
+    crate is_spotlight: bool,
+}
+
 #[derive(Clone, Debug)]
 crate struct ExternalCrate {
     crate name: Symbol,
index 5f24ec7b3f73ed16c596c5341b8ee544ab34cd1e..3883652375fa5017819015c556bf2b77755df7d1 100644 (file)
@@ -55,7 +55,7 @@
     /// Later on moved into `cache`
     crate renderinfo: RenderInfo,
     /// Later on moved through `clean::Crate` into `cache`
-    crate external_traits: Rc<RefCell<FxHashMap<DefId, (clean::Trait, bool)>>>,
+    crate external_traits: Rc<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>,
     /// Used while populating `external_traits` to ensure we don't process the same trait twice at
     /// the same time.
     crate active_extern_traits: FxHashSet<DefId>,
index 752233ade37126c5a81b0e4bbfd7775cd829a788..2b980ebe5926a88cf55f6e76e3c37946545803c7 100644 (file)
@@ -91,9 +91,10 @@ fn fold_crate(&mut self, mut c: Crate) -> Crate {
 
         {
             let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
-            for (k, (mut v, is_spotlight)) in external_traits {
-                v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
-                c.external_traits.borrow_mut().insert(k, (v, is_spotlight));
+            for (k, mut v) in external_traits {
+                v.trait_.items =
+                    v.trait_.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
+                c.external_traits.borrow_mut().insert(k, v);
             }
         }
         c
index a64eeb5bc58229ccca8ddc2660e503223162f47b..ef4e0e0d57c920565b87d954f008689866f2b644 100644 (file)
@@ -65,9 +65,7 @@
     /// Implementations of a crate should inherit the documentation of the
     /// parent trait if no extra documentation is specified, and default methods
     /// should show up in documentation about trait implementations.
-    ///
-    /// The `bool` parameter is about if the trait is `spotlight`.
-    crate traits: FxHashMap<DefId, (clean::Trait, bool)>,
+    crate traits: FxHashMap<DefId, clean::TraitWithExtraInfo>,
 
     /// When rendering traits, it's often useful to be able to list all
     /// implementors of the trait, and this mapping is exactly, that: a mapping
@@ -251,8 +249,12 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
         // Propagate a trait method's documentation to all implementors of the
         // trait.
         if let clean::TraitItem(ref t) = *item.kind {
-            self.cache.traits.entry(item.def_id).or_insert_with(|| {
-                (t.clone(), clean::utils::has_doc_flag(tcx.get_attrs(item.def_id), sym::spotlight))
+            self.cache.traits.entry(item.def_id).or_insert_with(|| clean::TraitWithExtraInfo {
+                trait_: t.clone(),
+                is_spotlight: clean::utils::has_doc_flag(
+                    tcx.get_attrs(item.def_id),
+                    sym::spotlight,
+                ),
             });
         }
 
index ab3c9bab64fbee68f5229d3686f3cdff6c8928f4..b21f6a13392361bd82f5ba20d3903a93a1f8a1f2 100644 (file)
@@ -3688,7 +3688,7 @@ fn spotlight_decl(decl: &clean::FnDecl, cache: &Cache) -> String {
             for i in impls {
                 let impl_ = i.inner_impl();
                 if impl_.trait_.def_id().map_or(false, |d| {
-                    cache.traits.get(&d).map(|(_, is_spotlight)| *is_spotlight).unwrap_or(false)
+                    cache.traits.get(&d).map(|t| t.is_spotlight).unwrap_or(false)
                 }) {
                     if out.is_empty() {
                         write!(
@@ -3980,7 +3980,7 @@ fn doc_impl_item(
             false,
             outer_version,
             outer_const_version,
-            trait_.map(|(t, _)| t),
+            trait_.map(|t| &t.trait_),
             show_def_docs,
         );
     }
@@ -4025,11 +4025,11 @@ fn render_default_items(
     // We don't emit documentation for default items if they appear in the
     // Implementations on Foreign Types or Implementors sections.
     if show_default_items {
-        if let Some((t, _)) = trait_ {
+        if let Some(t) = trait_ {
             render_default_items(
                 w,
                 cx,
-                t,
+                &t.trait_,
                 &i.inner_impl(),
                 &i.impl_item,
                 render_mode,
index aa093ba0a772d3e2bd5c5995555fbcb95bae9906..a3b214677941b143a857f6d30b075b5d749da15c 100644 (file)
@@ -84,9 +84,10 @@ fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
         Rc::clone(&self.cache)
             .traits
             .iter()
-            .filter_map(|(&id, (trait_item, _))| {
+            .filter_map(|(&id, trait_item)| {
                 // only need to synthesize items for external traits
                 if !id.is_local() {
+                    let trait_item = &trait_item.trait_;
                     trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
                     Some((
                         from_def_id(id),