Handle new ConstValue variants in mir

Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
This commit is contained in:
varkor 2019-02-20 01:19:13 +00:00
parent 2dfde88438
commit 8e56729b4d
7 changed files with 22 additions and 12 deletions

View File

@ -604,7 +604,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
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.

View File

@ -99,6 +99,11 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, '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.
}
}
}

View File

@ -2533,7 +2533,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
),
))
}
UnpackedKind::Type(_) => None,
UnpackedKind::Type(_) | UnpackedKind::Const(_) => None,
}
})
.collect();

View File

@ -594,6 +594,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
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.

View File

@ -2,7 +2,7 @@ use rustc::hir;
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 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
) {
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);

View 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()

View File

@ -259,7 +259,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
// 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;
}