diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-10-04 23:56:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-04 23:56:16 -0700 |
| commit | 7a09755148c4b1543f25862e785e04834feb8b61 (patch) | |
| tree | cf7ed9b36935bb86960652089881ef77e4fd671d | |
| parent | 0fb01224dd6d1966ca4f64416e092243ae19ec84 (diff) | |
| parent | e18a8efb8b8b87eb2576a12176c45dd59e5c5d18 (diff) | |
| download | rust-7a09755148c4b1543f25862e785e04834feb8b61.tar.gz rust-7a09755148c4b1543f25862e785e04834feb8b61.zip | |
Rollup merge of #88234 - hkmatsumoto:rustdoc-impls-for-primitive, r=jyn514
rustdoc-json: Don't ignore impls for primitive types Fix the issue discussed at [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.E2.9C.94.20Json.20output.20lacks.20some.20item.20which.20are.20supposed.20to.20be.20there) r? ``@jyn514``
| -rw-r--r-- | src/librustdoc/json/conversions.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/json/mod.rs | 23 | ||||
| -rw-r--r-- | src/rustdoc-json-types/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/rustdoc-json/primitive.rs | 14 |
4 files changed, 39 insertions, 3 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index ea81b041c3b..731fc4ff3ce 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -218,6 +218,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)), MacroItem(m) => ItemEnum::Macro(m.source), ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)), + PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()), AssocConstItem(t, s) => ItemEnum::AssocConst { type_: t.into_tcx(tcx), default: s }, AssocTypeItem(g, t) => ItemEnum::AssocType { bounds: g.into_iter().map(|x| x.into_tcx(tcx)).collect(), @@ -225,7 +226,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { }, // `convert_item` early returns `None` for striped items StrippedItem(_) => unreachable!(), - PrimitiveItem(_) | KeywordItem(_) => { + KeywordItem(_) => { panic!("{:?} is not supported for JSON output", item) } ExternCrateItem { ref src } => ItemEnum::ExternCrate { diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 915a9fd2b89..040a880ace9 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -69,7 +69,21 @@ impl JsonRenderer<'tcx> { .iter() .filter_map(|i| { let item = &i.impl_item; - if item.def_id.is_local() { + + // HACK(hkmatsumoto): For impls of primitive types, we index them + // regardless of whether they're local. This is because users can + // document primitive items in an arbitrary crate by using + // `doc(primitive)`. + let mut is_primitive_impl = false; + if let clean::types::ItemKind::ImplItem(ref impl_) = *item.kind { + if impl_.trait_.is_none() { + if let clean::types::Type::Primitive(_) = impl_.for_ { + is_primitive_impl = true; + } + } + } + + if item.def_id.is_local() || is_primitive_impl { self.item(item.clone()).unwrap(); Some(from_item_id(item.def_id)) } else { @@ -191,6 +205,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { fn after_krate(&mut self) -> Result<(), Error> { debug!("Done with crate"); + + for primitive in Rc::clone(&self.cache).primitive_locations.values() { + self.get_impls(primitive.clone()); + } + let mut index = (*self.index).clone().into_inner(); index.extend(self.get_trait_items()); // This needs to be the default HashMap for compatibility with the public interface for @@ -236,7 +255,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .collect(), - format_version: 7, + format_version: 8, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 37cdc94441d..22debd296c2 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -221,6 +221,8 @@ pub enum ItemEnum { Macro(String), ProcMacro(ProcMacro), + PrimitiveType(String), + AssocConst { #[serde(rename = "type")] type_: Type, diff --git a/src/test/rustdoc-json/primitive.rs b/src/test/rustdoc-json/primitive.rs new file mode 100644 index 00000000000..3a7d6d18c1b --- /dev/null +++ b/src/test/rustdoc-json/primitive.rs @@ -0,0 +1,14 @@ +// edition:2018 + +#![feature(doc_primitive)] + +#[doc(primitive = "usize")] +mod usize {} + +// @set local_crate_id = primitive.json "$.index[*][?(@.name=='primitive')].crate_id" + +// @has - "$.index[*][?(@.name=='log10')]" +// @!is - "$.index[*][?(@.name=='log10')].crate_id" $local_crate_id +// @has - "$.index[*][?(@.name=='checked_add')]" +// @!is - "$.index[*][?(@.name=='checked_add')]" $local_crate_id +// @!has - "$.index[*][?(@.name=='is_ascii_uppercase')]" |
