]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #67914 - Aaron1011:fix/const-prop-impossible, r=matthewjasper,oli-obk
authorYuki Okushi <huyuumi.dev@gmail.com>
Wed, 15 Jan 2020 12:51:43 +0000 (21:51 +0900)
committerGitHub <noreply@github.com>
Wed, 15 Jan 2020 12:51:43 +0000 (21:51 +0900)
Don't run const propagation on items with inconsistent bounds

Fixes #67696

Using `#![feature(trivial_bounds)]`, it's possible to write functions
with unsatisfiable 'where' clauses, making them uncallable. However, the
user can act as if these 'where' clauses are true inside the body of the
function, leading to code that would normally be impossible to write.

Since const propgation can run even without any user-written calls to a
function, we need to explcitly check for these uncallable functions.

1  2 
src/librustc/query/mod.rs
src/librustc/ty/query/keys.rs

index f4c262fbac1d47d40b8d25b451f2c947761baab2,669ba4abfadd8ae994ba9dc165443aefa05a6bd3..a20e011b91a7543697bdb006784a82e205397ace
@@@ -1,6 -1,6 +1,6 @@@
  use crate::dep_graph::{DepKind, DepNode, RecoverKey, SerializedDepNodeIndex};
  use crate::mir;
 -use crate::mir::interpret::GlobalId;
 +use crate::mir::interpret::{GlobalId, LitToConstInput};
  use crate::traits;
  use crate::traits::query::{
      CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
@@@ -518,13 -518,6 +518,13 @@@ rustc_queries! 
              no_force
              desc { "get a &core::panic::Location referring to a span" }
          }
 +
 +        query lit_to_const(
 +            key: LitToConstInput<'tcx>
 +        ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
 +            no_force
 +            desc { "converting literal to const" }
 +        }
      }
  
      TypeChecking {
              desc { "normalizing `{:?}`", goal }
          }
  
-         query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
+         query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>, traits::TraitQueryMode)) -> bool {
              no_force
              desc { |tcx|
-                 "testing substituted normalized predicates:`{}`",
-                 tcx.def_path_str(key.0)
+                 "testing substituted normalized predicates in mode {:?}:`{}`",
+                 key.2, tcx.def_path_str(key.0)
              }
          }
  
index cbf335ad607ef3e9f1ae84ed3825cde3a0f32df9,20f8e7f564abd6b407a4915dcf7416cfad6052fb..3fb3720a5638a1dc7d253425b4f57b13e357dd85
@@@ -52,16 -52,6 +52,16 @@@ impl<'tcx> Key for mir::interpret::Glob
      }
  }
  
 +impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
 +    fn query_crate(&self) -> CrateNum {
 +        LOCAL_CRATE
 +    }
 +
 +    fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
 +        DUMMY_SP
 +    }
 +}
 +
  impl Key for CrateNum {
      fn query_crate(&self) -> CrateNum {
          *self
@@@ -125,6 -115,15 +125,15 @@@ impl<'tcx> Key for (DefId, SubstsRef<'t
      }
  }
  
+ impl<'tcx> Key for (DefId, SubstsRef<'tcx>, traits::TraitQueryMode) {
+     fn query_crate(&self) -> CrateNum {
+         self.0.krate
+     }
+     fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
+         self.0.default_span(tcx)
+     }
+ }
  impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
      fn query_crate(&self) -> CrateNum {
          self.1.def_id().krate