diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-14 23:05:01 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-19 12:59:40 -0700 |
| commit | 9d5d97b55d6487ee23b805bc1acbaa0669b82116 (patch) | |
| tree | b72dcf7045e331e94ea0f8658d088ab42d917935 /src/libsyntax | |
| parent | fb169d5543c84e11038ba2d07b538ec88fb49ca6 (diff) | |
| download | rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.tar.gz rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.zip | |
Remove a large amount of deprecated functionality
Spring cleaning is here! In the Fall! This commit removes quite a large amount of deprecated functionality from the standard libraries. I tried to ensure that only old deprecated functionality was removed. This is removing lots and lots of deprecated features, so this is a breaking change. Please consult the deprecation messages of the deleted code to see how to migrate code forward if it still needs migration. [breaking-change]
Diffstat (limited to 'src/libsyntax')
31 files changed, 209 insertions, 411 deletions
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index fb5373cee00..60e4db405d7 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -699,8 +699,12 @@ struct NodeCollector<'ast> { impl<'ast> NodeCollector<'ast> { fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'ast>) { - self.map.grow_set(id as uint, &NotPresent, entry); debug!("ast_map: {} => {}", id, entry); + let len = self.map.len(); + if id as uint >= len { + self.map.grow(id as uint - len + 1, NotPresent); + } + *self.map.get_mut(id as uint) = entry; } fn insert(&mut self, id: NodeId, node: Node<'ast>) { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 726aceb5819..5626f0a8ad9 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -202,7 +202,7 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident { let mut pretty = pprust::ty_to_string(ty); match *trait_ref { Some(ref trait_ref) => { - pretty.push_char('.'); + pretty.push('.'); pretty.push_str(pprust::path_to_string(&trait_ref.path).as_slice()); } None => {} diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 5d96cc359c2..4df334a3f2c 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -283,9 +283,9 @@ impl FileMap { /// filemap.start_pos + newline_offset_relative_to_the_start_of_filemap. pub fn next_line(&self, pos: BytePos) { // the new charpos must be > the last one (or it's the first one). - let mut lines = self.lines.borrow_mut();; + let mut lines = self.lines.borrow_mut(); let line_len = lines.len(); - assert!(line_len == 0 || (*lines.get(line_len - 1) < pos)) + assert!(line_len == 0 || ((*lines)[line_len - 1] < pos)) lines.push(pos); } @@ -293,7 +293,7 @@ impl FileMap { /// pub fn get_line(&self, line: int) -> String { let lines = self.lines.borrow(); - let begin: BytePos = *lines.get(line as uint) - self.start_pos; + let begin: BytePos = (*lines)[line as uint] - self.start_pos; let begin = begin.to_uint(); let slice = self.src.as_slice().slice_from(begin); match slice.find('\n') { @@ -351,7 +351,7 @@ impl CodeMap { // overflowing into the next filemap in case the last byte of span is also the last // byte of filemap, which leads to incorrect results from CodeMap.span_to_*. if src.len() > 0 && !src.as_slice().ends_with("\n") { - src.push_char('\n'); + src.push('\n'); } let filemap = Rc::new(FileMap { @@ -446,7 +446,7 @@ impl CodeMap { pub fn lookup_byte_offset(&self, bpos: BytePos) -> FileMapAndBytePos { let idx = self.lookup_filemap_idx(bpos); - let fm = self.files.borrow().get(idx).clone(); + let fm = (*self.files.borrow())[idx].clone(); let offset = bpos - fm.start_pos; FileMapAndBytePos {fm: fm, pos: offset} } @@ -455,7 +455,7 @@ impl CodeMap { pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos { let idx = self.lookup_filemap_idx(bpos); let files = self.files.borrow(); - let map = files.get(idx); + let map = &(*files)[idx]; // The number of extra bytes due to multibyte chars in the FileMap let mut total_extra_bytes = 0; @@ -480,34 +480,37 @@ impl CodeMap { fn lookup_filemap_idx(&self, pos: BytePos) -> uint { let files = self.files.borrow(); - let files = files; + let files = &*files; let len = files.len(); let mut a = 0u; let mut b = len; while b - a > 1u { let m = (a + b) / 2u; - if files.get(m).start_pos > pos { + if files[m].start_pos > pos { b = m; } else { a = m; } } - // There can be filemaps with length 0. These have the same start_pos as the previous - // filemap, but are not the filemaps we want (because they are length 0, they cannot - // contain what we are looking for). So, rewind until we find a useful filemap. + // There can be filemaps with length 0. These have the same start_pos as + // the previous filemap, but are not the filemaps we want (because they + // are length 0, they cannot contain what we are looking for). So, + // rewind until we find a useful filemap. loop { - let lines = files.get(a).lines.borrow(); + let lines = files[a].lines.borrow(); let lines = lines; if lines.len() > 0 { break; } if a == 0 { - fail!("position {} does not resolve to a source location", pos.to_uint()); + fail!("position {} does not resolve to a source location", + pos.to_uint()); } a -= 1; } if a >= len { - fail!("position {} does not resolve to a source location", pos.to_uint()) + fail!("position {} does not resolve to a source location", + pos.to_uint()) } return a; @@ -517,14 +520,14 @@ impl CodeMap { let idx = self.lookup_filemap_idx(pos); let files = self.files.borrow(); - let f = files.get(idx).clone(); + let f = (*files)[idx].clone(); let mut a = 0u; { let lines = f.lines.borrow(); let mut b = lines.len(); while b - a > 1u { let m = (a + b) / 2u; - if *lines.get(m) > pos { b = m; } else { a = m; } + if (*lines)[m] > pos { b = m; } else { a = m; } } } FileMapAndLine {fm: f, line: a} @@ -534,7 +537,7 @@ impl CodeMap { let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos); let line = a + 1u; // Line numbers start at 1 let chpos = self.bytepos_to_file_charpos(pos); - let linebpos = *f.lines.borrow().get(a); + let linebpos = (*f.lines.borrow())[a]; let linechpos = self.bytepos_to_file_charpos(linebpos); debug!("byte pos {} is on the line at byte pos {}", pos, linebpos); @@ -704,7 +707,7 @@ mod test { assert_eq!(file_lines.file.name, "blork.rs".to_string()); assert_eq!(file_lines.lines.len(), 1); - assert_eq!(*file_lines.lines.get(0), 1u); + assert_eq!(file_lines.lines[0], 1u); } #[test] diff --git a/src/libsyntax/crateid.rs b/src/libsyntax/crateid.rs deleted file mode 100644 index 67605360a48..00000000000 --- a/src/libsyntax/crateid.rs +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright 2013-2014 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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::fmt; - -/// CrateIds identify crates and include the crate name and optionally a path -/// and version. In the full form, they look like relative URLs. Example: -/// `github.com/rust-lang/rust#std:1.0` would be a package ID with a path of -/// `github.com/rust-lang/rust` and a crate name of `std` with a version of -/// `1.0`. If no crate name is given after the hash, the name is inferred to -/// be the last component of the path. If no version is given, it is inferred -/// to be `0.0`. - -use std::from_str::FromStr; - -#[deriving(Clone, PartialEq)] -pub struct CrateId { - /// A path which represents the codes origin. By convention this is the - /// URL, without `http://` or `https://` prefix, to the crate's repository - pub path: String, - /// The name of the crate. - pub name: String, - /// The version of the crate. - pub version: Option<String>, -} - -impl fmt::Show for CrateId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{}", self.path)); - let version = match self.version { - None => "0.0", - Some(ref version) => version.as_slice(), - }; - if self.path == self.name || - self.path - .as_slice() - .ends_with(format!("/{}", self.name).as_slice()) { - write!(f, "#{}", version) - } else { - write!(f, "#{}:{}", self.name, version) - } - } -} - -impl FromStr for CrateId { - fn from_str(s: &str) -> Option<CrateId> { - let pieces: Vec<&str> = s.splitn(1, '#').collect(); - let path = pieces.get(0).to_string(); - - if path.as_slice().starts_with("/") || path.as_slice().ends_with("/") || - path.as_slice().starts_with(".") || path.is_empty() { - return None; - } - - let path_pieces: Vec<&str> = path.as_slice() - .rsplitn(1, '/') - .collect(); - let inferred_name = *path_pieces.get(0); - - let (name, version) = if pieces.len() == 1 { - (inferred_name.to_string(), None) - } else { - let hash_pieces: Vec<&str> = pieces.get(1) - .splitn(1, ':') - .collect(); - let (hash_name, hash_version) = if hash_pieces.len() == 1 { - ("", *hash_pieces.get(0)) - } else { - (*hash_pieces.get(0), *hash_pieces.get(1)) - }; - - let name = if !hash_name.is_empty() { - hash_name.to_string() - } else { - inferred_name.to_string() - }; - - let version = if !hash_version.is_empty() { - if hash_version == "0.0" { - None - } else { - Some(hash_version.to_string()) - } - } else { - None - }; - - (name, version) - }; - - Some(CrateId { - path: path.to_string(), - name: name, - version: version, - }) - } -} - -impl CrateId { - pub fn version_or_default<'a>(&'a self) -> &'a str { - match self.version { - None => "0.0", - Some(ref version) => version.as_slice(), - } - } - - pub fn short_name_with_version(&self) -> String { - format!("{}-{}", self.name, self.version_or_default()) - } - - pub fn matches(&self, other: &CrateId) -> bool { - // FIXME: why does this not match on `path`? - if self.name != other.name { return false } - match (&self.version, &other.version) { - (&Some(ref v1), &Some(ref v2)) => v1 == v2, - _ => true, - } - } -} - -#[test] -fn bare_name() { - let crateid: CrateId = from_str("foo").expect("valid crateid"); - assert_eq!(crateid.name, "foo".to_string()); - assert_eq!(crateid.version, None); - assert_eq!(crateid.path, "foo".to_string()); -} - -#[test] -fn bare_name_single_char() { - let crateid: CrateId = from_str("f").expect("valid crateid"); - assert_eq!(crateid.name, "f".to_string()); - assert_eq!(crateid.version, None); - assert_eq!(crateid.path, "f".to_string()); -} - -#[test] -fn empty_crateid() { - let crateid: Option<CrateId> = from_str(""); - assert!(crateid.is_none()); -} - -#[test] -fn simple_path() { - let crateid: CrateId = from_str("example.com/foo/bar").expect("valid crateid"); - assert_eq!(crateid.name, "bar".to_string()); - assert_eq!(crateid.version, None); - assert_eq!(crateid.path, "example.com/foo/bar".to_string()); -} - -#[test] -fn simple_version() { - let crateid: CrateId = from_str("foo#1.0").expect("valid crateid"); - assert_eq!(crateid.name, "foo".to_string()); - assert_eq!(crateid.version, Some("1.0".to_string())); - assert_eq!(crateid.path, "foo".to_string()); -} - -#[test] -fn absolute_path() { - let crateid: Option<CrateId> = from_str("/foo/bar"); - assert!(crateid.is_none()); -} - -#[test] -fn path_ends_with_slash() { - let crateid: Option<CrateId> = from_str("foo/bar/"); - assert!(crateid.is_none()); -} - -#[test] -fn path_and_version() { - let crateid: CrateId = from_str("example.com/foo/bar#1.0").expect("valid crateid"); - assert_eq!(crateid.name, "bar".to_string()); - assert_eq!(crateid.version, Some("1.0".to_string())); - assert_eq!(crateid.path, "example.com/foo/bar".to_string()); -} - -#[test] -fn single_chars() { - let crateid: CrateId = from_str("a/b#1").expect("valid crateid"); - assert_eq!(crateid.name, "b".to_string()); - assert_eq!(crateid.version, Some("1".to_string())); - assert_eq!(crateid.path, "a/b".to_string()); -} - -#[test] -fn missing_version() { - let crateid: CrateId = from_str("foo#").expect("valid crateid"); - assert_eq!(crateid.name, "foo".to_string()); - assert_eq!(crateid.version, None); - assert_eq!(crateid.path, "foo".to_string()); -} - -#[test] -fn path_and_name() { - let crateid: CrateId = from_str("foo/rust-bar#bar:1.0").expect("valid crateid"); - assert_eq!(crateid.name, "bar".to_string()); - assert_eq!(crateid.version, Some("1.0".to_string())); - assert_eq!(crateid.path, "foo/rust-bar".to_string()); -} - -#[test] -fn empty_name() { - let crateid: CrateId = from_str("foo/bar#:1.0").expect("valid crateid"); - assert_eq!(crateid.name, "bar".to_string()); - assert_eq!(crateid.version, Some("1.0".to_string())); - assert_eq!(crateid.path, "foo/bar".to_string()); -} diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 9782f301667..3da1b1f3175 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -446,7 +446,7 @@ fn highlight_lines(err: &mut EmitterWriter, if lines.lines.len() == 1u { let lo = cm.lookup_char_pos(sp.lo); let mut digits = 0u; - let mut num = (*lines.lines.get(0) + 1u) / 10u; + let mut num = (lines.lines[0] + 1u) / 10u; // how many digits must be indent past? while num > 0u { num /= 10u; digits += 1u; } @@ -458,9 +458,9 @@ fn highlight_lines(err: &mut EmitterWriter, // part of the 'filename:line ' part of the previous line. let skip = fm.name.len() + digits + 3u; for _ in range(0, skip) { - s.push_char(' '); + s.push(' '); } - let orig = fm.get_line(*lines.lines.get(0) as int); + let orig = fm.get_line(lines.lines[0] as int); for pos in range(0u, left-skip) { let cur_char = orig.as_bytes()[pos] as char; // Whenever a tab occurs on the previous line, we insert one on @@ -468,8 +468,8 @@ fn highlight_lines(err: &mut EmitterWriter, // That way the squiggly line will usually appear in the correct // position. match cur_char { - '\t' => s.push_char('\t'), - _ => s.push_char(' '), + '\t' => s.push('\t'), + _ => s.push(' '), }; } try!(write!(&mut err.dst, "{}", s)); @@ -479,7 +479,7 @@ fn highlight_lines(err: &mut EmitterWriter, // the ^ already takes up one space let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; for _ in range(0, num_squigglies) { - s.push_char('~'); + s.push('~'); } } try!(print_maybe_styled(err, @@ -523,10 +523,10 @@ fn custom_highlight_lines(w: &mut EmitterWriter, let skip = last_line_start.len() + hi.col.to_uint() - 1; let mut s = String::new(); for _ in range(0, skip) { - s.push_char(' '); + s.push(' '); } - s.push_char('^'); - s.push_char('\n'); + s.push('^'); + s.push('\n'); print_maybe_styled(w, s.as_slice(), term::attr::ForegroundColor(lvl.color())) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 63d45939c2a..5cc2fe03618 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -495,7 +495,7 @@ impl<'a> ExtCtxt<'a> { pub fn new_parser_from_tts(&self, tts: &[ast::TokenTree]) -> parser::Parser<'a> { - parse::tts_to_parser(self.parse_sess, Vec::from_slice(tts), self.cfg()) + parse::tts_to_parser(self.parse_sess, tts.to_vec(), self.cfg()) } pub fn codemap(&self) -> &'a CodeMap { &self.parse_sess.span_diagnostic.cm } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 98ac6fe6a6c..437efbf96f8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -618,7 +618,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, mut args: Vec<P<ast::Expr>> ) -> P<ast::Expr> { let id = Spanned { node: ident, span: span }; - args.unshift(expr); + args.insert(0, expr); self.expr(span, ast::ExprMethodCall(id, Vec::new(), args)) } fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> { diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index cd3e247a806..af7cd4157ec 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -35,7 +35,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, accumulator.push_str(s.get()); } ast::LitChar(c) => { - accumulator.push_char(c); + accumulator.push(c); } ast::LitInt(i, ast::UnsignedIntLit(_)) | ast::LitInt(i, ast::SignedIntLit(_, ast::Plus)) | diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 64607ffd5d4..9748b531345 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -80,7 +80,7 @@ fn cs_clone( } } - if all_fields.len() >= 1 && all_fields.get(0).name.is_none() { + if all_fields.len() >= 1 && all_fields[0].name.is_none() { // enum-like let subcalls = all_fields.iter().map(subcall).collect(); cx.expr_call_ident(trait_span, ctor_ident, subcalls) diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 10c045b811a..2310a4460e2 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -447,10 +447,12 @@ impl<'a> TraitDef<'a> { attr::mark_used(&attr); let opt_trait_ref = Some(trait_ref); let ident = ast_util::impl_pretty_name(&opt_trait_ref, &*self_type); + let mut a = vec![attr]; + a.extend(self.attributes.iter().map(|a| a.clone())); cx.item( self.span, ident, - (vec!(attr)).append(self.attributes.as_slice()), + a, ast::ItemImpl(trait_generics, opt_trait_ref, self_type, @@ -943,8 +945,8 @@ impl<'a> MethodDef<'a> { // of them (using `field_index` tracked above). // That is the heart of the transposition. let others = self_pats_idents.iter().map(|fields| { - let &(_, _opt_ident, ref other_getter_expr) = - fields.get(field_index); + let (_, _opt_ident, ref other_getter_expr) = + fields[field_index]; // All Self args have same variant, so // opt_idents are the same. (Assert diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 16ce264fe71..322a84eaa2b 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -80,7 +80,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, EnumMatching(_, _, ref fields) if fields.len() == 0 => {} Struct(ref fields) | EnumMatching(_, _, ref fields) => { - if fields.get(0).name.is_none() { + if fields[0].name.is_none() { // tuple struct/"normal" variant format_string.push_str("("); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c792d4b99ee..39b710e0d57 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -165,7 +165,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { let mut arms = Vec::with_capacity(else_if_arms.len() + 2); arms.push(pat_arm); - arms.push_all_move(else_if_arms); + arms.extend(else_if_arms.into_iter()); arms.push(else_arm); let match_expr = fld.cx.expr(span, ast::ExprMatch(expr, arms, ast::MatchIfLetDesugar)); @@ -257,7 +257,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, span: codemap::Span, // let compilation continue return None; } - let extname = pth.segments.get(0).identifier; + let extname = pth.segments[0].identifier; let extnamestr = token::get_ident(extname); match fld.cx.syntax_env.find(&extname.name) { None => { @@ -505,7 +505,7 @@ pub fn expand_item_mac(it: P<ast::Item>, fld: &mut MacroExpander) node: MacInvocTT(ref pth, ref tts, _), .. }) => { - (pth.segments.get(0).identifier, pth.span, (*tts).clone()) + (pth.segments[0].identifier, pth.span, (*tts).clone()) } _ => fld.cx.span_bug(it.span, "invalid item macro invocation") }; @@ -695,7 +695,8 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE rename_fld.fold_pat(expanded_pat) }; // add them to the existing pending renames: - fld.cx.syntax_env.info().pending_renames.push_all_move(new_pending_renames); + fld.cx.syntax_env.info().pending_renames + .extend(new_pending_renames.into_iter()); Local { id: id, ty: expanded_ty, @@ -744,7 +745,7 @@ fn expand_arm(arm: ast::Arm, fld: &mut MacroExpander) -> ast::Arm { } // all of the pats must have the same set of bindings, so use the // first one to extract them and generate new names: - let idents = pattern_bindings(&**expanded_pats.get(0)); + let idents = pattern_bindings(&*expanded_pats[0]); let new_renames = idents.into_iter().map(|id| (id, fresh_name(&id))).collect(); // apply the renaming, but only to the PatIdents: let mut rename_pats_fld = PatIdentRenamer{renames:&new_renames}; @@ -860,7 +861,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> { fld.cx.span_err(pth.span, "expected macro name without module separators"); return DummyResult::raw_pat(span); } - let extname = pth.segments.get(0).identifier; + let extname = pth.segments[0].identifier; let extnamestr = token::get_ident(extname); let marked_after = match fld.cx.syntax_env.find(&extname.name) { None => { @@ -1022,7 +1023,7 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as }; // expand again if necessary - let new_methods = new_methods.move_iter() + let new_methods = new_methods.into_iter() .flat_map(|m| fld.fold_method(m).into_iter()).collect(); fld.cx.bt_pop(); new_methods @@ -1610,8 +1611,8 @@ mod test { // must be one check clause for each binding: assert_eq!(bindings.len(),bound_connections.len()); for (binding_idx,shouldmatch) in bound_connections.iter().enumerate() { - let binding_name = mtwt::resolve(*bindings.get(binding_idx)); - let binding_marks = mtwt::marksof(bindings.get(binding_idx).ctxt, invalid_name); + let binding_name = mtwt::resolve(bindings[binding_idx]); + let binding_marks = mtwt::marksof(bindings[binding_idx].ctxt, invalid_name); // shouldmatch can't name varrefs that don't exist: assert!((shouldmatch.len() == 0) || (varrefs.len() > *shouldmatch.iter().max().unwrap())); @@ -1630,16 +1631,15 @@ mod test { let string = token::get_ident(final_varref_ident); println!("varref's first segment's string: \"{}\"", string.get()); println!("binding #{}: {}, resolves to {}", - binding_idx, *bindings.get(binding_idx), binding_name); + binding_idx, bindings[binding_idx], binding_name); mtwt::with_sctable(|x| mtwt::display_sctable(x)); }; if shouldmatch.contains(&idx) { // it should be a path of length 1, and it should // be free-identifier=? or bound-identifier=? to the given binding assert_eq!(varref.segments.len(),1); - let varref_name = mtwt::resolve(varref.segments.get(0).identifier); - let varref_marks = mtwt::marksof(varref.segments - .get(0) + let varref_name = mtwt::resolve(varref.segments[0].identifier); + let varref_marks = mtwt::marksof(varref.segments[0] .identifier .ctxt, invalid_name); @@ -1654,7 +1654,7 @@ mod test { assert_eq!(varref_marks,binding_marks.clone()); } } else { - let varref_name = mtwt::resolve(varref.segments.get(0).identifier); + let varref_name = mtwt::resolve(varref.segments[0].identifier); let fail = (varref.segments.len() == 1) && (varref_name == binding_name); // temp debugging: @@ -1696,19 +1696,19 @@ foo_module!() // the xx binding should bind all of the xx varrefs: for (idx,v) in varrefs.iter().filter(|p| { p.segments.len() == 1 - && "xx" == token::get_ident(p.segments.get(0).identifier).get() + && "xx" == token::get_ident(p.segments[0].identifier).get() }).enumerate() { - if mtwt::resolve(v.segments.get(0).identifier) != resolved_binding { + if mtwt::resolve(v.segments[0].identifier) != resolved_binding { println!("uh oh, xx binding didn't match xx varref:"); println!("this is xx varref \\# {}", idx); println!("binding: {}", cxbind); println!("resolves to: {}", resolved_binding); - println!("varref: {}", v.segments.get(0).identifier); + println!("varref: {}", v.segments[0].identifier); println!("resolves to: {}", - mtwt::resolve(v.segments.get(0).identifier)); + mtwt::resolve(v.segments[0].identifier)); mtwt::with_sctable(|x| mtwt::display_sctable(x)); } - assert_eq!(mtwt::resolve(v.segments.get(0).identifier), + assert_eq!(mtwt::resolve(v.segments[0].identifier), resolved_binding); }; } diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 07f0ca85f35..87cd61c9b22 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -241,13 +241,13 @@ impl<'a, 'b> Context<'a, 'b> { return; } { - let arg_type = match self.arg_types.get(arg) { - &None => None, - &Some(ref x) => Some(x) + let arg_type = match self.arg_types[arg] { + None => None, + Some(ref x) => Some(x) }; - self.verify_same(self.args.get(arg).span, &ty, arg_type); + self.verify_same(self.args[arg].span, &ty, arg_type); } - if self.arg_types.get(arg).is_none() { + if self.arg_types[arg].is_none() { *self.arg_types.get_mut(arg) = Some(ty); } } @@ -544,7 +544,7 @@ impl<'a, 'b> Context<'a, 'b> { // of each variable because we don't want to move out of the arguments // passed to this function. for (i, e) in self.args.into_iter().enumerate() { - let arg_ty = match self.arg_types.get(i).as_ref() { + let arg_ty = match self.arg_types[i].as_ref() { Some(ty) => ty, None => continue // error already generated }; @@ -568,7 +568,7 @@ impl<'a, 'b> Context<'a, 'b> { let lname = self.ecx.ident_of(format!("__arg{}", *name).as_slice()); pats.push(self.ecx.pat_ident(e.span, lname)); - *names.get_mut(*self.name_positions.get(name)) = + *names.get_mut(self.name_positions[*name]) = Some(Context::format_arg(self.ecx, e.span, arg_ty, self.ecx.expr_ident(e.span, lname))); heads.push(self.ecx.expr_addr_of(e.span, e)); @@ -787,7 +787,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, None => break } } - match parser.errors.shift() { + match parser.errors.remove(0) { Some(error) => { cx.ecx.span_err(cx.fmtsp, format!("invalid format string: {}", @@ -804,7 +804,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, // Make sure that all arguments were used and all arguments have types. for (i, ty) in cx.arg_types.iter().enumerate() { if ty.is_none() { - cx.ecx.span_err(cx.args.get(i).span, "argument never used"); + cx.ecx.span_err(cx.args[i].span, "argument never used"); } } for (name, e) in cx.names.iter() { diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 523299abce1..b4f8b9f8228 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -188,7 +188,7 @@ fn resolve_internal(id: Ident, } let resolved = { - let result = *table.table.borrow().get(id.ctxt as uint); + let result = (*table.table.borrow())[id.ctxt as uint]; match result { EmptyCtxt => id.name, // ignore marks here: @@ -232,7 +232,7 @@ fn marksof_internal(ctxt: SyntaxContext, let mut result = Vec::new(); let mut loopvar = ctxt; loop { - let table_entry = *table.table.borrow().get(loopvar as uint); + let table_entry = (*table.table.borrow())[loopvar as uint]; match table_entry { EmptyCtxt => { return result; @@ -259,7 +259,7 @@ fn marksof_internal(ctxt: SyntaxContext, /// FAILS when outside is not a mark. pub fn outer_mark(ctxt: SyntaxContext) -> Mrk { with_sctable(|sctable| { - match *sctable.table.borrow().get(ctxt as uint) { + match (*sctable.table.borrow())[ctxt as uint] { Mark(mrk, _) => mrk, _ => fail!("can't retrieve outer mark when outside is not a mark") } @@ -330,7 +330,7 @@ mod tests { let mut result = Vec::new(); loop { let table = table.table.borrow(); - match *table.get(sc as uint) { + match (*table)[sc as uint] { EmptyCtxt => {return result;}, Mark(mrk,tail) => { result.push(M(mrk)); @@ -355,9 +355,9 @@ mod tests { assert_eq!(unfold_test_sc(test_sc.clone(),EMPTY_CTXT,&mut t),4); { let table = t.table.borrow(); - assert!(*table.get(2) == Mark(9,0)); - assert!(*table.get(3) == Rename(id(101,0),Name(14),2)); - assert!(*table.get(4) == Mark(3,3)); + assert!((*table)[2] == Mark(9,0)); + assert!((*table)[3] == Rename(id(101,0),Name(14),2)); + assert!((*table)[4] == Mark(3,3)); } assert_eq!(refold_test_sc(4,&t),test_sc); } @@ -376,8 +376,8 @@ mod tests { assert_eq!(unfold_marks(vec!(3,7),EMPTY_CTXT,&mut t),3); { let table = t.table.borrow(); - assert!(*table.get(2) == Mark(7,0)); - assert!(*table.get(3) == Mark(3,2)); + assert!((*table)[2] == Mark(7,0)); + assert!((*table)[3] == Mark(3,2)); } } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index e8949c4aa4f..84775c12d64 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -657,18 +657,20 @@ fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> { ast::TTNonterminal(sp, ident) => { - // tt.push_all_move($ident.to_tokens(ext_cx)) + // tt.extend($ident.to_tokens(ext_cx).into_iter()) let e_to_toks = cx.expr_method_call(sp, cx.expr_ident(sp, ident), id_ext("to_tokens"), vec!(cx.expr_ident(sp, id_ext("ext_cx")))); + let e_to_toks = + cx.expr_method_call(sp, e_to_toks, id_ext("into_iter"), vec![]); let e_push = cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("tt")), - id_ext("push_all_move"), + id_ext("extend"), vec!(e_to_toks)); vec!(cx.stmt_expr(e_push)) @@ -680,7 +682,7 @@ fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Vec<P<ast::Stmt>> { let mut ss = Vec::new(); for tt in tts.iter() { - ss.push_all_move(mk_tt(cx, sp, tt)); + ss.extend(mk_tt(cx, sp, tt).into_iter()); } ss } @@ -742,7 +744,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let stmt_let_tt = cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp)); let mut vector = vec!(stmt_let_sp, stmt_let_tt); - vector.push_all_move(mk_tts(cx, sp, tts.as_slice())); + vector.extend(mk_tts(cx, sp, tts.as_slice()).into_iter()); let block = cx.expr_block( cx.block_all(sp, Vec::new(), diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 88376108fec..78fcd729aae 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -286,7 +286,7 @@ pub fn parse(sess: &ParseSess, // Only touch the binders we have actually bound for idx in range(ei.match_lo, ei.match_hi) { - let sub = (*ei.matches.get(idx)).clone(); + let sub = (ei.matches[idx]).clone(); new_pos.matches .get_mut(idx) .push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo, @@ -321,7 +321,7 @@ pub fn parse(sess: &ParseSess, eof_eis.push(ei); } } else { - match ei.elts.get(idx).node.clone() { + match ei.elts[idx].node.clone() { /* need to descend into sequence */ MatchSeq(ref matchers, ref sep, zero_ok, match_idx_lo, match_idx_hi) => { @@ -388,7 +388,7 @@ pub fn parse(sess: &ParseSess, if (bb_eis.len() > 0u && next_eis.len() > 0u) || bb_eis.len() > 1u { let nts = bb_eis.iter().map(|ei| { - match ei.elts.get(ei.idx).node { + match ei.elts[ei.idx].node { MatchNonterminal(bind, name, _) => { (format!("{} ('{}')", token::get_ident(name), @@ -413,7 +413,7 @@ pub fn parse(sess: &ParseSess, let mut rust_parser = Parser::new(sess, cfg.clone(), box rdr.clone()); let mut ei = bb_eis.pop().unwrap(); - match ei.elts.get(ei.idx).node { + match ei.elts[ei.idx].node { MatchNonterminal(_, name, idx) => { let name_string = token::get_ident(name); ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal( diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 7a7dbc54c9e..91db3a9d8df 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -255,12 +255,12 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, argument_gram); // Extract the arguments: - let lhses = match **argument_map.get(&lhs_nm) { + let lhses = match *argument_map[lhs_nm] { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(sp, "wrong-structured lhs") }; - let rhses = match **argument_map.get(&rhs_nm) { + let rhses = match *argument_map[rhs_nm] { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(sp, "wrong-structured rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 1b9f6f16542..35ec37d842a 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -79,7 +79,7 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc<NamedMatch>) -> Rc<Name // end of the line; duplicate henceforth ad.clone() } - MatchedSeq(ref ads, _) => ads.get(*idx).clone() + MatchedSeq(ref ads, _) => ads[*idx].clone() } }) } @@ -194,7 +194,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { let t = { let frame = r.stack.last().unwrap(); // FIXME(pcwalton): Bad copy. - (*frame.forest.get(frame.idx)).clone() + (*frame.forest)[frame.idx].clone() }; match t { TTDelim(tts) => { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 2eb3b398da8..5e29167bf1a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -22,9 +22,10 @@ use ast::*; use ast; use ast_util; use codemap::{respan, Span, Spanned}; +use owned_slice::OwnedSlice; use parse::token; use ptr::P; -use owned_slice::OwnedSlice; +use std::ptr; use util::small_vector::SmallVector; use std::rc::Rc; @@ -36,11 +37,10 @@ pub trait MoveMap<T> { impl<T> MoveMap<T> for Vec<T> { fn move_map(mut self, f: |T| -> T) -> Vec<T> { - use std::{mem, ptr}; for p in self.iter_mut() { unsafe { // FIXME(#5016) this shouldn't need to zero to be safe. - mem::move_val_init(p, f(ptr::read_and_zero(p))); + ptr::write(p, f(ptr::read_and_zero(p))); } } self @@ -935,7 +935,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { match *impl_item { MethodImplItem(ref x) => { for method in folder.fold_method((*x).clone()) - .move_iter() { + .into_iter() { new_impl_items.push(MethodImplItem(method)) } } @@ -963,7 +963,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { RequiredMethod(m) => { SmallVector::one(RequiredMethod( folder.fold_type_method(m))) - .move_iter() + .into_iter() } ProvidedMethod(method) => { // the awkward collect/iter idiom here is because @@ -971,15 +971,15 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { // trait bound, they're not actually the same type, so // the method arms don't unify. let methods: SmallVector<ast::TraitItem> = - folder.fold_method(method).move_iter() + folder.fold_method(method).into_iter() .map(|m| ProvidedMethod(m)).collect(); - methods.move_iter() + methods.into_iter() } TypeTraitItem(at) => { SmallVector::one(TypeTraitItem(P( folder.fold_associated_type( (*at).clone())))) - .move_iter() + .into_iter() } }; r diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 8c2652e5699..4881be8996a 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -26,7 +26,6 @@ #![allow(unknown_features)] #![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)] #![feature(quote, struct_variant, unsafe_destructor, import_shadowing)] -#![allow(deprecated)] extern crate arena; extern crate fmt_macros; @@ -61,7 +60,6 @@ pub mod ast_util; pub mod attr; pub mod codemap; pub mod config; -pub mod crateid; pub mod diagnostic; pub mod feature_gate; pub mod fold; diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 798a54c1062..e5c37e5041a 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -122,7 +122,7 @@ impl<T> Default for OwnedSlice<T> { impl<T: Clone> Clone for OwnedSlice<T> { fn clone(&self) -> OwnedSlice<T> { - OwnedSlice::from_vec(Vec::from_slice(self.as_slice())) + OwnedSlice::from_vec(self.as_slice().to_vec()) } } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index c53638ed07d..551d15048f1 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -64,21 +64,21 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut j = lines.len(); // first line of all-stars should be omitted if lines.len() > 0 && - lines.get(0).as_slice().chars().all(|c| c == '*') { + lines[0].as_slice().chars().all(|c| c == '*') { i += 1; } - while i < j && lines.get(i).as_slice().trim().is_empty() { + while i < j && lines[i].as_slice().trim().is_empty() { i += 1; } // like the first, a last line of all stars should be omitted - if j > i && lines.get(j - 1) + if j > i && lines[j - 1] .as_slice() .chars() .skip(1) .all(|c| c == '*') { j -= 1; } - while j > i && lines.get(j - 1).as_slice().trim().is_empty() { + while j > i && lines[j - 1].as_slice().trim().is_empty() { j -= 1; } return lines.slice(i, j).iter().map(|x| (*x).clone()).collect(); @@ -252,7 +252,7 @@ fn read_block_comment(rdr: &mut StringReader, // doc-comments are not really comments, they are attributes if (rdr.curr_is('*') && !rdr.nextch_is('*')) || rdr.curr_is('!') { while !(rdr.curr_is('*') && rdr.nextch_is('/')) && !rdr.is_eof() { - curr_line.push_char(rdr.curr.unwrap()); + curr_line.push(rdr.curr.unwrap()); rdr.bump(); } if !rdr.is_eof() { @@ -279,17 +279,17 @@ fn read_block_comment(rdr: &mut StringReader, curr_line = String::new(); rdr.bump(); } else { - curr_line.push_char(rdr.curr.unwrap()); + curr_line.push(rdr.curr.unwrap()); if rdr.curr_is('/') && rdr.nextch_is('*') { rdr.bump(); rdr.bump(); - curr_line.push_char('*'); + curr_line.push('*'); level += 1; } else { if rdr.curr_is('*') && rdr.nextch_is('/') { rdr.bump(); rdr.bump(); - curr_line.push_char('/'); + curr_line.push('/'); level -= 1; } else { rdr.bump(); } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 38c985af370..55d071b8d60 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -180,7 +180,7 @@ impl<'a> StringReader<'a> { fn fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) -> ! { let mut m = m.to_string(); m.push_str(": "); - char::escape_default(c, |c| m.push_char(c)); + char::escape_default(c, |c| m.push(c)); self.fatal_span_(from_pos, to_pos, m.as_slice()); } @@ -189,7 +189,7 @@ impl<'a> StringReader<'a> { fn err_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) { let mut m = m.to_string(); m.push_str(": "); - char::escape_default(c, |c| m.push_char(c)); + char::escape_default(c, |c| m.push(c)); self.err_span_(from_pos, to_pos, m.as_slice()); } @@ -1227,7 +1227,7 @@ impl<'a> StringReader<'a> { fn read_to_eol(&mut self) -> String { let mut val = String::new(); while !self.curr_is('\n') && !self.is_eof() { - val.push_char(self.curr.unwrap()); + val.push(self.curr.unwrap()); self.bump(); } if self.curr_is('\n') { self.bump(); } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c4a8775a012..f1baccfcd80 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -455,7 +455,7 @@ pub fn str_lit(lit: &str) -> String { for _ in range(0, n - 1) { // we don't need to move past the first \ chars.next(); } - res.push_char(c); + res.push(c); } }, '\r' => { @@ -467,9 +467,9 @@ pub fn str_lit(lit: &str) -> String { fail!("lexer accepted bare CR"); } chars.next(); - res.push_char('\n'); + res.push('\n'); } - c => res.push_char(c), + c => res.push(c), } }, None => break @@ -497,9 +497,9 @@ pub fn raw_str_lit(lit: &str) -> String { fail!("lexer accepted bare CR"); } chars.next(); - res.push_char('\n'); + res.push('\n'); } else { - res.push_char(c); + res.push(c); } }, None => break diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 17f52bc21c5..abab816bfeb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -281,12 +281,13 @@ macro_rules! maybe_whole ( ) -fn maybe_append(lhs: Vec<Attribute> , rhs: Option<Vec<Attribute> >) - -> Vec<Attribute> { +fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>) + -> Vec<Attribute> { match rhs { - None => lhs, - Some(ref attrs) => lhs.append(attrs.as_slice()) + Some(ref attrs) => lhs.extend(attrs.iter().map(|a| a.clone())), + None => {} } + lhs } @@ -452,7 +453,8 @@ impl<'a> Parser<'a> { } else if inedible.contains(&self.token) { // leave it in the input } else { - let expected = edible.iter().map(|x| (*x).clone()).collect::<Vec<_>>().append(inedible); + let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>(); + expected.push_all(inedible); let expect = tokens_to_string(expected.as_slice()); let actual = self.this_token_to_string(); self.fatal( @@ -496,8 +498,8 @@ impl<'a> Parser<'a> { match e.node { ExprPath(..) => { // might be unit-struct construction; check for recoverableinput error. - let expected = edible.iter().map(|x| (*x).clone()).collect::<Vec<_>>() - .append(inedible); + let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>(); + expected.push_all(inedible); self.check_for_erroneous_unit_struct_expecting( expected.as_slice()); } @@ -517,8 +519,8 @@ impl<'a> Parser<'a> { if self.last_token .as_ref() .map_or(false, |t| is_ident_or_path(&**t)) { - let expected = edible.iter().map(|x| (*x).clone()).collect::<Vec<_>>() - .append(inedible.as_slice()); + let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>(); + expected.push_all(inedible.as_slice()); self.check_for_erroneous_unit_struct_expecting( expected.as_slice()); } @@ -1335,7 +1337,8 @@ impl<'a> Parser<'a> { debug!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = p.parse_inner_attrs_and_block(); - let attrs = attrs.append(inner_attrs.as_slice()); + let mut attrs = attrs; + attrs.push_all(inner_attrs.as_slice()); ProvidedMethod(P(ast::Method { attrs: attrs, id: ast::DUMMY_NODE_ID, @@ -2119,7 +2122,7 @@ impl<'a> Parser<'a> { |p| p.parse_expr() ); let mut exprs = vec!(first_expr); - exprs.push_all_move(remaining_exprs); + exprs.extend(remaining_exprs.into_iter()); ex = ExprVec(exprs); } else { // Vector with one element. @@ -2337,7 +2340,7 @@ impl<'a> Parser<'a> { ); hi = self.last_span.hi; - es.unshift(e); + es.insert(0, e); let id = spanned(dot, hi, i); let nd = self.mk_method_call(id, tys, es); e = self.mk_expr(lo, hi, nd); @@ -2600,7 +2603,7 @@ impl<'a> Parser<'a> { self.parse_seq_to_before_end(&close_delim, seq_sep_none(), |p| p.parse_token_tree()); - result.push_all_move(trees); + result.extend(trees.into_iter()); // Parse the close delimiter. result.push(parse_any_tt_tok(self)); @@ -3380,12 +3383,10 @@ impl<'a> Parser<'a> { _ => { if !enum_path.global && enum_path.segments.len() == 1 && - enum_path.segments - .get(0) + enum_path.segments[0] .lifetimes .len() == 0 && - enum_path.segments - .get(0) + enum_path.segments[0] .types .len() == 0 { // it could still be either an enum @@ -3394,7 +3395,7 @@ impl<'a> Parser<'a> { pat = PatIdent(BindByValue(MutImmutable), codemap::Spanned{ span: enum_path.span, - node: enum_path.segments.get(0) + node: enum_path.segments[0] .identifier}, None); } else { @@ -4256,7 +4257,7 @@ impl<'a> Parser<'a> { sep, parse_arg_fn ); - fn_inputs.unshift(Arg::new_self(explicit_self_sp, mutbl_self, $self_id)); + fn_inputs.insert(0, Arg::new_self(explicit_self_sp, mutbl_self, $self_id)); fn_inputs } token::RPAREN => { @@ -4449,7 +4450,8 @@ impl<'a> Parser<'a> { self.parse_where_clause(&mut generics); let (inner_attrs, body) = self.parse_inner_attrs_and_block(); let body_span = body.span; - let new_attrs = attrs.append(inner_attrs.as_slice()); + let mut new_attrs = attrs; + new_attrs.push_all(inner_attrs.as_slice()); (ast::MethDecl(ident, generics, abi, @@ -4490,7 +4492,7 @@ impl<'a> Parser<'a> { let (inner_attrs, mut method_attrs) = self.parse_inner_attrs_and_next(); while !self.eat(&token::RBRACE) { - method_attrs.push_all_move(self.parse_outer_attributes()); + method_attrs.extend(self.parse_outer_attributes().into_iter()); let vis = self.parse_visibility(); if self.eat_keyword(keywords::Type) { impl_items.push(TypeImplItem(P(self.parse_typedef( @@ -4711,7 +4713,9 @@ impl<'a> Parser<'a> { while self.token != term { let mut attrs = self.parse_outer_attributes(); if first { - attrs = attrs_remaining.clone().append(attrs.as_slice()); + let mut tmp = attrs_remaining.clone(); + tmp.push_all(attrs.as_slice()); + attrs = tmp; first = false; } debug!("parse_mod_items: parse_item_or_view_item(attrs={})", @@ -4826,7 +4830,7 @@ impl<'a> Parser<'a> { "cannot declare a new module at this location"); let this_module = match self.mod_path_stack.last() { Some(name) => name.get().to_string(), - None => self.root_module_name.get_ref().clone(), + None => self.root_module_name.as_ref().unwrap().clone(), }; self.span_note(id_sp, format!("maybe move this module `{0}` \ @@ -5536,7 +5540,7 @@ impl<'a> Parser<'a> { } else { s.push_str("priv") } - s.push_char('`'); + s.push('`'); let last_span = self.last_span; self.span_fatal(last_span, s.as_slice()); } @@ -5677,7 +5681,7 @@ impl<'a> Parser<'a> { } _ => () } - let mut rename_to = *path.get(path.len() - 1u); + let mut rename_to = path[path.len() - 1u]; let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -5705,7 +5709,8 @@ impl<'a> Parser<'a> { mut extern_mod_allowed: bool, macros_allowed: bool) -> ParsedItemsAndViewItems { - let mut attrs = first_item_attrs.append(self.parse_outer_attributes().as_slice()); + let mut attrs = first_item_attrs; + attrs.push_all(self.parse_outer_attributes().as_slice()); // First, parse view items. let mut view_items : Vec<ast::ViewItem> = Vec::new(); let mut items = Vec::new(); @@ -5786,7 +5791,8 @@ impl<'a> Parser<'a> { fn parse_foreign_items(&mut self, first_item_attrs: Vec<Attribute> , macros_allowed: bool) -> ParsedItemsAndViewItems { - let mut attrs = first_item_attrs.append(self.parse_outer_attributes().as_slice()); + let mut attrs = first_item_attrs; + attrs.push_all(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/print/pp.rs b/src/libsyntax/print/pp.rs index f1fdc71b9c6..65efd4f0042 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -134,12 +134,12 @@ pub fn buf_str(toks: Vec<Token>, s.push_str(", "); } s.push_str(format!("{}={}", - szs.get(i), - tok_str(toks.get(i).clone())).as_slice()); + szs[i], + tok_str(toks[i].clone())).as_slice()); i += 1u; i %= n; } - s.push_char(']'); + s.push(']'); return s.into_string(); } @@ -299,7 +299,7 @@ pub struct Printer { impl Printer { pub fn last_token(&mut self) -> Token { - (*self.token.get(self.right)).clone() + self.token[self.right].clone() } // be very careful with this! pub fn replace_last_token(&mut self, t: Token) { @@ -311,8 +311,8 @@ impl Printer { Eof => { if !self.scan_stack_empty { self.check_stack(0); - let left = (*self.token.get(self.left)).clone(); - let left_size = *self.size.get(self.left); + let left = self.token[self.left].clone(); + let left_size = self.size[self.left]; try!(self.advance_left(left, left_size)); } self.indent(0); @@ -388,14 +388,14 @@ impl Printer { debug!("scan window is {}, longer than space on line ({})", self.right_total - self.left_total, self.space); if !self.scan_stack_empty { - if self.left == *self.scan_stack.get(self.bottom) { + if self.left == self.scan_stack[self.bottom] { debug!("setting {} to infinity and popping", self.left); let scanned = self.scan_pop_bottom(); *self.size.get_mut(scanned) = SIZE_INFINITY; } } - let left = (*self.token.get(self.left)).clone(); - let left_size = *self.size.get(self.left); + let left = self.token[self.left].clone(); + let left_size = self.size[self.left]; try!(self.advance_left(left, left_size)); if self.left != self.right { try!(self.check_stream()); @@ -416,7 +416,7 @@ impl Printer { } pub fn scan_pop(&mut self) -> uint { assert!((!self.scan_stack_empty)); - let x = *self.scan_stack.get(self.top); + let x = self.scan_stack[self.top]; if self.top == self.bottom { self.scan_stack_empty = true; } else { @@ -426,11 +426,11 @@ impl Printer { } pub fn scan_top(&mut self) -> uint { assert!((!self.scan_stack_empty)); - return *self.scan_stack.get(self.top); + return self.scan_stack[self.top]; } pub fn scan_pop_bottom(&mut self) -> uint { assert!((!self.scan_stack_empty)); - let x = *self.scan_stack.get(self.bottom); + let x = self.scan_stack[self.bottom]; if self.top == self.bottom { self.scan_stack_empty = true; } else { @@ -458,8 +458,8 @@ impl Printer { if self.left != self.right { self.left += 1u; self.left %= self.buf_len; - let left = (*self.token.get(self.left)).clone(); - let left_size = *self.size.get(self.left); + let left = self.token[self.left].clone(); + let left_size = self.size[self.left]; try!(self.advance_left(left, left_size)); } ret @@ -470,29 +470,28 @@ impl Printer { pub fn check_stack(&mut self, k: int) { if !self.scan_stack_empty { let x = self.scan_top(); - match self.token.get(x) { - &Begin(_) => { - if k > 0 { + match self.token[x] { + Begin(_) => { + if k > 0 { + let popped = self.scan_pop(); + *self.size.get_mut(popped) = self.size[x] + + self.right_total; + self.check_stack(k - 1); + } + } + End => { + // paper says + not =, but that makes no sense. let popped = self.scan_pop(); - *self.size.get_mut(popped) = *self.size.get(x) + - self.right_total; - self.check_stack(k - 1); + *self.size.get_mut(popped) = 1; + self.check_stack(k + 1); } - } - &End => { - // paper says + not =, but that makes no sense. - let popped = self.scan_pop(); - *self.size.get_mut(popped) = 1; - self.check_stack(k + 1); - } - _ => { - let popped = self.scan_pop(); - *self.size.get_mut(popped) = *self.size.get(x) + - self.right_total; - if k > 0 { - self.check_stack(k); + _ => { + let popped = self.scan_pop(); + *self.size.get_mut(popped) = self.size[x] + self.right_total; + if k > 0 { + self.check_stack(k); + } } - } } } } @@ -511,7 +510,7 @@ impl Printer { let print_stack = &mut self.print_stack; let n = print_stack.len(); if n != 0u { - *print_stack.get(n - 1u) + (*print_stack)[n - 1] } else { PrintStackElem { offset: 0, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d32828192e9..26cf79ff8f9 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -175,7 +175,7 @@ pub fn to_string(f: |&mut State| -> IoResult<()>) -> String { let obj: TraitObject = mem::transmute_copy(&s.s.out); let wr: Box<MemWriter> = mem::transmute(obj.data); let result = - String::from_utf8(Vec::from_slice(wr.get_ref().as_slice())).unwrap(); + String::from_utf8(wr.get_ref().as_slice().to_vec()).unwrap(); mem::forget(wr); result.to_string() } @@ -1466,7 +1466,7 @@ impl<'a> State<'a> { } ast::ExprMethodCall(ident, ref tys, ref args) => { let base_args = args.slice_from(1); - try!(self.print_expr(&**args.get(0))); + try!(self.print_expr(&*args[0])); try!(word(&mut self.s, ".")); try!(self.print_ident(ident.node)); if tys.len() > 0u { @@ -2144,7 +2144,7 @@ impl<'a> State<'a> { for &explicit_self in opt_explicit_self.iter() { let m = match explicit_self { &ast::SelfStatic => ast::MutImmutable, - _ => match decl.inputs.get(0).pat.node { + _ => match decl.inputs[0].pat.node { ast::PatIdent(ast::BindByValue(m), _, _) => m, _ => ast::MutImmutable } @@ -2319,7 +2319,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, ints.as_slice(), |s, &idx| { if idx < generics.lifetimes.len() { - let lifetime = generics.lifetimes.get(idx); + let lifetime = &generics.lifetimes[idx]; s.print_lifetime_def(lifetime) } else { let idx = idx - generics.lifetimes.len(); @@ -2663,14 +2663,14 @@ impl<'a> State<'a> { ast::LitStr(ref st, style) => self.print_string(st.get(), style), ast::LitByte(byte) => { let mut res = String::from_str("b'"); - (byte as char).escape_default(|c| res.push_char(c)); - res.push_char('\''); + (byte as char).escape_default(|c| res.push(c)); + res.push('\''); word(&mut self.s, res.as_slice()) } ast::LitChar(ch) => { let mut res = String::from_str("'"); - ch.escape_default(|c| res.push_char(c)); - res.push_char('\''); + ch.escape_default(|c| res.push(c)); + res.push('\''); word(&mut self.s, res.as_slice()) } ast::LitInt(i, t) => { @@ -2717,7 +2717,7 @@ impl<'a> State<'a> { match self.literals { Some(ref lits) => { while self.cur_cmnt_and_lit.cur_lit < lits.len() { - let ltrl = (*(*lits).get(self.cur_cmnt_and_lit.cur_lit)).clone(); + let ltrl = (*lits)[self.cur_cmnt_and_lit.cur_lit].clone(); if ltrl.pos > pos { return None; } self.cur_cmnt_and_lit.cur_lit += 1u; if ltrl.pos == pos { return Some(ltrl); } @@ -2749,7 +2749,7 @@ impl<'a> State<'a> { comments::Mixed => { assert_eq!(cmnt.lines.len(), 1u); try!(zerobreak(&mut self.s)); - try!(word(&mut self.s, cmnt.lines.get(0).as_slice())); + try!(word(&mut self.s, cmnt.lines[0].as_slice())); zerobreak(&mut self.s) } comments::Isolated => { @@ -2767,7 +2767,7 @@ impl<'a> State<'a> { comments::Trailing => { try!(word(&mut self.s, " ")); if cmnt.lines.len() == 1u { - try!(word(&mut self.s, cmnt.lines.get(0).as_slice())); + try!(word(&mut self.s, cmnt.lines[0].as_slice())); hardbreak(&mut self.s) } else { try!(self.ibox(0u)); @@ -2813,7 +2813,7 @@ impl<'a> State<'a> { match self.comments { Some(ref cmnts) => { if self.cur_cmnt_and_lit.cur_cmnt < cmnts.len() { - Some((*cmnts.get(self.cur_cmnt_and_lit.cur_cmnt)).clone()) + Some(cmnts[self.cur_cmnt_and_lit.cur_cmnt].clone()) } else { None } diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index bd560abf3bd..1b231ed861b 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -37,6 +37,7 @@ use std::fmt; use std::fmt::Show; use std::hash::Hash; +use std::ptr; use serialize::{Encodable, Decodable, Encoder, Decoder}; /// An owned smart pointer. @@ -61,11 +62,10 @@ impl<T: 'static> P<T> { /// Transform the inner value, consuming `self` and producing a new `P<T>`. pub fn map(mut self, f: |T| -> T) -> P<T> { - use std::{mem, ptr}; unsafe { let p = &mut *self.ptr; // FIXME(#5016) this shouldn't need to zero to be safe. - mem::move_val_init(p, f(ptr::read_and_zero(p))); + ptr::write(p, f(ptr::read_and_zero(p))); } self } diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 8a7e14643c1..0f86fb751da 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -100,7 +100,7 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> { // `extern crate` must be precede `use` items mem::swap(&mut vis, &mut krate.module.view_items); - krate.module.view_items.push_all_move(vis); + krate.module.view_items.extend(vis.into_iter()); // don't add #![no_std] here, that will block the prelude injection later. // Add it during the prelude injection instead. @@ -219,7 +219,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> { vis: ast::Inherited, span: DUMMY_SP, }); - view_items.push_all_move(uses); + view_items.extend(uses.into_iter()); fold::noop_fold_mod(ast::Mod { inner: inner, diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index c22bdde74a4..ed2455d0a30 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -67,7 +67,7 @@ impl<T: Eq + Hash + Clone + 'static> Interner<T> { pub fn get(&self, idx: Name) -> T { let vect = self.vect.borrow(); - (*(*vect).get(idx.uint())).clone() + (*vect)[idx.uint()].clone() } pub fn len(&self) -> uint { @@ -182,13 +182,13 @@ impl StrInterner { let new_idx = Name(self.len() as u32); // leave out of map to avoid colliding let mut vect = self.vect.borrow_mut(); - let existing = (*vect.get(idx.uint())).clone(); + let existing = (*vect)[idx.uint()].clone(); vect.push(existing); new_idx } pub fn get(&self, idx: Name) -> RcStr { - (*self.vect.borrow().get(idx.uint())).clone() + (*self.vect.borrow())[idx.uint()].clone() } pub fn len(&self) -> uint { diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index a3f081e7be4..60ba5f6615b 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -98,7 +98,7 @@ impl<T> SmallVector<T> { pub fn get<'a>(&'a self, idx: uint) -> &'a T { match self.repr { One(ref v) if idx == 0 => v, - Many(ref vs) => vs.get(idx), + Many(ref vs) => &vs[idx], _ => fail!("out of bounds access") } } |
