Skip to content

Commit e68a2da

Browse files
committed
Auto merge of #158002 - bushrat011899:get_module_children_unwrap, r=oli-obk
Fix(ICE): Remove `unwrap` from `get_module_children` # Objective Fix an ICE I ran into while developing rust-lang/rust-clippy#17252 that stems from `rustc_metadata::rmeta::decoder::CrateMetadata::get_module_children` calling `unwrap`. The local value `non_reexports` can be `None` when the passed in `DefIndex` is for a non-module-like item. The documentation for `get_module_children` *implies* that it must only be called with module-like item indices, however it seems to me that it would be appropriate to just return nothing when called on a non-module-like item (if it isn't module-like, it has zero children). ## Solution - Switched from an `Option::unwrap` to an `if let Some(...)` --- ## Notes * No AI tooling of any kind was used during the creation of this PR. * Please see [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/.E2.9C.94.20.60rustc.60.20ICE.20from.20.60TyCtxt.3A.3Amodule_children.60/with/603700184) for some discussion. * Please see this [failed Clippy CI run](https://github.com/rust-lang/rust-clippy/actions/runs/27596428127/job/81587609898#step:5:1) for an example of the ICE caused.
2 parents 98594f4 + b6fc0c3 commit e68a2da

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,10 @@ impl CrateMetadata {
12871287
} else {
12881288
// Iterate over all children.
12891289
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
1290-
for child_index in non_reexports.unwrap().decode((self, tcx)) {
1291-
yield self.get_mod_child(tcx, child_index);
1290+
if let Some(non_reexports) = non_reexports {
1291+
for child_index in non_reexports.decode((self, tcx)) {
1292+
yield self.get_mod_child(tcx, child_index);
1293+
}
12921294
}
12931295

12941296
let reexports = self.root.tables.module_children_reexports.get(self, id);

0 commit comments

Comments
 (0)