Skip to content

Commit b124dfe

Browse files
committed
Progress through the ICEs a little further
1 parent 23008d7 commit b124dfe

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

src/librustc/ty/context.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25522552
self.mk_ty(Param(ParamTy { idx: index, name: name }))
25532553
}
25542554

2555-
pub fn mk_const_param(self, index: u32, name: InternedString, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
2555+
pub fn mk_const_param(
2556+
self,
2557+
index: u32,
2558+
name: InternedString,
2559+
ty: Ty<'tcx>
2560+
) -> &'tcx ty::Const<'tcx> {
25562561
debug!("mk_const_param: index={} name={:?} ty={:?}", index, name, ty);
25572562
self.mk_const(ty::Const {
25582563
val: ConstValue::Param(ParamConst { index, name }),

src/librustc/ty/relate.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ pub fn super_relate_consts<'a, 'gcx, 'tcx, R>(relation: &mut R,
591591
-> RelateResult<'tcx, &'tcx Const<'tcx>>
592592
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
593593
{
594-
assert!(a.ty != b.ty);
594+
assert_eq!(a.ty, b.ty);
595595

596596
let tcx = relation.tcx();
597597
// Currently, the values that can be unified are those that
@@ -601,10 +601,13 @@ pub fn super_relate_consts<'a, 'gcx, 'tcx, R>(relation: &mut R,
601601
match (a.val, b.val) {
602602
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
603603
// The caller should handle these cases!
604-
bug!("var types encountered in super_relate_consts")
604+
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
605+
}
606+
(ConstValue::Param(a_p), ConstValue::Param(b_p)) if a_p.index == b_p.index => {
607+
Ok(a)
605608
}
606609
(ConstValue::Param(_), _) | (_, ConstValue::Param(_)) => {
607-
bug!("param types encountered in super_relate_consts")
610+
bug!("param types encountered in super_relate_consts: {:?} {:?}", a, b);
608611
}
609612
(ConstValue::Scalar(_), _) |
610613
(ConstValue::ScalarPair(..), _) |

src/librustc_mir/build/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ use util as mir_util;
3737
/// Construct the MIR for a given def-id.
3838
pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'tcx> {
3939
let id = tcx.hir.as_local_node_id(def_id).unwrap();
40-
let unsupported = || {
41-
span_bug!(tcx.hir.span(id), "can't build MIR for {:?}", def_id);
42-
};
4340

4441
// Figure out what primary body this item has.
4542
let body_id = match tcx.hir.get(id) {
@@ -50,7 +47,9 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
5047

5148
_ => match tcx.hir.maybe_body_owned_by(id) {
5249
Some(body) => body,
53-
None => unsupported(),
50+
None => {
51+
span_bug!(tcx.hir.span(id), "can't build MIR for {:?}", def_id)
52+
}
5453
},
5554
};
5655

src/librustc_typeck/collect.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,13 +1169,38 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11691169
NodeTy(&hir::Ty { node: hir::TyKind::Array(_, ref constant), .. }) |
11701170
NodeTy(&hir::Ty { node: hir::TyKind::Typeof(ref constant), .. }) |
11711171
NodeExpr(&hir::Expr { node: ExprKind::Repeat(_, ref constant), .. })
1172-
if constant.id == node_id => tcx.types.usize,
1172+
if constant.id == node_id =>
1173+
{
1174+
tcx.types.usize
1175+
}
11731176

11741177
NodeVariant(&Spanned { node: VariantKind { disr_expr: Some(ref e), .. }, .. })
1175-
if e.id == node_id => {
1176-
tcx.adt_def(tcx.hir.get_parent_did(node_id))
1177-
.repr.discr_type().to_ty(tcx)
1178+
if e.id == node_id =>
1179+
{
1180+
tcx.adt_def(tcx.hir.get_parent_did(node_id))
1181+
.repr.discr_type().to_ty(tcx)
1182+
}
1183+
1184+
NodeExpr(&hir::Expr { node: ExprKind::Path(ref path), .. }) => {
1185+
match path {
1186+
QPath::Resolved(_, ref path) => {
1187+
match path.def {
1188+
Def::Fn(def_id) => {
1189+
let generics = tcx.generics_of(def_id);
1190+
for param in &generics.params {
1191+
// if param.id == node_id {
1192+
// generics.param_def_id_to_index
1193+
return tcx.type_of(param.def_id);
1194+
// }
1195+
}
1196+
bug!("no such param");
1197+
}
1198+
x => bug!("other def {:?}", x),
1199+
}
1200+
}
1201+
_ => bug!("other path"),
11781202
}
1203+
}
11791204

11801205
x => {
11811206
bug!("unexpected const parent in type_of_def_id(): {:?}", x);

0 commit comments

Comments
 (0)