From 113cc0ef96544c44bf27bc42cbd912f403beb33f Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Mon, 5 Aug 2013 22:09:34 +0200 Subject: [PATCH 01/62] adjust error message to coding style --- src/libextra/ebml.rs | 4 +- src/libextra/terminfo/parser/compiled.rs | 8 +-- src/librustc/metadata/tydecode.rs | 4 +- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/ty.rs | 56 +++++++-------- src/librustc/middle/typeck/astconv.rs | 2 +- src/librustc/middle/typeck/check/_match.rs | 14 ++-- src/librustc/middle/typeck/check/mod.rs | 23 +++--- src/librustc/middle/typeck/check/vtable.rs | 2 +- src/librustc/middle/typeck/infer/doc.rs | 2 +- .../middle/typeck/infer/error_reporting.rs | 4 +- src/librustc/middle/typeck/infer/mod.rs | 2 +- src/librustpkg/installed_packages.rs | 2 +- .../testsuite/pass/src/fancy-lib/foo.rs | 2 +- .../testsuite/pass/src/install-paths/bench.rs | 2 +- .../testsuite/pass/src/simple-lib/src/foo.rs | 2 +- src/libstd/num/strconv.rs | 2 +- src/libstd/ops.rs | 2 +- src/libstd/rt/io/mock.rs | 2 +- src/libstd/rt/io/mod.rs | 2 +- src/libstd/rt/io/timer.rs | 2 +- src/libstd/rt/metrics.rs | 2 +- src/libstd/rt/sleeper_list.rs | 2 +- src/libstd/rt/util.rs | 2 +- src/libsyntax/parse/parser.rs | 16 ++--- src/test/compile-fail/bad-bang-ann-3.rs | 2 +- src/test/compile-fail/bad-bang-ann.rs | 2 +- src/test/compile-fail/bad-const-type.rs | 2 +- src/test/compile-fail/bang-tailexpr.rs | 2 +- .../block-must-not-have-result-do.rs | 2 +- .../block-must-not-have-result-res.rs | 2 +- .../block-must-not-have-result-while.rs | 2 +- .../borrowck-alias-mut-base-ptr.rs | 2 +- .../borrowck-anon-fields-struct.rs | 2 +- .../borrowck-anon-fields-tuple.rs | 2 +- .../borrowck-anon-fields-variant.rs | 2 +- .../borrowck-bad-nested-calls-free.rs | 2 +- .../borrowck-bad-nested-calls-move.rs | 2 +- ...ck-borrow-mut-base-ptr-in-aliasable-loc.rs | 2 +- .../borrowck-move-in-irrefut-pat.rs | 2 +- .../borrowck-move-mut-base-ptr.rs | 2 +- .../borrowck-swap-mut-base-ptr.rs | 2 +- .../cast-immutable-mutable-trait.rs | 2 +- .../cast-vector-to-unsafe-nonstatic.rs | 2 +- ...bounds-cant-promote-superkind-in-struct.rs | 2 +- .../closure-bounds-not-builtin.rs | 2 +- .../compile-fail/closure-bounds-subtype.rs | 2 +- src/test/compile-fail/coherence_inherent.rs | 2 +- .../compile-fail/coherence_inherent_cc.rs | 2 +- src/test/compile-fail/deprecated-auto-code.rs | 2 +- .../compile-fail/do-lambda-requires-braces.rs | 2 +- src/test/compile-fail/do1.rs | 2 +- src/test/compile-fail/do2.rs | 2 +- src/test/compile-fail/estr-subtyping.rs | 8 +-- src/test/compile-fail/evec-subtyping.rs | 18 ++--- src/test/compile-fail/extern-no-call.rs | 2 +- .../fully-qualified-type-name2.rs | 2 +- .../fully-qualified-type-name3.rs | 2 +- src/test/compile-fail/if-branch-types.rs | 2 +- .../compile-fail/if-without-else-result.rs | 2 +- .../integer-literal-suffix-inference.rs | 72 +++++++++---------- src/test/compile-fail/issue-2995.rs | 2 +- src/test/compile-fail/issue-3036.rs | 2 +- src/test/compile-fail/issue-3477.rs | 2 +- src/test/compile-fail/issue-3680.rs | 2 +- src/test/compile-fail/issue-4517.rs | 2 +- src/test/compile-fail/issue-4736.rs | 2 +- src/test/compile-fail/issue-4968.rs | 2 +- src/test/compile-fail/issue-5100.rs | 14 ++-- src/test/compile-fail/issue-5358-1.rs | 2 +- src/test/compile-fail/issue-5358.rs | 2 +- src/test/compile-fail/issue-6762.rs | 2 +- .../compile-fail/loop-does-not-diverge.rs | 2 +- src/test/compile-fail/lub-if.rs | 2 +- src/test/compile-fail/lub-match.rs | 2 +- src/test/compile-fail/main-wrong-location.rs | 2 +- src/test/compile-fail/map-types.rs | 2 +- src/test/compile-fail/match-struct.rs | 2 +- src/test/compile-fail/match-vec-mismatch-2.rs | 2 +- src/test/compile-fail/match-vec-mismatch.rs | 2 +- src/test/compile-fail/multitrait.rs | 2 +- src/test/compile-fail/noexporttypeexe.rs | 2 +- .../non-constant-expr-for-vec-repeat.rs | 2 +- .../compile-fail/omitted-arg-in-item-fn.rs | 2 +- .../compile-fail/omitted-arg-wrong-types.rs | 4 +- .../compile-fail/pattern-error-continue.rs | 6 +- src/test/compile-fail/regions-bounds.rs | 4 +- .../regions-free-region-ordering-callee.rs | 2 +- .../regions-free-region-ordering-caller.rs | 2 +- .../regions-infer-paramd-indirect.rs | 2 +- .../regions-infer-paramd-method.rs | 2 +- .../compile-fail/regions-ref-in-fn-arg.rs | 2 +- src/test/compile-fail/regions-trait-3.rs | 2 +- src/test/compile-fail/repeat_count.rs | 2 +- .../compile-fail/struct-base-wrong-type.rs | 4 +- src/test/compile-fail/suppressed-error.rs | 4 +- .../tag-that-dare-not-speak-its-name.rs | 2 +- src/test/compile-fail/tag-variant-disr-dup.rs | 2 +- src/test/compile-fail/terr-in-field.rs | 2 +- src/test/compile-fail/terr-sorts.rs | 2 +- .../trait-impl-method-mismatch.rs | 2 +- src/test/compile-fail/tuple-arity-mismatch.rs | 2 +- .../tutorial-suffix-inference-test.rs | 6 +- src/test/compile-fail/type-parameter-names.rs | 4 +- src/test/debug-info/borrowed-basic.rs | 2 +- src/test/debug-info/borrowed-c-style-enum.rs | 2 +- src/test/debug-info/borrowed-enum.rs | 2 +- src/test/debug-info/borrowed-managed-basic.rs | 2 +- src/test/debug-info/borrowed-struct.rs | 2 +- src/test/debug-info/borrowed-tuple.rs | 2 +- src/test/debug-info/borrowed-unique-basic.rs | 2 +- src/test/debug-info/boxed-struct.rs | 2 +- src/test/debug-info/boxed-vec.rs | 2 +- .../debug-info/c-style-enum-in-composite.rs | 2 +- src/test/debug-info/c-style-enum.rs | 2 +- .../debug-info/destructured-fn-argument.rs | 2 +- src/test/debug-info/destructured-local.rs | 2 +- src/test/debug-info/evec-in-struct.rs | 2 +- src/test/debug-info/function-arguments.rs | 2 +- src/test/debug-info/managed-enum.rs | 2 +- .../managed-pointer-within-unique-vec.rs | 2 +- .../managed-pointer-within-unique.rs | 2 +- src/test/debug-info/nil-enum.rs | 2 +- src/test/debug-info/option-like-enum.rs | 2 +- .../packed-struct-with-destructor.rs | 2 +- src/test/debug-info/packed-struct.rs | 2 +- src/test/debug-info/simple-struct.rs | 2 +- src/test/debug-info/simple-tuple.rs | 2 +- src/test/debug-info/struct-in-struct.rs | 2 +- src/test/debug-info/struct-style-enum.rs | 2 +- src/test/debug-info/tuple-in-struct.rs | 2 +- src/test/debug-info/tuple-in-tuple.rs | 2 +- src/test/debug-info/tuple-style-enum.rs | 2 +- src/test/debug-info/unique-enum.rs | 2 +- .../borrowck-scope-of-deref-issue-4666.rs | 2 +- src/test/run-pass/cast-mutable-trait.rs | 2 +- .../run-pass/conditional-debug-macro-off.rs | 2 +- .../run-pass/conditional-debug-macro-on.rs | 2 +- .../deriving-cmp-generic-struct-enum.rs | 2 +- .../deriving-via-extension-struct-empty.rs | 2 +- src/test/run-pass/enum-vec-initializer.rs | 2 +- ...xternal-iterators-hashmap-break-restart.rs | 2 +- .../foreach-external-iterators-hashmap.rs | 2 +- .../run-pass/foreach-external-iterators.rs | 2 +- .../run-pass/func-arg-incomplete-pattern.rs | 2 +- src/test/run-pass/issue-2804.rs | 4 +- src/test/run-pass/issue-4252.rs | 2 +- .../run-pass/issue-6141-leaking-owned-fn.rs | 2 +- src/test/run-pass/issue-6341.rs | 2 +- src/test/run-pass/move-out-of-field.rs | 2 +- src/test/run-pass/option_addition.rs | 2 +- src/test/run-pass/rt-start-main-thread.rs | 2 +- src/test/run-pass/unique-object-move.rs | 2 +- 153 files changed, 271 insertions(+), 272 deletions(-) diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index f66677c21f7d1..286ebe0b8d036 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -305,7 +305,7 @@ pub mod reader { self.pos = r_doc.end; let str = r_doc.as_str_slice(); if lbl != str { - fail!("Expected label %s but found %s", lbl, str); + fail!("Expected label %s, found %s", lbl, str); } } } @@ -326,7 +326,7 @@ pub mod reader { r_doc.start, r_doc.end); if r_tag != (exp_tag as uint) { - fail!("expected EBML doc with tag %? but found tag %?", exp_tag, r_tag); + fail!("expected EBML doc with tag %?, found tag %?", exp_tag, r_tag); } if r_doc.end > self.parent.end { fail!("invalid EBML, child extends to 0x%x, parent to 0x%x", diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index 426cacb62faad..2604682f2e9a7 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -178,7 +178,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { // Check magic number let magic = file.read_le_u16(); if (magic != 0x011A) { - return Err(fmt!("invalid magic number: expected %x but found %x", 0x011A, magic as uint)); + return Err(fmt!("invalid magic number: expected %x, found %x", 0x011A, magic as uint)); } let names_bytes = file.read_le_i16() as int; @@ -196,19 +196,19 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { debug!("string_table_bytes = %?", string_table_bytes); if (bools_bytes as uint) > boolnames.len() { - error!("expected bools_bytes to be less than %? but found %?", boolnames.len(), + error!("expected bools_bytes to be less than %?, found %?", boolnames.len(), bools_bytes); return Err(~"incompatible file: more booleans than expected"); } if (numbers_count as uint) > numnames.len() { - error!("expected numbers_count to be less than %? but found %?", numnames.len(), + error!("expected numbers_count to be less than %?, found %?", numnames.len(), numbers_count); return Err(~"incompatible file: more numbers than expected"); } if (string_offsets_count as uint) > stringnames.len() { - error!("expected string_offsets_count to be less than %? but found %?", stringnames.len(), + error!("expected string_offsets_count to be less than %?, found %?", stringnames.len(), string_offsets_count); return Err(~"incompatible file: more string offsets than expected"); } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 89b30e46ac06d..a922db55a3156 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -542,12 +542,12 @@ pub fn parse_def_id(buf: &[u8]) -> ast::def_id { let crate_num = match uint::parse_bytes(crate_part, 10u) { Some(cn) => cn as int, - None => fail!("internal error: parse_def_id: crate number expected, but found %?", + None => fail!("internal error: parse_def_id: crate number expected, found %?", crate_part) }; let def_num = match uint::parse_bytes(def_part, 10u) { Some(dn) => dn as int, - None => fail!("internal error: parse_def_id: id expected, but found %?", + None => fail!("internal error: parse_def_id: id expected, found %?", def_part) }; ast::def_id { crate: crate_num, node: def_num } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 725beee6604e7..c7f60cf0248a6 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -415,7 +415,7 @@ pub fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::pat) { if !pat_is_binding_or_wild(bcx.tcx().def_map, p) { bcx.sess().span_bug( p.span, - fmt!("Expected an identifier pattern but found p: %s", + fmt!("Expected an identifier pattern, found p: %s", pat_to_str(p, bcx.sess().intr()))); } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 29b975cdf99f8..923e94eca624d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3389,15 +3389,15 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { match *err { terr_mismatch => ~"types differ", terr_purity_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_abi_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_onceness_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_sigil_mismatch(values) => { @@ -3411,25 +3411,25 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { terr_ptr_mutability => ~"pointers differ in mutability", terr_ref_mutability => ~"references differ in mutability", terr_ty_param_size(values) => { - fmt!("expected a type with %? type params \ - but found one with %? type params", + fmt!("expected a type with %? type params, \ + found one with %? type params", values.expected, values.found) } terr_tuple_size(values) => { - fmt!("expected a tuple with %? elements \ - but found one with %? elements", + fmt!("expected a tuple with %? elements, \ + found one with %? elements", values.expected, values.found) } terr_record_size(values) => { - fmt!("expected a record with %? fields \ - but found one with %? fields", + fmt!("expected a record with %? fields, \ + found one with %? fields", values.expected, values.found) } terr_record_mutability => { ~"record elements differ in mutability" } terr_record_fields(values) => { - fmt!("expected a record with field `%s` but found one with field \ + fmt!("expected a record with field `%s`, found one with field \ `%s`", cx.sess.str_of(values.expected), cx.sess.str_of(values.found)) @@ -3446,22 +3446,22 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { } terr_regions_insufficiently_polymorphic(br, _) => { fmt!("expected bound lifetime parameter %s, \ - but found concrete lifetime", + found concrete lifetime", bound_region_ptr_to_str(cx, br)) } terr_regions_overly_polymorphic(br, _) => { fmt!("expected concrete lifetime, \ - but found bound lifetime parameter %s", + found bound lifetime parameter %s", bound_region_ptr_to_str(cx, br)) } terr_vstores_differ(k, ref values) => { - fmt!("%s storage differs: expected %s but found %s", + fmt!("%s storage differs: expected %s, found %s", terr_vstore_kind_to_str(k), vstore_to_str(cx, (*values).expected), vstore_to_str(cx, (*values).found)) } terr_trait_stores_differ(_, ref values) => { - fmt!("trait storage differs: expected %s but found %s", + fmt!("trait storage differs: expected %s, found %s", trait_store_to_str(cx, (*values).expected), trait_store_to_str(cx, (*values).found)) } @@ -3470,38 +3470,38 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { type_err_to_str(cx, err)) } terr_sorts(values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", ty_sort_str(cx, values.expected), ty_sort_str(cx, values.found)) } terr_traits(values) => { - fmt!("expected trait %s but found trait %s", + fmt!("expected trait %s, found trait %s", item_path_str(cx, values.expected), item_path_str(cx, values.found)) } terr_builtin_bounds(values) => { if values.expected.is_empty() { - fmt!("expected no bounds but found `%s`", + fmt!("expected no bounds, found `%s`", values.found.user_string(cx)) } else if values.found.is_empty() { - fmt!("expected bounds `%s` but found no bounds", + fmt!("expected bounds `%s`, found no bounds", values.expected.user_string(cx)) } else { - fmt!("expected bounds `%s` but found bounds `%s`", + fmt!("expected bounds `%s`, found bounds `%s`", values.expected.user_string(cx), values.found.user_string(cx)) } } terr_integer_as_char => { - fmt!("expected an integral type but found char") + fmt!("expected an integral type, found char") } terr_int_mismatch(ref values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", values.expected.to_str(), values.found.to_str()) } terr_float_mismatch(ref values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", values.expected.to_str(), values.found.to_str()) } @@ -4327,7 +4327,7 @@ pub fn eval_repeat_count(tcx: &T, count_expr: &ast::expr) -> const_eval::const_int(count) => if count < 0 { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found negative integer"); + repeat count, found negative integer"); return 0; } else { return count as uint @@ -4336,26 +4336,26 @@ pub fn eval_repeat_count(tcx: &T, count_expr: &ast::expr) -> const_eval::const_float(count) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found float"); + repeat count, found float"); return count as uint; } const_eval::const_str(_) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found string"); + repeat count, found string"); return 0; } const_eval::const_bool(_) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found boolean"); + repeat count, found boolean"); return 0; } }, Err(*) => { tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected constant integer for repeat count \ - but found variable"); + "expected constant integer for \ + repeat count, found variable"); return 0; } } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index ebf9d0944c9fb..e1c1ea2c7834b 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -177,7 +177,7 @@ fn ast_path_substs( if !vec::same_length(*decl_generics.type_param_defs, path.types) { this.tcx().sess.span_fatal( path.span, - fmt!("wrong number of type arguments: expected %u but found %u", + fmt!("wrong number of type arguments: expected %u, found %u", decl_generics.type_param_defs.len(), path.types.len())); } let tps = path.types.map(|a_t| ast_ty_to_ty(this, rscope, a_t)); diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 842bbff41e065..85faad6a631d2 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -159,7 +159,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"a structure pattern", None); @@ -202,7 +202,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"an enum or structure pattern", None); @@ -341,7 +341,7 @@ pub fn check_struct_pat(pcx: &pat_ctxt, pat_id: ast::NodeId, span: span, Some(&ast::def_struct(*)) | Some(&ast::def_variant(*)) => { let name = pprust::path_to_str(path, tcx.sess.intr()); tcx.sess.span_err(span, - fmt!("mismatched types: expected `%s` but found `%s`", + fmt!("mismatched types: expected `%s`, found `%s`", fcx.infcx().ty_to_str(expected), name)); } @@ -500,7 +500,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { } _ => { tcx.sess.span_err(pat.span, - fmt!("mismatched types: expected `%s` but found struct", + fmt!("mismatched types: expected `%s`, found struct", fcx.infcx().ty_to_str(expected))); error_happened = true; } @@ -536,7 +536,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { }; fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"tuple", Some(&type_error)); fcx.write_error(pat.id); } @@ -585,7 +585,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"a vector pattern", @@ -643,7 +643,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), fmt!("%s pattern", match pointer_kind { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 7f486f77447cb..52731f6dc52db 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1310,7 +1310,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::ty_bool => {} _ => fcx.type_error_message(call_expr.span, |actual| { fmt!("expected `for` closure to return `bool`, \ - but found `%s`", actual) }, + , found `%s`", actual) }, output, None) } ty::mk_nil() @@ -1358,8 +1358,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => sig, _ => { fcx.type_error_message(call_expr.span, |actual| { - fmt!("expected function but \ - found `%s`", actual) }, fn_ty, None); + fmt!("expected function, found `%s`", actual) }, fn_ty, None); &error_fn_sig } }; @@ -2751,7 +2750,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, pub fn require_integral(fcx: @mut FnCtxt, sp: span, t: ty::t) { if !type_is_integral(fcx, sp, t) { fcx.type_error_message(sp, |actual| { - fmt!("mismatched types: expected integral type but found `%s`", + fmt!("mismatched types: expected integral type, found `%s`", actual) }, t, None); } @@ -3131,28 +3130,28 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, ast::def_ty(_) | ast::def_prim_ty(_) | ast::def_ty_param(*)=> { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found type"); } ast::def_mod(*) | ast::def_foreign_mod(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found module"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found module"); } ast::def_use(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found use"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found use"); } ast::def_region(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found region"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found region"); } ast::def_typaram_binder(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type parameter"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found type parameter"); } ast::def_label(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found label"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found label"); } ast::def_self_ty(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found self ty"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found self ty"); } ast::def_method(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found method"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found method"); } } } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index abb97f0d1c7b9..456a9026d2dec 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -209,7 +209,7 @@ fn relate_trait_refs(vcx: &VtableContext, let tcx = vcx.tcx(); tcx.sess.span_err( location_info.span, - fmt!("expected %s, but found %s (%s)", + fmt!("expected %s, found %s (%s)", ppaux::trait_ref_to_str(tcx, &r_exp_trait_ref), ppaux::trait_ref_to_str(tcx, &r_act_trait_ref), ty::type_err_to_str(tcx, err))); diff --git a/src/librustc/middle/typeck/infer/doc.rs b/src/librustc/middle/typeck/infer/doc.rs index 11bfbc637169e..539418dbcb228 100644 --- a/src/librustc/middle/typeck/infer/doc.rs +++ b/src/librustc/middle/typeck/infer/doc.rs @@ -240,4 +240,4 @@ We make use of a trait-like impementation strategy to consolidate duplicated code between subtypes, GLB, and LUB computations. See the section on "Type Combining" below for details. -*/ \ No newline at end of file +*/ diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 1b325dd8a4b99..69db4bea3101c 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -173,7 +173,7 @@ impl ErrorReporting for InferCtxt { fn values_str(@mut self, values: &ValuePairs) -> Option<~str> { /*! - * Returns a string of the form "expected `%s` but found `%s`", + * Returns a string of the form "expected `%s`, found `%s`", * or None if this is a derived error. */ match *values { @@ -201,7 +201,7 @@ impl ErrorReporting for InferCtxt { return None; } - Some(fmt!("expected `%s` but found `%s`", + Some(fmt!("expected `%s`, found `%s`", expected.user_string(self.tcx), found.user_string(self.tcx))) } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 854ee835cc7dc..d2d83b2792235 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -764,7 +764,7 @@ impl InferCtxt { _ => { // if I leave out : ~str, it infers &str and complains |actual: ~str| { - fmt!("mismatched types: expected `%s` but found `%s`", + fmt!("mismatched types: expected `%s`, found `%s`", self.ty_to_str(resolved_expected), actual) } } diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index cec64f36947e0..10a141a9e558c 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -44,4 +44,4 @@ pub fn package_is_installed(p: &PkgId) -> bool { false }; is_installed -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs b/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs index 542a6af402d05..3b233c9f6a88a 100644 --- a/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs +++ b/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs @@ -9,4 +9,4 @@ // except according to those terms. pub fn do_nothing() { -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/install-paths/bench.rs b/src/librustpkg/testsuite/pass/src/install-paths/bench.rs index e1641ccf07493..3d22ddc57faa3 100644 --- a/src/librustpkg/testsuite/pass/src/install-paths/bench.rs +++ b/src/librustpkg/testsuite/pass/src/install-paths/bench.rs @@ -14,4 +14,4 @@ fn g() { while(x < 1000) { x += 1; } -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs b/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs index 542a6af402d05..3b233c9f6a88a 100644 --- a/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs +++ b/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs @@ -9,4 +9,4 @@ // except according to those terms. pub fn do_nothing() { -} \ No newline at end of file +} diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 722af828d5c11..7ab3c81b61f7a 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -726,4 +726,4 @@ mod bench { float::to_str(rng.gen()); } } -} \ No newline at end of file +} diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index 756b4a10d3c90..e41109ecf675b 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -105,4 +105,4 @@ mod bench { HasDtor { x : 10 }; } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/mock.rs b/src/libstd/rt/io/mock.rs index b580b752bd985..c46e1372c6414 100644 --- a/src/libstd/rt/io/mock.rs +++ b/src/libstd/rt/io/mock.rs @@ -47,4 +47,4 @@ impl MockWriter { impl Writer for MockWriter { fn write(&mut self, buf: &[u8]) { (self.write)(buf) } fn flush(&mut self) { (self.flush)() } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs index 838c2d86c9fa2..7d8c730e7c4b6 100644 --- a/src/libstd/rt/io/mod.rs +++ b/src/libstd/rt/io/mod.rs @@ -505,4 +505,4 @@ pub fn placeholder_error() -> IoError { desc: "Placeholder error. You shouldn't be seeing this", detail: None } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs index c7820ebf6238b..78ce52fca20ec 100644 --- a/src/libstd/rt/io/timer.rs +++ b/src/libstd/rt/io/timer.rs @@ -61,4 +61,4 @@ mod test { } } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/metrics.rs b/src/libstd/rt/metrics.rs index b0c0fa5d70862..8912420645750 100644 --- a/src/libstd/rt/metrics.rs +++ b/src/libstd/rt/metrics.rs @@ -95,4 +95,4 @@ impl ToStr for SchedMetrics { self.release_no_tombstone ) } -} \ No newline at end of file +} diff --git a/src/libstd/rt/sleeper_list.rs b/src/libstd/rt/sleeper_list.rs index d327023de978a..48012199bbef5 100644 --- a/src/libstd/rt/sleeper_list.rs +++ b/src/libstd/rt/sleeper_list.rs @@ -56,4 +56,4 @@ impl Clone for SleeperList { stack: self.stack.clone() } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index a1169954688b0..53307b3d2db81 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -118,4 +118,4 @@ pub fn get_exit_status() -> int { extern { fn rust_get_exit_status_newrt() -> libc::uintptr_t; } -} \ No newline at end of file +} diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index afa2e7a5e42f5..db520aa162553 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -366,7 +366,7 @@ impl Parser { } else { self.fatal( fmt!( - "expected `%s` but found `%s`", + "expected `%s`, found `%s`", self.token_to_str(t), self.this_token_to_str() ) @@ -872,7 +872,7 @@ impl Parser { _ => { p.fatal( fmt!( - "expected `;` or `}` but found `%s`", + "expected `;` or `}`, found `%s`", self.this_token_to_str() ) ); @@ -3192,7 +3192,7 @@ impl Parser { self.fatal( fmt!( "expected `;` or `}` after \ - expression but found `%s`", + expression, found `%s`", self.token_to_str(t) ) ); @@ -3391,7 +3391,7 @@ impl Parser { if !self.is_self_ident() { self.fatal( fmt!( - "expected `self` but found `%s`", + "expected `self`, found `%s`", self.this_token_to_str() ) ); @@ -3789,7 +3789,7 @@ impl Parser { self.fatal( fmt!( "expected `{`, `(`, or `;` after struct name \ - but found `%s`", + , found `%s`", self.this_token_to_str() ) ); @@ -3833,7 +3833,7 @@ impl Parser { token::RBRACE => {} _ => { self.span_fatal(*self.span, - fmt!("expected `,`, or '}' but found `%s`", + fmt!("expected `,`, or '}', found `%s`", self.this_token_to_str())); } } @@ -3917,7 +3917,7 @@ impl Parser { the module"); } _ => { - self.fatal(fmt!("expected item but found `%s`", + self.fatal(fmt!("expected item, found `%s`", self.this_token_to_str())); } } @@ -4165,7 +4165,7 @@ impl Parser { self.expect_keyword(keywords::Mod); } else if *self.token != token::LBRACE { self.span_fatal(*self.span, - fmt!("expected `{` or `mod` but found `%s`", + fmt!("expected `{` or `mod`, found `%s`", self.this_token_to_str())); } diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs index 9e73bbe1406bd..f7524787c7b96 100644 --- a/src/test/compile-fail/bad-bang-ann-3.rs +++ b/src/test/compile-fail/bad-bang-ann-3.rs @@ -13,7 +13,7 @@ fn bad_bang(i: uint) -> ! { return 7u; - //~^ ERROR expected `!` but found `uint` + //~^ ERROR expected `!`, found `uint` } fn main() { bad_bang(5u); } diff --git a/src/test/compile-fail/bad-bang-ann.rs b/src/test/compile-fail/bad-bang-ann.rs index 2ffb5dd29066f..a52c6f3a849a0 100644 --- a/src/test/compile-fail/bad-bang-ann.rs +++ b/src/test/compile-fail/bad-bang-ann.rs @@ -13,7 +13,7 @@ fn bad_bang(i: uint) -> ! { if i < 0u { } else { fail!(); } - //~^ ERROR expected `!` but found `()` + //~^ ERROR expected `!`, found `()` } fn main() { bad_bang(5u); } diff --git a/src/test/compile-fail/bad-const-type.rs b/src/test/compile-fail/bad-const-type.rs index 5045c87c2f3a8..21047716f303e 100644 --- a/src/test/compile-fail/bad-const-type.rs +++ b/src/test/compile-fail/bad-const-type.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected `~str` but found `int` +// error-pattern:expected `~str`, found `int` static i: ~str = 10i; fn main() { info!(i); } diff --git a/src/test/compile-fail/bang-tailexpr.rs b/src/test/compile-fail/bang-tailexpr.rs index af78e19e8c2e2..ff95f05279eea 100644 --- a/src/test/compile-fail/bang-tailexpr.rs +++ b/src/test/compile-fail/bang-tailexpr.rs @@ -9,6 +9,6 @@ // except according to those terms. fn f() -> ! { - 3i //~ ERROR expected `!` but found `int` + 3i //~ ERROR expected `!`, found `int` } fn main() { } diff --git a/src/test/compile-fail/block-must-not-have-result-do.rs b/src/test/compile-fail/block-must-not-have-result-do.rs index abeefa4aac810..687171f8c1f9b 100644 --- a/src/test/compile-fail/block-must-not-have-result-do.rs +++ b/src/test/compile-fail/block-must-not-have-result-do.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { loop { diff --git a/src/test/compile-fail/block-must-not-have-result-res.rs b/src/test/compile-fail/block-must-not-have-result-res.rs index c9b627f55f803..a3bef505d0d4e 100644 --- a/src/test/compile-fail/block-must-not-have-result-res.rs +++ b/src/test/compile-fail/block-must-not-have-result-res.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` struct r; diff --git a/src/test/compile-fail/block-must-not-have-result-while.rs b/src/test/compile-fail/block-must-not-have-result-while.rs index e4aceabf0c8fb..ed903f3fd6551 100644 --- a/src/test/compile-fail/block-must-not-have-result-while.rs +++ b/src/test/compile-fail/block-must-not-have-result-while.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { while true { diff --git a/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs b/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs index c51cf5b9538d9..1cde5cb94fd5e 100644 --- a/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs @@ -12,4 +12,4 @@ fn foo(t0: &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-struct.rs b/src/test/compile-fail/borrowck-anon-fields-struct.rs index 45a26068d8285..bcaa3b9086cf3 100644 --- a/src/test/compile-fail/borrowck-anon-fields-struct.rs +++ b/src/test/compile-fail/borrowck-anon-fields-struct.rs @@ -34,4 +34,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-tuple.rs b/src/test/compile-fail/borrowck-anon-fields-tuple.rs index ae02245c97f52..de2a8d8326808 100644 --- a/src/test/compile-fail/borrowck-anon-fields-tuple.rs +++ b/src/test/compile-fail/borrowck-anon-fields-tuple.rs @@ -32,4 +32,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-variant.rs b/src/test/compile-fail/borrowck-anon-fields-variant.rs index 3d9738df059ca..da0a9323d2c81 100644 --- a/src/test/compile-fail/borrowck-anon-fields-variant.rs +++ b/src/test/compile-fail/borrowck-anon-fields-variant.rs @@ -40,4 +40,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs index ff1ec38ad6406..c142876c5c2c5 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs @@ -40,4 +40,4 @@ fn explicit() { rewrite(&mut a)); //~ ERROR cannot borrow } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs index 0adf486b8b3ab..622d2e78ee794 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs @@ -40,4 +40,4 @@ fn explicit() { a); //~ ERROR cannot move } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs index 7e9c298ba4732..45238b36681b2 100644 --- a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs +++ b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs @@ -28,4 +28,4 @@ fn foo3(t0: &mut &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index c99a1ee60d7fd..628ccd1a5d782 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -13,4 +13,4 @@ fn let_pat() { //~^ ERROR cannot move out of dereference of & pointer } -pub fn main() {} \ No newline at end of file +pub fn main() {} diff --git a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs index 6a3832d2304cf..565629b1c306d 100644 --- a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs @@ -12,4 +12,4 @@ fn foo(t0: &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs index bea5f1f6ea765..ab6f70945be6c 100644 --- a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs @@ -13,4 +13,4 @@ fn foo<'a>(mut t0: &'a mut int, } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/cast-immutable-mutable-trait.rs b/src/test/compile-fail/cast-immutable-mutable-trait.rs index 1047a99577143..0a94d6c456081 100644 --- a/src/test/compile-fail/cast-immutable-mutable-trait.rs +++ b/src/test/compile-fail/cast-immutable-mutable-trait.rs @@ -25,4 +25,4 @@ fn main() { let s = @S { unused: 0 }; let _s2 = s as @mut T; //~ error: types differ in mutability let _s3 = &s as &mut T; //~ error: types differ in mutability -} \ No newline at end of file +} diff --git a/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs b/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs index a083757a0eb9a..ce58b260f6186 100644 --- a/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs +++ b/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs @@ -11,4 +11,4 @@ fn main() { let foo = ['h' as u8, 'i' as u8, 0 as u8]; let bar = &foo as *u8; //~ ERROR mismatched types -} \ No newline at end of file +} diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index b38cb89548807..2e7313b6afd54 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -13,7 +13,7 @@ struct X { } fn foo(blk: @fn:()) -> X { - return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds + return X { field: blk }; //~ ERROR expected bounds `Send`, found no bounds } fn main() { diff --git a/src/test/compile-fail/closure-bounds-not-builtin.rs b/src/test/compile-fail/closure-bounds-not-builtin.rs index a3484cb33dcae..fbf1acb60665b 100644 --- a/src/test/compile-fail/closure-bounds-not-builtin.rs +++ b/src/test/compile-fail/closure-bounds-not-builtin.rs @@ -5,4 +5,4 @@ fn take(f: &fn:Foo()) { //~^ ERROR only the builtin traits can be used as closure or object bounds } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index f04da0575b954..ba15d9a056544 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -11,7 +11,7 @@ fn give_any(f: &fn:()) { fn give_owned(f: &fn:Send()) { take_any(f); - take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send` + take_const_owned(f); //~ ERROR expected bounds `Send+Freeze`, found bounds `Send` } fn main() {} diff --git a/src/test/compile-fail/coherence_inherent.rs b/src/test/compile-fail/coherence_inherent.rs index 590c12826e4fe..2c3fbc827aad6 100644 --- a/src/test/compile-fail/coherence_inherent.rs +++ b/src/test/compile-fail/coherence_inherent.rs @@ -42,4 +42,4 @@ mod NoImport { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/coherence_inherent_cc.rs b/src/test/compile-fail/coherence_inherent_cc.rs index 72c6df57c4ff5..40d733f8bab5c 100644 --- a/src/test/compile-fail/coherence_inherent_cc.rs +++ b/src/test/compile-fail/coherence_inherent_cc.rs @@ -35,4 +35,4 @@ mod NoImport { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/deprecated-auto-code.rs b/src/test/compile-fail/deprecated-auto-code.rs index 1f7cbfe980782..e4576e0f57c54 100644 --- a/src/test/compile-fail/deprecated-auto-code.rs +++ b/src/test/compile-fail/deprecated-auto-code.rs @@ -12,4 +12,4 @@ #[auto_decode] //~ ERROR: `#[auto_decode]` is deprecated struct A; -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/do-lambda-requires-braces.rs b/src/test/compile-fail/do-lambda-requires-braces.rs index a836556dff881..abe066182b924 100644 --- a/src/test/compile-fail/do-lambda-requires-braces.rs +++ b/src/test/compile-fail/do-lambda-requires-braces.rs @@ -10,6 +10,6 @@ fn main() { do something - |x| do somethingelse //~ ERROR: expected `{` but found `do` + |x| do somethingelse //~ ERROR: expected `{`, found `do` |y| say(x, y) } diff --git a/src/test/compile-fail/do1.rs b/src/test/compile-fail/do1.rs index d16fa4eadd566..2da57bda273e2 100644 --- a/src/test/compile-fail/do1.rs +++ b/src/test/compile-fail/do1.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - let x = do y; //~ ERROR: expected `{` but found + let x = do y; //~ ERROR: expected `{`, found } diff --git a/src/test/compile-fail/do2.rs b/src/test/compile-fail/do2.rs index 4466c07518fec..0d815363635f2 100644 --- a/src/test/compile-fail/do2.rs +++ b/src/test/compile-fail/do2.rs @@ -12,5 +12,5 @@ fn f(f: @fn(int) -> bool) -> bool { f(10i) } fn main() { assert!(do f() |i| { i == 10i } == 10i); - //~^ ERROR: expected `bool` but found `int` + //~^ ERROR: expected `bool`, found `int` } diff --git a/src/test/compile-fail/estr-subtyping.rs b/src/test/compile-fail/estr-subtyping.rs index d0d1b2013a95b..f8dcd9052b3ef 100644 --- a/src/test/compile-fail/estr-subtyping.rs +++ b/src/test/compile-fail/estr-subtyping.rs @@ -14,19 +14,19 @@ fn wants_slice(x: &str) { } fn has_box(x: @str) { wants_box(x); - wants_uniq(x); //~ ERROR str storage differs: expected ~ but found @ + wants_uniq(x); //~ ERROR str storage differs: expected ~, found @ wants_slice(x); } fn has_uniq(x: ~str) { - wants_box(x); //~ ERROR str storage differs: expected @ but found ~ + wants_box(x); //~ ERROR str storage differs: expected @, found ~ wants_uniq(x); wants_slice(x); } fn has_slice(x: &str) { - wants_box(x); //~ ERROR str storage differs: expected @ but found & - wants_uniq(x); //~ ERROR str storage differs: expected ~ but found & + wants_box(x); //~ ERROR str storage differs: expected @, found & + wants_uniq(x); //~ ERROR str storage differs: expected ~, found & wants_slice(x); } diff --git a/src/test/compile-fail/evec-subtyping.rs b/src/test/compile-fail/evec-subtyping.rs index f9c8ba01f1805..9301798bddb72 100644 --- a/src/test/compile-fail/evec-subtyping.rs +++ b/src/test/compile-fail/evec-subtyping.rs @@ -14,26 +14,26 @@ fn wants_three(x: [uint, ..3]) { } fn has_box(x: @[uint]) { wants_box(x); - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found @ - wants_three(x); //~ ERROR [] storage differs: expected 3 but found @ + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found @ + wants_three(x); //~ ERROR [] storage differs: expected 3, found @ } fn has_uniq(x: ~[uint]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found ~ + wants_box(x); //~ ERROR [] storage differs: expected @, found ~ wants_uniq(x); - wants_three(x); //~ ERROR [] storage differs: expected 3 but found ~ + wants_three(x); //~ ERROR [] storage differs: expected 3, found ~ } fn has_three(x: [uint, ..3]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found 3 - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 3 + wants_box(x); //~ ERROR [] storage differs: expected @, found 3 + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found 3 wants_three(x); } fn has_four(x: [uint, ..4]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found 4 - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 4 - wants_three(x); //~ ERROR [] storage differs: expected 3 but found 4 + wants_box(x); //~ ERROR [] storage differs: expected @, found 4 + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found 4 + wants_three(x); //~ ERROR [] storage differs: expected 3, found 4 } fn main() { diff --git a/src/test/compile-fail/extern-no-call.rs b/src/test/compile-fail/extern-no-call.rs index 58649f3209bb1..343965a5c4a8c 100644 --- a/src/test/compile-fail/extern-no-call.rs +++ b/src/test/compile-fail/extern-no-call.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected function but found `*u8` +// error-pattern:expected function, found `*u8` extern fn f() { } diff --git a/src/test/compile-fail/fully-qualified-type-name2.rs b/src/test/compile-fail/fully-qualified-type-name2.rs index 986d19669b91e..94af50dac0ea5 100644 --- a/src/test/compile-fail/fully-qualified-type-name2.rs +++ b/src/test/compile-fail/fully-qualified-type-name2.rs @@ -20,7 +20,7 @@ mod y { fn bar(x: x::foo) -> y::foo { return x; - //~^ ERROR mismatched types: expected `y::foo` but found `x::foo` + //~^ ERROR mismatched types: expected `y::foo`, found `x::foo` } fn main() { diff --git a/src/test/compile-fail/fully-qualified-type-name3.rs b/src/test/compile-fail/fully-qualified-type-name3.rs index 464f292b75899..a9fd68e4bf64a 100644 --- a/src/test/compile-fail/fully-qualified-type-name3.rs +++ b/src/test/compile-fail/fully-qualified-type-name3.rs @@ -16,7 +16,7 @@ type T2 = int; fn bar(x: T1) -> T2 { return x; - //~^ ERROR mismatched types: expected `T2` but found `T1` + //~^ ERROR mismatched types: expected `T2`, found `T1` } fn main() { diff --git a/src/test/compile-fail/if-branch-types.rs b/src/test/compile-fail/if-branch-types.rs index 1c6dd0ef9f657..4a8c72c3877c5 100644 --- a/src/test/compile-fail/if-branch-types.rs +++ b/src/test/compile-fail/if-branch-types.rs @@ -10,5 +10,5 @@ fn main() { let x = if true { 10i } else { 10u }; - //~^ ERROR if and else have incompatible types: expected `int` but found `uint` + //~^ ERROR if and else have incompatible types: expected `int`, found `uint` } diff --git a/src/test/compile-fail/if-without-else-result.rs b/src/test/compile-fail/if-without-else-result.rs index 8e3318f6945ac..d9307d9669ae7 100644 --- a/src/test/compile-fail/if-without-else-result.rs +++ b/src/test/compile-fail/if-without-else-result.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { let a = if true { true }; diff --git a/src/test/compile-fail/integer-literal-suffix-inference.rs b/src/test/compile-fail/integer-literal-suffix-inference.rs index 2f77497acc4a8..1e42a9447f67a 100644 --- a/src/test/compile-fail/integer-literal-suffix-inference.rs +++ b/src/test/compile-fail/integer-literal-suffix-inference.rs @@ -39,62 +39,62 @@ fn main() { fn id_u64(n: u64) -> u64 { n } id_i8(a8); // ok - id_i8(a16); //~ ERROR mismatched types: expected `i8` but found `i16` - id_i8(a32); //~ ERROR mismatched types: expected `i8` but found `i32` - id_i8(a64); //~ ERROR mismatched types: expected `i8` but found `i64` + id_i8(a16); //~ ERROR mismatched types: expected `i8`, found `i16` + id_i8(a32); //~ ERROR mismatched types: expected `i8`, found `i32` + id_i8(a64); //~ ERROR mismatched types: expected `i8`, found `i64` - id_i16(a8); //~ ERROR mismatched types: expected `i16` but found `i8` + id_i16(a8); //~ ERROR mismatched types: expected `i16`, found `i8` id_i16(a16); // ok - id_i16(a32); //~ ERROR mismatched types: expected `i16` but found `i32` - id_i16(a64); //~ ERROR mismatched types: expected `i16` but found `i64` + id_i16(a32); //~ ERROR mismatched types: expected `i16`, found `i32` + id_i16(a64); //~ ERROR mismatched types: expected `i16`, found `i64` - id_i32(a8); //~ ERROR mismatched types: expected `i32` but found `i8` - id_i32(a16); //~ ERROR mismatched types: expected `i32` but found `i16` + id_i32(a8); //~ ERROR mismatched types: expected `i32`, found `i8` + id_i32(a16); //~ ERROR mismatched types: expected `i32`, found `i16` id_i32(a32); // ok - id_i32(a64); //~ ERROR mismatched types: expected `i32` but found `i64` + id_i32(a64); //~ ERROR mismatched types: expected `i32`, found `i64` - id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8` - id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16` - id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32` + id_i64(a8); //~ ERROR mismatched types: expected `i64`, found `i8` + id_i64(a16); //~ ERROR mismatched types: expected `i64`, found `i16` + id_i64(a32); //~ ERROR mismatched types: expected `i64`, found `i32` id_i64(a64); // ok id_i8(c8); // ok - id_i8(c16); //~ ERROR mismatched types: expected `i8` but found `i16` - id_i8(c32); //~ ERROR mismatched types: expected `i8` but found `i32` - id_i8(c64); //~ ERROR mismatched types: expected `i8` but found `i64` + id_i8(c16); //~ ERROR mismatched types: expected `i8`, found `i16` + id_i8(c32); //~ ERROR mismatched types: expected `i8`, found `i32` + id_i8(c64); //~ ERROR mismatched types: expected `i8`, found `i64` - id_i16(c8); //~ ERROR mismatched types: expected `i16` but found `i8` + id_i16(c8); //~ ERROR mismatched types: expected `i16`, found `i8` id_i16(c16); // ok - id_i16(c32); //~ ERROR mismatched types: expected `i16` but found `i32` - id_i16(c64); //~ ERROR mismatched types: expected `i16` but found `i64` + id_i16(c32); //~ ERROR mismatched types: expected `i16`, found `i32` + id_i16(c64); //~ ERROR mismatched types: expected `i16`, found `i64` - id_i32(c8); //~ ERROR mismatched types: expected `i32` but found `i8` - id_i32(c16); //~ ERROR mismatched types: expected `i32` but found `i16` + id_i32(c8); //~ ERROR mismatched types: expected `i32`, found `i8` + id_i32(c16); //~ ERROR mismatched types: expected `i32`, found `i16` id_i32(c32); // ok - id_i32(c64); //~ ERROR mismatched types: expected `i32` but found `i64` + id_i32(c64); //~ ERROR mismatched types: expected `i32`, found `i64` - id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8` - id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16` - id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32` + id_i64(a8); //~ ERROR mismatched types: expected `i64`, found `i8` + id_i64(a16); //~ ERROR mismatched types: expected `i64`, found `i16` + id_i64(a32); //~ ERROR mismatched types: expected `i64`, found `i32` id_i64(a64); // ok id_u8(b8); // ok - id_u8(b16); //~ ERROR mismatched types: expected `u8` but found `u16` - id_u8(b32); //~ ERROR mismatched types: expected `u8` but found `u32` - id_u8(b64); //~ ERROR mismatched types: expected `u8` but found `u64` + id_u8(b16); //~ ERROR mismatched types: expected `u8`, found `u16` + id_u8(b32); //~ ERROR mismatched types: expected `u8`, found `u32` + id_u8(b64); //~ ERROR mismatched types: expected `u8`, found `u64` - id_u16(b8); //~ ERROR mismatched types: expected `u16` but found `u8` + id_u16(b8); //~ ERROR mismatched types: expected `u16`, found `u8` id_u16(b16); // ok - id_u16(b32); //~ ERROR mismatched types: expected `u16` but found `u32` - id_u16(b64); //~ ERROR mismatched types: expected `u16` but found `u64` + id_u16(b32); //~ ERROR mismatched types: expected `u16`, found `u32` + id_u16(b64); //~ ERROR mismatched types: expected `u16`, found `u64` - id_u32(b8); //~ ERROR mismatched types: expected `u32` but found `u8` - id_u32(b16); //~ ERROR mismatched types: expected `u32` but found `u16` + id_u32(b8); //~ ERROR mismatched types: expected `u32`, found `u8` + id_u32(b16); //~ ERROR mismatched types: expected `u32`, found `u16` id_u32(b32); // ok - id_u32(b64); //~ ERROR mismatched types: expected `u32` but found `u64` + id_u32(b64); //~ ERROR mismatched types: expected `u32`, found `u64` - id_u64(b8); //~ ERROR mismatched types: expected `u64` but found `u8` - id_u64(b16); //~ ERROR mismatched types: expected `u64` but found `u16` - id_u64(b32); //~ ERROR mismatched types: expected `u64` but found `u32` + id_u64(b8); //~ ERROR mismatched types: expected `u64`, found `u8` + id_u64(b16); //~ ERROR mismatched types: expected `u64`, found `u16` + id_u64(b32); //~ ERROR mismatched types: expected `u64`, found `u32` id_u64(b64); // ok } diff --git a/src/test/compile-fail/issue-2995.rs b/src/test/compile-fail/issue-2995.rs index 3e771eef970f7..ea8ee8699e482 100644 --- a/src/test/compile-fail/issue-2995.rs +++ b/src/test/compile-fail/issue-2995.rs @@ -12,4 +12,4 @@ fn bad (p: *int) { let _q: &int = p as ∫ //~ ERROR non-scalar cast } -fn main() { } \ No newline at end of file +fn main() { } diff --git a/src/test/compile-fail/issue-3036.rs b/src/test/compile-fail/issue-3036.rs index 45b4ab1871dc9..5f56f6b8b6b99 100644 --- a/src/test/compile-fail/issue-3036.rs +++ b/src/test/compile-fail/issue-3036.rs @@ -13,4 +13,4 @@ fn main() { let x = 3 -} //~ ERROR: expected `;` but found `}` +} //~ ERROR: expected `;`, found `}` diff --git a/src/test/compile-fail/issue-3477.rs b/src/test/compile-fail/issue-3477.rs index 23e680fd851c3..cb7809eef55b7 100644 --- a/src/test/compile-fail/issue-3477.rs +++ b/src/test/compile-fail/issue-3477.rs @@ -1,3 +1,3 @@ fn main() { - let _p: char = 100; //~ ERROR mismatched types: expected `char` but found + let _p: char = 100; //~ ERROR mismatched types: expected `char`, found } diff --git a/src/test/compile-fail/issue-3680.rs b/src/test/compile-fail/issue-3680.rs index b453384c0c890..7cb63d712664b 100644 --- a/src/test/compile-fail/issue-3680.rs +++ b/src/test/compile-fail/issue-3680.rs @@ -10,6 +10,6 @@ fn main() { match None { - Err(_) => () //~ ERROR mismatched types: expected `std::option::Option<>` but found `std::result::Result<,>` + Err(_) => () //~ ERROR mismatched types: expected `std::option::Option<>`, found `std::result::Result<,>` } } diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs index 0fbc79b1bc7bd..02a245e0c97d0 100644 --- a/src/test/compile-fail/issue-4517.rs +++ b/src/test/compile-fail/issue-4517.rs @@ -2,5 +2,5 @@ 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) + bar(foo); //~ ERROR mismatched types: expected `int`, found `[u8, .. 4]` (expected int, found vector) } diff --git a/src/test/compile-fail/issue-4736.rs b/src/test/compile-fail/issue-4736.rs index f7144b4c8fa91..6f410ea3c3739 100644 --- a/src/test/compile-fail/issue-4736.rs +++ b/src/test/compile-fail/issue-4736.rs @@ -12,4 +12,4 @@ struct NonCopyable(()); fn main() { let z = NonCopyable{ p: () }; //~ ERROR structure has no field named `p` -} \ No newline at end of file +} diff --git a/src/test/compile-fail/issue-4968.rs b/src/test/compile-fail/issue-4968.rs index 700d8a61c3a39..d94a8d69a8e95 100644 --- a/src/test/compile-fail/issue-4968.rs +++ b/src/test/compile-fail/issue-4968.rs @@ -12,5 +12,5 @@ static A: (int,int) = (4,2); fn main() { - match 42 { A => () } //~ ERROR mismatched types: expected `` but found `(int,int)` (expected integral variable but found tuple) + match 42 { A => () } //~ ERROR mismatched types: expected ``, found `(int,int)` (expected integral variable, found tuple) } diff --git a/src/test/compile-fail/issue-5100.rs b/src/test/compile-fail/issue-5100.rs index 1ef67f784e386..c6db366e79274 100644 --- a/src/test/compile-fail/issue-5100.rs +++ b/src/test/compile-fail/issue-5100.rs @@ -12,33 +12,33 @@ enum A { B, C } fn main() { match (true, false) { - B => (), //~ ERROR expected `(bool,bool)` but found an enum or structure pattern + B => (), //~ ERROR expected `(bool,bool)`, found an enum or structure pattern _ => () } match (true, false) { - (true, false, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found tuple (expected a tuple with 2 elements but found one with 3 elements) + (true, false, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found tuple (expected a tuple with 2 elements, found one with 3 elements) } match (true, false) { - @(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found an @-box pattern + @(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found an @-box pattern } match (true, false) { - ~(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found a ~-box pattern + ~(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found a ~-box pattern } match (true, false) { - &(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found an &-pointer pattern + &(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found an &-pointer pattern } - let v = [('a', 'b') //~ ERROR expected function but found `(char,char)` + let v = [('a', 'b') //~ ERROR expected function, found `(char,char)` ('c', 'd'), ('e', 'f')]; for &(x,y) in v.iter() {} // should be OK // Make sure none of the errors above were fatal - let x: char = true; //~ ERROR expected `char` but found `bool` + let x: char = true; //~ ERROR expected `char`, found `bool` } diff --git a/src/test/compile-fail/issue-5358-1.rs b/src/test/compile-fail/issue-5358-1.rs index a3d25e7d2adca..85e34cd6db3ee 100644 --- a/src/test/compile-fail/issue-5358-1.rs +++ b/src/test/compile-fail/issue-5358-1.rs @@ -12,7 +12,7 @@ struct S(Either); fn main() { match S(Left(5)) { - Right(_) => {} //~ ERROR mismatched types: expected `S` but found `std::either::Either + Right(_) => {} //~ ERROR mismatched types: expected `S`, found `std::either::Either _ => {} } } diff --git a/src/test/compile-fail/issue-5358.rs b/src/test/compile-fail/issue-5358.rs index 8d4f463346693..b0a74fb37abe2 100644 --- a/src/test/compile-fail/issue-5358.rs +++ b/src/test/compile-fail/issue-5358.rs @@ -12,6 +12,6 @@ struct S(Either); fn main() { match *S(Left(5)) { - S(_) => {} //~ ERROR mismatched types: expected `std::either::Either` but found a structure pattern + S(_) => {} //~ ERROR mismatched types: expected `std::either::Either`, found a structure pattern } } diff --git a/src/test/compile-fail/issue-6762.rs b/src/test/compile-fail/issue-6762.rs index 391c1019a9468..14dcc4ea8a3a8 100644 --- a/src/test/compile-fail/issue-6762.rs +++ b/src/test/compile-fail/issue-6762.rs @@ -21,4 +21,4 @@ fn main() twice(x); invoke(sq); -} \ No newline at end of file +} diff --git a/src/test/compile-fail/loop-does-not-diverge.rs b/src/test/compile-fail/loop-does-not-diverge.rs index 0a9d9fb20ab0e..d0e5249305493 100644 --- a/src/test/compile-fail/loop-does-not-diverge.rs +++ b/src/test/compile-fail/loop-does-not-diverge.rs @@ -14,7 +14,7 @@ fn forever() -> ! { loop { break; } - return 42i; //~ ERROR expected `!` but found `int` + return 42i; //~ ERROR expected `!`, found `int` } fn main() { diff --git a/src/test/compile-fail/lub-if.rs b/src/test/compile-fail/lub-if.rs index 358c61921470f..6b5055cb1a2cd 100644 --- a/src/test/compile-fail/lub-if.rs +++ b/src/test/compile-fail/lub-if.rs @@ -49,4 +49,4 @@ pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str { } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/lub-match.rs b/src/test/compile-fail/lub-match.rs index 2a61b72997d1f..37b9cc55dc822 100644 --- a/src/test/compile-fail/lub-match.rs +++ b/src/test/compile-fail/lub-match.rs @@ -52,4 +52,4 @@ pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/main-wrong-location.rs b/src/test/compile-fail/main-wrong-location.rs index 90ef7843d4bf9..ef3f8140c68a0 100644 --- a/src/test/compile-fail/main-wrong-location.rs +++ b/src/test/compile-fail/main-wrong-location.rs @@ -12,4 +12,4 @@ mod m { // An inferred main entry point (that doesn't use #[main]) // must appear at the top of the crate fn main() { } //~ NOTE here is a function named 'main' -} \ No newline at end of file +} diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index f6fd8e29a4f4d..8b29d165b603c 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -17,5 +17,5 @@ fn main() { let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as @Map<~str, ~str>; let y: @Map = @x; - //~^ ERROR expected trait std::container::Map but found @-ptr + //~^ ERROR expected trait std::container::Map, found @-ptr } diff --git a/src/test/compile-fail/match-struct.rs b/src/test/compile-fail/match-struct.rs index 6e9bf603aef9e..2b75fc6410e86 100644 --- a/src/test/compile-fail/match-struct.rs +++ b/src/test/compile-fail/match-struct.rs @@ -4,7 +4,7 @@ enum E { C(int) } fn main() { match S { a: 1 } { - C(_) => (), //~ ERROR mismatched types: expected `S` but found `E` + C(_) => (), //~ ERROR mismatched types: expected `S`, found `E` _ => () } } diff --git a/src/test/compile-fail/match-vec-mismatch-2.rs b/src/test/compile-fail/match-vec-mismatch-2.rs index 6ea0300cf1e7d..f2c61898b385b 100644 --- a/src/test/compile-fail/match-vec-mismatch-2.rs +++ b/src/test/compile-fail/match-vec-mismatch-2.rs @@ -1,5 +1,5 @@ fn main() { match () { - [()] => { } //~ ERROR mismatched types: expected `()` but found a vector pattern + [()] => { } //~ ERROR mismatched types: expected `()`, found a vector pattern } } diff --git a/src/test/compile-fail/match-vec-mismatch.rs b/src/test/compile-fail/match-vec-mismatch.rs index 85ed8761ee935..ffc2e0b31ee48 100644 --- a/src/test/compile-fail/match-vec-mismatch.rs +++ b/src/test/compile-fail/match-vec-mismatch.rs @@ -1,6 +1,6 @@ fn main() { match ~"foo" { - ['f', 'o', .._] => { } //~ ERROR mismatched types: expected `~str` but found a vector pattern + ['f', 'o', .._] => { } //~ ERROR mismatched types: expected `~str`, found a vector pattern _ => { } } } diff --git a/src/test/compile-fail/multitrait.rs b/src/test/compile-fail/multitrait.rs index b49ee5aab47e6..2ad07dcbb069c 100644 --- a/src/test/compile-fail/multitrait.rs +++ b/src/test/compile-fail/multitrait.rs @@ -12,7 +12,7 @@ struct S { y: int } -impl Cmp, ToStr for S { //~ ERROR: expected `{` but found `,` +impl Cmp, ToStr for S { //~ ERROR: expected `{`, found `,` fn eq(&&other: S) { false } fn to_str(&self) -> ~str { ~"hi" } } diff --git a/src/test/compile-fail/noexporttypeexe.rs b/src/test/compile-fail/noexporttypeexe.rs index 3add0134d002a..e622122306f82 100644 --- a/src/test/compile-fail/noexporttypeexe.rs +++ b/src/test/compile-fail/noexporttypeexe.rs @@ -18,5 +18,5 @@ fn main() { // because the def_id associated with the type was // not convertible to a path. let x: int = noexporttypelib::foo(); - //~^ ERROR expected `int` but found `std::option::Option` + //~^ ERROR expected `int`, found `std::option::Option` } diff --git a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs index 2727db9d0422e..25d2bd2982fb3 100644 --- a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs +++ b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs @@ -12,6 +12,6 @@ fn main() { fn bar(n: int) { - let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count, found variable } } diff --git a/src/test/compile-fail/omitted-arg-in-item-fn.rs b/src/test/compile-fail/omitted-arg-in-item-fn.rs index fcbfb115af756..c5ff885997b72 100644 --- a/src/test/compile-fail/omitted-arg-in-item-fn.rs +++ b/src/test/compile-fail/omitted-arg-in-item-fn.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x) { //~ ERROR expected `:` but found `)` +fn foo(x) { //~ ERROR expected `:`, found `)` } diff --git a/src/test/compile-fail/omitted-arg-wrong-types.rs b/src/test/compile-fail/omitted-arg-wrong-types.rs index a44c113269b98..92052aaff5781 100644 --- a/src/test/compile-fail/omitted-arg-wrong-types.rs +++ b/src/test/compile-fail/omitted-arg-wrong-types.rs @@ -13,8 +13,8 @@ fn let_in(x: T, f: &fn(T)) {} fn main() { let_in(3u, |i| { assert!(i == 3); }); - //~^ ERROR expected `uint` but found `int` + //~^ ERROR expected `uint`, found `int` let_in(3, |i| { assert!(i == 3u); }); - //~^ ERROR expected `int` but found `uint` + //~^ ERROR expected `int`, found `uint` } diff --git a/src/test/compile-fail/pattern-error-continue.rs b/src/test/compile-fail/pattern-error-continue.rs index 14d8b04ade4eb..79fcc8468166e 100644 --- a/src/test/compile-fail/pattern-error-continue.rs +++ b/src/test/compile-fail/pattern-error-continue.rs @@ -29,8 +29,8 @@ fn main() { _ => () } match 'c' { - S { _ } => (), //~ ERROR mismatched types: expected `char` but found struct + S { _ } => (), //~ ERROR mismatched types: expected `char`, found struct _ => () } - f(true); //~ ERROR mismatched types: expected `char` but found `bool` -} \ No newline at end of file + f(true); //~ ERROR mismatched types: expected `char`, found `bool` +} diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index ab2ac6cc0e5b9..ebc19c6eaf772 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -16,12 +16,12 @@ struct an_enum<'self>(&'self int); struct a_class<'self> { x:&'self int } fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> { - return e; //~ ERROR mismatched types: expected `an_enum<'b>` but found `an_enum<'a>` + return e; //~ ERROR mismatched types: expected `an_enum<'b>`, found `an_enum<'a>` //~^ ERROR cannot infer an appropriate lifetime } fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> { - return e; //~ ERROR mismatched types: expected `a_class<'b>` but found `a_class<'a>` + return e; //~ ERROR mismatched types: expected `a_class<'b>`, found `a_class<'a>` //~^ ERROR cannot infer an appropriate lifetime } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index e5399fc7fa3b9..66ab4b7705433 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -34,4 +34,4 @@ fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: &fn(&'a &'b uint)) { let z: Option<&'a &'b uint> = None; } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index d06dcd8aa86b8..c9859899ea4f1 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -37,4 +37,4 @@ fn call4<'a, 'b>(a: &'a uint, b: &'b uint) { } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-infer-paramd-indirect.rs b/src/test/compile-fail/regions-infer-paramd-indirect.rs index 0b4aa44010bdc..97f551ca0c2ae 100644 --- a/src/test/compile-fail/regions-infer-paramd-indirect.rs +++ b/src/test/compile-fail/regions-infer-paramd-indirect.rs @@ -29,7 +29,7 @@ impl<'self> set_f<'self> for c<'self> { } fn set_f_bad(&self, b: @b) { - self.f = b; //~ ERROR mismatched types: expected `@@&'self int` but found `@@&int` + self.f = b; //~ ERROR mismatched types: expected `@@&'self int`, found `@@&int` //~^ ERROR cannot infer an appropriate lifetime } } diff --git a/src/test/compile-fail/regions-infer-paramd-method.rs b/src/test/compile-fail/regions-infer-paramd-method.rs index 8c3195f020a97..68bd2304b2ad0 100644 --- a/src/test/compile-fail/regions-infer-paramd-method.rs +++ b/src/test/compile-fail/regions-infer-paramd-method.rs @@ -30,7 +30,7 @@ trait set_foo_foo { impl<'self> set_foo_foo for with_foo<'self> { fn set_foo(&mut self, f: @foo) { - self.f = f; //~ ERROR mismatched types: expected `@foo/&self` but found `@foo/&` + self.f = f; //~ ERROR mismatched types: expected `@foo/&self`, found `@foo/&` } } diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index f90fe924587df..4848262750720 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -8,4 +8,4 @@ fn arg_closure() -> &'static int { with(|~ref x| x) //~ ERROR borrowed value does not live long enough } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index 072b0e83fdf58..a3f2a28d643f7 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -16,7 +16,7 @@ trait get_ctxt<'self> { } fn make_gc1(gc: @get_ctxt<'a>) -> @get_ctxt<'b> { - return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a` + return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b`, found `@get_ctxt/&a` } struct Foo { diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index 579575e2008f8..dd0fd7e221dc8 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -12,5 +12,5 @@ fn main() { let n = 1; - let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count, found variable } diff --git a/src/test/compile-fail/struct-base-wrong-type.rs b/src/test/compile-fail/struct-base-wrong-type.rs index adda356298d9f..af6fc64535149 100644 --- a/src/test/compile-fail/struct-base-wrong-type.rs +++ b/src/test/compile-fail/struct-base-wrong-type.rs @@ -12,11 +12,11 @@ struct Foo { a: int, b: int } struct Bar { x: int } static bar: Bar = Bar { x: 5 }; -static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo` but found `Bar` +static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo`, found `Bar` static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo` fn main() { let b = Bar { x: 5 }; - let f = Foo { a: 2, ..b }; //~ ERROR mismatched types: expected `Foo` but found `Bar` + let f = Foo { a: 2, ..b }; //~ ERROR mismatched types: expected `Foo`, found `Bar` let f_i = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo` } diff --git a/src/test/compile-fail/suppressed-error.rs b/src/test/compile-fail/suppressed-error.rs index b4a72548cfc0d..f13aabe52594a 100644 --- a/src/test/compile-fail/suppressed-error.rs +++ b/src/test/compile-fail/suppressed-error.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - let (x, y) = (); //~ ERROR expected `()` but found tuple (types differ) + let (x, y) = (); //~ ERROR expected `()`, found tuple (types differ) return x; -} \ No newline at end of file +} diff --git a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs index ebd3320d90126..478b4a4081ff6 100644 --- a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs +++ b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `char` but found +// error-pattern:mismatched types: expected `char`, found // Issue #876 #[no_std]; diff --git a/src/test/compile-fail/tag-variant-disr-dup.rs b/src/test/compile-fail/tag-variant-disr-dup.rs index 216779fac7c46..a5f85a685e695 100644 --- a/src/test/compile-fail/tag-variant-disr-dup.rs +++ b/src/test/compile-fail/tag-variant-disr-dup.rs @@ -20,4 +20,4 @@ enum color { white = 0x000000, } -fn main() { } \ No newline at end of file +fn main() { } diff --git a/src/test/compile-fail/terr-in-field.rs b/src/test/compile-fail/terr-in-field.rs index 6474a58c1cdb9..88da7bc854201 100644 --- a/src/test/compile-fail/terr-in-field.rs +++ b/src/test/compile-fail/terr-in-field.rs @@ -20,7 +20,7 @@ struct bar { fn want_foo(f: foo) {} fn have_bar(b: bar) { - want_foo(b); //~ ERROR (expected struct foo but found struct bar) + want_foo(b); //~ ERROR (expected struct foo, found struct bar) } fn main() {} diff --git a/src/test/compile-fail/terr-sorts.rs b/src/test/compile-fail/terr-sorts.rs index ad14688f08c62..462bb0a3962c7 100644 --- a/src/test/compile-fail/terr-sorts.rs +++ b/src/test/compile-fail/terr-sorts.rs @@ -17,7 +17,7 @@ type bar = @foo; fn want_foo(f: foo) {} fn have_bar(b: bar) { - want_foo(b); //~ ERROR (expected struct foo but found @-ptr) + want_foo(b); //~ ERROR (expected struct foo, found @-ptr) } fn main() {} diff --git a/src/test/compile-fail/trait-impl-method-mismatch.rs b/src/test/compile-fail/trait-impl-method-mismatch.rs index 54fa62f797766..e23c74880379c 100644 --- a/src/test/compile-fail/trait-impl-method-mismatch.rs +++ b/src/test/compile-fail/trait-impl-method-mismatch.rs @@ -15,7 +15,7 @@ trait Mumbo { impl Mumbo for uint { // Cannot have a larger effect than the trait: unsafe fn jumbo(&self, x: @uint) { *self + *x; } - //~^ ERROR expected impure fn but found unsafe fn + //~^ ERROR expected impure fn, found unsafe fn } fn main() {} diff --git a/src/test/compile-fail/tuple-arity-mismatch.rs b/src/test/compile-fail/tuple-arity-mismatch.rs index 517b3cb59232e..2ca8f3bcce261 100644 --- a/src/test/compile-fail/tuple-arity-mismatch.rs +++ b/src/test/compile-fail/tuple-arity-mismatch.rs @@ -13,5 +13,5 @@ fn first((value, _): (int, float)) -> int { value } fn main() { - let y = first ((1,2,3)); //~ ERROR expected a tuple with 2 elements but found one with 3 elements + let y = first ((1,2,3)); //~ ERROR expected a tuple with 2 elements, found one with 3 elements } diff --git a/src/test/compile-fail/tutorial-suffix-inference-test.rs b/src/test/compile-fail/tutorial-suffix-inference-test.rs index d92aa8d640ab5..c1be54b3f75e1 100644 --- a/src/test/compile-fail/tutorial-suffix-inference-test.rs +++ b/src/test/compile-fail/tutorial-suffix-inference-test.rs @@ -17,9 +17,9 @@ fn main() { identity_u8(x); // after this, `x` is assumed to have type `u8` identity_u16(x); - //~^ ERROR mismatched types: expected `u16` but found `u8` + //~^ ERROR mismatched types: expected `u16`, found `u8` identity_u16(y); - //~^ ERROR mismatched types: expected `u16` but found `i32` + //~^ ERROR mismatched types: expected `u16`, found `i32` let a = 3i; @@ -27,6 +27,6 @@ fn main() { identity_i(a); // ok identity_u16(a); - //~^ ERROR mismatched types: expected `u16` but found `int` + //~^ ERROR mismatched types: expected `u16`, found `int` } diff --git a/src/test/compile-fail/type-parameter-names.rs b/src/test/compile-fail/type-parameter-names.rs index 6af3166a2ff4e..c076e6b5c813f 100644 --- a/src/test/compile-fail/type-parameter-names.rs +++ b/src/test/compile-fail/type-parameter-names.rs @@ -1,6 +1,6 @@ // Test that we print out the names of type parameters correctly in // our error messages. -fn foo(x: Foo) -> Bar { x } //~ ERROR expected `Bar` but found `Foo` +fn foo(x: Foo) -> Bar { x } //~ ERROR expected `Bar`, found `Foo` -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/debug-info/borrowed-basic.rs b/src/test/debug-info/borrowed-basic.rs index 7610301f6f035..2ddf309b16916 100644 --- a/src/test/debug-info/borrowed-basic.rs +++ b/src/test/debug-info/borrowed-basic.rs @@ -110,4 +110,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-c-style-enum.rs b/src/test/debug-info/borrowed-c-style-enum.rs index 70c85258c7921..14771396bd1ae 100644 --- a/src/test/debug-info/borrowed-c-style-enum.rs +++ b/src/test/debug-info/borrowed-c-style-enum.rs @@ -39,4 +39,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-enum.rs b/src/test/debug-info/borrowed-enum.rs index 38aa9c3881000..7c8a6814dcb44 100644 --- a/src/test/debug-info/borrowed-enum.rs +++ b/src/test/debug-info/borrowed-enum.rs @@ -59,4 +59,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-managed-basic.rs b/src/test/debug-info/borrowed-managed-basic.rs index 9087bb36fa5d6..7403ead3fcedd 100644 --- a/src/test/debug-info/borrowed-managed-basic.rs +++ b/src/test/debug-info/borrowed-managed-basic.rs @@ -111,4 +111,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-struct.rs b/src/test/debug-info/borrowed-struct.rs index 8b6eca3e37f79..571333a8a3bc7 100644 --- a/src/test/debug-info/borrowed-struct.rs +++ b/src/test/debug-info/borrowed-struct.rs @@ -72,4 +72,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-tuple.rs b/src/test/debug-info/borrowed-tuple.rs index da199941c8419..dbbf7d537aa54 100644 --- a/src/test/debug-info/borrowed-tuple.rs +++ b/src/test/debug-info/borrowed-tuple.rs @@ -41,4 +41,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-unique-basic.rs b/src/test/debug-info/borrowed-unique-basic.rs index 52f5a2cba1ebe..893be617ac235 100644 --- a/src/test/debug-info/borrowed-unique-basic.rs +++ b/src/test/debug-info/borrowed-unique-basic.rs @@ -111,4 +111,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/boxed-struct.rs b/src/test/debug-info/boxed-struct.rs index 86162f0fa04cd..08f56154b62b8 100644 --- a/src/test/debug-info/boxed-struct.rs +++ b/src/test/debug-info/boxed-struct.rs @@ -56,4 +56,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/boxed-vec.rs b/src/test/debug-info/boxed-vec.rs index 8abead6519697..b6c6ce49ddaf4 100644 --- a/src/test/debug-info/boxed-vec.rs +++ b/src/test/debug-info/boxed-vec.rs @@ -33,4 +33,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/c-style-enum-in-composite.rs b/src/test/debug-info/c-style-enum-in-composite.rs index 47e433ea814ab..5a78666423a04 100644 --- a/src/test/debug-info/c-style-enum-in-composite.rs +++ b/src/test/debug-info/c-style-enum-in-composite.rs @@ -116,4 +116,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/c-style-enum.rs b/src/test/debug-info/c-style-enum.rs index d7cce4e6f3fb5..56c042f9e05fb 100644 --- a/src/test/debug-info/c-style-enum.rs +++ b/src/test/debug-info/c-style-enum.rs @@ -67,4 +67,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/destructured-fn-argument.rs b/src/test/debug-info/destructured-fn-argument.rs index 05718ab48909f..a3d53fb9efea2 100644 --- a/src/test/debug-info/destructured-fn-argument.rs +++ b/src/test/debug-info/destructured-fn-argument.rs @@ -315,4 +315,4 @@ fn main() { } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/destructured-local.rs b/src/test/debug-info/destructured-local.rs index f8db7981c941b..10d08ad66ba94 100644 --- a/src/test/debug-info/destructured-local.rs +++ b/src/test/debug-info/destructured-local.rs @@ -206,4 +206,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/evec-in-struct.rs b/src/test/debug-info/evec-in-struct.rs index 7e42690548e70..b23f3174705a9 100644 --- a/src/test/debug-info/evec-in-struct.rs +++ b/src/test/debug-info/evec-in-struct.rs @@ -85,4 +85,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/function-arguments.rs b/src/test/debug-info/function-arguments.rs index 1fe79b8e2a9e9..fba0a9b2dd2d1 100644 --- a/src/test/debug-info/function-arguments.rs +++ b/src/test/debug-info/function-arguments.rs @@ -45,4 +45,4 @@ fn fun(x: int, y: bool) -> (int, bool) { (x, y) } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-enum.rs b/src/test/debug-info/managed-enum.rs index 1a3600a7d8cb3..ab77d7180bae1 100644 --- a/src/test/debug-info/managed-enum.rs +++ b/src/test/debug-info/managed-enum.rs @@ -60,4 +60,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-pointer-within-unique-vec.rs b/src/test/debug-info/managed-pointer-within-unique-vec.rs index e42631599a9b9..facde86a305cc 100644 --- a/src/test/debug-info/managed-pointer-within-unique-vec.rs +++ b/src/test/debug-info/managed-pointer-within-unique-vec.rs @@ -34,4 +34,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-pointer-within-unique.rs b/src/test/debug-info/managed-pointer-within-unique.rs index 3eb1c2ef01e55..9ea7b86f71141 100644 --- a/src/test/debug-info/managed-pointer-within-unique.rs +++ b/src/test/debug-info/managed-pointer-within-unique.rs @@ -44,4 +44,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/nil-enum.rs b/src/test/debug-info/nil-enum.rs index d3afd4b11f9cd..55ed84cd8f2ef 100644 --- a/src/test/debug-info/nil-enum.rs +++ b/src/test/debug-info/nil-enum.rs @@ -37,4 +37,4 @@ fn main() { } } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/option-like-enum.rs b/src/test/debug-info/option-like-enum.rs index 6d3b157d63e80..71ed72017613e 100644 --- a/src/test/debug-info/option-like-enum.rs +++ b/src/test/debug-info/option-like-enum.rs @@ -68,4 +68,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/packed-struct-with-destructor.rs b/src/test/debug-info/packed-struct-with-destructor.rs index 9ff91aa00d1c9..cd2f9af26ca27 100644 --- a/src/test/debug-info/packed-struct-with-destructor.rs +++ b/src/test/debug-info/packed-struct-with-destructor.rs @@ -216,4 +216,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/packed-struct.rs b/src/test/debug-info/packed-struct.rs index 859166cb023a3..ef4d07fdb4322 100644 --- a/src/test/debug-info/packed-struct.rs +++ b/src/test/debug-info/packed-struct.rs @@ -101,4 +101,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/simple-struct.rs b/src/test/debug-info/simple-struct.rs index 49e7bc255c10f..7346c86fadb6e 100644 --- a/src/test/debug-info/simple-struct.rs +++ b/src/test/debug-info/simple-struct.rs @@ -81,4 +81,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/simple-tuple.rs b/src/test/debug-info/simple-tuple.rs index f45294221af16..f86959b7ca1eb 100644 --- a/src/test/debug-info/simple-tuple.rs +++ b/src/test/debug-info/simple-tuple.rs @@ -48,4 +48,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/struct-in-struct.rs b/src/test/debug-info/struct-in-struct.rs index 04c5eec610b73..60ac4bcea6087 100644 --- a/src/test/debug-info/struct-in-struct.rs +++ b/src/test/debug-info/struct-in-struct.rs @@ -142,4 +142,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/struct-style-enum.rs b/src/test/debug-info/struct-style-enum.rs index 61bbd2e215ff6..77d7746e2df86 100644 --- a/src/test/debug-info/struct-style-enum.rs +++ b/src/test/debug-info/struct-style-enum.rs @@ -70,4 +70,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-in-struct.rs b/src/test/debug-info/tuple-in-struct.rs index 369c9fd28ccdf..863cb57bd235a 100644 --- a/src/test/debug-info/tuple-in-struct.rs +++ b/src/test/debug-info/tuple-in-struct.rs @@ -148,4 +148,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-in-tuple.rs b/src/test/debug-info/tuple-in-tuple.rs index 9c6805dae67d3..ae77d4723f1ad 100644 --- a/src/test/debug-info/tuple-in-tuple.rs +++ b/src/test/debug-info/tuple-in-tuple.rs @@ -47,4 +47,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-style-enum.rs b/src/test/debug-info/tuple-style-enum.rs index ba1d02bb62a3c..dd52ee22766d4 100644 --- a/src/test/debug-info/tuple-style-enum.rs +++ b/src/test/debug-info/tuple-style-enum.rs @@ -70,4 +70,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/unique-enum.rs b/src/test/debug-info/unique-enum.rs index 443f641a85859..101b51632d9b6 100644 --- a/src/test/debug-info/unique-enum.rs +++ b/src/test/debug-info/unique-enum.rs @@ -60,4 +60,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs b/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs index 59e82a038bc79..0e7572220a8b4 100644 --- a/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs +++ b/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs @@ -47,4 +47,4 @@ fn fun2() { pub fn main() { fun1(); fun2(); -} \ No newline at end of file +} diff --git a/src/test/run-pass/cast-mutable-trait.rs b/src/test/run-pass/cast-mutable-trait.rs index 633188b9a623b..84827a7a82042 100644 --- a/src/test/run-pass/cast-mutable-trait.rs +++ b/src/test/run-pass/cast-mutable-trait.rs @@ -31,4 +31,4 @@ fn main() { s2.foo(); bar(s2); bar(s as @mut T); -} \ No newline at end of file +} diff --git a/src/test/run-pass/conditional-debug-macro-off.rs b/src/test/run-pass/conditional-debug-macro-off.rs index f40c8112e0bba..decd310c9a7e1 100644 --- a/src/test/run-pass/conditional-debug-macro-off.rs +++ b/src/test/run-pass/conditional-debug-macro-off.rs @@ -14,4 +14,4 @@ fn main() { // only fails if debug! evaluates its argument. debug!({ if true { fail!() } }); -} \ No newline at end of file +} diff --git a/src/test/run-pass/conditional-debug-macro-on.rs b/src/test/run-pass/conditional-debug-macro-on.rs index 65b751a58264d..a0da137369c1b 100644 --- a/src/test/run-pass/conditional-debug-macro-on.rs +++ b/src/test/run-pass/conditional-debug-macro-on.rs @@ -18,4 +18,4 @@ fn main() { debug!({ if true { return; } }); fail!(); -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs index 6f6e8d79d8b92..3d53ec97491a1 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs @@ -49,4 +49,4 @@ pub fn main() { assert_eq!(es1.cmp(es2), ord); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-via-extension-struct-empty.rs b/src/test/run-pass/deriving-via-extension-struct-empty.rs index 8f6a319798626..74698b9db28bc 100644 --- a/src/test/run-pass/deriving-via-extension-struct-empty.rs +++ b/src/test/run-pass/deriving-via-extension-struct-empty.rs @@ -14,4 +14,4 @@ struct Foo; pub fn main() { assert_eq!(Foo, Foo); assert!(!(Foo != Foo)); -} \ No newline at end of file +} diff --git a/src/test/run-pass/enum-vec-initializer.rs b/src/test/run-pass/enum-vec-initializer.rs index ae590ad7d1f71..11893bbf657ec 100644 --- a/src/test/run-pass/enum-vec-initializer.rs +++ b/src/test/run-pass/enum-vec-initializer.rs @@ -21,4 +21,4 @@ fn main() { let v = [0, .. BAR2]; static BAR3:uint = BAR2; let v = [0, .. BAR3]; -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs index 17c5bb5c0e253..cb438aa0b2085 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs @@ -38,4 +38,4 @@ fn main() { assert_eq!(x, 6); assert_eq!(y, 60); -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators-hashmap.rs b/src/test/run-pass/foreach-external-iterators-hashmap.rs index 908adc0d7620d..9a5c2fa86fadb 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap.rs @@ -24,4 +24,4 @@ fn main() { } assert_eq!(x, 6); assert_eq!(y, 60); -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators.rs b/src/test/run-pass/foreach-external-iterators.rs index c6f903821dd0e..0933ac09243c9 100644 --- a/src/test/run-pass/foreach-external-iterators.rs +++ b/src/test/run-pass/foreach-external-iterators.rs @@ -15,4 +15,4 @@ fn main() { y += *i } assert!(y == 100); -} \ No newline at end of file +} diff --git a/src/test/run-pass/func-arg-incomplete-pattern.rs b/src/test/run-pass/func-arg-incomplete-pattern.rs index b08d3beae1bfa..6144e46593677 100644 --- a/src/test/run-pass/func-arg-incomplete-pattern.rs +++ b/src/test/run-pass/func-arg-incomplete-pattern.rs @@ -17,4 +17,4 @@ fn main() { let f = Foo {x: obj, y: ~2}; let xptr = foo(f); assert_eq!(objptr, xptr); -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index aa9be2203c6b2..a2fc6392b75fd 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -47,7 +47,7 @@ fn add_interface(store: int, managed_ip: ~str, data: extra::json::Json) -> (~str (label, bool_value(false)) } _ => { - error!("Expected dict for %s interfaces but found %?", managed_ip, data); + error!("Expected dict for %s interfaces, found %?", managed_ip, data); (~"gnos:missing-interface", bool_value(true)) } } @@ -65,7 +65,7 @@ fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, extra::jso } _ => { - error!("Expected list for %s interfaces but found %?", managed_ip, + error!("Expected list for %s interfaces, found %?", managed_ip, device.get(&~"interfaces")); ~[] } diff --git a/src/test/run-pass/issue-4252.rs b/src/test/run-pass/issue-4252.rs index de1f630a245b8..ebbdf6cc230ac 100644 --- a/src/test/run-pass/issue-4252.rs +++ b/src/test/run-pass/issue-4252.rs @@ -34,4 +34,4 @@ impl Drop for Z { fn main() { let y = Y; let _z = Z{x: y}; -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-6141-leaking-owned-fn.rs b/src/test/run-pass/issue-6141-leaking-owned-fn.rs index fe11bb0a972ad..cd48eba0f2322 100644 --- a/src/test/run-pass/issue-6141-leaking-owned-fn.rs +++ b/src/test/run-pass/issue-6141-leaking-owned-fn.rs @@ -5,4 +5,4 @@ fn run(f: &fn()) { fn main() { let f: ~fn() = || (); run(f); -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-6341.rs b/src/test/run-pass/issue-6341.rs index 29fc074430584..dfead893392be 100644 --- a/src/test/run-pass/issue-6341.rs +++ b/src/test/run-pass/issue-6341.rs @@ -15,4 +15,4 @@ impl Drop for A { fn drop(&self) {} } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/run-pass/move-out-of-field.rs b/src/test/run-pass/move-out-of-field.rs index a3c2872803adc..04375052c3d6b 100644 --- a/src/test/run-pass/move-out-of-field.rs +++ b/src/test/run-pass/move-out-of-field.rs @@ -20,4 +20,4 @@ fn main() { sb.append("World!"); let str = to_str(sb); assert_eq!(str, ~"Hello, World!"); -} \ No newline at end of file +} diff --git a/src/test/run-pass/option_addition.rs b/src/test/run-pass/option_addition.rs index fe39d1b11d3b8..ac592d92cbadd 100644 --- a/src/test/run-pass/option_addition.rs +++ b/src/test/run-pass/option_addition.rs @@ -20,7 +20,7 @@ pub fn main() { match nope { None => (), - Some(foo) => fail!("expected None, but found %?", foo) + Some(foo) => fail!("expected None, found %?", foo) } assert_eq!(foo, somefoo.get()); assert_eq!(bar, somebar.get()); diff --git a/src/test/run-pass/rt-start-main-thread.rs b/src/test/run-pass/rt-start-main-thread.rs index 8328e7416c579..2edf99e19430e 100644 --- a/src/test/run-pass/rt-start-main-thread.rs +++ b/src/test/run-pass/rt-start-main-thread.rs @@ -18,4 +18,4 @@ fn start(argc: int, argv: **u8, crate_map: *u8) -> int { info!("running on another thread"); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/unique-object-move.rs b/src/test/run-pass/unique-object-move.rs index 540de1652138b..e067fd49b1d13 100644 --- a/src/test/run-pass/unique-object-move.rs +++ b/src/test/run-pass/unique-object-move.rs @@ -21,4 +21,4 @@ impl EventLoop for UvEventLoop { } pub fn main() { let loop_: ~EventLoop = ~UvEventLoop { uvio: 0 } as ~EventLoop; let loop2_ = loop_; -} \ No newline at end of file +} From 8129655ffb035327b3c64c7259516355c8e1c2cf Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Tue, 6 Aug 2013 22:11:59 +0200 Subject: [PATCH 02/62] rebase --- src/test/run-pass/option_addition.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/test/run-pass/option_addition.rs b/src/test/run-pass/option_addition.rs index 1abf7730b0077..8af173150a06d 100644 --- a/src/test/run-pass/option_addition.rs +++ b/src/test/run-pass/option_addition.rs @@ -18,27 +18,8 @@ pub fn main() { let somebar = None:: + Some(bar); let somefoobar = Some(foo) + Some(bar); -<<<<<<< HEAD - match nope { - None => (), - Some(foo) => fail!("expected None, found %?", foo) - } - assert_eq!(foo, somefoo.get()); - assert_eq!(bar, somebar.get()); - assert_eq!(foobar, somefoobar.get()); -} - -fn optint(input: int) -> Option { - if input == 0 { - return None; - } - else { - return Some(input); - } -======= assert_eq!(nope, None::); assert_eq!(somefoo, None::); assert_eq!(somebar, None::); assert_eq!(foobar, somefoobar.unwrap()); ->>>>>>> 72080954b9deb3a6a5f793d2fd1ef32c3d5acb5d } From 5c8803b5e8e934d548814474b7b19b6cf29af2af Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Fri, 2 Aug 2013 18:34:00 +0200 Subject: [PATCH 03/62] std: Speed up str::is_utf8 Use unchecked vec indexing since the vector bounds are checked by the loop. Iterators are not easy to use in this case since we skip 1-4 bytes each lap. This part of the commit speeds up is_utf8 for ASCII input. Check codepoint ranges by checking the byte ranges manually instead of computing a full decoding for multibyte encodings. This is easy to read and corresponds to the UTF-8 syntax in the RFC. No changes to what we accept. A comment notes that surrogate halves are accepted. Before: test str::bench::is_utf8_100_ascii ... bench: 165 ns/iter (+/- 3) test str::bench::is_utf8_100_multibyte ... bench: 218 ns/iter (+/- 5) After: test str::bench::is_utf8_100_ascii ... bench: 130 ns/iter (+/- 1) test str::bench::is_utf8_100_multibyte ... bench: 156 ns/iter (+/- 3) --- src/libstd/str.rs | 102 ++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 35 deletions(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3db0f203d810a..5c6895fea43c9 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -564,51 +564,63 @@ fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool { Section: Misc */ -// Return the initial codepoint accumulator for the first byte. -// The first byte is special, only want bottom 5 bits for width 2, 4 bits -// for width 3, and 3 bits for width 4 -macro_rules! utf8_first_byte( - ($byte:expr, $width:expr) => (($byte & (0x7F >> $width)) as uint) -) - -// return the value of $ch updated with continuation byte $byte -macro_rules! utf8_acc_cont_byte( - ($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63u8) as uint) -) - /// Determines if a vector of bytes contains valid UTF-8 pub fn is_utf8(v: &[u8]) -> bool { let mut i = 0u; let total = v.len(); + fn unsafe_get(xs: &[u8], i: uint) -> u8 { + unsafe { *xs.unsafe_ref(i) } + } while i < total { - if v[i] < 128u8 { + let v_i = unsafe_get(v, i); + if v_i < 128u8 { i += 1u; } else { - let w = utf8_char_width(v[i]); + let w = utf8_char_width(v_i); if w == 0u { return false; } let nexti = i + w; if nexti > total { return false; } - // 1. Make sure the correct number of continuation bytes are present - // 2. Check codepoint ranges (deny overlong encodings) - // 2-byte encoding is for codepoints \u0080 to \u07ff - // 3-byte encoding is for codepoints \u0800 to \uffff - // 4-byte encoding is for codepoints \u10000 to \u10ffff - - // 2-byte encodings are correct if the width and continuation match up - if v[i + 1] & 192u8 != TAG_CONT_U8 { return false; } - if w > 2 { - let mut ch; - ch = utf8_first_byte!(v[i], w); - ch = utf8_acc_cont_byte!(ch, v[i + 1]); - if v[i + 2] & 192u8 != TAG_CONT_U8 { return false; } - ch = utf8_acc_cont_byte!(ch, v[i + 2]); - if w == 3 && ch < MAX_TWO_B { return false; } - if w > 3 { - if v[i + 3] & 192u8 != TAG_CONT_U8 { return false; } - ch = utf8_acc_cont_byte!(ch, v[i + 3]); - if ch < MAX_THREE_B || ch >= MAX_UNICODE { return false; } - } + + // 2-byte encoding is for codepoints \u0080 to \u07ff + // first C2 80 last DF BF + // 3-byte encoding is for codepoints \u0800 to \uffff + // first E0 A0 80 last EF BF BF + // 4-byte encoding is for codepoints \u10000 to \u10ffff + // first F0 90 80 80 last F4 8F BF BF + // + // Use the UTF-8 syntax from the RFC + // + // https://tools.ietf.org/html/rfc3629 + // UTF8-1 = %x00-7F + // UTF8-2 = %xC2-DF UTF8-tail + // UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) / + // %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail ) + // UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) / + // %xF4 %x80-8F 2( UTF8-tail ) + // UTF8-tail = %x80-BF + // -- + // This code allows surrogate pairs: \uD800 to \uDFFF -> ED A0 80 to ED BF BF + match w { + 2 => if unsafe_get(v, i + 1) & 192u8 != TAG_CONT_U8 { + return false + }, + 3 => match (v_i, + unsafe_get(v, i + 1), + unsafe_get(v, i + 2) & 192u8) { + (0xE0 , 0xA0 .. 0xBF, TAG_CONT_U8) => (), + (0xE1 .. 0xEF, 0x80 .. 0xBF, TAG_CONT_U8) => (), + _ => return false, + }, + _ => match (v_i, + unsafe_get(v, i + 1), + unsafe_get(v, i + 2) & 192u8, + unsafe_get(v, i + 3) & 192u8) { + (0xF0 , 0x90 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) => (), + (0xF1 .. 0xF3, 0x80 .. 0xBF, TAG_CONT_U8, TAG_CONT_U8) => (), + (0xF4 , 0x80 .. 0x8F, TAG_CONT_U8, TAG_CONT_U8) => (), + _ => return false, + }, } i = nexti; @@ -756,6 +768,18 @@ pub struct CharRange { next: uint } +// Return the initial codepoint accumulator for the first byte. +// The first byte is special, only want bottom 5 bits for width 2, 4 bits +// for width 3, and 3 bits for width 4 +macro_rules! utf8_first_byte( + ($byte:expr, $width:expr) => (($byte & (0x7F >> $width)) as uint) +) + +// return the value of $ch updated with continuation byte $byte +macro_rules! utf8_acc_cont_byte( + ($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63u8) as uint) +) + // UTF-8 tags and ranges priv static TAG_CONT_U8: u8 = 128u8; priv static TAG_CONT: uint = 128u; @@ -2845,13 +2869,21 @@ mod tests { } #[test] - fn test_is_utf8_deny_overlong() { + fn test_is_utf8() { assert!(!is_utf8([0xc0, 0x80])); assert!(!is_utf8([0xc0, 0xae])); assert!(!is_utf8([0xe0, 0x80, 0x80])); assert!(!is_utf8([0xe0, 0x80, 0xaf])); assert!(!is_utf8([0xe0, 0x81, 0x81])); assert!(!is_utf8([0xf0, 0x82, 0x82, 0xac])); + assert!(!is_utf8([0xf4, 0x90, 0x80, 0x80])); + + assert!(is_utf8([0xC2, 0x80])); + assert!(is_utf8([0xDF, 0xBF])); + assert!(is_utf8([0xE0, 0xA0, 0x80])); + assert!(is_utf8([0xEF, 0xBF, 0xBF])); + assert!(is_utf8([0xF0, 0x90, 0x80, 0x80])); + assert!(is_utf8([0xF4, 0x8F, 0xBF, 0xBF])); } From c1c405bed69a91876908c51c93c0984a4ba9c735 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 3 Aug 2013 02:06:24 +0400 Subject: [PATCH 04/62] Rename IpAddr -> SocketAddr, extract IpAddr from SocketAddr multicast functions now take IpAddr (without port), because they dont't need port. Uv* types renamed: * UvIpAddr -> UvSocketAddr * UvIpv4 -> UvIpv4SocketAddr * UvIpv6 -> UvIpv6SocketAddr "Socket address" is a common name for (ip-address, port) pair (e.g. in sockaddr_in struct). --- src/libstd/rt/io/net/ip.rs | 40 ++++++++---- src/libstd/rt/io/net/tcp.rs | 30 ++++----- src/libstd/rt/io/net/udp.rs | 20 +++--- src/libstd/rt/rtio.rs | 16 ++--- src/libstd/rt/test.rs | 10 +-- src/libstd/rt/uv/mod.rs | 4 +- src/libstd/rt/uv/net.rs | 118 +++++++++++++++++------------------- src/libstd/rt/uv/uvio.rs | 52 ++++++---------- 8 files changed, 142 insertions(+), 148 deletions(-) diff --git a/src/libstd/rt/io/net/ip.rs b/src/libstd/rt/io/net/ip.rs index 2b572574b60b2..815ec9b5c61ec 100644 --- a/src/libstd/rt/io/net/ip.rs +++ b/src/libstd/rt/io/net/ip.rs @@ -15,19 +15,19 @@ type Port = u16; #[deriving(Eq, TotalEq)] pub enum IpAddr { - Ipv4(u8, u8, u8, u8, Port), - Ipv6(u16, u16, u16, u16, u16, u16, u16, u16, Port) + Ipv4Addr(u8, u8, u8, u8), + Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) } impl ToStr for IpAddr { fn to_str(&self) -> ~str { match *self { - Ipv4(a, b, c, d, p) => - fmt!("%u.%u.%u.%u:%u", - a as uint, b as uint, c as uint, d as uint, p as uint), + Ipv4Addr(a, b, c, d) => + fmt!("%u.%u.%u.%u", + a as uint, b as uint, c as uint, d as uint), // Ipv4 Compatible address - Ipv6(0, 0, 0, 0, 0, 0, g, h, p) => { + Ipv6Addr(0, 0, 0, 0, 0, 0, g, h) => { let a = fmt!("%04x", g as uint); let b = FromStrRadix::from_str_radix(a.slice(2, 4), 16).unwrap(); let a = FromStrRadix::from_str_radix(a.slice(0, 2), 16).unwrap(); @@ -35,11 +35,11 @@ impl ToStr for IpAddr { let d = FromStrRadix::from_str_radix(c.slice(2, 4), 16).unwrap(); let c = FromStrRadix::from_str_radix(c.slice(0, 2), 16).unwrap(); - fmt!("[::%u.%u.%u.%u]:%u", a, b, c, d, p as uint) + fmt!("::%u.%u.%u.%u", a, b, c, d) } // Ipv4-Mapped address - Ipv6(0, 0, 0, 0, 0, 1, g, h, p) => { + Ipv6Addr(0, 0, 0, 0, 0, 1, g, h) => { let a = fmt!("%04x", g as uint); let b = FromStrRadix::from_str_radix(a.slice(2, 4), 16).unwrap(); let a = FromStrRadix::from_str_radix(a.slice(0, 2), 16).unwrap(); @@ -47,13 +47,29 @@ impl ToStr for IpAddr { let d = FromStrRadix::from_str_radix(c.slice(2, 4), 16).unwrap(); let c = FromStrRadix::from_str_radix(c.slice(0, 2), 16).unwrap(); - fmt!("[::FFFF:%u.%u.%u.%u]:%u", a, b, c, d, p as uint) + fmt!("::FFFF:%u.%u.%u.%u", a, b, c, d) } - Ipv6(a, b, c, d, e, f, g, h, p) => - fmt!("[%x:%x:%x:%x:%x:%x:%x:%x]:%u", + Ipv6Addr(a, b, c, d, e, f, g, h) => + fmt!("%x:%x:%x:%x:%x:%x:%x:%x", a as uint, b as uint, c as uint, d as uint, - e as uint, f as uint, g as uint, h as uint, p as uint) + e as uint, f as uint, g as uint, h as uint) + } + } +} + +#[deriving(Eq, TotalEq)] +pub struct SocketAddr { + ip: IpAddr, + port: Port, +} + + +impl ToStr for SocketAddr { + fn to_str(&self) -> ~str { + match self.ip { + Ipv4Addr(*) => fmt!("%s:%u", self.ip.to_str(), self.port as uint), + Ipv6Addr(*) => fmt!("[%s]:%u", self.ip.to_str(), self.port as uint), } } } diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index 780aa9cb75c56..27222542e087d 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -10,7 +10,7 @@ use option::{Option, Some, None}; use result::{Ok, Err}; -use rt::io::net::ip::IpAddr; +use rt::io::net::ip::SocketAddr; use rt::io::{Reader, Writer, Listener}; use rt::io::{io_error, read_error, EndOfFile}; use rt::rtio::{IoFactory, IoFactoryObject, @@ -26,7 +26,7 @@ impl TcpStream { TcpStream(s) } - pub fn connect(addr: IpAddr) -> Option { + pub fn connect(addr: SocketAddr) -> Option { let stream = unsafe { rtdebug!("borrowing io to connect"); let io = Local::unsafe_borrow::(); @@ -44,7 +44,7 @@ impl TcpStream { } } - pub fn peer_name(&mut self) -> Option { + pub fn peer_name(&mut self) -> Option { match (**self).peer_name() { Ok(pn) => Some(pn), Err(ioerr) => { @@ -55,7 +55,7 @@ impl TcpStream { } } - pub fn socket_name(&mut self) -> Option { + pub fn socket_name(&mut self) -> Option { match (**self).socket_name() { Ok(sn) => Some(sn), Err(ioerr) => { @@ -100,7 +100,7 @@ impl Writer for TcpStream { pub struct TcpListener(~RtioTcpListenerObject); impl TcpListener { - pub fn bind(addr: IpAddr) -> Option { + pub fn bind(addr: SocketAddr) -> Option { let listener = unsafe { let io = Local::unsafe_borrow::(); (*io).tcp_bind(addr) @@ -114,7 +114,7 @@ impl TcpListener { } } - pub fn socket_name(&mut self) -> Option { + pub fn socket_name(&mut self) -> Option { match (**self).socket_name() { Ok(sn) => Some(sn), Err(ioerr) => { @@ -145,7 +145,7 @@ mod test { use super::*; use cell::Cell; use rt::test::*; - use rt::io::net::ip::Ipv4; + use rt::io::net::ip::{Ipv4Addr, SocketAddr}; use rt::io::*; use prelude::*; @@ -157,7 +157,7 @@ mod test { assert!(e.kind == PermissionDenied); called = true; }).inside { - let addr = Ipv4(0, 0, 0, 0, 1); + let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let listener = TcpListener::bind(addr); assert!(listener.is_none()); } @@ -173,7 +173,7 @@ mod test { assert!(e.kind == ConnectionRefused); called = true; }).inside { - let addr = Ipv4(0, 0, 0, 0, 1); + let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let stream = TcpStream::connect(addr); assert!(stream.is_none()); } @@ -437,7 +437,7 @@ mod test { connect(0, addr); - fn connect(i: int, addr: IpAddr) { + fn connect(i: int, addr: SocketAddr) { if i == MAX { return } do spawntask { @@ -476,7 +476,7 @@ mod test { connect(0, addr); - fn connect(i: int, addr: IpAddr) { + fn connect(i: int, addr: SocketAddr) { if i == MAX { return } do spawntask { @@ -515,7 +515,7 @@ mod test { connect(0, addr); - fn connect(i: int, addr: IpAddr) { + fn connect(i: int, addr: SocketAddr) { if i == MAX { return } do spawntask_later { @@ -553,7 +553,7 @@ mod test { connect(0, addr); - fn connect(i: int, addr: IpAddr) { + fn connect(i: int, addr: SocketAddr) { if i == MAX { return } do spawntask_later { @@ -569,7 +569,7 @@ mod test { } #[cfg(test)] - fn socket_name(addr: IpAddr) { + fn socket_name(addr: SocketAddr) { do run_in_newsched_task { do spawntask { let listener = TcpListener::bind(addr); @@ -588,7 +588,7 @@ mod test { } #[cfg(test)] - fn peer_name(addr: IpAddr) { + fn peer_name(addr: SocketAddr) { do run_in_newsched_task { do spawntask { let mut listener = TcpListener::bind(addr); diff --git a/src/libstd/rt/io/net/udp.rs b/src/libstd/rt/io/net/udp.rs index c04abfa899b1a..644abcbe145ec 100644 --- a/src/libstd/rt/io/net/udp.rs +++ b/src/libstd/rt/io/net/udp.rs @@ -10,7 +10,7 @@ use option::{Option, Some, None}; use result::{Ok, Err}; -use rt::io::net::ip::IpAddr; +use rt::io::net::ip::SocketAddr; use rt::io::{Reader, Writer}; use rt::io::{io_error, read_error, EndOfFile}; use rt::rtio::{RtioSocket, RtioUdpSocketObject, RtioUdpSocket, IoFactory, IoFactoryObject}; @@ -19,7 +19,7 @@ use rt::local::Local; pub struct UdpSocket(~RtioUdpSocketObject); impl UdpSocket { - pub fn bind(addr: IpAddr) -> Option { + pub fn bind(addr: SocketAddr) -> Option { let socket = unsafe { (*Local::unsafe_borrow::()).udp_bind(addr) }; match socket { Ok(s) => Some(UdpSocket(s)), @@ -30,7 +30,7 @@ impl UdpSocket { } } - pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, IpAddr)> { + pub fn recvfrom(&mut self, buf: &mut [u8]) -> Option<(uint, SocketAddr)> { match (**self).recvfrom(buf) { Ok((nread, src)) => Some((nread, src)), Err(ioerr) => { @@ -43,18 +43,18 @@ impl UdpSocket { } } - pub fn sendto(&mut self, buf: &[u8], dst: IpAddr) { + pub fn sendto(&mut self, buf: &[u8], dst: SocketAddr) { match (**self).sendto(buf, dst) { Ok(_) => (), Err(ioerr) => io_error::cond.raise(ioerr), } } - pub fn connect(self, other: IpAddr) -> UdpStream { + pub fn connect(self, other: SocketAddr) -> UdpStream { UdpStream { socket: self, connectedTo: other } } - pub fn socket_name(&mut self) -> Option { + pub fn socket_name(&mut self) -> Option { match (***self).socket_name() { Ok(sn) => Some(sn), Err(ioerr) => { @@ -68,7 +68,7 @@ impl UdpSocket { pub struct UdpStream { socket: UdpSocket, - connectedTo: IpAddr + connectedTo: SocketAddr } impl UdpStream { @@ -106,7 +106,7 @@ impl Writer for UdpStream { mod test { use super::*; use rt::test::*; - use rt::io::net::ip::Ipv4; + use rt::io::net::ip::{Ipv4Addr, SocketAddr}; use rt::io::*; use option::{Some, None}; @@ -118,7 +118,7 @@ mod test { assert!(e.kind == PermissionDenied); called = true; }).inside { - let addr = Ipv4(0, 0, 0, 0, 1); + let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; let socket = UdpSocket::bind(addr); assert!(socket.is_none()); } @@ -265,7 +265,7 @@ mod test { } #[cfg(test)] - fn socket_name(addr: IpAddr) { + fn socket_name(addr: SocketAddr) { do run_in_newsched_task { do spawntask { let server = UdpSocket::bind(addr); diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index d293d46e01262..a7c794fb5f142 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -12,7 +12,7 @@ use option::*; use result::*; use rt::io::IoError; -use super::io::net::ip::IpAddr; +use super::io::net::ip::{IpAddr, SocketAddr}; use rt::uv::uvio; // XXX: ~object doesn't work currently so these are some placeholder @@ -44,9 +44,9 @@ pub trait RemoteCallback { } pub trait IoFactory { - fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError>; - fn tcp_bind(&mut self, addr: IpAddr) -> Result<~RtioTcpListenerObject, IoError>; - fn udp_bind(&mut self, addr: IpAddr) -> Result<~RtioUdpSocketObject, IoError>; + fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStreamObject, IoError>; + fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListenerObject, IoError>; + fn udp_bind(&mut self, addr: SocketAddr) -> Result<~RtioUdpSocketObject, IoError>; fn timer_init(&mut self) -> Result<~RtioTimerObject, IoError>; } @@ -59,7 +59,7 @@ pub trait RtioTcpListener : RtioSocket { pub trait RtioTcpStream : RtioSocket { fn read(&mut self, buf: &mut [u8]) -> Result; fn write(&mut self, buf: &[u8]) -> Result<(), IoError>; - fn peer_name(&mut self) -> Result; + fn peer_name(&mut self) -> Result; fn control_congestion(&mut self) -> Result<(), IoError>; fn nodelay(&mut self) -> Result<(), IoError>; fn keepalive(&mut self, delay_in_seconds: uint) -> Result<(), IoError>; @@ -67,12 +67,12 @@ pub trait RtioTcpStream : RtioSocket { } pub trait RtioSocket { - fn socket_name(&mut self) -> Result; + fn socket_name(&mut self) -> Result; } pub trait RtioUdpSocket : RtioSocket { - fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, IpAddr), IoError>; - fn sendto(&mut self, buf: &[u8], dst: IpAddr) -> Result<(), IoError>; + fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, SocketAddr), IoError>; + fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> Result<(), IoError>; fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError>; fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError>; diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 2d45b1cd13938..2427da01a0c1c 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -16,7 +16,7 @@ use clone::Clone; use container::Container; use iterator::{Iterator, range}; use vec::{OwnedVector, MutableVector}; -use super::io::net::ip::{IpAddr, Ipv4, Ipv6}; +use super::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; use rt::sched::Scheduler; use unstable::run_in_bare_thread; use rt::thread::Thread; @@ -306,13 +306,13 @@ pub fn next_test_port() -> u16 { } /// Get a unique IPv4 localhost:port pair starting at 9600 -pub fn next_test_ip4() -> IpAddr { - Ipv4(127, 0, 0, 1, next_test_port()) +pub fn next_test_ip4() -> SocketAddr { + SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: next_test_port() } } /// Get a unique IPv6 localhost:port pair starting at 9600 -pub fn next_test_ip6() -> IpAddr { - Ipv6(0, 0, 0, 0, 0, 0, 0, 1, next_test_port()) +pub fn next_test_ip6() -> SocketAddr { + SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1), port: next_test_port() } } /* diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs index fa5c497a8776d..ae5e7dd27b5f3 100644 --- a/src/libstd/rt/uv/mod.rs +++ b/src/libstd/rt/uv/mod.rs @@ -47,7 +47,7 @@ use libc::{c_void, c_int, size_t, malloc, free}; use cast::transmute; use ptr::null; use unstable::finally::Finally; -use rt::io::net::ip::IpAddr; +use rt::io::net::ip::SocketAddr; use rt::io::IoError; @@ -128,7 +128,7 @@ pub type ConnectionCallback = ~fn(StreamWatcher, Option); pub type FsCallback = ~fn(FsRequest, Option); pub type TimerCallback = ~fn(TimerWatcher, Option); pub type AsyncCallback = ~fn(AsyncWatcher, Option); -pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, IpAddr, uint, Option); +pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option); pub type UdpSendCallback = ~fn(UdpWatcher, Option); diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 5ac9f52f335b2..67d3bbef8a9c6 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -15,56 +15,45 @@ use rt::uv::uvll::*; use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback}; use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle, NullCallback, status_to_maybe_uv_error}; -use rt::io::net::ip::{IpAddr, Ipv4, Ipv6}; +use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr}; use rt::uv::last_uv_error; use vec; use str; use from_str::{FromStr}; use num; -pub enum UvIpAddr { - UvIpv4(*sockaddr_in), - UvIpv6(*sockaddr_in6), +pub enum UvSocketAddr { + UvIpv4SocketAddr(*sockaddr_in), + UvIpv6SocketAddr(*sockaddr_in6), } -fn sockaddr_to_UvIpAddr(addr: *uvll::sockaddr) -> UvIpAddr { +fn sockaddr_to_UvSocketAddr(addr: *uvll::sockaddr) -> UvSocketAddr { unsafe { assert!((is_ip4_addr(addr) || is_ip6_addr(addr))); assert!(!(is_ip4_addr(addr) && is_ip6_addr(addr))); match addr { - _ if is_ip4_addr(addr) => UvIpv4(addr as *uvll::sockaddr_in), - _ if is_ip6_addr(addr) => UvIpv6(addr as *uvll::sockaddr_in6), + _ if is_ip4_addr(addr) => UvIpv4SocketAddr(addr as *uvll::sockaddr_in), + _ if is_ip6_addr(addr) => UvIpv6SocketAddr(addr as *uvll::sockaddr_in6), _ => fail!(), } } } -fn ip_as_uv_ip(addr: IpAddr, f: &fn(UvIpAddr) -> T) -> T { - let malloc = match addr { - Ipv4(*) => malloc_ip4_addr, - Ipv6(*) => malloc_ip6_addr, +fn socket_addr_as_uv_socket_addr(addr: SocketAddr, f: &fn(UvSocketAddr) -> T) -> T { + let malloc = match addr.ip { + Ipv4Addr(*) => malloc_ip4_addr, + Ipv6Addr(*) => malloc_ip6_addr, }; - let wrap = match addr { - Ipv4(*) => UvIpv4, - Ipv6(*) => UvIpv6, + let wrap = match addr.ip { + Ipv4Addr(*) => UvIpv4SocketAddr, + Ipv6Addr(*) => UvIpv6SocketAddr, }; - let ip_str = match addr { - Ipv4(x1, x2, x3, x4, _) => - fmt!("%u.%u.%u.%u", x1 as uint, x2 as uint, x3 as uint, x4 as uint), - Ipv6(x1, x2, x3, x4, x5, x6, x7, x8, _) => - fmt!("%x:%x:%x:%x:%x:%x:%x:%x", - x1 as uint, x2 as uint, x3 as uint, x4 as uint, - x5 as uint, x6 as uint, x7 as uint, x8 as uint), - }; - let port = match addr { - Ipv4(_, _, _, _, p) | Ipv6(_, _, _, _, _, _, _, _, p) => p as int - }; - let free = match addr { - Ipv4(*) => free_ip4_addr, - Ipv6(*) => free_ip6_addr, + let free = match addr.ip { + Ipv4Addr(*) => free_ip4_addr, + Ipv6Addr(*) => free_ip6_addr, }; - let addr = unsafe { malloc(ip_str, port) }; + let addr = unsafe { malloc(addr.ip.to_str(), addr.port as int) }; do (|| { f(wrap(addr)) }).finally { @@ -72,39 +61,43 @@ fn ip_as_uv_ip(addr: IpAddr, f: &fn(UvIpAddr) -> T) -> T { } } -fn uv_ip_as_ip(addr: UvIpAddr, f: &fn(IpAddr) -> T) -> T { +fn uv_socket_addr_as_socket_addr(addr: UvSocketAddr, f: &fn(SocketAddr) -> T) -> T { let ip_size = match addr { - UvIpv4(*) => 4/*groups of*/ * 3/*digits separated by*/ + 3/*periods*/, - UvIpv6(*) => 8/*groups of*/ * 4/*hex digits separated by*/ + 7 /*colons*/, + UvIpv4SocketAddr(*) => 4/*groups of*/ * 3/*digits separated by*/ + 3/*periods*/, + UvIpv6SocketAddr(*) => 8/*groups of*/ * 4/*hex digits separated by*/ + 7 /*colons*/, }; let ip_name = { let buf = vec::from_elem(ip_size + 1 /*null terminated*/, 0u8); unsafe { + let buf_ptr = vec::raw::to_ptr(buf); match addr { - UvIpv4(addr) => uvll::ip4_name(addr, vec::raw::to_ptr(buf), ip_size as size_t), - UvIpv6(addr) => uvll::ip6_name(addr, vec::raw::to_ptr(buf), ip_size as size_t), + UvIpv4SocketAddr(addr) => uvll::ip4_name(addr, buf_ptr, ip_size as size_t), + UvIpv6SocketAddr(addr) => uvll::ip6_name(addr, buf_ptr, ip_size as size_t), } }; buf }; let ip_port = unsafe { let port = match addr { - UvIpv4(addr) => uvll::ip4_port(addr), - UvIpv6(addr) => uvll::ip6_port(addr), + UvIpv4SocketAddr(addr) => uvll::ip4_port(addr), + UvIpv6SocketAddr(addr) => uvll::ip6_port(addr), }; port as u16 }; let ip_str = str::from_bytes_slice(ip_name).trim_right_chars(&'\x00'); let ip = match addr { - UvIpv4(*) => { + UvIpv4SocketAddr(*) => { let ip: ~[u8] = ip_str.split_iter('.') .transform(|s: &str| -> u8 { FromStr::from_str(s).unwrap() }) .collect(); assert_eq!(ip.len(), 4); - Ipv4(ip[0], ip[1], ip[2], ip[3], ip_port) + SocketAddr { + ip: Ipv4Addr(ip[0], ip[1], ip[2], ip[3]), + port: ip_port + } }, - UvIpv6(*) => { + UvIpv6SocketAddr(*) => { let ip: ~[u16] = { let expand_shorthand_and_convert = |s: &str| -> ~[~[u16]] { let convert_each_segment = |s: &str| -> ~[u16] { @@ -154,7 +147,10 @@ fn uv_ip_as_ip(addr: UvIpAddr, f: &fn(IpAddr) -> T) -> T { } }; assert_eq!(ip.len(), 8); - Ipv6(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip_port) + SocketAddr { + ip: Ipv6Addr(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7]), + port: ip_port + } }, }; @@ -162,9 +158,9 @@ fn uv_ip_as_ip(addr: UvIpAddr, f: &fn(IpAddr) -> T) -> T { f(ip) } -pub fn uv_ip_to_ip(addr: UvIpAddr) -> IpAddr { +pub fn uv_socket_addr_to_socket_addr(addr: UvSocketAddr) -> SocketAddr { use util; - uv_ip_as_ip(addr, util::id) + uv_socket_addr_as_socket_addr(addr, util::id) } #[cfg(test)] @@ -172,7 +168,7 @@ pub fn uv_ip_to_ip(addr: UvIpAddr) -> IpAddr { fn test_ip4_conversion() { use rt; let ip4 = rt::test::next_test_ip4(); - assert_eq!(ip4, ip_as_uv_ip(ip4, uv_ip_to_ip)); + assert_eq!(ip4, socket_addr_as_uv_socket_addr(ip4, uv_socket_addr_to_socket_addr)); } #[cfg(test)] @@ -180,7 +176,7 @@ fn test_ip4_conversion() { fn test_ip6_conversion() { use rt; let ip6 = rt::test::next_test_ip6(); - assert_eq!(ip6, ip_as_uv_ip(ip6, uv_ip_to_ip)); + assert_eq!(ip6, socket_addr_as_uv_socket_addr(ip6, uv_socket_addr_to_socket_addr)); } // uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t @@ -293,12 +289,12 @@ impl TcpWatcher { } } - pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> { - do ip_as_uv_ip(address) |addr| { + pub fn bind(&mut self, address: SocketAddr) -> Result<(), UvError> { + do socket_addr_as_uv_socket_addr(address) |addr| { let result = unsafe { match addr { - UvIpv4(addr) => uvll::tcp_bind(self.native_handle(), addr), - UvIpv6(addr) => uvll::tcp_bind6(self.native_handle(), addr), + UvIpv4SocketAddr(addr) => uvll::tcp_bind(self.native_handle(), addr), + UvIpv6SocketAddr(addr) => uvll::tcp_bind6(self.native_handle(), addr), } }; match result { @@ -308,18 +304,18 @@ impl TcpWatcher { } } - pub fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) { + pub fn connect(&mut self, address: SocketAddr, cb: ConnectionCallback) { unsafe { assert!(self.get_watcher_data().connect_cb.is_none()); self.get_watcher_data().connect_cb = Some(cb); let connect_handle = ConnectRequest::new().native_handle(); rtdebug!("connect_t: %x", connect_handle as uint); - do ip_as_uv_ip(address) |addr| { + do socket_addr_as_uv_socket_addr(address) |addr| { let result = match addr { - UvIpv4(addr) => uvll::tcp_connect(connect_handle, + UvIpv4SocketAddr(addr) => uvll::tcp_connect(connect_handle, self.native_handle(), addr, connect_cb), - UvIpv6(addr) => uvll::tcp_connect6(connect_handle, + UvIpv6SocketAddr(addr) => uvll::tcp_connect6(connect_handle, self.native_handle(), addr, connect_cb), }; assert_eq!(0, result); @@ -388,12 +384,12 @@ impl UdpWatcher { } } - pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> { - do ip_as_uv_ip(address) |addr| { + pub fn bind(&mut self, address: SocketAddr) -> Result<(), UvError> { + do socket_addr_as_uv_socket_addr(address) |addr| { let result = unsafe { match addr { - UvIpv4(addr) => uvll::udp_bind(self.native_handle(), addr, 0u32), - UvIpv6(addr) => uvll::udp_bind6(self.native_handle(), addr, 0u32), + UvIpv4SocketAddr(addr) => uvll::udp_bind(self.native_handle(), addr, 0u32), + UvIpv6SocketAddr(addr) => uvll::udp_bind6(self.native_handle(), addr, 0u32), } }; match result { @@ -432,7 +428,7 @@ impl UdpWatcher { let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle); let cb = udp_watcher.get_watcher_data().udp_recv_cb.get_ref(); let status = status_to_maybe_uv_error(udp_watcher, nread as c_int); - let addr = uv_ip_to_ip(sockaddr_to_UvIpAddr(addr)); + let addr = uv_socket_addr_to_socket_addr(sockaddr_to_UvSocketAddr(addr)); (*cb)(udp_watcher, nread as int, buf, addr, flags as uint, status); } } @@ -441,7 +437,7 @@ impl UdpWatcher { unsafe { uvll::udp_recv_stop(self.native_handle()); } } - pub fn send(&mut self, buf: Buf, address: IpAddr, cb: UdpSendCallback) { + pub fn send(&mut self, buf: Buf, address: SocketAddr, cb: UdpSendCallback) { { let data = self.get_watcher_data(); assert!(data.udp_send_cb.is_none()); @@ -449,12 +445,12 @@ impl UdpWatcher { } let req = UdpSendRequest::new(); - do ip_as_uv_ip(address) |addr| { + do socket_addr_as_uv_socket_addr(address) |addr| { let result = unsafe { match addr { - UvIpv4(addr) => uvll::udp_send(req.native_handle(), + UvIpv4SocketAddr(addr) => uvll::udp_send(req.native_handle(), self.native_handle(), [buf], addr, send_cb), - UvIpv6(addr) => uvll::udp_send6(req.native_handle(), + UvIpv6SocketAddr(addr) => uvll::udp_send6(req.native_handle(), self.native_handle(), [buf], addr, send_cb), } }; diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 5c17aea934143..85cf660a5f1aa 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -18,10 +18,10 @@ use clone::Clone; use libc::{c_int, c_uint, c_void}; use ptr; use rt::io::IoError; -use rt::io::net::ip::{IpAddr, Ipv4, Ipv6}; +use rt::io::net::ip::{SocketAddr, IpAddr}; use rt::uv::*; use rt::uv::idle::IdleWatcher; -use rt::uv::net::{UvIpv4, UvIpv6}; +use rt::uv::net::{UvIpv4SocketAddr, UvIpv6SocketAddr}; use rt::rtio::*; use rt::sched::Scheduler; use rt::io::{standard_error, OtherIoError}; @@ -44,7 +44,7 @@ enum SocketNameKind { } fn socket_name>(sk: SocketNameKind, - handle: U) -> Result { + handle: U) -> Result { let getsockname = match sk { TcpPeer => uvll::rust_uv_tcp_getpeername, @@ -67,9 +67,9 @@ fn socket_name>(sk: SocketNameKind, let addr = unsafe { if uvll::is_ip6_addr(r_addr as *uvll::sockaddr) { - net::uv_ip_to_ip(UvIpv6(r_addr as *uvll::sockaddr_in6)) + net::uv_socket_addr_to_socket_addr(UvIpv6SocketAddr(r_addr as *uvll::sockaddr_in6)) } else { - net::uv_ip_to_ip(UvIpv4(r_addr as *uvll::sockaddr_in)) + net::uv_socket_addr_to_socket_addr(UvIpv4SocketAddr(r_addr as *uvll::sockaddr_in)) } }; @@ -244,7 +244,7 @@ impl IoFactory for UvIoFactory { // Connect to an address and return a new stream // NB: This blocks the task waiting on the connection. // It would probably be better to return a future - fn tcp_connect(&mut self, addr: IpAddr) -> Result<~RtioTcpStreamObject, IoError> { + fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStreamObject, IoError> { // Create a cell in the task to hold the result. We will fill // the cell before resuming the task. let result_cell = Cell::new_empty(); @@ -291,7 +291,7 @@ impl IoFactory for UvIoFactory { return result_cell.take(); } - fn tcp_bind(&mut self, addr: IpAddr) -> Result<~RtioTcpListenerObject, IoError> { + fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListenerObject, IoError> { let mut watcher = TcpWatcher::new(self.uv_loop()); match watcher.bind(addr) { Ok(_) => Ok(~UvTcpListener::new(watcher)), @@ -309,7 +309,7 @@ impl IoFactory for UvIoFactory { } } - fn udp_bind(&mut self, addr: IpAddr) -> Result<~RtioUdpSocketObject, IoError> { + fn udp_bind(&mut self, addr: SocketAddr) -> Result<~RtioUdpSocketObject, IoError> { let mut watcher = UdpWatcher::new(self.uv_loop()); match watcher.bind(addr) { Ok(_) => Ok(~UvUdpSocket(watcher)), @@ -365,7 +365,7 @@ impl Drop for UvTcpListener { } impl RtioSocket for UvTcpListener { - fn socket_name(&mut self) -> Result { + fn socket_name(&mut self) -> Result { socket_name(Tcp, self.watcher) } } @@ -445,7 +445,7 @@ impl Drop for UvTcpStream { } impl RtioSocket for UvTcpStream { - fn socket_name(&mut self) -> Result { + fn socket_name(&mut self) -> Result { socket_name(Tcp, **self) } } @@ -519,7 +519,7 @@ impl RtioTcpStream for UvTcpStream { return result_cell.take(); } - fn peer_name(&mut self) -> Result { + fn peer_name(&mut self) -> Result { socket_name(TcpPeer, **self) } @@ -586,15 +586,15 @@ impl Drop for UvUdpSocket { } impl RtioSocket for UvUdpSocket { - fn socket_name(&mut self) -> Result { + fn socket_name(&mut self) -> Result { socket_name(Udp, **self) } } impl RtioUdpSocket for UvUdpSocket { - fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, IpAddr), IoError> { + fn recvfrom(&mut self, buf: &mut [u8]) -> Result<(uint, SocketAddr), IoError> { let result_cell = Cell::new_empty(); - let result_cell_ptr: *Cell> = &result_cell; + let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); let buf_ptr: *&mut [u8] = &buf; @@ -626,7 +626,7 @@ impl RtioUdpSocket for UvUdpSocket { return result_cell.take(); } - fn sendto(&mut self, buf: &[u8], dst: IpAddr) -> Result<(), IoError> { + fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> Result<(), IoError> { let result_cell = Cell::new_empty(); let result_cell_ptr: *Cell> = &result_cell; let scheduler = Local::take::(); @@ -653,17 +653,8 @@ impl RtioUdpSocket for UvUdpSocket { } fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { - let ip_str = match multi { - Ipv4(x1, x2, x3, x4, _) => - fmt!("%u.%u.%u.%u", x1 as uint, x2 as uint, x3 as uint, x4 as uint), - Ipv6(x1, x2, x3, x4, x5, x6, x7, x8, _) => - fmt!("%x:%x:%x:%x:%x:%x:%x:%x", - x1 as uint, x2 as uint, x3 as uint, x4 as uint, - x5 as uint, x6 as uint, x7 as uint, x8 as uint), - }; - let r = unsafe { - do ip_str.as_c_str |m_addr| { + do multi.to_str().as_c_str |m_addr| { uvll::udp_set_membership(self.native_handle(), m_addr, ptr::null(), uvll::UV_JOIN_GROUP) } @@ -676,17 +667,8 @@ impl RtioUdpSocket for UvUdpSocket { } fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { - let ip_str = match multi { - Ipv4(x1, x2, x3, x4, _) => - fmt!("%u.%u.%u.%u", x1 as uint, x2 as uint, x3 as uint, x4 as uint), - Ipv6(x1, x2, x3, x4, x5, x6, x7, x8, _) => - fmt!("%x:%x:%x:%x:%x:%x:%x:%x", - x1 as uint, x2 as uint, x3 as uint, x4 as uint, - x5 as uint, x6 as uint, x7 as uint, x8 as uint), - }; - let r = unsafe { - do ip_str.as_c_str |m_addr| { + do multi.to_str().as_c_str |m_addr| { uvll::udp_set_membership(self.native_handle(), m_addr, ptr::null(), uvll::UV_LEAVE_GROUP) } From 48e1af8852209035b333366f11ad4f8fbe117c53 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 2 Aug 2013 22:05:32 -0700 Subject: [PATCH 05/62] Suppress a libuv leak on mac I suspect that this is a race between process exit and the termination of worker threads used by libuv (if I sleep before exit it doesn't leak). This isn't going to cause any real problems but should probably be fixed at some point. --- src/etc/x86.supp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/etc/x86.supp b/src/etc/x86.supp index def1c5a53c1fd..e6064ff4f72d2 100644 --- a/src/etc/x86.supp +++ b/src/etc/x86.supp @@ -502,3 +502,16 @@ fun:* ... } + +{ + libuv-mac-no-thread-join + Memcheck:Leak + fun:malloc_zone_malloc + fun:_CFRuntimeCreateInstance + fun:CFRunLoopSourceCreate + fun:uv__platform_loop_init + fun:uv__loop_init + fun:uv_loop_new + fun:rust_uv_loop_new__c_stack_shim + ... +} \ No newline at end of file From db6ff76e858673d61e5455c2fedf2b93a3053f5d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 3 Aug 2013 18:31:23 +1000 Subject: [PATCH 06/62] etc: add the `in` keyword to the emacs mode. --- src/etc/emacs/rust-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 106cdbfd5f426..87c505e69d0b9 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -102,7 +102,7 @@ "do" "else" "enum" "extern" "false" "fn" "for" - "if" "impl" + "if" "impl" "in" "let" "loop" "match" "mod" "mut" "priv" "pub" From b1420771ed758bed2cf6dd2cfed2e04e89e51f5b Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Sat, 3 Aug 2013 07:06:27 +0900 Subject: [PATCH 07/62] Fix building problems in extra::unicode. Signed-off-by: OGINO Masanori --- src/libextra/unicode.rs | 51 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/libextra/unicode.rs b/src/libextra/unicode.rs index 4949ee79e5d80..3957551c84639 100644 --- a/src/libextra/unicode.rs +++ b/src/libextra/unicode.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; #[allow(missing_doc)]; pub mod icu { @@ -159,7 +158,10 @@ pub mod icu { pub static UCHAR_INVALID_CODE : UProperty = -1; pub mod libicu { - #[link_name = "icuuc"] + use unicode::icu::*; + + // #[link_name = "icuuc"] + #[link_args = "-licuuc"] #[abi = "cdecl"] extern { pub fn u_hasBinaryProperty(c: UChar32, which: UProperty) -> UBool; @@ -174,13 +176,17 @@ pub mod icu { } pub fn is_XID_start(c: char) -> bool { - return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START) - == icu::TRUE; + unsafe { + return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START) + == icu::TRUE; + } } pub fn is_XID_continue(c: char) -> bool { - return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START) - == icu::TRUE; + unsafe { + return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START) + == icu::TRUE; + } } /* @@ -189,7 +195,9 @@ Function: is_digit Returns true if a character is a digit. */ pub fn is_digit(c: char) -> bool { - return icu::libicu::u_isdigit(c) == icu::TRUE; + unsafe { + return icu::libicu::u_isdigit(c) == icu::TRUE; + } } /* @@ -198,7 +206,9 @@ Function: is_lower Returns true if a character is a lowercase letter. */ pub fn is_lower(c: char) -> bool { - return icu::libicu::u_islower(c) == icu::TRUE; + unsafe { + return icu::libicu::u_islower(c) == icu::TRUE; + } } /* @@ -207,7 +217,9 @@ Function: is_space Returns true if a character is space. */ pub fn is_space(c: char) -> bool { - return icu::libicu::u_isspace(c) == icu::TRUE; + unsafe { + return icu::libicu::u_isspace(c) == icu::TRUE; + } } /* @@ -216,33 +228,36 @@ Function: is_upper Returns true if a character is an uppercase letter. */ pub fn is_upper(c: char) -> bool { - return icu::libicu::u_isupper(c) == icu::TRUE; + unsafe { + return icu::libicu::u_isupper(c) == icu::TRUE; + } } #[cfg(test)] mod tests { + use unicode::*; #[test] fn test_is_digit() { - assert!((unicode::icu::is_digit('0'))); - assert!((!unicode::icu::is_digit('m'))); + assert!((is_digit('0'))); + assert!((!is_digit('m'))); } #[test] fn test_is_lower() { - assert!((unicode::icu::is_lower('m'))); - assert!((!unicode::icu::is_lower('M'))); + assert!((is_lower('m'))); + assert!((!is_lower('M'))); } #[test] fn test_is_space() { - assert!((unicode::icu::is_space(' '))); - assert!((!unicode::icu::is_space('m'))); + assert!((is_space(' '))); + assert!((!is_space('m'))); } #[test] fn test_is_upper() { - assert!((unicode::icu::is_upper('M'))); - assert!((!unicode::icu::is_upper('m'))); + assert!((is_upper('M'))); + assert!((!is_upper('m'))); } } From 4a09595d1b03548a984b0afa552a5a6fbcba4bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Sat, 3 Aug 2013 12:35:33 +0200 Subject: [PATCH 08/62] trans_arg_expr: Omit extra copies for rvalues rvalues aren't going to be used anywhere but as the argument, so there's no point in copying them. LLVM used to eliminate the copy later, but why bother emitting it in the first place? --- src/librustc/middle/trans/callee.rs | 75 +++++++++-------------------- 1 file changed, 24 insertions(+), 51 deletions(-) diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 581ffa5252cec..a0e71bc227279 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -762,60 +762,33 @@ pub fn trans_arg_expr(bcx: @mut Block, val = arg_datum.to_ref_llval(bcx); } DontAutorefArg => { - match self_mode { + let need_scratch = ty::type_needs_drop(bcx.tcx(), arg_datum.ty) || + (bcx.expr_is_lval(arg_expr) && + arg_datum.appropriate_mode(bcx.tcx()).is_by_ref()); + + let arg_datum = if need_scratch { + let scratch = scratch_datum(bcx, arg_datum.ty, "__self", false); + arg_datum.store_to_datum(bcx, INIT, scratch); + + // Technically, ownership of val passes to the callee. + // However, we must cleanup should we fail before the + // callee is actually invoked. + scratch.add_clean(bcx); + temp_cleanups.push(scratch.val); + + scratch + } else { + arg_datum + }; + + val = match self_mode { ty::ByRef => { - // This assertion should really be valid, but because - // the explicit self code currently passes by-ref, it - // does not hold. - // - //assert !bcx.ccx().maps.moves_map.contains_key( - // &arg_expr.id); - debug!("by ref arg with type %s, storing to scratch", - bcx.ty_to_str(arg_datum.ty)); - let scratch = scratch_datum(bcx, arg_datum.ty, - "__self", false); - - arg_datum.store_to_datum(bcx, - INIT, - scratch); - - // Technically, ownership of val passes to the callee. - // However, we must cleanup should we fail before the - // callee is actually invoked. - scratch.add_clean(bcx); - temp_cleanups.push(scratch.val); - - val = scratch.to_ref_llval(bcx); + debug!("by ref arg with type %s", bcx.ty_to_str(arg_datum.ty)); + arg_datum.to_ref_llval(bcx) } ty::ByCopy => { - if ty::type_needs_drop(bcx.tcx(), arg_datum.ty) || - arg_datum.appropriate_mode(bcx.tcx()).is_by_ref() { - debug!("by copy arg with type %s, storing to scratch", - bcx.ty_to_str(arg_datum.ty)); - let scratch = scratch_datum(bcx, arg_datum.ty, - "__arg", false); - - arg_datum.store_to_datum(bcx, - INIT, - scratch); - - // Technically, ownership of val passes to the callee. - // However, we must cleanup should we fail before the - // callee is actually invoked. - scratch.add_clean(bcx); - temp_cleanups.push(scratch.val); - - match scratch.appropriate_mode(bcx.tcx()) { - ByValue => val = Load(bcx, scratch.val), - ByRef(_) => val = scratch.val, - } - } else { - debug!("by copy arg with type %s", bcx.ty_to_str(arg_datum.ty)); - match arg_datum.mode { - ByRef(_) => val = Load(bcx, arg_datum.val), - ByValue => val = arg_datum.val, - } - } + debug!("by copy arg with type %s", bcx.ty_to_str(arg_datum.ty)); + arg_datum.to_appropriate_llval(bcx) } } } From 0ab4965c9117d59c8ff155a57e5c1080cf44058c Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Sat, 3 Aug 2013 22:14:01 -0400 Subject: [PATCH 09/62] Work around #8256, do not fail the task, just return None --- src/librustc/middle/resolve.rs | 2 +- src/libsyntax/codemap.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 60ecff39d8554..693c59d0edcf8 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -3097,7 +3097,7 @@ impl Resolver { let imports: &mut ~[@ImportDirective] = &mut *module_.imports; let import_count = imports.len(); if index != import_count { - let sn = self.session.codemap.span_to_snippet(imports[index].span); + let sn = self.session.codemap.span_to_snippet(imports[index].span).unwrap(); if sn.contains("::") { self.session.span_err(imports[index].span, "unresolved import"); } else { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 0da424ce54cdd..8c70f128d9a09 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -369,12 +369,19 @@ impl CodeMap { return @FileLines {file: lo.file, lines: lines}; } - pub fn span_to_snippet(&self, sp: span) -> ~str { + pub fn span_to_snippet(&self, sp: span) -> Option<~str> { let begin = self.lookup_byte_offset(sp.lo); let end = self.lookup_byte_offset(sp.hi); - assert_eq!(begin.fm.start_pos, end.fm.start_pos); - return begin.fm.src.slice( - begin.pos.to_uint(), end.pos.to_uint()).to_owned(); + + // FIXME #8256: this used to be an assert but whatever precondition + // it's testing isn't true for all spans in the AST, so to allow the + // caller to not have to fail (and it can't catch it since the CodeMap + // isn't sendable), return None + if begin.fm.start_pos != end.fm.start_pos { + None + } else { + Some(begin.fm.src.slice( begin.pos.to_uint(), end.pos.to_uint()).to_owned()) + } } pub fn get_filemap(&self, filename: &str) -> @FileMap { From 4b4960cfd9e1e389b890a73566daa3ce6fb7cd9e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 3 Aug 2013 19:59:46 -0700 Subject: [PATCH 10/62] librustc: Implement `#[no_main]`, which omits the entry point entirely. Useful for SDL and possibly Android too. --- src/librustc/driver/session.rs | 3 ++- src/librustc/middle/entry.rs | 6 ++++++ src/librustc/middle/trans/base.rs | 15 +++++++++------ src/librustc/middle/typeck/mod.rs | 3 ++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index e43f85008d5c3..d725e2db1eba1 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -179,7 +179,8 @@ pub struct crate_metadata { #[deriving(Eq)] pub enum EntryFnType { EntryMain, - EntryStart + EntryStart, + EntryNone, } pub struct Session_ { diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 1bf5c944fabb0..34aeaf8a6cebe 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -50,6 +50,12 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map) return; } + // If the user wants no main function at all, then stop here. + if attr::contains_name(crate.attrs, "no_main") { + *session.entry_type = Some(session::EntryNone); + return + } + let ctxt = @mut EntryContext { session: session, ast_map: ast_map, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 5070d678c9fab..f41c0adf0bd30 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2295,13 +2295,16 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool { // Create a _rust_main(args: ~[str]) function which will be called from the // runtime rust_start function pub fn create_entry_wrapper(ccx: @mut CrateContext, - _sp: span, main_llfn: ValueRef) { + _sp: span, + main_llfn: ValueRef) { let et = ccx.sess.entry_type.unwrap(); - if et == session::EntryMain { - let llfn = create_main(ccx, main_llfn); - create_entry_fn(ccx, llfn, true); - } else { - create_entry_fn(ccx, main_llfn, false); + match et { + session::EntryMain => { + let llfn = create_main(ccx, main_llfn); + create_entry_fn(ccx, llfn, true); + } + session::EntryStart => create_entry_fn(ccx, main_llfn, false), + session::EntryNone => {} // Do nothing. } fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef { diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 6128c16996742..e6c27fc8f836d 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -408,9 +408,10 @@ fn check_for_entry_fn(ccx: &CrateCtxt) { Some((id, sp)) => match *tcx.sess.entry_type { Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp), Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp), + Some(session::EntryNone) => {} None => tcx.sess.bug("entry function without a type") }, - None => tcx.sess.bug("type checking without entry function") + None => {} } } } From 35318b729bffea777fb76def1160aa05127c6bc1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 1 Aug 2013 23:31:53 -0700 Subject: [PATCH 11/62] std: Remove gc and stackwalk These are both obsoleted by the forthcoming new GC. --- src/libstd/gc.rs | 358 ---------------------------------------- src/libstd/stackwalk.rs | 80 --------- src/libstd/std.rs | 2 - src/libstd/sys.rs | 4 - 4 files changed, 444 deletions(-) delete mode 100644 src/libstd/gc.rs delete mode 100644 src/libstd/stackwalk.rs diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs deleted file mode 100644 index 2e27f82f6f6ef..0000000000000 --- a/src/libstd/gc.rs +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[doc(hidden)]; -#[allow(non_uppercase_statics)]; - -/*! Precise garbage collector - -The precise GC exposes two functions, gc and -cleanup_stack_for_failure. The gc function is the entry point to the -garbage collector itself. The cleanup_stack_for_failure is the entry -point for GC-based cleanup. - -Precise GC depends on changes to LLVM's GC which add support for -automatic rooting and addrspace-based metadata marking. Rather than -explicitly rooting pointers with LLVM's gcroot intrinsic, the GC -merely creates allocas for pointers, and allows an LLVM pass to -automatically infer roots based on the allocas present in a function -(and live at a given location). The compiler communicates the type of -the pointer to LLVM by setting the addrspace of the pointer type. The -compiler then emits a map from addrspace to tydesc, which LLVM then -uses to match pointers with their tydesc. The GC reads the metadata -table produced by LLVM, and uses it to determine which glue functions -to call to free objects on their respective heaps. - -GC-based cleanup is a replacement for landing pads which relies on the -GC infrastructure to find pointers on the stack to cleanup. Whereas -the normal GC needs to walk task-local heap allocations, the cleanup -code needs to walk exchange heap allocations and stack-allocations -with destructors. - -*/ - -use cast; -use container::{Set, MutableSet}; -use io; -use libc::{uintptr_t}; -use option::{None, Option, Some}; -use ptr; -use hashmap::HashSet; -use stackwalk::walk_stack; -use sys; -use unstable::intrinsics::{TyDesc}; - -pub use stackwalk::Word; - -// Mirrors rust_stack.h stk_seg -pub struct StackSegment { - prev: *StackSegment, - next: *StackSegment, - end: uintptr_t, - // And other fields which we don't care about... -} - -pub mod rustrt { - use stackwalk::Word; - use super::StackSegment; - - #[link_name = "rustrt"] - extern { - #[rust_stack] - pub fn rust_gc_metadata() -> *Word; - - pub fn rust_get_stack_segment() -> *StackSegment; - pub fn rust_get_c_stack() -> *StackSegment; - } -} - -unsafe fn bump(ptr: *T, count: uint) -> *U { - return ptr::offset(ptr, count as int) as *U; -} - -unsafe fn align_to_pointer(ptr: *T) -> *T { - let align = sys::min_align_of::<*T>(); - let ptr = ptr as uint; - let ptr = (ptr + (align - 1)) & -align; - return ptr as *T; -} - -unsafe fn get_safe_point_count() -> uint { - let module_meta = rustrt::rust_gc_metadata(); - return *module_meta; -} - -struct SafePoint { - sp_meta: *Word, - fn_meta: *Word, -} - -// Returns the safe point metadata for the given program counter, if -// any. -unsafe fn is_safe_point(pc: *Word) -> Option { - let module_meta = rustrt::rust_gc_metadata(); - let num_safe_points = *module_meta; - let safe_points: *Word = bump(module_meta, 1); - - if ptr::is_null(pc) { - return None; - } - - // FIXME (#2997): Use binary rather than linear search. - let mut spi = 0; - while spi < num_safe_points { - let sp: **Word = bump(safe_points, spi*3); - let sp_loc = *sp; - if sp_loc == pc { - return Some(SafePoint { - sp_meta: *bump(sp, 1), - fn_meta: *bump(sp, 2), - }); - } - spi += 1; - } - return None; -} - -type Visitor<'self> = &'self fn(root: **Word, tydesc: *TyDesc); - -// Walks the list of roots for the given safe point, and calls visitor -// on each root. -unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { - let fp_bytes = fp as *u8; - let sp_meta = sp.sp_meta as *u32; - - let num_stack_roots = *sp_meta as uint; - let num_reg_roots = *ptr::offset(sp_meta, 1) as uint; - - let stack_roots: *u32 = bump(sp_meta, 2); - let reg_roots: *u8 = bump(stack_roots, num_stack_roots); - let addrspaces: *Word = align_to_pointer(bump(reg_roots, num_reg_roots)); - let tydescs: ***TyDesc = bump(addrspaces, num_stack_roots); - - // Stack roots - let mut sri = 0; - while sri < num_stack_roots { - if *ptr::offset(addrspaces, sri as int) >= 1 { - let root = - ptr::offset(fp_bytes, *ptr::offset(stack_roots, sri as int) as int) - as **Word; - let tydescpp = ptr::offset(tydescs, sri as int); - let tydesc = if ptr::is_not_null(tydescpp) && - ptr::is_not_null(*tydescpp) { - **tydescpp - } else { - ptr::null() - }; - visitor(root, tydesc); - } - sri += 1; - } - - // Register roots - let mut rri = 0; - while rri < num_reg_roots { - if *ptr::offset(addrspaces, (num_stack_roots + rri) as int) == 1 { - // FIXME(#2997): Need to find callee saved registers on the stack. - } - rri += 1; - } -} - -unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { - _walk_safe_point(fp, sp, visitor) -} - -// Is fp contained in segment? -unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool { - let begin = segment as Word; - let end = (*segment).end as Word; - let frame = fp as Word; - - return begin <= frame && frame <= end; -} - -struct Segment { segment: *StackSegment, boundary: bool } - -// Find and return the segment containing the given frame pointer. At -// stack segment boundaries, returns true for boundary, so that the -// caller can do any special handling to identify where the correct -// return address is in the stack frame. -unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment) - -> Segment { - // Check if frame is in either current frame or previous frame. - let in_segment = is_frame_in_segment(fp, segment); - let in_prev_segment = ptr::is_not_null((*segment).prev) && - is_frame_in_segment(fp, (*segment).prev); - - // If frame is not in either segment, walk down segment list until - // we find the segment containing this frame. - if !in_segment && !in_prev_segment { - let mut segment = segment; - while ptr::is_not_null((*segment).next) && - is_frame_in_segment(fp, (*segment).next) { - segment = (*segment).next; - } - return Segment {segment: segment, boundary: false}; - } - - // If frame is in previous frame, then we're at a boundary. - if !in_segment && in_prev_segment { - return Segment {segment: (*segment).prev, boundary: true}; - } - - // Otherwise, we're somewhere on the inside of the frame. - return Segment {segment: segment, boundary: false}; -} - -type Memory = uint; - -static task_local_heap: Memory = 1; -static exchange_heap: Memory = 2; -static stack: Memory = 4; - -static need_cleanup: Memory = exchange_heap | stack; - -// Walks stack, searching for roots of the requested type, and passes -// each root to the visitor. -unsafe fn _walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) { - let mut segment = rustrt::rust_get_stack_segment(); - let mut last_ret: *Word = ptr::null(); - // To avoid collecting memory used by the GC itself, skip stack - // frames until past the root GC stack frame. The root GC stack - // frame is marked by a sentinel, which is a box pointer stored on - // the stack. - let mut reached_sentinel = ptr::is_null(sentinel); - do walk_stack |frame| { - let pc = last_ret; - let Segment {segment: next_segment, boundary: boundary} = - find_segment_for_frame(frame.fp, segment); - segment = next_segment; - // Each stack segment is bounded by a morestack frame. The - // morestack frame includes two return addresses, one for - // morestack itself, at the normal offset from the frame - // pointer, and then a second return address for the - // function prologue (which called morestack after - // determining that it had hit the end of the stack). - // Since morestack itself takes two parameters, the offset - // for this second return address is 3 greater than the - // return address for morestack. - let ret_offset = if boundary { 4 } else { 1 }; - last_ret = *ptr::offset(frame.fp, ret_offset as int) as *Word; - - if !ptr::is_null(pc) { - - let mut delay_reached_sentinel = reached_sentinel; - let sp = is_safe_point(pc); - match sp { - Some(sp_info) => { - do walk_safe_point(frame.fp, sp_info) |root, tydesc| { - // Skip roots until we see the sentinel. - if !reached_sentinel && root == sentinel { - delay_reached_sentinel = true; - } - - // Skip null pointers, which can occur when a - // unique pointer has already been freed. - if reached_sentinel && !ptr::is_null(*root) { - if ptr::is_null(tydesc) { - // Root is a generic box. - let refcount = **root; - if mem | task_local_heap != 0 && refcount != -1 { - visitor(root, tydesc); - } else if mem | exchange_heap != 0 && refcount == -1 { - visitor(root, tydesc); - } - } else { - // Root is a non-immediate. - if mem | stack != 0 { - visitor(root, tydesc); - } - } - } - } - } - None => () - } - reached_sentinel = delay_reached_sentinel; - } - } -} - -unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) { - _walk_gc_roots(mem, sentinel, visitor) -} -pub fn gc() { - unsafe { - // Abort when GC is disabled. - if get_safe_point_count() == 0 { - return; - } - - do walk_gc_roots(task_local_heap, ptr::null()) |_root, _tydesc| { - // FIXME(#2997): Walk roots and mark them. - io::stdout().write([46]); // . - } - } -} - -#[cfg(gc)] -fn expect_sentinel() -> bool { true } - -#[cfg(nogc)] -fn expect_sentinel() -> bool { false } - -// Entry point for GC-based cleanup. Walks stack looking for exchange -// heap and stack allocations requiring drop, and runs all -// destructors. -// -// This should only be called from fail!, as it will drop the roots -// which are *live* on the stack, rather than dropping those that are -// dead. -pub fn cleanup_stack_for_failure() { - unsafe { - // Abort when GC is disabled. - if get_safe_point_count() == 0 { - return; - } - - // Leave a sentinel on the stack to mark the current frame. The - // stack walker will ignore any frames above the sentinel, thus - // avoiding collecting any memory being used by the stack walker - // itself. - // - // However, when core itself is not compiled with GC, then none of - // the functions in core will have GC metadata, which means we - // won't be able to find the sentinel root on the stack. In this - // case, we can safely skip the sentinel since we won't find our - // own stack roots on the stack anyway. - let sentinel_box = ~0; - let sentinel: **Word = if expect_sentinel() { - cast::transmute(&sentinel_box) - } else { - ptr::null() - }; - - let mut roots = HashSet::new(); - do walk_gc_roots(need_cleanup, sentinel) |root, tydesc| { - // Track roots to avoid double frees. - if !roots.contains(&*root) { - roots.insert(*root); - - if ptr::is_null(tydesc) { - // FIXME #4420: Destroy this box - // FIXME #4330: Destroy this box - } else { - ((*tydesc).drop_glue)(*root as *i8); - } - } - } - } -} diff --git a/src/libstd/stackwalk.rs b/src/libstd/stackwalk.rs deleted file mode 100644 index cc516fb559ea8..0000000000000 --- a/src/libstd/stackwalk.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[allow(missing_doc)]; - -use cast::transmute; -use unstable::intrinsics; - -pub type Word = uint; - -pub struct Frame { - fp: *Word -} - -pub fn Frame(fp: *Word) -> Frame { - Frame { - fp: fp - } -} - -pub fn walk_stack(visit: &fn(Frame)) { - - debug!("beginning stack walk"); - - do frame_address |frame_pointer| { - let mut frame_address: *Word = unsafe { - transmute(frame_pointer) - }; - loop { - let fr = Frame(frame_address); - - debug!("frame: %x", unsafe { transmute(fr.fp) }); - visit(fr); - - unsafe { - let next_fp: **Word = transmute(frame_address); - frame_address = *next_fp; - if *frame_address == 0u { - debug!("encountered task_start_wrapper. ending walk"); - // This is the task_start_wrapper_frame. There is - // no stack beneath it and it is a foreign frame. - break; - } - } - } - } -} - -#[test] -fn test_simple() { - do walk_stack |_frame| { - } -} - -#[test] -fn test_simple_deep() { - fn run(i: int) { - if i == 0 { return } - - do walk_stack |_frame| { - // Would be nice to test something here... - } - run(i - 1); - } - - run(10); -} - -fn frame_address(f: &fn(x: *u8)) { - unsafe { - intrinsics::frame_address(f) - } -} diff --git a/src/libstd/std.rs b/src/libstd/std.rs index 76d65192e01a9..568709c89da73 100644 --- a/src/libstd/std.rs +++ b/src/libstd/std.rs @@ -170,7 +170,6 @@ pub mod local_data; /* Runtime and platform support */ -pub mod gc; pub mod libc; pub mod os; pub mod path; @@ -196,7 +195,6 @@ pub mod unstable; mod unicode; #[path = "num/cmath.rs"] mod cmath; -mod stackwalk; // XXX: This shouldn't be pub, and it should be reexported under 'unstable' // but name resolution doesn't work without it being pub. diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 51609709cdbca..9d853087123e8 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -13,7 +13,6 @@ #[allow(missing_doc)]; use cast; -use gc; use io; use libc; use libc::{c_char, size_t}; @@ -147,7 +146,6 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! { match context { OldTaskContext => { unsafe { - gc::cleanup_stack_for_failure(); rustrt::rust_upcall_fail(msg, file, line); cast::transmute(()) } @@ -180,8 +178,6 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! { msg, file, line as int); } - gc::cleanup_stack_for_failure(); - let task = Local::unsafe_borrow::(); if (*task).unwinder.unwinding { rtabort!("unwinding again"); From 0dcaf0744e99119f265d750bd627052f3d67b928 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Wed, 31 Jul 2013 20:24:35 +0400 Subject: [PATCH 12/62] Additional check in treemap iterator test. --- src/libextra/treemap.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 1736e62aee96b..4e19310f18093 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -983,6 +983,7 @@ mod test_treemap { assert_eq!(*v, n * 2); n += 1; } + assert_eq!(n, 5); } #[test] From 1b54e40fea1dc44790b49cae0631e6f4a3dbd427 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Fri, 2 Aug 2013 00:57:34 +0400 Subject: [PATCH 13/62] Remove redundant print. --- src/libextra/treemap.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 4e19310f18093..12a3553720c40 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -1257,7 +1257,6 @@ mod test_set { let mut n = 0; for x in m.iter() { - printfln!(x); assert_eq!(*x, n); n += 1 } From d946c8c3148d75aeea39cd6dd32a39910bce09d7 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Fri, 2 Aug 2013 00:59:07 +0400 Subject: [PATCH 14/62] Implemented TreeMap::{lower_bound_iter,upper_bound_iter} (issue #4604) --- src/libextra/treemap.rs | 150 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 146 insertions(+), 4 deletions(-) diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 12a3553720c40..487ad050e7864 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -184,7 +184,68 @@ impl TreeMap { /// Get a lazy iterator over the key-value pairs in the map. /// Requires that it be frozen (immutable). pub fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> { - TreeMapIterator{stack: ~[], node: &self.root, remaining: self.length} + TreeMapIterator { + stack: ~[], + node: &self.root, + remaining_min: self.length, + remaining_max: self.length + } + } + + /// Get a lazy iterator that should be initialized using + /// `iter_traverse_left`/`iter_traverse_right`/`iter_traverse_complete`. + fn iter_for_traversal<'a>(&'a self) -> TreeMapIterator<'a, K, V> { + TreeMapIterator { + stack: ~[], + node: &self.root, + remaining_min: 0, + remaining_max: self.length + } + } + + /// Return a lazy iterator to the first key-value pair whose key is not less than `k` + /// If all keys in map are less than `k` an empty iterator is returned. + pub fn lower_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> { + let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal(); + loop { + match *iter.node { + Some(ref r) => { + match k.cmp(&r.key) { + Less => iter_traverse_left(&mut iter), + Greater => iter_traverse_right(&mut iter), + Equal => { + iter_traverse_complete(&mut iter); + return iter; + } + } + } + None => { + iter_traverse_complete(&mut iter); + return iter; + } + } + } + } + + /// Return a lazy iterator to the first key-value pair whose key is greater than `k` + /// If all keys in map are not greater than `k` an empty iterator is returned. + pub fn upper_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> { + let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal(); + loop { + match *iter.node { + Some(ref r) => { + match k.cmp(&r.key) { + Less => iter_traverse_left(&mut iter), + Greater => iter_traverse_right(&mut iter), + Equal => iter_traverse_right(&mut iter) + } + } + None => { + iter_traverse_complete(&mut iter); + return iter; + } + } + } } /// Get a lazy iterator that consumes the treemap. @@ -205,7 +266,8 @@ impl TreeMap { pub struct TreeMapIterator<'self, K, V> { priv stack: ~[&'self ~TreeNode], priv node: &'self Option<~TreeNode>, - priv remaining: uint + priv remaining_min: uint, + priv remaining_max: uint } impl<'self, K, V> Iterator<(&'self K, &'self V)> for TreeMapIterator<'self, K, V> { @@ -222,7 +284,10 @@ impl<'self, K, V> Iterator<(&'self K, &'self V)> for TreeMapIterator<'self, K, V None => { let res = self.stack.pop(); self.node = &res.right; - self.remaining -= 1; + self.remaining_max -= 1; + if self.remaining_min > 0 { + self.remaining_min -= 1; + } return Some((&res.key, &res.value)); } } @@ -232,7 +297,46 @@ impl<'self, K, V> Iterator<(&'self K, &'self V)> for TreeMapIterator<'self, K, V #[inline] fn size_hint(&self) -> (uint, Option) { - (self.remaining, Some(self.remaining)) + (self.remaining_min, Some(self.remaining_max)) + } +} + +/// iter_traverse_left, iter_traverse_right and iter_traverse_complete are used to +/// initialize TreeMapIterator pointing to element inside tree structure. +/// +/// They should be used in following manner: +/// - create iterator using TreeMap::iter_for_traversal +/// - find required node using `iter_traverse_left`/`iter_traverse_right` +/// (current node is `TreeMapIterator::node` field) +/// - complete initialization with `iter_traverse_complete` +#[inline] +fn iter_traverse_left<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) { + let node = it.node.get_ref(); + it.stack.push(node); + it.node = &node.left; +} + +#[inline] +fn iter_traverse_right<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) { + it.node = &(it.node.get_ref().right); +} + +/// iter_traverse_left, iter_traverse_right and iter_traverse_complete are used to +/// initialize TreeMapIterator pointing to element inside tree structure. +/// +/// Completes traversal. Should be called before using iterator. +/// Iteration will start from `self.node`. +/// If `self.node` is None iteration will start from last node from which we +/// traversed left. +#[inline] +fn iter_traverse_complete<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) { + static none: Option<~TreeNode> = None; + match *it.node { + Some(ref n) => { + it.stack.push(n); + it.node = &none; + } + None => () } } @@ -417,6 +521,20 @@ impl TreeSet { TreeSetIterator{iter: self.map.iter()} } + /// Get a lazy iterator pointing to the first value not less than `v` (greater or equal). + /// If all elements in the set are less than `v` empty iterator is returned. + #[inline] + pub fn lower_bound_iter<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> { + TreeSetIterator{iter: self.map.lower_bound_iter(v)} + } + + /// Get a lazy iterator pointing to the first value greater than `v`. + /// If all elements in the set are not greater than `v` empty iterator is returned. + #[inline] + pub fn upper_bound_iter<'a>(&'a self, v: &T) -> TreeSetIterator<'a, T> { + TreeSetIterator{iter: self.map.upper_bound_iter(v)} + } + /// Visit all values in reverse order #[inline] pub fn each_reverse(&self, f: &fn(&T) -> bool) -> bool { @@ -986,6 +1104,30 @@ mod test_treemap { assert_eq!(n, 5); } + #[test] + fn test_interval_iteration() { + let mut m = TreeMap::new(); + for i in range(1, 100) { + assert!(m.insert(i * 2, i * 4)); + } + + for i in range(1, 198) { + let mut lb_it = m.lower_bound_iter(&i); + let (&k, &v) = lb_it.next().unwrap(); + let lb = i + i % 2; + assert_eq!(lb, k); + assert_eq!(lb * 2, v); + + let mut ub_it = m.upper_bound_iter(&i); + let (&k, &v) = ub_it.next().unwrap(); + let ub = i + 2 - i % 2; + assert_eq!(ub, k); + assert_eq!(ub * 2, v); + } + let mut end_it = m.lower_bound_iter(&199); + assert_eq!(end_it.next(), None); + } + #[test] fn test_each_reverse() { let mut m = TreeMap::new(); From f338e04872cdf54dae80d1f1685da19569f3ec4f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 21 May 2013 16:34:41 -0700 Subject: [PATCH 15/62] Try to fix a periodic windows build failure due to broken rwildcard macro --- mk/llvm.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mk/llvm.mk b/mk/llvm.mk index 77b6b4d96f362..12ccc55d4fae1 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -14,7 +14,9 @@ LLVM_DEPS := $(S)/.gitmodules else # This is just a rough approximation of LLVM deps -LLVM_DEPS=$(call rwildcard,$(CFG_LLVM_SRC_DIR),*cpp *hpp) +LLVM_DEPS_SRC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/lib,*cpp *hpp) +LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)/include,*cpp *hpp) +LLVM_DEPS=$(LLVM_DEPS_SRC) $(LLVM_DEPS_INC) endif define DEF_LLVM_RULES From 017740def863ad575311ad61dc6ff5fe12bcb63d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 24 May 2013 00:43:59 -0500 Subject: [PATCH 16/62] Update LLVM --- .gitmodules | 2 +- src/llvm | 2 +- src/rustllvm/llvm-auto-clean-trigger | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index c84426161796d..88ead6e608d5c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/llvm"] path = src/llvm - url = https://github.com/brson/llvm.git + url = https://github.com/alexcrichton/llvm.git branch = master [submodule "src/libuv"] path = src/libuv diff --git a/src/llvm b/src/llvm index 2e9f0d21fe321..e3abef3eedc8d 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 +Subproject commit e3abef3eedc8d5bad3420c7e29bf2fe80585316a diff --git a/src/rustllvm/llvm-auto-clean-trigger b/src/rustllvm/llvm-auto-clean-trigger index 9b8f0e3a46214..670eebbed1327 100644 --- a/src/rustllvm/llvm-auto-clean-trigger +++ b/src/rustllvm/llvm-auto-clean-trigger @@ -1,4 +1,4 @@ # If this file is modified, then llvm will be forcibly cleaned and then rebuilt. # The actual contents of this file do not matter, but to trigger a change on the # build bots then the contents should be changed so git updates the mtime. -2013-07-03 +2013-07-04 From afd12bf59d3cae36b328bbe38d301904b4714ffb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 25 May 2013 17:23:12 -0500 Subject: [PATCH 17/62] Fix build issues once LLVM has been upgraded * LLVM now has a C interface to LLVMBuildAtomicRMW * The exception handling support for the JIT seems to have been dropped * Various interfaces have been added or headers have changed --- src/librustc/back/passes.rs | 1 - src/librustc/lib/llvm.rs | 3 ++- src/librustc/middle/trans/builder.rs | 2 +- src/rustllvm/RustWrapper.cpp | 11 +---------- src/rustllvm/rustllvm.h | 2 ++ 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/librustc/back/passes.rs b/src/librustc/back/passes.rs index 714e7d666ac38..b77ed10c21ba4 100644 --- a/src/librustc/back/passes.rs +++ b/src/librustc/back/passes.rs @@ -97,7 +97,6 @@ pub fn create_standard_passes(level: OptLevel) -> ~[~str] { passes.push(~"sroa"); passes.push(~"domtree"); passes.push(~"early-cse"); - passes.push(~"simplify-libcalls"); passes.push(~"lazy-value-info"); passes.push(~"jump-threading"); passes.push(~"correlated-propagation"); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 6c631a104aa9f..842746f8209ee 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1541,7 +1541,8 @@ pub mod llvm { Op: AtomicBinOp, LHS: ValueRef, RHS: ValueRef, - Order: AtomicOrdering) + Order: AtomicOrdering, + SingleThreaded: Bool) -> ValueRef; pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering); diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index d876b4d0b1673..1d821e5af94bd 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -940,7 +940,7 @@ impl Builder { dst: ValueRef, src: ValueRef, order: AtomicOrdering) -> ValueRef { unsafe { - llvm::LLVMBuildAtomicRMW(self.llbuilder, op, dst, src, order) + llvm::LLVMBuildAtomicRMW(self.llbuilder, op, dst, src, order, False) } } diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index beaa7e1daef9c..04c062072d6cb 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -113,6 +113,7 @@ class RustMCJITMemoryManager : public JITMemoryManager { virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, bool isReadOnly); + bool finalizeMemory(std::string *ErrMsg) { return false; } virtual bool applyPermissions(std::string *Str); @@ -340,7 +341,6 @@ LLVMRustBuildJIT(void* mem, std::string Err; TargetOptions Options; - Options.JITExceptionHandling = true; Options.JITEmitDebugInfo = true; Options.NoFramePointerElim = true; Options.EnableSegmentedStacks = EnableSegmentedStacks; @@ -516,15 +516,6 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) { return wrap(unwrap(B)->CreateFence(order)); } -extern "C" LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, - AtomicRMWInst::BinOp op, - LLVMValueRef target, - LLVMValueRef source, - AtomicOrdering order) { - return wrap(unwrap(B)->CreateAtomicRMW(op, - unwrap(target), unwrap(source), - order)); -} extern "C" void LLVMSetDebug(int Enabled) { #ifndef NDEBUG diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index d4202abd2854e..eeefb19883eb3 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/InlineAsm.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/Linker.h" #include "llvm/PassManager.h" #include "llvm/IR/InlineAsm.h" From 59e8672995185e6c923b8f20e737b93d1015a4bb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 25 May 2013 21:26:08 -0500 Subject: [PATCH 18/62] Fix setting the fixed stack segment attribute on LLVM functions At the same time create a more robust wrapper to try to prevent this type of issue from cropping up in the future. --- src/librustc/lib/llvm.rs | 67 ++++++++++++++++++------------- src/librustc/middle/trans/base.rs | 41 ++++--------------- 2 files changed, 45 insertions(+), 63 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 842746f8209ee..5ec439ce386c5 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -59,35 +59,35 @@ pub enum Linkage { #[deriving(Clone)] pub enum Attribute { - ZExtAttribute = 1, - SExtAttribute = 2, - NoReturnAttribute = 4, - InRegAttribute = 8, - StructRetAttribute = 16, - NoUnwindAttribute = 32, - NoAliasAttribute = 64, - ByValAttribute = 128, - NestAttribute = 256, - ReadNoneAttribute = 512, - ReadOnlyAttribute = 1024, - NoInlineAttribute = 2048, - AlwaysInlineAttribute = 4096, - OptimizeForSizeAttribute = 8192, - StackProtectAttribute = 16384, - StackProtectReqAttribute = 32768, - // 31 << 16 - AlignmentAttribute = 2031616, - NoCaptureAttribute = 2097152, - NoRedZoneAttribute = 4194304, - NoImplicitFloatAttribute = 8388608, - NakedAttribute = 16777216, - InlineHintAttribute = 33554432, - // 7 << 26 - StackAttribute = 469762048, - ReturnsTwiceAttribute = 536870912, - // 1 << 30 - UWTableAttribute = 1073741824, - NonLazyBindAttribute = 2147483648, + ZExtAttribute = 1 << 0, + SExtAttribute = 1 << 1, + NoReturnAttribute = 1 << 2, + InRegAttribute = 1 << 3, + StructRetAttribute = 1 << 4, + NoUnwindAttribute = 1 << 5, + NoAliasAttribute = 1 << 6, + ByValAttribute = 1 << 7, + NestAttribute = 1 << 8, + ReadNoneAttribute = 1 << 9, + ReadOnlyAttribute = 1 << 10, + NoInlineAttribute = 1 << 11, + AlwaysInlineAttribute = 1 << 12, + OptimizeForSizeAttribute = 1 << 13, + StackProtectAttribute = 1 << 14, + StackProtectReqAttribute = 1 << 15, + AlignmentAttribute = 31 << 16, + NoCaptureAttribute = 1 << 21, + NoRedZoneAttribute = 1 << 22, + NoImplicitFloatAttribute = 1 << 23, + NakedAttribute = 1 << 24, + InlineHintAttribute = 1 << 25, + StackAttribute = 7 << 26, + ReturnsTwiceAttribute = 1 << 29, + UWTableAttribute = 1 << 30, + NonLazyBindAttribute = 1 << 31, + + // Not added to LLVM yet, so may need to stay updated if LLVM changes. + FixedStackSegment = 1 << 41, } // enum for the LLVM IntPredicate type @@ -2107,6 +2107,15 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef { llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2) } } + +pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { + unsafe { + let attr = attr as u64; + let lower = attr & 0xffffffff; + let upper = (attr >> 32) & 0xffffffff; + llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); + } +} /* Memory-managed object interface to type handles. */ pub struct TypeNames { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index f41c0adf0bd30..54f56b1c353d3 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -419,46 +419,25 @@ pub fn get_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { } pub fn set_optimize_for_size(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::OptimizeForSizeAttribute - as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::OptimizeForSizeAttribute) } pub fn set_no_inline(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::NoInlineAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::NoInlineAttribute) } pub fn set_no_unwind(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::NoUnwindAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::NoUnwindAttribute) } // Tell LLVM to emit the information necessary to unwind the stack for the // function f. pub fn set_uwtable(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::UWTableAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::UWTableAttribute) } pub fn set_inline_hint(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::InlineHintAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute) } pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute], @@ -473,17 +452,11 @@ pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute], } pub fn set_always_inline(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, - lib::llvm::AlwaysInlineAttribute as c_uint, - 0); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute) } pub fn set_fixed_stack_segment(f: ValueRef) { - unsafe { - llvm::LLVMAddFunctionAttr(f, 0, 1 << (39 - 32)); - } + lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment) } pub fn set_glue_inlining(f: ValueRef, t: ty::t) { From 0ebf15cd48e677cfb08c5df9b2026793f956373e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 1 Aug 2013 15:47:09 -0700 Subject: [PATCH 19/62] Add a workaround for 8199 for now --- src/librustc/lib/llvm.rs | 13 +++++++++++++ src/librustc/middle/trans/base.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 5ec439ce386c5..40fe9bd5fc6a1 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -87,6 +87,8 @@ pub enum Attribute { NonLazyBindAttribute = 1 << 31, // Not added to LLVM yet, so may need to stay updated if LLVM changes. + // FIXME(#8199): if this changes, be sure to change the relevant constant + // down below FixedStackSegment = 1 << 41, } @@ -2116,6 +2118,17 @@ pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); } } + +// FIXME(#8199): this shouldn't require this hackery. On i686 +// (FixedStackSegment as u64) will return 0 instead of 1 << 41. +// Furthermore, if we use a match of any sort then an LLVM +// assertion is generated! +pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) { + let attr = 1u64 << 41; + let lower = attr & 0xffffffff; + let upper = (attr >> 32) & 0xffffffff; + llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); +} /* Memory-managed object interface to type handles. */ pub struct TypeNames { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 54f56b1c353d3..0a28da5f88a7c 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -456,7 +456,7 @@ pub fn set_always_inline(f: ValueRef) { } pub fn set_fixed_stack_segment(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment) + lib::llvm::SetFixedStackSegmentAttribute(f); } pub fn set_glue_inlining(f: ValueRef, t: ty::t) { From 1e39db871c55aef7b595edd0068e9362a18d925b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 2 Aug 2013 00:55:49 -0700 Subject: [PATCH 20/62] Integrate new arm patch and fix an LLVM bug Thanks @luqama! --- src/librustc/lib/llvm.rs | 4 +++- src/llvm | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 40fe9bd5fc6a1..356cdaf754eeb 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -89,7 +89,7 @@ pub enum Attribute { // Not added to LLVM yet, so may need to stay updated if LLVM changes. // FIXME(#8199): if this changes, be sure to change the relevant constant // down below - FixedStackSegment = 1 << 41, + // FixedStackSegment = 1 << 41, } // enum for the LLVM IntPredicate type @@ -2124,10 +2124,12 @@ pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) { // Furthermore, if we use a match of any sort then an LLVM // assertion is generated! pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) { + unsafe { let attr = 1u64 << 41; let lower = attr & 0xffffffff; let upper = (attr >> 32) & 0xffffffff; llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint); + } } /* Memory-managed object interface to type handles. */ diff --git a/src/llvm b/src/llvm index e3abef3eedc8d..f67442eee27d3 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit e3abef3eedc8d5bad3420c7e29bf2fe80585316a +Subproject commit f67442eee27d3d075a65cf7f9a70f7ec6649ffd1 From e6dd0eaf439113e735167308be24ab8f2cb94384 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 4 Aug 2013 16:10:19 -0400 Subject: [PATCH 21/62] Fixed str::raw::push_byte It was previously pushing the byte on top of the string's null terminator. I added a test to make sure it doesn't break in the future. --- src/libstd/str.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 5c6895fea43c9..1a913fb4e996a 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -902,7 +902,7 @@ pub mod raw { let new_len = s.len() + 1; s.reserve_at_least(new_len); do s.as_mut_buf |buf, len| { - *ptr::mut_offset(buf, len as int) = b; + *ptr::mut_offset(buf, (len-1) as int) = b; } set_len(&mut *s, new_len); } @@ -2825,6 +2825,13 @@ mod tests { assert!(!" _ ".is_whitespace()); } + #[test] + fn test_push_byte() { + let mut s = ~"ABC"; + unsafe{raw::push_byte(&mut s, 'D' as u8)}; + assert_eq!(s, ~"ABCD"); + } + #[test] fn test_shift_byte() { let mut s = ~"ABC"; From 9eaeacd21719a6d6a71fd52792faf3b408eda454 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Aug 2013 17:39:59 -0700 Subject: [PATCH 22/62] std::rt: Improve the error message when the thread-local ptr is null Also fix some incorrect comments and variable names. --- src/libstd/rt/local_ptr.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index cd7c5daa444d7..652e39b05c7e0 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -52,7 +52,9 @@ pub unsafe fn put(sched: ~T) { pub unsafe fn take() -> ~T { let key = tls_key(); let void_ptr: *mut c_void = tls::get(key); - rtassert!(void_ptr.is_not_null()); + if void_ptr.is_null() { + rtabort!("thread-local pointer is null. bogus!"); + } let ptr: ~T = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); return ptr; @@ -68,8 +70,8 @@ pub fn exists() -> bool { } } -/// Borrow the thread-local scheduler from thread-local storage. -/// While the scheduler is borrowed it is not available in TLS. +/// Borrow the thread-local value from thread-local storage. +/// While the value is borrowed it is not available in TLS. /// /// # Safety note /// @@ -88,21 +90,23 @@ pub unsafe fn borrow(f: &fn(&mut T)) { } } -/// Borrow a mutable reference to the thread-local Scheduler +/// Borrow a mutable reference to the thread-local value /// /// # Safety Note /// -/// Because this leaves the Scheduler in thread-local storage it is possible +/// Because this leaves the value in thread-local storage it is possible /// For the Scheduler pointer to be aliased pub unsafe fn unsafe_borrow() -> *mut T { let key = tls_key(); - let mut void_sched: *mut c_void = tls::get(key); - rtassert!(void_sched.is_not_null()); + let mut void_ptr: *mut c_void = tls::get(key); + if void_ptr.is_null() { + rtabort!("thread-local pointer is null. bogus!"); + } { - let sched: *mut *mut c_void = &mut void_sched; - let sched: *mut ~T = sched as *mut ~T; - let sched: *mut T = &mut **sched; - return sched; + let ptr: *mut *mut c_void = &mut void_ptr; + let ptr: *mut ~T = ptr as *mut ~T; + let ptr: *mut T = &mut **ptr; + return ptr; } } From c589924a889b3a8bbe5ec4badea35c544cdb833d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Aug 2013 17:40:29 -0700 Subject: [PATCH 23/62] std::rt: Run the tests for Local in a bare thread Otherwise interferes with the existing runtime --- src/libstd/rt/local.rs | 81 +++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 7ab63233cff2f..131507196b1f2 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -126,6 +126,7 @@ impl Local for IoFactoryObject { #[cfg(test)] mod test { + use unstable::run_in_bare_thread; use rt::test::*; use super::*; use rt::task::Task; @@ -133,56 +134,64 @@ mod test { #[test] fn thread_local_task_smoke_test() { - local_ptr::init_tls_key(); - let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, || {}); - Local::put(task); - let task: ~Task = Local::take(); - cleanup_task(task); + do run_in_bare_thread { + local_ptr::init_tls_key(); + let mut sched = ~new_test_uv_sched(); + let task = ~Task::new_root(&mut sched.stack_pool, || {}); + Local::put(task); + let task: ~Task = Local::take(); + cleanup_task(task); + } } #[test] fn thread_local_task_two_instances() { - local_ptr::init_tls_key(); - let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, || {}); - Local::put(task); - let task: ~Task = Local::take(); - cleanup_task(task); - let task = ~Task::new_root(&mut sched.stack_pool, || {}); - Local::put(task); - let task: ~Task = Local::take(); - cleanup_task(task); + do run_in_bare_thread { + local_ptr::init_tls_key(); + let mut sched = ~new_test_uv_sched(); + let task = ~Task::new_root(&mut sched.stack_pool, || {}); + Local::put(task); + let task: ~Task = Local::take(); + cleanup_task(task); + let task = ~Task::new_root(&mut sched.stack_pool, || {}); + Local::put(task); + let task: ~Task = Local::take(); + cleanup_task(task); + } } #[test] fn borrow_smoke_test() { - local_ptr::init_tls_key(); - let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, || {}); - Local::put(task); - - unsafe { - let _task: *mut Task = Local::unsafe_borrow(); + do run_in_bare_thread { + local_ptr::init_tls_key(); + let mut sched = ~new_test_uv_sched(); + let task = ~Task::new_root(&mut sched.stack_pool, || {}); + Local::put(task); + + unsafe { + let _task: *mut Task = Local::unsafe_borrow(); + } + let task: ~Task = Local::take(); + cleanup_task(task); } - let task: ~Task = Local::take(); - cleanup_task(task); } #[test] fn borrow_with_return() { - local_ptr::init_tls_key(); - let mut sched = ~new_test_uv_sched(); - let task = ~Task::new_root(&mut sched.stack_pool, || {}); - Local::put(task); - - let res = do Local::borrow:: |_task| { - true - }; - assert!(res) - let task: ~Task = Local::take(); - cleanup_task(task); + do run_in_bare_thread { + local_ptr::init_tls_key(); + let mut sched = ~new_test_uv_sched(); + let task = ~Task::new_root(&mut sched.stack_pool, || {}); + Local::put(task); + + let res = do Local::borrow:: |_task| { + true + }; + assert!(res) + let task: ~Task = Local::take(); + cleanup_task(task); + } } } From d5c4733a90f1f2ef6dfccd5f033ae20ca2998dc0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Aug 2013 23:28:47 -0700 Subject: [PATCH 24/62] std::rt: 3MB stacks! rustc needs *even more* megabytes when run without optimizations --- src/libstd/rt/task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index abafe1cf209c7..ffe9f118b477c 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -303,7 +303,7 @@ impl Task { impl Drop for Task { fn drop(&self) { rtdebug!("called drop for a task: %u", borrow::to_uint(self)); - assert!(self.destroyed) + rtassert!(self.destroyed) } } @@ -313,7 +313,7 @@ impl Drop for Task { impl Coroutine { pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine { - static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack + static MIN_STACK_SIZE: uint = 3000000; // XXX: Too much stack let start = Coroutine::build_start_wrapper(start); let mut stack = stack_pool.take_segment(MIN_STACK_SIZE); From e4080f6cb313293fba3c7510984b899cb00bdbaa Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Aug 2013 23:29:21 -0700 Subject: [PATCH 25/62] std::rt: Don't allow schedulers to exit before handling all messages Every time run_sched_once performs a 'scheduling action' it needs to guarantee that it runs at least one more time, so enqueue another run_sched_once callback. The primary reason it needs to do this is because not all async callbacks are guaranteed to run, it's only guaranteed that *a* callback will run after enqueing one - some may get dropped. At the moment this means we wastefully create lots of callbacks to ensure that there will *definitely* be a callback queued up to continue running the scheduler. The logic really needs to be tightened up here. --- src/libstd/rt/sched.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 18cfeade157db..a5c8abc2a6c0e 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -172,6 +172,10 @@ impl Scheduler { rtdebug!("stopping scheduler %u", stask.sched.get_ref().sched_id()); + // Should not have any messages + let message = stask.sched.get_mut_ref().message_queue.pop(); + assert!(message.is_none()); + stask.destroyed = true; } @@ -336,11 +340,14 @@ impl Scheduler { match this.message_queue.pop() { Some(PinnedTask(task)) => { let mut task = task; + this.event_loop.callback(Scheduler::run_sched_once); task.give_home(Sched(this.make_handle())); this.resume_task_immediately(task); return None; } Some(TaskFromFriend(task)) => { + this.event_loop.callback(Scheduler::run_sched_once); + rtdebug!("got a task from a friend. lovely!"); return this.sched_schedule_task(task); } Some(Wake) => { @@ -395,6 +402,7 @@ impl Scheduler { /// Take a non-homed task we aren't allowed to run here and send /// it to the designated friend scheduler to execute. fn send_to_friend(&mut self, task: ~Task) { + rtdebug!("sending a task to friend"); match self.friend_handle { Some(ref mut handle) => { handle.send(TaskFromFriend(task)); @@ -426,12 +434,14 @@ impl Scheduler { Scheduler::send_task_home(task); return Some(this); } else { + this.event_loop.callback(Scheduler::run_sched_once); task.give_home(Sched(home_handle)); this.resume_task_immediately(task); return None; } } AnySched if this.run_anything => { + this.event_loop.callback(Scheduler::run_sched_once); task.give_home(AnySched); this.resume_task_immediately(task); return None; From 5d020d141e6e633d29a1298a8523ad565b9dc8ee Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Aug 2013 23:50:28 -0700 Subject: [PATCH 26/62] std::rt: Remove the test for context() This is no longer testable once newsched is turned on --- src/libstd/rt/mod.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 4cfe0efacfefe..33e83fd904041 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -432,13 +432,3 @@ pub fn context() -> RuntimeContext { pub fn rust_try_get_task() -> *rust_task; } } - -#[test] -fn test_context() { - use unstable::run_in_bare_thread; - - assert_eq!(context(), OldTaskContext); - do run_in_bare_thread { - assert_eq!(context(), GlobalContext); - } -} From 59a581667877a2726f0111d7b020431cede64be8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 00:40:10 -0700 Subject: [PATCH 27/62] Remove old tests and code for `select` Not compatible with newsched --- src/libextra/comm.rs | 9 +-- src/libstd/comm.rs | 110 +------------------------------- src/libstd/pipes.rs | 44 ------------- src/test/run-pass/issue-3176.rs | 39 ----------- 4 files changed, 3 insertions(+), 199 deletions(-) delete mode 100644 src/test/run-pass/issue-3176.rs diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 44581efc6f07b..776e25cac8908 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -18,9 +18,8 @@ Higher level communication abstractions. use std::comm::{GenericChan, GenericSmartChan, GenericPort}; -use std::comm::{Chan, Port, Selectable, Peekable}; +use std::comm::{Chan, Port, Peekable}; use std::comm; -use std::pipes; /// An extension of `pipes::stream` that allows both sending and receiving. pub struct DuplexStream { @@ -75,12 +74,6 @@ impl Peekable for DuplexStream { } } -impl Selectable for DuplexStream { - fn header(&mut self) -> *mut pipes::PacketHeader { - self.port.header() - } -} - /// Creates a bidirectional stream. pub fn DuplexStream() -> (DuplexStream, DuplexStream) diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index a0731dc3494c2..4356f1143da46 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -14,7 +14,6 @@ Message passing #[allow(missing_doc)]; -use cast::transmute; use either::{Either, Left, Right}; use kinds::Send; use option::{Option, Some}; @@ -23,12 +22,6 @@ pub use rt::comm::SendDeferred; use rtcomm = rt::comm; use rt; -use pipes::{wait_many, PacketHeader}; - -// FIXME #5160: Making this public exposes some plumbing from -// pipes. Needs some refactoring -pub use pipes::Selectable; - /// A trait for things that can send multiple messages. pub trait GenericChan { /// Sends a message. @@ -146,15 +139,6 @@ impl Peekable for Port { } } -impl Selectable for Port { - fn header(&mut self) -> *mut PacketHeader { - match self.inner { - Left(ref mut port) => port.header(), - Right(_) => fail!("can't select on newsched ports") - } - } -} - /// A channel that can be shared between many senders. pub struct SharedChan { inner: Either>, rtcomm::SharedChan> @@ -318,8 +302,8 @@ mod pipesy { use kinds::Send; use option::{Option, Some, None}; - use pipes::{recv, try_recv, peek, PacketHeader}; - use super::{GenericChan, GenericSmartChan, GenericPort, Peekable, Selectable}; + use pipes::{recv, try_recv, peek}; + use super::{GenericChan, GenericSmartChan, GenericPort, Peekable}; use cast::transmute_mut; /*proto! oneshot ( @@ -651,80 +635,6 @@ mod pipesy { } } - impl Selectable for Port { - fn header(&mut self) -> *mut PacketHeader { - match self.endp { - Some(ref mut endp) => endp.header(), - None => fail!("peeking empty stream") - } - } -} - -} - -/// Returns the index of an endpoint that is ready to receive. -pub fn selecti(endpoints: &mut [T]) -> uint { - wait_many(endpoints) -} - -/// Returns 0 or 1 depending on which endpoint is ready to receive -pub fn select2i(a: &mut A, b: &mut B) - -> Either<(), ()> { - let mut endpoints = [ a.header(), b.header() ]; - match wait_many(endpoints) { - 0 => Left(()), - 1 => Right(()), - _ => fail!("wait returned unexpected index"), - } -} - -/// Receive a message from one of two endpoints. -pub trait Select2 { - /// Receive a message or return `None` if a connection closes. - fn try_select(&mut self) -> Either, Option>; - /// Receive a message or fail if a connection closes. - fn select(&mut self) -> Either; -} - -impl, - Right:Selectable + GenericPort> - Select2 - for (Left, Right) { - fn select(&mut self) -> Either { - // XXX: Bad borrow check workaround. - unsafe { - let this: &(Left, Right) = transmute(self); - match *this { - (ref lp, ref rp) => { - let lp: &mut Left = transmute(lp); - let rp: &mut Right = transmute(rp); - match select2i(lp, rp) { - Left(()) => Left(lp.recv()), - Right(()) => Right(rp.recv()), - } - } - } - } - } - - fn try_select(&mut self) -> Either, Option> { - // XXX: Bad borrow check workaround. - unsafe { - let this: &(Left, Right) = transmute(self); - match *this { - (ref lp, ref rp) => { - let lp: &mut Left = transmute(lp); - let rp: &mut Right = transmute(rp); - match select2i(lp, rp) { - Left(()) => Left (lp.try_recv()), - Right(()) => Right(rp.try_recv()), - } - } - } - } - } } #[cfg(test)] @@ -732,22 +642,6 @@ mod test { use either::Right; use super::{Chan, Port, oneshot, stream}; - #[test] - fn test_select2() { - let (p1, c1) = stream(); - let (p2, c2) = stream(); - - c1.send(~"abc"); - - let mut tuple = (p1, p2); - match tuple.select() { - Right(_) => fail!(), - _ => (), - } - - c2.send(123); - } - #[test] fn test_oneshot() { let (p, c) = oneshot(); diff --git a/src/libstd/pipes.rs b/src/libstd/pipes.rs index 1fd534825a544..78f937e058a41 100644 --- a/src/libstd/pipes.rs +++ b/src/libstd/pipes.rs @@ -868,47 +868,3 @@ pub mod rt { pub fn make_some(val: T) -> Option { Some(val) } pub fn make_none() -> Option { None } } - -#[cfg(test)] -mod test { - use either::Right; - use comm::{Chan, Port, oneshot, recv_one, stream, Select2, - GenericChan, Peekable}; - - #[test] - fn test_select2() { - let (p1, c1) = stream(); - let (p2, c2) = stream(); - - c1.send(~"abc"); - - let mut tuple = (p1, p2); - match tuple.select() { - Right(_) => fail!(), - _ => (), - } - - c2.send(123); - } - - #[test] - fn test_oneshot() { - let (p, c) = oneshot(); - - c.send(()); - - recv_one(p) - } - - #[test] - fn test_peek_terminated() { - let (port, chan): (Port, Chan) = stream(); - - { - // Destroy the channel - let _chan = chan; - } - - assert!(!port.peek()); - } -} diff --git a/src/test/run-pass/issue-3176.rs b/src/test/run-pass/issue-3176.rs deleted file mode 100644 index df242ee3d3059..0000000000000 --- a/src/test/run-pass/issue-3176.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-fast -// xfail-win32 #7999 - -use std::comm::{Select2, Selectable}; -use std::comm; -use std::task; - -pub fn main() { - let (p,c) = comm::stream(); - do task::try || { - let (p2,c2) = comm::stream(); - do task::spawn || { - p2.recv(); - error!("sibling fails"); - fail!(); - } - let (p3,c3) = comm::stream(); - c.send(c3); - c2.send(()); - error!("child blocks"); - let (p, c) = comm::stream(); - let mut tuple = (p, p3); - tuple.select(); - c.send(()); - }; - error!("parent tries"); - assert!(!p.recv().try_send(())); - error!("all done!"); -} From b14b77a5b1c3242a1f101ccf0b4f5f3a9a3fa620 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 4 Aug 2013 18:21:29 -0400 Subject: [PATCH 28/62] fix warning still mentioning the `again` keyword --- src/librustc/middle/check_loop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index fb12f97c50cb0..cbd1d3cd9ad81 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -52,7 +52,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: &Crate) { } expr_again(_) => { if !cx.in_loop { - tcx.sess.span_err(e.span, "`again` outside of loop"); + tcx.sess.span_err(e.span, "`loop` outside of loop"); } } expr_ret(oe) => { From eabb4faf2bf8230211b16b836092da9fe42bbf17 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Mon, 5 Aug 2013 02:26:38 +0400 Subject: [PATCH 29/62] Implemented iterator for TrieMap Closes #5506. --- src/libstd/trie.rs | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 679d36b87f18e..93a11bdea98d5 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -14,6 +14,7 @@ use prelude::*; use iterator::{IteratorUtil, FromIterator, Extendable}; use uint; use util::{swap, replace}; +use vec; // FIXME: #5244: need to manually update the TrieNode constructor static SHIFT: uint = 4; @@ -146,6 +147,15 @@ impl TrieMap { pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool { self.each_reverse(|_, v| f(v)) } + + /// Get an iterator over the key-value pairs in the map + pub fn iter<'a>(&'a self) -> TrieMapIterator<'a, T> { + TrieMapIterator { + stack: ~[self.root.children.iter()], + remaining_min: self.length, + remaining_max: self.length + } + } } impl> FromIterator<(uint, T), Iter> for TrieMap { @@ -217,6 +227,12 @@ impl TrieSet { pub fn each_reverse(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key_reverse(f) } + + /// Get an iterator over the values in the set + #[inline] + pub fn iter<'a>(&'a self) -> TrieSetIterator<'a> { + TrieSetIterator{iter: self.map.iter()} + } } impl> FromIterator for TrieSet { @@ -366,6 +382,61 @@ fn remove(count: &mut uint, child: &mut Child, key: uint, return ret; } +/// Forward iterator over a map +pub struct TrieMapIterator<'self, T> { + priv stack: ~[vec::VecIterator<'self, Child>], + priv remaining_min: uint, + priv remaining_max: uint +} + +impl<'self, T> Iterator<(uint, &'self T)> for TrieMapIterator<'self, T> { + fn next(&mut self) -> Option<(uint, &'self T)> { + while !self.stack.is_empty() { + match self.stack[self.stack.len() - 1].next() { + None => { + self.stack.pop(); + } + Some(ref child) => { + match **child { + Internal(ref node) => { + self.stack.push(node.children.iter()); + } + External(key, ref value) => { + self.remaining_max -= 1; + if self.remaining_min > 0 { + self.remaining_min -= 1; + } + return Some((key, value)); + } + Nothing => {} + } + } + } + } + return None; + } + + #[inline] + fn size_hint(&self) -> (uint, Option) { + (self.remaining_min, Some(self.remaining_max)) + } +} + +/// Forward iterator over a set +pub struct TrieSetIterator<'self> { + priv iter: TrieMapIterator<'self, ()> +} + +impl<'self> Iterator for TrieSetIterator<'self> { + fn next(&mut self) -> Option { + do self.iter.next().map |&(key, _)| { key } + } + + fn size_hint(&self) -> (uint, Option) { + self.iter.size_hint() + } +} + #[cfg(test)] pub fn check_integrity(trie: &TrieNode) { assert!(trie.count != 0); @@ -553,6 +624,31 @@ mod test_map { assert_eq!(map.find(&k), Some(&v)); } } + + #[test] + fn test_iteration() { + let empty_map : TrieMap = TrieMap::new(); + assert_eq!(empty_map.iter().next(), None); + + let first = uint::max_value - 10000; + let last = uint::max_value; + + let mut map = TrieMap::new(); + do uint::range_rev(last, first) |x| { + printfln!("%x", x); + map.insert(x, x / 2); + true + }; + + let mut i = 0; + for (k, &v) in map.iter() { + printfln!("%x", k); + assert_eq!(k, first + i); + assert_eq!(v, k / 2); + i += 1; + } + assert_eq!(i, last - first); + } } #[cfg(test)] From a2207689e2b265898cbc2540a981b73a4d2ddf20 Mon Sep 17 00:00:00 2001 From: Dmitry Ermolov Date: Mon, 5 Aug 2013 02:51:43 +0400 Subject: [PATCH 30/62] Remove debug printing. --- src/libstd/trie.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 93a11bdea98d5..6f61d29780f04 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -635,14 +635,12 @@ mod test_map { let mut map = TrieMap::new(); do uint::range_rev(last, first) |x| { - printfln!("%x", x); map.insert(x, x / 2); true }; let mut i = 0; for (k, &v) in map.iter() { - printfln!("%x", k); assert_eq!(k, first + i); assert_eq!(v, k / 2); i += 1; From 0a686b3427f4ad661fdb4ec96790017bb629784b Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 1 Aug 2013 06:39:37 -0400 Subject: [PATCH 31/62] Add support for vanilla linux on arm. --- mk/platform.mk | 36 ++++++++++++++++++++++++++++++----- src/librustc/driver/driver.rs | 2 +- src/rt/arch/arm/record_sp.S | 14 ++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/mk/platform.mk b/mk/platform.mk index 61a170c21d51e..6ee5420664d8e 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -241,7 +241,7 @@ CFG_RUN_TARG_i686-apple-darwin=$(call CFG_RUN_i686-apple-darwin,,$(2)) # arm-linux-androideabi configuration CC_arm-linux-androideabi=$(CFG_ANDROID_CROSS_PATH)/bin/arm-linux-androideabi-gcc CXX_arm-linux-androideabi=$(CFG_ANDROID_CROSS_PATH)/bin/arm-linux-androideabi-g++ -CPP_arm-linux-androideabi=$(CFG_ANDROID_CROSS_PATH)/bin/arm-linux-androideabi-gcc +CPP_arm-linux-androideabi=$(CFG_ANDROID_CROSS_PATH)/bin/arm-linux-androideabi-gcc -E AR_arm-linux-androideabi=$(CFG_ANDROID_CROSS_PATH)/bin/arm-linux-androideabi-ar CFG_LIB_NAME_arm-linux-androideabi=lib$(1).so CFG_LIB_GLOB_arm-linux-androideabi=lib$(1)-*.so @@ -272,7 +272,7 @@ AR_arm-unknown-linux-gnueabihf=arm-linux-gnueabihf-ar CFG_LIB_NAME_arm-unknown-linux-gnueabihf=lib$(1).so CFG_LIB_GLOB_arm-unknown-linux-gnueabihf=lib$(1)-*.so CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabihf=lib$(1)-*.dylib.dSYM -CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabihf := -Wall -g -fPIC +CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabihf := -Wall -g -fPIC -D__arm__ CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabihf := -fno-rtti CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabihf := -shared -fPIC -g CFG_GCCISH_DEF_FLAG_arm-unknown-linux-gnueabihf := -Wl,--export-dynamic,--dynamic-list= @@ -290,6 +290,32 @@ CFG_RUN_arm-unknown-linux-gnueabihf= CFG_RUN_TARG_arm-unknown-linux-gnueabihf= RUSTC_FLAGS_arm-unknown-linux-gnueabihf := --linker=$(CC_arm-unknown-linux-gnueabihf) +# arm-unknown-linux-gnueabi configuration +CC_arm-unknown-linux-gnueabi=arm-linux-gnueabi-gcc +CXX_arm-unknown-linux-gnueabi=arm-linux-gnueabi-g++ +CPP_arm-unknown-linux-gnueabi=arm-linux-gnueabi-gcc -E +AR_arm-unknown-linux-gnueabi=arm-linux-gnueabi-ar +CFG_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).so +CFG_LIB_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.so +CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.dylib.dSYM +CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -D__arm__ +CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabi := -fno-rtti +CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabi := -shared -fPIC -g +CFG_GCCISH_DEF_FLAG_arm-unknown-linux-gnueabi := -Wl,--export-dynamic,--dynamic-list= +CFG_GCCISH_PRE_LIB_FLAGS_arm-unknown-linux-gnueabi := -Wl,-whole-archive +CFG_GCCISH_POST_LIB_FLAGS_arm-unknown-linux-gnueabi := -Wl,-no-whole-archive +CFG_DEF_SUFFIX_arm-unknown-linux-gnueabi := .linux.def +CFG_INSTALL_NAME_ar,-unknown-linux-gnueabi = +CFG_LIBUV_LINK_FLAGS_arm-unknown-linux-gnueabi = +CFG_EXE_SUFFIX_arm-unknown-linux-gnueabi := +CFG_WINDOWSY_arm-unknown-linux-gnueabi := +CFG_UNIXY_arm-unknown-linux-gnueabi := 1 +CFG_PATH_MUNGE_arm-unknown-linux-gnueabi := true +CFG_LDPATH_arm-unknown-linux-gnueabi := +CFG_RUN_arm-unknown-linux-gnueabi= +CFG_RUN_TARG_arm-unknown-linux-gnueabi= +RUSTC_FLAGS_arm-unknown-linux-gnueabi := --linker=$(CC_arm-unknown-linux-gnueabi) + # mips-unknown-linux-gnu configuration CC_mips-unknown-linux-gnu=mips-linux-gnu-gcc CXX_mips-unknown-linux-gnu=mips-linux-gnu-g++ @@ -450,7 +476,7 @@ define CFG_MAKE_TOOLCHAIN $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \ $$(call CFG_INSTALL_NAME_$(1),$$(4)) - ifneq ($(1),arm-linux-androideabi) + ifneq ($(HOST_$(1)),arm) # We're using llvm-mc as our assembler because it supports # .cfi pseudo-ops on mac @@ -462,9 +488,9 @@ define CFG_MAKE_TOOLCHAIN -o=$$(1) else - # For the Android cross, use the Android assembler + # For the ARM crosses, use the toolchain assembler # XXX: We should be able to use the LLVM assembler - CFG_ASSEMBLE_$(1)=$$(CPP_$(1)) $$(CFG_DEPEND_FLAGS) $$(2) -c -o $$(1) + CFG_ASSEMBLE_$(1)=$$(CC_$(1)) $$(CFG_DEPEND_FLAGS) $$(2) -c -o $$(1) endif diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1c983057dba0f..ea679d19f73b8 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -335,7 +335,7 @@ pub fn phase_5_run_llvm_passes(sess: Session, outputs: &OutputFilenames) { // NB: Android hack - if sess.targ_cfg.arch == abi::Arm && + if sess.targ_cfg.os == session::os_android && (sess.opts.output_type == link::output_type_object || sess.opts.output_type == link::output_type_exe) { let output_type = link::output_type_assembly; diff --git a/src/rt/arch/arm/record_sp.S b/src/rt/arch/arm/record_sp.S index 8d5f24bc5a8c5..3c5c7644bebf7 100644 --- a/src/rt/arch/arm/record_sp.S +++ b/src/rt/arch/arm/record_sp.S @@ -14,22 +14,36 @@ .globl get_sp record_sp_limit: + // First, try to read TLS address from coprocessor mrc p15, #0, r3, c13, c0, #3 + cmp r3, #0 + // Otherwise, try to read from magic address 0xFFFF0FF0 + mvneq r3, #0xF000 + ldreq r3, [r3, #-15] + #if __ANDROID__ add r3, r3, #252 #elif __linux__ add r3, r3, #4 #endif + str r0, [r3] mov pc, lr get_sp_limit: + // First, try to read TLS address from coprocessor mrc p15, #0, r3, c13, c0, #3 + cmp r3, #0 + // Otherwise, try to read from magic address 0xFFFF0FF0 + mvneq r3, #0xF000 + ldreq r3, [r3, #-15] + #if __ANDROID__ add r3, r3, #252 #elif __linux__ add r3, r3, #4 #endif + ldr r0, [r3] mov pc, lr From f10e934ae572448fdb04724f0b72cf07a95d5fa0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 18:38:06 -0700 Subject: [PATCH 32/62] extra: Don't recurse in DList drop glue. #8295 The compiler-generated dtor for DList recurses deeply to drop Nodes. For big lists this can overflow the stack. --- src/libextra/dlist.rs | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 4142bdadaf63e..75487a44f2600 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -92,6 +92,11 @@ impl Rawlink { Some(unsafe { cast::transmute(self.p) }) } } + + /// Return the `Rawlink` and replace with `Rawlink::none()` + fn take(&mut self) -> Rawlink { + util::replace(self, Rawlink::none()) + } } impl Clone for Rawlink { @@ -280,13 +285,16 @@ impl DList { /// Add all elements from `other` to the end of the list /// /// O(1) - pub fn append(&mut self, other: DList) { + pub fn append(&mut self, mut other: DList) { match self.list_tail.resolve() { None => *self = other, Some(tail) => { - match other { - DList{list_head: None, _} => return, - DList{list_head: Some(node), list_tail: o_tail, length: o_length} => { + // Carefully empty `other`. + let o_tail = other.list_tail.take(); + let o_length = other.length; + match other.list_head.take() { + None => return, + Some(node) => { tail.next = link_with_prev(node, self.list_tail); self.list_tail = o_tail; self.length += o_length; @@ -404,6 +412,32 @@ impl DList { } } +#[unsafe_destructor] +impl Drop for DList { + fn drop(&self) { + let mut_self = unsafe { + cast::transmute_mut(self) + }; + // Dissolve the dlist in backwards direction + // Just dropping the list_head can lead to stack exhaustion + // when length is >> 1_000_000 + let mut tail = mut_self.list_tail; + loop { + match tail.resolve() { + None => break, + Some(prev) => { + prev.next.take(); // release ~Node + tail = prev.prev; + } + } + } + mut_self.length = 0; + mut_self.list_head = None; + mut_self.list_tail = Rawlink::none(); + } +} + + impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> { #[inline] fn next(&mut self) -> Option<&'self A> { From 9624c20d4ac761ec699ab2dd7472ce8693fe938b Mon Sep 17 00:00:00 2001 From: darkf Date: Sun, 4 Aug 2013 21:54:24 -0700 Subject: [PATCH 33/62] Open files in binary mode. Closes #3948 --- src/libstd/io.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/io.rs b/src/libstd/io.rs index f750f3f3195e7..55e60f03ea9c6 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1041,7 +1041,7 @@ pub fn stdin() -> @Reader { pub fn file_reader(path: &Path) -> Result<@Reader, ~str> { let f = do path.to_str().as_c_str |pathbuf| { - do "r".as_c_str |modebuf| { + do "rb".as_c_str |modebuf| { unsafe { libc::fopen(pathbuf, modebuf as *libc::c_char) } } }; From 92aa473b26651c47532120acd6aaf6c317bd4920 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 21:54:59 -0700 Subject: [PATCH 34/62] std: Fix newsched logging truncation The truncation needs to be done in the console logger in order to catch all the logging output, and because truncation only matters when outputting to the console. --- src/libstd/logging.rs | 10 ---------- src/libstd/rt/logging.rs | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index c662e5997afa6..6e11d14aea9a3 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -85,16 +85,6 @@ pub fn log_type(level: u32, object: &T) { fn newsched_log_str(msg: ~str) { use rt::task::Task; use rt::local::Local; - use str::StrSlice; - use container::Container; - - // Truncate the string - let buf_bytes = 256; - let msg = if msg.len() > buf_bytes { - msg.slice(0, buf_bytes) + "[...]" - } else { - msg - }; unsafe { match Local::try_unsafe_borrow::() { diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 11d11daebc254..9056f0d52e09a 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -10,6 +10,7 @@ use either::*; use libc; +use str::StrSlice; pub trait Logger { fn log(&mut self, msg: Either<~str, &'static str>); @@ -35,10 +36,22 @@ impl Logger for StdErrLogger { s } }; - let dbg = ::libc::STDERR_FILENO as ::io::fd_t; - dbg.write_str(s); - dbg.write_str("\n"); - dbg.flush(); + + // Truncate the string + let buf_bytes = 256; + if s.len() > buf_bytes { + let s = s.slice(0, buf_bytes) + "[...]"; + print(s); + } else { + print(s) + }; + + fn print(s: &str) { + let dbg = ::libc::STDERR_FILENO as ::io::fd_t; + dbg.write_str(s); + dbg.write_str("\n"); + dbg.flush(); + } } } From 8ce8dfe4e3200bf40237fab78390842faac7f251 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 21:55:52 -0700 Subject: [PATCH 35/62] std::rt: Schedule more scheduler callbacks to avoid dropping messages --- src/libstd/rt/sched.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index a5c8abc2a6c0e..1a75f2569b59e 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -339,8 +339,8 @@ impl Scheduler { let mut this = self; match this.message_queue.pop() { Some(PinnedTask(task)) => { - let mut task = task; this.event_loop.callback(Scheduler::run_sched_once); + let mut task = task; task.give_home(Sched(this.make_handle())); this.resume_task_immediately(task); return None; @@ -351,10 +351,12 @@ impl Scheduler { return this.sched_schedule_task(task); } Some(Wake) => { + this.event_loop.callback(Scheduler::run_sched_once); this.sleepy = false; return Some(this); } Some(Shutdown) => { + this.event_loop.callback(Scheduler::run_sched_once); if this.sleepy { // There may be an outstanding handle on the // sleeper list. Pop them all to make sure that's From 8949610a9e8867bb237a38ce5ecf6fc0f8c4d56a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 5 Aug 2013 00:32:46 -0700 Subject: [PATCH 36/62] std::rt: Use magic to make TLS work from annihilated boxes. #8302 --- src/libstd/rt/task.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index ffe9f118b477c..cb949edd7bb4a 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -228,6 +228,19 @@ impl Task { _ => () } + // FIXME #8302: Dear diary. I'm so tired and confused. + // There's some interaction in rustc between the box + // annihilator and the TLS dtor by which TLS is + // accessed from annihilated box dtors *after* TLS is + // destroyed. Somehow setting TLS back to null, as the + // old runtime did, makes this work, but I don't currently + // understand how. I would expect that, if the annihilator + // reinvokes TLS while TLS is uninitialized, that + // TLS would be reinitialized but never destroyed, + // but somehow this works. I have no idea what's going + // on but this seems to make things magically work. FML. + self.storage = LocalStorage(ptr::null(), None); + // Destroy remaining boxes. Also may run user dtors. unsafe { cleanup::annihilate(); } } From b74e3e77965409c2d59fc631333f32cde394f4ef Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Mon, 5 Aug 2013 17:43:40 +0900 Subject: [PATCH 37/62] Add extra::arena::Arena::new{, _with_size}. Signed-off-by: OGINO Masanori --- src/libextra/arena.rs | 46 ++++++++++++------------ src/test/bench/shootout-binarytrees.rs | 8 ++--- src/test/run-pass/placement-new-arena.rs | 4 +-- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 47b64d7695168..ae4356eb4bacc 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -67,17 +67,16 @@ pub struct Arena { priv chunks: @mut MutList, } -#[unsafe_destructor] -impl Drop for Arena { - fn drop(&self) { - unsafe { - destroy_chunk(&self.head); - do self.chunks.each |chunk| { - if !chunk.is_pod { - destroy_chunk(chunk); - } - true - }; +impl Arena { + pub fn new() -> Arena { + Arena::new_with_size(32u) + } + + pub fn new_with_size(initial_size: uint) -> Arena { + Arena { + head: chunk(initial_size, false), + pod_head: chunk(initial_size, true), + chunks: @mut MutNil, } } } @@ -92,18 +91,21 @@ fn chunk(size: uint, is_pod: bool) -> Chunk { } } -pub fn arena_with_size(initial_size: uint) -> Arena { - Arena { - head: chunk(initial_size, false), - pod_head: chunk(initial_size, true), - chunks: @mut MutNil, +#[unsafe_destructor] +impl Drop for Arena { + fn drop(&self) { + unsafe { + destroy_chunk(&self.head); + do self.chunks.each |chunk| { + if !chunk.is_pod { + destroy_chunk(chunk); + } + true + }; + } } } -pub fn Arena() -> Arena { - arena_with_size(32u) -} - #[inline] fn round_up_to(base: uint, align: uint) -> uint { (base + (align - 1)) & !(align - 1) @@ -276,7 +278,7 @@ impl Arena { #[test] fn test_arena_destructors() { - let arena = Arena(); + let arena = Arena::new(); for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it // doesn't leak. @@ -291,7 +293,7 @@ fn test_arena_destructors() { #[should_fail] #[ignore(cfg(windows))] fn test_arena_destructors_fail() { - let arena = Arena(); + let arena = Arena::new(); // Put some stuff in the arena. for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 596a5b5422a5d..57bf33fb2fdac 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -9,7 +9,7 @@ // except according to those terms. extern mod extra; -use extra::arena; +use extra::arena::Arena; enum Tree<'self> { Nil, @@ -25,7 +25,7 @@ fn item_check(t: &Tree) -> int { } } -fn bottom_up_tree<'r>(arena: &'r arena::Arena, item: int, depth: int) +fn bottom_up_tree<'r>(arena: &'r Arena, item: int, depth: int) -> &'r Tree<'r> { if depth > 0 { return arena.alloc( @@ -57,7 +57,7 @@ fn main() { max_depth = n; } - let stretch_arena = arena::Arena(); + let stretch_arena = Arena::new(); let stretch_depth = max_depth + 1; let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth); @@ -65,7 +65,7 @@ fn main() { stretch_depth, item_check(stretch_tree)); - let long_lived_arena = arena::Arena(); + let long_lived_arena = Arena::new(); let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth); let mut depth = min_depth; while depth <= max_depth { diff --git a/src/test/run-pass/placement-new-arena.rs b/src/test/run-pass/placement-new-arena.rs index 9500f83b76b09..f2063b583e4f9 100644 --- a/src/test/run-pass/placement-new-arena.rs +++ b/src/test/run-pass/placement-new-arena.rs @@ -11,10 +11,10 @@ // except according to those terms. extern mod extra; -use extra::arena; +use extra::arena::Arena; pub fn main() { - let mut arena = arena::Arena(); + let mut arena = Arena::new(); let p = &mut arena; let x = p.alloc(|| 4u); printf!("%u", *x); From 987ad253f131487e099aed107221c3a0a6251ed0 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Mon, 5 Aug 2013 17:52:03 +0200 Subject: [PATCH 38/62] std: Use correct lifetime parameter on str::raw::slice_bytes fn slice_bytes is marked unsafe since it allows violating the valid string encoding property; but the function did also allow extending the lifetime of the slice by mistake, since it's returning `&str`. Use the annotation `slice_bytes<'a>(&'a str, ...) -> &'a str` so that all uses of slice_bytes are region checked correctly. --- src/libstd/str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 1a913fb4e996a..e43b58174bb56 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -885,7 +885,7 @@ pub mod raw { /// If begin is greater than end. /// If end is greater than the length of the string. #[inline] - pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str { + pub unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str { do s.as_imm_buf |sbuf, n| { assert!((begin <= end)); assert!((end <= n)); From d28f85a4f0cbe43eddf96c968e6687776487b891 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Mon, 29 Jul 2013 13:44:53 -0700 Subject: [PATCH 39/62] Make node_id_to_str print more useful info in some cases. Closes #2410. --- src/libsyntax/ast_map.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 5cba22a8e2375..6b4da9671a963 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -466,11 +466,11 @@ pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str { Some(&node_local(ident)) => { fmt!("local (id=%?, name=%s)", id, itr.get(ident.name)) } - Some(&node_block(_)) => { - fmt!("block") + Some(&node_block(ref block)) => { + fmt!("block %s (id=%?)", pprust::block_to_str(block, itr), id) } - Some(&node_struct_ctor(*)) => { - fmt!("struct_ctor") + Some(&node_struct_ctor(_, _, path)) => { + fmt!("struct_ctor %s (id=%?)", path_to_str(*path, itr), id) } } } From 411435335be5674db191285277910da13dd61ad8 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Mon, 29 Jul 2013 14:19:04 -0700 Subject: [PATCH 40/62] Fix an unused variable warning and clean up some dead code/names. --- src/librustc/middle/trans/base.rs | 30 ++++++++++------------------ src/librustc/middle/trans/foreign.rs | 2 +- src/libsyntax/ast_util.rs | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0a28da5f88a7c..6b35f4ae9a4ee 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2218,23 +2218,14 @@ pub fn trans_mod(ccx: @mut CrateContext, m: &ast::_mod) { pub fn register_fn(ccx: @mut CrateContext, sp: span, sym: ~str, - node_id: ast::NodeId) - -> ValueRef { - let t = ty::node_id_to_type(ccx.tcx, node_id); - register_fn_full(ccx, sp, sym, node_id, t) -} - -pub fn register_fn_full(ccx: @mut CrateContext, - sp: span, - sym: ~str, - node_id: ast::NodeId, - node_type: ty::t) - -> ValueRef { + node_id: ast::NodeId, + node_type: ty::t) + -> ValueRef { let llfty = type_of_fn_from_ty(ccx, node_type); - register_fn_fuller(ccx, sp, sym, node_id, lib::llvm::CCallConv, llfty) + register_fn_llvmty(ccx, sp, sym, node_id, lib::llvm::CCallConv, llfty) } -pub fn register_fn_fuller(ccx: @mut CrateContext, +pub fn register_fn_llvmty(ccx: @mut CrateContext, sp: span, sym: ~str, node_id: ast::NodeId, @@ -2449,7 +2440,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { ast::item_fn(_, purity, _, _, _) => { let llfn = if purity != ast::extern_fn { - register_fn_full(ccx, i.span, sym, i.id, ty) + register_fn(ccx, i.span, sym, i.id, ty) } else { foreign::register_foreign_fn(ccx, i.span, sym, i.id) }; @@ -2499,7 +2490,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { let path = vec::append((*pth).clone(), [path_name(ni.ident)]); let sym = exported_name(ccx, path, ty, ni.attrs); - register_fn_full(ccx, ni.span, sym, ni.id, ty) + register_fn(ccx, ni.span, sym, ni.id, ty) } ast::foreign_item_static(*) => { let ident = token::ident_to_str(&ni.ident); @@ -2527,7 +2518,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { llfn = match enm.node { ast::item_enum(_, _) => { - register_fn_full(ccx, (*v).span, sym, id, ty) + register_fn(ccx, (*v).span, sym, id, ty) } _ => fail!("node_variant, shouldn't happen") }; @@ -2551,7 +2542,8 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { let ty = ty::node_id_to_type(ccx.tcx, ctor_id); let sym = exported_name(ccx, (*struct_path).clone(), ty, struct_item.attrs); - let llfn = register_fn_full(ccx, struct_item.span, sym, ctor_id, ty); + let llfn = register_fn(ccx, struct_item.span, + sym, ctor_id, ty); set_inline_hint(llfn); llfn } @@ -2586,7 +2578,7 @@ pub fn register_method(ccx: @mut CrateContext, let sym = exported_name(ccx, path, mty, m.attrs); - let llfn = register_fn_full(ccx, m.span, sym, id, mty); + let llfn = register_fn(ccx, m.span, sym, id, mty); set_inline_hint_if_appr(m.attrs, llfn); llfn } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 20c8e69129d74..ede2292725cc9 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -1157,6 +1157,6 @@ pub fn register_foreign_fn(ccx: @mut CrateContext, let tys = shim_types(ccx, node_id); do tys.fn_ty.decl_fn |fnty| { - register_fn_fuller(ccx, sp, sym.take(), node_id, lib::llvm::CCallConv, fnty) + register_fn_llvmty(ccx, sp, sym.take(), node_id, lib::llvm::CCallConv, fnty) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 11d3740be3f51..84e6544f78092 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -410,7 +410,7 @@ impl IdVisitor { impl Visitor<()> for IdVisitor { fn visit_mod(@mut self, module: &_mod, - span: span, + _span: span, node_id: NodeId, env: ()) { (self.visit_callback)(node_id); From 8a421ec85578506ec597e3f1c8c3d2a299bbc975 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 30 Jul 2013 15:40:19 -0700 Subject: [PATCH 41/62] Warn when using -o option on libraries. Closes #6554. --- mk/target.mk | 8 ++++---- mk/tools.mk | 8 ++++---- src/librustc/driver/driver.rs | 13 ++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mk/target.mk b/mk/target.mk index b9221a56b9d85..fce6e8a9e2fcc 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -48,7 +48,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)): \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(STDLIB_GLOB_$(2)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(STDLIB_GLOB_$(2)),$$(notdir $$@)) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \ @@ -58,7 +58,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(EXTRALIB_GLOB_$(2)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(EXTRALIB_GLOB_$(2)),$$(notdir $$@)) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \ @@ -69,7 +69,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@)) # Only build the compiler for host triples @@ -90,7 +90,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@)) $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \ diff --git a/mk/tools.mk b/mk/tools.mk index 56aad4f10a259..32c034d878cb9 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -49,7 +49,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTPKG_$(4)): \ | $$(TLIB$(1)_T_$(4)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTPKG_GLOB_$(4)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(4)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTPKG_GLOB_$(4)),$$(notdir $$@)) $$(TBIN$(1)_T_$(4)_H_$(3))/rustpkg$$(X_$(4)): \ @@ -67,7 +67,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTDOC_$(4)): \ | $$(TLIB$(1)_T_$(4)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTDOC_GLOB_$(4)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTDOC_GLOB_$(4)),$$(notdir $$@)) $$(TBIN$(1)_T_$(4)_H_$(3))/rustdoc$$(X_$(4)): \ @@ -85,7 +85,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTI_$(4)): \ | $$(TLIB$(1)_T_$(4)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTI_GLOB_$(4)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTI_GLOB_$(4)),$$(notdir $$@)) $$(TBIN$(1)_T_$(4)_H_$(3))/rusti$$(X_$(4)): \ @@ -106,7 +106,7 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUST_$(4)): \ | $$(TLIB$(1)_T_$(4)_H_$(3))/ @$$(call E, compile_and_link: $$@) $$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUST_GLOB_$(4)),$$(notdir $$@)) - $$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(4)_H_$(3)) --out-dir $$(@D) $$< && touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUST_GLOB_$(4)),$$(notdir $$@)) $$(TBIN$(1)_T_$(4)_H_$(3))/rust$$(X_$(4)): \ diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index ea679d19f73b8..3daacf38036ae 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -408,11 +408,10 @@ pub fn stop_after_phase_5(sess: Session) -> bool { #[fixed_stack_segment] pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input, outdir: &Option, output: &Option) { - let outputs = build_output_filenames(input, outdir, output, [], sess); // We need nested scopes here, because the intermediate results can keep // large chunks of memory alive and we want to free them as soon as // possible to keep the peak memory usage low - let trans = { + let (outputs, trans) = { let expanded_crate = { let crate = phase_1_parse_input(sess, cfg.clone(), input); if stop_after_phase_1(sess) { return; } @@ -420,7 +419,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input, }; let analysis = phase_3_run_analysis_passes(sess, expanded_crate); if stop_after_phase_3(sess) { return; } - phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs) + let outputs = build_output_filenames(input, outdir, output, [], sess); + let trans = phase_4_translate_to_llvm(sess, expanded_crate, + &analysis, outputs); + (outputs, trans) }; phase_5_run_llvm_passes(sess, &trans, outputs); if stop_after_phase_5(sess) { return; } @@ -957,10 +959,7 @@ pub fn build_output_filenames(input: &input, }; if *sess.building_library { - // FIXME (#2401): We might want to warn here; we're actually not - // going to respect the user's choice of library name when it - // comes time to link, we'll be linking to - // lib--.so no matter what. + sess.warn("ignoring specified output filename for library."); } if *odir != None { From 6446c828a4b6091f7ff706f8b5284b225a12230a Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 30 Jul 2013 16:47:22 -0700 Subject: [PATCH 42/62] Get rid of some NOTEs. --- src/compiletest/compiletest.rs | 1 - src/librustc/middle/cfg/construct.rs | 2 +- src/libstd/rt/io/flate.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index b01de242590d0..ce715ac2db5ad 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -11,7 +11,6 @@ #[crate_type = "bin"]; #[allow(non_camel_case_types)]; -#[allow(unrecognized_lint)]; // NOTE: remove after snapshot #[deny(warnings)]; extern mod extra; diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index f34b28e1642fc..767c2b4ee2ed7 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -225,7 +225,7 @@ impl CFGBuilder { // Note that `break` and `loop` statements // may cause additional edges. - // NOTE: Is the condition considered part of the loop? + // Is the condition considered part of the loop? let loopback = self.add_dummy_node([pred]); // 1 let cond_exit = self.expr(cond, loopback); // 2 let expr_exit = self.add_node(expr.id, [cond_exit]); // 3 diff --git a/src/libstd/rt/io/flate.rs b/src/libstd/rt/io/flate.rs index e57b80658eef2..cbcc441811de6 100644 --- a/src/libstd/rt/io/flate.rs +++ b/src/libstd/rt/io/flate.rs @@ -10,7 +10,7 @@ //! Some various other I/O types -// NOTE: These ultimately belong somewhere else +// FIXME(#3660): should move to libextra use prelude::*; use super::*; From 0ba3f9199dec77f8f9566cc23d9d8cccef826cd0 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Fri, 2 Aug 2013 10:34:33 -0700 Subject: [PATCH 43/62] Improve debug spew in _match. --- src/librustc/middle/trans/_match.rs | 81 ++++++++++++++--------------- src/librustc/util/ppaux.rs | 10 ++-- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 725beee6604e7..0a008b2215ae5 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -171,6 +171,7 @@ use middle::trans::tvec; use middle::trans::type_of; use middle::ty; use util::common::indenter; +use util::ppaux::{Repr, vec_map_to_str}; use std::hashmap::HashMap; use std::vec; @@ -179,7 +180,6 @@ use syntax::ast::ident; use syntax::ast_util::path_to_ident; use syntax::ast_util; use syntax::codemap::{span, dummy_sp}; -use syntax::print::pprust::pat_to_str; // An option identifying a literal: either a unit-like struct or an // expression. @@ -353,19 +353,17 @@ pub struct Match<'self> { data: ArmData<'self> } -pub fn match_to_str(bcx: @mut Block, m: &Match) -> ~str { - if bcx.sess().verbose() { - // for many programs, this just take too long to serialize - fmt!("%?", m.pats.map(|p| pat_to_str(*p, bcx.sess().intr()))) - } else { - fmt!("%u pats", m.pats.len()) +impl<'self> Repr for Match<'self> { + fn repr(&self, tcx: ty::ctxt) -> ~str { + if tcx.sess.verbose() { + // for many programs, this just take too long to serialize + self.pats.repr(tcx) + } else { + fmt!("%u pats", self.pats.len()) + } } } -pub fn matches_to_str(bcx: @mut Block, m: &[Match]) -> ~str { - fmt!("%?", m.map(|n| match_to_str(bcx, n))) -} - pub fn has_nested_bindings(m: &[Match], col: uint) -> bool { for br in m.iter() { match br.pats[col].node { @@ -381,9 +379,9 @@ pub fn expand_nested_bindings<'r>(bcx: @mut Block, col: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("expand_nested_bindings(bcx=%s, m=%s, col=%u, val=%?)", + debug!("expand_nested_bindings(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -416,7 +414,7 @@ pub fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::pat) { bcx.sess().span_bug( p.span, fmt!("Expected an identifier pattern but found p: %s", - pat_to_str(p, bcx.sess().intr()))); + p.repr(bcx.tcx()))); } } @@ -429,9 +427,9 @@ pub fn enter_match<'r>(bcx: @mut Block, val: ValueRef, e: enter_pat) -> ~[Match<'r>] { - debug!("enter_match(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_match(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -467,7 +465,7 @@ pub fn enter_match<'r>(bcx: @mut Block, } } - debug!("result=%s", matches_to_str(bcx, result)); + debug!("result=%s", result.repr(bcx.tcx())); return result; } @@ -478,9 +476,9 @@ pub fn enter_default<'r>(bcx: @mut Block, col: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_default(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_default(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -525,9 +523,9 @@ pub fn enter_opt<'r>(bcx: @mut Block, variant_size: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_opt(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_opt(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -637,9 +635,9 @@ pub fn enter_rec_or_struct<'r>(bcx: @mut Block, fields: &[ast::ident], val: ValueRef) -> ~[Match<'r>] { - debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -672,9 +670,9 @@ pub fn enter_tup<'r>(bcx: @mut Block, val: ValueRef, n_elts: uint) -> ~[Match<'r>] { - debug!("enter_tup(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_tup(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -698,9 +696,9 @@ pub fn enter_tuple_struct<'r>(bcx: @mut Block, val: ValueRef, n_elts: uint) -> ~[Match<'r>] { - debug!("enter_tuple_struct(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_tuple_struct(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -723,9 +721,9 @@ pub fn enter_box<'r>(bcx: @mut Block, col: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_box(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_box(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -750,9 +748,9 @@ pub fn enter_uniq<'r>(bcx: @mut Block, col: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_uniq(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_uniq(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -777,9 +775,9 @@ pub fn enter_region<'r>(bcx: @mut Block, col: uint, val: ValueRef) -> ~[Match<'r>] { - debug!("enter_region(bcx=%s, m=%s, col=%u, val=%?)", + debug!("enter_region(bcx=%s, m=%s, col=%u, val=%s)", bcx.to_str(), - matches_to_str(bcx, m), + m.repr(bcx.tcx()), col, bcx.val_to_str(val)); let _indenter = indenter(); @@ -1213,11 +1211,11 @@ pub fn compile_guard(bcx: @mut Block, vals: &[ValueRef], chk: Option) -> @mut Block { - debug!("compile_guard(bcx=%s, guard_expr=%s, m=%s, vals=%?)", + debug!("compile_guard(bcx=%s, guard_expr=%s, m=%s, vals=%s)", bcx.to_str(), bcx.expr_to_str(guard_expr), - matches_to_str(bcx, m), - vals.map(|v| bcx.val_to_str(*v))); + m.repr(bcx.tcx()), + vec_map_to_str(vals, |v| bcx.val_to_str(*v))); let _indenter = indenter(); let mut bcx = bcx; @@ -1267,10 +1265,10 @@ pub fn compile_submatch(bcx: @mut Block, m: &[Match], vals: &[ValueRef], chk: Option) { - debug!("compile_submatch(bcx=%s, m=%s, vals=%?)", + debug!("compile_submatch(bcx=%s, m=%s, vals=%s)", bcx.to_str(), - matches_to_str(bcx, m), - vals.map(|v| bcx.val_to_str(*v))); + m.repr(bcx.tcx()), + vec_map_to_str(vals, |v| bcx.val_to_str(*v))); let _indenter = indenter(); /* @@ -1427,6 +1425,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, // Decide what kind of branch we need let opts = get_options(bcx, m, col); + debug!("options=%?", opts); let mut kind = no_branch; let mut test_val = val; if opts.len() > 0u { @@ -1914,12 +1913,12 @@ fn bind_irrefutable_pat(bcx: @mut Block, debug!("bind_irrefutable_pat(bcx=%s, pat=%s, binding_mode=%?)", bcx.to_str(), - pat_to_str(pat, bcx.sess().intr()), + pat.repr(bcx.tcx()), binding_mode); if bcx.sess().asm_comments() { add_comment(bcx, fmt!("bind_irrefutable_pat(pat=%s)", - pat_to_str(pat, bcx.sess().intr()))); + pat.repr(bcx.tcx()))); } let _indenter = indenter(); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8f0dd51457074..f396ed7f510a6 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -280,9 +280,13 @@ pub fn vstore_ty_to_str(cx: ctxt, mt: &mt, vs: ty::vstore) -> ~str { } } +pub fn vec_map_to_str(ts: &[T], f: &fn(t: &T) -> ~str) -> ~str { + let tstrs = ts.map(f); + fmt!("[%s]", tstrs.connect(", ")) +} + pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str { - let tstrs = ts.map(|t| ty_to_str(cx, *t)); - fmt!("(%s)", tstrs.connect(", ")) + vec_map_to_str(ts, |t| ty_to_str(cx, *t)) } pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str { @@ -529,7 +533,7 @@ impl Repr for ~T { } fn repr_vec(tcx: ctxt, v: &[T]) -> ~str { - fmt!("[%s]", v.map(|t| t.repr(tcx)).connect(",")) + vec_map_to_str(v, |t| t.repr(tcx)) } impl<'self, T:Repr> Repr for &'self [T] { From b204783ebbddf98683cfac10335fd455491d8835 Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Mon, 5 Aug 2013 22:09:34 +0200 Subject: [PATCH 44/62] adjust error message to coding style --- src/libextra/ebml.rs | 4 +- src/libextra/terminfo/parser/compiled.rs | 8 +-- src/librustc/metadata/tydecode.rs | 4 +- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/ty.rs | 56 +++++++-------- src/librustc/middle/typeck/astconv.rs | 2 +- src/librustc/middle/typeck/check/_match.rs | 14 ++-- src/librustc/middle/typeck/check/mod.rs | 23 +++--- src/librustc/middle/typeck/check/vtable.rs | 2 +- src/librustc/middle/typeck/infer/doc.rs | 2 +- .../middle/typeck/infer/error_reporting.rs | 4 +- src/librustc/middle/typeck/infer/mod.rs | 2 +- src/librustpkg/installed_packages.rs | 2 +- .../testsuite/pass/src/fancy-lib/foo.rs | 2 +- .../testsuite/pass/src/install-paths/bench.rs | 2 +- .../testsuite/pass/src/simple-lib/src/foo.rs | 2 +- src/libstd/num/strconv.rs | 2 +- src/libstd/ops.rs | 2 +- src/libstd/rt/io/mock.rs | 2 +- src/libstd/rt/io/mod.rs | 2 +- src/libstd/rt/io/timer.rs | 2 +- src/libstd/rt/metrics.rs | 2 +- src/libstd/rt/sleeper_list.rs | 2 +- src/libstd/rt/util.rs | 2 +- src/libsyntax/parse/parser.rs | 16 ++--- src/test/compile-fail/bad-bang-ann-3.rs | 2 +- src/test/compile-fail/bad-bang-ann.rs | 2 +- src/test/compile-fail/bad-const-type.rs | 2 +- src/test/compile-fail/bang-tailexpr.rs | 2 +- .../block-must-not-have-result-do.rs | 2 +- .../block-must-not-have-result-res.rs | 2 +- .../block-must-not-have-result-while.rs | 2 +- .../borrowck-alias-mut-base-ptr.rs | 2 +- .../borrowck-anon-fields-struct.rs | 2 +- .../borrowck-anon-fields-tuple.rs | 2 +- .../borrowck-anon-fields-variant.rs | 2 +- .../borrowck-bad-nested-calls-free.rs | 2 +- .../borrowck-bad-nested-calls-move.rs | 2 +- ...ck-borrow-mut-base-ptr-in-aliasable-loc.rs | 2 +- .../borrowck-move-in-irrefut-pat.rs | 2 +- .../borrowck-move-mut-base-ptr.rs | 2 +- .../borrowck-swap-mut-base-ptr.rs | 2 +- .../cast-immutable-mutable-trait.rs | 2 +- .../cast-vector-to-unsafe-nonstatic.rs | 2 +- ...bounds-cant-promote-superkind-in-struct.rs | 2 +- .../closure-bounds-not-builtin.rs | 2 +- .../compile-fail/closure-bounds-subtype.rs | 2 +- src/test/compile-fail/coherence_inherent.rs | 2 +- .../compile-fail/coherence_inherent_cc.rs | 2 +- src/test/compile-fail/deprecated-auto-code.rs | 2 +- .../compile-fail/do-lambda-requires-braces.rs | 2 +- src/test/compile-fail/do1.rs | 2 +- src/test/compile-fail/do2.rs | 2 +- src/test/compile-fail/estr-subtyping.rs | 8 +-- src/test/compile-fail/evec-subtyping.rs | 18 ++--- src/test/compile-fail/extern-no-call.rs | 2 +- .../fully-qualified-type-name2.rs | 2 +- .../fully-qualified-type-name3.rs | 2 +- src/test/compile-fail/if-branch-types.rs | 2 +- .../compile-fail/if-without-else-result.rs | 2 +- .../integer-literal-suffix-inference.rs | 72 +++++++++---------- src/test/compile-fail/issue-2995.rs | 2 +- src/test/compile-fail/issue-3036.rs | 2 +- src/test/compile-fail/issue-3477.rs | 2 +- src/test/compile-fail/issue-3680.rs | 2 +- src/test/compile-fail/issue-4517.rs | 2 +- src/test/compile-fail/issue-4736.rs | 2 +- src/test/compile-fail/issue-4968.rs | 2 +- src/test/compile-fail/issue-5100.rs | 14 ++-- src/test/compile-fail/issue-5358-1.rs | 2 +- src/test/compile-fail/issue-5358.rs | 2 +- src/test/compile-fail/issue-6762.rs | 2 +- .../compile-fail/loop-does-not-diverge.rs | 2 +- src/test/compile-fail/lub-if.rs | 2 +- src/test/compile-fail/lub-match.rs | 2 +- src/test/compile-fail/main-wrong-location.rs | 2 +- src/test/compile-fail/map-types.rs | 2 +- src/test/compile-fail/match-struct.rs | 2 +- src/test/compile-fail/match-vec-mismatch-2.rs | 2 +- src/test/compile-fail/match-vec-mismatch.rs | 2 +- src/test/compile-fail/multitrait.rs | 2 +- src/test/compile-fail/noexporttypeexe.rs | 2 +- .../non-constant-expr-for-vec-repeat.rs | 2 +- .../compile-fail/omitted-arg-in-item-fn.rs | 2 +- .../compile-fail/omitted-arg-wrong-types.rs | 4 +- .../compile-fail/pattern-error-continue.rs | 6 +- src/test/compile-fail/regions-bounds.rs | 4 +- .../regions-free-region-ordering-callee.rs | 2 +- .../regions-free-region-ordering-caller.rs | 2 +- .../regions-infer-paramd-indirect.rs | 2 +- .../regions-infer-paramd-method.rs | 2 +- .../compile-fail/regions-ref-in-fn-arg.rs | 2 +- src/test/compile-fail/regions-trait-3.rs | 2 +- src/test/compile-fail/repeat_count.rs | 2 +- .../compile-fail/struct-base-wrong-type.rs | 4 +- src/test/compile-fail/suppressed-error.rs | 4 +- .../tag-that-dare-not-speak-its-name.rs | 2 +- src/test/compile-fail/tag-variant-disr-dup.rs | 2 +- src/test/compile-fail/terr-in-field.rs | 2 +- src/test/compile-fail/terr-sorts.rs | 2 +- .../trait-impl-method-mismatch.rs | 2 +- src/test/compile-fail/tuple-arity-mismatch.rs | 2 +- .../tutorial-suffix-inference-test.rs | 6 +- src/test/compile-fail/type-parameter-names.rs | 4 +- src/test/debug-info/borrowed-basic.rs | 2 +- src/test/debug-info/borrowed-c-style-enum.rs | 2 +- src/test/debug-info/borrowed-enum.rs | 2 +- src/test/debug-info/borrowed-managed-basic.rs | 2 +- src/test/debug-info/borrowed-struct.rs | 2 +- src/test/debug-info/borrowed-tuple.rs | 2 +- src/test/debug-info/borrowed-unique-basic.rs | 2 +- src/test/debug-info/boxed-struct.rs | 2 +- src/test/debug-info/boxed-vec.rs | 2 +- .../debug-info/c-style-enum-in-composite.rs | 2 +- src/test/debug-info/c-style-enum.rs | 2 +- .../debug-info/destructured-fn-argument.rs | 2 +- src/test/debug-info/destructured-local.rs | 2 +- src/test/debug-info/evec-in-struct.rs | 2 +- src/test/debug-info/function-arguments.rs | 2 +- src/test/debug-info/managed-enum.rs | 2 +- .../managed-pointer-within-unique-vec.rs | 2 +- .../managed-pointer-within-unique.rs | 2 +- src/test/debug-info/nil-enum.rs | 2 +- src/test/debug-info/option-like-enum.rs | 2 +- .../packed-struct-with-destructor.rs | 2 +- src/test/debug-info/packed-struct.rs | 2 +- src/test/debug-info/simple-struct.rs | 2 +- src/test/debug-info/simple-tuple.rs | 2 +- src/test/debug-info/struct-in-struct.rs | 2 +- src/test/debug-info/struct-style-enum.rs | 2 +- src/test/debug-info/tuple-in-struct.rs | 2 +- src/test/debug-info/tuple-in-tuple.rs | 2 +- src/test/debug-info/tuple-style-enum.rs | 2 +- src/test/debug-info/unique-enum.rs | 2 +- .../borrowck-scope-of-deref-issue-4666.rs | 2 +- src/test/run-pass/cast-mutable-trait.rs | 2 +- .../run-pass/conditional-debug-macro-off.rs | 2 +- .../run-pass/conditional-debug-macro-on.rs | 2 +- .../deriving-cmp-generic-struct-enum.rs | 2 +- .../deriving-via-extension-struct-empty.rs | 2 +- src/test/run-pass/enum-vec-initializer.rs | 2 +- ...xternal-iterators-hashmap-break-restart.rs | 2 +- .../foreach-external-iterators-hashmap.rs | 2 +- .../run-pass/foreach-external-iterators.rs | 2 +- .../run-pass/func-arg-incomplete-pattern.rs | 2 +- src/test/run-pass/issue-2804.rs | 4 +- src/test/run-pass/issue-4252.rs | 2 +- .../run-pass/issue-6141-leaking-owned-fn.rs | 2 +- src/test/run-pass/issue-6341.rs | 2 +- src/test/run-pass/move-out-of-field.rs | 2 +- src/test/run-pass/option_addition.rs | 2 +- src/test/run-pass/rt-start-main-thread.rs | 2 +- src/test/run-pass/unique-object-move.rs | 2 +- 153 files changed, 271 insertions(+), 272 deletions(-) diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index f66677c21f7d1..286ebe0b8d036 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -305,7 +305,7 @@ pub mod reader { self.pos = r_doc.end; let str = r_doc.as_str_slice(); if lbl != str { - fail!("Expected label %s but found %s", lbl, str); + fail!("Expected label %s, found %s", lbl, str); } } } @@ -326,7 +326,7 @@ pub mod reader { r_doc.start, r_doc.end); if r_tag != (exp_tag as uint) { - fail!("expected EBML doc with tag %? but found tag %?", exp_tag, r_tag); + fail!("expected EBML doc with tag %?, found tag %?", exp_tag, r_tag); } if r_doc.end > self.parent.end { fail!("invalid EBML, child extends to 0x%x, parent to 0x%x", diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index 426cacb62faad..2604682f2e9a7 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -178,7 +178,7 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { // Check magic number let magic = file.read_le_u16(); if (magic != 0x011A) { - return Err(fmt!("invalid magic number: expected %x but found %x", 0x011A, magic as uint)); + return Err(fmt!("invalid magic number: expected %x, found %x", 0x011A, magic as uint)); } let names_bytes = file.read_le_i16() as int; @@ -196,19 +196,19 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> { debug!("string_table_bytes = %?", string_table_bytes); if (bools_bytes as uint) > boolnames.len() { - error!("expected bools_bytes to be less than %? but found %?", boolnames.len(), + error!("expected bools_bytes to be less than %?, found %?", boolnames.len(), bools_bytes); return Err(~"incompatible file: more booleans than expected"); } if (numbers_count as uint) > numnames.len() { - error!("expected numbers_count to be less than %? but found %?", numnames.len(), + error!("expected numbers_count to be less than %?, found %?", numnames.len(), numbers_count); return Err(~"incompatible file: more numbers than expected"); } if (string_offsets_count as uint) > stringnames.len() { - error!("expected string_offsets_count to be less than %? but found %?", stringnames.len(), + error!("expected string_offsets_count to be less than %?, found %?", stringnames.len(), string_offsets_count); return Err(~"incompatible file: more string offsets than expected"); } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 89b30e46ac06d..a922db55a3156 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -542,12 +542,12 @@ pub fn parse_def_id(buf: &[u8]) -> ast::def_id { let crate_num = match uint::parse_bytes(crate_part, 10u) { Some(cn) => cn as int, - None => fail!("internal error: parse_def_id: crate number expected, but found %?", + None => fail!("internal error: parse_def_id: crate number expected, found %?", crate_part) }; let def_num = match uint::parse_bytes(def_part, 10u) { Some(dn) => dn as int, - None => fail!("internal error: parse_def_id: id expected, but found %?", + None => fail!("internal error: parse_def_id: id expected, found %?", def_part) }; ast::def_id { crate: crate_num, node: def_num } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 0a008b2215ae5..e7441125645d6 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -413,7 +413,7 @@ pub fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::pat) { if !pat_is_binding_or_wild(bcx.tcx().def_map, p) { bcx.sess().span_bug( p.span, - fmt!("Expected an identifier pattern but found p: %s", + fmt!("Expected an identifier pattern, but found p: %s", p.repr(bcx.tcx()))); } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 29b975cdf99f8..923e94eca624d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3389,15 +3389,15 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { match *err { terr_mismatch => ~"types differ", terr_purity_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_abi_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_onceness_mismatch(values) => { - fmt!("expected %s fn but found %s fn", + fmt!("expected %s fn, found %s fn", values.expected.to_str(), values.found.to_str()) } terr_sigil_mismatch(values) => { @@ -3411,25 +3411,25 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { terr_ptr_mutability => ~"pointers differ in mutability", terr_ref_mutability => ~"references differ in mutability", terr_ty_param_size(values) => { - fmt!("expected a type with %? type params \ - but found one with %? type params", + fmt!("expected a type with %? type params, \ + found one with %? type params", values.expected, values.found) } terr_tuple_size(values) => { - fmt!("expected a tuple with %? elements \ - but found one with %? elements", + fmt!("expected a tuple with %? elements, \ + found one with %? elements", values.expected, values.found) } terr_record_size(values) => { - fmt!("expected a record with %? fields \ - but found one with %? fields", + fmt!("expected a record with %? fields, \ + found one with %? fields", values.expected, values.found) } terr_record_mutability => { ~"record elements differ in mutability" } terr_record_fields(values) => { - fmt!("expected a record with field `%s` but found one with field \ + fmt!("expected a record with field `%s`, found one with field \ `%s`", cx.sess.str_of(values.expected), cx.sess.str_of(values.found)) @@ -3446,22 +3446,22 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { } terr_regions_insufficiently_polymorphic(br, _) => { fmt!("expected bound lifetime parameter %s, \ - but found concrete lifetime", + found concrete lifetime", bound_region_ptr_to_str(cx, br)) } terr_regions_overly_polymorphic(br, _) => { fmt!("expected concrete lifetime, \ - but found bound lifetime parameter %s", + found bound lifetime parameter %s", bound_region_ptr_to_str(cx, br)) } terr_vstores_differ(k, ref values) => { - fmt!("%s storage differs: expected %s but found %s", + fmt!("%s storage differs: expected %s, found %s", terr_vstore_kind_to_str(k), vstore_to_str(cx, (*values).expected), vstore_to_str(cx, (*values).found)) } terr_trait_stores_differ(_, ref values) => { - fmt!("trait storage differs: expected %s but found %s", + fmt!("trait storage differs: expected %s, found %s", trait_store_to_str(cx, (*values).expected), trait_store_to_str(cx, (*values).found)) } @@ -3470,38 +3470,38 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { type_err_to_str(cx, err)) } terr_sorts(values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", ty_sort_str(cx, values.expected), ty_sort_str(cx, values.found)) } terr_traits(values) => { - fmt!("expected trait %s but found trait %s", + fmt!("expected trait %s, found trait %s", item_path_str(cx, values.expected), item_path_str(cx, values.found)) } terr_builtin_bounds(values) => { if values.expected.is_empty() { - fmt!("expected no bounds but found `%s`", + fmt!("expected no bounds, found `%s`", values.found.user_string(cx)) } else if values.found.is_empty() { - fmt!("expected bounds `%s` but found no bounds", + fmt!("expected bounds `%s`, found no bounds", values.expected.user_string(cx)) } else { - fmt!("expected bounds `%s` but found bounds `%s`", + fmt!("expected bounds `%s`, found bounds `%s`", values.expected.user_string(cx), values.found.user_string(cx)) } } terr_integer_as_char => { - fmt!("expected an integral type but found char") + fmt!("expected an integral type, found char") } terr_int_mismatch(ref values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", values.expected.to_str(), values.found.to_str()) } terr_float_mismatch(ref values) => { - fmt!("expected %s but found %s", + fmt!("expected %s, found %s", values.expected.to_str(), values.found.to_str()) } @@ -4327,7 +4327,7 @@ pub fn eval_repeat_count(tcx: &T, count_expr: &ast::expr) -> const_eval::const_int(count) => if count < 0 { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found negative integer"); + repeat count, found negative integer"); return 0; } else { return count as uint @@ -4336,26 +4336,26 @@ pub fn eval_repeat_count(tcx: &T, count_expr: &ast::expr) -> const_eval::const_float(count) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found float"); + repeat count, found float"); return count as uint; } const_eval::const_str(_) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found string"); + repeat count, found string"); return 0; } const_eval::const_bool(_) => { tcx.ty_ctxt().sess.span_err(count_expr.span, "expected positive integer for \ - repeat count but found boolean"); + repeat count, found boolean"); return 0; } }, Err(*) => { tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected constant integer for repeat count \ - but found variable"); + "expected constant integer for \ + repeat count, found variable"); return 0; } } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index ebf9d0944c9fb..e1c1ea2c7834b 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -177,7 +177,7 @@ fn ast_path_substs( if !vec::same_length(*decl_generics.type_param_defs, path.types) { this.tcx().sess.span_fatal( path.span, - fmt!("wrong number of type arguments: expected %u but found %u", + fmt!("wrong number of type arguments: expected %u, found %u", decl_generics.type_param_defs.len(), path.types.len())); } let tps = path.types.map(|a_t| ast_ty_to_ty(this, rscope, a_t)); diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 842bbff41e065..85faad6a631d2 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -159,7 +159,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"a structure pattern", None); @@ -202,7 +202,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"an enum or structure pattern", None); @@ -341,7 +341,7 @@ pub fn check_struct_pat(pcx: &pat_ctxt, pat_id: ast::NodeId, span: span, Some(&ast::def_struct(*)) | Some(&ast::def_variant(*)) => { let name = pprust::path_to_str(path, tcx.sess.intr()); tcx.sess.span_err(span, - fmt!("mismatched types: expected `%s` but found `%s`", + fmt!("mismatched types: expected `%s`, found `%s`", fcx.infcx().ty_to_str(expected), name)); } @@ -500,7 +500,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { } _ => { tcx.sess.span_err(pat.span, - fmt!("mismatched types: expected `%s` but found struct", + fmt!("mismatched types: expected `%s`, found struct", fcx.infcx().ty_to_str(expected))); error_happened = true; } @@ -536,7 +536,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { }; fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"tuple", Some(&type_error)); fcx.write_error(pat.id); } @@ -585,7 +585,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { pat.span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), ~"a vector pattern", @@ -643,7 +643,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, span, |expected, actual| { expected.map_default(~"", |e| { - fmt!("mismatched types: expected `%s` but found %s", + fmt!("mismatched types: expected `%s`, found %s", *e, actual)})}, Some(expected), fmt!("%s pattern", match pointer_kind { diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 7f486f77447cb..52731f6dc52db 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1310,7 +1310,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::ty_bool => {} _ => fcx.type_error_message(call_expr.span, |actual| { fmt!("expected `for` closure to return `bool`, \ - but found `%s`", actual) }, + , found `%s`", actual) }, output, None) } ty::mk_nil() @@ -1358,8 +1358,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => sig, _ => { fcx.type_error_message(call_expr.span, |actual| { - fmt!("expected function but \ - found `%s`", actual) }, fn_ty, None); + fmt!("expected function, found `%s`", actual) }, fn_ty, None); &error_fn_sig } }; @@ -2751,7 +2750,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, pub fn require_integral(fcx: @mut FnCtxt, sp: span, t: ty::t) { if !type_is_integral(fcx, sp, t) { fcx.type_error_message(sp, |actual| { - fmt!("mismatched types: expected integral type but found `%s`", + fmt!("mismatched types: expected integral type, found `%s`", actual) }, t, None); } @@ -3131,28 +3130,28 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, ast::def_ty(_) | ast::def_prim_ty(_) | ast::def_ty_param(*)=> { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found type"); } ast::def_mod(*) | ast::def_foreign_mod(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found module"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found module"); } ast::def_use(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found use"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found use"); } ast::def_region(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found region"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found region"); } ast::def_typaram_binder(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found type parameter"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found type parameter"); } ast::def_label(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found label"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found label"); } ast::def_self_ty(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found self ty"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found self ty"); } ast::def_method(*) => { - fcx.ccx.tcx.sess.span_bug(sp, "expected value but found method"); + fcx.ccx.tcx.sess.span_bug(sp, "expected value, found method"); } } } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index abb97f0d1c7b9..456a9026d2dec 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -209,7 +209,7 @@ fn relate_trait_refs(vcx: &VtableContext, let tcx = vcx.tcx(); tcx.sess.span_err( location_info.span, - fmt!("expected %s, but found %s (%s)", + fmt!("expected %s, found %s (%s)", ppaux::trait_ref_to_str(tcx, &r_exp_trait_ref), ppaux::trait_ref_to_str(tcx, &r_act_trait_ref), ty::type_err_to_str(tcx, err))); diff --git a/src/librustc/middle/typeck/infer/doc.rs b/src/librustc/middle/typeck/infer/doc.rs index 11bfbc637169e..539418dbcb228 100644 --- a/src/librustc/middle/typeck/infer/doc.rs +++ b/src/librustc/middle/typeck/infer/doc.rs @@ -240,4 +240,4 @@ We make use of a trait-like impementation strategy to consolidate duplicated code between subtypes, GLB, and LUB computations. See the section on "Type Combining" below for details. -*/ \ No newline at end of file +*/ diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 1b325dd8a4b99..69db4bea3101c 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -173,7 +173,7 @@ impl ErrorReporting for InferCtxt { fn values_str(@mut self, values: &ValuePairs) -> Option<~str> { /*! - * Returns a string of the form "expected `%s` but found `%s`", + * Returns a string of the form "expected `%s`, found `%s`", * or None if this is a derived error. */ match *values { @@ -201,7 +201,7 @@ impl ErrorReporting for InferCtxt { return None; } - Some(fmt!("expected `%s` but found `%s`", + Some(fmt!("expected `%s`, found `%s`", expected.user_string(self.tcx), found.user_string(self.tcx))) } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 854ee835cc7dc..d2d83b2792235 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -764,7 +764,7 @@ impl InferCtxt { _ => { // if I leave out : ~str, it infers &str and complains |actual: ~str| { - fmt!("mismatched types: expected `%s` but found `%s`", + fmt!("mismatched types: expected `%s`, found `%s`", self.ty_to_str(resolved_expected), actual) } } diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index cec64f36947e0..10a141a9e558c 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -44,4 +44,4 @@ pub fn package_is_installed(p: &PkgId) -> bool { false }; is_installed -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs b/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs index 542a6af402d05..3b233c9f6a88a 100644 --- a/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs +++ b/src/librustpkg/testsuite/pass/src/fancy-lib/foo.rs @@ -9,4 +9,4 @@ // except according to those terms. pub fn do_nothing() { -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/install-paths/bench.rs b/src/librustpkg/testsuite/pass/src/install-paths/bench.rs index e1641ccf07493..3d22ddc57faa3 100644 --- a/src/librustpkg/testsuite/pass/src/install-paths/bench.rs +++ b/src/librustpkg/testsuite/pass/src/install-paths/bench.rs @@ -14,4 +14,4 @@ fn g() { while(x < 1000) { x += 1; } -} \ No newline at end of file +} diff --git a/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs b/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs index 542a6af402d05..3b233c9f6a88a 100644 --- a/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs +++ b/src/librustpkg/testsuite/pass/src/simple-lib/src/foo.rs @@ -9,4 +9,4 @@ // except according to those terms. pub fn do_nothing() { -} \ No newline at end of file +} diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 722af828d5c11..7ab3c81b61f7a 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -726,4 +726,4 @@ mod bench { float::to_str(rng.gen()); } } -} \ No newline at end of file +} diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index 756b4a10d3c90..e41109ecf675b 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -105,4 +105,4 @@ mod bench { HasDtor { x : 10 }; } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/mock.rs b/src/libstd/rt/io/mock.rs index b580b752bd985..c46e1372c6414 100644 --- a/src/libstd/rt/io/mock.rs +++ b/src/libstd/rt/io/mock.rs @@ -47,4 +47,4 @@ impl MockWriter { impl Writer for MockWriter { fn write(&mut self, buf: &[u8]) { (self.write)(buf) } fn flush(&mut self) { (self.flush)() } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs index 838c2d86c9fa2..7d8c730e7c4b6 100644 --- a/src/libstd/rt/io/mod.rs +++ b/src/libstd/rt/io/mod.rs @@ -505,4 +505,4 @@ pub fn placeholder_error() -> IoError { desc: "Placeholder error. You shouldn't be seeing this", detail: None } -} \ No newline at end of file +} diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs index c7820ebf6238b..78ce52fca20ec 100644 --- a/src/libstd/rt/io/timer.rs +++ b/src/libstd/rt/io/timer.rs @@ -61,4 +61,4 @@ mod test { } } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/metrics.rs b/src/libstd/rt/metrics.rs index b0c0fa5d70862..8912420645750 100644 --- a/src/libstd/rt/metrics.rs +++ b/src/libstd/rt/metrics.rs @@ -95,4 +95,4 @@ impl ToStr for SchedMetrics { self.release_no_tombstone ) } -} \ No newline at end of file +} diff --git a/src/libstd/rt/sleeper_list.rs b/src/libstd/rt/sleeper_list.rs index d327023de978a..48012199bbef5 100644 --- a/src/libstd/rt/sleeper_list.rs +++ b/src/libstd/rt/sleeper_list.rs @@ -56,4 +56,4 @@ impl Clone for SleeperList { stack: self.stack.clone() } } -} \ No newline at end of file +} diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index a1169954688b0..53307b3d2db81 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -118,4 +118,4 @@ pub fn get_exit_status() -> int { extern { fn rust_get_exit_status_newrt() -> libc::uintptr_t; } -} \ No newline at end of file +} diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index afa2e7a5e42f5..db520aa162553 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -366,7 +366,7 @@ impl Parser { } else { self.fatal( fmt!( - "expected `%s` but found `%s`", + "expected `%s`, found `%s`", self.token_to_str(t), self.this_token_to_str() ) @@ -872,7 +872,7 @@ impl Parser { _ => { p.fatal( fmt!( - "expected `;` or `}` but found `%s`", + "expected `;` or `}`, found `%s`", self.this_token_to_str() ) ); @@ -3192,7 +3192,7 @@ impl Parser { self.fatal( fmt!( "expected `;` or `}` after \ - expression but found `%s`", + expression, found `%s`", self.token_to_str(t) ) ); @@ -3391,7 +3391,7 @@ impl Parser { if !self.is_self_ident() { self.fatal( fmt!( - "expected `self` but found `%s`", + "expected `self`, found `%s`", self.this_token_to_str() ) ); @@ -3789,7 +3789,7 @@ impl Parser { self.fatal( fmt!( "expected `{`, `(`, or `;` after struct name \ - but found `%s`", + , found `%s`", self.this_token_to_str() ) ); @@ -3833,7 +3833,7 @@ impl Parser { token::RBRACE => {} _ => { self.span_fatal(*self.span, - fmt!("expected `,`, or '}' but found `%s`", + fmt!("expected `,`, or '}', found `%s`", self.this_token_to_str())); } } @@ -3917,7 +3917,7 @@ impl Parser { the module"); } _ => { - self.fatal(fmt!("expected item but found `%s`", + self.fatal(fmt!("expected item, found `%s`", self.this_token_to_str())); } } @@ -4165,7 +4165,7 @@ impl Parser { self.expect_keyword(keywords::Mod); } else if *self.token != token::LBRACE { self.span_fatal(*self.span, - fmt!("expected `{` or `mod` but found `%s`", + fmt!("expected `{` or `mod`, found `%s`", self.this_token_to_str())); } diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs index 9e73bbe1406bd..f7524787c7b96 100644 --- a/src/test/compile-fail/bad-bang-ann-3.rs +++ b/src/test/compile-fail/bad-bang-ann-3.rs @@ -13,7 +13,7 @@ fn bad_bang(i: uint) -> ! { return 7u; - //~^ ERROR expected `!` but found `uint` + //~^ ERROR expected `!`, found `uint` } fn main() { bad_bang(5u); } diff --git a/src/test/compile-fail/bad-bang-ann.rs b/src/test/compile-fail/bad-bang-ann.rs index 2ffb5dd29066f..a52c6f3a849a0 100644 --- a/src/test/compile-fail/bad-bang-ann.rs +++ b/src/test/compile-fail/bad-bang-ann.rs @@ -13,7 +13,7 @@ fn bad_bang(i: uint) -> ! { if i < 0u { } else { fail!(); } - //~^ ERROR expected `!` but found `()` + //~^ ERROR expected `!`, found `()` } fn main() { bad_bang(5u); } diff --git a/src/test/compile-fail/bad-const-type.rs b/src/test/compile-fail/bad-const-type.rs index 5045c87c2f3a8..21047716f303e 100644 --- a/src/test/compile-fail/bad-const-type.rs +++ b/src/test/compile-fail/bad-const-type.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected `~str` but found `int` +// error-pattern:expected `~str`, found `int` static i: ~str = 10i; fn main() { info!(i); } diff --git a/src/test/compile-fail/bang-tailexpr.rs b/src/test/compile-fail/bang-tailexpr.rs index af78e19e8c2e2..ff95f05279eea 100644 --- a/src/test/compile-fail/bang-tailexpr.rs +++ b/src/test/compile-fail/bang-tailexpr.rs @@ -9,6 +9,6 @@ // except according to those terms. fn f() -> ! { - 3i //~ ERROR expected `!` but found `int` + 3i //~ ERROR expected `!`, found `int` } fn main() { } diff --git a/src/test/compile-fail/block-must-not-have-result-do.rs b/src/test/compile-fail/block-must-not-have-result-do.rs index abeefa4aac810..687171f8c1f9b 100644 --- a/src/test/compile-fail/block-must-not-have-result-do.rs +++ b/src/test/compile-fail/block-must-not-have-result-do.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { loop { diff --git a/src/test/compile-fail/block-must-not-have-result-res.rs b/src/test/compile-fail/block-must-not-have-result-res.rs index c9b627f55f803..a3bef505d0d4e 100644 --- a/src/test/compile-fail/block-must-not-have-result-res.rs +++ b/src/test/compile-fail/block-must-not-have-result-res.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` struct r; diff --git a/src/test/compile-fail/block-must-not-have-result-while.rs b/src/test/compile-fail/block-must-not-have-result-while.rs index e4aceabf0c8fb..ed903f3fd6551 100644 --- a/src/test/compile-fail/block-must-not-have-result-while.rs +++ b/src/test/compile-fail/block-must-not-have-result-while.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { while true { diff --git a/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs b/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs index c51cf5b9538d9..1cde5cb94fd5e 100644 --- a/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-alias-mut-base-ptr.rs @@ -12,4 +12,4 @@ fn foo(t0: &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-struct.rs b/src/test/compile-fail/borrowck-anon-fields-struct.rs index 45a26068d8285..bcaa3b9086cf3 100644 --- a/src/test/compile-fail/borrowck-anon-fields-struct.rs +++ b/src/test/compile-fail/borrowck-anon-fields-struct.rs @@ -34,4 +34,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-tuple.rs b/src/test/compile-fail/borrowck-anon-fields-tuple.rs index ae02245c97f52..de2a8d8326808 100644 --- a/src/test/compile-fail/borrowck-anon-fields-tuple.rs +++ b/src/test/compile-fail/borrowck-anon-fields-tuple.rs @@ -32,4 +32,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-anon-fields-variant.rs b/src/test/compile-fail/borrowck-anon-fields-variant.rs index 3d9738df059ca..da0a9323d2c81 100644 --- a/src/test/compile-fail/borrowck-anon-fields-variant.rs +++ b/src/test/compile-fail/borrowck-anon-fields-variant.rs @@ -40,4 +40,4 @@ fn same_variant() { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs index ff1ec38ad6406..c142876c5c2c5 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs @@ -40,4 +40,4 @@ fn explicit() { rewrite(&mut a)); //~ ERROR cannot borrow } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs index 0adf486b8b3ab..622d2e78ee794 100644 --- a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs +++ b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs @@ -40,4 +40,4 @@ fn explicit() { a); //~ ERROR cannot move } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs index 7e9c298ba4732..45238b36681b2 100644 --- a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs +++ b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs @@ -28,4 +28,4 @@ fn foo3(t0: &mut &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs index c99a1ee60d7fd..628ccd1a5d782 100644 --- a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -13,4 +13,4 @@ fn let_pat() { //~^ ERROR cannot move out of dereference of & pointer } -pub fn main() {} \ No newline at end of file +pub fn main() {} diff --git a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs index 6a3832d2304cf..565629b1c306d 100644 --- a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs @@ -12,4 +12,4 @@ fn foo(t0: &mut int) { } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs index bea5f1f6ea765..ab6f70945be6c 100644 --- a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs +++ b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs @@ -13,4 +13,4 @@ fn foo<'a>(mut t0: &'a mut int, } fn main() { -} \ No newline at end of file +} diff --git a/src/test/compile-fail/cast-immutable-mutable-trait.rs b/src/test/compile-fail/cast-immutable-mutable-trait.rs index 1047a99577143..0a94d6c456081 100644 --- a/src/test/compile-fail/cast-immutable-mutable-trait.rs +++ b/src/test/compile-fail/cast-immutable-mutable-trait.rs @@ -25,4 +25,4 @@ fn main() { let s = @S { unused: 0 }; let _s2 = s as @mut T; //~ error: types differ in mutability let _s3 = &s as &mut T; //~ error: types differ in mutability -} \ No newline at end of file +} diff --git a/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs b/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs index a083757a0eb9a..ce58b260f6186 100644 --- a/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs +++ b/src/test/compile-fail/cast-vector-to-unsafe-nonstatic.rs @@ -11,4 +11,4 @@ fn main() { let foo = ['h' as u8, 'i' as u8, 0 as u8]; let bar = &foo as *u8; //~ ERROR mismatched types -} \ No newline at end of file +} diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index b38cb89548807..2e7313b6afd54 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -13,7 +13,7 @@ struct X { } fn foo(blk: @fn:()) -> X { - return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds + return X { field: blk }; //~ ERROR expected bounds `Send`, found no bounds } fn main() { diff --git a/src/test/compile-fail/closure-bounds-not-builtin.rs b/src/test/compile-fail/closure-bounds-not-builtin.rs index a3484cb33dcae..fbf1acb60665b 100644 --- a/src/test/compile-fail/closure-bounds-not-builtin.rs +++ b/src/test/compile-fail/closure-bounds-not-builtin.rs @@ -5,4 +5,4 @@ fn take(f: &fn:Foo()) { //~^ ERROR only the builtin traits can be used as closure or object bounds } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index f04da0575b954..ba15d9a056544 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -11,7 +11,7 @@ fn give_any(f: &fn:()) { fn give_owned(f: &fn:Send()) { take_any(f); - take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send` + take_const_owned(f); //~ ERROR expected bounds `Send+Freeze`, found bounds `Send` } fn main() {} diff --git a/src/test/compile-fail/coherence_inherent.rs b/src/test/compile-fail/coherence_inherent.rs index 590c12826e4fe..2c3fbc827aad6 100644 --- a/src/test/compile-fail/coherence_inherent.rs +++ b/src/test/compile-fail/coherence_inherent.rs @@ -42,4 +42,4 @@ mod NoImport { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/coherence_inherent_cc.rs b/src/test/compile-fail/coherence_inherent_cc.rs index 72c6df57c4ff5..40d733f8bab5c 100644 --- a/src/test/compile-fail/coherence_inherent_cc.rs +++ b/src/test/compile-fail/coherence_inherent_cc.rs @@ -35,4 +35,4 @@ mod NoImport { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/deprecated-auto-code.rs b/src/test/compile-fail/deprecated-auto-code.rs index 1f7cbfe980782..e4576e0f57c54 100644 --- a/src/test/compile-fail/deprecated-auto-code.rs +++ b/src/test/compile-fail/deprecated-auto-code.rs @@ -12,4 +12,4 @@ #[auto_decode] //~ ERROR: `#[auto_decode]` is deprecated struct A; -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/do-lambda-requires-braces.rs b/src/test/compile-fail/do-lambda-requires-braces.rs index a836556dff881..abe066182b924 100644 --- a/src/test/compile-fail/do-lambda-requires-braces.rs +++ b/src/test/compile-fail/do-lambda-requires-braces.rs @@ -10,6 +10,6 @@ fn main() { do something - |x| do somethingelse //~ ERROR: expected `{` but found `do` + |x| do somethingelse //~ ERROR: expected `{`, found `do` |y| say(x, y) } diff --git a/src/test/compile-fail/do1.rs b/src/test/compile-fail/do1.rs index d16fa4eadd566..2da57bda273e2 100644 --- a/src/test/compile-fail/do1.rs +++ b/src/test/compile-fail/do1.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - let x = do y; //~ ERROR: expected `{` but found + let x = do y; //~ ERROR: expected `{`, found } diff --git a/src/test/compile-fail/do2.rs b/src/test/compile-fail/do2.rs index 4466c07518fec..0d815363635f2 100644 --- a/src/test/compile-fail/do2.rs +++ b/src/test/compile-fail/do2.rs @@ -12,5 +12,5 @@ fn f(f: @fn(int) -> bool) -> bool { f(10i) } fn main() { assert!(do f() |i| { i == 10i } == 10i); - //~^ ERROR: expected `bool` but found `int` + //~^ ERROR: expected `bool`, found `int` } diff --git a/src/test/compile-fail/estr-subtyping.rs b/src/test/compile-fail/estr-subtyping.rs index d0d1b2013a95b..f8dcd9052b3ef 100644 --- a/src/test/compile-fail/estr-subtyping.rs +++ b/src/test/compile-fail/estr-subtyping.rs @@ -14,19 +14,19 @@ fn wants_slice(x: &str) { } fn has_box(x: @str) { wants_box(x); - wants_uniq(x); //~ ERROR str storage differs: expected ~ but found @ + wants_uniq(x); //~ ERROR str storage differs: expected ~, found @ wants_slice(x); } fn has_uniq(x: ~str) { - wants_box(x); //~ ERROR str storage differs: expected @ but found ~ + wants_box(x); //~ ERROR str storage differs: expected @, found ~ wants_uniq(x); wants_slice(x); } fn has_slice(x: &str) { - wants_box(x); //~ ERROR str storage differs: expected @ but found & - wants_uniq(x); //~ ERROR str storage differs: expected ~ but found & + wants_box(x); //~ ERROR str storage differs: expected @, found & + wants_uniq(x); //~ ERROR str storage differs: expected ~, found & wants_slice(x); } diff --git a/src/test/compile-fail/evec-subtyping.rs b/src/test/compile-fail/evec-subtyping.rs index f9c8ba01f1805..9301798bddb72 100644 --- a/src/test/compile-fail/evec-subtyping.rs +++ b/src/test/compile-fail/evec-subtyping.rs @@ -14,26 +14,26 @@ fn wants_three(x: [uint, ..3]) { } fn has_box(x: @[uint]) { wants_box(x); - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found @ - wants_three(x); //~ ERROR [] storage differs: expected 3 but found @ + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found @ + wants_three(x); //~ ERROR [] storage differs: expected 3, found @ } fn has_uniq(x: ~[uint]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found ~ + wants_box(x); //~ ERROR [] storage differs: expected @, found ~ wants_uniq(x); - wants_three(x); //~ ERROR [] storage differs: expected 3 but found ~ + wants_three(x); //~ ERROR [] storage differs: expected 3, found ~ } fn has_three(x: [uint, ..3]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found 3 - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 3 + wants_box(x); //~ ERROR [] storage differs: expected @, found 3 + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found 3 wants_three(x); } fn has_four(x: [uint, ..4]) { - wants_box(x); //~ ERROR [] storage differs: expected @ but found 4 - wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 4 - wants_three(x); //~ ERROR [] storage differs: expected 3 but found 4 + wants_box(x); //~ ERROR [] storage differs: expected @, found 4 + wants_uniq(x); //~ ERROR [] storage differs: expected ~, found 4 + wants_three(x); //~ ERROR [] storage differs: expected 3, found 4 } fn main() { diff --git a/src/test/compile-fail/extern-no-call.rs b/src/test/compile-fail/extern-no-call.rs index 58649f3209bb1..343965a5c4a8c 100644 --- a/src/test/compile-fail/extern-no-call.rs +++ b/src/test/compile-fail/extern-no-call.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected function but found `*u8` +// error-pattern:expected function, found `*u8` extern fn f() { } diff --git a/src/test/compile-fail/fully-qualified-type-name2.rs b/src/test/compile-fail/fully-qualified-type-name2.rs index 986d19669b91e..94af50dac0ea5 100644 --- a/src/test/compile-fail/fully-qualified-type-name2.rs +++ b/src/test/compile-fail/fully-qualified-type-name2.rs @@ -20,7 +20,7 @@ mod y { fn bar(x: x::foo) -> y::foo { return x; - //~^ ERROR mismatched types: expected `y::foo` but found `x::foo` + //~^ ERROR mismatched types: expected `y::foo`, found `x::foo` } fn main() { diff --git a/src/test/compile-fail/fully-qualified-type-name3.rs b/src/test/compile-fail/fully-qualified-type-name3.rs index 464f292b75899..a9fd68e4bf64a 100644 --- a/src/test/compile-fail/fully-qualified-type-name3.rs +++ b/src/test/compile-fail/fully-qualified-type-name3.rs @@ -16,7 +16,7 @@ type T2 = int; fn bar(x: T1) -> T2 { return x; - //~^ ERROR mismatched types: expected `T2` but found `T1` + //~^ ERROR mismatched types: expected `T2`, found `T1` } fn main() { diff --git a/src/test/compile-fail/if-branch-types.rs b/src/test/compile-fail/if-branch-types.rs index 1c6dd0ef9f657..4a8c72c3877c5 100644 --- a/src/test/compile-fail/if-branch-types.rs +++ b/src/test/compile-fail/if-branch-types.rs @@ -10,5 +10,5 @@ fn main() { let x = if true { 10i } else { 10u }; - //~^ ERROR if and else have incompatible types: expected `int` but found `uint` + //~^ ERROR if and else have incompatible types: expected `int`, found `uint` } diff --git a/src/test/compile-fail/if-without-else-result.rs b/src/test/compile-fail/if-without-else-result.rs index 8e3318f6945ac..d9307d9669ae7 100644 --- a/src/test/compile-fail/if-without-else-result.rs +++ b/src/test/compile-fail/if-without-else-result.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `()` but found `bool` +// error-pattern:mismatched types: expected `()`, found `bool` fn main() { let a = if true { true }; diff --git a/src/test/compile-fail/integer-literal-suffix-inference.rs b/src/test/compile-fail/integer-literal-suffix-inference.rs index 2f77497acc4a8..1e42a9447f67a 100644 --- a/src/test/compile-fail/integer-literal-suffix-inference.rs +++ b/src/test/compile-fail/integer-literal-suffix-inference.rs @@ -39,62 +39,62 @@ fn main() { fn id_u64(n: u64) -> u64 { n } id_i8(a8); // ok - id_i8(a16); //~ ERROR mismatched types: expected `i8` but found `i16` - id_i8(a32); //~ ERROR mismatched types: expected `i8` but found `i32` - id_i8(a64); //~ ERROR mismatched types: expected `i8` but found `i64` + id_i8(a16); //~ ERROR mismatched types: expected `i8`, found `i16` + id_i8(a32); //~ ERROR mismatched types: expected `i8`, found `i32` + id_i8(a64); //~ ERROR mismatched types: expected `i8`, found `i64` - id_i16(a8); //~ ERROR mismatched types: expected `i16` but found `i8` + id_i16(a8); //~ ERROR mismatched types: expected `i16`, found `i8` id_i16(a16); // ok - id_i16(a32); //~ ERROR mismatched types: expected `i16` but found `i32` - id_i16(a64); //~ ERROR mismatched types: expected `i16` but found `i64` + id_i16(a32); //~ ERROR mismatched types: expected `i16`, found `i32` + id_i16(a64); //~ ERROR mismatched types: expected `i16`, found `i64` - id_i32(a8); //~ ERROR mismatched types: expected `i32` but found `i8` - id_i32(a16); //~ ERROR mismatched types: expected `i32` but found `i16` + id_i32(a8); //~ ERROR mismatched types: expected `i32`, found `i8` + id_i32(a16); //~ ERROR mismatched types: expected `i32`, found `i16` id_i32(a32); // ok - id_i32(a64); //~ ERROR mismatched types: expected `i32` but found `i64` + id_i32(a64); //~ ERROR mismatched types: expected `i32`, found `i64` - id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8` - id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16` - id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32` + id_i64(a8); //~ ERROR mismatched types: expected `i64`, found `i8` + id_i64(a16); //~ ERROR mismatched types: expected `i64`, found `i16` + id_i64(a32); //~ ERROR mismatched types: expected `i64`, found `i32` id_i64(a64); // ok id_i8(c8); // ok - id_i8(c16); //~ ERROR mismatched types: expected `i8` but found `i16` - id_i8(c32); //~ ERROR mismatched types: expected `i8` but found `i32` - id_i8(c64); //~ ERROR mismatched types: expected `i8` but found `i64` + id_i8(c16); //~ ERROR mismatched types: expected `i8`, found `i16` + id_i8(c32); //~ ERROR mismatched types: expected `i8`, found `i32` + id_i8(c64); //~ ERROR mismatched types: expected `i8`, found `i64` - id_i16(c8); //~ ERROR mismatched types: expected `i16` but found `i8` + id_i16(c8); //~ ERROR mismatched types: expected `i16`, found `i8` id_i16(c16); // ok - id_i16(c32); //~ ERROR mismatched types: expected `i16` but found `i32` - id_i16(c64); //~ ERROR mismatched types: expected `i16` but found `i64` + id_i16(c32); //~ ERROR mismatched types: expected `i16`, found `i32` + id_i16(c64); //~ ERROR mismatched types: expected `i16`, found `i64` - id_i32(c8); //~ ERROR mismatched types: expected `i32` but found `i8` - id_i32(c16); //~ ERROR mismatched types: expected `i32` but found `i16` + id_i32(c8); //~ ERROR mismatched types: expected `i32`, found `i8` + id_i32(c16); //~ ERROR mismatched types: expected `i32`, found `i16` id_i32(c32); // ok - id_i32(c64); //~ ERROR mismatched types: expected `i32` but found `i64` + id_i32(c64); //~ ERROR mismatched types: expected `i32`, found `i64` - id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8` - id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16` - id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32` + id_i64(a8); //~ ERROR mismatched types: expected `i64`, found `i8` + id_i64(a16); //~ ERROR mismatched types: expected `i64`, found `i16` + id_i64(a32); //~ ERROR mismatched types: expected `i64`, found `i32` id_i64(a64); // ok id_u8(b8); // ok - id_u8(b16); //~ ERROR mismatched types: expected `u8` but found `u16` - id_u8(b32); //~ ERROR mismatched types: expected `u8` but found `u32` - id_u8(b64); //~ ERROR mismatched types: expected `u8` but found `u64` + id_u8(b16); //~ ERROR mismatched types: expected `u8`, found `u16` + id_u8(b32); //~ ERROR mismatched types: expected `u8`, found `u32` + id_u8(b64); //~ ERROR mismatched types: expected `u8`, found `u64` - id_u16(b8); //~ ERROR mismatched types: expected `u16` but found `u8` + id_u16(b8); //~ ERROR mismatched types: expected `u16`, found `u8` id_u16(b16); // ok - id_u16(b32); //~ ERROR mismatched types: expected `u16` but found `u32` - id_u16(b64); //~ ERROR mismatched types: expected `u16` but found `u64` + id_u16(b32); //~ ERROR mismatched types: expected `u16`, found `u32` + id_u16(b64); //~ ERROR mismatched types: expected `u16`, found `u64` - id_u32(b8); //~ ERROR mismatched types: expected `u32` but found `u8` - id_u32(b16); //~ ERROR mismatched types: expected `u32` but found `u16` + id_u32(b8); //~ ERROR mismatched types: expected `u32`, found `u8` + id_u32(b16); //~ ERROR mismatched types: expected `u32`, found `u16` id_u32(b32); // ok - id_u32(b64); //~ ERROR mismatched types: expected `u32` but found `u64` + id_u32(b64); //~ ERROR mismatched types: expected `u32`, found `u64` - id_u64(b8); //~ ERROR mismatched types: expected `u64` but found `u8` - id_u64(b16); //~ ERROR mismatched types: expected `u64` but found `u16` - id_u64(b32); //~ ERROR mismatched types: expected `u64` but found `u32` + id_u64(b8); //~ ERROR mismatched types: expected `u64`, found `u8` + id_u64(b16); //~ ERROR mismatched types: expected `u64`, found `u16` + id_u64(b32); //~ ERROR mismatched types: expected `u64`, found `u32` id_u64(b64); // ok } diff --git a/src/test/compile-fail/issue-2995.rs b/src/test/compile-fail/issue-2995.rs index 3e771eef970f7..ea8ee8699e482 100644 --- a/src/test/compile-fail/issue-2995.rs +++ b/src/test/compile-fail/issue-2995.rs @@ -12,4 +12,4 @@ fn bad (p: *int) { let _q: &int = p as ∫ //~ ERROR non-scalar cast } -fn main() { } \ No newline at end of file +fn main() { } diff --git a/src/test/compile-fail/issue-3036.rs b/src/test/compile-fail/issue-3036.rs index 45b4ab1871dc9..5f56f6b8b6b99 100644 --- a/src/test/compile-fail/issue-3036.rs +++ b/src/test/compile-fail/issue-3036.rs @@ -13,4 +13,4 @@ fn main() { let x = 3 -} //~ ERROR: expected `;` but found `}` +} //~ ERROR: expected `;`, found `}` diff --git a/src/test/compile-fail/issue-3477.rs b/src/test/compile-fail/issue-3477.rs index 23e680fd851c3..cb7809eef55b7 100644 --- a/src/test/compile-fail/issue-3477.rs +++ b/src/test/compile-fail/issue-3477.rs @@ -1,3 +1,3 @@ fn main() { - let _p: char = 100; //~ ERROR mismatched types: expected `char` but found + let _p: char = 100; //~ ERROR mismatched types: expected `char`, found } diff --git a/src/test/compile-fail/issue-3680.rs b/src/test/compile-fail/issue-3680.rs index b453384c0c890..7cb63d712664b 100644 --- a/src/test/compile-fail/issue-3680.rs +++ b/src/test/compile-fail/issue-3680.rs @@ -10,6 +10,6 @@ fn main() { match None { - Err(_) => () //~ ERROR mismatched types: expected `std::option::Option<>` but found `std::result::Result<,>` + Err(_) => () //~ ERROR mismatched types: expected `std::option::Option<>`, found `std::result::Result<,>` } } diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs index 0fbc79b1bc7bd..02a245e0c97d0 100644 --- a/src/test/compile-fail/issue-4517.rs +++ b/src/test/compile-fail/issue-4517.rs @@ -2,5 +2,5 @@ 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) + bar(foo); //~ ERROR mismatched types: expected `int`, found `[u8, .. 4]` (expected int, found vector) } diff --git a/src/test/compile-fail/issue-4736.rs b/src/test/compile-fail/issue-4736.rs index f7144b4c8fa91..6f410ea3c3739 100644 --- a/src/test/compile-fail/issue-4736.rs +++ b/src/test/compile-fail/issue-4736.rs @@ -12,4 +12,4 @@ struct NonCopyable(()); fn main() { let z = NonCopyable{ p: () }; //~ ERROR structure has no field named `p` -} \ No newline at end of file +} diff --git a/src/test/compile-fail/issue-4968.rs b/src/test/compile-fail/issue-4968.rs index 700d8a61c3a39..d94a8d69a8e95 100644 --- a/src/test/compile-fail/issue-4968.rs +++ b/src/test/compile-fail/issue-4968.rs @@ -12,5 +12,5 @@ static A: (int,int) = (4,2); fn main() { - match 42 { A => () } //~ ERROR mismatched types: expected `` but found `(int,int)` (expected integral variable but found tuple) + match 42 { A => () } //~ ERROR mismatched types: expected ``, found `(int,int)` (expected integral variable, found tuple) } diff --git a/src/test/compile-fail/issue-5100.rs b/src/test/compile-fail/issue-5100.rs index 1ef67f784e386..c6db366e79274 100644 --- a/src/test/compile-fail/issue-5100.rs +++ b/src/test/compile-fail/issue-5100.rs @@ -12,33 +12,33 @@ enum A { B, C } fn main() { match (true, false) { - B => (), //~ ERROR expected `(bool,bool)` but found an enum or structure pattern + B => (), //~ ERROR expected `(bool,bool)`, found an enum or structure pattern _ => () } match (true, false) { - (true, false, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found tuple (expected a tuple with 2 elements but found one with 3 elements) + (true, false, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found tuple (expected a tuple with 2 elements, found one with 3 elements) } match (true, false) { - @(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found an @-box pattern + @(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found an @-box pattern } match (true, false) { - ~(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found a ~-box pattern + ~(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found a ~-box pattern } match (true, false) { - &(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)` but found an &-pointer pattern + &(true, false) => () //~ ERROR mismatched types: expected `(bool,bool)`, found an &-pointer pattern } - let v = [('a', 'b') //~ ERROR expected function but found `(char,char)` + let v = [('a', 'b') //~ ERROR expected function, found `(char,char)` ('c', 'd'), ('e', 'f')]; for &(x,y) in v.iter() {} // should be OK // Make sure none of the errors above were fatal - let x: char = true; //~ ERROR expected `char` but found `bool` + let x: char = true; //~ ERROR expected `char`, found `bool` } diff --git a/src/test/compile-fail/issue-5358-1.rs b/src/test/compile-fail/issue-5358-1.rs index a3d25e7d2adca..85e34cd6db3ee 100644 --- a/src/test/compile-fail/issue-5358-1.rs +++ b/src/test/compile-fail/issue-5358-1.rs @@ -12,7 +12,7 @@ struct S(Either); fn main() { match S(Left(5)) { - Right(_) => {} //~ ERROR mismatched types: expected `S` but found `std::either::Either + Right(_) => {} //~ ERROR mismatched types: expected `S`, found `std::either::Either _ => {} } } diff --git a/src/test/compile-fail/issue-5358.rs b/src/test/compile-fail/issue-5358.rs index 8d4f463346693..b0a74fb37abe2 100644 --- a/src/test/compile-fail/issue-5358.rs +++ b/src/test/compile-fail/issue-5358.rs @@ -12,6 +12,6 @@ struct S(Either); fn main() { match *S(Left(5)) { - S(_) => {} //~ ERROR mismatched types: expected `std::either::Either` but found a structure pattern + S(_) => {} //~ ERROR mismatched types: expected `std::either::Either`, found a structure pattern } } diff --git a/src/test/compile-fail/issue-6762.rs b/src/test/compile-fail/issue-6762.rs index 391c1019a9468..14dcc4ea8a3a8 100644 --- a/src/test/compile-fail/issue-6762.rs +++ b/src/test/compile-fail/issue-6762.rs @@ -21,4 +21,4 @@ fn main() twice(x); invoke(sq); -} \ No newline at end of file +} diff --git a/src/test/compile-fail/loop-does-not-diverge.rs b/src/test/compile-fail/loop-does-not-diverge.rs index 0a9d9fb20ab0e..d0e5249305493 100644 --- a/src/test/compile-fail/loop-does-not-diverge.rs +++ b/src/test/compile-fail/loop-does-not-diverge.rs @@ -14,7 +14,7 @@ fn forever() -> ! { loop { break; } - return 42i; //~ ERROR expected `!` but found `int` + return 42i; //~ ERROR expected `!`, found `int` } fn main() { diff --git a/src/test/compile-fail/lub-if.rs b/src/test/compile-fail/lub-if.rs index 358c61921470f..6b5055cb1a2cd 100644 --- a/src/test/compile-fail/lub-if.rs +++ b/src/test/compile-fail/lub-if.rs @@ -49,4 +49,4 @@ pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str { } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/lub-match.rs b/src/test/compile-fail/lub-match.rs index 2a61b72997d1f..37b9cc55dc822 100644 --- a/src/test/compile-fail/lub-match.rs +++ b/src/test/compile-fail/lub-match.rs @@ -52,4 +52,4 @@ pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str { } } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/main-wrong-location.rs b/src/test/compile-fail/main-wrong-location.rs index 90ef7843d4bf9..ef3f8140c68a0 100644 --- a/src/test/compile-fail/main-wrong-location.rs +++ b/src/test/compile-fail/main-wrong-location.rs @@ -12,4 +12,4 @@ mod m { // An inferred main entry point (that doesn't use #[main]) // must appear at the top of the crate fn main() { } //~ NOTE here is a function named 'main' -} \ No newline at end of file +} diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index f6fd8e29a4f4d..8b29d165b603c 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -17,5 +17,5 @@ fn main() { let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as @Map<~str, ~str>; let y: @Map = @x; - //~^ ERROR expected trait std::container::Map but found @-ptr + //~^ ERROR expected trait std::container::Map, found @-ptr } diff --git a/src/test/compile-fail/match-struct.rs b/src/test/compile-fail/match-struct.rs index 6e9bf603aef9e..2b75fc6410e86 100644 --- a/src/test/compile-fail/match-struct.rs +++ b/src/test/compile-fail/match-struct.rs @@ -4,7 +4,7 @@ enum E { C(int) } fn main() { match S { a: 1 } { - C(_) => (), //~ ERROR mismatched types: expected `S` but found `E` + C(_) => (), //~ ERROR mismatched types: expected `S`, found `E` _ => () } } diff --git a/src/test/compile-fail/match-vec-mismatch-2.rs b/src/test/compile-fail/match-vec-mismatch-2.rs index 6ea0300cf1e7d..f2c61898b385b 100644 --- a/src/test/compile-fail/match-vec-mismatch-2.rs +++ b/src/test/compile-fail/match-vec-mismatch-2.rs @@ -1,5 +1,5 @@ fn main() { match () { - [()] => { } //~ ERROR mismatched types: expected `()` but found a vector pattern + [()] => { } //~ ERROR mismatched types: expected `()`, found a vector pattern } } diff --git a/src/test/compile-fail/match-vec-mismatch.rs b/src/test/compile-fail/match-vec-mismatch.rs index 85ed8761ee935..ffc2e0b31ee48 100644 --- a/src/test/compile-fail/match-vec-mismatch.rs +++ b/src/test/compile-fail/match-vec-mismatch.rs @@ -1,6 +1,6 @@ fn main() { match ~"foo" { - ['f', 'o', .._] => { } //~ ERROR mismatched types: expected `~str` but found a vector pattern + ['f', 'o', .._] => { } //~ ERROR mismatched types: expected `~str`, found a vector pattern _ => { } } } diff --git a/src/test/compile-fail/multitrait.rs b/src/test/compile-fail/multitrait.rs index b49ee5aab47e6..2ad07dcbb069c 100644 --- a/src/test/compile-fail/multitrait.rs +++ b/src/test/compile-fail/multitrait.rs @@ -12,7 +12,7 @@ struct S { y: int } -impl Cmp, ToStr for S { //~ ERROR: expected `{` but found `,` +impl Cmp, ToStr for S { //~ ERROR: expected `{`, found `,` fn eq(&&other: S) { false } fn to_str(&self) -> ~str { ~"hi" } } diff --git a/src/test/compile-fail/noexporttypeexe.rs b/src/test/compile-fail/noexporttypeexe.rs index 3add0134d002a..e622122306f82 100644 --- a/src/test/compile-fail/noexporttypeexe.rs +++ b/src/test/compile-fail/noexporttypeexe.rs @@ -18,5 +18,5 @@ fn main() { // because the def_id associated with the type was // not convertible to a path. let x: int = noexporttypelib::foo(); - //~^ ERROR expected `int` but found `std::option::Option` + //~^ ERROR expected `int`, found `std::option::Option` } diff --git a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs index 2727db9d0422e..25d2bd2982fb3 100644 --- a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs +++ b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs @@ -12,6 +12,6 @@ fn main() { fn bar(n: int) { - let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count, found variable } } diff --git a/src/test/compile-fail/omitted-arg-in-item-fn.rs b/src/test/compile-fail/omitted-arg-in-item-fn.rs index fcbfb115af756..c5ff885997b72 100644 --- a/src/test/compile-fail/omitted-arg-in-item-fn.rs +++ b/src/test/compile-fail/omitted-arg-in-item-fn.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x) { //~ ERROR expected `:` but found `)` +fn foo(x) { //~ ERROR expected `:`, found `)` } diff --git a/src/test/compile-fail/omitted-arg-wrong-types.rs b/src/test/compile-fail/omitted-arg-wrong-types.rs index a44c113269b98..92052aaff5781 100644 --- a/src/test/compile-fail/omitted-arg-wrong-types.rs +++ b/src/test/compile-fail/omitted-arg-wrong-types.rs @@ -13,8 +13,8 @@ fn let_in(x: T, f: &fn(T)) {} fn main() { let_in(3u, |i| { assert!(i == 3); }); - //~^ ERROR expected `uint` but found `int` + //~^ ERROR expected `uint`, found `int` let_in(3, |i| { assert!(i == 3u); }); - //~^ ERROR expected `int` but found `uint` + //~^ ERROR expected `int`, found `uint` } diff --git a/src/test/compile-fail/pattern-error-continue.rs b/src/test/compile-fail/pattern-error-continue.rs index 14d8b04ade4eb..79fcc8468166e 100644 --- a/src/test/compile-fail/pattern-error-continue.rs +++ b/src/test/compile-fail/pattern-error-continue.rs @@ -29,8 +29,8 @@ fn main() { _ => () } match 'c' { - S { _ } => (), //~ ERROR mismatched types: expected `char` but found struct + S { _ } => (), //~ ERROR mismatched types: expected `char`, found struct _ => () } - f(true); //~ ERROR mismatched types: expected `char` but found `bool` -} \ No newline at end of file + f(true); //~ ERROR mismatched types: expected `char`, found `bool` +} diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index ab2ac6cc0e5b9..ebc19c6eaf772 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -16,12 +16,12 @@ struct an_enum<'self>(&'self int); struct a_class<'self> { x:&'self int } fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> { - return e; //~ ERROR mismatched types: expected `an_enum<'b>` but found `an_enum<'a>` + return e; //~ ERROR mismatched types: expected `an_enum<'b>`, found `an_enum<'a>` //~^ ERROR cannot infer an appropriate lifetime } fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> { - return e; //~ ERROR mismatched types: expected `a_class<'b>` but found `a_class<'a>` + return e; //~ ERROR mismatched types: expected `a_class<'b>`, found `a_class<'a>` //~^ ERROR cannot infer an appropriate lifetime } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index e5399fc7fa3b9..66ab4b7705433 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -34,4 +34,4 @@ fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: &fn(&'a &'b uint)) { let z: Option<&'a &'b uint> = None; } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index d06dcd8aa86b8..c9859899ea4f1 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -37,4 +37,4 @@ fn call4<'a, 'b>(a: &'a uint, b: &'b uint) { } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-infer-paramd-indirect.rs b/src/test/compile-fail/regions-infer-paramd-indirect.rs index 0b4aa44010bdc..97f551ca0c2ae 100644 --- a/src/test/compile-fail/regions-infer-paramd-indirect.rs +++ b/src/test/compile-fail/regions-infer-paramd-indirect.rs @@ -29,7 +29,7 @@ impl<'self> set_f<'self> for c<'self> { } fn set_f_bad(&self, b: @b) { - self.f = b; //~ ERROR mismatched types: expected `@@&'self int` but found `@@&int` + self.f = b; //~ ERROR mismatched types: expected `@@&'self int`, found `@@&int` //~^ ERROR cannot infer an appropriate lifetime } } diff --git a/src/test/compile-fail/regions-infer-paramd-method.rs b/src/test/compile-fail/regions-infer-paramd-method.rs index 8c3195f020a97..68bd2304b2ad0 100644 --- a/src/test/compile-fail/regions-infer-paramd-method.rs +++ b/src/test/compile-fail/regions-infer-paramd-method.rs @@ -30,7 +30,7 @@ trait set_foo_foo { impl<'self> set_foo_foo for with_foo<'self> { fn set_foo(&mut self, f: @foo) { - self.f = f; //~ ERROR mismatched types: expected `@foo/&self` but found `@foo/&` + self.f = f; //~ ERROR mismatched types: expected `@foo/&self`, found `@foo/&` } } diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs index f90fe924587df..4848262750720 100644 --- a/src/test/compile-fail/regions-ref-in-fn-arg.rs +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -8,4 +8,4 @@ fn arg_closure() -> &'static int { with(|~ref x| x) //~ ERROR borrowed value does not live long enough } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index 072b0e83fdf58..a3f2a28d643f7 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -16,7 +16,7 @@ trait get_ctxt<'self> { } fn make_gc1(gc: @get_ctxt<'a>) -> @get_ctxt<'b> { - return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a` + return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b`, found `@get_ctxt/&a` } struct Foo { diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index 579575e2008f8..dd0fd7e221dc8 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -12,5 +12,5 @@ fn main() { let n = 1; - let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count, found variable } diff --git a/src/test/compile-fail/struct-base-wrong-type.rs b/src/test/compile-fail/struct-base-wrong-type.rs index adda356298d9f..af6fc64535149 100644 --- a/src/test/compile-fail/struct-base-wrong-type.rs +++ b/src/test/compile-fail/struct-base-wrong-type.rs @@ -12,11 +12,11 @@ struct Foo { a: int, b: int } struct Bar { x: int } static bar: Bar = Bar { x: 5 }; -static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo` but found `Bar` +static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo`, found `Bar` static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo` fn main() { let b = Bar { x: 5 }; - let f = Foo { a: 2, ..b }; //~ ERROR mismatched types: expected `Foo` but found `Bar` + let f = Foo { a: 2, ..b }; //~ ERROR mismatched types: expected `Foo`, found `Bar` let f_i = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo` } diff --git a/src/test/compile-fail/suppressed-error.rs b/src/test/compile-fail/suppressed-error.rs index b4a72548cfc0d..f13aabe52594a 100644 --- a/src/test/compile-fail/suppressed-error.rs +++ b/src/test/compile-fail/suppressed-error.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() { - let (x, y) = (); //~ ERROR expected `()` but found tuple (types differ) + let (x, y) = (); //~ ERROR expected `()`, found tuple (types differ) return x; -} \ No newline at end of file +} diff --git a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs index ebd3320d90126..478b4a4081ff6 100644 --- a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs +++ b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:mismatched types: expected `char` but found +// error-pattern:mismatched types: expected `char`, found // Issue #876 #[no_std]; diff --git a/src/test/compile-fail/tag-variant-disr-dup.rs b/src/test/compile-fail/tag-variant-disr-dup.rs index 216779fac7c46..a5f85a685e695 100644 --- a/src/test/compile-fail/tag-variant-disr-dup.rs +++ b/src/test/compile-fail/tag-variant-disr-dup.rs @@ -20,4 +20,4 @@ enum color { white = 0x000000, } -fn main() { } \ No newline at end of file +fn main() { } diff --git a/src/test/compile-fail/terr-in-field.rs b/src/test/compile-fail/terr-in-field.rs index 6474a58c1cdb9..88da7bc854201 100644 --- a/src/test/compile-fail/terr-in-field.rs +++ b/src/test/compile-fail/terr-in-field.rs @@ -20,7 +20,7 @@ struct bar { fn want_foo(f: foo) {} fn have_bar(b: bar) { - want_foo(b); //~ ERROR (expected struct foo but found struct bar) + want_foo(b); //~ ERROR (expected struct foo, found struct bar) } fn main() {} diff --git a/src/test/compile-fail/terr-sorts.rs b/src/test/compile-fail/terr-sorts.rs index ad14688f08c62..462bb0a3962c7 100644 --- a/src/test/compile-fail/terr-sorts.rs +++ b/src/test/compile-fail/terr-sorts.rs @@ -17,7 +17,7 @@ type bar = @foo; fn want_foo(f: foo) {} fn have_bar(b: bar) { - want_foo(b); //~ ERROR (expected struct foo but found @-ptr) + want_foo(b); //~ ERROR (expected struct foo, found @-ptr) } fn main() {} diff --git a/src/test/compile-fail/trait-impl-method-mismatch.rs b/src/test/compile-fail/trait-impl-method-mismatch.rs index 54fa62f797766..e23c74880379c 100644 --- a/src/test/compile-fail/trait-impl-method-mismatch.rs +++ b/src/test/compile-fail/trait-impl-method-mismatch.rs @@ -15,7 +15,7 @@ trait Mumbo { impl Mumbo for uint { // Cannot have a larger effect than the trait: unsafe fn jumbo(&self, x: @uint) { *self + *x; } - //~^ ERROR expected impure fn but found unsafe fn + //~^ ERROR expected impure fn, found unsafe fn } fn main() {} diff --git a/src/test/compile-fail/tuple-arity-mismatch.rs b/src/test/compile-fail/tuple-arity-mismatch.rs index 517b3cb59232e..2ca8f3bcce261 100644 --- a/src/test/compile-fail/tuple-arity-mismatch.rs +++ b/src/test/compile-fail/tuple-arity-mismatch.rs @@ -13,5 +13,5 @@ fn first((value, _): (int, float)) -> int { value } fn main() { - let y = first ((1,2,3)); //~ ERROR expected a tuple with 2 elements but found one with 3 elements + let y = first ((1,2,3)); //~ ERROR expected a tuple with 2 elements, found one with 3 elements } diff --git a/src/test/compile-fail/tutorial-suffix-inference-test.rs b/src/test/compile-fail/tutorial-suffix-inference-test.rs index d92aa8d640ab5..c1be54b3f75e1 100644 --- a/src/test/compile-fail/tutorial-suffix-inference-test.rs +++ b/src/test/compile-fail/tutorial-suffix-inference-test.rs @@ -17,9 +17,9 @@ fn main() { identity_u8(x); // after this, `x` is assumed to have type `u8` identity_u16(x); - //~^ ERROR mismatched types: expected `u16` but found `u8` + //~^ ERROR mismatched types: expected `u16`, found `u8` identity_u16(y); - //~^ ERROR mismatched types: expected `u16` but found `i32` + //~^ ERROR mismatched types: expected `u16`, found `i32` let a = 3i; @@ -27,6 +27,6 @@ fn main() { identity_i(a); // ok identity_u16(a); - //~^ ERROR mismatched types: expected `u16` but found `int` + //~^ ERROR mismatched types: expected `u16`, found `int` } diff --git a/src/test/compile-fail/type-parameter-names.rs b/src/test/compile-fail/type-parameter-names.rs index 6af3166a2ff4e..c076e6b5c813f 100644 --- a/src/test/compile-fail/type-parameter-names.rs +++ b/src/test/compile-fail/type-parameter-names.rs @@ -1,6 +1,6 @@ // Test that we print out the names of type parameters correctly in // our error messages. -fn foo(x: Foo) -> Bar { x } //~ ERROR expected `Bar` but found `Foo` +fn foo(x: Foo) -> Bar { x } //~ ERROR expected `Bar`, found `Foo` -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/debug-info/borrowed-basic.rs b/src/test/debug-info/borrowed-basic.rs index 7610301f6f035..2ddf309b16916 100644 --- a/src/test/debug-info/borrowed-basic.rs +++ b/src/test/debug-info/borrowed-basic.rs @@ -110,4 +110,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-c-style-enum.rs b/src/test/debug-info/borrowed-c-style-enum.rs index 70c85258c7921..14771396bd1ae 100644 --- a/src/test/debug-info/borrowed-c-style-enum.rs +++ b/src/test/debug-info/borrowed-c-style-enum.rs @@ -39,4 +39,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-enum.rs b/src/test/debug-info/borrowed-enum.rs index 38aa9c3881000..7c8a6814dcb44 100644 --- a/src/test/debug-info/borrowed-enum.rs +++ b/src/test/debug-info/borrowed-enum.rs @@ -59,4 +59,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-managed-basic.rs b/src/test/debug-info/borrowed-managed-basic.rs index 9087bb36fa5d6..7403ead3fcedd 100644 --- a/src/test/debug-info/borrowed-managed-basic.rs +++ b/src/test/debug-info/borrowed-managed-basic.rs @@ -111,4 +111,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-struct.rs b/src/test/debug-info/borrowed-struct.rs index 8b6eca3e37f79..571333a8a3bc7 100644 --- a/src/test/debug-info/borrowed-struct.rs +++ b/src/test/debug-info/borrowed-struct.rs @@ -72,4 +72,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-tuple.rs b/src/test/debug-info/borrowed-tuple.rs index da199941c8419..dbbf7d537aa54 100644 --- a/src/test/debug-info/borrowed-tuple.rs +++ b/src/test/debug-info/borrowed-tuple.rs @@ -41,4 +41,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/borrowed-unique-basic.rs b/src/test/debug-info/borrowed-unique-basic.rs index 52f5a2cba1ebe..893be617ac235 100644 --- a/src/test/debug-info/borrowed-unique-basic.rs +++ b/src/test/debug-info/borrowed-unique-basic.rs @@ -111,4 +111,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/boxed-struct.rs b/src/test/debug-info/boxed-struct.rs index 86162f0fa04cd..08f56154b62b8 100644 --- a/src/test/debug-info/boxed-struct.rs +++ b/src/test/debug-info/boxed-struct.rs @@ -56,4 +56,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/boxed-vec.rs b/src/test/debug-info/boxed-vec.rs index 8abead6519697..b6c6ce49ddaf4 100644 --- a/src/test/debug-info/boxed-vec.rs +++ b/src/test/debug-info/boxed-vec.rs @@ -33,4 +33,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/c-style-enum-in-composite.rs b/src/test/debug-info/c-style-enum-in-composite.rs index 47e433ea814ab..5a78666423a04 100644 --- a/src/test/debug-info/c-style-enum-in-composite.rs +++ b/src/test/debug-info/c-style-enum-in-composite.rs @@ -116,4 +116,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/c-style-enum.rs b/src/test/debug-info/c-style-enum.rs index d7cce4e6f3fb5..56c042f9e05fb 100644 --- a/src/test/debug-info/c-style-enum.rs +++ b/src/test/debug-info/c-style-enum.rs @@ -67,4 +67,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/destructured-fn-argument.rs b/src/test/debug-info/destructured-fn-argument.rs index 05718ab48909f..a3d53fb9efea2 100644 --- a/src/test/debug-info/destructured-fn-argument.rs +++ b/src/test/debug-info/destructured-fn-argument.rs @@ -315,4 +315,4 @@ fn main() { } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/destructured-local.rs b/src/test/debug-info/destructured-local.rs index f8db7981c941b..10d08ad66ba94 100644 --- a/src/test/debug-info/destructured-local.rs +++ b/src/test/debug-info/destructured-local.rs @@ -206,4 +206,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/evec-in-struct.rs b/src/test/debug-info/evec-in-struct.rs index 7e42690548e70..b23f3174705a9 100644 --- a/src/test/debug-info/evec-in-struct.rs +++ b/src/test/debug-info/evec-in-struct.rs @@ -85,4 +85,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/function-arguments.rs b/src/test/debug-info/function-arguments.rs index 1fe79b8e2a9e9..fba0a9b2dd2d1 100644 --- a/src/test/debug-info/function-arguments.rs +++ b/src/test/debug-info/function-arguments.rs @@ -45,4 +45,4 @@ fn fun(x: int, y: bool) -> (int, bool) { (x, y) } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-enum.rs b/src/test/debug-info/managed-enum.rs index 1a3600a7d8cb3..ab77d7180bae1 100644 --- a/src/test/debug-info/managed-enum.rs +++ b/src/test/debug-info/managed-enum.rs @@ -60,4 +60,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-pointer-within-unique-vec.rs b/src/test/debug-info/managed-pointer-within-unique-vec.rs index e42631599a9b9..facde86a305cc 100644 --- a/src/test/debug-info/managed-pointer-within-unique-vec.rs +++ b/src/test/debug-info/managed-pointer-within-unique-vec.rs @@ -34,4 +34,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/managed-pointer-within-unique.rs b/src/test/debug-info/managed-pointer-within-unique.rs index 3eb1c2ef01e55..9ea7b86f71141 100644 --- a/src/test/debug-info/managed-pointer-within-unique.rs +++ b/src/test/debug-info/managed-pointer-within-unique.rs @@ -44,4 +44,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/nil-enum.rs b/src/test/debug-info/nil-enum.rs index d3afd4b11f9cd..55ed84cd8f2ef 100644 --- a/src/test/debug-info/nil-enum.rs +++ b/src/test/debug-info/nil-enum.rs @@ -37,4 +37,4 @@ fn main() { } } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/option-like-enum.rs b/src/test/debug-info/option-like-enum.rs index 6d3b157d63e80..71ed72017613e 100644 --- a/src/test/debug-info/option-like-enum.rs +++ b/src/test/debug-info/option-like-enum.rs @@ -68,4 +68,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/packed-struct-with-destructor.rs b/src/test/debug-info/packed-struct-with-destructor.rs index 9ff91aa00d1c9..cd2f9af26ca27 100644 --- a/src/test/debug-info/packed-struct-with-destructor.rs +++ b/src/test/debug-info/packed-struct-with-destructor.rs @@ -216,4 +216,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/packed-struct.rs b/src/test/debug-info/packed-struct.rs index 859166cb023a3..ef4d07fdb4322 100644 --- a/src/test/debug-info/packed-struct.rs +++ b/src/test/debug-info/packed-struct.rs @@ -101,4 +101,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/simple-struct.rs b/src/test/debug-info/simple-struct.rs index 49e7bc255c10f..7346c86fadb6e 100644 --- a/src/test/debug-info/simple-struct.rs +++ b/src/test/debug-info/simple-struct.rs @@ -81,4 +81,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/simple-tuple.rs b/src/test/debug-info/simple-tuple.rs index f45294221af16..f86959b7ca1eb 100644 --- a/src/test/debug-info/simple-tuple.rs +++ b/src/test/debug-info/simple-tuple.rs @@ -48,4 +48,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/struct-in-struct.rs b/src/test/debug-info/struct-in-struct.rs index 04c5eec610b73..60ac4bcea6087 100644 --- a/src/test/debug-info/struct-in-struct.rs +++ b/src/test/debug-info/struct-in-struct.rs @@ -142,4 +142,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/struct-style-enum.rs b/src/test/debug-info/struct-style-enum.rs index 61bbd2e215ff6..77d7746e2df86 100644 --- a/src/test/debug-info/struct-style-enum.rs +++ b/src/test/debug-info/struct-style-enum.rs @@ -70,4 +70,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-in-struct.rs b/src/test/debug-info/tuple-in-struct.rs index 369c9fd28ccdf..863cb57bd235a 100644 --- a/src/test/debug-info/tuple-in-struct.rs +++ b/src/test/debug-info/tuple-in-struct.rs @@ -148,4 +148,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-in-tuple.rs b/src/test/debug-info/tuple-in-tuple.rs index 9c6805dae67d3..ae77d4723f1ad 100644 --- a/src/test/debug-info/tuple-in-tuple.rs +++ b/src/test/debug-info/tuple-in-tuple.rs @@ -47,4 +47,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/tuple-style-enum.rs b/src/test/debug-info/tuple-style-enum.rs index ba1d02bb62a3c..dd52ee22766d4 100644 --- a/src/test/debug-info/tuple-style-enum.rs +++ b/src/test/debug-info/tuple-style-enum.rs @@ -70,4 +70,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/debug-info/unique-enum.rs b/src/test/debug-info/unique-enum.rs index 443f641a85859..101b51632d9b6 100644 --- a/src/test/debug-info/unique-enum.rs +++ b/src/test/debug-info/unique-enum.rs @@ -60,4 +60,4 @@ fn main() { zzz(); } -fn zzz() {()} \ No newline at end of file +fn zzz() {()} diff --git a/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs b/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs index 59e82a038bc79..0e7572220a8b4 100644 --- a/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs +++ b/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs @@ -47,4 +47,4 @@ fn fun2() { pub fn main() { fun1(); fun2(); -} \ No newline at end of file +} diff --git a/src/test/run-pass/cast-mutable-trait.rs b/src/test/run-pass/cast-mutable-trait.rs index 633188b9a623b..84827a7a82042 100644 --- a/src/test/run-pass/cast-mutable-trait.rs +++ b/src/test/run-pass/cast-mutable-trait.rs @@ -31,4 +31,4 @@ fn main() { s2.foo(); bar(s2); bar(s as @mut T); -} \ No newline at end of file +} diff --git a/src/test/run-pass/conditional-debug-macro-off.rs b/src/test/run-pass/conditional-debug-macro-off.rs index f40c8112e0bba..decd310c9a7e1 100644 --- a/src/test/run-pass/conditional-debug-macro-off.rs +++ b/src/test/run-pass/conditional-debug-macro-off.rs @@ -14,4 +14,4 @@ fn main() { // only fails if debug! evaluates its argument. debug!({ if true { fail!() } }); -} \ No newline at end of file +} diff --git a/src/test/run-pass/conditional-debug-macro-on.rs b/src/test/run-pass/conditional-debug-macro-on.rs index 65b751a58264d..a0da137369c1b 100644 --- a/src/test/run-pass/conditional-debug-macro-on.rs +++ b/src/test/run-pass/conditional-debug-macro-on.rs @@ -18,4 +18,4 @@ fn main() { debug!({ if true { return; } }); fail!(); -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs index 6f6e8d79d8b92..3d53ec97491a1 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs @@ -49,4 +49,4 @@ pub fn main() { assert_eq!(es1.cmp(es2), ord); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-via-extension-struct-empty.rs b/src/test/run-pass/deriving-via-extension-struct-empty.rs index 8f6a319798626..74698b9db28bc 100644 --- a/src/test/run-pass/deriving-via-extension-struct-empty.rs +++ b/src/test/run-pass/deriving-via-extension-struct-empty.rs @@ -14,4 +14,4 @@ struct Foo; pub fn main() { assert_eq!(Foo, Foo); assert!(!(Foo != Foo)); -} \ No newline at end of file +} diff --git a/src/test/run-pass/enum-vec-initializer.rs b/src/test/run-pass/enum-vec-initializer.rs index ae590ad7d1f71..11893bbf657ec 100644 --- a/src/test/run-pass/enum-vec-initializer.rs +++ b/src/test/run-pass/enum-vec-initializer.rs @@ -21,4 +21,4 @@ fn main() { let v = [0, .. BAR2]; static BAR3:uint = BAR2; let v = [0, .. BAR3]; -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs index 17c5bb5c0e253..cb438aa0b2085 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs @@ -38,4 +38,4 @@ fn main() { assert_eq!(x, 6); assert_eq!(y, 60); -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators-hashmap.rs b/src/test/run-pass/foreach-external-iterators-hashmap.rs index 908adc0d7620d..9a5c2fa86fadb 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap.rs @@ -24,4 +24,4 @@ fn main() { } assert_eq!(x, 6); assert_eq!(y, 60); -} \ No newline at end of file +} diff --git a/src/test/run-pass/foreach-external-iterators.rs b/src/test/run-pass/foreach-external-iterators.rs index c6f903821dd0e..0933ac09243c9 100644 --- a/src/test/run-pass/foreach-external-iterators.rs +++ b/src/test/run-pass/foreach-external-iterators.rs @@ -15,4 +15,4 @@ fn main() { y += *i } assert!(y == 100); -} \ No newline at end of file +} diff --git a/src/test/run-pass/func-arg-incomplete-pattern.rs b/src/test/run-pass/func-arg-incomplete-pattern.rs index b08d3beae1bfa..6144e46593677 100644 --- a/src/test/run-pass/func-arg-incomplete-pattern.rs +++ b/src/test/run-pass/func-arg-incomplete-pattern.rs @@ -17,4 +17,4 @@ fn main() { let f = Foo {x: obj, y: ~2}; let xptr = foo(f); assert_eq!(objptr, xptr); -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index aa9be2203c6b2..a2fc6392b75fd 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -47,7 +47,7 @@ fn add_interface(store: int, managed_ip: ~str, data: extra::json::Json) -> (~str (label, bool_value(false)) } _ => { - error!("Expected dict for %s interfaces but found %?", managed_ip, data); + error!("Expected dict for %s interfaces, found %?", managed_ip, data); (~"gnos:missing-interface", bool_value(true)) } } @@ -65,7 +65,7 @@ fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, extra::jso } _ => { - error!("Expected list for %s interfaces but found %?", managed_ip, + error!("Expected list for %s interfaces, found %?", managed_ip, device.get(&~"interfaces")); ~[] } diff --git a/src/test/run-pass/issue-4252.rs b/src/test/run-pass/issue-4252.rs index de1f630a245b8..ebbdf6cc230ac 100644 --- a/src/test/run-pass/issue-4252.rs +++ b/src/test/run-pass/issue-4252.rs @@ -34,4 +34,4 @@ impl Drop for Z { fn main() { let y = Y; let _z = Z{x: y}; -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-6141-leaking-owned-fn.rs b/src/test/run-pass/issue-6141-leaking-owned-fn.rs index fe11bb0a972ad..cd48eba0f2322 100644 --- a/src/test/run-pass/issue-6141-leaking-owned-fn.rs +++ b/src/test/run-pass/issue-6141-leaking-owned-fn.rs @@ -5,4 +5,4 @@ fn run(f: &fn()) { fn main() { let f: ~fn() = || (); run(f); -} \ No newline at end of file +} diff --git a/src/test/run-pass/issue-6341.rs b/src/test/run-pass/issue-6341.rs index 29fc074430584..dfead893392be 100644 --- a/src/test/run-pass/issue-6341.rs +++ b/src/test/run-pass/issue-6341.rs @@ -15,4 +15,4 @@ impl Drop for A { fn drop(&self) {} } -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/test/run-pass/move-out-of-field.rs b/src/test/run-pass/move-out-of-field.rs index a3c2872803adc..04375052c3d6b 100644 --- a/src/test/run-pass/move-out-of-field.rs +++ b/src/test/run-pass/move-out-of-field.rs @@ -20,4 +20,4 @@ fn main() { sb.append("World!"); let str = to_str(sb); assert_eq!(str, ~"Hello, World!"); -} \ No newline at end of file +} diff --git a/src/test/run-pass/option_addition.rs b/src/test/run-pass/option_addition.rs index fe39d1b11d3b8..ac592d92cbadd 100644 --- a/src/test/run-pass/option_addition.rs +++ b/src/test/run-pass/option_addition.rs @@ -20,7 +20,7 @@ pub fn main() { match nope { None => (), - Some(foo) => fail!("expected None, but found %?", foo) + Some(foo) => fail!("expected None, found %?", foo) } assert_eq!(foo, somefoo.get()); assert_eq!(bar, somebar.get()); diff --git a/src/test/run-pass/rt-start-main-thread.rs b/src/test/run-pass/rt-start-main-thread.rs index 8328e7416c579..2edf99e19430e 100644 --- a/src/test/run-pass/rt-start-main-thread.rs +++ b/src/test/run-pass/rt-start-main-thread.rs @@ -18,4 +18,4 @@ fn start(argc: int, argv: **u8, crate_map: *u8) -> int { info!("running on another thread"); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/unique-object-move.rs b/src/test/run-pass/unique-object-move.rs index 540de1652138b..e067fd49b1d13 100644 --- a/src/test/run-pass/unique-object-move.rs +++ b/src/test/run-pass/unique-object-move.rs @@ -21,4 +21,4 @@ impl EventLoop for UvEventLoop { } pub fn main() { let loop_: ~EventLoop = ~UvEventLoop { uvio: 0 } as ~EventLoop; let loop2_ = loop_; -} \ No newline at end of file +} From 2c581e12fc16a85d34f55756ed6fcec7bcafe508 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 5 Aug 2013 10:37:53 -0700 Subject: [PATCH 45/62] Use TreeMap's ord implementation for Json Closes #4430 --- src/libextra/json.rs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/libextra/json.rs b/src/libextra/json.rs index cd35cbdf30980..ec9cb902d3d29 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -26,7 +26,6 @@ use std::to_str; use serialize::Encodable; use serialize; -use sort::Sort; use treemap::TreeMap; /// Represents a json value @@ -1152,23 +1151,7 @@ impl Ord for Json { Object(ref d0) => { match *other { Number(_) | String(_) | Boolean(_) | List(_) => false, - Object(ref d1) => { - let mut d0_flat = ~[]; - let mut d1_flat = ~[]; - - // FIXME #4430: this is horribly inefficient... - for (k, v) in d0.iter() { - d0_flat.push((@(*k).clone(), @(*v).clone())); - } - d0_flat.qsort(); - - for (k, v) in d1.iter() { - d1_flat.push((@(*k).clone(), @(*v).clone())); - } - d1_flat.qsort(); - - d0_flat < d1_flat - } + Object(ref d1) => d0 < d1, Null => true } } From abd2ffbd44d117af4a6dd92f1a8b831e7a0ceadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Sun, 4 Aug 2013 01:59:24 +0200 Subject: [PATCH 46/62] Updated std::Option, std::Either and std::Result - Made naming schemes consistent between Option, Result and Either - Changed Options Add implementation to work like the maybe monad (return None if any of the inputs is None) - Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead --- src/compiletest/compiletest.rs | 6 +- src/compiletest/runtest.rs | 12 +- src/libextra/base64.rs | 20 +- src/libextra/fileinput.rs | 4 +- src/libextra/getopts.rs | 8 +- src/libextra/num/bigint.rs | 12 +- src/libextra/ringbuf.rs | 12 +- src/libextra/semver.rs | 4 +- src/libextra/smallintmap.rs | 6 +- src/libextra/test.rs | 57 ++- src/libextra/url.rs | 4 +- src/librustc/back/link.rs | 4 +- src/librustc/back/passes.rs | 6 +- src/librustc/driver/driver.rs | 2 +- src/librustc/front/test.rs | 4 +- src/librustc/middle/astencode.rs | 10 +- src/librustc/middle/borrowck/check_loans.rs | 2 +- src/librustc/middle/check_match.rs | 12 +- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/privacy.rs | 2 +- src/librustc/middle/resolve.rs | 4 +- src/librustc/middle/trans/_match.rs | 8 +- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/base.rs | 22 +- src/librustc/middle/trans/build.rs | 4 +- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/closure.rs | 4 +- src/librustc/middle/trans/common.rs | 4 +- src/librustc/middle/trans/controlflow.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 4 +- src/librustc/middle/trans/foreign.rs | 20 +- src/librustc/middle/trans/glue.rs | 4 +- src/librustc/middle/trans/monomorphize.rs | 4 +- src/librustc/middle/trans/reflect.rs | 4 +- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/ty.rs | 32 +- src/librustc/middle/typeck/astconv.rs | 6 +- src/librustc/middle/typeck/check/_match.rs | 4 +- src/librustc/middle/typeck/check/method.rs | 6 +- src/librustc/middle/typeck/check/mod.rs | 4 +- src/librustc/middle/typeck/infer/glb.rs | 2 +- src/librustc/middle/typeck/mod.rs | 2 +- src/librustc/middle/typeck/rscope.rs | 1 + src/librustc/util/enum_set.rs | 2 +- src/librustdoc/attr_pass.rs | 4 +- src/librustdoc/config.rs | 30 +- src/librustdoc/desc_to_brief_pass.rs | 2 +- src/librustdoc/doc.rs | 2 +- src/librustdoc/markdown_index_pass.rs | 12 +- src/librustdoc/markdown_pass.rs | 8 +- src/librustdoc/sectionalize_pass.rs | 4 +- src/librustdoc/tystr_pass.rs | 6 +- src/librusti/rusti.rs | 10 +- src/librustpkg/rustpkg.rs | 4 +- src/librustpkg/util.rs | 2 +- src/libstd/at_vec.rs | 6 +- src/libstd/either.rs | 366 +++++++++--------- src/libstd/local_data.rs | 14 +- src/libstd/option.rs | 212 +++++----- src/libstd/os.rs | 6 +- src/libstd/rand.rs | 4 +- src/libstd/result.rs | 327 +++++++--------- src/libstd/rt/io/flate.rs | 2 +- src/libstd/rt/io/mod.rs | 34 ++ src/libstd/rt/mod.rs | 2 +- src/libstd/rt/task.rs | 4 +- src/libstd/rt/test.rs | 4 +- src/libstd/rt/util.rs | 2 +- src/libstd/rt/uv/net.rs | 6 +- src/libstd/rt/uv/uvio.rs | 2 +- src/libstd/str.rs | 4 +- src/libstd/task/mod.rs | 2 +- src/libstd/vec.rs | 6 +- src/libsyntax/abi.rs | 4 +- src/libsyntax/ast.rs | 4 +- src/libsyntax/attr.rs | 2 +- src/libsyntax/ext/base.rs | 16 +- src/libsyntax/ext/deriving/generic.rs | 2 +- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/ext/source_util.rs | 6 +- src/libsyntax/parse/parser.rs | 8 +- src/libsyntax/print/pprust.rs | 10 +- src/test/bench/core-map.rs | 2 +- src/test/bench/core-set.rs | 2 +- src/test/bench/core-uint-to-str.rs | 2 +- src/test/bench/graph500-bfs.rs | 4 +- src/test/bench/msgsend-pipes-shared.rs | 4 +- src/test/bench/msgsend-pipes.rs | 4 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 4 +- src/test/bench/msgsend-ring-rw-arcs.rs | 4 +- src/test/bench/shootout-ackermann.rs | 2 +- src/test/bench/shootout-binarytrees.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 2 +- src/test/bench/shootout-fannkuch-redux.rs | 2 +- src/test/bench/shootout-fasta-redux.rs | 2 +- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-fibo.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/bench/shootout-nbody.rs | 2 +- src/test/bench/shootout-pfib.rs | 2 +- src/test/bench/shootout-spectralnorm.rs | 2 +- src/test/bench/shootout-threadring.rs | 4 +- src/test/bench/std-smallintmap.rs | 4 +- src/test/bench/sudoku.rs | 6 +- .../bench/task-perf-jargon-metal-smoke.rs | 2 +- src/test/bench/task-perf-linked-failure.rs | 2 +- src/test/bench/task-perf-spawnalot.rs | 2 +- .../arc-rw-read-mode-shouldnt-escape.rs | 2 +- .../arc-rw-write-mode-shouldnt-escape.rs | 2 +- src/test/run-fail/result-get-fail.rs | 4 +- .../run-pass/borrowck-wg-borrow-mut-to-imm.rs | 2 +- .../run-pass/borrowed-ptr-pattern-option.rs | 2 +- src/test/run-pass/option_addition.rs | 32 +- src/test/run-pass/region-dependent-addr-of.rs | 6 +- 114 files changed, 789 insertions(+), 814 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index ce715ac2db5ad..4e4261e8b2bbd 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -130,7 +130,7 @@ pub fn parse_config(args: ~[~str]) -> config { ratchet_noise_percent: getopts::opt_maybe_str(matches, "ratchet-noise-percent").map(|s| - f64::from_str(*s).get()), + f64::from_str(*s).unwrap()), runtool: getopts::opt_maybe_str(matches, "runtool"), rustcflags: getopts::opt_maybe_str(matches, "rustcflags"), jit: getopts::opt_present(matches, "jit"), @@ -266,7 +266,7 @@ pub fn is_test(config: &config, testfile: &Path) -> bool { _ => ~[~".rc", ~".rs"] }; let invalid_prefixes = ~[~".", ~"#", ~"~"]; - let name = testfile.filename().get(); + let name = testfile.filename().unwrap(); let mut valid = false; @@ -299,7 +299,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName { fn shorten(path: &Path) -> ~str { let filename = path.filename(); let dir = path.pop().filename(); - fmt!("%s/%s", dir.get_or_default(~""), filename.get_or_default(~"")) + fmt!("%s/%s", dir.unwrap_or_default(~""), filename.unwrap_or_default(~"")) } test::DynTestName(fmt!("[%s] %s", diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 74b4a1de5e0d1..5c1cc78d678f3 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -145,7 +145,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { let rounds = match props.pp_exact { Some(_) => 1, None => 2 }; - let mut srcs = ~[io::read_whole_file_str(testfile).get()]; + let mut srcs = ~[io::read_whole_file_str(testfile).unwrap()]; let mut round = 0; while round < rounds { @@ -166,7 +166,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { match props.pp_exact { Some(ref file) => { let filepath = testfile.dir_path().push_rel(file); - io::read_whole_file_str(&filepath).get() + io::read_whole_file_str(&filepath).unwrap() } None => { srcs[srcs.len() - 2u].clone() } }; @@ -448,7 +448,7 @@ fn scan_until_char(haystack: &str, needle: char, idx: &mut uint) -> bool { if opt.is_none() { return false; } - *idx = opt.get(); + *idx = opt.unwrap(); return true; } @@ -709,7 +709,7 @@ fn aux_output_dir_name(config: &config, testfile: &Path) -> Path { } fn output_testname(testfile: &Path) -> Path { - Path(testfile.filestem().get()) + Path(testfile.filestem().unwrap()) } fn output_base_name(config: &config, testfile: &Path) -> Path { @@ -878,7 +878,7 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path { if suffix.len() == 0 { (*p).clone() } else { - let stem = p.filestem().get(); + let stem = p.filestem().unwrap(); p.with_filestem(stem + "-" + suffix) } } @@ -938,7 +938,7 @@ fn disassemble_extract(config: &config, _props: &TestProps, fn count_extracted_lines(p: &Path) -> uint { - let x = io::read_whole_file_str(&p.with_filetype("ll")).get(); + let x = io::read_whole_file_str(&p.with_filetype("ll")).unwrap(); x.line_iter().len_() } diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index f2cbcf86935e7..550b891a4db16 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -322,24 +322,24 @@ mod test { #[test] fn test_from_base64_basic() { - assert_eq!("".from_base64().get(), "".as_bytes().to_owned()); - assert_eq!("Zg==".from_base64().get(), "f".as_bytes().to_owned()); - assert_eq!("Zm8=".from_base64().get(), "fo".as_bytes().to_owned()); - assert_eq!("Zm9v".from_base64().get(), "foo".as_bytes().to_owned()); - assert_eq!("Zm9vYg==".from_base64().get(), "foob".as_bytes().to_owned()); - assert_eq!("Zm9vYmE=".from_base64().get(), "fooba".as_bytes().to_owned()); - assert_eq!("Zm9vYmFy".from_base64().get(), "foobar".as_bytes().to_owned()); + assert_eq!("".from_base64().unwrap(), "".as_bytes().to_owned()); + assert_eq!("Zg==".from_base64().unwrap(), "f".as_bytes().to_owned()); + assert_eq!("Zm8=".from_base64().unwrap(), "fo".as_bytes().to_owned()); + assert_eq!("Zm9v".from_base64().unwrap(), "foo".as_bytes().to_owned()); + assert_eq!("Zm9vYg==".from_base64().unwrap(), "foob".as_bytes().to_owned()); + assert_eq!("Zm9vYmE=".from_base64().unwrap(), "fooba".as_bytes().to_owned()); + assert_eq!("Zm9vYmFy".from_base64().unwrap(), "foobar".as_bytes().to_owned()); } #[test] fn test_from_base64_newlines() { - assert_eq!("Zm9v\r\nYmFy".from_base64().get(), + assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(), "foobar".as_bytes().to_owned()); } #[test] fn test_from_base64_urlsafe() { - assert_eq!("-_8".from_base64().get(), "+/8=".from_base64().get()); + assert_eq!("-_8".from_base64().unwrap(), "+/8=".from_base64().unwrap()); } #[test] @@ -364,7 +364,7 @@ mod test { push(random()); } }; - assert_eq!(v.to_base64(STANDARD).from_base64().get(), v); + assert_eq!(v.to_base64(STANDARD).from_base64().unwrap(), v); } } diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index a161989c37516..7a36b25eac57a 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -526,8 +526,8 @@ mod test { do input_vec_state(filenames) |line, state| { let nums: ~[&str] = line.split_iter(' ').collect(); - let file_num = uint::from_str(nums[0]).get(); - let line_num = uint::from_str(nums[1]).get(); + let file_num = uint::from_str(nums[0]).unwrap(); + let line_num = uint::from_str(nums[1]).unwrap(); assert_eq!(line_num, state.line_num_file); assert_eq!(file_num * 3 + line_num, state.line_num); true diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index b9ee38317f321..15aac8ef47c9e 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -196,7 +196,7 @@ fn find_opt(opts: &[Opt], nm: Name) -> Option { * The type returned when the command line does not conform to the * expected format. Pass this value to to get an error message. */ -#[deriving(Clone, Eq)] +#[deriving(Clone, Eq, ToStr)] pub enum Fail_ { ArgumentMissing(~str), UnrecognizedOption(~str), @@ -288,7 +288,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { None => { let arg_follows = last_valid_opt_id.is_some() && - match opts[last_valid_opt_id.get()] + match opts[last_valid_opt_id.unwrap()] .hasarg { Yes | Maybe => true, @@ -322,7 +322,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { } Maybe => { if !i_arg.is_none() { - vals[optid].push(Val((i_arg.clone()).get())); + vals[optid].push(Val((i_arg.clone()).unwrap())); } else if name_pos < names.len() || i + 1 == l || is_arg(args[i + 1]) { vals[optid].push(Given); @@ -330,7 +330,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { } Yes => { if !i_arg.is_none() { - vals[optid].push(Val(i_arg.clone().get())); + vals[optid].push(Val(i_arg.clone().unwrap())); } else if i + 1 == l { return Err(ArgumentMissing(name_str(nm))); } else { i += 1; vals[optid].push(Val(args[i].clone())); } diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index ab843fe65464b..bced00902c95f 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -1510,11 +1510,11 @@ mod biguint_tests { #[test] fn test_is_even() { - assert!(FromStr::from_str::("1").get().is_odd()); - assert!(FromStr::from_str::("2").get().is_even()); - assert!(FromStr::from_str::("1000").get().is_even()); - assert!(FromStr::from_str::("1000000000000000000000").get().is_even()); - assert!(FromStr::from_str::("1000000000000000000001").get().is_odd()); + assert!(FromStr::from_str::("1").unwrap().is_odd()); + assert!(FromStr::from_str::("2").unwrap().is_even()); + assert!(FromStr::from_str::("1000").unwrap().is_even()); + assert!(FromStr::from_str::("1000000000000000000000").unwrap().is_even()); + assert!(FromStr::from_str::("1000000000000000000001").unwrap().is_odd()); assert!((BigUint::from_uint(1) << 64).is_even()); assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd()); } @@ -1595,7 +1595,7 @@ mod biguint_tests { let &(ref n, ref rs) = num_pair; for str_pair in rs.iter() { let &(ref radix, ref str) = str_pair; - assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).get()); + assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).unwrap()); } } diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index 89d23191a7634..9833bd5d1cbf2 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -437,12 +437,12 @@ mod tests { assert_eq!(deq.len(), 3); deq.push_back(d.clone()); assert_eq!(deq.len(), 4); - assert_eq!((*deq.front().get()).clone(), b.clone()); - assert_eq!((*deq.back().get()).clone(), d.clone()); - assert_eq!(deq.pop_front().get(), b.clone()); - assert_eq!(deq.pop_back().get(), d.clone()); - assert_eq!(deq.pop_back().get(), c.clone()); - assert_eq!(deq.pop_back().get(), a.clone()); + assert_eq!((*deq.front().unwrap()).clone(), b.clone()); + assert_eq!((*deq.back().unwrap()).clone(), d.clone()); + assert_eq!(deq.pop_front().unwrap(), b.clone()); + assert_eq!(deq.pop_back().unwrap(), d.clone()); + assert_eq!(deq.pop_back().unwrap(), c.clone()); + assert_eq!(deq.pop_back().unwrap(), a.clone()); assert_eq!(deq.len(), 0); deq.push_back(c.clone()); assert_eq!(deq.len(), 1); diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index 8c298a7373d96..b0f89e219d8d8 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -386,8 +386,8 @@ fn test_spec_order() { "1.0.0"]; let mut i = 1; while i < vs.len() { - let a = parse(vs[i-1]).get(); - let b = parse(vs[i]).get(); + let a = parse(vs[i-1]).unwrap(); + let b = parse(vs[i]).unwrap(); assert!(a < b); i += 1; } diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 52e6c1fcc1c90..3f62317eb8908 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -366,9 +366,9 @@ mod test_map { map.update_with_key(3, 2, addMoreToCount); // check the total counts - assert_eq!(map.find(&3).get(), &10); - assert_eq!(map.find(&5).get(), &3); - assert_eq!(map.find(&9).get(), &1); + assert_eq!(map.find(&3).unwrap(), &10); + assert_eq!(map.find(&5).unwrap(), &3); + assert_eq!(map.find(&9).unwrap(), &1); // sadly, no sevens were counted assert!(map.find(&7).is_none()); diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 02481693eb971..e87be14622674 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -247,9 +247,8 @@ pub fn parse_opts(args: &[~str]) -> OptRes { let ratchet_metrics = getopts::opt_maybe_str(&matches, "ratchet-metrics"); let ratchet_metrics = ratchet_metrics.map(|s| Path(*s)); - let ratchet_noise_percent = - getopts::opt_maybe_str(&matches, "ratchet-noise-percent"); - let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).get()); + let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent"); + let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).unwrap()); let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics"); let save_metrics = save_metrics.map(|s| Path(*s)); @@ -631,8 +630,8 @@ fn should_sort_failures_before_printing_them() { st.write_failures(); }; - let apos = s.find_str("a").get(); - let bpos = s.find_str("b").get(); + let apos = s.find_str("a").unwrap(); + let bpos = s.find_str("b").unwrap(); assert!(apos < bpos); } @@ -868,7 +867,7 @@ impl MetricMap { pub fn load(p: &Path) -> MetricMap { assert!(os::path_exists(p)); let f = io::file_reader(p).unwrap(); - let mut decoder = json::Decoder(json::from_reader(f).get()); + let mut decoder = json::Decoder(json::from_reader(f).unwrap()); MetricMap(Decodable::decode(&mut decoder)) } @@ -1207,7 +1206,7 @@ mod tests { either::Left(o) => o, _ => fail!("Malformed arg in first_free_arg_should_be_a_filter") }; - assert!("filter" == opts.filter.clone().get()); + assert!("filter" == opts.filter.clone().unwrap()); } #[test] @@ -1346,28 +1345,28 @@ mod tests { let diff1 = m2.compare_to_old(&m1, None); - assert_eq!(*(diff1.find(&~"in-both-noise").get()), LikelyNoise); - assert_eq!(*(diff1.find(&~"in-first-noise").get()), MetricRemoved); - assert_eq!(*(diff1.find(&~"in-second-noise").get()), MetricAdded); - assert_eq!(*(diff1.find(&~"in-both-want-downwards-but-regressed").get()), + assert_eq!(*(diff1.find(&~"in-both-noise").unwrap()), LikelyNoise); + assert_eq!(*(diff1.find(&~"in-first-noise").unwrap()), MetricRemoved); + assert_eq!(*(diff1.find(&~"in-second-noise").unwrap()), MetricAdded); + assert_eq!(*(diff1.find(&~"in-both-want-downwards-but-regressed").unwrap()), Regression(100.0)); - assert_eq!(*(diff1.find(&~"in-both-want-downwards-and-improved").get()), + assert_eq!(*(diff1.find(&~"in-both-want-downwards-and-improved").unwrap()), Improvement(50.0)); - assert_eq!(*(diff1.find(&~"in-both-want-upwards-but-regressed").get()), + assert_eq!(*(diff1.find(&~"in-both-want-upwards-but-regressed").unwrap()), Regression(50.0)); - assert_eq!(*(diff1.find(&~"in-both-want-upwards-and-improved").get()), + assert_eq!(*(diff1.find(&~"in-both-want-upwards-and-improved").unwrap()), Improvement(100.0)); assert_eq!(diff1.len(), 7); let diff2 = m2.compare_to_old(&m1, Some(200.0)); - assert_eq!(*(diff2.find(&~"in-both-noise").get()), LikelyNoise); - assert_eq!(*(diff2.find(&~"in-first-noise").get()), MetricRemoved); - assert_eq!(*(diff2.find(&~"in-second-noise").get()), MetricAdded); - assert_eq!(*(diff2.find(&~"in-both-want-downwards-but-regressed").get()), LikelyNoise); - assert_eq!(*(diff2.find(&~"in-both-want-downwards-and-improved").get()), LikelyNoise); - assert_eq!(*(diff2.find(&~"in-both-want-upwards-but-regressed").get()), LikelyNoise); - assert_eq!(*(diff2.find(&~"in-both-want-upwards-and-improved").get()), LikelyNoise); + assert_eq!(*(diff2.find(&~"in-both-noise").unwrap()), LikelyNoise); + assert_eq!(*(diff2.find(&~"in-first-noise").unwrap()), MetricRemoved); + assert_eq!(*(diff2.find(&~"in-second-noise").unwrap()), MetricAdded); + assert_eq!(*(diff2.find(&~"in-both-want-downwards-but-regressed").unwrap()), LikelyNoise); + assert_eq!(*(diff2.find(&~"in-both-want-downwards-and-improved").unwrap()), LikelyNoise); + assert_eq!(*(diff2.find(&~"in-both-want-upwards-but-regressed").unwrap()), LikelyNoise); + assert_eq!(*(diff2.find(&~"in-both-want-upwards-and-improved").unwrap()), LikelyNoise); assert_eq!(diff2.len(), 7); } @@ -1391,28 +1390,28 @@ mod tests { let (diff1, ok1) = m2.ratchet(&pth, None); assert_eq!(ok1, false); assert_eq!(diff1.len(), 2); - assert_eq!(*(diff1.find(&~"runtime").get()), Regression(10.0)); - assert_eq!(*(diff1.find(&~"throughput").get()), LikelyNoise); + assert_eq!(*(diff1.find(&~"runtime").unwrap()), Regression(10.0)); + assert_eq!(*(diff1.find(&~"throughput").unwrap()), LikelyNoise); // Check that it was not rewritten. let m3 = MetricMap::load(&pth); assert_eq!(m3.len(), 2); - assert_eq!(*(m3.find(&~"runtime").get()), Metric { value: 1000.0, noise: 2.0 }); - assert_eq!(*(m3.find(&~"throughput").get()), Metric { value: 50.0, noise: 2.0 }); + assert_eq!(*(m3.find(&~"runtime").unwrap()), Metric { value: 1000.0, noise: 2.0 }); + assert_eq!(*(m3.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 }); // Ask for a ratchet with an explicit noise-percentage override, // that should advance. let (diff2, ok2) = m2.ratchet(&pth, Some(10.0)); assert_eq!(ok2, true); assert_eq!(diff2.len(), 2); - assert_eq!(*(diff2.find(&~"runtime").get()), LikelyNoise); - assert_eq!(*(diff2.find(&~"throughput").get()), LikelyNoise); + assert_eq!(*(diff2.find(&~"runtime").unwrap()), LikelyNoise); + assert_eq!(*(diff2.find(&~"throughput").unwrap()), LikelyNoise); // Check that it was rewritten. let m4 = MetricMap::load(&pth); assert_eq!(m4.len(), 2); - assert_eq!(*(m4.find(&~"runtime").get()), Metric { value: 1100.0, noise: 2.0 }); - assert_eq!(*(m4.find(&~"throughput").get()), Metric { value: 50.0, noise: 2.0 }); + assert_eq!(*(m4.find(&~"runtime").unwrap()), Metric { value: 1100.0, noise: 2.0 }); + assert_eq!(*(m4.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 }); os::remove_dir_recursive(&dpth); } diff --git a/src/libextra/url.rs b/src/libextra/url.rs index 523c3521f8665..581bdf2a294db 100644 --- a/src/libextra/url.rs +++ b/src/libextra/url.rs @@ -134,7 +134,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str { match rdr.read_char() { '%' => { let bytes = rdr.read_bytes(2u); - let ch = uint::parse_bytes(bytes, 16u).get() as char; + let ch = uint::parse_bytes(bytes, 16u).unwrap() as char; if full_url { // Only decode some characters: @@ -257,7 +257,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> { let ch = match ch { '%' => { let bytes = rdr.read_bytes(2u); - uint::parse_bytes(bytes, 16u).get() as char + uint::parse_bytes(bytes, 16u).unwrap() as char } '+' => ' ', ch => ch diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index f066ede65f976..637ea159d79d0 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -912,7 +912,7 @@ pub fn link_args(sess: Session, } let dir = cratepath.dirname(); if dir != ~"" { args.push(~"-L" + dir); } - let libarg = unlib(sess.targ_cfg, cratepath.filestem().get()); + let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap()); args.push(~"-l" + libarg); } @@ -950,7 +950,7 @@ pub fn link_args(sess: Session, // be rpathed if sess.targ_cfg.os == session::os_macos { args.push(~"-Wl,-install_name,@rpath/" - + output.filename().get()); + + output.filename().unwrap()); } } diff --git a/src/librustc/back/passes.rs b/src/librustc/back/passes.rs index b77ed10c21ba4..35d070baa9bac 100644 --- a/src/librustc/back/passes.rs +++ b/src/librustc/back/passes.rs @@ -319,7 +319,7 @@ fn passes_exist() { if !pass.is_some() { failed.push(name); } else { - unsafe { llvm::LLVMDestroyPass(pass.get()) } + unsafe { llvm::LLVMDestroyPass(pass.unwrap()) } } } for &(name,_) in transform_passes.iter() { @@ -327,7 +327,7 @@ fn passes_exist() { if !pass.is_some() { failed.push(name); } else { - unsafe { llvm::LLVMDestroyPass(pass.get()) } + unsafe { llvm::LLVMDestroyPass(pass.unwrap()) } } } for &(name,_) in utility_passes.iter() { @@ -335,7 +335,7 @@ fn passes_exist() { if !pass.is_some() { failed.push(name); } else { - unsafe { llvm::LLVMDestroyPass(pass.get()) } + unsafe { llvm::LLVMDestroyPass(pass.unwrap()) } } } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 3daacf38036ae..2c642d54253b6 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -924,7 +924,7 @@ pub fn build_output_filenames(input: &input, }; let mut stem = match *input { - file_input(ref ifile) => (*ifile).filestem().get().to_managed(), + file_input(ref ifile) => (*ifile).filestem().unwrap().to_managed(), str_input(_) => @"rust_out" }; diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 8ca68251cb891..d2d2a8b4be99d 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -308,7 +308,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item { #[main]; extra::test::test_main_static(::std::os::args(), TESTS); } - )).get(); + )).unwrap(); let testmod = ast::_mod { view_items: view_items, @@ -366,7 +366,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item { pub static TESTS : &'static [self::extra::test::TestDescAndFn] = $test_descs ; - )).get() + )).unwrap() } fn is_extra(cx: &TestCtxt) -> bool { diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 34f4425a871dd..b909f70440a82 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -328,7 +328,7 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item { match *ii { //hack: we're not dropping items - ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()), + ast::ii_item(i) => ast::ii_item(fld.fold_item(i).unwrap()), ast::ii_method(d, is_provided, m) => ast::ii_method(d, is_provided, fld.fold_method(m)), ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)) @@ -350,7 +350,7 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) }); match ii { - ast::ii_item(i) => ast::ii_item(fld.fold_item(i).get()), + ast::ii_item(i) => ast::ii_item(fld.fold_item(i).unwrap()), ast::ii_method(d, is_provided, m) => ast::ii_method(xcx.tr_def_id(d), is_provided, fld.fold_method(m)), ast::ii_foreign(i) => ast::ii_foreign(fld.fold_foreign_item(i)), @@ -1275,7 +1275,7 @@ fn mk_ctxt() -> @fake_ext_ctxt { fn roundtrip(in_item: Option<@ast::item>) { use std::io; - let in_item = in_item.get(); + let in_item = in_item.unwrap(); let bytes = do io::with_bytes_writer |wr| { let mut ebml_w = writer::Encoder(wr); encode_item_ast(&mut ebml_w, in_item); @@ -1321,13 +1321,13 @@ fn test_simplification() { fn eq_int(a: int, b: int) -> bool { a == b } return alist {eq_fn: eq_int, data: ~[]}; } - ).get()); + ).unwrap()); let item_out = simplify_ast(&item_in); let item_exp = ast::ii_item(quote_item!( fn new_int_alist() -> alist { return alist {eq_fn: eq_int, data: ~[]}; } - ).get()); + ).unwrap()); match (item_out, item_exp) { (ast::ii_item(item_out), ast::ii_item(item_exp)) => { assert!(pprust::item_to_str(item_out, diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 646840f1e3063..c3bb2000447f7 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -307,7 +307,7 @@ impl<'self> CheckLoanCtxt<'self> { // if they cannot already have been assigned if self.is_local_variable(cmt) { assert!(cmt.mutbl.is_immutable()); // no "const" locals - let lp = opt_loan_path(cmt).get(); + let lp = opt_loan_path(cmt).unwrap(); do self.move_data.each_assignment_of(expr.id, lp) |assign| { self.bccx.report_reassigned_immutable_variable( expr.span, diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 4de096428f26f..1b420b9c06a55 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -109,7 +109,7 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[arm]) { let pat_matches_nan: &fn(@pat) -> bool = |p| { match cx.tcx.def_map.find(&p.id) { Some(&def_static(did, false)) => { - let const_expr = lookup_const_by_id(cx.tcx, did).get(); + let const_expr = lookup_const_by_id(cx.tcx, did).unwrap(); match eval_const_expr(cx.tcx, const_expr) { const_float(f) if f.is_NaN() => true, _ => false @@ -304,7 +304,7 @@ pub fn is_useful_specialized(cx: &MatchCheckCtxt, -> useful { let ms = m.iter().filter_map(|r| specialize(cx, *r, &ctor, arity, lty)).collect::(); let could_be_useful = is_useful( - cx, &ms, specialize(cx, v, &ctor, arity, lty).get()); + cx, &ms, specialize(cx, v, &ctor, arity, lty).unwrap()); match could_be_useful { useful_ => useful(lty, ctor), ref u => *u, @@ -319,7 +319,7 @@ pub fn pat_ctor_id(cx: &MatchCheckCtxt, p: @pat) -> Option { match cx.tcx.def_map.find(&pat.id) { Some(&def_variant(_, id)) => Some(variant(id)), Some(&def_static(did, false)) => { - let const_expr = lookup_const_by_id(cx.tcx, did).get(); + let const_expr = lookup_const_by_id(cx.tcx, did).unwrap(); Some(val(eval_const_expr(cx.tcx, const_expr))) } _ => None @@ -515,7 +515,7 @@ pub fn specialize(cx: &MatchCheckCtxt, } Some(&def_static(did, _)) => { let const_expr = - lookup_const_by_id(cx.tcx, did).get(); + lookup_const_by_id(cx.tcx, did).unwrap(); let e_v = eval_const_expr(cx.tcx, const_expr); let match_ = match *ctor_id { val(ref v) => { @@ -565,7 +565,7 @@ pub fn specialize(cx: &MatchCheckCtxt, match cx.tcx.def_map.get_copy(&pat_id) { def_static(did, _) => { let const_expr = - lookup_const_by_id(cx.tcx, did).get(); + lookup_const_by_id(cx.tcx, did).unwrap(); let e_v = eval_const_expr(cx.tcx, const_expr); let match_ = match *ctor_id { val(ref v) => @@ -867,7 +867,7 @@ pub fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, "cannot bind by-move and by-ref \ in the same pattern"); tcx.sess.span_note( - by_ref_span.get(), + by_ref_span.unwrap(), "by-ref binding occurs here"); } }; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 330e44893f04a..77e81709a03d7 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -466,9 +466,9 @@ pub fn lit_to_const(lit: &lit) -> const_val { lit_int(n, _) => const_int(n), lit_uint(n, _) => const_uint(n), lit_int_unsuffixed(n) => const_int(n), - lit_float(n, _) => const_float(float::from_str(n).get() as f64), + lit_float(n, _) => const_float(float::from_str(n).unwrap() as f64), lit_float_unsuffixed(n) => - const_float(float::from_str(n).get() as f64), + const_float(float::from_str(n).unwrap() as f64), lit_nil => const_int(0i64), lit_bool(b) => const_bool(b) } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 76d1d0b05ffbc..9ffeb99ac3559 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -225,7 +225,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, // the default implementation. // Having to do this this is really unfortunate. let method_id = ty::method(tcx, method_id).provided_source - .get_or_default(method_id); + .unwrap_or_default(method_id); if method_id.crate == LOCAL_CRATE { let is_private = method_is_private(span, method_id.node); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 693c59d0edcf8..625dcd5d9cc49 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1726,7 +1726,7 @@ impl Resolver { let mut modules = HashMap::new(); // Create all the items reachable by paths. - do each_path(self.session.cstore, root.def_id.get().crate) + do each_path(self.session.cstore, root.def_id.unwrap().crate) |path_string, def_like, visibility| { debug!("(building reduced graph for external crate) found path \ @@ -2350,7 +2350,7 @@ impl Resolver { match type_result { BoundResult(target_module, name_bindings) => { debug!("(resolving single import) found type target: %?", - name_bindings.type_def.get().type_def); + name_bindings.type_def.unwrap().type_def); import_resolution.type_target = Some(Target(target_module, name_bindings)); import_resolution.type_id = directive.id; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index e7441125645d6..3efc0242ef09b 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -210,7 +210,7 @@ pub fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool { ExprLit(existing_a_expr) => a_expr = existing_a_expr, ConstLit(a_const) => { let e = const_eval::lookup_const_by_id(tcx, a_const); - a_expr = e.get(); + a_expr = e.unwrap(); } UnitLikeStructLit(_) => { fail!("UnitLikeStructLit should have been handled \ @@ -223,7 +223,7 @@ pub fn opt_eq(tcx: ty::ctxt, a: &Opt, b: &Opt) -> bool { ExprLit(existing_b_expr) => b_expr = existing_b_expr, ConstLit(b_const) => { let e = const_eval::lookup_const_by_id(tcx, b_const); - b_expr = e.get(); + b_expr = e.unwrap(); } UnitLikeStructLit(_) => { fail!("UnitLikeStructLit should have been handled \ @@ -920,7 +920,7 @@ pub fn extract_vec_elems(bcx: @mut Block, } }; if slice.is_some() { - let n = slice.get(); + let n = slice.unwrap(); let slice_offset = Mul(bcx, vt.llunit_size, C_int(bcx.ccx(), n as int) ); @@ -1278,7 +1278,7 @@ pub fn compile_submatch(bcx: @mut Block, let _icx = push_ctxt("match::compile_submatch"); let mut bcx = bcx; if m.len() == 0u { - Br(bcx, chk.get()()); + Br(bcx, chk.unwrap()()); return; } if m[0].pats.len() == 0u { diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index fad5b9ec73b0f..2eb9841c6c757 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -260,7 +260,7 @@ fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool) -> ~[Type] { most_aligned = Some(st); } } - let most_aligned = most_aligned.get(); + let most_aligned = most_aligned.unwrap(); let padding = largest_size - most_aligned.size; struct_llfields(cx, most_aligned, sizing) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 6b35f4ae9a4ee..2efed8f36d7ff 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1321,7 +1321,7 @@ pub fn cleanup_and_leave(bcx: @mut Block, } match leave { Some(target) => Br(bcx, target), - None => { Resume(bcx, Load(bcx, bcx.fcx.personality.get())); } + None => { Resume(bcx, Load(bcx, bcx.fcx.personality.unwrap())); } } } @@ -1529,7 +1529,7 @@ pub fn alloca_maybe_zeroed(cx: @mut Block, ty: Type, name: &str, zero: bool) -> let p = Alloca(cx, ty, name); if zero { let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.get()); + b.position_before(cx.fcx.alloca_insert_pt.unwrap()); memzero(&b, p, ty); } p @@ -1575,7 +1575,7 @@ pub fn make_return_pointer(fcx: @mut FunctionContext, output_type: ty::t) -> Val llvm::LLVMGetParam(fcx.llfn, 0) } else { let lloutputtype = type_of::type_of(fcx.ccx, output_type); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); Alloca(bcx, lloutputtype, "__make_return_pointer") } } @@ -1793,7 +1793,7 @@ pub fn finish_fn(fcx: @mut FunctionContext, last_bcx: @mut Block) { pub fn build_return_block(fcx: &FunctionContext, ret_cx: @mut Block) { // Return the value if this function immediate; otherwise, return void. if fcx.llretptr.is_some() && fcx.has_immediate_return_value { - Ret(ret_cx, Load(ret_cx, fcx.llretptr.get())) + Ret(ret_cx, Load(ret_cx, fcx.llretptr.unwrap())) } else { RetVoid(ret_cx) } @@ -1843,7 +1843,7 @@ pub fn trans_closure(ccx: @mut CrateContext, // Create the first basic block in the function and keep a handle on it to // pass to finish_fn later. - let bcx_top = fcx.entry_bcx.get(); + let bcx_top = fcx.entry_bcx.unwrap(); let mut bcx = bcx_top; let block_ty = node_id_type(bcx, body.id); @@ -1861,7 +1861,7 @@ pub fn trans_closure(ccx: @mut CrateContext, { bcx = controlflow::trans_block(bcx, body, expr::Ignore); } else { - let dest = expr::SaveIn(fcx.llretptr.get()); + let dest = expr::SaveIn(fcx.llretptr.unwrap()); bcx = controlflow::trans_block(bcx, body, dest); } @@ -2055,18 +2055,18 @@ pub fn trans_enum_variant_or_tuple_like_struct( let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); let arg_tys = ty::ty_fn_args(ctor_ty); insert_synthetic_type_entries(bcx, fn_args, arg_tys); let bcx = copy_args_to_allocas(fcx, bcx, fn_args, raw_llargs, arg_tys); let repr = adt::represent_type(ccx, result_ty); - adt::trans_start_init(bcx, repr, fcx.llretptr.get(), disr); + adt::trans_start_init(bcx, repr, fcx.llretptr.unwrap(), disr); for (i, fn_arg) in fn_args.iter().enumerate() { let lldestptr = adt::trans_field_ptr(bcx, repr, - fcx.llretptr.get(), + fcx.llretptr.unwrap(), disr, i); let llarg = fcx.llargs.get_copy(&fn_arg.pat.id); @@ -2284,7 +2284,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext, // be updated if this assertion starts to fail. assert!(fcx.has_immediate_return_value); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); // Call main. let llenvarg = unsafe { let env_arg = fcx.env_arg_pos(); @@ -2774,7 +2774,7 @@ pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef { } for key in keys.iter() { - let val = *ccx.module_data.find_equiv(key).get(); + let val = *ccx.module_data.find_equiv(key).unwrap(); let s_const = C_cstr(ccx, *key); let s_ptr = p2i(ccx, s_const); let v_ptr = p2i(ccx, val); diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 07b774105bbde..c8e2a17c3b5f1 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -319,7 +319,7 @@ pub fn Alloca(cx: @mut Block, Ty: Type, name: &str) -> ValueRef { unsafe { if cx.unreachable { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); } let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.get()); + b.position_before(cx.fcx.alloca_insert_pt.unwrap()); b.alloca(Ty, name) } } @@ -328,7 +328,7 @@ pub fn ArrayAlloca(cx: @mut Block, Ty: Type, Val: ValueRef) -> ValueRef { unsafe { if cx.unreachable { return llvm::LLVMGetUndef(Ty.ptr_to().to_ref()); } let b = cx.fcx.ccx.builder(); - b.position_before(cx.fcx.alloca_insert_pt.get()); + b.position_before(cx.fcx.alloca_insert_pt.unwrap()); b.array_alloca(Ty, Val) } } diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 3a6577e28b7cc..895bea715c964 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -169,7 +169,7 @@ impl FnType { } else { Load(bcx, llretval) }; - let llretptr = BitCast(bcx, bcx.fcx.llretptr.get(), self.ret_ty.ty.ptr_to()); + let llretptr = BitCast(bcx, bcx.fcx.llretptr.unwrap(), self.ret_ty.ty.ptr_to()); Store(bcx, llretval, llretptr); } } diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index ae3b773af0b63..602d33a197e29 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -330,7 +330,7 @@ pub fn load_environment(fcx: @mut FunctionContext, return; } - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); // Load a pointer to the closure data, skipping over the box header: let llcdata = opaque_box_body(bcx, cdata_ty, fcx.llenv); @@ -443,7 +443,7 @@ pub fn trans_expr_fn(bcx: @mut Block, if is_loop_body.is_some() { Store(bcx, C_bool(true), - bcx.fcx.llretptr.get()); + bcx.fcx.llretptr.unwrap()); } }); rslt(bcx, llbox) diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 527706be6c1f7..f303e7b827597 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -251,7 +251,7 @@ impl FunctionContext { pub fn cleanup(&mut self) { unsafe { - llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt.get()); + llvm::LLVMInstructionEraseFromParent(self.alloca_insert_pt.unwrap()); } // Remove the cycle between fcx and bcx, so memory can be freed self.entry_bcx = None; @@ -262,7 +262,7 @@ impl FunctionContext { self.llreturn = Some(base::mk_return_basic_block(self.llfn)); } - self.llreturn.get() + self.llreturn.unwrap() } } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 4fa64b4130aa9..823b1e0645cbc 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -314,7 +314,7 @@ pub fn trans_break_cont(bcx: @mut Block, Some(bcx) => bcx, // This is a return from a loop body block None => { - Store(bcx, C_bool(!to_end), bcx.fcx.llretptr.get()); + Store(bcx, C_bool(!to_end), bcx.fcx.llretptr.unwrap()); cleanup_and_leave(bcx, None, Some(bcx.fcx.get_llreturn())); Unreachable(bcx); return bcx; @@ -346,7 +346,7 @@ pub fn trans_ret(bcx: @mut Block, e: Option<@ast::expr>) -> @mut Block { // to false, return flag to true, and then store the value in the // parent's retptr. Store(bcx, C_bool(true), flagptr); - Store(bcx, C_bool(false), bcx.fcx.llretptr.get()); + Store(bcx, C_bool(false), bcx.fcx.llretptr.unwrap()); expr::SaveIn(match e { Some(x) => PointerCast(bcx, retptr, type_of(bcx.ccx(), expr_ty(bcx, x)).ptr_to()), diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index e31a27a4c6ca0..624704c2c686c 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -485,8 +485,8 @@ fn lexical_block_metadata(bcx: @mut Block) -> DILexicalBlock { } } - let span = bcx.node_info.get().span; - let id = bcx.node_info.get().id; + let span = bcx.node_info.unwrap().span; + let id = bcx.node_info.unwrap().id; // Check whether we already have a cache entry for this node id match dbg_cx(cx).created_blocks.find(&id) { diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index ede2292725cc9..5153296337dae 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -149,7 +149,7 @@ fn build_shim_fn_(ccx: @mut CrateContext, // Declare the body of the shim function: let fcx = new_fn_ctxt(ccx, ~[], llshimfn, tys.fn_sig.output, None); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); let llargbundle = get_param(llshimfn, 0u); let llargvals = arg_builder(bcx, tys, llargbundle); @@ -190,7 +190,7 @@ fn build_wrap_fn_(ccx: @mut CrateContext, ret_builder: wrap_ret_builder) { let _icx = push_ctxt("foreign::build_wrap_fn_"); let fcx = new_fn_ctxt(ccx, ~[], llwrapfn, tys.fn_sig.output, None); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); // Patch up the return type if it's not immediate and we're returning via // the C ABI. @@ -226,7 +226,7 @@ fn build_wrap_fn_(ccx: @mut CrateContext, } else { // Cast if we have to... // XXX: This is ugly. - let llretptr = BitCast(return_context, fcx.llretptr.get(), return_type.ptr_to()); + let llretptr = BitCast(return_context, fcx.llretptr.unwrap(), return_type.ptr_to()); Ret(return_context, Load(return_context, llretptr)); } fcx.cleanup(); @@ -421,7 +421,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext, debug!("build_direct_fn(%s)", link_name(ccx, item)); let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); let llbasefn = base_fn(ccx, link_name(ccx, item), tys, cc); let ty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(item.id)).ty; @@ -431,7 +431,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext, }); let retval = Call(bcx, llbasefn, args); if !ty::type_is_nil(ret_ty) && !ty::type_is_bot(ret_ty) { - Store(bcx, retval, fcx.llretptr.get()); + Store(bcx, retval, fcx.llretptr.unwrap()); } finish_fn(fcx, bcx); } @@ -446,7 +446,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext, debug!("build_fast_ffi_fn(%s)", link_name(ccx, item)); let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None); - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); let llbasefn = base_fn(ccx, link_name(ccx, item), tys, cc); set_no_inline(fcx.llfn); set_fixed_stack_segment(fcx.llfn); @@ -458,7 +458,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext, }); let retval = Call(bcx, llbasefn, args); if !ty::type_is_nil(ret_ty) && !ty::type_is_bot(ret_ty) { - Store(bcx, retval, fcx.llretptr.get()); + Store(bcx, retval, fcx.llretptr.unwrap()); } finish_fn(fcx, bcx); } @@ -618,7 +618,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, set_fixed_stack_segment(fcx.llfn); } - let mut bcx = fcx.entry_bcx.get(); + let mut bcx = fcx.entry_bcx.unwrap(); let first_real_arg = fcx.arg_pos(0u); let nm = ccx.sess.str_of(item.ident); @@ -775,7 +775,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, let in_type_size = machine::llbitsize_of_real(ccx, llintype); let out_type_size = machine::llbitsize_of_real(ccx, llouttype); if in_type_size != out_type_size { - let sp = match ccx.tcx.items.get_copy(&ref_id.get()) { + let sp = match ccx.tcx.items.get_copy(&ref_id.unwrap()) { ast_map::node_expr(e) => e.span, _ => fail!("transmute has non-expr arg"), }; @@ -816,7 +816,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, // NB: Do not use a Load and Store here. This causes massive // code bloat when `transmute` is used on large structural // types. - let lldestptr = fcx.llretptr.get(); + let lldestptr = fcx.llretptr.unwrap(); let lldestptr = PointerCast(bcx, lldestptr, Type::i8p()); let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p()); diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 659f56b355e79..948c9ceef8e61 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -311,7 +311,7 @@ pub fn call_tydesc_glue_full(bcx: @mut Block, let llrawptr = if static_ti.is_none() || static_glue_fn.is_none() { PointerCast(bcx, v, Type::i8p()) } else { - let ty = static_ti.get().ty; + let ty = static_ti.unwrap().ty; let simpl = simplified_glue_type(ccx.tcx, field, ty); if simpl != ty { PointerCast(bcx, v, type_of(ccx, simpl).ptr_to()) @@ -708,7 +708,7 @@ pub fn make_generic_glue_inner(ccx: @mut CrateContext, // llfn is expected be declared to take a parameter of the appropriate // type, so we don't need to explicitly cast the function parameter. - let bcx = fcx.entry_bcx.get(); + let bcx = fcx.entry_bcx.unwrap(); let rawptr0_arg = fcx.arg_pos(0u); let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, rawptr0_arg as c_uint) }; let bcx = helper(bcx, llrawptr0, t); diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 6fd47436fd884..5f8837b538cdf 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -180,7 +180,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, let idx = psubsts.tys.len() - num_method_ty_params; let substs = (psubsts.tys.slice(0, idx) + - &[psubsts.self_ty.get()] + + &[psubsts.self_ty.unwrap()] + psubsts.tys.tailn(idx)); debug!("static default: changed substitution to %s", substs.repr(ccx.tcx)); @@ -245,7 +245,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, } ast_map::node_variant(ref v, enum_item, _) => { let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); - let this_tv = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).get(); + let this_tv = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).unwrap(); let d = mk_lldecl(); set_inline_hint(d); match v.node.kind { diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index e4259c80720e6..609aad0bc201c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -303,10 +303,10 @@ impl Reflector { // llvm::LLVMGetParam(llfdecl, fcx.arg_pos(0u) as c_uint) }; - let mut bcx = fcx.entry_bcx.get(); + let mut bcx = fcx.entry_bcx.unwrap(); let arg = BitCast(bcx, arg, llptrty); let ret = adt::trans_get_discr(bcx, repr, arg); - Store(bcx, ret, fcx.llretptr.get()); + Store(bcx, ret, fcx.llretptr.unwrap()); match fcx.llreturn { Some(llreturn) => cleanup_and_Br(bcx, bcx, llreturn), None => bcx = cleanup_block(bcx, Some(bcx.llbb)) diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index b743f2e940157..6a382cc1a5d1c 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -239,7 +239,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { ty::ty_estr(ty::vstore_slice(_)) => { // This means we get a nicer name in the output - cx.tn.find_type("str_slice").get() + cx.tn.find_type("str_slice").unwrap() } ty::ty_estr(ty::vstore_fixed(n)) => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 923e94eca624d..b15580034c2a8 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -33,6 +33,7 @@ use std::hashmap::{HashMap, HashSet}; use std::ops; use std::ptr::to_unsafe_ptr; use std::to_bytes; +use std::to_str::ToStr; use std::u32; use std::vec; use syntax::ast::*; @@ -116,7 +117,7 @@ pub struct mt { mutbl: ast::mutability, } -#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes, ToStr)] pub enum vstore { vstore_fixed(uint), vstore_uniq, @@ -124,7 +125,7 @@ pub enum vstore { vstore_slice(Region) } -#[deriving(Clone, Eq, IterBytes, Encodable, Decodable)] +#[deriving(Clone, Eq, IterBytes, Encodable, Decodable, ToStr)] pub enum TraitStore { BoxTraitStore, // @Trait UniqTraitStore, // ~Trait @@ -350,6 +351,12 @@ pub struct t_box_ { enum t_opaque {} pub type t = *t_opaque; +impl ToStr for t { + fn to_str(&self) -> ~str { + ~"*t_opaque" + } +} + pub fn get(t: t) -> t_box { unsafe { let t2: t_box = cast::transmute(t); @@ -410,7 +417,7 @@ pub struct param_ty { } /// Representation of regions: -#[deriving(Clone, Eq, IterBytes, Encodable, Decodable)] +#[deriving(Clone, Eq, IterBytes, Encodable, Decodable, ToStr)] pub enum Region { /// Bound regions are found (primarily) in function types. They indicate /// region parameters that have yet to be replaced with actual regions @@ -456,13 +463,13 @@ impl Region { } } -#[deriving(Clone, Eq, IterBytes, Encodable, Decodable)] +#[deriving(Clone, Eq, IterBytes, Encodable, Decodable, ToStr)] pub struct FreeRegion { scope_id: NodeId, bound_region: bound_region } -#[deriving(Clone, Eq, IterBytes, Encodable, Decodable)] +#[deriving(Clone, Eq, IterBytes, Encodable, Decodable, ToStr)] pub enum bound_region { /// The self region for structs, impls (&T in a type defn or &'self T) br_self, @@ -620,19 +627,22 @@ pub enum IntVarValue { UintType(ast::uint_ty), } -#[deriving(Clone)] +#[deriving(Clone, ToStr)] pub enum terr_vstore_kind { - terr_vec, terr_str, terr_fn, terr_trait + terr_vec, + terr_str, + terr_fn, + terr_trait } -#[deriving(Clone)] +#[deriving(Clone, ToStr)] pub struct expected_found { expected: T, found: T } // Data structures used in type unification -#[deriving(Clone)] +#[deriving(Clone, ToStr)] pub enum type_err { terr_mismatch, terr_purity_mismatch(expected_found), @@ -674,7 +684,7 @@ pub struct ParamBounds { pub type BuiltinBounds = EnumSet; -#[deriving(Clone, Eq, IterBytes)] +#[deriving(Clone, Eq, IterBytes, ToStr)] pub enum BuiltinBound { BoundStatic, BoundSend, @@ -725,7 +735,7 @@ pub enum InferTy { FloatVar(FloatVid) } -#[deriving(Clone, Encodable, Decodable, IterBytes)] +#[deriving(Clone, Encodable, Decodable, IterBytes, ToStr)] pub enum InferRegion { ReVar(RegionVid), ReSkolemized(uint, bound_region) diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index e1c1ea2c7834b..b604fb19e9998 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -531,7 +531,7 @@ pub fn ty_of_arg) -> ty::t { match a.ty.node { - ast::ty_infer if expected_ty.is_some() => expected_ty.get(), + ast::ty_infer if expected_ty.is_some() => expected_ty.unwrap(), ast::ty_infer => this.ty_infer(a.ty.span), _ => ast_ty_to_ty(this, rscope, &a.ty), } @@ -587,7 +587,7 @@ pub fn ty_of_method( }; let (a, b) = ty_of_method_or_bare_fn( this, rscope, purity, AbiSet::Rust(), lifetimes, Some(&self_info), decl); - (a.get(), b) + (a.unwrap(), b) } pub fn ty_of_bare_fn( @@ -735,7 +735,7 @@ pub fn ty_of_closure( let expected_ret_ty = expected_sig.map(|e| e.output); let output_ty = match decl.output.node { - ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(), + ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.unwrap(), ast::ty_infer => this.ty_infer(decl.output.span), _ => ast_ty_to_ty(this, &rb, &decl.output) }; diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 85faad6a631d2..42e4b3e353fbb 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -166,7 +166,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.write_error(pat.id); kind_name = "[error]"; arg_types = (*subpats).clone() - .get_or_default(~[]) + .unwrap_or_default(~[]) .map(|_| ty::mk_err()); } } @@ -209,7 +209,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path, fcx.write_error(pat.id); kind_name = "[error]"; arg_types = (*subpats).clone() - .get_or_default(~[]) + .unwrap_or_default(~[]) .map(|_| ty::mk_err()); } } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 209f636ddc238..e1e7d10db0abd 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -854,7 +854,7 @@ impl<'self> LookupContext<'self> { // like &'a Self. We then perform a // substitution which will replace Self with // @Trait. - let t = candidate.method_ty.transformed_self_ty.get(); + let t = candidate.method_ty.transformed_self_ty.unwrap(); ty::subst(tcx, &candidate.rcvr_substs, t) } _ => { @@ -863,7 +863,7 @@ impl<'self> LookupContext<'self> { } } _ => { - let t = candidate.method_ty.transformed_self_ty.get(); + let t = candidate.method_ty.transformed_self_ty.unwrap(); ty::subst(tcx, &candidate.rcvr_substs, t) } }; @@ -922,7 +922,7 @@ impl<'self> LookupContext<'self> { tcx, @Nil, Some(transformed_self_ty), &bare_fn_ty.sig, |br| self.fcx.infcx().next_region_var( infer::BoundRegionInFnCall(self.expr.span, br))); - let transformed_self_ty = opt_transformed_self_ty.get(); + let transformed_self_ty = opt_transformed_self_ty.unwrap(); let fty = ty::mk_bare_fn(tcx, ty::BareFnTy { sig: fn_sig, purity: bare_fn_ty.purity, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 52731f6dc52db..9fc9076a29d10 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -365,7 +365,7 @@ pub fn check_fn(ccx: @mut CrateCtxt, bound_region: br})); let opt_self_info = opt_self_info.map( - |si| SelfInfo {self_ty: opt_self_ty.get(), ..*si}); + |si| SelfInfo {self_ty: opt_self_ty.unwrap(), ..*si}); (isr, opt_self_info, fn_sig) }; @@ -2448,7 +2448,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expected, |x| Some((*x).clone())); let inner_ty = match expected_sty { - Some(ty::ty_closure(_)) => expected.get(), + Some(ty::ty_closure(_)) => expected.unwrap(), _ => match expected { Some(expected_t) => { fcx.type_error_message(expr.span, |actual| { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index b9a62acd0bd87..f05388344bc71 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -253,7 +253,7 @@ impl Combine for Glb { if a_r.is_some() && b_r.is_some() && only_new_vars { // Related to exactly one bound variable from each fn: - return rev_lookup(this, a_isr, a_r.get()); + return rev_lookup(this, a_isr, a_r.unwrap()); } else if a_r.is_none() && b_r.is_none() { // Not related to bound variables from either fn: return r0; diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index e6c27fc8f836d..b1356ffb2d5e9 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -295,7 +295,7 @@ trait get_and_find_region { impl get_and_find_region for isr_alist { pub fn get(&self, br: ty::bound_region) -> ty::Region { - self.find(br).get() + self.find(br).unwrap() } pub fn find(&self, br: ty::bound_region) -> Option { diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index e2b25a67c3dde..bbcf42b1c5d32 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -18,6 +18,7 @@ use syntax::opt_vec::OptVec; use syntax::opt_vec; use syntax::parse::token::special_idents; +#[deriving(ToStr)] pub struct RegionError { msg: ~str, replacement: ty::Region diff --git a/src/librustc/util/enum_set.rs b/src/librustc/util/enum_set.rs index 2466c373f23b4..ced29f18f7f11 100644 --- a/src/librustc/util/enum_set.rs +++ b/src/librustc/util/enum_set.rs @@ -10,7 +10,7 @@ use std::iterator::Iterator; -#[deriving(Clone, Eq, IterBytes)] +#[deriving(Clone, Eq, IterBytes, ToStr)] pub struct EnumSet { // We must maintain the invariant that no bits are set // for which no variant exists diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index b189bd2bc2dcd..a1cb81f450357 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -68,7 +68,7 @@ fn fold_crate( doc::CrateDoc { topmod: doc::ModDoc { item: doc::ItemDoc { - name: attrs.name.clone().get_or_default(doc.topmod.name_()), + name: attrs.name.clone().unwrap_or_default(doc.topmod.name_()), .. doc.topmod.item.clone() }, .. doc.topmod.clone() @@ -135,7 +135,7 @@ fn fold_enum( let ast_variant = (*enum_definition.variants.iter().find_(|v| { to_str(v.node.name) == variant.name - }).get()).clone(); + }).unwrap()).clone(); attr_parser::parse_desc( ast_variant.node.attrs.clone()) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index f287e17880bb3..d387bbea592d3 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -142,7 +142,7 @@ fn config_from_opts( let output_dir = getopts::opt_maybe_str(matches, opt_output_dir()); let output_dir = output_dir.map(|s| Path(*s)); result::Ok(Config { - output_dir: output_dir.get_or_default(config.output_dir.clone()), + output_dir: output_dir.unwrap_or_default(config.output_dir.clone()), .. config }) }; @@ -273,20 +273,20 @@ mod test { #[test] fn should_error_with_no_crates() { let config = parse_config([~"rustdoc"]); - assert!(config.get_err() == ~"no crates specified"); + assert!(config.unwrap_err() == ~"no crates specified"); } #[test] fn should_error_with_multiple_crates() { let config = parse_config([~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); - assert!(config.get_err() == ~"multiple crates specified"); + assert!(config.unwrap_err() == ~"multiple crates specified"); } #[test] fn should_set_output_dir_to_cwd_if_not_provided() { let config = parse_config([~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_dir == Path(".")); + assert!(config.unwrap().output_dir == Path(".")); } #[test] @@ -294,13 +294,13 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" ]); - assert!(config.get().output_dir == Path("snuggles")); + assert!(config.unwrap().output_dir == Path("snuggles")); } #[test] fn should_set_output_format_to_pandoc_html_if_not_provided() { let config = parse_config([~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_format == PandocHtml); + assert!(config.unwrap().output_format == PandocHtml); } #[test] @@ -308,7 +308,7 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" ]); - assert!(config.get().output_format == Markdown); + assert!(config.unwrap().output_format == Markdown); } #[test] @@ -316,7 +316,7 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" ]); - assert!(config.get().output_format == PandocHtml); + assert!(config.unwrap().output_format == PandocHtml); } #[test] @@ -324,13 +324,13 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" ]); - assert!(config.get_err() == ~"unknown output format 'bogus'"); + assert!(config.unwrap_err() == ~"unknown output format 'bogus'"); } #[test] fn should_set_output_style_to_doc_per_mod_by_default() { let config = parse_config([~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_style == DocPerMod); + assert!(config.unwrap().output_style == DocPerMod); } #[test] @@ -338,7 +338,7 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" ]); - assert!(config.get().output_style == DocPerCrate); + assert!(config.unwrap().output_style == DocPerCrate); } #[test] @@ -346,7 +346,7 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" ]); - assert!(config.get().output_style == DocPerMod); + assert!(config.unwrap().output_style == DocPerMod); } #[test] @@ -354,7 +354,7 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" ]); - assert!(config.get_err() == ~"unknown output style 'bogus'"); + assert!(config.unwrap_err() == ~"unknown output style 'bogus'"); } #[test] @@ -362,12 +362,12 @@ mod test { let config = parse_config([ ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" ]); - assert!(config.get().pandoc_cmd == Some(~"panda-bear-doc")); + assert!(config.unwrap().pandoc_cmd == Some(~"panda-bear-doc")); } #[test] fn should_set_pandoc_command_when_using_pandoc() { let config = parse_config([~"rustdoc", ~"crate.rc"]); - assert!(config.get().pandoc_cmd == Some(~"pandoc")); + assert!(config.unwrap().pandoc_cmd == Some(~"pandoc")); } } diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 9e1dffb989b00..9f8041712eaec 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -83,7 +83,7 @@ pub fn extract(desc: Option<~str>) -> Option<~str> { return None } - parse_desc(desc.clone().get()) + parse_desc(desc.clone().unwrap()) } fn parse_desc(desc: ~str) -> Option<~str> { diff --git a/src/librustdoc/doc.rs b/src/librustdoc/doc.rs index cca898feba2b2..d24fd1f5bfe54 100644 --- a/src/librustdoc/doc.rs +++ b/src/librustdoc/doc.rs @@ -176,7 +176,7 @@ impl Doc { doc::CratePage(doc) => Some(doc), _ => None } - }).get() + }).unwrap() } pub fn cratemod(&self) -> ModDoc { diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs index 2c6312e01b205..90634770a501e 100644 --- a/src/librustdoc/markdown_index_pass.rs +++ b/src/librustdoc/markdown_index_pass.rs @@ -223,13 +223,13 @@ mod test { config::DocPerCrate, ~"mod a { } fn b() { }" ); - assert!(doc.cratemod().index.get().entries[0] == doc::IndexEntry { + assert!(doc.cratemod().index.unwrap().entries[0] == doc::IndexEntry { kind: ~"Module", name: ~"a", brief: None, link: ~"#module-a" }); - assert!(doc.cratemod().index.get().entries[1] == doc::IndexEntry { + assert!(doc.cratemod().index.unwrap().entries[1] == doc::IndexEntry { kind: ~"Function", name: ~"b", brief: None, @@ -243,13 +243,13 @@ mod test { config::DocPerMod, ~"mod a { } fn b() { }" ); - assert_eq!(doc.cratemod().index.get().entries[0], doc::IndexEntry { + assert_eq!(doc.cratemod().index.unwrap().entries[0], doc::IndexEntry { kind: ~"Module", name: ~"a", brief: None, link: ~"a.html" }); - assert_eq!(doc.cratemod().index.get().entries[1], doc::IndexEntry { + assert_eq!(doc.cratemod().index.unwrap().entries[1], doc::IndexEntry { kind: ~"Function", name: ~"b", brief: None, @@ -263,7 +263,7 @@ mod test { config::DocPerMod, ~"#[doc = \"test\"] mod a { }" ); - assert_eq!(doc.cratemod().index.get().entries[0].brief, Some(~"test")); + assert_eq!(doc.cratemod().index.unwrap().entries[0].brief, Some(~"test")); } #[test] @@ -273,7 +273,7 @@ mod test { ~"extern { fn b(); }" ); // hidden __std_macros module at the start. - assert_eq!(doc.cratemod().nmods()[0].index.get().entries[0], + assert_eq!(doc.cratemod().nmods()[0].index.unwrap().entries[0], doc::IndexEntry { kind: ~"Function", name: ~"b", diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index 0dbd29df48b63..85c360a9e0dfd 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -617,10 +617,10 @@ mod test { fn d() { }" ); - let idx_a = markdown.find_str("# Module `a`").get(); - let idx_b = markdown.find_str("## Function `b`").get(); - let idx_c = markdown.find_str("# Module `c`").get(); - let idx_d = markdown.find_str("## Function `d`").get(); + let idx_a = markdown.find_str("# Module `a`").unwrap(); + let idx_b = markdown.find_str("## Function `b`").unwrap(); + let idx_c = markdown.find_str("# Module `c`").unwrap(); + let idx_d = markdown.find_str("## Function `d`").unwrap(); assert!(idx_b < idx_d); assert!(idx_d < idx_a); diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index 4cd442bb95147..20f3ff3e98d48 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -218,8 +218,8 @@ mod test { Body\"]\ mod a { }"); - assert!(!doc.cratemod().mods()[0].desc().get().contains("Header")); - assert!(!doc.cratemod().mods()[0].desc().get().contains("Body")); + assert!(!doc.cratemod().mods()[0].desc().unwrap().contains("Header")); + assert!(!doc.cratemod().mods()[0].desc().unwrap().contains("Body")); } #[test] diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index abfc3517d60eb..684b4e9d198d4 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -135,7 +135,7 @@ fn fold_enum( let ast_variant = (*do enum_definition.variants.iter().find_ |v| { to_str(v.node.name) == variant.name - }.get()).clone(); + }.unwrap()).clone(); pprust::variant_to_str( &ast_variant, extract::interner()) @@ -443,7 +443,7 @@ mod test { #[test] fn should_add_struct_defs() { let doc = mk_doc(~"struct S { field: () }"); - assert!(doc.cratemod().structs()[0].sig.get().contains( + assert!(doc.cratemod().structs()[0].sig.unwrap().contains( "struct S {")); } @@ -451,6 +451,6 @@ mod test { fn should_not_serialize_struct_attrs() { // All we care about are the fields let doc = mk_doc(~"#[wut] struct S { field: () }"); - assert!(!doc.cratemod().structs()[0].sig.get().contains("wut")); + assert!(!doc.cratemod().structs()[0].sig.unwrap().contains("wut")); } } diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index 568a691290c88..5d5518997f68f 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -322,14 +322,14 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option { // instead we guess which file is the library by matching // the prefix and suffix of out_filename to files in the // directory. - let file_str = file.filename().get(); - file_str.starts_with(outputs.out_filename.filestem().get()) - && file_str.ends_with(outputs.out_filename.filetype().get()) + let file_str = file.filename().unwrap(); + file_str.starts_with(outputs.out_filename.filestem().unwrap()) + && file_str.ends_with(outputs.out_filename.filetype().unwrap()) }; match maybe_lib_path { Some(lib_path) => { - let (src_mtime, _) = src_path.get_mtime().get(); - let (lib_mtime, _) = lib_path.get_mtime().get(); + let (src_mtime, _) = src_path.get_mtime().unwrap(); + let (lib_mtime, _) = lib_path.get_mtime().unwrap(); if lib_mtime >= src_mtime { should_compile = false; } diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 4d6033de54de4..fa03a5bbfc2fb 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -102,7 +102,7 @@ impl<'self> PkgScript<'self> { debug!("pkgscript parse: %?", os::self_exe_path()); let options = @session::options { binary: binary, - maybe_sysroot: Some(@os::self_exe_path().get().pop()), + maybe_sysroot: Some(@os::self_exe_path().unwrap().pop()), crate_type: session::bin_crate, .. (*session::basic_options()).clone() }; @@ -535,7 +535,7 @@ pub fn main() { * in is the working directory. */ pub fn work_dir() -> Path { - os::self_exe_path().get() + os::self_exe_path().unwrap() } /** diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 361981289d3ce..81b47d6a16c0a 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -195,7 +195,7 @@ pub fn compile_input(ctxt: &Ctx, } + flags + cfgs.flat_map(|c| { ~[~"--cfg", (*c).clone()] }), - driver::optgroups()).get(); + driver::optgroups()).unwrap(); let options = @session::options { crate_type: crate_type, optimize: if opt { session::Aggressive } else { session::No }, diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 4ece53d0e7f52..a84f3137bbd5b 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -78,10 +78,8 @@ pub fn build(builder: &fn(push: &fn(v: A))) -> @[A] { * onto the vector being constructed. */ #[inline] -pub fn build_sized_opt(size: Option, - builder: &fn(push: &fn(v: A))) - -> @[A] { - build_sized(size.get_or_default(4), builder) +pub fn build_sized_opt(size: Option, builder: &fn(push: &fn(v: A))) -> @[A] { + build_sized(size.unwrap_or_default(4), builder) } // Appending diff --git a/src/libstd/either.rs b/src/libstd/either.rs index 6bdc45d72042a..cfaef550c6fa7 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -23,29 +23,102 @@ use str::StrSlice; use vec; use vec::{OwnedVector, ImmutableVector}; -/// The either type +/// `Either` is a type that represents one of two alternatives #[deriving(Clone, Eq)] -pub enum Either { - Left(T), - Right(U) +pub enum Either { + Left(L), + Right(R) } -/// Applies a function based on the given either value -/// -/// If `value` is left(T) then `f_left` is applied to its contents, if -/// `value` is right(U) then `f_right` is applied to its contents, and the -/// result is returned. -#[inline] -pub fn either(f_left: &fn(&T) -> V, - f_right: &fn(&U) -> V, value: &Either) -> V { - match *value { - Left(ref l) => f_left(l), - Right(ref r) => f_right(r) +impl Either { + /// Applies a function based on the given either value + /// + /// If `value` is `Left(L)` then `f_left` is applied to its contents, if + /// `value` is `Right(R)` then `f_right` is applied to its contents, and the + /// result is returned. + #[inline] + pub fn either(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T { + match *self { + Left(ref l) => f_left(l), + Right(ref r) => f_right(r) + } + } + + /// Flips between left and right of a given `Either` + #[inline] + pub fn flip(self) -> Either { + match self { + Right(r) => Left(r), + Left(l) => Right(l) + } + } + + /// Converts a `Either` to a `Result` + /// + /// Converts an `Either` type to a `Result` type, making the "right" choice + /// an `Ok` result, and the "left" choice a `Err` + #[inline] + pub fn to_result(self) -> Result { + match self { + Right(r) => result::Ok(r), + Left(l) => result::Err(l) + } + } + + /// Checks whether the given value is a `Left` + #[inline] + pub fn is_left(&self) -> bool { + match *self { + Left(_) => true, + _ => false + } + } + + /// Checks whether the given value is a `Right` + #[inline] + pub fn is_right(&self) -> bool { + match *self { + Right(_) => true, + _ => false + } + } + + /// Retrieves the value from a `Left`. + /// Fails with a specified reason if the `Either` is `Right`. + #[inline] + pub fn expect_left(self, reason: &str) -> L { + match self { + Left(x) => x, + Right(_) => fail!(reason.to_owned()) + } + } + + /// Retrieves the value from a `Left`. Fails if the `Either` is `Right`. + #[inline] + pub fn unwrap_left(self) -> L { + self.expect_left("called Either::unwrap_left()` on `Right` value") + } + + /// Retrieves the value from a `Right`. + /// Fails with a specified reason if the `Either` is `Left`. + #[inline] + pub fn expect_right(self, reason: &str) -> R { + match self { + Right(x) => x, + Left(_) => fail!(reason.to_owned()) + } + } + + /// Retrieves the value from a `Right`. Fails if the `Either` is `Left`. + #[inline] + pub fn unwrap_right(self) -> R { + self.expect_right("called Either::unwrap_right()` on `Left` value") } } +// FIXME: #8228 Replaceable by an external iterator? /// Extracts from a vector of either all the left values -pub fn lefts(eithers: &[Either]) -> ~[T] { +pub fn lefts(eithers: &[Either]) -> ~[L] { do vec::build_sized(eithers.len()) |push| { for elt in eithers.iter() { match *elt { @@ -56,8 +129,9 @@ pub fn lefts(eithers: &[Either]) -> ~[T] { } } +// FIXME: #8228 Replaceable by an external iterator? /// Extracts from a vector of either all the right values -pub fn rights(eithers: &[Either]) -> ~[U] { +pub fn rights(eithers: &[Either]) -> ~[R] { do vec::build_sized(eithers.len()) |push| { for elt in eithers.iter() { match *elt { @@ -68,13 +142,14 @@ pub fn rights(eithers: &[Either]) -> ~[U] { } } +// FIXME: #8228 Replaceable by an external iterator? /// Extracts from a vector of either all the left values and right values /// /// Returns a structure containing a vector of left values and a vector of /// right values. -pub fn partition(eithers: ~[Either]) -> (~[T], ~[U]) { - let mut lefts: ~[T] = ~[]; - let mut rights: ~[U] = ~[]; +pub fn partition(eithers: ~[Either]) -> (~[L], ~[R]) { + let mut lefts: ~[L] = ~[]; + let mut rights: ~[R] = ~[]; for elt in eithers.consume_iter() { match elt { Left(l) => lefts.push(l), @@ -84,196 +159,101 @@ pub fn partition(eithers: ~[Either]) -> (~[T], ~[U]) { return (lefts, rights); } -/// Flips between left and right of a given either -#[inline] -pub fn flip(eith: Either) -> Either { - match eith { - Right(r) => Left(r), - Left(l) => Right(l) - } -} +#[cfg(test)] +mod tests { + use super::*; -/// Converts either::t to a result::t -/// -/// Converts an `either` type to a `result` type, making the "right" choice -/// an ok result, and the "left" choice a fail -#[inline] -pub fn to_result(eith: Either) -> Result { - match eith { - Right(r) => result::Ok(r), - Left(l) => result::Err(l) + #[test] + fn test_either_left() { + let val = Left(10); + fn f_left(x: &int) -> bool { *x == 10 } + fn f_right(_x: &uint) -> bool { false } + assert!(val.either(f_left, f_right)); } -} -/// Checks whether the given value is a left -#[inline] -pub fn is_left(eith: &Either) -> bool { - match *eith { - Left(_) => true, - _ => false + #[test] + fn test_either_right() { + let val = Right(10u); + fn f_left(_x: &int) -> bool { false } + fn f_right(x: &uint) -> bool { *x == 10u } + assert!(val.either(f_left, f_right)); } -} -/// Checks whether the given value is a right -#[inline] -pub fn is_right(eith: &Either) -> bool { - match *eith { - Right(_) => true, - _ => false + #[test] + fn test_lefts() { + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; + let result = lefts(input); + assert_eq!(result, ~[10, 12, 14]); } -} -/// Retrieves the value in the left branch. -/// Fails with a specified reason if the either is Right. -#[inline] -pub fn expect_left(eith: Either, reason: &str) -> T { - match eith { - Left(x) => x, - Right(_) => fail!(reason.to_owned()) + #[test] + fn test_lefts_none() { + let input: ~[Either] = ~[Right(10), Right(10)]; + let result = lefts(input); + assert_eq!(result.len(), 0u); } -} -/// Retrieves the value in the left branch. Fails if the either is Right. -#[inline] -pub fn unwrap_left(eith: Either) -> T { - expect_left(eith, "either::unwrap_left Right") -} - -/// Retrieves the value in the right branch. -/// Fails with a specified reason if the either is Left. -#[inline] -pub fn expect_right(eith: Either, reason: &str) -> U { - match eith { - Right(x) => x, - Left(_) => fail!(reason.to_owned()) + #[test] + fn test_lefts_empty() { + let input: ~[Either] = ~[]; + let result = lefts(input); + assert_eq!(result.len(), 0u); } -} -/// Retrieves the value in the right branch. Fails if the either is Left. -pub fn unwrap_right(eith: Either) -> U { - expect_right(eith, "either::unwrap_right Left") -} - -impl Either { - #[inline] - pub fn either(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V { - either(f_left, f_right, self) + #[test] + fn test_rights() { + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; + let result = rights(input); + assert_eq!(result, ~[11, 13]); } - #[inline] - pub fn flip(self) -> Either { flip(self) } - - #[inline] - pub fn to_result(self) -> Result { to_result(self) } - - #[inline] - pub fn is_left(&self) -> bool { is_left(self) } - - #[inline] - pub fn is_right(&self) -> bool { is_right(self) } - - #[inline] - pub fn expect_left(self, reason: &str) -> T { expect_left(self, reason) } - - #[inline] - pub fn unwrap_left(self) -> T { unwrap_left(self) } - - #[inline] - pub fn expect_right(self, reason: &str) -> U { expect_right(self, reason) } - - #[inline] - pub fn unwrap_right(self) -> U { unwrap_right(self) } -} - -#[test] -fn test_either_left() { - let val = Left(10); - fn f_left(x: &int) -> bool { *x == 10 } - fn f_right(_x: &uint) -> bool { false } - assert!((either(f_left, f_right, &val))); -} - -#[test] -fn test_either_right() { - let val = Right(10u); - fn f_left(_x: &int) -> bool { false } - fn f_right(x: &uint) -> bool { *x == 10u } - assert!((either(f_left, f_right, &val))); -} - -#[test] -fn test_lefts() { - let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; - let result = lefts(input); - assert_eq!(result, ~[10, 12, 14]); -} - -#[test] -fn test_lefts_none() { - let input: ~[Either] = ~[Right(10), Right(10)]; - let result = lefts(input); - assert_eq!(result.len(), 0u); -} - -#[test] -fn test_lefts_empty() { - let input: ~[Either] = ~[]; - let result = lefts(input); - assert_eq!(result.len(), 0u); -} - -#[test] -fn test_rights() { - let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; - let result = rights(input); - assert_eq!(result, ~[11, 13]); -} + #[test] + fn test_rights_none() { + let input: ~[Either] = ~[Left(10), Left(10)]; + let result = rights(input); + assert_eq!(result.len(), 0u); + } -#[test] -fn test_rights_none() { - let input: ~[Either] = ~[Left(10), Left(10)]; - let result = rights(input); - assert_eq!(result.len(), 0u); -} + #[test] + fn test_rights_empty() { + let input: ~[Either] = ~[]; + let result = rights(input); + assert_eq!(result.len(), 0u); + } -#[test] -fn test_rights_empty() { - let input: ~[Either] = ~[]; - let result = rights(input); - assert_eq!(result.len(), 0u); -} + #[test] + fn test_partition() { + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; + let (lefts, rights) = partition(input); + assert_eq!(lefts[0], 10); + assert_eq!(lefts[1], 12); + assert_eq!(lefts[2], 14); + assert_eq!(rights[0], 11); + assert_eq!(rights[1], 13); + } -#[test] -fn test_partition() { - let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; - let (lefts, rights) = partition(input); - assert_eq!(lefts[0], 10); - assert_eq!(lefts[1], 12); - assert_eq!(lefts[2], 14); - assert_eq!(rights[0], 11); - assert_eq!(rights[1], 13); -} + #[test] + fn test_partition_no_lefts() { + let input: ~[Either] = ~[Right(10), Right(11)]; + let (lefts, rights) = partition(input); + assert_eq!(lefts.len(), 0u); + assert_eq!(rights.len(), 2u); + } -#[test] -fn test_partition_no_lefts() { - let input: ~[Either] = ~[Right(10), Right(11)]; - let (lefts, rights) = partition(input); - assert_eq!(lefts.len(), 0u); - assert_eq!(rights.len(), 2u); -} + #[test] + fn test_partition_no_rights() { + let input: ~[Either] = ~[Left(10), Left(11)]; + let (lefts, rights) = partition(input); + assert_eq!(lefts.len(), 2u); + assert_eq!(rights.len(), 0u); + } -#[test] -fn test_partition_no_rights() { - let input: ~[Either] = ~[Left(10), Left(11)]; - let (lefts, rights) = partition(input); - assert_eq!(lefts.len(), 2u); - assert_eq!(rights.len(), 0u); -} + #[test] + fn test_partition_empty() { + let input: ~[Either] = ~[]; + let (lefts, rights) = partition(input); + assert_eq!(lefts.len(), 0u); + assert_eq!(rights.len(), 0u); + } -#[test] -fn test_partition_empty() { - let input: ~[Either] = ~[]; - let (lefts, rights) = partition(input); - assert_eq!(lefts.len(), 0u); - assert_eq!(rights.len(), 0u); } diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 537289c8dd6c2..c2a60e1c0e9c0 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -112,14 +112,14 @@ fn test_tls_multitask() { // TLS shouldn't carry over. assert!(get(my_key, |k| k.map(|&k| *k)).is_none()); set(my_key, @~"child data"); - assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == + assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"child data"); // should be cleaned up for us } // Must work multiple times - assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data"); } #[test] @@ -127,14 +127,14 @@ fn test_tls_overwrite() { static my_key: Key<@~str> = &Key; set(my_key, @~"first data"); set(my_key, @~"next data"); // Shouldn't leak. - assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"next data"); + assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"next data"); } #[test] fn test_tls_pop() { static my_key: Key<@~str> = &Key; set(my_key, @~"weasel"); - assert!(*(pop(my_key).get()) == ~"weasel"); + assert!(*(pop(my_key).unwrap()) == ~"weasel"); // Pop must remove the data from the map. assert!(pop(my_key).is_none()); } @@ -155,7 +155,7 @@ fn test_tls_modify() { None => fail!("missing value") } }); - assert!(*(pop(my_key).get()) == ~"next data"); + assert!(*(pop(my_key).unwrap()) == ~"next data"); } #[test] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 417251d3740e6..3a4a9220ee16c 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -47,7 +47,8 @@ use ops::Add; use util; use num::Zero; use iterator::Iterator; -use str::StrSlice; +use str::{StrSlice, OwnedStr}; +use to_str::ToStr; use clone::DeepClone; /// The option type @@ -85,18 +86,33 @@ impl Ord for Option { } } -impl> Add, Option> for Option { +impl> Add, Option> for Option { #[inline] fn add(&self, other: &Option) -> Option { match (&*self, &*other) { (&None, &None) => None, - (_, &None) => (*self).clone(), - (&None, _) => (*other).clone(), + (_, &None) => None, + (&None, _) => None, (&Some(ref lhs), &Some(ref rhs)) => Some(*lhs + *rhs) } } } +// FIXME: #8242 implementing manually because deriving doesn't work for some reason +impl ToStr for Option { + fn to_str(&self) -> ~str { + match *self { + Some(ref x) => { + let mut s = ~"Some("; + s.push_str(x.to_str()); + s.push_str(")"); + s + } + None => ~"None" + } + } +} + impl Option { /// Return an iterator over the possibly contained value #[inline] @@ -148,8 +164,7 @@ impl Option { /// Update an optional value by optionally running its content by reference /// through a function that returns an option. #[inline] - pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option) - -> Option { + pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option) -> Option { match *self { Some(ref x) => f(x), None => None @@ -159,8 +174,7 @@ impl Option { /// Update an optional value by optionally running its content by mut reference /// through a function that returns an option. #[inline] - pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option) - -> Option { + pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option) -> Option { match *self { Some(ref mut x) => f(x), None => None @@ -256,132 +270,105 @@ impl Option { } } - /** - Gets an immutable reference to the value inside an option. - - # Failure - - Fails if the value equals `None` - - # Safety note - - In general, because this function may fail, its use is discouraged - (calling `get` on `None` is akin to dereferencing a null pointer). - Instead, prefer to use pattern matching and handle the `None` - case explicitly. - */ + /// Gets an immutable reference to the value inside an option. + /// + /// # Failure + /// + /// Fails if the value equals `None` + /// + /// # Safety note + /// + /// In general, because this function may fail, its use is discouraged + /// (calling `get` on `None` is akin to dereferencing a null pointer). + /// Instead, prefer to use pattern matching and handle the `None` + /// case explicitly. #[inline] pub fn get_ref<'a>(&'a self) -> &'a T { match *self { - Some(ref x) => x, - None => fail!("option::get_ref `None`"), + Some(ref x) => x, + None => fail!("called `Option::get_ref()` on a `None` value"), } } - /** - Gets a mutable reference to the value inside an option. - - # Failure - - Fails if the value equals `None` - - # Safety note - - In general, because this function may fail, its use is discouraged - (calling `get` on `None` is akin to dereferencing a null pointer). - Instead, prefer to use pattern matching and handle the `None` - case explicitly. - */ + /// Gets a mutable reference to the value inside an option. + /// + /// # Failure + /// + /// Fails if the value equals `None` + /// + /// # Safety note + /// + /// In general, because this function may fail, its use is discouraged + /// (calling `get` on `None` is akin to dereferencing a null pointer). + /// Instead, prefer to use pattern matching and handle the `None` + /// case explicitly. #[inline] pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut T { match *self { - Some(ref mut x) => x, - None => fail!("option::get_mut_ref `None`"), + Some(ref mut x) => x, + None => fail!("called `Option::get_mut_ref()` on a `None` value"), } } + /// Moves a value out of an option type and returns it. + /// + /// Useful primarily for getting strings, vectors and unique pointers out + /// of option types without copying them. + /// + /// # Failure + /// + /// Fails if the value equals `None`. + /// + /// # Safety note + /// + /// In general, because this function may fail, its use is discouraged. + /// Instead, prefer to use pattern matching and handle the `None` + /// case explicitly. #[inline] pub fn unwrap(self) -> T { - /*! - Moves a value out of an option type and returns it. - - Useful primarily for getting strings, vectors and unique pointers out - of option types without copying them. - - # Failure - - Fails if the value equals `None`. - - # Safety note - - In general, because this function may fail, its use is discouraged. - Instead, prefer to use pattern matching and handle the `None` - case explicitly. - */ match self { - Some(x) => x, - None => fail!("option::unwrap `None`"), + Some(x) => x, + None => fail!("called `Option::unwrap()` on a `None` value"), } } - /** - * The option dance. Moves a value out of an option type and returns it, - * replacing the original with `None`. - * - * # Failure - * - * Fails if the value equals `None`. - */ + /// The option dance. Moves a value out of an option type and returns it, + /// replacing the original with `None`. + /// + /// # Failure + /// + /// Fails if the value equals `None`. #[inline] pub fn take_unwrap(&mut self) -> T { - if self.is_none() { fail!("option::take_unwrap `None`") } + if self.is_none() { + fail!("called `Option::take_unwrap()` on a `None` value") + } self.take().unwrap() } - /** - * Gets the value out of an option, printing a specified message on - * failure - * - * # Failure - * - * Fails if the value equals `None` - */ + /// Gets the value out of an option, printing a specified message on + /// failure + /// + /// # Failure + /// + /// Fails if the value equals `None` #[inline] pub fn expect(self, reason: &str) -> T { match self { - Some(val) => val, - None => fail!(reason.to_owned()), + Some(val) => val, + None => fail!(reason.to_owned()), } } - /** - Gets the value out of an option - - # Failure - - Fails if the value equals `None` - - # Safety note - - In general, because this function may fail, its use is discouraged - (calling `get` on `None` is akin to dereferencing a null pointer). - Instead, prefer to use pattern matching and handle the `None` - case explicitly. - */ + /// Returns the contained value or a default #[inline] - pub fn get(self) -> T { + pub fn unwrap_or_default(self, def: T) -> T { match self { - Some(x) => return x, - None => fail!("option::get `None`") + Some(x) => x, + None => def } } - /// Returns the contained value or a default - #[inline] - pub fn get_or_default(self, def: T) -> T { - match self { Some(x) => x, None => def } - } - /// Applies a function zero or more times until the result is `None`. #[inline] pub fn while_some(self, blk: &fn(v: T) -> Option) { @@ -395,12 +382,21 @@ impl Option { impl Option { /// Returns the contained value or zero (for this type) #[inline] - pub fn get_or_zero(self) -> T { + pub fn unwrap_or_zero(self) -> T { match self { Some(x) => x, None => Zero::zero() } } + + /// Returns self or `Some(zero)` (for this type) + #[inline] + pub fn or_zero(self) -> Option { + match self { + None => Some(Zero::zero()), + x => x + } + } } impl Zero for Option { @@ -450,7 +446,7 @@ mod tests { use util; #[test] - fn test_unwrap_ptr() { + fn test_get_ptr() { unsafe { let x = ~0; let addr_x: *int = ::cast::transmute(&*x); @@ -462,7 +458,7 @@ mod tests { } #[test] - fn test_unwrap_str() { + fn test_get_str() { let x = ~"test"; let addr_x = x.as_imm_buf(|buf, _len| buf); let opt = Some(x); @@ -472,7 +468,7 @@ mod tests { } #[test] - fn test_unwrap_resource() { + fn test_get_resource() { struct R { i: @mut int, } @@ -530,18 +526,18 @@ mod tests { } #[test] - fn test_get_or_zero() { + fn test_unwrap_or_zero() { let some_stuff = Some(42); - assert_eq!(some_stuff.get_or_zero(), 42); + assert_eq!(some_stuff.unwrap_or_zero(), 42); let no_stuff: Option = None; - assert_eq!(no_stuff.get_or_zero(), 0); + assert_eq!(no_stuff.unwrap_or_zero(), 0); } #[test] fn test_filtered() { let some_stuff = Some(42); let modified_stuff = some_stuff.filtered(|&x| {x < 10}); - assert_eq!(some_stuff.get(), 42); + assert_eq!(some_stuff.unwrap(), 42); assert!(modified_stuff.is_none()); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 2d0b7d4f849d7..b0e1f35b4a018 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -571,7 +571,7 @@ pub fn tmpdir() -> Path { #[cfg(unix)] fn lookup() -> Path { - getenv_nonempty("TMPDIR").get_or_default(Path("/tmp")) + getenv_nonempty("TMPDIR").unwrap_or_default(Path("/tmp")) } #[cfg(windows)] @@ -579,7 +579,7 @@ pub fn tmpdir() -> Path { getenv_nonempty("TMP").or( getenv_nonempty("TEMP").or( getenv_nonempty("USERPROFILE").or( - getenv_nonempty("WINDIR")))).get_or_default(Path("C:\\Windows")) + getenv_nonempty("WINDIR")))).unwrap_or_default(Path("C:\\Windows")) } } @@ -1782,7 +1782,7 @@ mod tests { fn test_self_exe_path() { let path = os::self_exe_path(); assert!(path.is_some()); - let path = path.get(); + let path = path.unwrap(); debug!(path.clone()); // Hard to test this function diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index b7d72c11ff7a8..4ef524d77152b 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -533,7 +533,7 @@ impl RngUtil for R { /// Choose an item randomly, failing if values is empty fn choose(&mut self, values: &[T]) -> T { - self.choose_option(values).get() + self.choose_option(values).unwrap() } /// Choose Some(item) randomly, returning None if values is empty @@ -549,7 +549,7 @@ impl RngUtil for R { * the weights is 0 */ fn choose_weighted(&mut self, v: &[Weighted]) -> T { - self.choose_weighted_option(v).get() + self.choose_weighted_option(v).unwrap() } /** diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 7a578465841bb..181590e3929c5 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -20,23 +20,27 @@ use option::{None, Option, Some}; use vec; use vec::{OwnedVector, ImmutableVector}; use container::Container; - -/// The result type +use to_str::ToStr; +use str::StrSlice; + +/// `Result` is a type that represents either success (`Ok`) or failure (`Err`). +/// +/// In order to provide informative error messages, `E` is reqired to implement `ToStr`. +/// It is further recommended for `E` to be a descriptive error type, eg a `enum` for +/// all possible errors cases. #[deriving(Clone, Eq)] -pub enum Result { +pub enum Result { /// Contains the successful result value Ok(T), /// Contains the error value - Err(U) + Err(E) } -impl Result { - /** - * Convert to the `either` type - * - * `Ok` result variants are converted to `either::Right` variants, `Err` - * result variants are converted to `either::Left`. - */ +impl Result { + /// Convert to the `either` type + /// + /// `Ok` result variants are converted to `either::Right` variants, `Err` + /// result variants are converted to `either::Left`. #[inline] pub fn to_either(self)-> either::Either{ match self { @@ -45,18 +49,16 @@ impl Result { } } - /** - * Get a reference to the value out of a successful result - * - * # Failure - * - * If the result is an error - */ + /// Get a reference to the value out of a successful result + /// + /// # Failure + /// + /// If the result is an error #[inline] pub fn get_ref<'a>(&'a self) -> &'a T { match *self { Ok(ref t) => t, - Err(ref e) => fail!("get_ref called on `Err` result: %?", *e), + Err(ref e) => fail!("called `Result::get_ref()` on `Err` value: %s", e.to_str()), } } @@ -75,20 +77,18 @@ impl Result { !self.is_ok() } - /** - * Call a method based on a previous result - * - * If `self` is `Ok` then the value is extracted and passed to `op` - * whereupon `op`s result is returned. if `self` is `Err` then it is - * immediately returned. This function can be used to compose the results - * of two functions. - * - * Example: - * - * do read_file(file).iter |buf| { - * print_buf(buf) - * } - */ + /// Call a method based on a previous result + /// + /// If `self` is `Ok` then the value is extracted and passed to `op` + /// whereupon `op`s result is returned. if `self` is `Err` then it is + /// immediately returned. This function can be used to compose the results + /// of two functions. + /// + /// Example: + /// + /// do read_file(file).iter |buf| { + /// print_buf(buf) + /// } #[inline] pub fn iter(&self, f: &fn(&T)) { match *self { @@ -97,14 +97,12 @@ impl Result { } } - /** - * Call a method based on a previous result - * - * If `self` is `Err` then the value is extracted and passed to `op` - * whereupon `op`s result is returned. if `self` is `Ok` then it is - * immediately returned. This function can be used to pass through a - * successful result while handling an error. - */ + /// Call a method based on a previous result + /// + /// If `self` is `Err` then the value is extracted and passed to `op` + /// whereupon `op`s result is returned. if `self` is `Ok` then it is + /// immediately returned. This function can be used to pass through a + /// successful result while handling an error. #[inline] pub fn iter_err(&self, f: &fn(&E)) { match *self { @@ -113,38 +111,56 @@ impl Result { } } - /// Unwraps a result, assuming it is an `Ok(T)` + /// Unwraps a result, yielding the content of an `Ok`. + /// Fails if the value is a `Err` with an error message derived + /// from `E`'s `ToStr` implementation. #[inline] pub fn unwrap(self) -> T { match self { Ok(t) => t, - Err(_) => fail!("unwrap called on an `Err` result"), + Err(e) => fail!("called `Result::unwrap()` on `Err` value: %s", e.to_str()), } } - /// Unwraps a result, assuming it is an `Err(U)` + /// Unwraps a result, yielding the content of an `Err`. + /// Fails if the value is a `Ok`. #[inline] pub fn unwrap_err(self) -> E { + self.expect_err("called `Result::unwrap_err()` on `Ok` value") + } + + /// Unwraps a result, yielding the content of an `Ok`. + /// Fails if the value is a `Err` with a custom failure message. + #[inline] + pub fn expect(self, reason: &str) -> T { + match self { + Ok(t) => t, + Err(_) => fail!(reason.to_owned()), + } + } + + /// Unwraps a result, yielding the content of an `Err` + /// Fails if the value is a `Ok` with a custom failure message. + #[inline] + pub fn expect_err(self, reason: &str) -> E { match self { Err(e) => e, - Ok(_) => fail!("unwrap called on an `Ok` result"), + Ok(_) => fail!(reason.to_owned()), } } - /** - * Call a method based on a previous result - * - * If `self` is `Ok` then the value is extracted and passed to `op` - * whereupon `op`s result is returned. if `self` is `Err` then it is - * immediately returned. This function can be used to compose the results - * of two functions. - * - * Example: - * - * let res = do read_file(file) |buf| { - * Ok(parse_bytes(buf)) - * }; - */ + /// Call a method based on a previous result + /// + /// If `self` is `Ok` then the value is extracted and passed to `op` + /// whereupon `op`s result is returned. if `self` is `Err` then it is + /// immediately returned. This function can be used to compose the results + /// of two functions. + /// + /// Example: + /// + /// let res = do read_file(file) |buf| { + /// Ok(parse_bytes(buf)) + /// }; #[inline] pub fn chain(self, op: &fn(T) -> Result) -> Result { match self { @@ -153,14 +169,12 @@ impl Result { } } - /** - * Call a function based on a previous result - * - * If `self` is `Err` then the value is extracted and passed to `op` - * whereupon `op`s result is returned. if `self` is `Ok` then it is - * immediately returned. This function can be used to pass through a - * successful result while handling an error. - */ + /// Call a function based on a previous result + /// + /// If `self` is `Err` then the value is extracted and passed to `op` + /// whereupon `op`s result is returned. if `self` is `Ok` then it is + /// immediately returned. This function can be used to pass through a + /// successful result while handling an error. #[inline] pub fn chain_err(self, op: &fn(E) -> Result) -> Result { match self { @@ -170,32 +184,15 @@ impl Result { } } -impl Result { - /** - * Get the value out of a successful result - * - * # Failure - * - * If the result is an error - */ +impl Result { + /// Call a method based on a previous result + /// + /// If `self` is `Err` then the value is extracted and passed to `op` + /// whereupon `op`s result is wrapped in an `Err` and returned. if `self` is + /// `Ok` then it is immediately returned. This function can be used to pass + /// through a successful result while handling an error. #[inline] - pub fn get(&self) -> T { - match *self { - Ok(ref t) => t.clone(), - Err(ref e) => fail!("get called on `Err` result: %?", *e), - } - } - - /** - * Call a method based on a previous result - * - * If `self` is `Err` then the value is extracted and passed to `op` - * whereupon `op`s result is wrapped in an `Err` and returned. if `self` is - * `Ok` then it is immediately returned. This function can be used to pass - * through a successful result while handling an error. - */ - #[inline] - pub fn map_err(&self, op: &fn(&E) -> F) -> Result { + pub fn map_err(&self, op: &fn(&E) -> F) -> Result { match *self { Ok(ref t) => Ok(t.clone()), Err(ref e) => Err(op(e)) @@ -203,62 +200,57 @@ impl Result { } } -impl Result { - /** - * Get the value out of an error result - * - * # Failure - * - * If the result is not an error - */ +impl Result { + /// Call a method based on a previous result + /// + /// If `self` is `Ok` then the value is extracted and passed to `op` + /// whereupon `op`s result is wrapped in `Ok` and returned. if `self` is + /// `Err` then it is immediately returned. This function can be used to + /// compose the results of two functions. + /// + /// Example: + /// + /// let res = do read_file(file).map |buf| { + /// parse_bytes(buf) + /// }; #[inline] - pub fn get_err(&self) -> E { + pub fn map(&self, op: &fn(&T) -> U) -> Result { match *self { - Err(ref e) => e.clone(), - Ok(_) => fail!("get_err called on `Ok` result") + Ok(ref t) => Ok(op(t)), + Err(ref e) => Err(e.clone()) } } +} - /** - * Call a method based on a previous result - * - * If `self` is `Ok` then the value is extracted and passed to `op` - * whereupon `op`s result is wrapped in `Ok` and returned. if `self` is - * `Err` then it is immediately returned. This function can be used to - * compose the results of two functions. - * - * Example: - * - * let res = do read_file(file).map |buf| { - * parse_bytes(buf) - * }; - */ - #[inline] - pub fn map(&self, op: &fn(&T) -> U) -> Result { - match *self { - Ok(ref t) => Ok(op(t)), - Err(ref e) => Err(e.clone()) +#[inline] +#[allow(missing_doc)] +pub fn map_opt(o_t: &Option, + op: &fn(&T) -> Result) -> Result,U> { + match *o_t { + None => Ok(None), + Some(ref t) => match op(t) { + Ok(v) => Ok(Some(v)), + Err(e) => Err(e) } } } -/** - * Maps each element in the vector `ts` using the operation `op`. Should an - * error occur, no further mappings are performed and the error is returned. - * Should no error occur, a vector containing the result of each map is - * returned. - * - * Here is an example which increments every integer in a vector, - * checking for overflow: - * - * fn inc_conditionally(x: uint) -> result { - * if x == uint::max_value { return Err("overflow"); } - * else { return Ok(x+1u); } - * } - * map(~[1u, 2u, 3u], inc_conditionally).chain {|incd| - * assert!(incd == ~[2u, 3u, 4u]); - * } - */ +// FIXME: #8228 Replaceable by an external iterator? +/// Maps each element in the vector `ts` using the operation `op`. Should an +/// error occur, no further mappings are performed and the error is returned. +/// Should no error occur, a vector containing the result of each map is +/// returned. +/// +/// Here is an example which increments every integer in a vector, +/// checking for overflow: +/// +/// fn inc_conditionally(x: uint) -> result { +/// if x == uint::max_value { return Err("overflow"); } +/// else { return Ok(x+1u); } +/// } +/// map(~[1u, 2u, 3u], inc_conditionally).chain {|incd| +/// assert!(incd == ~[2u, 3u, 4u]); +/// } #[inline] pub fn map_vec(ts: &[T], op: &fn(&T) -> Result) -> Result<~[V],U> { @@ -272,36 +264,17 @@ pub fn map_vec(ts: &[T], op: &fn(&T) -> Result) return Ok(vs); } +// FIXME: #8228 Replaceable by an external iterator? +/// Same as map, but it operates over two parallel vectors. +/// +/// A precondition is used here to ensure that the vectors are the same +/// length. While we do not often use preconditions in the standard +/// library, a precondition is used here because result::t is generally +/// used in 'careful' code contexts where it is both appropriate and easy +/// to accommodate an error like the vectors being of different lengths. #[inline] -#[allow(missing_doc)] -pub fn map_opt( - o_t: &Option, - op: &fn(&T) -> Result) - -> Result,U> { - match *o_t { - None => Ok(None), - Some(ref t) => match op(t) { - Ok(v) => Ok(Some(v)), - Err(e) => Err(e) - } - } -} - -/** - * Same as map, but it operates over two parallel vectors. - * - * A precondition is used here to ensure that the vectors are the same - * length. While we do not often use preconditions in the standard - * library, a precondition is used here because result::t is generally - * used in 'careful' code contexts where it is both appropriate and easy - * to accommodate an error like the vectors being of different lengths. - */ -#[inline] -pub fn map_vec2(ss: &[S], ts: &[T], - op: &fn(&S,&T) -> Result) -> Result<~[V],U> { - +pub fn map_vec2(ss: &[S], ts: &[T], + op: &fn(&S,&T) -> Result) -> Result<~[V],U> { assert!(vec::same_length(ss, ts)); let n = ts.len(); let mut vs = vec::with_capacity(n); @@ -316,15 +289,13 @@ pub fn map_vec2(ss: &[S], ts: &[T], return Ok(vs); } -/** - * Applies op to the pairwise elements from `ss` and `ts`, aborting on - * error. This could be implemented using `map_zip()` but it is more efficient - * on its own as no result vector is built. - */ +// FIXME: #8228 Replaceable by an external iterator? +/// Applies op to the pairwise elements from `ss` and `ts`, aborting on +/// error. This could be implemented using `map_zip()` but it is more efficient +/// on its own as no result vector is built. #[inline] -pub fn iter_vec2(ss: &[S], ts: &[T], - op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> { - +pub fn iter_vec2(ss: &[S], ts: &[T], + op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> { assert!(vec::same_length(ss, ts)); let n = ts.len(); let mut i = 0u; @@ -353,12 +324,12 @@ mod tests { #[test] pub fn chain_success() { - assert_eq!(op1().chain(op2).get(), 667u); + assert_eq!(op1().chain(op2).unwrap(), 667u); } #[test] pub fn chain_failure() { - assert_eq!(op3().chain( op2).get_err(), ~"sadface"); + assert_eq!(op3().chain( op2).unwrap_err(), ~"sadface"); } #[test] diff --git a/src/libstd/rt/io/flate.rs b/src/libstd/rt/io/flate.rs index cbcc441811de6..16bca850fd289 100644 --- a/src/libstd/rt/io/flate.rs +++ b/src/libstd/rt/io/flate.rs @@ -115,7 +115,7 @@ mod test { let mem_reader = MemReader::new(buf); let mut inflate_reader = InflateReader::new(mem_reader); let mut out_bytes = [0, .. 100]; - let bytes_read = inflate_reader.read(out_bytes).get(); + let bytes_read = inflate_reader.read(out_bytes).unwrap(); assert_eq!(bytes_read, in_bytes.len()); let out_msg = str::from_bytes(out_bytes); assert!(in_msg == out_msg); diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs index 7d8c730e7c4b6..c980dc9d73efd 100644 --- a/src/libstd/rt/io/mod.rs +++ b/src/libstd/rt/io/mod.rs @@ -243,6 +243,8 @@ Out of scope */ use prelude::*; +use to_str::ToStr; +use str::{StrSlice, OwnedStr}; // Reexports pub use self::stdio::stdin; @@ -334,6 +336,20 @@ pub struct IoError { detail: Option<~str> } +// FIXME: #8242 implementing manually because deriving doesn't work for some reason +impl ToStr for IoError { + fn to_str(&self) -> ~str { + let mut s = ~"IoError { kind: "; + s.push_str(self.kind.to_str()); + s.push_str(", desc: "); + s.push_str(self.desc); + s.push_str(", detail: "); + s.push_str(self.detail.to_str()); + s.push_str(" }"); + s + } +} + #[deriving(Eq)] pub enum IoErrorKind { PreviousIoError, @@ -348,6 +364,24 @@ pub enum IoErrorKind { BrokenPipe } +// FIXME: #8242 implementing manually because deriving doesn't work for some reason +impl ToStr for IoErrorKind { + fn to_str(&self) -> ~str { + match *self { + PreviousIoError => ~"PreviousIoError", + OtherIoError => ~"OtherIoError", + EndOfFile => ~"EndOfFile", + FileNotFound => ~"FileNotFound", + PermissionDenied => ~"PermissionDenied", + ConnectionFailed => ~"ConnectionFailed", + Closed => ~"Closed", + ConnectionRefused => ~"ConnectionRefused", + ConnectionReset => ~"ConnectionReset", + BrokenPipe => ~"BrokenPipe" + } + } +} + // XXX: Can't put doc comments on macros // Raised by `I/O` operations on error. condition! { diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 33e83fd904041..760ca8a9adadc 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -365,7 +365,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int { rtdebug!("about to create the main scheduler task"); - let mut main_sched = main_sched.get(); + let mut main_sched = main_sched.unwrap(); let home = Sched(main_sched.make_handle()); let mut main_task = ~Task::new_root_homed(&mut main_sched.stack_pool, diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index cb949edd7bb4a..4c5e4bdc3c1d9 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -465,10 +465,10 @@ mod test { do run_in_newsched_task() { static key: local_data::Key<@~str> = &local_data::Key; local_data::set(key, @~"data"); - assert!(*local_data::get(key, |k| k.map(|&k| *k)).get() == ~"data"); + assert!(*local_data::get(key, |k| k.map(|&k| *k)).unwrap() == ~"data"); static key2: local_data::Key<@~str> = &local_data::Key; local_data::set(key2, @~"data"); - assert!(*local_data::get(key2, |k| k.map(|&k| *k)).get() == ~"data"); + assert!(*local_data::get(key2, |k| k.map(|&k| *k)).unwrap() == ~"data"); } } diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 2427da01a0c1c..8b5215ae9694a 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -154,7 +154,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { do run_in_bare_thread { let nthreads = match os::getenv("RUST_RT_TEST_THREADS") { - Some(nstr) => FromStr::from_str(nstr).get(), + Some(nstr) => FromStr::from_str(nstr).unwrap(), None => { // Using more threads than cores in test code // to force the OS to preempt them frequently. @@ -362,7 +362,7 @@ pub fn stress_factor() -> uint { use os::getenv; match getenv("RUST_RT_STRESS") { - Some(val) => uint::from_str(val).get(), + Some(val) => uint::from_str(val).unwrap(), None => 1 } } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 53307b3d2db81..40e5c8d4bf1a0 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -31,7 +31,7 @@ pub fn num_cpus() -> uint { /// either `RUST_THREADS` or `num_cpus`. pub fn default_sched_threads() -> uint { match os::getenv("RUST_THREADS") { - Some(nstr) => FromStr::from_str(nstr).get(), + Some(nstr) => FromStr::from_str(nstr).unwrap(), None => num_cpus() } } diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 67d3bbef8a9c6..fd3042899f6bc 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -108,7 +108,7 @@ fn uv_socket_addr_as_socket_addr(addr: UvSocketAddr, f: &fn(SocketAddr) -> T) "" => ~[], // IPv4-Mapped/Compatible IPv6 Address? s if s.find('.').is_some() => { - let i = s.rfind(':').get_or_default(-1); + let i = s.rfind(':').unwrap_or_default(-1); let b = s.slice(i + 1, s.len()); // the ipv4 part @@ -614,7 +614,7 @@ mod test { do tcp_watcher.connect(addr) |stream_watcher, status| { rtdebug!("tcp_watcher.connect!"); assert!(status.is_some()); - assert_eq!(status.get().name(), ~"ECONNREFUSED"); + assert_eq!(status.unwrap().name(), ~"ECONNREFUSED"); stream_watcher.close(||()); } loop_.run(); @@ -632,7 +632,7 @@ mod test { do tcp_watcher.connect(addr) |stream_watcher, status| { rtdebug!("tcp_watcher.connect!"); assert!(status.is_some()); - assert_eq!(status.get().name(), ~"ECONNREFUSED"); + assert_eq!(status.unwrap().name(), ~"ECONNREFUSED"); stream_watcher.close(||()); } loop_.run(); diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 85cf660a5f1aa..70a397199ab7c 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -278,7 +278,7 @@ impl IoFactory for UvIoFactory { rtdebug!("status is some"); let task_cell = Cell::new(task_cell.take()); do stream_watcher.close { - let res = Err(uv_error_to_io_error(status.get())); + let res = Err(uv_error_to_io_error(status.unwrap())); unsafe { (*result_cell_ptr).put_back(res); } let scheduler = Local::take::(); scheduler.resume_blocked_task_immediately(task_cell.take()); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index e43b58174bb56..b4057b85cbfef 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -58,7 +58,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get(); + let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } else { @@ -75,7 +75,7 @@ pub fn from_bytes_owned(vv: ~[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get(); + let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } else { diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index f7a943f8d2fdf..225a4b8cfd294 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -926,7 +926,7 @@ fn test_named_task() { t.name(~"ada lovelace"); do t.spawn { do with_task_name |name| { - assert!(name.get() == "ada lovelace"); + assert!(name.unwrap() == "ada lovelace"); } } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index f037aa2b7e789..4d4437cc963ea 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -195,10 +195,8 @@ pub fn build(builder: &fn(push: &fn(v: A))) -> ~[A] { * onto the vector being constructed. */ #[inline] -pub fn build_sized_opt(size: Option, - builder: &fn(push: &fn(v: A))) - -> ~[A] { - build_sized(size.get_or_default(4), builder) +pub fn build_sized_opt(size: Option, builder: &fn(push: &fn(v: A))) -> ~[A] { + build_sized(size.unwrap_or_default(4), builder) } /// An iterator over the slices of a vector separated by elements that diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index e6bbd45dae770..883020e637a1b 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -280,13 +280,13 @@ impl ToStr for AbiSet { #[test] fn lookup_Rust() { let abi = lookup("Rust"); - assert!(abi.is_some() && abi.get().data().name == "Rust"); + assert!(abi.is_some() && abi.unwrap().data().name == "Rust"); } #[test] fn lookup_cdecl() { let abi = lookup("cdecl"); - assert!(abi.is_some() && abi.get().data().name == "cdecl"); + assert!(abi.is_some() && abi.unwrap().data().name == "cdecl"); } #[test] diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index cf7a1e51798ac..435be3c71af6f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -24,7 +24,7 @@ use extra::serialize::{Encodable, Decodable, Encoder, Decoder}; // table) and a SyntaxContext to track renaming and // macro expansion per Flatt et al., "Macros // That Work Together" -#[deriving(Clone, Eq, IterBytes)] +#[deriving(Clone, Eq, IterBytes, ToStr)] pub struct ident { name: Name, ctxt: SyntaxContext } /// Construct an identifier with the given name and an empty context: @@ -121,7 +121,7 @@ pub type CrateNum = int; pub type NodeId = int; -#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes, ToStr)] pub struct def_id { crate: CrateNum, node: NodeId, diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index d1ddebfc347af..d39cb2f507ca9 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -114,7 +114,7 @@ impl AttributeMethods for Attribute { /// non-sugared doc attributes.) pub fn desugar_doc(&self) -> Attribute { if self.node.is_sugared_doc { - let comment = self.value_str().get(); + let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str(@"doc", strip_doc_comment_decoration(comment).to_managed()); mk_attr(meta) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 1dda2493da20a..6ed5ca3e402a8 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -538,20 +538,20 @@ mod test { m.insert (@"def",@16); // FIXME: #4492 (ICE) assert_eq!(m.find(&@"abc"),Some(@15)); // .... assert_eq!(m.find(&@"def"),Some(@16)); - assert_eq!(*(m.find(&@"abc").get()),15); - assert_eq!(*(m.find(&@"def").get()),16); + assert_eq!(*(m.find(&@"abc").unwrap()),15); + assert_eq!(*(m.find(&@"def").unwrap()),16); let n = m.push_frame(); // old bindings are still present: - assert_eq!(*(n.find(&@"abc").get()),15); - assert_eq!(*(n.find(&@"def").get()),16); + assert_eq!(*(n.find(&@"abc").unwrap()),15); + assert_eq!(*(n.find(&@"def").unwrap()),16); n.insert (@"def",@17); // n shows the new binding - assert_eq!(*(n.find(&@"abc").get()),15); - assert_eq!(*(n.find(&@"def").get()),17); + assert_eq!(*(n.find(&@"abc").unwrap()),15); + assert_eq!(*(n.find(&@"def").unwrap()),17); // ... but m still has the old ones // FIXME: #4492: assert_eq!(m.find(&@"abc"),Some(@15)); // FIXME: #4492: assert_eq!(m.find(&@"def"),Some(@16)); - assert_eq!(*(m.find(&@"abc").get()),15); - assert_eq!(*(m.find(&@"def").get()),16); + assert_eq!(*(m.find(&@"abc").unwrap()),15); + assert_eq!(*(m.find(&@"def").unwrap()),16); } } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index f5eb57c94b76f..fb1e6bf191384 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -961,7 +961,7 @@ fn create_struct_pattern(cx: @ExtCtxt, let field_pats = do vec::build |push| { for (&pat, &(id, _)) in subpats.iter().zip(ident_expr.iter()) { // id is guaranteed to be Some - push(ast::field_pat { ident: id.get(), pat: pat }) + push(ast::field_pat { ident: id.unwrap(), pat: pat }) } }; cx.pat_struct(span, matching_path, field_pats) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a6c5526b5a9b4..c7020b990bf00 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1182,9 +1182,9 @@ mod test { let a2_name = intern("a2"); let renamer = new_ident_renamer(ast::ident{name:a_name,ctxt:empty_ctxt}, a2_name); - let renamed_ast = fun_to_ident_folder(renamer).fold_item(item_ast).get(); + let renamed_ast = fun_to_ident_folder(renamer).fold_item(item_ast).unwrap(); let resolver = new_ident_resolver(); - let resolved_ast = fun_to_ident_folder(resolver).fold_item(renamed_ast).get(); + let resolved_ast = fun_to_ident_folder(resolver).fold_item(renamed_ast).unwrap(); let resolved_as_str = pprust::item_to_str(resolved_ast, get_ident_interner()); assert_eq!(resolved_as_str,~"fn a2() -> int { let b = 13; b }"); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 626a562b92c03..71903b9aa0204 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -31,7 +31,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); - let topmost = topmost_expn_info(cx.backtrace().get()); + let topmost = topmost_expn_info(cx.backtrace().unwrap()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); base::MRExpr(cx.expr_uint(topmost.call_site, loc.line)) @@ -42,7 +42,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); - let topmost = topmost_expn_info(cx.backtrace().get()); + let topmost = topmost_expn_info(cx.backtrace().unwrap()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); base::MRExpr(cx.expr_uint(topmost.call_site, loc.col.to_uint())) } @@ -54,7 +54,7 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); - let topmost = topmost_expn_info(cx.backtrace().get()); + let topmost = topmost_expn_info(cx.backtrace().unwrap()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); let filename = loc.file.name; base::MRExpr(cx.expr_str(topmost.call_site, filename)) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index db520aa162553..cffae66e614fd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -691,7 +691,7 @@ impl Parser { */ let opt_abis = self.parse_opt_abis(); - let abis = opt_abis.get_or_default(AbiSet::Rust()); + let abis = opt_abis.unwrap_or_default(AbiSet::Rust()); let purity = self.parse_unsafety(); self.expect_keyword(keywords::Fn); let (decl, lifetimes) = self.parse_ty_fn_decl(); @@ -3326,7 +3326,7 @@ impl Parser { let ident = self.parse_ident(); let opt_bounds = self.parse_optional_ty_param_bounds(); // For typarams we don't care about the difference b/w "" and "". - let bounds = opt_bounds.get_or_default(opt_vec::Empty); + let bounds = opt_bounds.unwrap_or_default(opt_vec::Empty); ast::TyParam { ident: ident, id: self.get_id(), bounds: bounds } } @@ -4196,7 +4196,7 @@ impl Parser { self.obsolete(*self.last_span, ObsoleteExternVisibility); } - let abis = opt_abis.get_or_default(AbiSet::C()); + let abis = opt_abis.unwrap_or_default(AbiSet::C()); let (inner, next) = self.parse_inner_attrs_and_next(); let m = self.parse_foreign_mod_items(sort, abis, next); @@ -4463,7 +4463,7 @@ impl Parser { if self.eat_keyword(keywords::Fn) { // EXTERN FUNCTION ITEM - let abis = opt_abis.get_or_default(AbiSet::C()); + let abis = opt_abis.unwrap_or_default(AbiSet::C()); let (ident, item_, extra_attrs) = self.parse_item_fn(extern_fn, abis); return iovi_item(self.mk_item(lo, self.last_span.hi, ident, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 174b0f8e4517c..f517179f60366 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -874,7 +874,7 @@ pub fn print_attribute(s: @ps, attr: &ast::Attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); if attr.node.is_sugared_doc { - let comment = attr.value_str().get(); + let comment = attr.value_str().unwrap(); word(s.s, comment); } else { word(s.s, "#["); @@ -1085,7 +1085,7 @@ pub fn print_call_post(s: @ps, } if sugar != ast::NoSugar { nbsp(s); - match blk.get().node { + match blk.unwrap().node { // need to handle closures specifically ast::expr_do_body(e) => { end(s); // we close our head box; closure @@ -1095,7 +1095,7 @@ pub fn print_call_post(s: @ps, } _ => { // not sure if this can happen. - print_expr(s, blk.get()); + print_expr(s, blk.unwrap()); } } } @@ -1323,13 +1323,13 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { assert!(body.stmts.is_empty()); assert!(body.expr.is_some()); // we extract the block, so as not to create another set of boxes - match body.expr.get().node { + match body.expr.unwrap().node { ast::expr_block(ref blk) => { print_block_unclosed(s, blk); } _ => { // this is a bare expression - print_expr(s, body.expr.get()); + print_expr(s, body.expr.unwrap()); end(s); // need to close a box } } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index da1c3596ff6c9..cf160ca31c6f1 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -100,7 +100,7 @@ fn main() { let args = os::args(); let n_keys = { if args.len() == 2 { - uint::from_str(args[1]).get() + uint::from_str(args[1]).unwrap() } else { 1000000 } diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 2c412e2eecd80..4fbe00622aa26 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -159,7 +159,7 @@ fn main() { let args = os::args(); let num_keys = { if args.len() == 2 { - uint::from_str(args[1]).get() + uint::from_str(args[1]).unwrap() } else { 100 // woefully inadequate for any real measurement } diff --git a/src/test/bench/core-uint-to-str.rs b/src/test/bench/core-uint-to-str.rs index 8924a9beb6e5e..4a32fda59d81a 100644 --- a/src/test/bench/core-uint-to-str.rs +++ b/src/test/bench/core-uint-to-str.rs @@ -21,7 +21,7 @@ fn main() { args }; - let n = uint::from_str(args[1]).get(); + let n = uint::from_str(args[1]).unwrap(); for i in range(0u, n) { let x = uint::to_str(i); diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 2557680f7b507..2f4d763b84d77 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -418,8 +418,8 @@ fn main() { args }; - let scale = uint::from_str(args[1]).get(); - let num_keys = uint::from_str(args[2]).get(); + let scale = uint::from_str(args[1]).unwrap(); + let num_keys = uint::from_str(args[2]).unwrap(); let do_validate = false; let do_sequential = true; diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 186923da43b8c..4e9656afb813d 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -59,8 +59,8 @@ fn run(args: &[~str]) { let to_child = SharedChan::new(to_child); - let size = uint::from_str(args[1]).get(); - let workers = uint::from_str(args[2]).get(); + let size = uint::from_str(args[1]).unwrap(); + let workers = uint::from_str(args[2]).unwrap(); let num_bytes = 100; let start = extra::time::precise_time_s(); let mut worker_results = ~[]; diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 05ace5fd8e6c7..470e23d63a514 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -53,8 +53,8 @@ fn run(args: &[~str]) { let (from_parent, to_child) = stream(); let to_child = SharedChan::new(to_child); - let size = uint::from_str(args[1]).get(); - let workers = uint::from_str(args[2]).get(); + let size = uint::from_str(args[1]).unwrap(); + let workers = uint::from_str(args[2]).unwrap(); let num_bytes = 100; let start = extra::time::precise_time_s(); let mut worker_results = ~[]; diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 649d029e60e8b..7de95f4d822c5 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -79,8 +79,8 @@ fn main() { args.clone() }; - let num_tasks = uint::from_str(args[1]).get(); - let msg_per_task = uint::from_str(args[2]).get(); + let num_tasks = uint::from_str(args[1]).unwrap(); + let msg_per_task = uint::from_str(args[2]).unwrap(); let (num_chan, num_port) = init(); let num_chan = Cell::new(num_chan); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 7f9d7aa588906..1299e863db6b3 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -75,8 +75,8 @@ fn main() { args.clone() }; - let num_tasks = uint::from_str(args[1]).get(); - let msg_per_task = uint::from_str(args[2]).get(); + let num_tasks = uint::from_str(args[1]).unwrap(); + let msg_per_task = uint::from_str(args[2]).unwrap(); let (num_chan, num_port) = init(); let num_chan = Cell::new(num_chan); diff --git a/src/test/bench/shootout-ackermann.rs b/src/test/bench/shootout-ackermann.rs index e06ff02a0b38f..e8659ba26d4bc 100644 --- a/src/test/bench/shootout-ackermann.rs +++ b/src/test/bench/shootout-ackermann.rs @@ -35,6 +35,6 @@ fn main() { } else { args }; - let n = int::from_str(args[1]).get(); + let n = int::from_str(args[1]).unwrap(); printfln!("Ack(3,%d): %d\n", n, ack(3, n)); } diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 57bf33fb2fdac..8a2ae3e899520 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -48,7 +48,7 @@ fn main() { args }; - let n = int::from_str(args[1]).get(); + let n = int::from_str(args[1]).unwrap(); let min_depth = 4; let mut max_depth; if min_depth + 2 > n { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index f48c15329463e..190ad62d6e17f 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -212,7 +212,7 @@ fn main() { args }; - let nn = uint::from_str(args[1]).get(); + let nn = uint::from_str(args[1]).unwrap(); print_complements(); io::println(""); diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index bf942cf61a38c..9d4d31b896920 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -91,6 +91,6 @@ fn fannkuch_redux(n: i32) -> i32 { #[fixed_stack_segment] fn main() { - let n: i32 = FromStr::from_str(os::args()[1]).get(); + let n: i32 = FromStr::from_str(os::args()[1]).unwrap(); printfln!("Pfannkuchen(%d) = %d", n as int, fannkuch_redux(n) as int); } diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index af96170c79c87..579b88a7e0e72 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -184,7 +184,7 @@ impl RandomFasta { #[fixed_stack_segment] fn main() { - let n: uint = FromStr::from_str(os::args()[1]).get(); + let n: uint = FromStr::from_str(os::args()[1]).unwrap(); unsafe { let mode = "w"; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 3a90c6647e08e..4e2ab8b0a498d 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -130,7 +130,7 @@ fn main() { io::stdout() }; - let n = int::from_str(args[1]).get(); + let n = int::from_str(args[1]).unwrap(); let iub: ~[AminoAcids] = make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32), diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs index 7b8bc31bf1c83..9c07df36eb3c1 100644 --- a/src/test/bench/shootout-fibo.rs +++ b/src/test/bench/shootout-fibo.rs @@ -31,6 +31,6 @@ fn main() { } else { args }; - let n = int::from_str(args[1]).get(); + let n = int::from_str(args[1]).unwrap(); printfln!("%d\n", fib(n)); } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 16936f6ed722d..cf43f470e7177 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -9,7 +9,7 @@ static LIMIT: f64 = 2.0; #[fixed_stack_segment] fn main() { unsafe { - let w: i32 = FromStr::from_str(os::args()[1]).get(); + let w: i32 = FromStr::from_str(os::args()[1]).unwrap(); let h = w; let mut byte_acc: i8 = 0; let mut bit_num: i32 = 0; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 99bd7c0f78672..115607d0a992c 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -137,7 +137,7 @@ fn offset_momentum(bodies: &mut [Planet, ..N_BODIES]) { } fn main() { - let n: i32 = FromStr::from_str(os::args()[1]).get(); + let n: i32 = FromStr::from_str(os::args()[1]).unwrap(); let mut bodies = BODIES; offset_momentum(&mut bodies); diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 663ebcac3340a..611b11560e4ae 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -110,7 +110,7 @@ fn main() { if opts.stress { stress(2); } else { - let max = uint::parse_bytes(args[1].as_bytes(), 10u).get() as int; + let max = uint::parse_bytes(args[1].as_bytes(), 10u).unwrap() as int; let num_trials = 10; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index e3c3c19c33bb3..aef22bc2b8426 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -52,7 +52,7 @@ fn mult_AtAv(v: &mut [f64], out: &mut [f64], tmp: &mut [f64]) { #[fixed_stack_segment] fn main() { - let n: uint = FromStr::from_str(os::args()[1]).get(); + let n: uint = FromStr::from_str(os::args()[1]).unwrap(); let mut u = vec::from_elem(n, 1f64); let mut v = u.clone(); let mut tmp = u.clone(); diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 203b9c297fa6b..ace008c1f95d2 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -62,13 +62,13 @@ fn main() { os::args() }; let token = if args.len() > 1u { - FromStr::from_str(args[1]).get() + FromStr::from_str(args[1]).unwrap() } else { 1000 }; let n_tasks = if args.len() > 2u { - FromStr::from_str(args[2]).get() + FromStr::from_str(args[2]).unwrap() } else { 503 diff --git a/src/test/bench/std-smallintmap.rs b/src/test/bench/std-smallintmap.rs index 2c2073eafea62..a035041a662dc 100644 --- a/src/test/bench/std-smallintmap.rs +++ b/src/test/bench/std-smallintmap.rs @@ -39,8 +39,8 @@ fn main() { } else { args }; - let max = uint::from_str(args[1]).get(); - let rep = uint::from_str(args[2]).get(); + let max = uint::from_str(args[1]).unwrap(); + let rep = uint::from_str(args[2]).unwrap(); let mut checkf = 0.0; let mut appendf = 0.0; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 49b2c32ed6867..6757354089534 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -75,9 +75,9 @@ impl Sudoku { let comps: ~[&str] = line.trim().split_iter(',').collect(); if comps.len() == 3u { - let row = uint::from_str(comps[0]).get() as u8; - let col = uint::from_str(comps[1]).get() as u8; - g[row][col] = uint::from_str(comps[2]).get() as u8; + let row = uint::from_str(comps[0]).unwrap() as u8; + let col = uint::from_str(comps[1]).unwrap() as u8; + g[row][col] = uint::from_str(comps[2]).unwrap() as u8; } else { fail!("Invalid sudoku file"); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 4e27841a74850..be7f9b5f43adf 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -52,7 +52,7 @@ fn main() { }; let (p,c) = comm::stream(); - child_generation(uint::from_str(args[1]).get(), c); + child_generation(uint::from_str(args[1]).unwrap(), c); if p.try_recv().is_none() { fail!("it happened when we slumbered"); } diff --git a/src/test/bench/task-perf-linked-failure.rs b/src/test/bench/task-perf-linked-failure.rs index 6ab83e5b3830b..95dd803af8183 100644 --- a/src/test/bench/task-perf-linked-failure.rs +++ b/src/test/bench/task-perf-linked-failure.rs @@ -71,7 +71,7 @@ fn main() { args.clone() }; - let num_tasks = uint::from_str(args[1]).get(); + let num_tasks = uint::from_str(args[1]).unwrap(); // Main group #0 waits for unsupervised group #1. // Grandparent group #1 waits for middle group #2, then fails, killing #3. diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index a152c30213318..83116ae3c87de 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -31,7 +31,7 @@ fn main() { } else { args }; - let n = uint::from_str(args[1]).get(); + let n = uint::from_str(args[1]).unwrap(); let mut i = 0u; while i < n { task::spawn(|| f(n) ); i += 1u; } } diff --git a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs index 451616a074f11..cb6290686816d 100644 --- a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs @@ -17,7 +17,7 @@ fn main() { y = Some(x.downgrade(write_mode)); //~^ ERROR cannot infer an appropriate lifetime } - y.get(); + y.unwrap(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).read |state| { assert!(*state == 1); } } diff --git a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs index b6535b6189a04..75e1989aff01a 100644 --- a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs @@ -17,7 +17,7 @@ fn main() { do x.write_downgrade |write_mode| { y = Some(write_mode); } - y.get(); + y.unwrap(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).write |state| { assert!(*state == 1); } } diff --git a/src/test/run-fail/result-get-fail.rs b/src/test/run-fail/result-get-fail.rs index 782ce61cab253..4f552bc8f4216 100644 --- a/src/test/run-fail/result-get-fail.rs +++ b/src/test/run-fail/result-get-fail.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:get called on `Err` result: ~"kitty" +// error-pattern:called `Result::unwrap()` on `Err` value: kitty use std::result; fn main() { - error!(result::Err::(~"kitty").get()); + error!(result::Err::(~"kitty").unwrap()); } diff --git a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm.rs b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm.rs index 3b18a8649eeea..668f602b3d35c 100644 --- a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm.rs +++ b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm.rs @@ -1,5 +1,5 @@ fn g(x: &Option) { - println(x.get().to_str()); + println(x.unwrap().to_str()); } fn f(x: &mut Option) { diff --git a/src/test/run-pass/borrowed-ptr-pattern-option.rs b/src/test/run-pass/borrowed-ptr-pattern-option.rs index 4775e5fe0a80e..9f17b9d7f95b5 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-option.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-option.rs @@ -19,5 +19,5 @@ fn select<'r>(x: &'r Option, y: &'r Option) -> &'r Option { pub fn main() { let x = None; let y = Some(3); - assert_eq!(select(&x, &y).get(), 3); + assert_eq!(select(&x, &y).unwrap(), 3); } diff --git a/src/test/run-pass/option_addition.rs b/src/test/run-pass/option_addition.rs index ac592d92cbadd..8af173150a06d 100644 --- a/src/test/run-pass/option_addition.rs +++ b/src/test/run-pass/option_addition.rs @@ -9,29 +9,17 @@ // except according to those terms. pub fn main() { - let foo = 1; - let bar = 2; + let foo: int = 1; + let bar: int = 2; let foobar = foo + bar; - let nope = optint(0) + optint(0); - let somefoo = optint(foo) + optint(0); - let somebar = optint(bar) + optint(0); - let somefoobar = optint(foo) + optint(bar); + let nope = None:: + None::; + let somefoo = Some(foo) + None::; + let somebar = None:: + Some(bar); + let somefoobar = Some(foo) + Some(bar); - match nope { - None => (), - Some(foo) => fail!("expected None, found %?", foo) - } - assert_eq!(foo, somefoo.get()); - assert_eq!(bar, somebar.get()); - assert_eq!(foobar, somefoobar.get()); -} - -fn optint(input: int) -> Option { - if input == 0 { - return None; - } - else { - return Some(input); - } + assert_eq!(nope, None::); + assert_eq!(somefoo, None::); + assert_eq!(somebar, None::); + assert_eq!(foobar, somefoobar.unwrap()); } diff --git a/src/test/run-pass/region-dependent-addr-of.rs b/src/test/run-pass/region-dependent-addr-of.rs index ac2fc2eda23cf..f5eb04dd83bfe 100644 --- a/src/test/run-pass/region-dependent-addr-of.rs +++ b/src/test/run-pass/region-dependent-addr-of.rs @@ -105,13 +105,13 @@ pub fn main() { assert_eq!(*p, a.value.v5.f); let p = get_v6_a(&a, 1); - assert_eq!(*p, a.value.v6.get().f); + assert_eq!(*p, a.value.v6.unwrap().f); let p = get_v6_b(&a, 1); - assert_eq!(*p, a.value.v6.get().f); + assert_eq!(*p, a.value.v6.unwrap().f); let p = get_v6_c(&a, 1); - assert_eq!(*p, a.value.v6.get().f); + assert_eq!(*p, a.value.v6.unwrap().f); let p = get_v5_ref(&a, 1); assert_eq!(*p, a.value.v5.f); From 1662f69068a2068cd719d4c3eecdba55b401d257 Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Fri, 2 Aug 2013 19:35:13 -0400 Subject: [PATCH 47/62] (cleanup) Uncomment an assertion that now holds. --- src/libstd/rt/kill.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index deec8dd37a600..ef2d0de5312ca 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -205,11 +205,10 @@ impl BlockedTask { let flag_arc = match task.death.spare_kill_flag.take() { Some(spare_flag) => spare_flag, None => { - // FIXME(#7544): Uncomment this when terminate_current_task - // stops being *terrible*. That's the only place that violates - // the assumption of "becoming unkillable will fail if the - // task was killed". - // rtassert!(task.unwinder.unwinding); + // A task that kills us won't have a spare kill flag to + // give back to us, so we restore it ourselves here. This + // situation should only arise when we're already failing. + rtassert!(task.unwinder.unwinding); (*task.death.kill_handle.get_ref().get()).killed.clone() } }; From ed814397068df8b84542a9f5f2a009fd734be1fb Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Mon, 5 Aug 2013 16:55:08 -0400 Subject: [PATCH 48/62] Lazily initialize 'leaf node' taskgroups for unlinked spawns, for an apparent 11% speedup. --- src/libstd/rt/kill.rs | 4 ++ src/libstd/task/spawn.rs | 104 ++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index ef2d0de5312ca..3372c13b87703 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -193,6 +193,10 @@ impl BlockedTask { /// Create a blocked task, unless the task was already killed. pub fn try_block(mut task: ~Task) -> Either<~Task, BlockedTask> { + // NB: As an optimization, we could give a free pass to being unkillable + // to tasks whose taskgroups haven't been initialized yet, but that + // introduces complications with select() and with the test cases below, + // and it's not clear the uncommon performance boost is worth it. if task.death.unkillable > 0 { Right(Unkillable(task)) } else { diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 3bf2f255f5751..527b20b0e9027 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -568,7 +568,8 @@ impl RuntimeGlue { let me = Local::unsafe_borrow::(); blk(match (*me).taskgroup { None => { - // Main task, doing first spawn ever. Lazily initialize. + // First task in its (unlinked/unsupervised) taskgroup. + // Lazily initialize. let mut members = TaskSet::new(); let my_handle = (*me).death.kill_handle.get_ref().clone(); members.insert(NewTask(my_handle)); @@ -591,37 +592,46 @@ impl RuntimeGlue { } } +// Returns 'None' in the case where the child's TG should be lazily initialized. fn gen_child_taskgroup(linked: bool, supervised: bool) - -> (TaskGroupArc, AncestorList, bool) { - do RuntimeGlue::with_my_taskgroup |spawner_group| { - let ancestors = AncestorList(spawner_group.ancestors.map(|x| x.clone())); - if linked { - // Child is in the same group as spawner. - // Child's ancestors are spawner's ancestors. - // Propagate main-ness. - (spawner_group.tasks.clone(), ancestors, spawner_group.is_main) - } else { - // Child is in a separate group from spawner. - let g = Exclusive::new(Some(TaskGroupData { - members: TaskSet::new(), - descendants: TaskSet::new(), - })); - let a = if supervised { - let new_generation = incr_generation(&ancestors); - assert!(new_generation < uint::max_value); - // Child's ancestors start with the spawner. - // Build a new node in the ancestor list. - AncestorList(Some(Exclusive::new(AncestorNode { - generation: new_generation, - parent_group: spawner_group.tasks.clone(), - ancestors: ancestors, - }))) + -> Option<(TaskGroupArc, AncestorList, bool)> { + // FIXME(#7544): Not safe to lazily initialize in the old runtime. Remove + // this context check once 'spawn_raw_oldsched' is gone. + if context() == OldTaskContext || linked || supervised { + // with_my_taskgroup will lazily initialize the parent's taskgroup if + // it doesn't yet exist. We don't want to call it in the unlinked case. + do RuntimeGlue::with_my_taskgroup |spawner_group| { + let ancestors = AncestorList(spawner_group.ancestors.map(|x| x.clone())); + if linked { + // Child is in the same group as spawner. + // Child's ancestors are spawner's ancestors. + // Propagate main-ness. + Some((spawner_group.tasks.clone(), ancestors, spawner_group.is_main)) } else { - // Child has no ancestors. - AncestorList(None) - }; - (g, a, false) + // Child is in a separate group from spawner. + let g = Exclusive::new(Some(TaskGroupData { + members: TaskSet::new(), + descendants: TaskSet::new(), + })); + let a = if supervised { + let new_generation = incr_generation(&ancestors); + assert!(new_generation < uint::max_value); + // Child's ancestors start with the spawner. + // Build a new node in the ancestor list. + AncestorList(Some(Exclusive::new(AncestorNode { + generation: new_generation, + parent_group: spawner_group.tasks.clone(), + ancestors: ancestors, + }))) + } else { + // Child has no ancestors. + AncestorList(None) + }; + Some((g, a, false)) + } } + } else { + None } } @@ -670,20 +680,24 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { let child_wrapper: ~fn() = || { // Child task runs this code. - let child_data = Cell::new(child_data.take()); // :( - let enlist_success = do Local::borrow:: |me| { - let (child_tg, ancestors, is_main) = child_data.take(); - let mut ancestors = ancestors; - // FIXME(#7544): Optimize out the xadd in this clone, somehow. - let handle = me.death.kill_handle.get_ref().clone(); - // Atomically try to get into all of our taskgroups. - if enlist_many(NewTask(handle), &child_tg, &mut ancestors) { - // Got in. We can run the provided child body, and can also run - // the taskgroup's exit-time-destructor afterward. - me.taskgroup = Some(Taskgroup(child_tg, ancestors, is_main, None)); - true - } else { - false + + // If child data is 'None', the enlist is vacuously successful. + let enlist_success = do child_data.take().map_consume_default(true) |child_data| { + let child_data = Cell::new(child_data); // :( + do Local::borrow:: |me| { + let (child_tg, ancestors, is_main) = child_data.take(); + let mut ancestors = ancestors; + // FIXME(#7544): Optimize out the xadd in this clone, somehow. + let handle = me.death.kill_handle.get_ref().clone(); + // Atomically try to get into all of our taskgroups. + if enlist_many(NewTask(handle), &child_tg, &mut ancestors) { + // Got in. We can run the provided child body, and can also run + // the taskgroup's exit-time-destructor afterward. + me.taskgroup = Some(Taskgroup(child_tg, ancestors, is_main, None)); + true + } else { + false + } } }; // Should be run after the local-borrowed task is returned. @@ -749,7 +763,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { let join_task = join_task_cell.take(); let bootstrap_task = ~do Task::new_root(&mut new_sched.stack_pool) || { - rtdebug!("boostraping a 1:1 scheduler"); + rtdebug!("bootstrapping a 1:1 scheduler"); }; new_sched.bootstrap(bootstrap_task); @@ -793,7 +807,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let (child_tg, ancestors, is_main) = - gen_child_taskgroup(opts.linked, opts.supervised); + gen_child_taskgroup(opts.linked, opts.supervised).expect("old runtime needs TG"); unsafe { let child_data = Cell::new((child_tg, ancestors, f)); From 94f82321242e5315cd4b321b16253e5a2b3b5ffc Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 19:40:20 +0200 Subject: [PATCH 49/62] std: Add .consume_iter() for Option, to make it reusable Let Option be a base for a widely useful one- or zero- item iterator. Refactor OptionIterator to support any generic element type, so the same iterator impl can be used for both &T, &mut T and T iterators. --- src/libstd/option.rs | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 3a4a9220ee16c..40a3944b7e0a4 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -116,7 +116,7 @@ impl ToStr for Option { impl Option { /// Return an iterator over the possibly contained value #[inline] - pub fn iter<'r>(&'r self) -> OptionIterator<'r, T> { + pub fn iter<'r>(&'r self) -> OptionIterator<&'r T> { match *self { Some(ref x) => OptionIterator{opt: Some(x)}, None => OptionIterator{opt: None} @@ -125,13 +125,19 @@ impl Option { /// Return a mutable iterator over the possibly contained value #[inline] - pub fn mut_iter<'r>(&'r mut self) -> OptionMutIterator<'r, T> { + pub fn mut_iter<'r>(&'r mut self) -> OptionIterator<&'r mut T> { match *self { - Some(ref mut x) => OptionMutIterator{opt: Some(x)}, - None => OptionMutIterator{opt: None} + Some(ref mut x) => OptionIterator{opt: Some(x)}, + None => OptionIterator{opt: None} } } + /// Return a consuming iterator over the possibly contained value + #[inline] + pub fn consume_iter(self) -> OptionIterator { + OptionIterator{opt: self} + } + /// Returns true if the option equals `None` #[inline] pub fn is_none(&self) -> bool { @@ -404,31 +410,13 @@ impl Zero for Option { fn is_zero(&self) -> bool { self.is_none() } } -/// Immutable iterator over an `Option` -pub struct OptionIterator<'self, A> { - priv opt: Option<&'self A> -} - -impl<'self, A> Iterator<&'self A> for OptionIterator<'self, A> { - fn next(&mut self) -> Option<&'self A> { - util::replace(&mut self.opt, None) - } - - fn size_hint(&self) -> (uint, Option) { - match self.opt { - Some(_) => (1, Some(1)), - None => (0, Some(0)), - } - } -} - -/// Mutable iterator over an `Option` -pub struct OptionMutIterator<'self, A> { - priv opt: Option<&'self mut A> +/// Immutable iterator over an Option +pub struct OptionIterator { + priv opt: Option } -impl<'self, A> Iterator<&'self mut A> for OptionMutIterator<'self, A> { - fn next(&mut self) -> Option<&'self mut A> { +impl Iterator for OptionIterator { + fn next(&mut self) -> Option { util::replace(&mut self.opt, None) } From 55657e6b7f861bd24819a7a049a5d776e00f1a80 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 19:40:20 +0200 Subject: [PATCH 50/62] std: Convert Result to use external iterators convert iter() and iter_err() for Result. Use OptionIterator. --- src/libstd/result.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 181590e3929c5..e06e58acbc8e8 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -16,7 +16,7 @@ use clone::Clone; use cmp::Eq; use either; use iterator::Iterator; -use option::{None, Option, Some}; +use option::{None, Option, Some, OptionIterator}; use vec; use vec::{OwnedVector, ImmutableVector}; use container::Container; @@ -86,15 +86,15 @@ impl Result { /// /// Example: /// - /// do read_file(file).iter |buf| { + /// for buf in read_file(file) { /// print_buf(buf) /// } #[inline] - pub fn iter(&self, f: &fn(&T)) { + pub fn iter<'r>(&'r self) -> OptionIterator<&'r T> { match *self { - Ok(ref t) => f(t), - Err(_) => (), - } + Ok(ref t) => Some(t), + Err(*) => None, + }.consume_iter() } /// Call a method based on a previous result @@ -104,11 +104,11 @@ impl Result { /// immediately returned. This function can be used to pass through a /// successful result while handling an error. #[inline] - pub fn iter_err(&self, f: &fn(&E)) { + pub fn iter_err<'r>(&'r self) -> OptionIterator<&'r E> { match *self { - Ok(_) => (), - Err(ref e) => f(e), - } + Ok(*) => None, + Err(ref t) => Some(t), + }.consume_iter() } /// Unwraps a result, yielding the content of an `Ok`. @@ -335,21 +335,25 @@ mod tests { #[test] pub fn test_impl_iter() { let mut valid = false; - Ok::<~str, ~str>(~"a").iter(|_x| valid = true); + let okval = Ok::<~str, ~str>(~"a"); + do okval.iter().next().map |_| { valid = true; }; assert!(valid); - Err::<~str, ~str>(~"b").iter(|_x| valid = false); + let errval = Err::<~str, ~str>(~"b"); + do errval.iter().next().map |_| { valid = false; }; assert!(valid); } #[test] pub fn test_impl_iter_err() { let mut valid = true; - Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false); + let okval = Ok::<~str, ~str>(~"a"); + do okval.iter_err().next().map |_| { valid = false }; assert!(valid); valid = false; - Err::<~str, ~str>(~"b").iter_err(|_x| valid = true); + let errval = Err::<~str, ~str>(~"b"); + do errval.iter_err().next().map |_| { valid = true }; assert!(valid); } From ecee2857a94ea347780cfede028ac11986985904 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 19:40:20 +0200 Subject: [PATCH 51/62] std: Remove unused trait bound in Result::map --- src/libstd/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/result.rs b/src/libstd/result.rs index e06e58acbc8e8..5a6021d32a5e3 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -214,7 +214,7 @@ impl Result { /// parse_bytes(buf) /// }; #[inline] - pub fn map(&self, op: &fn(&T) -> U) -> Result { + pub fn map(&self, op: &fn(&T) -> U) -> Result { match *self { Ok(ref t) => Ok(op(t)), Err(ref e) => Err(e.clone()) From 2c21b99f4e30b4fe1fec423ee1b80f7e117efefa Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 19:40:20 +0200 Subject: [PATCH 52/62] std: Implement RandomAccessIterator for Invert --- src/libstd/iterator.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 0769aa6a76464..372afd7402d45 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -106,6 +106,16 @@ impl> DoubleEndedIterator for Invert { fn next_back(&mut self) -> Option { self.iter.next() } } +impl + RandomAccessIterator> RandomAccessIterator + for Invert { + #[inline] + fn indexable(&self) -> uint { self.iter.indexable() } + #[inline] + fn idx(&self, index: uint) -> Option { + self.iter.idx(self.indexable() - index - 1) + } +} + /// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also /// implementations of the `Iterator` trait. /// @@ -2017,6 +2027,17 @@ mod tests { check_randacc_iter(xs.iter().enumerate(), xs.len()); } + #[test] + fn test_random_access_invert() { + let xs = [1, 2, 3, 4, 5]; + check_randacc_iter(xs.iter().invert(), xs.len()); + let mut it = xs.iter().invert(); + it.next(); + it.next_back(); + it.next(); + check_randacc_iter(it, xs.len() - 3); + } + #[test] fn test_random_access_zip() { let xs = [1, 2, 3, 4, 5]; From 1c01b1da8e4cacc609b4401669711b946e716563 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 19:40:20 +0200 Subject: [PATCH 53/62] std: Improve vec::ChunkIter Implement clone, bidirectionality and random access for this iterator --- src/libstd/vec.rs | 59 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 4d4437cc963ea..fa1291c61e1be 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -479,6 +479,7 @@ pub fn each_permutation(values: &[T], fun: &fn(perm : &[T]) -> bool) -> /// An iterator over the (overlapping) slices of length `size` within /// a vector. +#[deriving(Clone)] pub struct WindowIter<'self, T> { priv v: &'self [T], priv size: uint @@ -498,6 +499,10 @@ impl<'self, T> Iterator<&'self [T]> for WindowIter<'self, T> { /// An iterator over a vector in (non-overlapping) chunks (`size` /// elements at a time). +/// +/// When the vector len is not evenly divided by the chunk size, +/// the last slice of the iteration will be the remainer. +#[deriving(Clone)] pub struct ChunkIter<'self, T> { priv v: &'self [T], priv size: uint @@ -505,16 +510,46 @@ pub struct ChunkIter<'self, T> { impl<'self, T> Iterator<&'self [T]> for ChunkIter<'self, T> { fn next(&mut self) -> Option<&'self [T]> { - if self.size == 0 { + if self.v.len() == 0 { None - } else if self.size >= self.v.len() { - // finished - self.size = 0; - Some(self.v) } else { - let ret = Some(self.v.slice(0, self.size)); - self.v = self.v.slice(self.size, self.v.len()); - ret + let chunksz = cmp::min(self.v.len(), self.size); + let (fst, snd) = (self.v.slice_to(chunksz), + self.v.slice_from(chunksz)); + self.v = snd; + Some(fst) + } + } +} + +impl<'self, T> DoubleEndedIterator<&'self [T]> for ChunkIter<'self, T> { + fn next_back(&mut self) -> Option<&'self [T]> { + if self.v.len() == 0 { + None + } else { + let remainder = self.v.len() % self.size; + let chunksz = if remainder != 0 { remainder } else { self.size }; + let (fst, snd) = (self.v.slice_to(self.v.len() - chunksz), + self.v.slice_from(self.v.len() - chunksz)); + self.v = fst; + Some(snd) + } + } +} + +impl<'self, T> RandomAccessIterator<&'self [T]> for ChunkIter<'self, T> { + #[inline] + fn indexable(&self) -> uint { + self.v.len()/self.size + if self.v.len() % self.size != 0 { 1 } else { 0 } + } + + #[inline] + fn idx(&self, index: uint) -> Option<&'self [T]> { + if index < self.indexable() { + let lo = index * self.size; + Some(self.v.slice(lo, cmp::min(lo, self.v.len() - self.size) + self.size)) + } else { + None } } } @@ -3378,6 +3413,14 @@ mod tests { assert_eq!(v.chunk_iter(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]); assert_eq!(v.chunk_iter(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]); assert_eq!(v.chunk_iter(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]); + + assert_eq!(v.chunk_iter(2).invert().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]); + let it = v.chunk_iter(2); + assert_eq!(it.indexable(), 3); + assert_eq!(it.idx(0).unwrap(), &[1,2]); + assert_eq!(it.idx(1).unwrap(), &[3,4]); + assert_eq!(it.idx(2).unwrap(), &[5]); + assert_eq!(it.idx(3), None); } #[test] From c2d481215a1e865dbac74b714cad6de1121a6914 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 21:34:00 +0200 Subject: [PATCH 54/62] std: Add iterator::Repeat to repeat an element endlessly --- src/libstd/iterator.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 372afd7402d45..bf55b4f7ce2e3 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -1565,6 +1565,39 @@ impl + Clone> Iterator for Counter { } } +/// An iterator that repeats an element endlessly +#[deriving(Clone, DeepClone)] +pub struct Repeat { + priv element: A +} + +impl Repeat { + /// Create a new `Repeat` that enlessly repeats the element `elt`. + #[inline] + pub fn new(elt: A) -> Repeat { + Repeat{element: elt} + } +} + +impl Iterator for Repeat { + #[inline] + fn next(&mut self) -> Option { self.idx(0) } + #[inline] + fn size_hint(&self) -> (uint, Option) { (uint::max_value, None) } +} + +impl DoubleEndedIterator for Repeat { + #[inline] + fn next_back(&mut self) -> Option { self.idx(0) } +} + +impl RandomAccessIterator for Repeat { + #[inline] + fn indexable(&self) -> uint { uint::max_value } + #[inline] + fn idx(&self, _: uint) -> Option { Some(self.element.clone()) } +} + #[cfg(test)] mod tests { use super::*; From a2f116c3a6ec600db9fea2676b33f2dcc8d9779a Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 21:34:00 +0200 Subject: [PATCH 55/62] std: Rewrite the HashSet set operation iterators Use the Repeat iterator to carry the "explicit closure capture" that was previously done with the custom EnvFilterIterator. --- src/libstd/hashmap.rs | 54 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 658f854c50d81..fbc471c0ae05d 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -19,7 +19,8 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; use clone::Clone; use cmp::{Eq, Equiv}; use hash::Hash; -use iterator::{Iterator, IteratorUtil, FromIterator, Extendable, Chain, range}; +use iterator::{Iterator, IteratorUtil, FromIterator, Extendable, range}; +use iterator::{FilterMap, Chain, Repeat, Zip}; use num; use option::{None, Option, Some}; use rand::RngUtil; @@ -712,10 +713,12 @@ impl HashSet { } /// Visit the values representing the difference - pub fn difference_iter<'a>(&'a self, other: &'a HashSet) - -> SetAlgebraIter<'a, T> { - EnvFilterIterator{iter: self.iter(), env: other, - filter: |elt, other| !other.contains(elt) } + pub fn difference_iter<'a>(&'a self, other: &'a HashSet) -> SetAlgebraIter<'a, T> { + Repeat::new(other) + .zip(self.iter()) + .filter_map(|(other, elt)| { + if !other.contains(elt) { Some(elt) } else { None } + }) } /// Visit the values representing the symmetric difference @@ -727,8 +730,11 @@ impl HashSet { /// Visit the values representing the intersection pub fn intersection_iter<'a>(&'a self, other: &'a HashSet) -> SetAlgebraIter<'a, T> { - EnvFilterIterator{iter: self.iter(), env: other, - filter: |elt, other| other.contains(elt) } + Repeat::new(other) + .zip(self.iter()) + .filter_map(|(other, elt)| { + if other.contains(elt) { Some(elt) } else { None } + }) } /// Visit the values representing the union @@ -756,38 +762,12 @@ impl> Extendable for HashSet { } } -// FIXME #7814: use std::iterator::FilterIterator -/// Building block for Set operation iterators -pub struct EnvFilterIterator { - priv env: Env, - priv filter: &'static fn(&A, Env) -> bool, - priv iter: I, -} - -impl<'self, A, Env: Clone, I: Iterator<&'self A>> Iterator<&'self A> - for EnvFilterIterator { - #[inline] - fn next(&mut self) -> Option<&'self A> { - loop { - match self.iter.next() { - Some(elt) => if (self.filter)(elt, self.env.clone()) { - return Some(elt) - }, - None => return None, - } - } - } - - #[inline] - fn size_hint(&self) -> (uint, Option) { - let (_, upper) = self.iter.size_hint(); - (0, upper) - } -} - +// `Repeat` is used to feed the filter closure an explicit capture +// of a reference to the other set /// Set operations iterator pub type SetAlgebraIter<'self, T> = - EnvFilterIterator, HashSetIterator<'self, T>>; + FilterMap<'static,(&'self HashSet, &'self T), &'self T, + Zip>,HashSetIterator<'self,T>>>; #[cfg(test)] From e843b881719dde9ffeabc7dcfc9db3bd8b9dbf47 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 21:34:00 +0200 Subject: [PATCH 56/62] std: Use method name Option::consume With Option as the simplest container, `consume` is the way to turn it into a by-value iterator. --- src/libstd/option.rs | 8 +++++--- src/libstd/result.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 40a3944b7e0a4..ea1bddcdb4b9d 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -134,7 +134,7 @@ impl Option { /// Return a consuming iterator over the possibly contained value #[inline] - pub fn consume_iter(self) -> OptionIterator { + pub fn consume(self) -> OptionIterator { OptionIterator{opt: self} } @@ -410,16 +410,18 @@ impl Zero for Option { fn is_zero(&self) -> bool { self.is_none() } } -/// Immutable iterator over an Option +/// An iterator that yields either one or zero elements pub struct OptionIterator { priv opt: Option } impl Iterator for OptionIterator { + #[inline] fn next(&mut self) -> Option { - util::replace(&mut self.opt, None) + self.opt.take() } + #[inline] fn size_hint(&self) -> (uint, Option) { match self.opt { Some(_) => (1, Some(1)), diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 5a6021d32a5e3..91f42edf0aecd 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -94,7 +94,7 @@ impl Result { match *self { Ok(ref t) => Some(t), Err(*) => None, - }.consume_iter() + }.consume() } /// Call a method based on a previous result @@ -108,7 +108,7 @@ impl Result { match *self { Ok(*) => None, Err(ref t) => Some(t), - }.consume_iter() + }.consume() } /// Unwraps a result, yielding the content of an `Ok`. From cbbca97876a0f9d823108cc874d0c4fb14cbacd6 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sat, 3 Aug 2013 21:34:00 +0200 Subject: [PATCH 57/62] std: Improve the documentation for iterator::Invert --- src/libstd/iterator.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index bf55b4f7ce2e3..56a0dca56679c 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -82,6 +82,17 @@ pub trait DoubleEndedIteratorUtil { /// In the future these will be default methods instead of a utility trait. impl> DoubleEndedIteratorUtil for T { /// Flip the direction of the iterator + /// + /// The inverted iterator flips the ends on an iterator that can already + /// be iterated from the front and from the back. + /// + /// + /// If the iterator also implements RandomAccessIterator, the inverted + /// iterator is also random access, with the indices starting at the back + /// of the original iterator. + /// + /// Note: Random access with inverted indices still only applies to the first + /// `uint::max_value` elements of the original iterator. #[inline] fn invert(self) -> Invert { Invert{iter: self} From f0e345b693323004327ac0a50f46642ec3ca1004 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 4 Aug 2013 04:49:44 +0200 Subject: [PATCH 58/62] extra: Simplify the bitv iterators using Repeat --- src/libextra/bitv.rs | 63 +++++++++++++------------------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index bf618d7bd3a6f..f32170a3a6de6 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -13,7 +13,7 @@ use std::cmp; use std::iterator::RandomAccessIterator; -use std::iterator::{Invert, Enumerate}; +use std::iterator::{Invert, Enumerate, Repeat, Map, Zip}; use std::num; use std::ops; use std::uint; @@ -864,13 +864,12 @@ impl BitvSet { /// w1, w2) where the bit location is the number of bits offset so far, /// and w1/w2 are the words coming from the two vectors self, other. fn common_iter<'a>(&'a self, other: &'a BitvSet) - -> MapE<(uint,&uint),(uint,uint,uint), &'a ~[uint],Enumerate>> { - let min = num::min(self.bitv.storage.len(), - other.bitv.storage.len()); - MapE{iter: self.bitv.storage.slice(0, min).iter().enumerate(), - env: &other.bitv.storage, - f: |(i, &w): (uint, &uint), o_store| (i * uint::bits, w, o_store[i]) - } + -> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint), + Zip>, Repeat<&'a ~[uint]>>> { + let min = num::min(self.bitv.storage.len(), other.bitv.storage.len()); + self.bitv.storage.slice(0, min).iter().enumerate() + .zip(Repeat::new(&other.bitv.storage)) + .transform(|((i, &w), o_store)| (i * uint::bits, w, o_store[i])) } /// Visits each word in self or other that extends beyond the other. This @@ -881,45 +880,21 @@ impl BitvSet { /// is true if the word comes from 'self', and false if it comes from /// 'other'. fn outlier_iter<'a>(&'a self, other: &'a BitvSet) - -> MapE<(uint, &uint),(bool, uint, uint), uint, Enumerate>> { - let len1 = self.bitv.storage.len(); - let len2 = other.bitv.storage.len(); - let min = num::min(len1, len2); - - if min < len1 { - MapE{iter: self.bitv.storage.slice(min, len1).iter().enumerate(), - env: min, - f: |(i, &w): (uint, &uint), min| (true, (i + min) * uint::bits, w) - } + -> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint), + Zip>, Repeat>> { + let slen = self.bitv.storage.len(); + let olen = other.bitv.storage.len(); + + if olen < slen { + self.bitv.storage.slice_from(olen).iter().enumerate() + .zip(Repeat::new(olen)) + .transform(|((i, &w), min)| (true, (i + min) * uint::bits, w)) } else { - MapE{iter: other.bitv.storage.slice(min, len2).iter().enumerate(), - env: min, - f: |(i, &w): (uint, &uint), min| (false, (i + min) * uint::bits, w) - } - } - } -} - -/// Like iterator::Map with explicit env capture -struct MapE { - priv env: Env, - priv f: &'static fn(A, Env) -> B, - priv iter: I, -} - -impl<'self, A, B, Env: Clone, I: Iterator> Iterator for MapE { - #[inline] - fn next(&mut self) -> Option { - match self.iter.next() { - Some(elt) => Some((self.f)(elt, self.env.clone())), - None => None + other.bitv.storage.slice_from(slen).iter().enumerate() + .zip(Repeat::new(slen)) + .transform(|((i, &w), min)| (false, (i + min) * uint::bits, w)) } } - - #[inline] - fn size_hint(&self) -> (uint, Option) { - self.iter.size_hint() - } } pub struct BitvSetIterator<'self> { From eccf370beccf828b26da903672a65062431dfddd Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 4 Aug 2013 17:10:09 +0200 Subject: [PATCH 59/62] std: Remove uint::iterate, replaced by `range` --- src/libextra/bitv.rs | 7 +++---- src/libstd/num/uint.rs | 24 ------------------------ src/libstd/ptr.rs | 7 +++---- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index f32170a3a6de6..6dedd9ee4dd26 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -206,14 +206,13 @@ impl BigBitv { #[inline] pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool { let len = b.storage.len(); - do uint::iterate(0, len) |i| { + for i in range(0, len) { let mask = big_mask(nbits, i); if mask & self.storage[i] != mask & b.storage[i] { - false - } else { - true + return false; } } + true } } diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 275a72d6ecc05..86bc98e53fcb6 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -70,30 +70,6 @@ pub fn div_round(x: uint, y: uint) -> uint { /// pub fn div_floor(x: uint, y: uint) -> uint { return x / y; } -/// -/// Iterate over the range [`lo`..`hi`), or stop when requested -/// -/// # Arguments -/// -/// * lo - The integer at which to start the loop (included) -/// * hi - The integer at which to stop the loop (excluded) -/// * it - A block to execute with each consecutive integer of the range. -/// Return `true` to continue, `false` to stop. -/// -/// # Return value -/// -/// `true` If execution proceeded correctly, `false` if it was interrupted, -/// that is if `it` returned `false` at any point. -/// -pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool { - let mut i = lo; - while i < hi { - if (!it(i)) { return false; } - i += 1u; - } - return true; -} - impl iter::Times for uint { #[inline] /// diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 55c18faf83dee..dfd11f9227d41 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -12,6 +12,7 @@ use cast; use clone::Clone; +use iterator::{range, Iterator}; use option::{Option, Some, None}; use unstable::intrinsics; use util::swap; @@ -20,7 +21,6 @@ use util::swap; #[cfg(not(test))] use num::Int; #[cfg(not(test))] use cmp::{Eq, Ord}; -use uint; /// Calculate the offset from a pointer #[inline] @@ -240,11 +240,10 @@ pub unsafe fn array_each_with_len(arr: **T, len: uint, cb: &fn(*T)) { fail!("ptr::array_each_with_len failure: arr input is null pointer"); } //let start_ptr = *arr; - uint::iterate(0, len, |e| { + for e in range(0, len) { let n = offset(arr, e as int); cb(*n); - true - }); + } debug!("array_each_with_len: after iterate"); } From 282fb72ed3ef6f9c541548b8e3abb118330d2638 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 4 Aug 2013 22:46:26 +0200 Subject: [PATCH 60/62] std: Fix bug in ChunkIter::idx ChunkIter .idx() didn't handle overflow correctly, even though it tried. --- src/libstd/vec.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index fa1291c61e1be..0259b547ab3f0 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -547,7 +547,10 @@ impl<'self, T> RandomAccessIterator<&'self [T]> for ChunkIter<'self, T> { fn idx(&self, index: uint) -> Option<&'self [T]> { if index < self.indexable() { let lo = index * self.size; - Some(self.v.slice(lo, cmp::min(lo, self.v.len() - self.size) + self.size)) + let mut hi = lo + self.size; + if hi < lo || hi > self.v.len() { hi = self.v.len(); } + + Some(self.v.slice(lo, hi)) } else { None } From 26d74df5523c276ad074d1754288e4885fb7c73f Mon Sep 17 00:00:00 2001 From: Sangeun Kim Date: Fri, 26 Jul 2013 13:53:29 +0900 Subject: [PATCH 61/62] Move EnumSet into libextra --- src/{librustc/util => libextra}/enum_set.rs | 62 ++++++--------------- src/libextra/extra.rs | 1 + src/librustc/metadata/tyencode.rs | 5 +- src/librustc/middle/kind.rs | 5 +- src/librustc/middle/ty.rs | 12 ++-- src/librustc/rustc.rs | 1 - src/librustc/util/ppaux.rs | 10 ++-- 7 files changed, 30 insertions(+), 66 deletions(-) rename src/{librustc/util => libextra}/enum_set.rs (86%) diff --git a/src/librustc/util/enum_set.rs b/src/libextra/enum_set.rs similarity index 86% rename from src/librustc/util/enum_set.rs rename to src/libextra/enum_set.rs index ced29f18f7f11..25501faa02e12 100644 --- a/src/librustc/util/enum_set.rs +++ b/src/libextra/enum_set.rs @@ -11,14 +11,18 @@ use std::iterator::Iterator; #[deriving(Clone, Eq, IterBytes, ToStr)] +/// A specialized Set implementation to use enum types. pub struct EnumSet { // We must maintain the invariant that no bits are set // for which no variant exists priv bits: uint } +/// An iterface for casting C-like enum to uint and back. pub trait CLike { + /// Converts C-like enum to uint. pub fn to_uint(&self) -> uint; + /// Converts uint to C-like enum. pub fn from_uint(uint) -> Self; } @@ -27,54 +31,47 @@ fn bit(e: E) -> uint { } impl EnumSet { + /// Returns an empty EnumSet. pub fn empty() -> EnumSet { EnumSet {bits: 0} } + /// Returns true if an EnumSet is empty. pub fn is_empty(&self) -> bool { self.bits == 0 } + /// Returns true if an EnumSet contains any enum of a given EnumSet pub fn intersects(&self, e: EnumSet) -> bool { (self.bits & e.bits) != 0 } + /// Returns an intersection of both EnumSets. pub fn intersection(&self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & e.bits} } + /// Returns true if a given EnumSet is included in an EnumSet. pub fn contains(&self, e: EnumSet) -> bool { (self.bits & e.bits) == e.bits } + /// Returns a union of both EnumSets. pub fn union(&self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits | e.bits} } + /// Add an enum to an EnumSet pub fn add(&mut self, e: E) { self.bits |= bit(e); } + /// Returns true if an EnumSet contains a given enum pub fn contains_elem(&self, e: E) -> bool { (self.bits & bit(e)) != 0 } - pub fn each(&self, f: &fn(E) -> bool) -> bool { - let mut bits = self.bits; - let mut index = 0; - while bits != 0 { - if (bits & 1) != 0 { - let e = CLike::from_uint(index); - if !f(e) { - return false; - } - } - index += 1; - bits >>= 1; - } - return true; - } - + /// Returns an iterator over an EnumSet pub fn iter(&self) -> EnumSetIterator { EnumSetIterator::new(self.bits) } @@ -98,6 +95,7 @@ impl BitAnd, EnumSet> for EnumSet { } } +/// An iterator over an EnumSet pub struct EnumSetIterator { priv index: uint, priv bits: uint, @@ -136,7 +134,7 @@ mod test { use std::cast; - use util::enum_set::*; + use enum_set::*; #[deriving(Eq)] enum Foo { @@ -236,7 +234,7 @@ mod test { } /////////////////////////////////////////////////////////////////////////// - // iter / each + // iter #[test] fn test_iterator() { @@ -262,34 +260,6 @@ mod test { assert_eq!(~[A,B,C], elems) } - #[test] - fn test_each() { - let mut e1: EnumSet = EnumSet::empty(); - - assert_eq!(~[], collect(e1)) - - e1.add(A); - assert_eq!(~[A], collect(e1)) - - e1.add(C); - assert_eq!(~[A,C], collect(e1)) - - e1.add(C); - assert_eq!(~[A,C], collect(e1)) - - e1.add(B); - assert_eq!(~[A,B,C], collect(e1)) - } - - fn collect(e: EnumSet) -> ~[Foo] { - let mut elems = ~[]; - e.each(|elem| { - elems.push(elem); - true - }); - elems - } - /////////////////////////////////////////////////////////////////////////// // operators diff --git a/src/libextra/extra.rs b/src/libextra/extra.rs index e6134bb340cd8..58929778a59e2 100644 --- a/src/libextra/extra.rs +++ b/src/libextra/extra.rs @@ -91,6 +91,7 @@ pub mod par; pub mod base64; pub mod rl; pub mod workcache; +pub mod enum_set; #[path="num/bigint.rs"] pub mod bigint; #[path="num/rational.rs"] diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index ec50f564385c3..ffd79433b7693 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -413,15 +413,14 @@ fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) { } fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) { - do bs.builtin_bounds.each |bound| { + for bound in bs.builtin_bounds.iter() { match bound { ty::BoundSend => w.write_char('S'), ty::BoundFreeze => w.write_char('K'), ty::BoundStatic => w.write_char('O'), ty::BoundSized => w.write_char('Z'), } - true - }; + } for &tp in bs.trait_bounds.iter() { w.write_char('I'); diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 3bdf0c0f6dcb8..84eb371d7b34a 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -338,12 +338,11 @@ pub fn check_builtin_bounds(cx: Context, ty: ty::t, bounds: ty::BuiltinBounds, { let kind = ty::type_contents(cx.tcx, ty); let mut missing = ty::EmptyBuiltinBounds(); - do bounds.each |bound| { + for bound in bounds.iter() { if !kind.meets_bound(cx.tcx, bound) { missing.add(bound); } - true - }; + } if !missing.is_empty() { any_missing(missing); } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b15580034c2a8..d01d480959a10 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -25,7 +25,6 @@ use util::ppaux::{note_and_explain_region, bound_region_ptr_to_str}; use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str}; use util::ppaux::{Repr, UserString}; use util::common::{indenter}; -use util::enum_set::{EnumSet, CLike}; use std::cast; use std::cmp; @@ -48,6 +47,7 @@ use syntax::opt_vec::OptVec; use syntax::opt_vec; use syntax::abi::AbiSet; use syntax; +use extra::enum_set::{EnumSet, CLike}; pub static INITIAL_DISCRIMINANT_VALUE: uint = 0; @@ -2287,7 +2287,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { // This is like with typarams below, but less "pessimistic" and also // dependent on the trait store. let mut bt = TC_NONE; - do (AllBuiltinBounds() - bounds).each |bound| { + for bound in (AllBuiltinBounds() - bounds).iter() { bt = bt + match bound { BoundStatic if bounds.contains_elem(BoundSend) => TC_NONE, // Send bound implies static bound. @@ -2296,8 +2296,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { BoundFreeze => TC_MUTABLE, BoundSized => TC_NONE, // don't care if interior is sized }; - true - }; + } st + mt + bt } @@ -2308,7 +2307,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { let _i = indenter(); let mut tc = TC_ALL; - do type_param_def.bounds.builtin_bounds.each |bound| { + for bound in type_param_def.bounds.builtin_bounds.iter() { debug!("tc = %s, bound = %?", tc.to_str(), bound); tc = tc - match bound { BoundStatic => TypeContents::nonstatic(cx), @@ -2317,8 +2316,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { // The dynamic-size bit can be removed at pointer-level, etc. BoundSized => TypeContents::dynamically_sized(cx), }; - true - }; + } debug!("result = %s", tc.to_str()); return tc; diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index c48b30e814164..46414a7a5e23e 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -96,7 +96,6 @@ pub mod driver; pub mod util { pub mod common; pub mod ppaux; - pub mod enum_set; } pub mod lib { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index f396ed7f510a6..1bea3003c63d2 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -593,15 +593,14 @@ impl Repr for ty::RegionSubsts { impl Repr for ty::ParamBounds { fn repr(&self, tcx: ctxt) -> ~str { let mut res = ~[]; - do self.builtin_bounds.each |b| { + for b in self.builtin_bounds.iter() { res.push(match b { ty::BoundStatic => ~"'static", ty::BoundSend => ~"Send", ty::BoundFreeze => ~"Freeze", ty::BoundSized => ~"Sized", }); - true - }; + } for t in self.trait_bounds.iter() { res.push(t.repr(tcx)); } @@ -837,10 +836,9 @@ impl UserString for ty::BuiltinBounds { fn user_string(&self, tcx: ctxt) -> ~str { if self.is_empty() { ~"" } else { let mut result = ~[]; - do self.each |bb| { + for bb in self.iter() { result.push(bb.user_string(tcx)); - true - }; + } result.connect("+") } } From ab93bc4ed9587d07a58f7830d152dd412441d124 Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Tue, 6 Aug 2013 22:20:15 +0200 Subject: [PATCH 62/62] rebase --- src/llvm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm b/src/llvm index f67442eee27d3..2e9f0d21fe321 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit f67442eee27d3d075a65cf7f9a70f7ec6649ffd1 +Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6