Skip to content

Commit

Permalink
Fix another query panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Oct 31, 2024
1 parent b0d1bf7 commit 156c862
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions frontend/exporter/src/types/new/full_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub enum FullDefKind<Body> {
},
/// An `extern` block.
ForeignMod {
#[value(get_mod_children(s.base().tcx, s.owner_id()).sinto(s))]
#[value(get_foreign_mod_children(s.base().tcx, s.owner_id()).sinto(s))]
items: Vec<DefId>,
},

Expand Down Expand Up @@ -538,14 +538,6 @@ fn get_mod_children<'tcx>(tcx: ty::TyCtxt<'tcx>, def_id: RDefId) -> Vec<RDefId>
.iter()
.map(|item_id| item_id.owner_id.to_def_id())
.collect(),

rustc_hir::Node::Item(rustc_hir::Item {
kind: rustc_hir::ItemKind::ForeignMod { items, .. },
..
}) => items
.iter()
.map(|foreign_item_ref| foreign_item_ref.id.owner_id.to_def_id())
.collect(),
node => panic!("DefKind::Module is an unexpected node: {node:?}"),
},
None => tcx
Expand All @@ -556,6 +548,22 @@ fn get_mod_children<'tcx>(tcx: ty::TyCtxt<'tcx>, def_id: RDefId) -> Vec<RDefId>
}
}

/// Gets the children of an `extern` block. Empty if the block is not defined in the current crate.
#[cfg(feature = "rustc")]
fn get_foreign_mod_children<'tcx>(tcx: ty::TyCtxt<'tcx>, def_id: RDefId) -> Vec<RDefId> {
match def_id.as_local() {
Some(ldid) => tcx
.hir_node_by_def_id(ldid)
.expect_item()
.expect_foreign_mod()
.1
.iter()
.map(|foreign_item_ref| foreign_item_ref.id.owner_id.to_def_id())
.collect(),
None => vec![],
}
}

/// This normalizes trait clauses before calling `sinto` on them. This is a bit of a hack required
/// by charon for now. We can't normalize all clauses as this would lose region information in
/// outlives clauses.
Expand Down

0 comments on commit 156c862

Please sign in to comment.