From 7f99a02ddb3ff30388ae1dd5db06e332c215fea2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 7 Mar 2013 18:37:22 -0500 Subject: syntax: Remove uses of DVec --- src/libsyntax/codemap.rs | 9 ++++----- src/libsyntax/diagnostic.rs | 3 +-- src/libsyntax/ext/deriving.rs | 24 +++++++++--------------- src/libsyntax/ext/tt/macro_parser.rs | 18 +++++++++--------- src/libsyntax/print/pprust.rs | 7 +++---- src/libsyntax/util/interner.rs | 7 +++---- 6 files changed, 29 insertions(+), 39 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a525c0df5fa..3397ca91c96 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -24,7 +24,6 @@ source code snippets, etc. use core::prelude::*; use core::cmp; -use core::dvec::DVec; use core::str; use core::to_bytes; use core::uint; @@ -242,7 +241,7 @@ pub struct FileMap { /// Locations of lines beginnings in the source code lines: @mut ~[BytePos], /// Locations of multi-byte characters in the source code - multibyte_chars: DVec + multibyte_chars: @mut ~[MultiByteChar], } pub impl FileMap { @@ -282,13 +281,13 @@ pub impl FileMap { } pub struct CodeMap { - files: DVec<@FileMap> + files: @mut ~[@FileMap] } pub impl CodeMap { static pub fn new() -> CodeMap { CodeMap { - files: DVec() + files: @mut ~[], } } @@ -315,7 +314,7 @@ pub impl CodeMap { name: filename, substr: substr, src: src, start_pos: BytePos(start_pos), lines: @mut ~[], - multibyte_chars: DVec() + multibyte_chars: @mut ~[], }; self.files.push(filemap); diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index e9ea5deda3f..33e734fbd64 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -18,7 +18,6 @@ use core::io; use core::option; use core::str; use core::vec; -use core::dvec::DVec; use std::term; @@ -203,7 +202,7 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: &str) { io::stderr().write_str(fmt!(" %s\n", msg)); } -pub fn collect(messages: @DVec<~str>) +pub fn collect(messages: @mut ~[~str]) -> @fn(Option<(@codemap::CodeMap, span)>, &str, level) { let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) = |_o, msg: &str, _l| { messages.push(msg.to_str()); }; diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 8c12bbad360..a1514bc3eab 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -29,7 +29,6 @@ use parse::token::special_idents::clownshoes_extensions; use ast_util; use opt_vec; -use core::dvec; use core::uint; enum Junction { @@ -99,7 +98,7 @@ fn expand_deriving(cx: ext_ctxt, expand_deriving_struct_def: ExpandDerivingStructDefFn, expand_deriving_enum_def: ExpandDerivingEnumDefFn) -> ~[@item] { - let result = dvec::DVec(); + let mut result = ~[]; for in_items.each |item| { result.push(copy *item); match item.node { @@ -120,7 +119,7 @@ fn expand_deriving(cx: ext_ctxt, _ => () } } - dvec::unwrap(result) + result } fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item { @@ -202,14 +201,13 @@ fn create_self_type_with_params(cx: ext_ctxt, generics: &Generics) -> @Ty { // Create the type parameters on the `self` path. - let self_ty_params = dvec::DVec(); + let mut self_ty_params = ~[]; for generics.ty_params.each |ty_param| { let self_ty_param = build::mk_simple_ty_path(cx, span, ty_param.ident); self_ty_params.push(self_ty_param); } - let self_ty_params = dvec::unwrap(self_ty_params); // Create the type of `self`. let self_type = build::mk_raw_path_(span, @@ -433,7 +431,7 @@ fn create_subpatterns(cx: ext_ctxt, prefix: ~str, n: uint) -> ~[@pat] { - let subpats = dvec::DVec(); + let mut subpats = ~[]; for uint::range(0, n) |_i| { // Create the subidentifier. let index = subpats.len().to_str(); @@ -445,7 +443,7 @@ fn create_subpatterns(cx: ext_ctxt, let subpat = build::mk_pat(cx, span, subpat); subpats.push(subpat); } - return dvec::unwrap(subpats); + return subpats; } fn is_struct_tuple(struct_def: &struct_def) -> bool { @@ -809,7 +807,7 @@ fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt, let self_ident = cx.ident_of(~"self"); // Create the body of the method. - let statements = dvec::DVec(); + let mut statements = ~[]; for struct_def.fields.each |struct_field| { match struct_field.node.kind { named_field(ident, _, _) => { @@ -833,7 +831,6 @@ fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt, } // Create the method itself. - let statements = dvec::unwrap(statements); return create_iter_bytes_method(cx, span, statements); } @@ -942,9 +939,9 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, } // Create the arms of the self match in the method body. - let self_arms = dvec::DVec(); + let mut self_arms = ~[]; for enum_definition.variants.each |self_variant| { - let other_arms = dvec::DVec(); + let mut other_arms = ~[]; // Create the matching pattern. let matching_pat = create_enum_variant_pattern(cx, @@ -1026,7 +1023,6 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, // Create the self pattern body. let other_expr = build::mk_path(cx, span, ~[ other_ident ]); let other_expr = build::mk_unary(cx, span, deref, other_expr); - let other_arms = dvec::unwrap(other_arms); let other_match_expr = expr_match(other_expr, other_arms); let other_match_expr = build::mk_expr(cx, span, @@ -1047,7 +1043,6 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, // Create the method body. let self_expr = build::mk_path(cx, span, ~[ self_ident ]); let self_expr = build::mk_unary(cx, span, deref, self_expr); - let self_arms = dvec::unwrap(self_arms); let self_match_expr = expr_match(self_expr, self_arms); let self_match_expr = build::mk_expr(cx, span, self_match_expr); @@ -1148,7 +1143,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, } // Feed the discriminant to the byte iteration function. - let stmts = dvec::DVec(); + let mut stmts = ~[]; let discrim_stmt = call_substructure_iter_bytes_method(cx, span, discriminant); @@ -1167,7 +1162,6 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, } // Create the pattern body. - let stmts = dvec::unwrap(stmts); let match_body_block = build::mk_block_(cx, span, stmts); // Create the arm. diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index c66e726bbf7..88797a15206 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -19,8 +19,6 @@ use parse::parser::Parser; use parse::token::{Token, EOF, to_str, nonterminal}; use parse::token; -use core::dvec::DVec; -use core::dvec; use core::option::{Option, Some, None}; use core::str; use core::uint; @@ -115,7 +113,7 @@ pub struct MatcherPos { sep: Option, idx: uint, up: matcher_pos_up, // mutable for swapping only - matches: ~[DVec<@named_match>], + matches: ~[~[@named_match]], match_lo: uint, match_hi: uint, sp_lo: BytePos, } @@ -151,7 +149,7 @@ pub fn initial_matcher_pos(+ms: ~[matcher], +sep: Option, lo: BytePos) } } } - let matches = vec::from_fn(count_names(ms), |_i| dvec::DVec()); + let matches = vec::from_fn(count_names(ms), |_i| ~[]); ~MatcherPos { elts: ms, sep: sep, @@ -283,7 +281,7 @@ pub fn parse( // Only touch the binders we have actually bound for uint::range(ei.match_lo, ei.match_hi) |idx| { - let sub = ei.matches[idx].get(); + let sub = ei.matches[idx]; new_pos.matches[idx] .push(@matched_seq(sub, mk_sp(ei.sp_lo, @@ -331,7 +329,7 @@ pub fn parse( } let matches = vec::map(ei.matches, // fresh, same size: - |_m| DVec::<@named_match>()); + |_m| ~[]); let ei_t = ei; cur_eis.push(~MatcherPos { elts: copy *matchers, @@ -358,9 +356,11 @@ pub fn parse( /* error messages here could be improved with links to orig. rules */ if tok == EOF { if eof_eis.len() == 1u { - return success( - nameize(sess, ms, - eof_eis[0u].matches.map(|dv| dv.pop()))); + let mut v = ~[]; + for vec::each_mut(eof_eis[0u].matches) |dv| { + v.push(dv.pop()); + } + return success(nameize(sess, ms, v)); } else if eof_eis.len() > 1u { return error(sp, ~"Ambiguity: multiple successful parses"); } else { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4a8176abc6f..c68341c20fa 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -28,7 +28,6 @@ use print::pp; use print::pprust; use core::char; -use core::dvec::DVec; use core::io; use core::str; use core::u64; @@ -63,7 +62,7 @@ pub struct ps { comments: Option<~[comments::cmnt]>, literals: Option<~[comments::lit]>, cur_cmnt_and_lit: @mut CurrentCommentAndLiteral, - boxes: DVec, + boxes: @mut ~[pp::breaks], ann: pp_ann } @@ -88,7 +87,7 @@ pub fn rust_printer(writer: io::Writer, intr: @ident_interner) -> @ps { cur_cmnt: 0, cur_lit: 0 }, - boxes: DVec(), + boxes: @mut ~[], ann: no_ann() }; } @@ -123,7 +122,7 @@ pub fn print_crate(cm: @CodeMap, intr: @ident_interner, cur_cmnt: 0, cur_lit: 0 }, - boxes: DVec(), + boxes: @mut ~[], ann: ann }; print_crate_(s, crate); diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 2c852084aa7..7a5708049e9 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -13,12 +13,11 @@ // type, and vice versa. use core::prelude::*; -use core::dvec::DVec; use core::hashmap::linear::LinearMap; pub struct Interner { priv map: @mut LinearMap, - priv vect: DVec, + priv vect: @mut ~[T], } // when traits can extend traits, we should extend index to get [] @@ -26,7 +25,7 @@ pub impl Interner { static fn new() -> Interner { Interner { map: @mut LinearMap::new(), - vect: DVec(), + vect: @mut ~[], } } @@ -58,7 +57,7 @@ pub impl Interner { // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - pure fn get(&self, idx: uint) -> T { self.vect.get_elt(idx) } + pure fn get(&self, idx: uint) -> T { self.vect[idx] } fn len(&self) -> uint { self.vect.len() } } -- cgit 1.4.1-3-g733a5 From 62651df2b482af4dc98b0aec6c5f1ad112fab8ec Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 7 Mar 2013 23:44:38 -0500 Subject: Fix dvec-related fallout in tests --- src/libcore/io.rs | 8 +++--- src/libstd/flatpipes.rs | 15 +++++------- src/libstd/json.rs | 9 +++---- src/libsyntax/parse/mod.rs | 6 ++--- .../run-pass/call-closure-from-overloaded-op.rs | 2 +- src/test/run-pass/issue-2631-b.rs | 3 +-- src/test/run-pass/issue-5275 | Bin 16176 -> 0 bytes src/test/run-pass/issue-5275.rs | 27 --------------------- 8 files changed, 17 insertions(+), 53 deletions(-) delete mode 100755 src/test/run-pass/issue-5275 delete mode 100644 src/test/run-pass/issue-5275.rs (limited to 'src/libsyntax') diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 34fa4c972ea..4634eb8793d 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -1442,17 +1442,15 @@ mod tests { fn bytes_buffer_overwrite() { let wr = BytesWriter(); wr.write(~[0u8, 1u8, 2u8, 3u8]); - fail_unless!(wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8])); + fail_unless!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]); wr.seek(-2, SeekCur); wr.write(~[4u8, 5u8, 6u8, 7u8]); - fail_unless!(wr.bytes.borrow(|bytes| bytes == - ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8])); + fail_unless!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]); wr.seek(-2, SeekEnd); wr.write(~[8u8]); wr.seek(1, SeekSet); wr.write(~[9u8]); - fail_unless!(wr.bytes.borrow(|bytes| bytes == - ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8])); + fail_unless!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]); } #[test] diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index b117834238f..897cb4c2034 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -452,13 +452,10 @@ pub mod flatteners { pub fn serialize_value>(val: &T) -> ~[u8] { - let mut bytes_writer = BytesWriter(); - let writer = @bytes_writer as @Writer; - let ser = FromWriter::from_writer(writer); - val.encode(&ser); - let mut ret = ~[]; - ret <-> bytes_writer.bytes; - return ret; + do io::with_bytes_writer |writer| { + let ser = FromWriter::from_writer(writer); + val.encode(&ser); + } } pub trait FromReader { @@ -652,7 +649,7 @@ mod test { chan.send(10); - let bytes = chan.byte_chan.writer.bytes.get(); + let bytes = copy chan.byte_chan.writer.bytes; let reader = BufReader::new(bytes); let port = serial::reader_port(reader); @@ -698,7 +695,7 @@ mod test { chan.send(10); - let bytes = chan.byte_chan.writer.bytes.get(); + let bytes = copy chan.byte_chan.writer.bytes; let reader = BufReader::new(bytes); let port = pod::reader_port(reader); diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 6506d8e3c41..9208d415971 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -1311,8 +1311,7 @@ mod tests { } } } - check_equal(str::from_bytes(bw.bytes.data), - ~"[\"frog\",[\"Henry\",349]]"); + check_equal(str::from_bytes(bw.bytes), ~"[\"frog\",[\"Henry\",349]]"); } #[test] @@ -1327,8 +1326,7 @@ mod tests { } } } - check_equal(str::from_bytes(bw.bytes.data), - ~"\"jodhpurs\""); + check_equal(str::from_bytes(bw.bytes), ~"\"jodhpurs\""); } #[test] @@ -1340,8 +1338,7 @@ mod tests { do encoder.emit_enum_variant (~"None",37,1242) { } } - check_equal(str::from_bytes(bw.bytes.data), - ~"null"); + check_equal(str::from_bytes(bw.bytes), ~"null"); } #[test] diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 48d3fbe8889..a1fc7230dd1 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -303,9 +303,9 @@ mod test { use util::testing::*; #[test] fn to_json_str (val: Encodable) -> ~str { - let bw = @io::BytesWriter(); - val.encode(~std::json::Encoder(bw as io::Writer)); - str::from_bytes(bw.bytes.data) + do io::with_str_writer |writer| { + val.encode(~std::json::Encoder(writer)); + } } #[test] fn alltts () { diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs index cbfae48302b..39864059fcd 100644 --- a/src/test/run-pass/call-closure-from-overloaded-op.rs +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -11,7 +11,7 @@ fn foo() -> int { 22 } pub fn main() { - let x: ~[@fn() -> int] = ~[]; + let mut x: ~[@fn() -> int] = ~[]; x.push(foo); fail_unless!((x[0])() == 22); } diff --git a/src/test/run-pass/issue-2631-b.rs b/src/test/run-pass/issue-2631-b.rs index 66383253f7c..5f5e2f9fc30 100644 --- a/src/test/run-pass/issue-2631-b.rs +++ b/src/test/run-pass/issue-2631-b.rs @@ -15,12 +15,11 @@ extern mod req; extern mod std; use req::*; -use std::oldmap::*; use std::oldmap::HashMap; pub fn main() { let v = ~[@~"hi"]; let m: req::header_map = HashMap(); - m.insert(~"METHOD", @mut ~[v]); + m.insert(~"METHOD", @mut v); request::(m); } diff --git a/src/test/run-pass/issue-5275 b/src/test/run-pass/issue-5275 deleted file mode 100755 index ea8edf5156a..00000000000 Binary files a/src/test/run-pass/issue-5275 and /dev/null differ diff --git a/src/test/run-pass/issue-5275.rs b/src/test/run-pass/issue-5275.rs deleted file mode 100644 index a1b93d99f28..00000000000 --- a/src/test/run-pass/issue-5275.rs +++ /dev/null @@ -1,27 +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. - -fn foo(self: &A) -> int { - if true { - fail!() - } else { - *bar(self.bar) - } -} - -pub fn main() {} - -fn bar(_: &r/mut int) -> &r/int { - fail!() -} - -struct A { - bar: @mut int, -} -- cgit 1.4.1-3-g733a5