]> git.lizzy.rs Git - rust.git/commitdiff
Handle new ConstValue variants in mir
authorvarkor <github@varkor.com>
Wed, 20 Feb 2019 01:19:13 +0000 (01:19 +0000)
committervarkor <github@varkor.com>
Tue, 5 Mar 2019 22:19:26 +0000 (22:19 +0000)
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/interpret/operand.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/inline.rs

index cc01f632e075cac4210a3b0b40c7169058a55d66..fdede054e15f304516dffe2c3c5d9f233c6363b7 100644 (file)
@@ -604,7 +604,14 @@ fn try_match_adt_and_generic_args<'hir>(
                     search_stack.push((ty, hir_ty));
                 }
 
-                (UnpackedKind::Lifetime(_), _) | (UnpackedKind::Type(_), _) => {
+                (UnpackedKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {
+                    // Lifetimes cannot be found in consts, so we don't need
+                    // to search anything here.
+                }
+
+                (UnpackedKind::Lifetime(_), _)
+                | (UnpackedKind::Type(_), _)
+                | (UnpackedKind::Const(_), _) => {
                     // I *think* that HIR lowering should ensure this
                     // doesn't happen, even in erroneous
                     // programs. Else we should use delay-span-bug.
index 1a72205ad7ae1ba0e3e4c7a7fb3e767b9a2c7d12..bef159e996b8778a60902d2a71d7c7116a992f5c 100644 (file)
@@ -99,6 +99,11 @@ pub(super) fn convert(&mut self, query_constraint: &QueryRegionConstraint<'tcx>)
                     param_env,
                 ).type_must_outlive(origin, t1, r2);
             }
+
+            UnpackedKind::Const(_) => {
+                // Consts cannot outlive one another, so we
+                // don't need to handle any relations here.
+            }
         }
     }
 
index cc03d4a0c96431835072ab92d5b0f94d6df37dd9..5b444ab9690ca7dcb76be567974639aa7097b78f 100644 (file)
@@ -2533,7 +2533,7 @@ fn prove_closure_bounds(
                                     ),
                                 ))
                             }
-                            UnpackedKind::Type(_) => None,
+                            UnpackedKind::Type(_) | UnpackedKind::Const(_) => None,
                         }
                     })
                     .collect();
index 979595d6c00095b5b40631aad1c199bc02abac18..574506ed2329d4f7a1b9a5ea79530ad0120b3c1d 100644 (file)
@@ -594,6 +594,8 @@ pub(super) fn eval_operands(
             self.layout_of(ty)
         })?;
         let op = match val.val {
+            ConstValue::Param(_) => Err(EvalErrorKind::TooGeneric.into()),
+            ConstValue::Infer(_) => bug!(),
             ConstValue::ByRef(ptr, alloc) => {
                 // We rely on mutability being set correctly in that allocation to prevent writes
                 // where none should happen -- and for `static mut`, we copy on demand anyway.
index db8476f3be5f79afa61b66ffef97a352be1b2006..1c6b1450be86230e2b40507023a6063d1db740d0 100644 (file)
@@ -2,7 +2,7 @@
 use rustc::hir::def_id::DefId;
 use rustc::infer;
 use rustc::mir::*;
-use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind};
+use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::layout::VariantIdx;
 use rustc::ty::subst::{Subst, InternalSubsts};
 use rustc::ty::query::Providers;
@@ -450,12 +450,7 @@ fn make_clone_call(
     ) {
         let tcx = self.tcx;
 
-        let substs = InternalSubsts::for_item(tcx, self.def_id, |param, _| {
-            match param.kind {
-                GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
-                GenericParamDefKind::Type {..} => ty.into(),
-            }
-        });
+        let substs = tcx.mk_substs_trait(ty, &[]);
 
         // `func == Clone::clone(&ty) -> ty`
         let func_ty = tcx.mk_fn_def(self.def_id, substs);
index a8816720b28bd6f4dfa8b2868ddba4482954513d..047731e3fe6a7bea4bd04ba1c6e9af9de64352bb 100644 (file)
@@ -558,9 +558,10 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
 
     // FIXME: when we make this a hard error, this should have its
     // own error code.
-    let message = if tcx.generics_of(def_id).own_counts().types != 0 {
+    let counts = tcx.generics_of(def_id).own_counts();
+    let message = if counts.types + counts.consts != 0 {
         "#[derive] can't be used on a #[repr(packed)] struct with \
-         type parameters (error E0133)".to_string()
+         type or const parameters (error E0133)".to_string()
     } else {
         "#[derive] can't be used on a #[repr(packed)] struct that \
          does not derive Copy (error E0133)".to_string()
index 4cdef015b53ff0697aee3e7bd0ca74045e950d02..918375e426b7df606f30588a8b64a972fdf6be63 100644 (file)
@@ -259,7 +259,7 @@ fn should_inline(&self,
         // inlining. This is to ensure that the final crate doesn't have MIR that
         // reference unexported symbols
         if callsite.callee.is_local() {
-            if callsite.substs.types().count() == 0 && !hinted {
+            if callsite.substs.non_erasable_generics().count() == 0 && !hinted {
                 debug!("    callee is an exported function - not inlining");
                 return false;
             }