Skip to content

Commit f8e85f1

Browse files
Rollup merge of rust-lang#98390 - GuillaumeGomez:keyword-rustdoc-json, r=notriddle
Fixes handling of keywords in rustdoc json output Fixes rust-lang#98002. Instead of panicking, we just filter them out. cc ``@matthiaskrgr`` r? ``@notriddle``
2 parents ba2f09e + 75ad2f7 commit f8e85f1

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/librustdoc/json/conversions.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl JsonRenderer<'_> {
4343
let span = item.span(self.tcx);
4444
let clean::Item { name, attrs: _, kind: _, visibility, item_id, cfg: _ } = item;
4545
let inner = match *item.kind {
46-
clean::StrippedItem(_) => return None,
46+
clean::StrippedItem(_) | clean::KeywordItem(_) => return None,
4747
_ => from_clean_item(item, self.tcx),
4848
};
4949
Some(Item {
@@ -254,11 +254,8 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
254254
},
255255
// FIXME: do not map to Typedef but to a custom variant
256256
AssocTypeItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
257-
// `convert_item` early returns `None` for striped items
258-
StrippedItem(_) => unreachable!(),
259-
KeywordItem(_) => {
260-
panic!("{:?} is not supported for JSON output", item)
261-
}
257+
// `convert_item` early returns `None` for striped items and keywords.
258+
StrippedItem(_) | KeywordItem(_) => unreachable!(),
262259
ExternCrateItem { ref src } => ItemEnum::ExternCrate {
263260
name: name.as_ref().unwrap().to_string(),
264261
rename: src.map(|x| x.to_string()),
@@ -764,7 +761,7 @@ impl FromWithTcx<ItemType> for ItemKind {
764761
fn ids(items: impl IntoIterator<Item = clean::Item>, tcx: TyCtxt<'_>) -> Vec<Id> {
765762
items
766763
.into_iter()
767-
.filter(|x| !x.is_stripped())
764+
.filter(|x| !x.is_stripped() && !x.is_keyword())
768765
.map(|i| from_item_id_with_name(i.item_id, tcx, i.name))
769766
.collect()
770767
}

src/test/rustdoc-json/keyword.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/98002>.
2+
3+
// Keywords should not be generated in rustdoc JSON output and this test
4+
// ensures it.
5+
6+
#![feature(rustdoc_internals)]
7+
#![no_std]
8+
9+
// @has keyword.json
10+
// @!has - "$.index[*][?(@.name=='match')]"
11+
// @has - "$.index[*][?(@.name=='foo')]"
12+
13+
#[doc(keyword = "match")]
14+
/// this is a test!
15+
pub mod foo {}
16+
17+
// @!has - "$.index[*][?(@.name=='hello')]"
18+
// @!has - "$.index[*][?(@.name=='bar')]"
19+
#[doc(keyword = "hello")]
20+
/// hello
21+
mod bar {}

0 commit comments

Comments
 (0)