wfcheck closures

This commit is contained in:
Oli Scherer 2025-06-05 10:33:13 +00:00
parent 9949ea73c1
commit c83bd8b5f3
4 changed files with 22 additions and 12 deletions

View file

@ -860,6 +860,15 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}
}
DefKind::Closure => {
// This is guaranteed to be called by metadata encoding,
// we still call it in wfcheck eagerly to ensure errors in codegen
// attrs prevent lints from spamming the output.
tcx.ensure_ok().codegen_fn_attrs(def_id);
// We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide
// any further errors in case one typeck fails.
}
_ => {}
}
}

View file

@ -195,7 +195,9 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
hir::Node::TraitItem(item) => check_trait_item(tcx, item),
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => {
Ok(crate::check::check::check_item_type(tcx, def_id))
}
_ => unreachable!("{node:?}"),
};
@ -2411,6 +2413,7 @@ fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
.and(
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
)
.and(items.par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
super::entry::check_for_entry_fn(tcx);

View file

@ -287,17 +287,6 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
intravisit::walk_item(self, item);
}
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = expr.kind {
self.tcx.ensure_ok().generics_of(closure.def_id);
self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
// We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide
// any further errors in case one typeck fails.
}
intravisit::walk_expr(self, expr);
}
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
lower_trait_item(self.tcx, trait_item.trait_item_id());
intravisit::walk_trait_item(self, trait_item);

View file

@ -71,6 +71,7 @@ impl ModuleItems {
self.opaques.iter().copied()
}
/// Closures and inline consts
pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
self.nested_bodies.iter().copied()
}
@ -79,6 +80,14 @@ impl ModuleItems {
self.owners().map(|id| id.def_id)
}
/// Closures and inline consts
pub fn par_nested_bodies(
&self,
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
}
pub fn par_items(
&self,
f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,