Skip to content

Commit 8e56729

Browse files
varkoryodaldevoid
andcommitted
Handle new ConstValue variants in mir
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 2dfde88 commit 8e56729

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
604604
search_stack.push((ty, hir_ty));
605605
}
606606

607-
(UnpackedKind::Lifetime(_), _) | (UnpackedKind::Type(_), _) => {
607+
(UnpackedKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {
608+
// Lifetimes cannot be found in consts, so we don't need
609+
// to search anything here.
610+
}
611+
612+
(UnpackedKind::Lifetime(_), _)
613+
| (UnpackedKind::Type(_), _)
614+
| (UnpackedKind::Const(_), _) => {
608615
// I *think* that HIR lowering should ensure this
609616
// doesn't happen, even in erroneous
610617
// programs. Else we should use delay-span-bug.

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
9999
param_env,
100100
).type_must_outlive(origin, t1, r2);
101101
}
102+
103+
UnpackedKind::Const(_) => {
104+
// Consts cannot outlive one another, so we
105+
// don't need to handle any relations here.
106+
}
102107
}
103108
}
104109

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
25332533
),
25342534
))
25352535
}
2536-
UnpackedKind::Type(_) => None,
2536+
UnpackedKind::Type(_) | UnpackedKind::Const(_) => None,
25372537
}
25382538
})
25392539
.collect();

src/librustc_mir/interpret/operand.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
594594
self.layout_of(ty)
595595
})?;
596596
let op = match val.val {
597+
ConstValue::Param(_) => Err(EvalErrorKind::TooGeneric.into()),
598+
ConstValue::Infer(_) => bug!(),
597599
ConstValue::ByRef(ptr, alloc) => {
598600
// We rely on mutability being set correctly in that allocation to prevent writes
599601
// where none should happen -- and for `static mut`, we copy on demand anyway.

src/librustc_mir/shim.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc::hir;
22
use rustc::hir::def_id::DefId;
33
use rustc::infer;
44
use rustc::mir::*;
5-
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind};
5+
use rustc::ty::{self, Ty, TyCtxt};
66
use rustc::ty::layout::VariantIdx;
77
use rustc::ty::subst::{Subst, InternalSubsts};
88
use rustc::ty::query::Providers;
@@ -450,12 +450,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
450450
) {
451451
let tcx = self.tcx;
452452

453-
let substs = InternalSubsts::for_item(tcx, self.def_id, |param, _| {
454-
match param.kind {
455-
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
456-
GenericParamDefKind::Type {..} => ty.into(),
457-
}
458-
});
453+
let substs = tcx.mk_substs_trait(ty, &[]);
459454

460455
// `func == Clone::clone(&ty) -> ty`
461456
let func_ty = tcx.mk_fn_def(self.def_id, substs);

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,10 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D
558558

559559
// FIXME: when we make this a hard error, this should have its
560560
// own error code.
561-
let message = if tcx.generics_of(def_id).own_counts().types != 0 {
561+
let counts = tcx.generics_of(def_id).own_counts();
562+
let message = if counts.types + counts.consts != 0 {
562563
"#[derive] can't be used on a #[repr(packed)] struct with \
563-
type parameters (error E0133)".to_string()
564+
type or const parameters (error E0133)".to_string()
564565
} else {
565566
"#[derive] can't be used on a #[repr(packed)] struct that \
566567
does not derive Copy (error E0133)".to_string()

src/librustc_mir/transform/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
259259
// inlining. This is to ensure that the final crate doesn't have MIR that
260260
// reference unexported symbols
261261
if callsite.callee.is_local() {
262-
if callsite.substs.types().count() == 0 && !hinted {
262+
if callsite.substs.non_erasable_generics().count() == 0 && !hinted {
263263
debug!(" callee is an exported function - not inlining");
264264
return false;
265265
}

0 commit comments

Comments
 (0)