Store type names in crate metadata
Improves type error messages referring to external types. Issue #1507
This commit is contained in:
parent
c2fe7b6398
commit
1375b31c1c
@ -292,6 +292,13 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
assert (next(st) as char == ']');
|
||||
ret ty::mk_constr(st.tcx, tt, tcs);
|
||||
}
|
||||
'"' {
|
||||
let name = "";
|
||||
while peek(st) as char != '"' { str::push_byte(name, next(st)); }
|
||||
st.pos = st.pos + 1u;
|
||||
let inner = parse_ty(st, conv);
|
||||
ty::mk_named(st.tcx, inner, @name)
|
||||
}
|
||||
c { #error("unexpected char in type string: %c", c); fail;}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
|
||||
some(s) { *s }
|
||||
none. {
|
||||
let buf = io::mk_mem_buffer();
|
||||
enc_sty(io::mem_buffer_writer(buf), cx, ty::struct(cx.tcx, t));
|
||||
enc_sty(io::mem_buffer_writer(buf), cx,
|
||||
ty::struct_raw(cx.tcx, t));
|
||||
cx.tcx.short_names_cache.insert(t, @io::mem_buffer_str(buf));
|
||||
io::mem_buffer_str(buf)
|
||||
}
|
||||
@ -53,7 +54,7 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
|
||||
some(a) { w.write_str(*a.s); ret; }
|
||||
none. {
|
||||
let pos = w.tell();
|
||||
enc_sty(w, cx, ty::struct(cx.tcx, t));
|
||||
enc_sty(w, cx, ty::struct_raw(cx.tcx, t));
|
||||
let end = w.tell();
|
||||
let len = end - pos;
|
||||
fn estimate_sz(u: uint) -> uint {
|
||||
@ -188,6 +189,12 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
|
||||
for tc: @ty::type_constr in cs { enc_ty_constr(w, cx, tc); }
|
||||
w.write_char(']');
|
||||
}
|
||||
ty::ty_named(t, name) {
|
||||
w.write_char('"');
|
||||
w.write_str(*name);
|
||||
w.write_char('"');
|
||||
enc_ty(w, cx, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn enc_proto(w: io::writer, proto: proto) {
|
||||
|
@ -93,7 +93,7 @@ export node_type_table;
|
||||
export pat_ty;
|
||||
export ret_ty_of_fn;
|
||||
export sequence_element_type;
|
||||
export struct;
|
||||
export struct, struct_raw;
|
||||
export ty_name;
|
||||
export sort_methods;
|
||||
export stmt_node_id;
|
||||
@ -641,6 +641,10 @@ pure fn struct(cx: ctxt, typ: t) -> sty {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn struct_raw(cx: ctxt, typ: t) -> sty {
|
||||
interner::get(*cx.ts, typ).struct
|
||||
}
|
||||
|
||||
// Returns struact(cx, typ) but replaces all occurences of platform
|
||||
// dependent primitive types with their machine type equivalent
|
||||
pure fn mach_struct(cx: ctxt, cfg: @session::config, typ: t) -> sty {
|
||||
|
@ -439,6 +439,7 @@ fn ty_of_native_item(tcx: ty::ctxt, mode: mode, it: @ast::native_item)
|
||||
none. { }
|
||||
}
|
||||
let t = ty::mk_native(tcx, ast_util::local_def(it.id));
|
||||
let t = ty::mk_named(tcx, t, @it.ident);
|
||||
let tpt = {bounds: @[], ty: t};
|
||||
tcx.tcache.insert(local_def(it.id), tpt);
|
||||
ret tpt;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// error-pattern:expected `*u8` but found `native`
|
||||
// error-pattern:expected `sbuf` but found `FILE`
|
||||
use std;
|
||||
|
||||
fn main() unsafe {
|
||||
|
Loading…
x
Reference in New Issue
Block a user