diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index ba701f42c660b..2ccf17387d1c7 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -76,17 +76,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { new_generics }); - let negative_polarity; + let polarity; let new_generics = match result { AutoTraitResult::PositiveImpl(new_generics) => { - negative_polarity = false; + polarity = ty::ImplPolarity::Positive; if discard_positive_impl { return None; } new_generics } AutoTraitResult::NegativeImpl => { - negative_polarity = true; + polarity = ty::ImplPolarity::Negative; // For negative impls, we use the generic params, but *not* the predicates, // from the original type. Otherwise, the displayed impl appears to be a @@ -115,15 +115,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { visibility: Inherited, def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, kind: box ImplItem(Impl { - span: Span::dummy(), unsafety: hir::Unsafety::Normal, generics: new_generics, trait_: Some(trait_ref.clean(self.cx)), for_: ty.clean(self.cx), items: Vec::new(), - negative_polarity, - synthetic: true, - blanket_impl: None, + polarity, + kind: ImplKind::Auto, }), cfg: None, }) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 843dda324da7f..f44589f60675f 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -106,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { visibility: Inherited, def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, kind: box ImplItem(Impl { - span: Span::new(self.cx.tcx.def_span(impl_def_id)), unsafety: hir::Unsafety::Normal, generics: ( self.cx.tcx.generics_of(impl_def_id), @@ -122,11 +121,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .tcx .associated_items(impl_def_id) .in_definition_order() - .collect::>() - .clean(self.cx), - negative_polarity: false, - synthetic: false, - blanket_impl: Some(box trait_ref.self_ty().clean(self.cx)), + .map(|x| x.clean(self.cx)) + .collect::>(), + polarity: ty::ImplPolarity::Positive, + kind: ImplKind::Blanket(box trait_ref.self_ty().clean(self.cx)), }), cfg: None, }); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index cb70f465f62b1..d670288270a40 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -14,7 +14,9 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{kw, sym, Symbol}; -use crate::clean::{self, utils, Attributes, AttributesExt, ItemId, NestedAttributesExt, Type}; +use crate::clean::{ + self, utils, Attributes, AttributesExt, ImplKind, ItemId, NestedAttributesExt, Type, +}; use crate::core::DocContext; use crate::formats::item_type::ItemType; @@ -242,7 +244,7 @@ fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum { clean::Enum { generics: (cx.tcx.generics_of(did), predicates).clean(cx), variants_stripped: false, - variants: cx.tcx.adt_def(did).variants.clean(cx), + variants: cx.tcx.adt_def(did).variants.iter().map(|v| v.clean(cx)).collect(), } } @@ -253,7 +255,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct { clean::Struct { struct_type: variant.ctor_kind, generics: (cx.tcx.generics_of(did), predicates).clean(cx), - fields: variant.fields.clean(cx), + fields: variant.fields.iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, } } @@ -262,11 +264,9 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union { let predicates = cx.tcx.explicit_predicates_of(did); let variant = cx.tcx.adt_def(did).non_enum_variant(); - clean::Union { - generics: (cx.tcx.generics_of(did), predicates).clean(cx), - fields: variant.fields.clean(cx), - fields_stripped: false, - } + let generics = (cx.tcx.generics_of(did), predicates).clean(cx); + let fields = variant.fields.iter().map(|x| x.clean(cx)).collect(); + clean::Union { generics, fields, fields_stripped: false } } fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { @@ -446,7 +446,7 @@ crate fn build_impl( ), }; let polarity = tcx.impl_polarity(did); - let trait_ = associated_trait.clean(cx); + let trait_ = associated_trait.map(|t| t.clean(cx)); if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() { super::build_deref_target_impls(cx, &trait_items, ret); } @@ -490,15 +490,13 @@ crate fn build_impl( did, None, clean::ImplItem(clean::Impl { - span: clean::types::rustc_span(did, cx.tcx), unsafety: hir::Unsafety::Normal, generics, trait_, for_, items: trait_items, - negative_polarity: polarity.clean(cx), - synthetic: false, - blanket_impl: None, + polarity, + kind: ImplKind::Normal, }), box merged_attrs, cx, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 62da44f0c984d..9d893f3d06d51 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -16,7 +16,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc_index::vec::{Idx, IndexVec}; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::fold::TypeFolder; @@ -34,7 +33,6 @@ use std::assert_matches::assert_matches; use std::collections::hash_map::Entry; use std::default::Default; use std::hash::Hash; -use std::rc::Rc; use std::{mem, vec}; use crate::core::{self, DocContext, ImplTraitParam}; @@ -56,36 +54,6 @@ crate trait Clean { fn clean(&self, cx: &mut DocContext<'_>) -> T; } -impl, U> Clean> for [T] { - fn clean(&self, cx: &mut DocContext<'_>) -> Vec { - self.iter().map(|x| x.clean(cx)).collect() - } -} - -impl, U, V: Idx> Clean> for IndexVec { - fn clean(&self, cx: &mut DocContext<'_>) -> IndexVec { - self.iter().map(|x| x.clean(cx)).collect() - } -} - -impl, U> Clean for &T { - fn clean(&self, cx: &mut DocContext<'_>) -> U { - (**self).clean(cx) - } -} - -impl, U> Clean for Rc { - fn clean(&self, cx: &mut DocContext<'_>) -> U { - (**self).clean(cx) - } -} - -impl, U> Clean> for Option { - fn clean(&self, cx: &mut DocContext<'_>) -> Option { - self.as_ref().map(|v| v.clean(cx)) - } -} - impl Clean for doctree::Module<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> Item { let mut items: Vec = vec![]; @@ -287,14 +255,14 @@ impl Clean for hir::WherePredicate<'_> { .collect(); WherePredicate::BoundPredicate { ty: wbp.bounded_ty.clean(cx), - bounds: wbp.bounds.clean(cx), + bounds: wbp.bounds.iter().map(|x| x.clean(cx)).collect(), bound_params, } } hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate { lifetime: wrp.lifetime.clean(cx), - bounds: wrp.bounds.clean(cx), + bounds: wrp.bounds.iter().map(|x| x.clean(cx)).collect(), }, hir::WherePredicate::EqPredicate(ref wrp) => { @@ -459,8 +427,8 @@ impl Clean for hir::GenericParam<'_> { self.name.ident().name, GenericParamDefKind::Type { did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(), - bounds: self.bounds.clean(cx), - default: default.clean(cx).map(Box::new), + bounds: self.bounds.iter().map(|x| x.clean(cx)).collect(), + default: default.map(|t| t.clean(cx)).map(Box::new), synthetic, }, ), @@ -530,8 +498,10 @@ impl Clean for hir::Generics<'_> { } params.extend(impl_trait_params); - let mut generics = - Generics { params, where_predicates: self.where_clause.predicates.clean(cx) }; + let mut generics = Generics { + params, + where_predicates: self.where_clause.predicates.iter().map(|x| x.clean(cx)).collect(), + }; // Some duplicates are generated for ?Sized bounds between type params and where // predicates. The point in here is to move the bounds definitions from type params @@ -900,7 +870,7 @@ impl Clean for hir::PolyTraitRef<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> PolyTrait { PolyTrait { trait_: self.trait_ref.clean(cx), - generic_params: self.bound_generic_params.clean(cx), + generic_params: self.bound_generic_params.iter().map(|x| x.clean(cx)).collect(), } } } @@ -935,7 +905,9 @@ impl Clean for hir::TraitItem<'_> { TyMethodItem(t) } hir::TraitItemKind::Type(bounds, ref default) => { - AssocTypeItem(bounds.clean(cx), default.clean(cx)) + let bounds = bounds.iter().map(|x| x.clean(cx)).collect(); + let default = default.map(|t| t.clean(cx)); + AssocTypeItem(bounds, default) } }; let what_rustc_thinks = @@ -1127,7 +1099,7 @@ impl Clean for ty::AssocItem { None }; - AssocTypeItem(bounds, ty.clean(cx)) + AssocTypeItem(bounds, ty.map(|t| t.clean(cx))) } else { // FIXME: when could this happen? Associated items in inherent impls? let type_ = tcx.type_of(self.def_id).clean(cx); @@ -1269,7 +1241,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type { let trait_def = cx.tcx.associated_item(p.res.def_id()).container.id(); let trait_ = self::Path { res: Res::Def(DefKind::Trait, trait_def), - segments: trait_segments.clean(cx), + segments: trait_segments.iter().map(|x| x.clean(cx)).collect(), }; register_res(cx, trait_.res); Type::QPath { @@ -1335,11 +1307,11 @@ impl Clean for hir::Ty<'_> { let length = print_const(cx, ct.eval(cx.tcx, param_env)); Array(box ty.clean(cx), length) } - TyKind::Tup(tys) => Tuple(tys.clean(cx)), + TyKind::Tup(tys) => Tuple(tys.iter().map(|x| x.clean(cx)).collect()), TyKind::OpaqueDef(item_id, _) => { let item = cx.tcx.hir().item(item_id); if let hir::ItemKind::OpaqueTy(ref ty) = item.kind { - ImplTrait(ty.bounds.clean(cx)) + ImplTrait(ty.bounds.iter().map(|x| x.clean(cx)).collect()) } else { unreachable!() } @@ -1479,7 +1451,7 @@ impl<'tcx> Clean for Ty<'tcx> { DynTrait(bounds, lifetime) } - ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty()).collect::>().clean(cx)), + ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty().clean(cx)).collect()), ty::Projection(ref data) => data.clean(cx), @@ -1712,7 +1684,7 @@ impl Clean for hir::VariantData<'_> { impl Clean for hir::Path<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> Path { - Path { res: self.res, segments: self.segments.clean(cx) } + Path { res: self.res, segments: self.segments.iter().map(|x| x.clean(cx)).collect() } } } @@ -1722,24 +1694,24 @@ impl Clean for hir::GenericArgs<'_> { let output = self.bindings[0].ty().clean(cx); let output = if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None }; - GenericArgs::Parenthesized { inputs: self.inputs().clean(cx), output } + let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect(); + GenericArgs::Parenthesized { inputs, output } } else { - GenericArgs::AngleBracketed { - args: self - .args - .iter() - .map(|arg| match arg { - hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { - GenericArg::Lifetime(lt.clean(cx)) - } - hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), - hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), - hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))), - hir::GenericArg::Infer(_inf) => GenericArg::Infer, - }) - .collect(), - bindings: self.bindings.clean(cx), - } + let args = self + .args + .iter() + .map(|arg| match arg { + hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { + GenericArg::Lifetime(lt.clean(cx)) + } + hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), + hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), + hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))), + hir::GenericArg::Infer(_inf) => GenericArg::Infer, + }) + .collect(); + let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect(); + GenericArgs::AngleBracketed { args, bindings } } } } @@ -1753,7 +1725,9 @@ impl Clean for hir::PathSegment<'_> { impl Clean for hir::BareFnTy<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> BareFunctionDecl { let (generic_params, decl) = enter_impl_trait(cx, |cx| { - (self.generic_params.clean(cx), (&*self.decl, self.param_names).clean(cx)) + let generic_params = self.generic_params.iter().map(|x| x.clean(cx)).collect(); + let decl = (self.decl, self.param_names).clean(cx); + (generic_params, decl) }); BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params } } @@ -1776,7 +1750,7 @@ impl Clean> for (&hir::Item<'_>, Option) { kind: ConstantKind::Local { body: body_id, def_id }, }), ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { - bounds: ty.bounds.clean(cx), + bounds: ty.bounds.iter().map(|x| x.clean(cx)).collect(), generics: ty.generics.clean(cx), }), ItemKind::TyAlias(hir_ty, ref generics) => { @@ -1798,17 +1772,17 @@ impl Clean> for (&hir::Item<'_>, Option) { }), ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias { generics: generics.clean(cx), - bounds: bounds.clean(cx), + bounds: bounds.iter().map(|x| x.clean(cx)).collect(), }), ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union { generics: generics.clean(cx), - fields: variant_data.fields().clean(cx), + fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, }), ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct { struct_type: CtorKind::from_hir(variant_data), generics: generics.clean(cx), - fields: variant_data.fields().clean(cx), + fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, }), ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx), @@ -1817,7 +1791,7 @@ impl Clean> for (&hir::Item<'_>, Option) { clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } ItemKind::Macro(ref macro_def) => MacroItem(Macro { - source: display_macro_source(cx, name, macro_def, def_id, &item.vis), + source: display_macro_source(cx, name, macro_def, def_id, item.vis), }), ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => { let items = item_ids @@ -1828,7 +1802,7 @@ impl Clean> for (&hir::Item<'_>, Option) { unsafety, items, generics: generics.clean(cx), - bounds: bounds.clean(cx), + bounds: bounds.iter().map(|x| x.clean(cx)).collect(), is_auto: is_auto.clean(cx), }) } @@ -1856,22 +1830,10 @@ impl Clean for hir::Variant<'_> { } } -impl Clean for ty::ImplPolarity { - /// Returns whether the impl has negative polarity. - fn clean(&self, _: &mut DocContext<'_>) -> bool { - match self { - &ty::ImplPolarity::Positive | - // FIXME: do we want to do something else here? - &ty::ImplPolarity::Reservation => false, - &ty::ImplPolarity::Negative => true, - } - } -} - fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_>) -> Vec { let tcx = cx.tcx; let mut ret = Vec::new(); - let trait_ = impl_.of_trait.clean(cx); + let trait_ = impl_.of_trait.as_ref().map(|t| t.clean(cx)); let items = impl_.items.iter().map(|ii| tcx.hir().impl_item(ii.id).clean(cx)).collect::>(); let def_id = tcx.hir().local_def_id(hir_id); @@ -1889,15 +1851,13 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_> }); let mut make_item = |trait_: Option, for_: Type, items: Vec| { let kind = ImplItem(Impl { - span: types::rustc_span(tcx.hir().local_def_id(hir_id).to_def_id(), tcx), unsafety: impl_.unsafety, generics: impl_.generics.clean(cx), trait_, for_, items, - negative_polarity: tcx.impl_polarity(def_id).clean(cx), - synthetic: false, - blanket_impl: None, + polarity: tcx.impl_polarity(def_id), + kind: ImplKind::Normal, }); Item::from_hir_id_and_parts(hir_id, None, kind, cx) }; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 56ae43855de92..0dc1c24b16e19 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -391,12 +391,19 @@ impl Item { ItemKind::StrippedItem(k) => k, _ => &*self.kind, }; - if let ItemKind::ModuleItem(Module { span, .. }) | ItemKind::ImplItem(Impl { span, .. }) = - kind - { - *span - } else { - self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy) + match kind { + ItemKind::ModuleItem(Module { span, .. }) => *span, + ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(), + ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => { + if let ItemId::Blanket { impl_id, .. } = self.def_id { + rustc_span(impl_id, tcx) + } else { + panic!("blanket impl item has non-blanket ID") + } + } + _ => { + self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy) + } } } @@ -2165,15 +2172,13 @@ impl Constant { #[derive(Clone, Debug)] crate struct Impl { - crate span: Span, crate unsafety: hir::Unsafety, crate generics: Generics, crate trait_: Option, crate for_: Type, crate items: Vec, - crate negative_polarity: bool, - crate synthetic: bool, - crate blanket_impl: Option>, + crate polarity: ty::ImplPolarity, + crate kind: ImplKind, } impl Impl { @@ -2186,6 +2191,30 @@ impl Impl { } } +#[derive(Clone, Debug)] +crate enum ImplKind { + Normal, + Auto, + Blanket(Box), +} + +impl ImplKind { + crate fn is_auto(&self) -> bool { + matches!(self, ImplKind::Auto) + } + + crate fn is_blanket(&self) -> bool { + matches!(self, ImplKind::Blanket(_)) + } + + crate fn as_blanket_ty(&self) -> Option<&Type> { + match self { + ImplKind::Blanket(ty) => Some(ty), + _ => None, + } + } +} + #[derive(Clone, Debug)] crate struct Import { crate kind: ImportKind, diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 6b9c9a9669b1a..a929cd094f8c3 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -228,7 +228,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { // Collect all the implementors of traits. if let clean::ImplItem(ref i) = *item.kind { if let Some(trait_) = &i.trait_ { - if i.blanket_impl.is_none() { + if !i.kind.is_blanket() { self.cache .implementors .entry(trait_.def_id()) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index c51bda60b7385..4f2049132046d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -14,6 +14,7 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_middle::ty; use rustc_middle::ty::TyCtxt; use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_target::spec::abi::Abi; @@ -990,14 +991,15 @@ impl clean::Impl { } if let Some(ref ty) = self.trait_ { - if self.negative_polarity { - write!(f, "!")?; + match self.polarity { + ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => {} + ty::ImplPolarity::Negative => write!(f, "!")?, } fmt::Display::fmt(&ty.print(cx), f)?; write!(f, " for ")?; } - if let Some(ref ty) = self.blanket_impl { + if let Some(ref ty) = self.kind.as_blanket_ty() { fmt_type(ty, f, use_absolute, cx)?; } else { fmt_type(&self.for_, f, use_absolute, cx)?; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 25fef114d95fd..fdadc68998dc6 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -34,8 +34,8 @@ mod span_map; mod templates; mod write_shared; -crate use context::*; -crate use span_map::{collect_spans_and_sources, LinkFromSrc}; +crate use self::context::*; +crate use self::span_map::{collect_spans_and_sources, LinkFromSrc}; use std::collections::VecDeque; use std::default::Default; @@ -54,6 +54,7 @@ use rustc_hir::def::CtorKind; use rustc_hir::def_id::DefId; use rustc_hir::Mutability; use rustc_middle::middle::stability; +use rustc_middle::ty; use rustc_middle::ty::TyCtxt; use rustc_span::{ symbol::{kw, sym, Symbol}, @@ -1147,9 +1148,9 @@ fn render_assoc_items_inner( } let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = - traits.iter().partition(|t| t.inner_impl().synthetic); + traits.iter().partition(|t| t.inner_impl().kind.is_auto()); let (blanket_impl, concrete): (Vec<&&Impl>, _) = - concrete.into_iter().partition(|t| t.inner_impl().blanket_impl.is_some()); + concrete.into_iter().partition(|t| t.inner_impl().kind.is_blanket()); let mut impls = Buffer::empty_from(w); render_impls(cx, &mut impls, &concrete, containing_item); @@ -2033,12 +2034,12 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { let i_display = format!("{:#}", i.print(cx)); let out = Escape(&i_display); let encoded = small_url_encode(format!("{:#}", i.print(cx))); - let generated = format!( - "{}{}", - encoded, - if it.inner_impl().negative_polarity { "!" } else { "" }, - out - ); + let prefix = match it.inner_impl().polarity { + ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "", + ty::ImplPolarity::Negative => "!", + }; + let generated = + format!("{}{}", encoded, prefix, out); if links.insert(generated.clone()) { Some(generated) } else { None } } else { None @@ -2058,10 +2059,9 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { }; let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) = - v.iter().partition::, _>(|i| i.inner_impl().synthetic); - let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) = concrete - .into_iter() - .partition::, _>(|i| i.inner_impl().blanket_impl.is_some()); + v.iter().partition::, _>(|i| i.inner_impl().kind.is_auto()); + let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) = + concrete.into_iter().partition::, _>(|i| i.inner_impl().kind.is_blanket()); let concrete_format = format_impls(concrete); let synthetic_format = format_impls(synthetic); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d07ef6db4c6b0..7ef773fe5ff29 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -746,7 +746,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra }); let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = - local.iter().partition(|i| i.inner_impl().synthetic); + local.iter().partition(|i| i.inner_impl().kind.is_auto()); synthetic.sort_by(|a, b| compare_impl(a, b, cx)); concrete.sort_by(|a, b| compare_impl(a, b, cx)); diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 978701746b75b..2d3b2490677e9 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -585,7 +585,7 @@ pub(super) fn write_shared( } else { Some(Implementor { text: imp.inner_impl().print(false, cx).to_string(), - synthetic: imp.inner_impl().synthetic, + synthetic: imp.inner_impl().kind.is_auto(), types: collect_paths_for_type(imp.inner_impl().for_.clone(), cache), }) } diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index f740ecdbded74..a46518ef489aa 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -9,7 +9,7 @@ use std::fmt; use rustc_ast::ast; use rustc_hir::{def::CtorKind, def_id::DefId}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{self, TyCtxt}; use rustc_span::def_id::CRATE_DEF_INDEX; use rustc_span::Pos; @@ -500,22 +500,22 @@ impl FromWithTcx for Trait { impl FromWithTcx for Impl { fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self { let provided_trait_methods = impl_.provided_trait_methods(tcx); - let clean::Impl { - unsafety, - generics, - trait_, - for_, - items, - negative_polarity, - synthetic, - blanket_impl, - span: _span, - } = impl_; + let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_; // FIXME: should `trait_` be a clean::Path equivalent in JSON? let trait_ = trait_.map(|path| { let did = path.def_id(); clean::ResolvedPath { path, did }.into_tcx(tcx) }); + // FIXME: use something like ImplKind in JSON? + let (synthetic, blanket_impl) = match kind { + clean::ImplKind::Normal => (false, None), + clean::ImplKind::Auto => (true, None), + clean::ImplKind::Blanket(ty) => (false, Some(*ty)), + }; + let negative_polarity = match polarity { + ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => false, + ty::ImplPolarity::Negative => true, + }; Impl { is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe, generics: generics.into_tcx(tcx), @@ -528,7 +528,7 @@ impl FromWithTcx for Impl { items: ids(items), negative: negative_polarity, synthetic, - blanket_impl: blanket_impl.map(|x| (*x).into_tcx(tcx)), + blanket_impl: blanket_impl.map(|x| x.into_tcx(tcx)), } } } diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 77513b05ff2f9..ea50134f00d47 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -111,12 +111,12 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate } new_items.retain(|it| { - if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = *it.kind { + if let ImplItem(Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind { cleaner.keep_impl( for_, trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(), ) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into())) - || blanket_impl.is_some() + || kind.is_blanket() } else { true }