Skip to content

Commit 3b6e9d4

Browse files
pcwaltonpnkfelix
authored andcommitted
librustc: Automatically change uses of ~[T] to Vec<T> in rustc.
1 parent f690cc2 commit 3b6e9d4

Some content is hidden

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

98 files changed

+811
-817
lines changed

src/librustc/back/archive.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use metadata::filesearch;
1616
use lib::llvm::{ArchiveRef, llvm};
1717

1818
use std::cast;
19+
use std::vec_ng::Vec;
1920
use std::io::fs;
2021
use std::io;
2122
use std::libc;
@@ -41,7 +42,7 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
4142
paths: &[&Path]) -> ProcessOutput {
4243
let ar = get_ar_prog(sess);
4344

44-
let mut args = ~[args.to_owned()];
45+
let mut args = vec!(args.to_owned());
4546
let mut paths = paths.iter().map(|p| p.as_str().unwrap().to_owned());
4647
args.extend(&mut paths);
4748
debug!("{} {}", ar, args.connect(" "));
@@ -89,7 +90,7 @@ impl Archive {
8990
}
9091

9192
/// Read a file in the archive
92-
pub fn read(&self, file: &str) -> ~[u8] {
93+
pub fn read(&self, file: &str) -> Vec<u8> {
9394
// Apparently if "ar p" is used on windows, it generates a corrupt file
9495
// which has bad headers and LLVM will immediately choke on it
9596
if cfg!(windows) && cfg!(windows) { // FIXME(#10734) double-and
@@ -119,7 +120,7 @@ impl Archive {
119120
lto: bool) -> io::IoResult<()> {
120121
let object = format!("{}.o", name);
121122
let bytecode = format!("{}.bc", name);
122-
let mut ignore = ~[METADATA_FILENAME, bytecode.as_slice()];
123+
let mut ignore = vec!(METADATA_FILENAME, bytecode.as_slice());
123124
if lto {
124125
ignore.push(object.as_slice());
125126
}
@@ -143,7 +144,7 @@ impl Archive {
143144
}
144145

145146
/// Lists all files in an archive
146-
pub fn files(&self) -> ~[~str] {
147+
pub fn files(&self) -> Vec<~str> {
147148
let output = run_ar(self.sess, "t", None, [&self.dst]);
148149
let output = str::from_utf8(output.output).unwrap();
149150
// use lines_any because windows delimits output with `\r\n` instead of
@@ -168,7 +169,7 @@ impl Archive {
168169
// all SYMDEF files as these are just magical placeholders which get
169170
// re-created when we make a new archive anyway.
170171
let files = try!(fs::readdir(loc.path()));
171-
let mut inputs = ~[];
172+
let mut inputs = Vec::new();
172173
for file in files.iter() {
173174
let filename = file.filename_str().unwrap();
174175
if skip.iter().any(|s| *s == filename) { continue }
@@ -182,7 +183,7 @@ impl Archive {
182183
if inputs.len() == 0 { return Ok(()) }
183184

184185
// Finally, add all the renamed files to this archive
185-
let mut args = ~[&self.dst];
186+
let mut args = vec!(&self.dst);
186187
args.extend(&mut inputs.iter());
187188
run_ar(self.sess, "r", None, args.as_slice());
188189
Ok(())

src/librustc/back/arm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use syntax::abi;
1515

1616
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
1717
let cc_args = if target_triple.contains("thumb") {
18-
~[~"-mthumb"]
18+
vec!(~"-mthumb")
1919
} else {
20-
~[~"-marm"]
20+
vec!(~"-marm")
2121
};
2222
return target_strs::t {
2323
module_asm: ~"",

src/librustc/back/link.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ pub mod write {
363363
let vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
364364
sess.opts.optimize == session::Aggressive;
365365

366-
let mut llvm_c_strs = ~[];
367-
let mut llvm_args = ~[];
366+
let mut llvm_c_strs = Vec::new();
367+
let mut llvm_args = Vec::new();
368368
{
369369
let add = |arg: &str| {
370370
let s = arg.to_c_str();
@@ -781,8 +781,8 @@ fn remove(sess: Session, path: &Path) {
781781
pub fn link_binary(sess: Session,
782782
trans: &CrateTranslation,
783783
outputs: &OutputFilenames,
784-
id: &CrateId) -> ~[Path] {
785-
let mut out_filenames = ~[];
784+
id: &CrateId) -> Vec<Path> {
785+
let mut out_filenames = Vec::new();
786786
let crate_types = sess.crate_types.borrow();
787787
for &crate_type in crate_types.get().iter() {
788788
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
@@ -1071,15 +1071,15 @@ fn link_args(sess: Session,
10711071
dylib: bool,
10721072
tmpdir: &Path,
10731073
obj_filename: &Path,
1074-
out_filename: &Path) -> ~[~str] {
1074+
out_filename: &Path) -> Vec<~str> {
10751075

10761076
// The default library location, we need this to find the runtime.
10771077
// The location of crates will be determined as needed.
10781078
// FIXME (#9639): This needs to handle non-utf8 paths
10791079
let lib_path = sess.filesearch.get_target_lib_path();
10801080
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
10811081

1082-
let mut args = ~[stage];
1082+
let mut args = vec!(stage);
10831083

10841084
// FIXME (#9639): This needs to handle non-utf8 paths
10851085
args.push_all([
@@ -1230,7 +1230,7 @@ fn link_args(sess: Session,
12301230
// Also note that the native libraries linked here are only the ones located
12311231
// in the current crate. Upstream crates with native library dependencies
12321232
// may have their native library pulled in above.
1233-
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
1233+
fn add_local_native_libraries(args: &mut Vec<~str> , sess: Session) {
12341234
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
12351235
for path in addl_lib_search_paths.get().iter() {
12361236
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1263,7 +1263,7 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
12631263
// Rust crates are not considered at all when creating an rlib output. All
12641264
// dependencies will be linked when producing the final output (instead of
12651265
// the intermediate rlib version)
1266-
fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
1266+
fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
12671267
dylib: bool, tmpdir: &Path) {
12681268

12691269
// As a limitation of the current implementation, we require that everything
@@ -1347,7 +1347,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
13471347
// returning `None` if not all libraries could be found with that
13481348
// preference.
13491349
fn get_deps(cstore: &cstore::CStore, preference: cstore::LinkagePreference)
1350-
-> Option<~[(ast::CrateNum, Path)]>
1350+
-> Option<Vec<(ast::CrateNum, Path)> >
13511351
{
13521352
let crates = cstore.get_used_crates(preference);
13531353
if crates.iter().all(|&(_, ref p)| p.is_some()) {
@@ -1358,8 +1358,8 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
13581358
}
13591359

13601360
// Adds the static "rlib" versions of all crates to the command line.
1361-
fn add_static_crates(args: &mut ~[~str], sess: Session, tmpdir: &Path,
1362-
crates: ~[(ast::CrateNum, Path)]) {
1361+
fn add_static_crates(args: &mut Vec<~str> , sess: Session, tmpdir: &Path,
1362+
crates: Vec<(ast::CrateNum, Path)> ) {
13631363
for (cnum, cratepath) in crates.move_iter() {
13641364
// When performing LTO on an executable output, all of the
13651365
// bytecode from the upstream libraries has already been
@@ -1405,8 +1405,8 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
14051405
}
14061406

14071407
// Same thing as above, but for dynamic crates instead of static crates.
1408-
fn add_dynamic_crates(args: &mut ~[~str], sess: Session,
1409-
crates: ~[(ast::CrateNum, Path)]) {
1408+
fn add_dynamic_crates(args: &mut Vec<~str> , sess: Session,
1409+
crates: Vec<(ast::CrateNum, Path)> ) {
14101410
// If we're performing LTO, then it should have been previously required
14111411
// that all upstream rust dependencies were available in an rlib format.
14121412
assert!(!sess.lto());
@@ -1440,7 +1440,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
14401440
// generic function calls a native function, then the generic function must
14411441
// be instantiated in the target crate, meaning that the native symbol must
14421442
// also be resolved in the target crate.
1443-
fn add_upstream_native_libraries(args: &mut ~[~str], sess: Session) {
1443+
fn add_upstream_native_libraries(args: &mut Vec<~str> , sess: Session) {
14441444
let cstore = sess.cstore;
14451445
cstore.iter_crate_data(|cnum, _| {
14461446
let libs = csearch::get_native_libraries(cstore, cnum);

src/librustc/back/mips.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
6363

6464
target_triple: target_triple,
6565

66-
cc_args: ~[],
66+
cc_args: Vec::new(),
6767
};
6868
}

src/librustc/back/rpath.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ fn not_win32(os: abi::Os) -> bool {
2121
os != abi::OsWin32
2222
}
2323

24-
pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {
24+
pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> Vec<~str> {
2525
let os = sess.targ_cfg.os;
2626

2727
// No rpath on windows
2828
if os == abi::OsWin32 {
29-
return ~[];
29+
return Vec::new();
3030
}
3131

32-
let mut flags = ~[];
32+
let mut flags = Vec::new();
3333

3434
if sess.targ_cfg.os == abi::OsFreebsd {
3535
flags.push_all([~"-Wl,-rpath,/usr/local/lib/gcc46",
@@ -60,8 +60,8 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
6060
p
6161
}
6262

63-
pub fn rpaths_to_flags(rpaths: &[~str]) -> ~[~str] {
64-
let mut ret = ~[];
63+
pub fn rpaths_to_flags(rpaths: &[~str]) -> Vec<~str> {
64+
let mut ret = Vec::new();
6565
for rpath in rpaths.iter() {
6666
ret.push("-Wl,-rpath," + *rpath);
6767
}
@@ -72,7 +72,7 @@ fn get_rpaths(os: abi::Os,
7272
sysroot: &Path,
7373
output: &Path,
7474
libs: &[Path],
75-
target_triple: &str) -> ~[~str] {
75+
target_triple: &str) -> Vec<~str> {
7676
debug!("sysroot: {}", sysroot.display());
7777
debug!("output: {}", output.display());
7878
debug!("libs:");
@@ -91,7 +91,7 @@ fn get_rpaths(os: abi::Os,
9191
let abs_rpaths = get_absolute_rpaths(libs);
9292

9393
// And a final backup rpath to the global library location.
94-
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
94+
let fallback_rpaths = vec!(get_install_prefix_rpath(target_triple));
9595

9696
fn log_rpaths(desc: &str, rpaths: &[~str]) {
9797
debug!("{} rpaths:", desc);
@@ -115,7 +115,7 @@ fn get_rpaths(os: abi::Os,
115115

116116
fn get_rpaths_relative_to_output(os: abi::Os,
117117
output: &Path,
118-
libs: &[Path]) -> ~[~str] {
118+
libs: &[Path]) -> Vec<~str> {
119119
libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
120120
}
121121

@@ -145,7 +145,7 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
145145
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
146146
}
147147

148-
fn get_absolute_rpaths(libs: &[Path]) -> ~[~str] {
148+
fn get_absolute_rpaths(libs: &[Path]) -> Vec<~str> {
149149
libs.iter().map(|a| get_absolute_rpath(a)).collect()
150150
}
151151

@@ -167,9 +167,9 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
167167
path.as_str().expect("non-utf8 component in rpath").to_owned()
168168
}
169169

170-
pub fn minimize_rpaths(rpaths: &[~str]) -> ~[~str] {
170+
pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
171171
let mut set = HashSet::new();
172-
let mut minimized = ~[];
172+
let mut minimized = Vec::new();
173173
for rpath in rpaths.iter() {
174174
if set.insert(rpath.as_slice()) {
175175
minimized.push(rpath.clone());
@@ -190,7 +190,7 @@ mod test {
190190
#[test]
191191
fn test_rpaths_to_flags() {
192192
let flags = rpaths_to_flags([~"path1", ~"path2"]);
193-
assert_eq!(flags, ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
193+
assert_eq!(flags, vec!(~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"));
194194
}
195195
196196
#[test]

src/librustc/back/target_strs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ pub struct t {
1515
meta_sect_name: ~str,
1616
data_layout: ~str,
1717
target_triple: ~str,
18-
cc_args: ~[~str],
18+
cc_args: Vec<~str> ,
1919
}

src/librustc/back/x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
4646

4747
target_triple: target_triple,
4848

49-
cc_args: ~[~"-m32"],
49+
cc_args: vec!(~"-m32"),
5050
};
5151
}

src/librustc/back/x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
5454

5555
target_triple: target_triple,
5656

57-
cc_args: ~[~"-m64"],
57+
cc_args: vec!(~"-m64"),
5858
};
5959
}

src/librustc/driver/driver.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn build_configuration(sess: Session) -> ast::CrateConfig {
145145
}
146146

147147
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
148-
fn parse_cfgspecs(cfgspecs: ~[~str])
148+
fn parse_cfgspecs(cfgspecs: Vec<~str> )
149149
-> ast::CrateConfig {
150150
cfgspecs.move_iter().map(|s| {
151151
let sess = parse::new_parse_sess();
@@ -399,8 +399,8 @@ pub struct CrateTranslation {
399399
module: ModuleRef,
400400
metadata_module: ModuleRef,
401401
link: LinkMeta,
402-
metadata: ~[u8],
403-
reachable: ~[~str],
402+
metadata: Vec<u8> ,
403+
reachable: Vec<~str> ,
404404
}
405405

406406
/// Run the translation phase to LLVM, after which the AST and analysis can
@@ -489,7 +489,7 @@ fn write_out_deps(sess: Session,
489489
krate: &ast::Crate) -> io::IoResult<()> {
490490
let id = link::find_crate_id(krate.attrs.as_slice(), outputs);
491491

492-
let mut out_filenames = ~[];
492+
let mut out_filenames = Vec::new();
493493
for output_type in sess.opts.output_types.iter() {
494494
let file = outputs.path(*output_type);
495495
match *output_type {
@@ -524,7 +524,7 @@ fn write_out_deps(sess: Session,
524524

525525
// Build a list of files used to compile the output and
526526
// write Makefile-compatible dependency rules
527-
let files: ~[~str] = {
527+
let files: Vec<~str> = {
528528
let files = sess.codemap.files.borrow();
529529
files.get()
530530
.iter()
@@ -786,14 +786,14 @@ pub fn build_session_options(matches: &getopts::Matches)
786786

787787
let lint_levels = [lint::allow, lint::warn,
788788
lint::deny, lint::forbid];
789-
let mut lint_opts = ~[];
789+
let mut lint_opts = Vec::new();
790790
let lint_dict = lint::get_lint_dict();
791791
for level in lint_levels.iter() {
792792
let level_name = lint::level_to_str(*level);
793793

794794
let level_short = level_name.slice_chars(0, 1);
795795
let level_short = level_short.to_ascii().to_upper().into_str();
796-
let flags = vec::append(matches.opt_strs(level_short),
796+
let flags = vec_ng::append(matches.opt_strs(level_short),
797797
matches.opt_strs(level_name));
798798
for lint_name in flags.iter() {
799799
let lint_name = lint_name.replace("-", "_");
@@ -829,7 +829,7 @@ pub fn build_session_options(matches: &getopts::Matches)
829829
}
830830

831831
let mut output_types = if parse_only || no_trans {
832-
~[]
832+
Vec::new()
833833
} else {
834834
matches.opt_strs("emit").flat_map(|s| {
835835
s.split(',').map(|part| {
@@ -1005,7 +1005,7 @@ pub fn build_session_(sopts: @session::Options,
10051005
working_dir: os::getcwd(),
10061006
lints: RefCell::new(HashMap::new()),
10071007
node_id: Cell::new(1),
1008-
crate_types: @RefCell::new(~[]),
1008+
crate_types: @RefCell::new(Vec::new()),
10091009
features: front::feature_gate::Features::new()
10101010
}
10111011
}
@@ -1026,8 +1026,8 @@ pub fn parse_pretty(sess: Session, name: &str) -> PpMode {
10261026
}
10271027

10281028
// rustc command line options
1029-
pub fn optgroups() -> ~[getopts::OptGroup] {
1030-
~[
1029+
pub fn optgroups() -> Vec<getopts::OptGroup> {
1030+
vec!(
10311031
optflag("h", "help", "Display this message"),
10321032
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
10331033
optmulti("L", "", "Add a directory to the library search path", "PATH"),
@@ -1071,8 +1071,7 @@ pub fn optgroups() -> ~[getopts::OptGroup] {
10711071
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
10721072
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
10731073
optmulti("Z", "", "Set internal debugging options", "FLAG"),
1074-
optflag( "v", "version", "Print version info and exit"),
1075-
]
1074+
optflag( "v", "version", "Print version info and exit"))
10761075
}
10771076

10781077
pub struct OutputFilenames {

0 commit comments

Comments
 (0)