Skip to content

Commit 12f1821

Browse files
authored
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
2 parents f03ce30 + 1b6f629 commit 12f1821

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -681,24 +681,18 @@ impl FromWithTcx<clean::Variant> for Variant {
681681
impl FromWithTcx<clean::Import> for Import {
682682
fn from_tcx(import: clean::Import, tcx: TyCtxt<'_>) -> Self {
683683
use clean::ImportKind::*;
684-
match import.kind {
685-
Simple(s) => Import {
686-
source: import.source.path.whole_name(),
687-
name: s.to_string(),
688-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
689-
glob: false,
690-
},
691-
Glob => Import {
692-
source: import.source.path.whole_name(),
693-
name: import
694-
.source
695-
.path
696-
.last_opt()
697-
.unwrap_or_else(|| Symbol::intern("*"))
698-
.to_string(),
699-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
700-
glob: true,
701-
},
684+
let (name, glob) = match import.kind {
685+
Simple(s) => (s.to_string(), false),
686+
Glob => (
687+
import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
688+
true,
689+
),
690+
};
691+
Import {
692+
source: import.source.path.whole_name(),
693+
name,
694+
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
695+
glob,
702696
}
703697
}
704698
}

src/rustdoc-json-types/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,11 @@ pub struct Import {
561561
/// May be different from the last segment of `source` when renaming imports:
562562
/// `use source as name;`
563563
pub name: String,
564-
/// The ID of the item being imported.
565-
pub id: Option<Id>, // FIXME is this actually ever None?
564+
/// The ID of the item being imported. Will be `None` in case of re-exports of primitives:
565+
/// ```rust
566+
/// pub use i32 as my_i32;
567+
/// ```
568+
pub id: Option<Id>,
566569
/// Whether this import uses a glob: `use source::*;`
567570
pub glob: bool,
568571
}

src/test/rustdoc-json/primitive.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ mod usize {}
1212
// @has - "$.index[*][?(@.name=='checked_add')]"
1313
// @!is - "$.index[*][?(@.name=='checked_add')]" $local_crate_id
1414
// @!has - "$.index[*][?(@.name=='is_ascii_uppercase')]"
15+
16+
// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='my_i32')].inner.id" null
17+
pub use i32 as my_i32;
18+
19+
// @is - "$.index[*][?(@.kind=='import' && @.inner.name=='u32')].inner.id" null
20+
pub use u32;

0 commit comments

Comments
 (0)