Skip to content

Commit 4aa7719

Browse files
committed
auto merge of #6992 : Blei/rust/fix-autoderef-ice, r=catamorphism
Related to #5062, but doesn't fix that one.
2 parents 59bbbe4 + a99ba11 commit 4aa7719

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

src/librustc/middle/ty.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -3044,15 +3044,17 @@ pub fn adjust_ty(cx: ctxt,
30443044
Some(@AutoDerefRef(ref adj)) => {
30453045
let mut adjusted_ty = unadjusted_ty;
30463046

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

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

+10
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ fn constrain_call(rcx: @mut Rcx,
460460
debug!("constrain_call(call_expr=%s, implicitly_ref_args=%?)",
461461
call_expr.repr(tcx), implicitly_ref_args);
462462
let callee_ty = rcx.resolve_node_type(callee_id);
463+
if ty::type_is_error(callee_ty) {
464+
// Bail, as function type is unknown
465+
return;
466+
}
463467
let fn_sig = ty::ty_fn_sig(callee_ty);
464468

465469
// `callee_region` is the scope representing the time in which the
@@ -1108,6 +1112,12 @@ pub mod guarantor {
11081112
-> ExprCategorizationType {
11091113
let mut ct = ct;
11101114
let tcx = rcx.fcx.ccx.tcx;
1115+
1116+
if (ty::type_is_error(ct.ty)) {
1117+
ct.cat.pointer = NotPointer;
1118+
return ct;
1119+
}
1120+
11111121
for uint::range(0, autoderefs) |_| {
11121122
ct.cat.guarantor = guarantor_of_deref(&ct.cat);
11131123

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Issue #5062
12+
13+
fn main() {
14+
fmt!("%?", None); //~ ERROR cannot determine a type for this expression: unconstrained type
15+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S<'self, T> {
12+
o: &'self Option<T>
13+
}
14+
15+
fn main() {
16+
S { o: &None }; //~ ERROR cannot determine a type for this expression: unconstrained type
17+
}

0 commit comments

Comments
 (0)