Skip to content
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

rustdoc-json: Remove doc FIXME for Import::id and explain #99479

Merged
merged 3 commits into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/librustdoc/json/conversions.rs
Expand Up @@ -679,24 +679,18 @@ impl FromWithTcx<clean::Variant> for Variant {
impl FromWithTcx<clean::Import> for Import {
fn from_tcx(import: clean::Import, tcx: TyCtxt<'_>) -> Self {
use clean::ImportKind::*;
match import.kind {
Simple(s) => Import {
source: import.source.path.whole_name(),
name: s.to_string(),
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
glob: false,
},
Glob => Import {
source: import.source.path.whole_name(),
name: import
.source
.path
.last_opt()
.unwrap_or_else(|| Symbol::intern("*"))
.to_string(),
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
glob: true,
},
let (name, glob) = match import.kind {
Simple(s) => (s.to_string(), false),
Glob => (
import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
true,
),
};
Import {
source: import.source.path.whole_name(),
name,
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
glob,
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/rustdoc-json-types/lib.rs
Expand Up @@ -561,8 +561,11 @@ pub struct Import {
/// May be different from the last segment of `source` when renaming imports:
/// `use source as name;`
pub name: String,
/// The ID of the item being imported.
pub id: Option<Id>, // FIXME is this actually ever None?
/// The ID of the item being imported. Will be `None` in case of re-exports of primitives:
/// ```rust
/// pub use i32 as my_i32;
/// ```
pub id: Option<Id>,
/// Whether this import uses a glob: `use source::*;`
pub glob: bool,
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc-json/primitive.rs
Expand Up @@ -12,3 +12,9 @@ mod usize {}
// @has - "$.index[*][?(@.name=='checked_add')]"
// @!is - "$.index[*][?(@.name=='checked_add')]" $local_crate_id
// @!has - "$.index[*][?(@.name=='is_ascii_uppercase')]"

// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='my_i32')].inner.id" null
pub use i32 as my_i32;

// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='u32')].inner.id" null
pub use u32;