Skip to content

Commit 0dc39c7

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 02fc0fa + 1b6f629 commit 0dc39c7

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/librustdoc/json/conversions.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -685,24 +685,18 @@ impl FromWithTcx<clean::Variant> for Variant {
685685
impl FromWithTcx<clean::Import> for Import {
686686
fn from_tcx(import: clean::Import, tcx: TyCtxt<'_>) -> Self {
687687
use clean::ImportKind::*;
688-
match import.kind {
689-
Simple(s) => Import {
690-
source: import.source.path.whole_name(),
691-
name: s.to_string(),
692-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
693-
glob: false,
694-
},
695-
Glob => Import {
696-
source: import.source.path.whole_name(),
697-
name: import
698-
.source
699-
.path
700-
.last_opt()
701-
.unwrap_or_else(|| Symbol::intern("*"))
702-
.to_string(),
703-
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
704-
glob: true,
705-
},
688+
let (name, glob) = match import.kind {
689+
Simple(s) => (s.to_string(), false),
690+
Glob => (
691+
import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
692+
true,
693+
),
694+
};
695+
Import {
696+
source: import.source.path.whole_name(),
697+
name,
698+
id: import.source.did.map(ItemId::from).map(|i| from_item_id(i, tcx)),
699+
glob,
706700
}
707701
}
708702
}

src/rustdoc-json-types/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,11 @@ pub struct Import {
591591
/// May be different from the last segment of `source` when renaming imports:
592592
/// `use source as name;`
593593
pub name: String,
594-
/// The ID of the item being imported.
595-
pub id: Option<Id>, // FIXME is this actually ever None?
594+
/// The ID of the item being imported. Will be `None` in case of re-exports of primitives:
595+
/// ```rust
596+
/// pub use i32 as my_i32;
597+
/// ```
598+
pub id: Option<Id>,
596599
/// Whether this import uses a glob: `use source::*;`
597600
pub glob: bool,
598601
}

src/test/rustdoc-json/primitive.rs

+6
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)