Skip to content

Commit 403571c

Browse files
committed
wfcheck closures
1 parent fa1c9a8 commit 403571c

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,15 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
860860
}
861861
}
862862
}
863+
DefKind::Closure => {
864+
// This is guaranteed to be called by metadata encoding,
865+
// we still call it in wfcheck eagerly to ensure errors in codegen
866+
// attrs prevent lints from spamming the output.
867+
tcx.ensure_ok().codegen_fn_attrs(def_id);
868+
// We do not call `type_of` for closures here as that
869+
// depends on typecheck and would therefore hide
870+
// any further errors in case one typeck fails.
871+
}
863872
_ => {}
864873
}
865874
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
195195
hir::Node::TraitItem(item) => check_trait_item(tcx, item),
196196
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
197197
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
198-
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
198+
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => {
199+
Ok(crate::check::check::check_item_type(tcx, def_id))
200+
}
199201
_ => unreachable!("{node:?}"),
200202
};
201203

@@ -2411,6 +2413,7 @@ fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
24112413
.and(
24122414
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
24132415
)
2416+
.and(items.par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
24142417
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
24152418
super::entry::check_for_entry_fn(tcx);
24162419

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,6 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
287287
intravisit::walk_item(self, item);
288288
}
289289

290-
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
291-
if let hir::ExprKind::Closure(closure) = expr.kind {
292-
self.tcx.ensure_ok().generics_of(closure.def_id);
293-
self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
294-
// We do not call `type_of` for closures here as that
295-
// depends on typecheck and would therefore hide
296-
// any further errors in case one typeck fails.
297-
}
298-
intravisit::walk_expr(self, expr);
299-
}
300-
301290
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
302291
lower_trait_item(self.tcx, trait_item.trait_item_id());
303292
intravisit::walk_trait_item(self, trait_item);

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl ModuleItems {
7171
self.opaques.iter().copied()
7272
}
7373

74+
/// Closures and inline consts
7475
pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
7576
self.nested_bodies.iter().copied()
7677
}
@@ -79,6 +80,14 @@ impl ModuleItems {
7980
self.owners().map(|id| id.def_id)
8081
}
8182

83+
/// Closures and inline consts
84+
pub fn par_nested_bodies(
85+
&self,
86+
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
87+
) -> Result<(), ErrorGuaranteed> {
88+
try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
89+
}
90+
8291
pub fn par_items(
8392
&self,
8493
f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,

0 commit comments

Comments
 (0)