Skip to content

Commit 5ce5f31

Browse files
committed
check_const: use the same ParamEnv as codegen for statics
1 parent 70cac59 commit 5ce5f31

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc_lint/builtin.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,16 +1630,21 @@ 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+
ty::ParamEnv::reveal_all()
1636+
} else {
1637+
cx.tcx.param_env(def_id)
1638+
};
16341639
let cid = ::rustc::mir::interpret::GlobalId {
16351640
instance: ty::Instance::mono(cx.tcx, def_id),
16361641
promoted: None
16371642
};
16381643
match cx.tcx.const_eval(param_env.and(cid)) {
16391644
Ok(val) => validate_const(cx.tcx, val, param_env, cid, what),
16401645
Err(err) => {
1641-
// errors for statics are already reported directly in the query
1642-
if cx.tcx.is_static(def_id).is_none() {
1646+
// errors for statics are already reported directly in the query, avoid duplicates
1647+
if !is_static {
16431648
let span = cx.tcx.def_span(def_id);
16441649
err.report_as_lint(
16451650
cx.tcx.at(span),

0 commit comments

Comments
 (0)