diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-02-28 12:54:01 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-03-01 22:40:52 -0800 |
| commit | 198cc3d850136582651489328fec221a2b98bfef (patch) | |
| tree | fe47f6fab3d4ead61053684613d0b1852ec7e311 /src/libsyntax/parse | |
| parent | 58fd6ab90db3eb68c94695e1254a73e57bc44658 (diff) | |
| download | rust-198cc3d850136582651489328fec221a2b98bfef.tar.gz rust-198cc3d850136582651489328fec221a2b98bfef.zip | |
libsyntax: Fix errors arising from the automated `~[T]` conversion
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 64 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 13 |
6 files changed, 63 insertions, 39 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 25bd051a69d..0a74c7ca821 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -15,6 +15,8 @@ use parse::token; use parse::parser::Parser; use parse::token::INTERPOLATED; +use std::vec_ng::Vec; + // a parser that can parse attributes. pub trait ParserAttr { fn parse_outer_attributes(&mut self) -> Vec<ast::Attribute> ; diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 1c45fe5ee2c..c2a2097de24 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -20,6 +20,7 @@ use parse::token; use std::io; use std::str; use std::uint; +use std::vec_ng::Vec; #[deriving(Clone, Eq)] pub enum CommentStyle { @@ -58,20 +59,20 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { let mut i = 0u; let mut j = lines.len(); // first line of all-stars should be omitted - if lines.len() > 0 && lines[0].chars().all(|c| c == '*') { + if lines.len() > 0 && lines.get(0).chars().all(|c| c == '*') { i += 1; } - while i < j && lines[i].trim().is_empty() { + while i < j && lines.get(i).trim().is_empty() { i += 1; } // like the first, a last line of all stars should be omitted - if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') { + if j > i && lines.get(j - 1).chars().skip(1).all(|c| c == '*') { j -= 1; } - while j > i && lines[j - 1].trim().is_empty() { + while j > i && lines.get(j - 1).trim().is_empty() { j -= 1; } - return lines.slice(i, j).to_owned(); + return lines.slice(i, j).iter().map(|x| (*x).clone()).collect(); } /// remove a "[ \t]*\*" block from each line, if possible diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 677881de684..884fc306f22 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -1005,6 +1005,7 @@ mod test { use parse::token; use parse::token::{str_to_ident}; use std::io::util; + use std::vec_ng::Vec; // represents a testing reader (incl. both reader and interner) struct Env { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 40c9f346007..9e5db1770bf 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -21,6 +21,7 @@ use parse::parser::Parser; use std::cell::RefCell; use std::io::File; use std::str; +use std::vec_ng::Vec; pub mod lexer; pub mod parser; @@ -288,6 +289,7 @@ mod test { use std::io; use std::io::MemWriter; use std::str; + use std::vec_ng::Vec; use codemap::{Span, BytePos, Spanned}; use opt_vec; use ast; @@ -362,27 +364,28 @@ mod test { // check the token-tree-ization of macros #[test] fn string_to_tts_macro () { let tts = string_to_tts(~"macro_rules! zip (($a)=>($a))"); - let tts: &[ast::TokenTree] = tts; + let tts: &[ast::TokenTree] = tts.as_slice(); match tts { [ast::TTTok(_,_), ast::TTTok(_,token::NOT), ast::TTTok(_,_), ast::TTDelim(delim_elts)] => { - let delim_elts: &[ast::TokenTree] = *delim_elts; + let delim_elts: &[ast::TokenTree] = delim_elts.as_slice(); match delim_elts { [ast::TTTok(_,token::LPAREN), ast::TTDelim(first_set), ast::TTTok(_,token::FAT_ARROW), ast::TTDelim(second_set), ast::TTTok(_,token::RPAREN)] => { - let first_set: &[ast::TokenTree] = *first_set; + let first_set: &[ast::TokenTree] = + first_set.as_slice(); match first_set { [ast::TTTok(_,token::LPAREN), ast::TTTok(_,token::DOLLAR), ast::TTTok(_,_), ast::TTTok(_,token::RPAREN)] => { let second_set: &[ast::TokenTree] = - *second_set; + second_set.as_slice(); match second_set { [ast::TTTok(_,token::LPAREN), ast::TTTok(_,token::DOLLAR), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ceafa10cbec..9b209aadf19 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -82,7 +82,8 @@ use std::cell::Cell; use collections::HashSet; use std::kinds::marker; use std::mem::replace; -use std::vec; +use std::vec_ng::Vec; +use std::vec_ng; #[allow(non_camel_case_types)] #[deriving(Eq)] @@ -270,7 +271,7 @@ fn maybe_append(lhs: Vec<Attribute> , rhs: Option<Vec<Attribute> >) -> Vec<Attribute> { match rhs { None => lhs, - Some(ref attrs) => vec_ng::append(lhs, (*attrs)) + Some(ref attrs) => vec_ng::append(lhs, attrs.as_slice()) } } @@ -406,8 +407,11 @@ impl Parser { } else if inedible.contains(&self.token) { // leave it in the input } else { - let expected = vec_ng::append(edible.to_owned(), inedible); - let expect = tokens_to_str(expected); + let expected = vec_ng::append(edible.iter() + .map(|x| (*x).clone()) + .collect(), + inedible); + let expect = tokens_to_str(expected.as_slice()); let actual = self.this_token_to_str(); self.fatal( if expected.len() != 1 { @@ -445,8 +449,12 @@ impl Parser { match e.node { ExprPath(..) => { // might be unit-struct construction; check for recoverableinput error. - let expected = vec_ng::append(edible.to_owned(), inedible); - self.check_for_erroneous_unit_struct_expecting(expected); + let expected = vec_ng::append(edible.iter() + .map(|x| (*x).clone()) + .collect(), + inedible); + self.check_for_erroneous_unit_struct_expecting( + expected.as_slice()); } _ => {} } @@ -464,8 +472,12 @@ impl Parser { debug!("commit_stmt {:?}", s); let _s = s; // unused, but future checks might want to inspect `s`. if self.last_token.as_ref().map_or(false, |t| is_ident_or_path(*t)) { - let expected = vec_ng::append(edible.to_owned(), inedible); - self.check_for_erroneous_unit_struct_expecting(expected); + let expected = vec_ng::append(edible.iter() + .map(|x| (*x).clone()) + .collect(), + inedible.as_slice()); + self.check_for_erroneous_unit_struct_expecting( + expected.as_slice()); } self.expect_one_of(edible, inedible) } @@ -1082,7 +1094,7 @@ impl Parser { debug!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = p.parse_inner_attrs_and_block(); - let attrs = vec_ng::append(attrs, inner_attrs); + let attrs = vec_ng::append(attrs, inner_attrs.as_slice()); Provided(@ast::Method { ident: ident, attrs: attrs, @@ -1189,7 +1201,7 @@ impl Parser { if ts.len() == 1 && !one_tuple { self.expect(&token::RPAREN); - return ts[0] + return *ts.get(0) } let t = TyTup(ts); @@ -1769,7 +1781,7 @@ impl Parser { self.commit_expr_expecting(*es.last().unwrap(), token::RPAREN); return if es.len() == 1 && !trailing_comma { - self.mk_expr(lo, hi, ExprParen(es[0])) + self.mk_expr(lo, hi, ExprParen(*es.get(0))) } else { self.mk_expr(lo, hi, ExprTup(es)) @@ -1859,7 +1871,9 @@ impl Parser { seq_sep_trailing_allowed(token::COMMA), |p| p.parse_expr() ); - ex = ExprVec(vec!(first_expr) + remaining_exprs, mutbl); + let mut exprs = vec!(first_expr); + exprs.push_all_move(remaining_exprs); + ex = ExprVec(exprs, mutbl); } else { // Vector with one element. self.expect(&token::RBRACKET); @@ -3327,7 +3341,7 @@ impl Parser { while self.token != token::RBRACE { // parsing items even when they're not allowed lets us give // better error messages and recover more gracefully. - attributes_box.push_all(self.parse_outer_attributes()); + attributes_box.push_all(self.parse_outer_attributes().as_slice()); match self.token { token::SEMI => { if !attributes_box.is_empty() { @@ -3850,7 +3864,7 @@ impl Parser { let (inner_attrs, body) = self.parse_inner_attrs_and_block(); let hi = body.span.hi; - let attrs = vec_ng::append(attrs, inner_attrs); + let attrs = vec_ng::append(attrs, inner_attrs.as_slice()); @ast::Method { ident: ident, attrs: attrs, @@ -4082,7 +4096,8 @@ impl Parser { while self.token != term { let mut attrs = self.parse_outer_attributes(); if first { - attrs = attrs_remaining + attrs; + attrs = vec_ng::append(attrs_remaining.clone(), + attrs.as_slice()); first = false; } debug!("parse_mod_items: parse_item_or_view_item(attrs={:?})", @@ -4164,7 +4179,7 @@ impl Parser { -> (ast::Item_, Vec<ast::Attribute> ) { let mut prefix = Path::new(self.sess.cm.span_to_filename(self.span)); prefix.pop(); - let mod_path = Path::new(".").join_many(self.mod_path_stack); + let mod_path = Path::new(".").join_many(self.mod_path_stack.as_slice()); let dir_path = prefix.join(&mod_path); let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { @@ -4194,7 +4209,7 @@ impl Parser { }; self.eval_src_mod_from_path(file_path, - outer_attrs.to_owned(), + outer_attrs.iter().map(|x| *x).collect(), id_sp) } @@ -4231,7 +4246,7 @@ impl Parser { &path, id_sp); let (inner, next) = p0.parse_inner_attrs_and_next(); - let mod_attrs = vec_ng::append(outer_attrs, inner); + let mod_attrs = vec_ng::append(outer_attrs, inner.as_slice()); let first_item_outer_attrs = next; let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); { @@ -4556,7 +4571,7 @@ impl Parser { match self.token { INTERPOLATED(token::NtItem(item)) => { self.bump(); - let new_attrs = vec_ng::append(attrs, item.attrs); + let new_attrs = vec_ng::append(attrs, item.attrs.as_slice()); return IoviItem(@Item { attrs: new_attrs, ..(*item).clone() @@ -4662,7 +4677,8 @@ impl Parser { } if self.eat_keyword(keywords::Mod) { // MODULE ITEM - let (ident, item_, extra_attrs) = self.parse_item_mod(attrs); + let (ident, item_, extra_attrs) = + self.parse_item_mod(attrs.as_slice()); let item = self.mk_item(lo, self.last_span.hi, ident, @@ -4946,7 +4962,7 @@ impl Parser { } _ => () } - let last = path[path.len() - 1u]; + let last = *path.get(path.len() - 1u); let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -4984,7 +5000,8 @@ impl Parser { macros_allowed: bool) -> ParsedItemsAndViewItems { let mut attrs = vec_ng::append(first_item_attrs, - self.parse_outer_attributes()); + self.parse_outer_attributes() + .as_slice()); // First, parse view items. let mut view_items : Vec<ast::ViewItem> = Vec::new(); let mut items = Vec::new(); @@ -5065,7 +5082,8 @@ impl Parser { macros_allowed: bool) -> ParsedItemsAndViewItems { let mut attrs = vec_ng::append(first_item_attrs, - self.parse_outer_attributes()); + self.parse_outer_attributes() + .as_slice()); let mut foreign_items = Vec::new(); loop { match self.parse_foreign_item(attrs, macros_allowed) { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index d7d8752b009..1499a1b4c19 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -21,6 +21,7 @@ use std::char; use std::fmt; use std::local_data; use std::path::BytesContainer; +use std::vec_ng::Vec; #[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] @@ -412,13 +413,11 @@ macro_rules! declare_special_idents_and_keywords {( // The indices here must correspond to the numbers in // special_idents, in Keyword to_ident(), and in static // constants below. - let init_vec = vec!( - $( $si_str, )* - $( $sk_str, )* - $( $rk_str, )* - ); - - interner::StrInterner::prefill(init_vec) + let mut init_vec = Vec::new(); + $(init_vec.push($si_str);)* + $(init_vec.push($sk_str);)* + $(init_vec.push($rk_str);)* + interner::StrInterner::prefill(init_vec.as_slice()) } }} |
