Skip to content

Commit 4835f90

Browse files
committed
WfCheck opaques.
1 parent 6bdc396 commit 4835f90

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,24 @@ where
184184
}
185185
}
186186

187-
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorGuaranteed> {
188-
let node = tcx.hir_owner_node(def_id);
187+
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
188+
let node = tcx.hir_node_by_def_id(def_id);
189189
let mut res = match node {
190-
hir::OwnerNode::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
191-
hir::OwnerNode::Item(item) => check_item(tcx, item),
192-
hir::OwnerNode::TraitItem(item) => check_trait_item(tcx, item),
193-
hir::OwnerNode::ImplItem(item) => check_impl_item(tcx, item),
194-
hir::OwnerNode::ForeignItem(item) => check_foreign_item(tcx, item),
195-
hir::OwnerNode::Synthetic => unreachable!(),
190+
hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
191+
hir::Node::Item(item) => check_item(tcx, item),
192+
hir::Node::TraitItem(item) => check_trait_item(tcx, item),
193+
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
194+
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
195+
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
196+
_ => unreachable!(),
196197
};
197198

198199
if let Some(generics) = node.generics() {
199200
for param in generics.params {
200201
res = res.and(check_param_wf(tcx, param));
201202
}
202203
}
204+
203205
res
204206
}
205207

@@ -2119,10 +2121,14 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
21192121

21202122
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
21212123
let items = tcx.hir_module_items(module);
2122-
let mut res = items.par_items(|item| tcx.ensure().check_well_formed(item.owner_id));
2123-
res = res.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id)));
2124-
res = res.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id)));
2125-
res = res.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id)));
2124+
let mut res = items.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id));
2125+
res =
2126+
res.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2127+
res =
2128+
res.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2129+
res = res
2130+
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)));
2131+
res = res.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item)));
21262132
if module == LocalModDefId::CRATE_DEF_ID {
21272133
super::entry::check_for_entry_fn(tcx);
21282134
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
328328
intravisit::walk_expr(self, expr);
329329
}
330330

331+
/// Don't call `type_of` on opaque types, since that depends on type checking function bodies.
332+
/// `check_item_type` ensures that it's called instead.
333+
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
334+
let def_id = opaque.def_id;
335+
self.tcx.ensure().generics_of(def_id);
336+
self.tcx.ensure().predicates_of(def_id);
337+
self.tcx.ensure().explicit_item_bounds(def_id);
338+
self.tcx.ensure().explicit_item_super_predicates(def_id);
339+
self.tcx.ensure().item_bounds(def_id);
340+
self.tcx.ensure().item_super_predicates(def_id);
341+
intravisit::walk_opaque_ty(self, opaque);
342+
}
343+
331344
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
332345
lower_trait_item(self.tcx, trait_item.trait_item_id());
333346
intravisit::walk_trait_item(self, trait_item);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ rustc_queries! {
15461546
feedable
15471547
}
15481548

1549-
query check_well_formed(key: hir::OwnerId) -> Result<(), ErrorGuaranteed> {
1549+
query check_well_formed(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
15501550
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
15511551
ensure_forwards_result_if_red
15521552
}

0 commit comments

Comments
 (0)