Skip to content

Commit e012f19

Browse files
committed
Made matching machine types equal to float, int, uint (fixes rust-lang#1376)
1 parent 389329e commit e012f19

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/comp/middle/ty.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,25 @@ pure fn struct(cx: ctxt, typ: t) -> sty {
626626
}
627627
}
628628

629+
// Returns struact(cx, typ) but replaces all occurences of platform
630+
// dependent primitive types with their machine type equivalent
631+
pure fn mach_struct(cx: ctxt, cfg: @session::config, typ: t) -> sty {
632+
alt interner::get(*cx.ts, typ).struct {
633+
ty_named(t, _) { mach_struct(cx, cfg, t) }
634+
s { mach_sty(cfg, s) }
635+
}
636+
}
637+
638+
// Converts s to its machine type equivalent
639+
pure fn mach_sty(cfg: @session::config, s: sty) -> sty {
640+
alt s {
641+
ty_int(ast::ty_i.) { ty_int(cfg.int_type) }
642+
ty_uint(ast::ty_u.) { ty_uint(cfg.uint_type) }
643+
ty_float(ast::ty_f.) { ty_float(cfg.float_type) }
644+
s { s }
645+
}
646+
}
647+
629648
pure fn ty_name(cx: ctxt, typ: t) -> option::t<@str> {
630649
alt interner::get(*cx.ts, typ).struct {
631650
ty_named(_, n) { some(n) }
@@ -1758,7 +1777,9 @@ mod unify {
17581777

17591778
// Simple structural type comparison.
17601779
fn struct_cmp(cx: @ctxt, expected: t, actual: t) -> result {
1761-
if struct(cx.tcx, expected) == struct(cx.tcx, actual) {
1780+
let tcx = cx.tcx;
1781+
let cfg = tcx.sess.get_targ_cfg();
1782+
if mach_struct(tcx, cfg, expected) == mach_struct(tcx, cfg, actual) {
17621783
ret ures_ok(expected);
17631784
}
17641785
ret ures_err(terr_mismatch);

0 commit comments

Comments
 (0)