Skip to content

Commit 4209522

Browse files
committed
Properly suppress derived type error messages
Previously, the typechecker suppressed many but not all errors, by suppressing errors where the actual type was either ty_err, or a function type whose result was ty_err. Added a has_ty_err flag to the type flags so as to suppress errors for any types involving ty_err. r=nmatsakis
1 parent 0274292 commit 4209522

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

src/librustc/middle/ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export re_bound, re_free, re_scope, re_static, re_infer;
151151
export ReVar, ReSkolemized;
152152
export br_self, br_anon, br_named, br_cap_avoid, br_fresh;
153153
export get, type_has_params, type_needs_infer, type_has_regions;
154-
export type_is_region_ptr;
154+
export type_contains_err, type_is_region_ptr;
155155
export type_id;
156156
export tbox_has_flag;
157157
export ty_var_id;
@@ -475,6 +475,7 @@ enum tbox_flag {
475475
has_self = 2,
476476
needs_infer = 4,
477477
has_regions = 8,
478+
has_ty_err = 16,
478479

479480
// a meta-flag: subst may be required if the type has parameters, a self
480481
// type, or references bound regions
@@ -508,6 +509,7 @@ pure fn type_has_params(t: t) -> bool { tbox_has_flag(get(t), has_params) }
508509
pure fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), has_self) }
509510
pure fn type_needs_infer(t: t) -> bool { tbox_has_flag(get(t), needs_infer) }
510511
pure fn type_has_regions(t: t) -> bool { tbox_has_flag(get(t), has_regions) }
512+
pure fn type_contains_err(t: t) -> bool { tbox_has_flag(get(t), has_ty_err) }
511513
pure fn type_def_id(t: t) -> Option<ast::def_id> { get(t).o_def_id }
512514
pure fn type_id(t: t) -> uint { get(t).id }
513515

@@ -1059,7 +1061,8 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
10591061
}
10601062
&ty_nil | &ty_bot | &ty_bool | &ty_int(_) | &ty_float(_) | &ty_uint(_) |
10611063
&ty_estr(_) | &ty_type | &ty_opaque_closure_ptr(_) |
1062-
&ty_opaque_box | &ty_err => (),
1064+
&ty_opaque_box => (),
1065+
&ty_err => flags |= has_ty_err as uint,
10631066
&ty_param(_) => flags |= has_params as uint,
10641067
&ty_infer(_) => flags |= needs_infer as uint,
10651068
&ty_self => flags |= has_self as uint,

src/librustc/middle/typeck/infer/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -744,20 +744,10 @@ impl @InferCtxt {
744744
fn type_error_message(sp: span, mk_msg: fn(~str) -> ~str,
745745
actual_ty: ty::t, err: Option<&ty::type_err>) {
746746
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
747-
let mut actual_sty = ty::get(copy actual_ty);
748747

749748
// Don't report an error if actual type is ty_err.
750-
match actual_sty.sty {
751-
ty::ty_err => return,
752-
// Should really not report an error if the type
753-
// has ty_err anywhere as a component, but that's
754-
// annoying since we haven't written a visitor for
755-
// ty::t yet
756-
ty::ty_fn(ref fty) => match ty::get(fty.sig.output).sty {
757-
ty::ty_err => return,
758-
_ => ()
759-
},
760-
_ => ()
749+
if ty::type_contains_err(actual_ty) {
750+
return;
761751
}
762752
let error_str = err.map_default(~"", |t_err|
763753
fmt!(" (%s)",

0 commit comments

Comments
 (0)