Skip to content

Commit d8953cd

Browse files
committed
Document Panic in get_module_children
Also replicated documentation on `TyCtxt::module_children`
1 parent 9e2abe0 commit d8953cd

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,10 @@ impl CrateMetadata {
12741274
/// including both proper items and reexports.
12751275
/// Module here is understood in name resolution sense - it can be a `mod` item,
12761276
/// or a crate root, or an enum, or a trait.
1277+
///
1278+
/// # Panics
1279+
///
1280+
/// May panic if the provided `id` does not refer to a module.
12771281
fn get_module_children(&self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Item = ModChild> {
12781282
gen move {
12791283
if let Some(data) = &self.root.proc_macro_data {
@@ -1287,7 +1291,9 @@ impl CrateMetadata {
12871291
} else {
12881292
// Iterate over all children.
12891293
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
1290-
for child_index in non_reexports.unwrap().decode((self, tcx)) {
1294+
let non_reexports =
1295+
non_reexports.expect("provided `DefIndex` must refer to a module-like item");
1296+
for child_index in non_reexports.decode((self, tcx)) {
12911297
yield self.get_mod_child(tcx, child_index);
12921298
}
12931299

compiler/rustc_middle/src/queries.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,15 @@ rustc_queries! {
21612161
desc { "fetching what a crate is named" }
21622162
separate_provide_extern
21632163
}
2164+
2165+
/// Iterates over all named children of the given module,
2166+
/// including both proper items and reexports.
2167+
/// Module here is understood in name resolution sense - it can be a `mod` item,
2168+
/// or a crate root, or an enum, or a trait.
2169+
///
2170+
/// # Panics
2171+
///
2172+
/// May panic if the provided `id` does not refer to a module.
21642173
query module_children(def_id: DefId) -> &'tcx [ModChild] {
21652174
desc { "collecting child items of module `{}`", tcx.def_path_str(def_id) }
21662175
separate_provide_extern

0 commit comments

Comments
 (0)