]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #52925 - RalfJung:sanity_check, r=oli-obk
authorbors <bors@rust-lang.org>
Fri, 3 Aug 2018 06:34:16 +0000 (06:34 +0000)
committerbors <bors@rust-lang.org>
Fri, 3 Aug 2018 06:34:16 +0000 (06:34 +0000)
check_const: use the same ParamEnv as codegen for statics

Fixes at least part of https://github.com/rust-lang/rust/issues/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

1  2 
src/librustc_lint/builtin.rs

index 561f5fbf5c41e5a809f59257b5ebdf93626b4fa4,cf3a5449b0395f75c3583e519566c8a8a45ce16d..8481f738adc7b5f94573a53d021d6b713c51bd0f
@@@ -1630,7 -1630,13 +1630,13 @@@ 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),
@@@ -1891,16 -1897,12 +1897,16 @@@ impl Async2018 
              span,
              "`async` is a keyword in the 2018 edition",
          );
 -        lint.span_suggestion_with_applicability(
 -            span,
 -            "you can use a raw identifier to stay compatible",
 -            "r#async".to_string(),
 -            Applicability::MachineApplicable,
 -        );
 +
 +        // Don't suggest about raw identifiers if the feature isn't active
 +        if cx.sess.features_untracked().raw_identifiers {
 +            lint.span_suggestion_with_applicability(
 +                span,
 +                "you can use a raw identifier to stay compatible",
 +                "r#async".to_string(),
 +                Applicability::MachineApplicable,
 +            );
 +        }
          lint.emit()
      }
  }