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 0bb9b2b

Browse files
committedFeb 15, 2024
Always evaluate free constants and statics, even if previous errors occurred
1 parent ee9c7c9 commit 0bb9b2b

File tree

94 files changed

+866
-553
lines changed

Some content is hidden

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

94 files changed

+866
-553
lines changed
 

‎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.into()),
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();

‎compiler/rustc_lint/src/builtin.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,32 +1542,6 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
15421542
}
15431543
}
15441544

1545-
declare_lint_pass!(
1546-
/// Lint constants that are erroneous.
1547-
/// Without this lint, we might not get any diagnostic if the constant is
1548-
/// unused within this crate, even though downstream crates can't use it
1549-
/// without producing an error.
1550-
UnusedBrokenConst => []
1551-
);
1552-
1553-
impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst {
1554-
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
1555-
match it.kind {
1556-
hir::ItemKind::Const(_, _, body_id) => {
1557-
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
1558-
// trigger the query once for all constants since that will already report the errors
1559-
// FIXME(generic_const_items): Does this work properly with generic const items?
1560-
cx.tcx.ensure().const_eval_poly(def_id);
1561-
}
1562-
hir::ItemKind::Static(_, _, body_id) => {
1563-
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
1564-
cx.tcx.ensure().eval_static_initializer(def_id);
1565-
}
1566-
_ => {}
1567-
}
1568-
}
1569-
}
1570-
15711545
declare_lint! {
15721546
/// The `trivial_bounds` lint detects trait bounds that don't depend on
15731547
/// any type parameters.

0 commit comments

Comments
 (0)
Please sign in to comment.