diff options
| author | Ralf Jung <post@ralfj.de> | 2018-08-01 00:25:46 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-08-01 00:25:46 +0200 |
| commit | 5ce5f310cc1d08fd27d16f0335ff74f56ef321c2 (patch) | |
| tree | c3bcb40257a3b71fd34068d4e5a2db386fe24e5e /src | |
| parent | 70cac59031d5c33962a1f53cdca9359c0dcd1f9f (diff) | |
| download | rust-5ce5f310cc1d08fd27d16f0335ff74f56ef321c2.tar.gz rust-5ce5f310cc1d08fd27d16f0335ff74f56ef321c2.zip | |
check_const: use the same ParamEnv as codegen for statics
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_lint/builtin.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 7cb4f7d3860..223edd16c63 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1630,7 +1630,12 @@ 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 { + 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 @@ -1638,8 +1643,8 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { 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), |
