From 4ffff6697b144b346cc3853a82f1056b593ef58d Mon Sep 17 00:00:00 2001 From: oncemoreification Date: Mon, 18 Feb 2013 23:55:37 -0800 Subject: [PATCH 1/2] Fix vector syntax in error messages --- src/librustc/middle/typeck/infer/mod.rs | 3 +-- src/librustc/util/ppaux.rs | 14 ++++++++------ src/test/compile-fail/issue-2149.rs | 2 +- src/test/compile-fail/issue-4517.rs | 6 ++++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/test/compile-fail/issue-4517.rs diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 7d799b7ea2fb6..55a9527213848 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -733,10 +733,10 @@ impl @mut InferCtxt { fn report_mismatched_types(sp: span, e: ty::t, a: ty::t, err: &ty::type_err) { - // Don't report an error if expected is ty_err let resolved_expected = self.resolve_type_vars_if_possible(e); let mk_msg = match ty::get(resolved_expected).sty { + // Don't report an error if expected is ty_err ty::ty_err => return, _ => { // if I leave out : ~str, it infers &str and complains @@ -779,4 +779,3 @@ impl @mut InferCtxt { } } - diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8b0c84cff8343..924574a4c0c01 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -238,6 +238,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { ty::vstore_fixed(n) => fmt!("%u", n), ty::vstore_uniq => ~"~", ty::vstore_box => ~"@", + /* FIXME(#4517) slice fmt */ ty::vstore_slice(r) => region_to_str(cx, r) } } @@ -245,12 +246,13 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { match vs { ty::vstore_fixed(_) => { - fmt!("%s/%s", ty, vstore_to_str(cx, vs)) + fmt!("[%s * %s]", ty, vstore_to_str(cx, vs)) } + /* FIXME(#4517) slice fmt */ ty::vstore_slice(_) => { fmt!("%s/%s", vstore_to_str(cx, vs), ty) } - _ => fmt!("%s%s", vstore_to_str(cx, vs), ty) + _ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty) } } @@ -453,13 +455,13 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_trait(did, ref substs, vs) => { let path = ty::item_path(cx, did); let base = ast_map::path_to_str(path, cx.sess.intr()); - let result = parameterized(cx, base, substs.self_r, substs.tps); - vstore_ty_to_str(cx, result, vs) + let ty = parameterized(cx, base, substs.self_r, substs.tps); + fmt!("%s%s", vstore_to_str(cx, vs), ty) } ty_evec(mt, vs) => { - vstore_ty_to_str(cx, fmt!("[%s]", mt_to_str(cx, mt)), vs) + vstore_ty_to_str(cx, fmt!("%s", mt_to_str(cx, mt)), vs) } - ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs), + ty_estr(vs) => fmt!("%s%s", vstore_to_str(cx, vs), ~"str"), ty_opaque_box => ~"@?", ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"closure&", ty_opaque_closure_ptr(ast::ManagedSigil) => ~"closure@", diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 7e3ffb92950ad..b3820939f8a9e 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,6 +22,6 @@ impl vec_monad for ~[A] { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&static/str]/1` does not implement any method in scope named `bind` + //~^ ERROR type `[&staticstr * 1]` does not implement any method in scope named `bind` //~^^ ERROR Unconstrained region variable } diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs new file mode 100644 index 0000000000000..18caaa697a17d --- /dev/null +++ b/src/test/compile-fail/issue-4517.rs @@ -0,0 +1,6 @@ +fn bar(int_param: int) {} + +fn main() { + let foo: [u8 * 4] = [1u8, ..4u8]; + bar(foo); //~ ERROR mismatched types: expected `int` but found `[u8 * 4]` (expected int but found vector) +} From c4ef822dc7e4fcd05f9e4663e6f5c2196129d605 Mon Sep 17 00:00:00 2001 From: oncemoreification Date: Sat, 23 Feb 2013 21:46:36 -0800 Subject: [PATCH 2/2] Fix slice printing --- src/librustc/util/ppaux.rs | 4 +--- src/test/compile-fail/issue-2149.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 924574a4c0c01..a337431cefdb8 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -238,8 +238,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { ty::vstore_fixed(n) => fmt!("%u", n), ty::vstore_uniq => ~"~", ty::vstore_box => ~"@", - /* FIXME(#4517) slice fmt */ - ty::vstore_slice(r) => region_to_str(cx, r) + ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/") } } @@ -248,7 +247,6 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { ty::vstore_fixed(_) => { fmt!("[%s * %s]", ty, vstore_to_str(cx, vs)) } - /* FIXME(#4517) slice fmt */ ty::vstore_slice(_) => { fmt!("%s/%s", vstore_to_str(cx, vs), ty) } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index b3820939f8a9e..0880cabb2abf9 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,6 +22,6 @@ impl vec_monad for ~[A] { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&staticstr * 1]` does not implement any method in scope named `bind` + //~^ ERROR type `[&static/str * 1]` does not implement any method in scope named `bind` //~^^ ERROR Unconstrained region variable }