Skip to content

Commit 4dae470

Browse files
committed
Auto merge of #52925 - RalfJung:sanity_check, r=oli-obk
check_const: use the same ParamEnv as codegen for statics Fixes at least part of #52849 (my CTFE-stress benchmark). Note that I do not know what I am doing here, this is just based on hints from @oli-obk. r? @oli-obk
2 parents 7e8ca9f + 222dd17 commit 4dae470

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/librustc_lint/builtin.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1630,16 +1630,22 @@ fn validate_const<'a, 'tcx>(
16301630

16311631
fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) {
16321632
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
1633-
let param_env = cx.tcx.param_env(def_id);
1633+
let is_static = cx.tcx.is_static(def_id).is_some();
1634+
let param_env = if is_static {
1635+
// Use the same param_env as `codegen_static_initializer`, to reuse the cache.
1636+
ty::ParamEnv::reveal_all()
1637+
} else {
1638+
cx.tcx.param_env(def_id)
1639+
};
16341640
let cid = ::rustc::mir::interpret::GlobalId {
16351641
instance: ty::Instance::mono(cx.tcx, def_id),
16361642
promoted: None
16371643
};
16381644
match cx.tcx.const_eval(param_env.and(cid)) {
16391645
Ok(val) => validate_const(cx.tcx, val, param_env, cid, what),
16401646
Err(err) => {
1641-
// errors for statics are already reported directly in the query
1642-
if cx.tcx.is_static(def_id).is_none() {
1647+
// errors for statics are already reported directly in the query, avoid duplicates
1648+
if !is_static {
16431649
let span = cx.tcx.def_span(def_id);
16441650
err.report_as_lint(
16451651
cx.tcx.at(span),

0 commit comments

Comments
 (0)