Improve code readability

This commit is contained in:
Guillaume Gomez 2021-02-23 22:13:48 +01:00
parent 3c59e64abf
commit 33aaead6a1
3 changed files with 12 additions and 11 deletions

View File

@ -624,12 +624,10 @@ crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
debug!("record_extern_trait: {:?}", did); debug!("record_extern_trait: {:?}", did);
let trait_ = build_external_trait(cx, did); let trait_ = build_external_trait(cx, did);
cx.external_traits.borrow_mut().insert( let trait_ = clean::TraitWithExtraInfo {
did, trait_,
clean::TraitWithExtraInfo { is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight),
trait_, };
is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight), cx.external_traits.borrow_mut().insert(did, trait_);
},
);
cx.active_extern_traits.remove(&did); cx.active_extern_traits.remove(&did);
} }

View File

@ -13,7 +13,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_middle::mir::interpret::ConstValue; use rustc_middle::mir::interpret::ConstValue;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, Attributes, DefIdTree, Ty, TyCtxt}; use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use std::mem; use std::mem;
@ -530,7 +530,7 @@ crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<De
/// ///
/// This function exists because it runs on `hir::Attributes` whereas the other is a /// This function exists because it runs on `hir::Attributes` whereas the other is a
/// `clean::Attributes` method. /// `clean::Attributes` method.
crate fn has_doc_flag(attrs: Attributes<'_>, flag: Symbol) -> bool { crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
attrs.iter().any(|attr| { attrs.iter().any(|attr| {
attr.has_name(sym::doc) attr.has_name(sym::doc)
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) && attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))

View File

@ -30,7 +30,7 @@ use std::{cell::RefCell, collections::hash_map::Entry};
use crate::clean; use crate::clean;
use crate::clean::inline::build_external_trait; use crate::clean::inline::build_external_trait;
use crate::clean::{AttributesExt, MAX_DEF_IDX}; use crate::clean::{AttributesExt, TraitWithExtraInfo, MAX_DEF_IDX};
use crate::config::{Options as RustdocOptions, RenderOptions}; use crate::config::{Options as RustdocOptions, RenderOptions};
use crate::config::{OutputFormat, RenderInfo}; use crate::config::{OutputFormat, RenderInfo};
use crate::formats::cache::Cache; use crate::formats::cache::Cache;
@ -538,7 +538,10 @@ crate fn run_global_ctxt(
if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() { if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() {
let mut sized_trait = build_external_trait(&mut ctxt, sized_trait_did); let mut sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
sized_trait.is_auto = true; sized_trait.is_auto = true;
ctxt.external_traits.borrow_mut().insert(sized_trait_did, sized_trait); ctxt.external_traits.borrow_mut().insert(
sized_trait_did,
TraitWithExtraInfo { trait_: sized_trait, is_spotlight: false },
);
} }
debug!("crate: {:?}", tcx.hir().krate()); debug!("crate: {:?}", tcx.hir().krate());