Skip to content

Commit 580df4d

Browse files
committed
auto merge of #5084 : oncemoreification/rust/issue-4517, r=brson
Patch for #4517 This works for fixed vectors, but I am unclear how slices should be printed, simply '&[...]' or... e.i. How should regions be printed?
2 parents 6e5705a + c4ef822 commit 580df4d

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/librustc/middle/typeck/infer/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,10 @@ impl @mut InferCtxt {
734734

735735
fn report_mismatched_types(&self, sp: span, e: ty::t, a: ty::t,
736736
err: &ty::type_err) {
737-
// Don't report an error if expected is ty_err
738737
let resolved_expected =
739738
self.resolve_type_vars_if_possible(e);
740739
let mk_msg = match ty::get(resolved_expected).sty {
740+
// Don't report an error if expected is ty_err
741741
ty::ty_err => return,
742742
_ => {
743743
// if I leave out : ~str, it infers &str and complains
@@ -780,4 +780,3 @@ impl @mut InferCtxt {
780780
}
781781

782782
}
783-

src/librustc/util/ppaux.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
238238
ty::vstore_fixed(n) => fmt!("%u", n),
239239
ty::vstore_uniq => ~"~",
240240
ty::vstore_box => ~"@",
241-
ty::vstore_slice(r) => region_to_str(cx, r)
241+
ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/")
242242
}
243243
}
244244

245245
pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
246246
match vs {
247247
ty::vstore_fixed(_) => {
248-
fmt!("%s/%s", ty, vstore_to_str(cx, vs))
248+
fmt!("[%s * %s]", ty, vstore_to_str(cx, vs))
249249
}
250250
ty::vstore_slice(_) => {
251251
fmt!("%s/%s", vstore_to_str(cx, vs), ty)
252252
}
253-
_ => fmt!("%s%s", vstore_to_str(cx, vs), ty)
253+
_ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty)
254254
}
255255
}
256256

@@ -453,13 +453,13 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
453453
ty_trait(did, ref substs, vs) => {
454454
let path = ty::item_path(cx, did);
455455
let base = ast_map::path_to_str(path, cx.sess.intr());
456-
let result = parameterized(cx, base, substs.self_r, substs.tps);
457-
vstore_ty_to_str(cx, result, vs)
456+
let ty = parameterized(cx, base, substs.self_r, substs.tps);
457+
fmt!("%s%s", vstore_to_str(cx, vs), ty)
458458
}
459459
ty_evec(mt, vs) => {
460-
vstore_ty_to_str(cx, fmt!("[%s]", mt_to_str(cx, mt)), vs)
460+
vstore_ty_to_str(cx, fmt!("%s", mt_to_str(cx, mt)), vs)
461461
}
462-
ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs),
462+
ty_estr(vs) => fmt!("%s%s", vstore_to_str(cx, vs), ~"str"),
463463
ty_opaque_box => ~"@?",
464464
ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"closure&",
465465
ty_opaque_closure_ptr(ast::ManagedSigil) => ~"closure@",

src/test/compile-fail/issue-2149.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ impl<A> vec_monad<A> for ~[A] {
2222
}
2323
fn main() {
2424
["hi"].bind(|x| [x] );
25-
//~^ ERROR type `[&static/str]/1` does not implement any method in scope named `bind`
25+
//~^ ERROR type `[&static/str * 1]` does not implement any method in scope named `bind`
2626
//~^^ ERROR Unconstrained region variable
2727
}

src/test/compile-fail/issue-4517.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn bar(int_param: int) {}
2+
3+
fn main() {
4+
let foo: [u8 * 4] = [1u8, ..4u8];
5+
bar(foo); //~ ERROR mismatched types: expected `int` but found `[u8 * 4]` (expected int but found vector)
6+
}

0 commit comments

Comments
 (0)