From: Guillaume Gomez Date: Tue, 23 Feb 2021 21:13:48 +0000 (+0100) Subject: Improve code readability X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=33aaead6a1bdd4b2fde50efde825d2a770d8ecb8;p=rust.git Improve code readability --- diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 51cdcd74147..f9c63186544 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -624,12 +624,10 @@ fn separate_supertrait_bounds( debug!("record_extern_trait: {:?}", did); let trait_ = build_external_trait(cx, did); - cx.external_traits.borrow_mut().insert( - did, - clean::TraitWithExtraInfo { - trait_, - is_spotlight: clean::utils::has_doc_flag(cx.tcx.get_attrs(did), sym::spotlight), - }, - ); + let trait_ = clean::TraitWithExtraInfo { + 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); } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 0089a3838f4..a0a2b785353 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -13,7 +13,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_middle::mir::interpret::ConstValue; 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 std::mem; @@ -530,7 +530,7 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const /// /// This function exists because it runs on `hir::Attributes` whereas the other is a /// `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| { attr.has_name(sym::doc) && attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 3883652375f..f0b3159f737 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -30,7 +30,7 @@ use crate::clean; 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::{OutputFormat, RenderInfo}; use crate::formats::cache::Cache; @@ -538,7 +538,10 @@ pub(crate) fn init_lints( if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() { let mut sized_trait = build_external_trait(&mut ctxt, sized_trait_did); 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());