Skip to content

Commit 198cc3d

Browse files
committed
libsyntax: Fix errors arising from the automated ~[T] conversion
1 parent 58fd6ab commit 198cc3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+577
-306
lines changed

src/libstd/vec_ng.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use clone::Clone;
1616
use cmp::{Eq, Ordering, TotalEq, TotalOrd};
1717
use container::Container;
1818
use default::Default;
19+
use fmt;
1920
use iter::{DoubleEndedIterator, FromIterator, Iterator};
2021
use libc::{free, c_void};
2122
use mem::{size_of, move_val_init};
@@ -82,6 +83,26 @@ impl<T: Clone> Vec<T> {
8283
self.push((*element).clone())
8384
}
8485
}
86+
87+
88+
pub fn grow(&mut self, n: uint, initval: &T) {
89+
let new_len = self.len() + n;
90+
self.reserve(new_len);
91+
let mut i: uint = 0u;
92+
93+
while i < n {
94+
self.push((*initval).clone());
95+
i += 1u;
96+
}
97+
}
98+
99+
pub fn grow_set(&mut self, index: uint, initval: &T, val: T) {
100+
let l = self.len();
101+
if index >= l {
102+
self.grow(index - l + 1u, initval);
103+
}
104+
*self.get_mut(index) = val;
105+
}
85106
}
86107

87108
impl<T:Clone> Clone for Vec<T> {
@@ -388,6 +409,12 @@ impl<T> Default for Vec<T> {
388409
}
389410
}
390411

412+
impl<T:fmt::Show> fmt::Show for Vec<T> {
413+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
414+
self.as_slice().fmt(f)
415+
}
416+
}
417+
391418
pub struct MoveItems<T> {
392419
priv allocation: *mut c_void, // the block of memory allocated for the vector
393420
priv iter: Items<'static, T>

src/libsyntax/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn lookup(name: &str) -> Option<Abi> {
119119
}
120120

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

125125
impl Abi {

src/libsyntax/ast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cell::RefCell;
2323
use collections::HashMap;
2424
use std::option::Option;
2525
use std::rc::Rc;
26+
use std::vec_ng::Vec;
2627
use serialize::{Encodable, Decodable, Encoder, Decoder};
2728

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

1197+
use std::vec_ng::Vec;
1198+
11961199
fn is_freeze<T: Freeze>() {}
11971200

11981201
// Assert that the AST remains Freeze (#10693).

src/libsyntax/ast_map.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cell::RefCell;
2323
use std::iter;
2424
use std::vec;
2525
use std::fmt;
26+
use std::vec_ng::Vec;
2627

2728
#[deriving(Clone, Eq)]
2829
pub enum PathElem {
@@ -191,7 +192,11 @@ pub struct Map {
191192
impl Map {
192193
fn find_entry(&self, id: NodeId) -> Option<MapEntry> {
193194
let map = self.map.borrow();
194-
map.get().get(id as uint).map(|x| *x)
195+
if map.get().len() > id as uint {
196+
Some(*map.get().get(id as uint))
197+
} else {
198+
None
199+
}
195200
}
196201

197202
/// Retrieve the Node corresponding to `id`, failing if it cannot

src/libsyntax/ast_util.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cmp;
2323
use collections::HashMap;
2424
use std::u32;
2525
use std::local_data;
26+
use std::vec_ng::Vec;
2627

2728
pub fn path_name_i(idents: &[Ident]) -> ~str {
2829
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
@@ -795,7 +796,7 @@ pub fn resolve_internal(id : Ident,
795796
let resolved = {
796797
let result = {
797798
let table = table.table.borrow();
798-
table.get()[id.ctxt]
799+
*table.get().get(id.ctxt as uint)
799800
};
800801
match result {
801802
EmptyCtxt => id.name,
@@ -844,7 +845,7 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> Vec<Mrk>
844845
loop {
845846
let table_entry = {
846847
let table = table.table.borrow();
847-
table.get()[loopvar]
848+
*table.get().get(loopvar as uint)
848849
};
849850
match table_entry {
850851
EmptyCtxt => {
@@ -873,7 +874,7 @@ pub fn marksof(ctxt: SyntaxContext, stopname: Name, table: &SCTable) -> Vec<Mrk>
873874
pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk {
874875
let sctable = get_sctable();
875876
let table = sctable.table.borrow();
876-
match table.get()[ctxt] {
877+
match *table.get().get(ctxt as uint) {
877878
ast::Mark(mrk,_) => mrk,
878879
_ => fail!("can't retrieve outer mark when outside is not a mark")
879880
}
@@ -901,7 +902,7 @@ pub fn getLast(arr: &Vec<Mrk> ) -> Mrk {
901902
pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
902903
(a.span == b.span)
903904
&& (a.global == b.global)
904-
&& (segments_name_eq(a.segments, b.segments))
905+
&& (segments_name_eq(a.segments.as_slice(), b.segments.as_slice()))
905906
}
906907

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

942+
use std::vec_ng::Vec;
943+
941944
fn ident_to_segment(id : &Ident) -> PathSegment {
942945
PathSegment {identifier:id.clone(),
943946
lifetimes: opt_vec::Empty,
@@ -1000,7 +1003,7 @@ mod test {
10001003
let mut result = Vec::new();
10011004
loop {
10021005
let table = table.table.borrow();
1003-
match table.get()[sc] {
1006+
match *table.get().get(sc as uint) {
10041007
EmptyCtxt => {return result;},
10051008
Mark(mrk,tail) => {
10061009
result.push(M(mrk));
@@ -1024,9 +1027,9 @@ mod test {
10241027
assert_eq!(unfold_test_sc(test_sc.clone(),EMPTY_CTXT,&mut t),4);
10251028
{
10261029
let table = t.table.borrow();
1027-
assert!(table.get()[2] == Mark(9,0));
1028-
assert!(table.get()[3] == Rename(id(101,0),14,2));
1029-
assert!(table.get()[4] == Mark(3,3));
1030+
assert!(*table.get().get(2) == Mark(9,0));
1031+
assert!(*table.get().get(3) == Rename(id(101,0),14,2));
1032+
assert!(*table.get().get(4) == Mark(3,3));
10301033
}
10311034
assert_eq!(refold_test_sc(4,&t),test_sc);
10321035
}
@@ -1045,8 +1048,8 @@ mod test {
10451048
assert_eq!(unfold_marks(vec!(3,7),EMPTY_CTXT,&mut t),3);
10461049
{
10471050
let table = t.table.borrow();
1048-
assert!(table.get()[2] == Mark(7,0));
1049-
assert!(table.get()[3] == Mark(3,2));
1051+
assert!(*table.get().get(2) == Mark(7,0));
1052+
assert!(*table.get().get(3) == Mark(3,2));
10501053
}
10511054
}
10521055

src/libsyntax/attr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use parse::token;
2121
use crateid::CrateId;
2222

2323
use collections::HashSet;
24+
use std::vec_ng::Vec;
2425

2526
pub trait AttrMetaMethods {
2627
// This could be changed to `fn check_name(&self, name: InternedString) ->
@@ -226,7 +227,8 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> Vec<@MetaItem> {
226227
match m.node {
227228
MetaList(ref n, ref mis) => {
228229
@Spanned {
229-
node: MetaList((*n).clone(), sort_meta_items(*mis)),
230+
node: MetaList((*n).clone(),
231+
sort_meta_items(mis.as_slice())),
230232
.. /*bad*/ (*m).clone()
231233
}
232234
}
@@ -243,7 +245,7 @@ pub fn find_linkage_metas(attrs: &[Attribute]) -> Vec<@MetaItem> {
243245
let mut result = Vec::new();
244246
for attr in attrs.iter().filter(|at| at.name().equiv(&("link"))) {
245247
match attr.meta().node {
246-
MetaList(_, ref items) => result.push_all(*items),
248+
MetaList(_, ref items) => result.push_all(items.as_slice()),
247249
_ => ()
248250
}
249251
}
@@ -272,9 +274,9 @@ pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr {
272274
match attr.node.value.node {
273275
MetaWord(ref n) if n.equiv(&("inline")) => InlineHint,
274276
MetaList(ref n, ref items) if n.equiv(&("inline")) => {
275-
if contains_name(*items, "always") {
277+
if contains_name(items.as_slice(), "always") {
276278
InlineAlways
277-
} else if contains_name(*items, "never") {
279+
} else if contains_name(items.as_slice(), "never") {
278280
InlineNever
279281
} else {
280282
InlineHint

src/libsyntax/codemap.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ source code snippets, etc.
2323

2424
use std::cell::RefCell;
2525
use std::cmp;
26+
use std::vec_ng::Vec;
2627
use serialize::{Encodable, Decodable, Encoder, Decoder};
2728

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

231232
// get a line from the list of pre-computed line-beginnings
232233
pub fn get_line(&self, line: int) -> ~str {
233234
let mut lines = self.lines.borrow_mut();
234-
let begin: BytePos = lines.get()[line] - self.start_pos;
235+
let begin: BytePos = *lines.get().get(line as uint) - self.start_pos;
235236
let begin = begin.to_uint();
236237
let slice = self.src.slice_from(begin);
237238
match slice.find('\n') {
@@ -373,7 +374,7 @@ impl CodeMap {
373374
let mut b = len;
374375
while b - a > 1u {
375376
let m = (a + b) / 2u;
376-
if files[m].start_pos > pos {
377+
if files.get(m).start_pos > pos {
377378
b = m;
378379
} else {
379380
a = m;
@@ -383,7 +384,7 @@ impl CodeMap {
383384
// filemap, but are not the filemaps we want (because they are length 0, they cannot
384385
// contain what we are looking for). So, rewind until we find a useful filemap.
385386
loop {
386-
let lines = files[a].lines.borrow();
387+
let lines = files.get(a).lines.borrow();
387388
let lines = lines.get();
388389
if lines.len() > 0 {
389390
break;
@@ -405,13 +406,13 @@ impl CodeMap {
405406
let idx = self.lookup_filemap_idx(pos);
406407

407408
let files = self.files.borrow();
408-
let f = files.get()[idx];
409+
let f = *files.get().get(idx);
409410
let mut a = 0u;
410411
let mut lines = f.lines.borrow_mut();
411412
let mut b = lines.get().len();
412413
while b - a > 1u {
413414
let m = (a + b) / 2u;
414-
if lines.get()[m] > pos { b = m; } else { a = m; }
415+
if *lines.get().get(m) > pos { b = m; } else { a = m; }
415416
}
416417
return FileMapAndLine {fm: f, line: a};
417418
}
@@ -421,7 +422,7 @@ impl CodeMap {
421422
let line = a + 1u; // Line numbers start at 1
422423
let chpos = self.bytepos_to_file_charpos(pos);
423424
let lines = f.lines.borrow();
424-
let linebpos = lines.get()[a];
425+
let linebpos = *lines.get().get(a);
425426
let linechpos = self.bytepos_to_file_charpos(linebpos);
426427
debug!("codemap: byte pos {:?} is on the line at byte pos {:?}",
427428
pos, linebpos);
@@ -440,7 +441,7 @@ impl CodeMap {
440441
-> FileMapAndBytePos {
441442
let idx = self.lookup_filemap_idx(bpos);
442443
let files = self.files.borrow();
443-
let fm = files.get()[idx];
444+
let fm = *files.get().get(idx);
444445
let offset = bpos - fm.start_pos;
445446
return FileMapAndBytePos {fm: fm, pos: offset};
446447
}
@@ -450,7 +451,7 @@ impl CodeMap {
450451
debug!("codemap: converting {:?} to char pos", bpos);
451452
let idx = self.lookup_filemap_idx(bpos);
452453
let files = self.files.borrow();
453-
let map = files.get()[idx];
454+
let map = files.get().get(idx);
454455

455456
// The number of extra bytes due to multibyte chars in the FileMap
456457
let mut total_extra_bytes = 0;

src/libsyntax/crateid.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::fmt;
1919
/// to be `0.0`.
2020
2121
use std::from_str::FromStr;
22+
use std::vec_ng::Vec;
2223

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

5455
if path.starts_with("/") || path.ends_with("/") ||
5556
path.starts_with(".") || path.is_empty() {
5657
return None;
5758
}
5859

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

6263
let (name, version) = if pieces.len() == 1 {
6364
(inferred_name.to_owned(), None)
6465
} else {
65-
let hash_pieces: Vec<&str> = pieces[1].splitn(':', 1).collect();
66+
let hash_pieces: Vec<&str> = pieces.get(1)
67+
.splitn(':', 1)
68+
.collect();
6669
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
67-
("", hash_pieces[0])
70+
("", *hash_pieces.get(0))
6871
} else {
69-
(hash_pieces[0], hash_pieces[1])
72+
(*hash_pieces.get(0), *hash_pieces.get(1))
7073
};
7174

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

9194
Some(CrateId {
92-
path: path,
95+
path: path.clone(),
9396
name: name,
9497
version: version,
9598
})

src/libsyntax/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn highlight_lines(err: &mut EmitterWriter,
325325
if lines.lines.len() == 1u {
326326
let lo = cm.lookup_char_pos(sp.lo);
327327
let mut digits = 0u;
328-
let mut num = (lines.lines[0] + 1u) / 10u;
328+
let mut num = (*lines.lines.get(0) + 1u) / 10u;
329329

330330
// how many digits must be indent past?
331331
while num > 0u { num /= 10u; digits += 1u; }
@@ -337,7 +337,7 @@ fn highlight_lines(err: &mut EmitterWriter,
337337
// part of the 'filename:line ' part of the previous line.
338338
let skip = fm.name.len() + digits + 3u;
339339
for _ in range(0, skip) { s.push_char(' '); }
340-
let orig = fm.get_line(lines.lines[0] as int);
340+
let orig = fm.get_line(*lines.lines.get(0) as int);
341341
for pos in range(0u, left-skip) {
342342
let curChar = orig[pos] as char;
343343
// Whenever a tab occurs on the previous line, we insert one on

src/libsyntax/ext/asm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use parse;
2020
use parse::token::InternedString;
2121
use parse::token;
2222

23+
use std::vec_ng::Vec;
24+
2325
enum State {
2426
Asm,
2527
Outputs,
@@ -42,7 +44,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4244
-> base::MacResult {
4345
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
4446
cx.cfg(),
45-
tts.to_owned());
47+
tts.iter()
48+
.map(|x| (*x).clone())
49+
.collect());
4650

4751
let mut asm = InternedString::new("");
4852
let mut asm_str_style = None;

0 commit comments

Comments
 (0)