Skip to content

Commit

Permalink
libsyntax: Fix errors arising from the automated ~[T] conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Mar 2, 2014
1 parent 58fd6ab commit 198cc3d
Show file tree
Hide file tree
Showing 54 changed files with 577 additions and 306 deletions.
27 changes: 27 additions & 0 deletions src/libstd/vec_ng.rs
Expand Up @@ -16,6 +16,7 @@ use clone::Clone;
use cmp::{Eq, Ordering, TotalEq, TotalOrd};
use container::Container;
use default::Default;
use fmt;
use iter::{DoubleEndedIterator, FromIterator, Iterator};
use libc::{free, c_void};
use mem::{size_of, move_val_init};
Expand Down Expand Up @@ -82,6 +83,26 @@ impl<T: Clone> Vec<T> {
self.push((*element).clone())
}
}


pub fn grow(&mut self, n: uint, initval: &T) {
let new_len = self.len() + n;
self.reserve(new_len);
let mut i: uint = 0u;

while i < n {
self.push((*initval).clone());
i += 1u;
}
}

pub fn grow_set(&mut self, index: uint, initval: &T, val: T) {
let l = self.len();
if index >= l {
self.grow(index - l + 1u, initval);
}
*self.get_mut(index) = val;
}
}

impl<T:Clone> Clone for Vec<T> {
Expand Down Expand Up @@ -388,6 +409,12 @@ impl<T> Default for Vec<T> {
}
}

impl<T:fmt::Show> fmt::Show for Vec<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_slice().fmt(f)
}
}

pub struct MoveItems<T> {
priv allocation: *mut c_void, // the block of memory allocated for the vector
priv iter: Items<'static, T>
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/abi.rs
Expand Up @@ -119,7 +119,7 @@ pub fn lookup(name: &str) -> Option<Abi> {
}

pub fn all_names() -> Vec<&'static str> {
AbiDatas.map(|d| d.name)
AbiDatas.iter().map(|d| d.name).collect()
}

impl Abi {
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/ast.rs
Expand Up @@ -23,6 +23,7 @@ use std::cell::RefCell;
use collections::HashMap;
use std::option::Option;
use std::rc::Rc;
use std::vec_ng::Vec;
use serialize::{Encodable, Decodable, Encoder, Decoder};

/// A pointer abstraction. FIXME(eddyb) #10676 use Rc<T> in the future.
Expand Down Expand Up @@ -1193,6 +1194,8 @@ mod test {
use codemap::*;
use super::*;

use std::vec_ng::Vec;

fn is_freeze<T: Freeze>() {}

// Assert that the AST remains Freeze (#10693).
Expand Down
7 changes: 6 additions & 1 deletion src/libsyntax/ast_map.rs
Expand Up @@ -23,6 +23,7 @@ use std::cell::RefCell;
use std::iter;
use std::vec;
use std::fmt;
use std::vec_ng::Vec;

#[deriving(Clone, Eq)]
pub enum PathElem {
Expand Down Expand Up @@ -191,7 +192,11 @@ pub struct Map {
impl Map {
fn find_entry(&self, id: NodeId) -> Option<MapEntry> {
let map = self.map.borrow();
map.get().get(id as uint).map(|x| *x)
if map.get().len() > id as uint {
Some(*map.get().get(id as uint))
} else {
None
}
}

/// Retrieve the Node corresponding to `id`, failing if it cannot
Expand Down
23 changes: 13 additions & 10 deletions src/libsyntax/ast_util.rs
Expand Up @@ -23,6 +23,7 @@ use std::cmp;
use collections::HashMap;
use std::u32;
use std::local_data;
use std::vec_ng::Vec;

pub fn path_name_i(idents: &[Ident]) -> ~str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
Expand Down Expand Up @@ -795,7 +796,7 @@ pub fn resolve_internal(id : Ident,
let resolved = {
let result = {
let table = table.table.borrow();
table.get()[id.ctxt]
*table.get().get(id.ctxt as uint)
};
match result {
EmptyCtxt => id.name,
Expand Down Expand Up @@ -844,7 +845,7 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> Vec<Mrk>
loop {
let table_entry = {
let table = table.table.borrow();
table.get()[loopvar]
*table.get().get(loopvar as uint)
};
match table_entry {
EmptyCtxt => {
Expand Down Expand Up @@ -873,7 +874,7 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> Vec<Mrk>
pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk {
let sctable = get_sctable();
let table = sctable.table.borrow();
match table.get()[ctxt] {
match *table.get().get(ctxt as uint) {
ast::Mark(mrk,_) => mrk,
_ => fail!("can't retrieve outer mark when outside is not a mark")
}
Expand Down Expand Up @@ -901,7 +902,7 @@ pub fn getLast(arr: &Vec<Mrk> ) -> Mrk {
pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
(a.span == b.span)
&& (a.global == b.global)
&& (segments_name_eq(a.segments, b.segments))
&& (segments_name_eq(a.segments.as_slice(), b.segments.as_slice()))
}

// are two arrays of segments equal when compared unhygienically?
Expand Down Expand Up @@ -938,6 +939,8 @@ mod test {
use opt_vec;
use collections::HashMap;

use std::vec_ng::Vec;

fn ident_to_segment(id : &Ident) -> PathSegment {
PathSegment {identifier:id.clone(),
lifetimes: opt_vec::Empty,
Expand Down Expand Up @@ -1000,7 +1003,7 @@ mod test {
let mut result = Vec::new();
loop {
let table = table.table.borrow();
match table.get()[sc] {
match *table.get().get(sc as uint) {
EmptyCtxt => {return result;},
Mark(mrk,tail) => {
result.push(M(mrk));
Expand All @@ -1024,9 +1027,9 @@ mod test {
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),14,2));
assert!(table.get()[4] == Mark(3,3));
assert!(*table.get().get(2) == Mark(9,0));
assert!(*table.get().get(3) == Rename(id(101,0),14,2));
assert!(*table.get().get(4) == Mark(3,3));
}
assert_eq!(refold_test_sc(4,&t),test_sc);
}
Expand All @@ -1045,8 +1048,8 @@ mod test {
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.get().get(2) == Mark(7,0));
assert!(*table.get().get(3) == Mark(3,2));
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/libsyntax/attr.rs
Expand Up @@ -21,6 +21,7 @@ use parse::token;
use crateid::CrateId;

use collections::HashSet;
use std::vec_ng::Vec;

pub trait AttrMetaMethods {
// This could be changed to `fn check_name(&self, name: InternedString) ->
Expand Down Expand Up @@ -226,7 +227,8 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> Vec<@MetaItem> {
match m.node {
MetaList(ref n, ref mis) => {
@Spanned {
node: MetaList((*n).clone(), sort_meta_items(*mis)),
node: MetaList((*n).clone(),
sort_meta_items(mis.as_slice())),
.. /*bad*/ (*m).clone()
}
}
Expand All @@ -243,7 +245,7 @@ pub fn find_linkage_metas(attrs: &[Attribute]) -> Vec<@MetaItem> {
let mut result = Vec::new();
for attr in attrs.iter().filter(|at| at.name().equiv(&("link"))) {
match attr.meta().node {
MetaList(_, ref items) => result.push_all(*items),
MetaList(_, ref items) => result.push_all(items.as_slice()),
_ => ()
}
}
Expand Down Expand Up @@ -272,9 +274,9 @@ pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr {
match attr.node.value.node {
MetaWord(ref n) if n.equiv(&("inline")) => InlineHint,
MetaList(ref n, ref items) if n.equiv(&("inline")) => {
if contains_name(*items, "always") {
if contains_name(items.as_slice(), "always") {
InlineAlways
} else if contains_name(*items, "never") {
} else if contains_name(items.as_slice(), "never") {
InlineNever
} else {
InlineHint
Expand Down
19 changes: 10 additions & 9 deletions src/libsyntax/codemap.rs
Expand Up @@ -23,6 +23,7 @@ source code snippets, etc.

use std::cell::RefCell;
use std::cmp;
use std::vec_ng::Vec;
use serialize::{Encodable, Decodable, Encoder, Decoder};

pub trait Pos {
Expand Down Expand Up @@ -224,14 +225,14 @@ impl FileMap {
// the new charpos must be > the last one (or it's the first one).
let mut lines = self.lines.borrow_mut();;
let line_len = lines.get().len();
assert!(line_len == 0 || (lines.get()[line_len - 1] < pos))
assert!(line_len == 0 || (*lines.get().get(line_len - 1) < pos))
lines.get().push(pos);
}

// get a line from the list of pre-computed line-beginnings
pub fn get_line(&self, line: int) -> ~str {
let mut lines = self.lines.borrow_mut();
let begin: BytePos = lines.get()[line] - self.start_pos;
let begin: BytePos = *lines.get().get(line as uint) - self.start_pos;
let begin = begin.to_uint();
let slice = self.src.slice_from(begin);
match slice.find('\n') {
Expand Down Expand Up @@ -373,7 +374,7 @@ impl CodeMap {
let mut b = len;
while b - a > 1u {
let m = (a + b) / 2u;
if files[m].start_pos > pos {
if files.get(m).start_pos > pos {
b = m;
} else {
a = m;
Expand All @@ -383,7 +384,7 @@ impl CodeMap {
// 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[a].lines.borrow();
let lines = files.get(a).lines.borrow();
let lines = lines.get();
if lines.len() > 0 {
break;
Expand All @@ -405,13 +406,13 @@ impl CodeMap {
let idx = self.lookup_filemap_idx(pos);

let files = self.files.borrow();
let f = files.get()[idx];
let f = *files.get().get(idx);
let mut a = 0u;
let mut lines = f.lines.borrow_mut();
let mut b = lines.get().len();
while b - a > 1u {
let m = (a + b) / 2u;
if lines.get()[m] > pos { b = m; } else { a = m; }
if *lines.get().get(m) > pos { b = m; } else { a = m; }
}
return FileMapAndLine {fm: f, line: a};
}
Expand All @@ -421,7 +422,7 @@ impl CodeMap {
let line = a + 1u; // Line numbers start at 1
let chpos = self.bytepos_to_file_charpos(pos);
let lines = f.lines.borrow();
let linebpos = lines.get()[a];
let linebpos = *lines.get().get(a);
let linechpos = self.bytepos_to_file_charpos(linebpos);
debug!("codemap: byte pos {:?} is on the line at byte pos {:?}",
pos, linebpos);
Expand All @@ -440,7 +441,7 @@ impl CodeMap {
-> FileMapAndBytePos {
let idx = self.lookup_filemap_idx(bpos);
let files = self.files.borrow();
let fm = files.get()[idx];
let fm = *files.get().get(idx);
let offset = bpos - fm.start_pos;
return FileMapAndBytePos {fm: fm, pos: offset};
}
Expand All @@ -450,7 +451,7 @@ impl CodeMap {
debug!("codemap: converting {:?} to char pos", bpos);
let idx = self.lookup_filemap_idx(bpos);
let files = self.files.borrow();
let map = files.get()[idx];
let map = files.get().get(idx);

// The number of extra bytes due to multibyte chars in the FileMap
let mut total_extra_bytes = 0;
Expand Down
15 changes: 9 additions & 6 deletions src/libsyntax/crateid.rs
Expand Up @@ -19,6 +19,7 @@ use std::fmt;
/// to be `0.0`.

use std::from_str::FromStr;
use std::vec_ng::Vec;

#[deriving(Clone, Eq)]
pub struct CrateId {
Expand Down Expand Up @@ -49,24 +50,26 @@ impl fmt::Show for CrateId {
impl FromStr for CrateId {
fn from_str(s: &str) -> Option<CrateId> {
let pieces: Vec<&str> = s.splitn('#', 1).collect();
let path = pieces[0].to_owned();
let path = pieces.get(0).to_owned();

if path.starts_with("/") || path.ends_with("/") ||
path.starts_with(".") || path.is_empty() {
return None;
}

let path_pieces: Vec<&str> = path.rsplitn('/', 1).collect();
let inferred_name = path_pieces[0];
let inferred_name = *path_pieces.get(0);

let (name, version) = if pieces.len() == 1 {
(inferred_name.to_owned(), None)
} else {
let hash_pieces: Vec<&str> = pieces[1].splitn(':', 1).collect();
let hash_pieces: Vec<&str> = pieces.get(1)
.splitn(':', 1)
.collect();
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
("", hash_pieces[0])
("", *hash_pieces.get(0))
} else {
(hash_pieces[0], hash_pieces[1])
(*hash_pieces.get(0), *hash_pieces.get(1))
};

let name = if !hash_name.is_empty() {
Expand All @@ -89,7 +92,7 @@ impl FromStr for CrateId {
};

Some(CrateId {
path: path,
path: path.clone(),
name: name,
version: version,
})
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/diagnostic.rs
Expand Up @@ -325,7 +325,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[0] + 1u) / 10u;
let mut num = (*lines.lines.get(0) + 1u) / 10u;

// how many digits must be indent past?
while num > 0u { num /= 10u; digits += 1u; }
Expand All @@ -337,7 +337,7 @@ 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(' '); }
let orig = fm.get_line(lines.lines[0] as int);
let orig = fm.get_line(*lines.lines.get(0) as int);
for pos in range(0u, left-skip) {
let curChar = orig[pos] as char;
// Whenever a tab occurs on the previous line, we insert one on
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/ext/asm.rs
Expand Up @@ -20,6 +20,8 @@ use parse;
use parse::token::InternedString;
use parse::token;

use std::vec_ng::Vec;

enum State {
Asm,
Outputs,
Expand All @@ -42,7 +44,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
tts.to_owned());
tts.iter()
.map(|x| (*x).clone())
.collect());

let mut asm = InternedString::new("");
let mut asm_str_style = None;
Expand Down

0 comments on commit 198cc3d

Please sign in to comment.