Skip to content

Commit

Permalink
Rollup merge of #98390 - GuillaumeGomez:keyword-rustdoc-json, r=notri…
Browse files Browse the repository at this point in the history
…ddle

Fixes handling of keywords in rustdoc json output

Fixes #98002.

Instead of panicking, we just filter them out.

cc ```@matthiaskrgr```
r? ```@notriddle```
  • Loading branch information
compiler-errors committed Jun 23, 2022
2 parents aafddd2 + 75ad2f7 commit 5620983
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl JsonRenderer<'_> {
let span = item.span(self.tcx);
let clean::Item { name, attrs: _, kind: _, visibility, item_id, cfg: _ } = item;
let inner = match *item.kind {
clean::StrippedItem(_) => return None,
clean::StrippedItem(_) | clean::KeywordItem(_) => return None,
_ => from_clean_item(item, self.tcx),
};
Some(Item {
Expand Down Expand Up @@ -254,11 +254,8 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
},
// FIXME: do not map to Typedef but to a custom variant
AssocTypeItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
// `convert_item` early returns `None` for striped items
StrippedItem(_) => unreachable!(),
KeywordItem(_) => {
panic!("{:?} is not supported for JSON output", item)
}
// `convert_item` early returns `None` for striped items and keywords.
StrippedItem(_) | KeywordItem(_) => unreachable!(),
ExternCrateItem { ref src } => ItemEnum::ExternCrate {
name: name.as_ref().unwrap().to_string(),
rename: src.map(|x| x.to_string()),
Expand Down Expand Up @@ -764,7 +761,7 @@ impl FromWithTcx<ItemType> for ItemKind {
fn ids(items: impl IntoIterator<Item = clean::Item>, tcx: TyCtxt<'_>) -> Vec<Id> {
items
.into_iter()
.filter(|x| !x.is_stripped())
.filter(|x| !x.is_stripped() && !x.is_keyword())
.map(|i| from_item_id_with_name(i.item_id, tcx, i.name))
.collect()
}
21 changes: 21 additions & 0 deletions src/test/rustdoc-json/keyword.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Regression test for <https://github.com/rust-lang/rust/issues/98002>.

// Keywords should not be generated in rustdoc JSON output and this test
// ensures it.

#![feature(rustdoc_internals)]
#![no_std]

// @has keyword.json
// @!has - "$.index[*][?(@.name=='match')]"
// @has - "$.index[*][?(@.name=='foo')]"

#[doc(keyword = "match")]
/// this is a test!
pub mod foo {}

// @!has - "$.index[*][?(@.name=='hello')]"
// @!has - "$.index[*][?(@.name=='bar')]"
#[doc(keyword = "hello")]
/// hello
mod bar {}

0 comments on commit 5620983

Please sign in to comment.