Skip to content

Commit 4a5caf9

Browse files
committed
---
yaml --- r: 55195 b: refs/heads/snap-stage3 c: 782e06e h: refs/heads/master i: 55193: e0776bf 55191: abc4298 v: v3
1 parent 3aedb73 commit 4a5caf9

File tree

11 files changed

+143
-214
lines changed

11 files changed

+143
-214
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: 7a857673ff76c966ceb061e3794b119e2e498c40
4+
refs/heads/snap-stage3: 782e06e0e379768d03e35acae16e7ee1e1841633
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-
~~~~
2396+
~~~~ {.xfail-test}
23972397
# fn process_pair(a: int, b: int) { }
23982398
# fn process_ten() { }
23992399

branches/snap-stage3/src/libcore/os.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,36 @@ pub fn change_dir(p: &Path) -> bool {
818818
}
819819
}
820820
821+
/// Changes the current working directory to the specified
822+
/// path while acquiring a global lock, then calls `action`.
823+
/// If the change is successful, releases the lock and restores the
824+
/// CWD to what it was before, returning true.
825+
/// Returns false if the directory doesn't exist or if the directory change
826+
/// is otherwise unsuccessful.
827+
pub fn change_dir_locked(p: &Path, action: &fn()) -> bool {
828+
use unstable::global::global_data_clone_create;
829+
use unstable::{Exclusive, exclusive};
830+
831+
fn key(_: Exclusive<()>) { }
832+
833+
let result = unsafe {
834+
global_data_clone_create(key, || {
835+
~exclusive(())
836+
})
837+
};
838+
839+
do result.with_imm() |_| {
840+
let old_dir = os::getcwd();
841+
if change_dir(p) {
842+
action();
843+
change_dir(&old_dir)
844+
}
845+
else {
846+
false
847+
}
848+
}
849+
}
850+
821851
/// Copies a file from one location to another
822852
pub fn copy_file(from: &Path, to: &Path) -> bool {
823853
return do_copy_file(from, to);

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

Lines changed: 70 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,11 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
175175
kind_name = "structure";
176176
}
177177
_ => {
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());
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)));
190183
}
191184
}
192185

@@ -493,44 +486,74 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
493486
}
494487
ast::pat_tup(ref elts) => {
495488
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+
};
496498
let e_count = elts.len();
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-
}
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));
524504
}
505+
let mut i = 0u;
506+
for elts.each |elt| {
507+
check_pat(pcx, *elt, ex_elts[i]);
508+
i += 1u;
509+
}
510+
511+
fcx.write_ty(pat.id, expected);
525512
}
526513
ast::pat_box(inner) => {
527-
check_pointer_pat(pcx, Managed, inner, pat.id, pat.span, expected);
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+
}
528527
}
529528
ast::pat_uniq(inner) => {
530-
check_pointer_pat(pcx, Owned, inner, pat.id, pat.span, expected);
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+
}
531542
}
532543
ast::pat_region(inner) => {
533-
check_pointer_pat(pcx, Borrowed, inner, pat.id, pat.span, expected);
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+
}
534557
}
535558
ast::pat_vec(ref before, slice, ref after) => {
536559
let default_region_var =
@@ -554,25 +577,11 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
554577
(mt, default_region_var)
555578
},
556579
_ => {
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;
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+
);
576585
}
577586
};
578587
for before.each |elt| {
@@ -596,46 +605,3 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
596605
}
597606
}
598607

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: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -749,19 +749,6 @@ pub impl InferCtxt {
749749
}
750750
}
751751

752-
753-
fn type_error_message_str(@mut self, sp: span, mk_msg: &fn(~str) -> ~str,
754-
actual_ty: ~str, err: Option<&ty::type_err>) {
755-
let error_str = err.map_default(~"", |t_err|
756-
fmt!(" (%s)",
757-
ty::type_err_to_str(self.tcx, *t_err)));
758-
self.tcx.sess.span_err(sp,
759-
fmt!("%s%s", mk_msg(actual_ty), error_str));
760-
for err.each |err| {
761-
ty::note_and_explain_type_err(self.tcx, *err)
762-
}
763-
}
764-
765752
fn type_error_message(@mut self, sp: span, mk_msg: &fn(~str) -> ~str,
766753
actual_ty: ty::t, err: Option<&ty::type_err>) {
767754
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
@@ -770,9 +757,15 @@ pub impl InferCtxt {
770757
if ty::type_is_error(actual_ty) {
771758
return;
772759
}
773-
774-
self.type_error_message_str(sp, mk_msg, self.ty_to_str(actual_ty),
775-
err);
760+
let error_str = err.map_default(~"", |t_err|
761+
fmt!(" (%s)",
762+
ty::type_err_to_str(self.tcx, *t_err)));
763+
self.tcx.sess.span_err(sp,
764+
fmt!("%s%s", mk_msg(self.ty_to_str(actual_ty)),
765+
error_str));
766+
for err.each |err| {
767+
ty::note_and_explain_type_err(self.tcx, *err)
768+
}
776769
}
777770

778771
fn report_mismatched_types(@mut self, sp: span, e: ty::t, a: ty::t,

branches/snap-stage3/src/libstd/tempfile.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ mod tests {
4242
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
4343
use core::os;
4444

45-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel");
46-
os::change_dir(&root);
47-
let path = Path("frob");
48-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
49-
assert!(os::path_is_dir(&path));
50-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
51-
assert!(os::path_is_dir(&path));
45+
let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel").
46+
expect("recursive_mkdir_rel");
47+
assert!(do os::change_dir_locked(&root) {
48+
let path = Path("frob");
49+
debug!("recursive_mkdir_rel: Making: %s in cwd %s [%?]", path.to_str(),
50+
os::getcwd().to_str(),
51+
os::path_exists(&path));
52+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
53+
assert!(os::path_is_dir(&path));
54+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
55+
assert!(os::path_is_dir(&path));
56+
});
5257
}
5358

5459
#[test]
@@ -67,18 +72,21 @@ mod tests {
6772
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
6873
use core::os;
6974

70-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel_2");
71-
os::change_dir(&root);
72-
let path = Path("./frob/baz");
73-
debug!("...Making: %s in cwd %s", path.to_str(), os::getcwd().to_str());
74-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
75-
assert!(os::path_is_dir(&path));
76-
assert!(os::path_is_dir(&path.pop()));
77-
let path2 = Path("quux/blat");
78-
debug!("Making: %s in cwd %s", path2.to_str(), os::getcwd().to_str());
79-
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
80-
assert!(os::path_is_dir(&path2));
81-
assert!(os::path_is_dir(&path2.pop()));
75+
let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel_2").
76+
expect("recursive_mkdir_rel_2");
77+
assert!(do os::change_dir_locked(&root) {
78+
let path = Path("./frob/baz");
79+
debug!("recursive_mkdir_rel_2: Making: %s in cwd %s [%?]", path.to_str(),
80+
os::getcwd().to_str(), os::path_exists(&path));
81+
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
82+
assert!(os::path_is_dir(&path));
83+
assert!(os::path_is_dir(&path.pop()));
84+
let path2 = Path("quux/blat");
85+
debug!("recursive_mkdir_rel_2: Making: %s in cwd %s", path2.to_str(),
86+
os::getcwd().to_str());
87+
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
88+
assert!(os::path_is_dir(&path2));
89+
assert!(os::path_is_dir(&path2.pop()));
90+
});
8291
}
83-
84-
}
92+
}

branches/snap-stage3/src/llvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6
1+
Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb
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 types: expected `()` but found a vector pattern
3+
[()] => { } //~ ERROR mismatched type: expected `()` but found vector
44
}
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
match ~"foo" {
3-
['f', 'o', .._] => { } //~ ERROR mismatched types: expected `~str` but found a vector pattern
3+
['f', 'o', .._] => { } //~ ERROR mismatched type: expected `~str` but found vector
44
_ => { }
55
}
66
}

0 commit comments

Comments
 (0)