Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39d167c

Browse files
committedFeb 15, 2024
Always evaluate free constants and statics, even if previous errors occurred
1 parent fa9f77f commit 39d167c

File tree

73 files changed

+647
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+647
-578
lines changed
 

‎compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
249249
let secondary_errors = mem::take(&mut self.secondary_errors);
250250
if self.error_emitted.is_none() {
251251
for error in secondary_errors {
252-
error.emit();
252+
self.error_emitted = Some(error.emit());
253253
}
254254
} else {
255255
assert!(self.tcx.dcx().has_errors().is_some());

‎compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
196196
collect::test_opaque_hidden_types(tcx)?;
197197
}
198198

199+
// Make sure we evaluate all static and (non-associated) const items, even if unused.
200+
// If any of these fail to evaluate, we do not want this crate to pass compilation.
201+
tcx.hir().par_body_owners(|item_def_id| {
202+
let def_kind = tcx.def_kind(item_def_id);
203+
match def_kind {
204+
DefKind::Static(_) => tcx.ensure().eval_static_initializer(item_def_id),
205+
DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()),
206+
_ => (),
207+
}
208+
});
209+
199210
// Freeze definitions as we don't add new ones at this point. This improves performance by
200211
// allowing lock-free access to them.
201212
tcx.untracked().definitions.freeze();

0 commit comments

Comments
 (0)
Please sign in to comment.