Skip to content

Commit

Permalink
Refactor from_clean_item_kind to improve ExternCrateItem handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 5, 2021
1 parent f879ecc commit 286a357
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ impl JsonRenderer<'_> {
let deprecation = item.deprecation(self.tcx);
let clean::Item { source, name, attrs, kind, visibility, def_id } = item;
let inner = match *kind {
clean::ItemKind::ExternCrateItem { ref src } => ItemEnum::ExternCrateItem {
name: name.as_ref().unwrap().to_string(),
rename: src.map(|x| x.to_string()),
},
clean::StrippedItem(_) => return None,
x => from_clean_item_kind(x, self.tcx),
x => from_clean_item_kind(x, self.tcx, &name),
};
Some(Item {
id: from_def_id(def_id),
Expand Down Expand Up @@ -155,7 +151,7 @@ crate fn from_def_id(did: DefId) -> Id {
Id(format!("{}:{}", did.krate.as_u32(), u32::from(did.index)))
}

fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>, name: &Option<Symbol>) -> ItemEnum {
use clean::ItemKind::*;
match item {
ModuleItem(m) => ItemEnum::ModuleItem(m.into()),
Expand Down Expand Up @@ -185,11 +181,14 @@ fn from_clean_item_kind(item: clean::ItemKind, tcx: TyCtxt<'_>) -> ItemEnum {
bounds: g.into_iter().map(Into::into).collect(),
default: t.map(Into::into),
},
StrippedItem(inner) => from_clean_item_kind(*inner, tcx),
StrippedItem(inner) => from_clean_item_kind(*inner, tcx, name),
PrimitiveItem(_) | KeywordItem(_) => {
panic!("{:?} is not supported for JSON output", item)
}
ExternCrateItem { .. } => unreachable!(),
ExternCrateItem { ref src } => ItemEnum::ExternCrateItem {
name: name.as_ref().unwrap().to_string(),
rename: src.map(|x| x.to_string()),
},
}
}

Expand Down

0 comments on commit 286a357

Please sign in to comment.