Skip to content

Commit 1375b31

Browse files
committed
Store type names in crate metadata
Improves type error messages referring to external types. Issue #1507
1 parent c2fe7b6 commit 1375b31

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/comp/metadata/tydecode.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
292292
assert (next(st) as char == ']');
293293
ret ty::mk_constr(st.tcx, tt, tcs);
294294
}
295+
'"' {
296+
let name = "";
297+
while peek(st) as char != '"' { str::push_byte(name, next(st)); }
298+
st.pos = st.pos + 1u;
299+
let inner = parse_ty(st, conv);
300+
ty::mk_named(st.tcx, inner, @name)
301+
}
295302
c { #error("unexpected char in type string: %c", c); fail;}
296303
}
297304
}

src/comp/metadata/tyencode.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
4141
some(s) { *s }
4242
none. {
4343
let buf = io::mk_mem_buffer();
44-
enc_sty(io::mem_buffer_writer(buf), cx, ty::struct(cx.tcx, t));
44+
enc_sty(io::mem_buffer_writer(buf), cx,
45+
ty::struct_raw(cx.tcx, t));
4546
cx.tcx.short_names_cache.insert(t, @io::mem_buffer_str(buf));
4647
io::mem_buffer_str(buf)
4748
}
@@ -53,7 +54,7 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
5354
some(a) { w.write_str(*a.s); ret; }
5455
none. {
5556
let pos = w.tell();
56-
enc_sty(w, cx, ty::struct(cx.tcx, t));
57+
enc_sty(w, cx, ty::struct_raw(cx.tcx, t));
5758
let end = w.tell();
5859
let len = end - pos;
5960
fn estimate_sz(u: uint) -> uint {
@@ -188,6 +189,12 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
188189
for tc: @ty::type_constr in cs { enc_ty_constr(w, cx, tc); }
189190
w.write_char(']');
190191
}
192+
ty::ty_named(t, name) {
193+
w.write_char('"');
194+
w.write_str(*name);
195+
w.write_char('"');
196+
enc_ty(w, cx, t);
197+
}
191198
}
192199
}
193200
fn enc_proto(w: io::writer, proto: proto) {

src/comp/middle/ty.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export node_type_table;
9393
export pat_ty;
9494
export ret_ty_of_fn;
9595
export sequence_element_type;
96-
export struct;
96+
export struct, struct_raw;
9797
export ty_name;
9898
export sort_methods;
9999
export stmt_node_id;
@@ -641,6 +641,10 @@ pure fn struct(cx: ctxt, typ: t) -> sty {
641641
}
642642
}
643643

644+
pure fn struct_raw(cx: ctxt, typ: t) -> sty {
645+
interner::get(*cx.ts, typ).struct
646+
}
647+
644648
// Returns struact(cx, typ) but replaces all occurences of platform
645649
// dependent primitive types with their machine type equivalent
646650
pure fn mach_struct(cx: ctxt, cfg: @session::config, typ: t) -> sty {

src/comp/middle/typeck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ fn ty_of_native_item(tcx: ty::ctxt, mode: mode, it: @ast::native_item)
439439
none. { }
440440
}
441441
let t = ty::mk_native(tcx, ast_util::local_def(it.id));
442+
let t = ty::mk_named(tcx, t, @it.ident);
442443
let tpt = {bounds: @[], ty: t};
443444
tcx.tcache.insert(local_def(it.id), tpt);
444445
ret tpt;

src/test/compile-fail/native-type-mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:expected `*u8` but found `native`
1+
// error-pattern:expected `sbuf` but found `FILE`
22
use std;
33

44
fn main() unsafe {

0 commit comments

Comments
 (0)