Skip to content

Commit b6cb9b6

Browse files
RalfJungoli-obk
authored andcommitted
check_const: use the same ParamEnv as codegen for statics
1 parent 49720ea commit b6cb9b6

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
@@ -1631,16 +1631,21 @@ fn validate_const<'a, 'tcx>(
16311631

16321632
fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) {
16331633
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
1634-
let param_env = cx.tcx.param_env(def_id);
1634+
let is_static = cx.tcx.is_static(def_id).is_some();
1635+
let param_env = if is_static {
1636+
ty::ParamEnv::reveal_all()
1637+
} else {
1638+
cx.tcx.param_env(def_id)
1639+
};
16351640
let cid = ::rustc::mir::interpret::GlobalId {
16361641
instance: ty::Instance::mono(cx.tcx, def_id),
16371642
promoted: None
16381643
};
16391644
match cx.tcx.const_eval(param_env.and(cid)) {
16401645
Ok(val) => validate_const(cx.tcx, val, param_env, cid, what),
16411646
Err(err) => {
1642-
// errors for statics are already reported directly in the query
1643-
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 {
16441649
let span = cx.tcx.def_span(def_id);
16451650
err.report_as_lint(
16461651
cx.tcx.at(span),

0 commit comments

Comments
 (0)