Skip to content

Commit 3aedb73

Browse files
committed
---
yaml --- r: 55194 b: refs/heads/snap-stage3 c: 7a85767 h: refs/heads/master v: v3
1 parent e0776bf commit 3aedb73

36 files changed

+496
-235
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ab1d8ead91ac23e07f4ba9a186e0ae7ddbcd2515
4+
refs/heads/snap-stage3: 7a857673ff76c966ceb061e3794b119e2e498c40
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ variables in the arm's block, and control enters the block.
23932393
An example of an `match` expression:
23942394

23952395

2396-
~~~~ {.xfail-test}
2396+
~~~~
23972397
# fn process_pair(a: int, b: int) { }
23982398
# fn process_ten() { }
23992399

branches/snap-stage3/src/librustc/middle/trans/adt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
409409
st.fields.len() - (if dtor { 1 } else { 0 })
410410
}
411411
General(ref cases) => cases[discr as uint].fields.len() - 1,
412-
NullablePointer{ nonnull: ref nonnull, nndiscr, _ } => {
413-
if discr == nndiscr { nonnull.fields.len() } else { 0 }
412+
NullablePointer{ nonnull: ref nonnull, nndiscr, nullfields: ref nullfields, _ } => {
413+
if discr == nndiscr { nonnull.fields.len() } else { nullfields.len() }
414414
}
415415
}
416416
}

branches/snap-stage3/src/librustc/middle/typeck/check/_match.rs

Lines changed: 104 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,18 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
175175
kind_name = "structure";
176176
}
177177
_ => {
178-
tcx.sess.span_fatal(
179-
pat.span,
180-
fmt!("mismatched types: expected `%s` but found enum or \
181-
structure",
182-
fcx.infcx().ty_to_str(expected)));
178+
let resolved_expected =
179+
fcx.infcx().ty_to_str(fcx.infcx().resolve_type_vars_if_possible(expected));
180+
fcx.infcx().type_error_message_str(pat.span,
181+
|actual| {
182+
fmt!("mismatched types: expected `%s` but found %s",
183+
resolved_expected, actual)},
184+
~"an enum or structure pattern",
185+
None);
186+
fcx.write_error(pat.id);
187+
kind_name = "[error]";
188+
arg_types = (copy subpats).get_or_default(~[]).map(|_|
189+
ty::mk_err());
183190
}
184191
}
185192

@@ -486,74 +493,44 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
486493
}
487494
ast::pat_tup(ref elts) => {
488495
let s = structure_of(fcx, pat.span, expected);
489-
let ex_elts = match s {
490-
ty::ty_tup(ref elts) => elts,
491-
_ => {
492-
tcx.sess.span_fatal
493-
(pat.span,
494-
fmt!("mismatched types: expected `%s`, found tuple",
495-
fcx.infcx().ty_to_str(expected)));
496-
}
497-
};
498496
let e_count = elts.len();
499-
if e_count != ex_elts.len() {
500-
tcx.sess.span_fatal
501-
(pat.span, fmt!("mismatched types: expected a tuple \
502-
with %u fields, found one with %u \
503-
fields", ex_elts.len(), e_count));
504-
}
505-
let mut i = 0u;
506-
for elts.each |elt| {
507-
check_pat(pcx, *elt, ex_elts[i]);
508-
i += 1u;
497+
match s {
498+
ty::ty_tup(ref ex_elts) if e_count == ex_elts.len() => {
499+
for elts.eachi |i, elt| {
500+
check_pat(pcx, *elt, ex_elts[i]);
501+
}
502+
fcx.write_ty(pat.id, expected);
503+
}
504+
_ => {
505+
for elts.each |elt| {
506+
check_pat(pcx, *elt, ty::mk_err());
507+
}
508+
let actual = ty::mk_tup(tcx, elts.map(|pat_var| {
509+
fcx.node_ty(pat_var.id)
510+
}));
511+
// use terr_tuple_size if both types are tuples
512+
let type_error = match s {
513+
ty::ty_tup(ref ex_elts) =>
514+
ty::terr_tuple_size(ty::expected_found{expected: ex_elts.len(),
515+
found: e_count}),
516+
_ => ty::terr_mismatch
517+
};
518+
fcx.infcx().report_mismatched_types(pat.span,
519+
expected,
520+
actual,
521+
&type_error);
522+
fcx.write_error(pat.id);
523+
}
509524
}
510-
511-
fcx.write_ty(pat.id, expected);
512525
}
513526
ast::pat_box(inner) => {
514-
match structure_of(fcx, pat.span, expected) {
515-
ty::ty_box(e_inner) => {
516-
check_pat(pcx, inner, e_inner.ty);
517-
fcx.write_ty(pat.id, expected);
518-
}
519-
_ => {
520-
tcx.sess.span_fatal(
521-
pat.span,
522-
~"mismatched types: expected `" +
523-
fcx.infcx().ty_to_str(expected) +
524-
~"` found box");
525-
}
526-
}
527+
check_pointer_pat(pcx, Managed, inner, pat.id, pat.span, expected);
527528
}
528529
ast::pat_uniq(inner) => {
529-
match structure_of(fcx, pat.span, expected) {
530-
ty::ty_uniq(e_inner) => {
531-
check_pat(pcx, inner, e_inner.ty);
532-
fcx.write_ty(pat.id, expected);
533-
}
534-
_ => {
535-
tcx.sess.span_fatal(
536-
pat.span,
537-
~"mismatched types: expected `" +
538-
fcx.infcx().ty_to_str(expected) +
539-
~"` found uniq");
540-
}
541-
}
530+
check_pointer_pat(pcx, Owned, inner, pat.id, pat.span, expected);
542531
}
543532
ast::pat_region(inner) => {
544-
match structure_of(fcx, pat.span, expected) {
545-
ty::ty_rptr(_, e_inner) => {
546-
check_pat(pcx, inner, e_inner.ty);
547-
fcx.write_ty(pat.id, expected);
548-
}
549-
_ => {
550-
tcx.sess.span_fatal(
551-
pat.span,
552-
~"mismatched types: expected `" +
553-
fcx.infcx().ty_to_str(expected) +
554-
~"` found borrowed pointer");
555-
}
556-
}
533+
check_pointer_pat(pcx, Borrowed, inner, pat.id, pat.span, expected);
557534
}
558535
ast::pat_vec(ref before, slice, ref after) => {
559536
let default_region_var =
@@ -577,11 +554,25 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
577554
(mt, default_region_var)
578555
},
579556
_ => {
580-
tcx.sess.span_fatal(
581-
pat.span,
582-
fmt!("mismatched type: expected `%s` but found vector",
583-
fcx.infcx().ty_to_str(expected))
584-
);
557+
for before.each |&elt| {
558+
check_pat(pcx, elt, ty::mk_err());
559+
}
560+
for slice.each |&elt| {
561+
check_pat(pcx, elt, ty::mk_err());
562+
}
563+
for after.each |&elt| {
564+
check_pat(pcx, elt, ty::mk_err());
565+
}
566+
let resolved_expected =
567+
fcx.infcx().ty_to_str(fcx.infcx().resolve_type_vars_if_possible(expected));
568+
fcx.infcx().type_error_message_str(pat.span,
569+
|actual| {
570+
fmt!("mismatched types: expected `%s` but found %s",
571+
resolved_expected, actual)},
572+
~"a vector pattern",
573+
None);
574+
fcx.write_error(pat.id);
575+
return;
585576
}
586577
};
587578
for before.each |elt| {
@@ -605,3 +596,46 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
605596
}
606597
}
607598
599+
// Helper function to check @, ~ and & patterns
600+
pub fn check_pointer_pat(pcx: &pat_ctxt,
601+
pointer_kind: PointerKind,
602+
inner: @ast::pat,
603+
pat_id: ast::node_id,
604+
span: span,
605+
expected: ty::t) {
606+
let fcx = pcx.fcx;
607+
let check_inner: &fn(ty::mt) = |e_inner| {
608+
check_pat(pcx, inner, e_inner.ty);
609+
fcx.write_ty(pat_id, expected);
610+
};
611+
match structure_of(fcx, span, expected) {
612+
ty::ty_box(e_inner) if pointer_kind == Managed => {
613+
check_inner(e_inner);
614+
}
615+
ty::ty_uniq(e_inner) if pointer_kind == Owned => {
616+
check_inner(e_inner);
617+
}
618+
ty::ty_rptr(_, e_inner) if pointer_kind == Borrowed => {
619+
check_inner(e_inner);
620+
}
621+
_ => {
622+
check_pat(pcx, inner, ty::mk_err());
623+
let resolved_expected =
624+
fcx.infcx().ty_to_str(fcx.infcx().resolve_type_vars_if_possible(expected));
625+
fcx.infcx().type_error_message_str(span, |actual| {
626+
fmt!("mismatched types: expected `%s` but found %s",
627+
resolved_expected, actual)},
628+
fmt!("%s pattern", match pointer_kind {
629+
Managed => "an @-box",
630+
Owned => "a ~-box",
631+
Borrowed => "an &-pointer"
632+
}),
633+
None);
634+
fcx.write_error(pat_id);
635+
}
636+
}
637+
}
638+
639+
#[deriving(Eq)]
640+
enum PointerKind { Managed, Owned, Borrowed }
641+

branches/snap-stage3/src/librustc/middle/typeck/infer/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,25 +749,32 @@ pub impl InferCtxt {
749749
}
750750
}
751751

752-
fn type_error_message(@mut self, sp: span, mk_msg: &fn(~str) -> ~str,
753-
actual_ty: ty::t, err: Option<&ty::type_err>) {
754-
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
755752

756-
// Don't report an error if actual type is ty_err.
757-
if ty::type_is_error(actual_ty) {
758-
return;
759-
}
753+
fn type_error_message_str(@mut self, sp: span, mk_msg: &fn(~str) -> ~str,
754+
actual_ty: ~str, err: Option<&ty::type_err>) {
760755
let error_str = err.map_default(~"", |t_err|
761756
fmt!(" (%s)",
762757
ty::type_err_to_str(self.tcx, *t_err)));
763758
self.tcx.sess.span_err(sp,
764-
fmt!("%s%s", mk_msg(self.ty_to_str(actual_ty)),
765-
error_str));
759+
fmt!("%s%s", mk_msg(actual_ty), error_str));
766760
for err.each |err| {
767761
ty::note_and_explain_type_err(self.tcx, *err)
768762
}
769763
}
770764

765+
fn type_error_message(@mut self, sp: span, mk_msg: &fn(~str) -> ~str,
766+
actual_ty: ty::t, err: Option<&ty::type_err>) {
767+
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
768+
769+
// Don't report an error if actual type is ty_err.
770+
if ty::type_is_error(actual_ty) {
771+
return;
772+
}
773+
774+
self.type_error_message_str(sp, mk_msg, self.ty_to_str(actual_ty),
775+
err);
776+
}
777+
771778
fn report_mismatched_types(@mut self, sp: span, e: ty::t, a: ty::t,
772779
err: &ty::type_err) {
773780
let resolved_expected =

branches/snap-stage3/src/llvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb
1+
Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[link(name = "issue2196a", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[link(name = "issue2196b", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
14+
use a(name = "issue2196a");
15+
16+
type d = str;
17+
impl d for d { }
18+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[link(name = "issue2196c", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
14+
use b(name = "issue2196b");
15+
#[path = "issue-2196-d.rs"]
16+
mod d;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use b::d;
12+
13+
type t = uint;
14+

branches/snap-stage3/src/test/auxiliary/issue-2196-d.rs

Whitespace-only changes.

branches/snap-stage3/src/test/auxiliary/issue2378a.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[link (name = "issue2378a")];
12-
#[crate_type = "lib"];
13-
1411
enum maybe<T> { just(T), nothing }
1512

16-
impl <T:Copy> Index<uint,T> for maybe<T> {
17-
fn index(&self, idx: &uint) -> T {
13+
impl copy> for maybe<T> for methods<T {
14+
fn ~[](idx: uint) -> T {
1815
match self {
19-
&just(ref t) => copy *t,
20-
&nothing => { fail!(); }
16+
just(t) { t }
17+
nothing { fail!(); }
2118
}
2219
}
2320
}

branches/snap-stage3/src/test/auxiliary/issue2378b.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[link (name = "issue2378b")];
12-
#[crate_type = "lib"];
13-
14-
extern mod issue2378a;
11+
use issue2378a;
1512

1613
use issue2378a::maybe;
14+
use issue2378a::methods;
1715

18-
struct two_maybes<T> {a: maybe<T>, b: maybe<T>}
16+
type two_maybes<T> = {a: maybe<T>, b: maybe<T>};
1917

20-
impl <T:Copy> Index<uint,(T,T)> for two_maybes<T> {
21-
fn index(&self, idx: &uint) -> (T, T) {
22-
(self.a[*idx], self.b[*idx])
18+
impl copy> for two_maybes<T> for methods<T {
19+
fn ~[](idx: uint) -> (T, T) {
20+
(self.a[idx], self.b[idx])
2321
}
2422
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
match () {
3-
[()] => { } //~ ERROR mismatched type: expected `()` but found vector
3+
[()] => { } //~ ERROR mismatched types: expected `()` but found a vector pattern
44
}
55
}

0 commit comments

Comments
 (0)