Skip to content

Commit

Permalink
Auto merge of #52925 - RalfJung:sanity_check, r=<try>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 1, 2018
2 parents e94df4a + 222dd17 commit daf753a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,16 +1630,22 @@ fn validate_const<'a, 'tcx>(

fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) {
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
let param_env = cx.tcx.param_env(def_id);
let is_static = cx.tcx.is_static(def_id).is_some();
let param_env = if is_static {
// Use the same param_env as `codegen_static_initializer`, to reuse the cache.
ty::ParamEnv::reveal_all()
} else {
cx.tcx.param_env(def_id)
};
let cid = ::rustc::mir::interpret::GlobalId {
instance: ty::Instance::mono(cx.tcx, def_id),
promoted: None
};
match cx.tcx.const_eval(param_env.and(cid)) {
Ok(val) => validate_const(cx.tcx, val, param_env, cid, what),
Err(err) => {
// errors for statics are already reported directly in the query
if cx.tcx.is_static(def_id).is_none() {
// errors for statics are already reported directly in the query, avoid duplicates
if !is_static {
let span = cx.tcx.def_span(def_id);
err.report_as_lint(
cx.tcx.at(span),
Expand Down

0 comments on commit daf753a

Please sign in to comment.