about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-06 09:31:27 +0000
committerbors <bors@rust-lang.org>2020-01-06 09:31:27 +0000
commita80e63f3fa77792e848e3b248acf4c0acda2e310 (patch)
tree6e9574bac0128d5184af68d208b2ee8d9e98e416 /src/librustc
parent33640f0e03af2fb31ce380d5389d5545f24ce29a (diff)
parent34716a31db9371501fe98100a7aa1566f37c1d23 (diff)
downloadrust-a80e63f3fa77792e848e3b248acf4c0acda2e310.tar.gz
rust-a80e63f3fa77792e848e3b248acf4c0acda2e310.zip
Auto merge of #67917 - Dylan-DPC:rollup-id05y91, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #67800 (Fix ICE involving calling `Instance.ty` during const evaluation)
 - #67873 (change remove to have a PartialEq bound)
 - #67897 (Use `as_deref()` to replace `as_ref().map(...)`)
 - #67906 (Silence `TooGeneric` error)
 - #67912 (macros: typo fix)
 - #67915 (Use Self instead of $type)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/traits/error_reporting.rs6
-rw-r--r--src/librustc/ty/instance.rs27
-rw-r--r--src/librustc/ty/layout.rs2
3 files changed, 33 insertions, 2 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index 3fef1dd064e..009e52e479a 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -12,6 +12,7 @@ use crate::hir::Node;
 use crate::infer::error_reporting::TypeAnnotationNeeded as ErrorCode;
 use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use crate::infer::{self, InferCtxt};
+use crate::mir::interpret::ErrorHandled;
 use crate::session::DiagnosticMessageId;
 use crate::ty::error::ExpectedFound;
 use crate::ty::fast_reject;
@@ -1086,6 +1087,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
 
             // already reported in the query
             ConstEvalFailure(err) => {
+                if let ErrorHandled::TooGeneric = err {
+                    // Silence this error, as it can be produced during intermediate steps
+                    // when a constant is not yet able to be evaluated (but will be later).
+                    return;
+                }
                 self.tcx.sess.delay_span_bug(
                     span,
                     &format!("constant in type had an ignored error: {:?}", err),
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index a7e716ad7b7..e315de11568 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -62,10 +62,35 @@ pub enum InstanceDef<'tcx> {
 }
 
 impl<'tcx> Instance<'tcx> {
-    pub fn ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
+    /// Returns the `Ty` corresponding to this `Instance`,
+    /// with generic substitutions applied and lifetimes erased.
+    ///
+    /// This method can only be called when the 'substs' for this Instance
+    /// are fully monomorphic (no `ty::Param`'s are present).
+    /// This is usually the case (e.g. during codegen).
+    /// However, during constant evaluation, we may want
+    /// to try to resolve a `Instance` using generic parameters
+    /// (e.g. when we are attempting to to do const-propagation).
+    /// In this case, `Instance.ty_env` should be used to provide
+    /// the `ParamEnv` for our generic context.
+    pub fn monomorphic_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
         let ty = tcx.type_of(self.def.def_id());
+        // There shouldn't be any params - if there are, then
+        // Instance.ty_env should have been used to provide the proper
+        // ParamEnv
+        if self.substs.has_param_types() {
+            bug!("Instance.ty called for type {:?} with params in substs: {:?}", ty, self.substs);
+        }
         tcx.subst_and_normalize_erasing_regions(self.substs, ty::ParamEnv::reveal_all(), &ty)
     }
+
+    /// Like `Instance.ty`, but allows a `ParamEnv` to be specified for use during
+    /// normalization. This method is only really useful during constant evaluation,
+    /// where we are dealing with potentially generic types.
+    pub fn ty_env(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Ty<'tcx> {
+        let ty = tcx.type_of(self.def.def_id());
+        tcx.subst_and_normalize_erasing_regions(self.substs, param_env, &ty)
+    }
 }
 
 impl<'tcx> InstanceDef<'tcx> {
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index 63345f828e0..5f599034e7d 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -2301,7 +2301,7 @@ impl<'tcx> ty::Instance<'tcx> {
     // or should go through `FnAbi` instead, to avoid losing any
     // adjustments `FnAbi::of_instance` might be performing.
     fn fn_sig_for_fn_abi(&self, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
-        let ty = self.ty(tcx);
+        let ty = self.monomorphic_ty(tcx);
         match ty.kind {
             ty::FnDef(..) |
             // Shims currently have type FnPtr. Not sure this should remain.