Skip to content

Commit f3f9db1

Browse files
committed
rustc: Fix an ICE "Autoderef but type not derefable"
Related to #5062 (same error message), but that test case causes a different ICE than mentioned there (even without this fix).
1 parent c786b68 commit f3f9db1

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/librustc/middle/ty.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,15 +3042,17 @@ pub fn adjust_ty(cx: ctxt,
30423042
Some(@AutoDerefRef(ref adj)) => {
30433043
let mut adjusted_ty = unadjusted_ty;
30443044

3045-
for uint::range(0, adj.autoderefs) |i| {
3046-
match ty::deref(cx, adjusted_ty, true) {
3047-
Some(mt) => { adjusted_ty = mt.ty; }
3048-
None => {
3049-
cx.sess.span_bug(
3050-
span,
3051-
fmt!("The %uth autoderef failed: %s",
3052-
i, ty_to_str(cx,
3053-
adjusted_ty)));
3045+
if (!ty::type_is_error(adjusted_ty)) {
3046+
for uint::range(0, adj.autoderefs) |i| {
3047+
match ty::deref(cx, adjusted_ty, true) {
3048+
Some(mt) => { adjusted_ty = mt.ty; }
3049+
None => {
3050+
cx.sess.span_bug(
3051+
span,
3052+
fmt!("The %uth autoderef failed: %s",
3053+
i, ty_to_str(cx,
3054+
adjusted_ty)));
3055+
}
30543056
}
30553057
}
30563058
}

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,12 @@ pub mod guarantor {
11081108
-> ExprCategorizationType {
11091109
let mut ct = ct;
11101110
let tcx = rcx.fcx.ccx.tcx;
1111+
1112+
if (ty::type_is_error(ct.ty)) {
1113+
ct.cat.pointer = NotPointer;
1114+
return ct;
1115+
}
1116+
11111117
for uint::range(0, autoderefs) |_| {
11121118
ct.cat.guarantor = guarantor_of_deref(&ct.cat);
11131119

0 commit comments

Comments
 (0)