Skip to content

Commit ef833d4

Browse files
committed
Introduce a T_err type for type errors
This allows more errors to be non-fatal, as per #1871. I only went through and started changing span_fatal to span_err in check.rs. There are probably more errors that could be made non-fatal. So if you see derived type errors appearing from now on, file a bug! r=graydon Closes #1871
1 parent 77ef4e7 commit ef833d4

File tree

15 files changed

+256
-146
lines changed

15 files changed

+256
-146
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
318318
debug!("~~~~ %s", ~"]");
319319
w.write_char(']');
320320
}
321+
ty::ty_err => fail ~"Shouldn't encode error type"
321322
}
322323
}
323324

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ impl reflector {
266266
// Miscallaneous extra types
267267
ty::ty_trait(_, _, _) => self.leaf(~"trait"),
268268
ty::ty_infer(_) => self.leaf(~"infer"),
269+
ty::ty_err => self.leaf(~"err"),
269270
ty::ty_param(p) => self.visit(~"param", ~[self.c_uint(p.idx)]),
270271
ty::ty_self => self.leaf(~"self"),
271272
ty::ty_type => self.leaf(~"type"),

src/librustc/middle/trans/type_of.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
179179
ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"),
180180
ty::ty_infer(*) => cx.tcx.sess.bug(~"type_of with ty_infer"),
181181
ty::ty_param(*) => cx.tcx.sess.bug(~"type_of with ty_param"),
182+
ty::ty_err(*) => cx.tcx.sess.bug(~"type_of with ty_err")
182183
};
183184

184185
cx.lltypes.insert(t, llty);

src/librustc/middle/ty.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export lookup_item_type;
5757
export lookup_public_fields;
5858
export method;
5959
export method_idx;
60-
export mk_class;
60+
export mk_class, mk_err;
6161
export mk_ctxt;
6262
export mk_with_id, type_def_id;
6363
export mt;
@@ -87,6 +87,7 @@ export ty_fn_proto, ty_fn_purity, ty_fn_ret, ty_fn_ret_style, tys_in_fn_ty;
8787
export ty_int, mk_int, mk_mach_int, mk_char;
8888
export mk_i8, mk_u8, mk_i16, mk_u16, mk_i32, mk_u32, mk_i64, mk_u64;
8989
export mk_f32, mk_f64;
90+
export ty_err;
9091
export ty_estr, mk_estr, type_is_str;
9192
export ty_evec, mk_evec, type_is_vec;
9293
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
@@ -127,7 +128,7 @@ export kind_is_owned;
127128
export meta_kind, kind_lteq, type_kind;
128129
export operators;
129130
export type_err, terr_vstore_kind;
130-
export terr_onceness_mismatch;
131+
export terr_mismatch, terr_onceness_mismatch;
131132
export type_err_to_str, note_and_explain_type_err;
132133
export expected_found;
133134
export type_needs_drop;
@@ -673,6 +674,9 @@ enum sty {
673674
ty_self, // special, implicit `self` type parameter
674675

675676
ty_infer(InferTy), // soething used only during inference/typeck
677+
ty_err, // Also only used during inference/typeck, to represent
678+
// the type of an erroneous expression (helps cut down
679+
// on non-useful type error messages)
676680

677681
// "Fake" types, used for trans purposes
678682
ty_type, // type_desc*
@@ -1062,7 +1066,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
10621066
}
10631067
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
10641068
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
1065-
ty_opaque_box => (),
1069+
ty_opaque_box | ty_err => (),
10661070
ty_param(_) => flags |= has_params as uint,
10671071
ty_infer(_) => flags |= needs_infer as uint,
10681072
ty_self => flags |= has_self as uint,
@@ -1094,6 +1098,8 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
10941098

10951099
fn mk_nil(cx: ctxt) -> t { mk_t(cx, ty_nil) }
10961100

1101+
fn mk_err(cx: ctxt) -> t { mk_t(cx, ty_err) }
1102+
10971103
fn mk_bot(cx: ctxt) -> t { mk_t(cx, ty_bot) }
10981104

10991105
fn mk_bool(cx: ctxt) -> t { mk_t(cx, ty_bool) }
@@ -1301,7 +1307,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
13011307
match get(ty).sty {
13021308
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
13031309
ty_estr(_) | ty_type | ty_opaque_box | ty_self |
1304-
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(_) => {
1310+
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(_) | ty_err => {
13051311
}
13061312
ty_box(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) |
13071313
ty_ptr(tm) | ty_rptr(_, tm) => {
@@ -1386,7 +1392,7 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
13861392
ty_class(did, fold_substs(substs, fldop))
13871393
}
13881394
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
1389-
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
1395+
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) | ty_err |
13901396
ty_opaque_box | ty_infer(_) | ty_param(*) | ty_self => {
13911397
*sty
13921398
}
@@ -1794,7 +1800,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
17941800
ty_trait(_, _, vstore_fixed(_)) |
17951801
ty_trait(_, _, vstore_slice(_)) => false,
17961802
1797-
ty_param(*) | ty_infer(*) => true,
1803+
ty_param(*) | ty_infer(*) | ty_err => true,
17981804
17991805
ty_evec(mt, vstore_fixed(_)) => type_needs_drop(cx, mt.ty),
18001806
ty_unboxed_vec(mt) => type_needs_drop(cx, mt.ty),
@@ -2270,7 +2276,7 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
22702276
cx.sess.bug(~"Asked to compute kind of a type variable");
22712277
}
22722278
ty_type | ty_opaque_closure_ptr(_)
2273-
| ty_opaque_box | ty_unboxed_vec(_) => {
2279+
| ty_opaque_box | ty_unboxed_vec(_) | ty_err => {
22742280
cx.sess.bug(~"Asked to compute kind of fictitious type");
22752281
}
22762282
};
@@ -2341,7 +2347,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
23412347
cx.sess.bug(~"Asked to compute kind of a type variable");
23422348
}
23432349
ty_type | ty_opaque_closure_ptr(_)
2344-
| ty_opaque_box | ty_unboxed_vec(_) => {
2350+
| ty_opaque_box | ty_unboxed_vec(_) | ty_err => {
23452351
cx.sess.bug(~"Asked to compute kind of fictitious type");
23462352
}
23472353
}
@@ -2384,6 +2390,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
23842390
ty_estr(_) |
23852391
ty_fn(_) |
23862392
ty_infer(_) |
2393+
ty_err |
23872394
ty_param(_) |
23882395
ty_self |
23892396
ty_type |
@@ -2589,7 +2596,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
25892596
result = false;
25902597
}
25912598
2592-
ty_infer(*) | ty_self(*) => {
2599+
ty_infer(*) | ty_self(*) | ty_err => {
25932600
cx.sess.bug(~"non concrete type in type_is_pod");
25942601
}
25952602
}
@@ -2862,6 +2869,8 @@ impl sty : to_bytes::IterBytes {
28622869
28632870
ty_rptr(ref r, ref mt) =>
28642871
to_bytes::iter_bytes_3(&24u8, r, mt, lsb0, f),
2872+
2873+
ty_err => 25u8.iter_bytes(lsb0, f)
28652874
}
28662875
}
28672876
}
@@ -3357,7 +3366,8 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
33573366
ty_infer(IntVar(_)) => ~"integral variable",
33583367
ty_infer(FloatVar(_)) => ~"floating-point variable",
33593368
ty_param(_) => ~"type parameter",
3360-
ty_self => ~"self"
3369+
ty_self => ~"self",
3370+
ty_err => ~"type error"
33613371
}
33623372
}
33633373

@@ -4787,6 +4797,12 @@ impl sty : cmp::Eq {
47874797
_ => false
47884798
}
47894799
}
4800+
ty_err => {
4801+
match (*other) {
4802+
ty_err => true,
4803+
_ => false
4804+
}
4805+
}
47904806
ty_param(e0a) => {
47914807
match (*other) {
47924808
ty_param(e0b) => e0a == e0b,
@@ -4944,6 +4960,12 @@ impl sty : cmp::Eq {
49444960
_ => false
49454961
}
49464962
}
4963+
ty_err => {
4964+
match (*other) {
4965+
ty_err => true,
4966+
_ => false
4967+
}
4968+
}
49474969
ty_param(e0a) => {
49484970
match (*other) {
49494971
ty_param(e0b) => e0a == e0b,

0 commit comments

Comments
 (0)