Rollup merge of #99479 - Enselic:import-can-be-without-id, r=camelid

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

Also add some test and refactor related code a bit.

``@rustbot`` labels +A-rustdoc-json +T-rustdoc
This commit is contained in:
Matthias Krüger 2022-08-10 00:00:24 +02:00 committed by GitHub
commit 0dc39c7bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 20 deletions

View File

@ -685,24 +685,18 @@ fn from_tcx(variant: clean::Variant, tcx: TyCtxt<'_>) -> Self {
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,
}
}
}

View File

@ -591,8 +591,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,
}

View File

@ -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;