-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler #80845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use rustc_ast::ast; | |
use rustc_hir::def::CtorKind; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX}; | ||
use rustc_span::symbol::Symbol; | ||
use rustc_span::Pos; | ||
|
||
use rustdoc_json_types::*; | ||
|
@@ -25,32 +26,33 @@ impl JsonRenderer<'_> { | |
let item_type = ItemType::from(&item); | ||
let deprecation = item.deprecation(self.tcx); | ||
let clean::Item { source, name, attrs, kind, visibility, def_id } = item; | ||
match *kind { | ||
clean::StrippedItem(_) => None, | ||
kind => Some(Item { | ||
id: from_def_id(def_id), | ||
crate_id: def_id.krate.as_u32(), | ||
name: name.map(|sym| sym.to_string()), | ||
source: self.convert_span(source), | ||
visibility: self.convert_visibility(visibility), | ||
docs: attrs.collapsed_doc_value(), | ||
links: attrs | ||
.links | ||
.into_iter() | ||
.filter_map(|clean::ItemLink { link, did, .. }| { | ||
did.map(|did| (link, from_def_id(did))) | ||
}) | ||
.collect(), | ||
attrs: attrs | ||
.other_attrs | ||
.iter() | ||
.map(rustc_ast_pretty::pprust::attribute_to_string) | ||
.collect(), | ||
deprecation: deprecation.map(from_deprecation), | ||
kind: item_type.into(), | ||
inner: from_clean_item_kind(kind, self.tcx), | ||
}), | ||
} | ||
let inner = match *kind { | ||
clean::StrippedItem(_) => return None, | ||
x => from_clean_item_kind(x, self.tcx, &name), | ||
}; | ||
Some(Item { | ||
id: from_def_id(def_id), | ||
crate_id: def_id.krate.as_u32(), | ||
name: name.map(|sym| sym.to_string()), | ||
source: self.convert_span(source), | ||
visibility: self.convert_visibility(visibility), | ||
docs: attrs.collapsed_doc_value(), | ||
links: attrs | ||
.links | ||
.into_iter() | ||
.filter_map(|clean::ItemLink { link, did, .. }| { | ||
did.map(|did| (link, from_def_id(did))) | ||
}) | ||
.collect(), | ||
attrs: attrs | ||
.other_attrs | ||
.iter() | ||
.map(rustc_ast_pretty::pprust::attribute_to_string) | ||
.collect(), | ||
deprecation: deprecation.map(from_deprecation), | ||
kind: item_type.into(), | ||
inner, | ||
}) | ||
} | ||
|
||
fn convert_span(&self, span: clean::Span) -> Option<Span> { | ||
|
@@ -149,13 +151,10 @@ 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()), | ||
ExternCrateItem(c, a) => { | ||
ItemEnum::ExternCrateItem { name: c.to_string(), rename: a.map(|x| x.to_string()) } | ||
} | ||
ImportItem(i) => ItemEnum::ImportItem(i.into()), | ||
StructItem(s) => ItemEnum::StructItem(s.into()), | ||
UnionItem(u) => ItemEnum::UnionItem(u.into()), | ||
|
@@ -182,10 +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 { ref src } => ItemEnum::ExternCrateItem { | ||
name: name.as_ref().unwrap().to_string(), | ||
rename: src.map(|x| x.to_string()), | ||
}, | ||
Comment on lines
+188
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, this is what I was expecting, thanks :) |
||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.