Skip to content

Commit 2833976

Browse files
committed
Rollup merge of rust-lang#22402 - nagisa:spring-cleanup-2, r=nikomatsakis
This commit mostly replaces some of the uses of os::args with env::args. This, for obvious reasons is based on top of rust-lang#22400. Do not r+ before that lands.
2 parents c0865df + 7d941fa commit 2833976

Some content is hidden

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

55 files changed

+239
-255
lines changed

src/libstd/env.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,20 @@ impl Iterator for Args {
488488
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
489489
}
490490

491+
impl ExactSizeIterator for Args {
492+
fn len(&self) -> usize { self.inner.len() }
493+
}
494+
491495
impl Iterator for ArgsOs {
492496
type Item = OsString;
493497
fn next(&mut self) -> Option<OsString> { self.inner.next() }
494498
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
495499
}
496500

501+
impl ExactSizeIterator for ArgsOs {
502+
fn len(&self) -> usize { self.inner.len() }
503+
}
504+
497505
/// Returns the page size of the current architecture in bytes.
498506
pub fn page_size() -> usize {
499507
os_imp::page_size()

src/libstd/sys/unix/os.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ impl Iterator for Args {
247247
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
248248
}
249249

250+
impl ExactSizeIterator for Args {
251+
fn len(&self) -> usize { self.iter.len() }
252+
}
253+
250254
/// Returns the command line arguments
251255
///
252256
/// Returns a list of the command line arguments.

src/libstd/sys/windows/os.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ impl Iterator for Args {
303303
fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
304304
}
305305

306+
impl ExactSizeIterator for Args {
307+
fn len(&self) -> usize { self.range.len() }
308+
}
309+
306310
impl Drop for Args {
307311
fn drop(&mut self) {
308312
unsafe { c::LocalFree(self.cur as *mut c_void); }

src/rustbook/build.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Implementation of the `build` subcommand, used to compile a book.
1212
1313
use std::os;
14+
use std::env;
1415
use std::old_io;
1516
use std::old_io::{fs, File, BufferedWriter, TempDir, IoResult};
1617

@@ -80,10 +81,10 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
8081
let out_path = tgt.join(item.path.dirname());
8182

8283
let src;
83-
if os::args().len() < 3 {
84+
if env::args().len() < 3 {
8485
src = os::getcwd().unwrap().clone();
8586
} else {
86-
src = Path::new(os::args()[2].clone());
87+
src = Path::new(env::args().nth(2).unwrap().clone());
8788
}
8889
// preprocess the markdown, rerouting markdown references to html references
8990
let markdown_data = try!(File::open(&src.join(&item.path)).read_to_string());
@@ -153,16 +154,16 @@ impl Subcommand for Build {
153154
let src;
154155
let tgt;
155156

156-
if os::args().len() < 3 {
157+
if env::args().len() < 3 {
157158
src = cwd.clone();
158159
} else {
159-
src = Path::new(os::args()[2].clone());
160+
src = Path::new(env::args().nth(2).unwrap().clone());
160161
}
161162

162-
if os::args().len() < 4 {
163+
if env::args().len() < 4 {
163164
tgt = cwd.join("_book");
164165
} else {
165-
tgt = Path::new(os::args()[3].clone());
166+
tgt = Path::new(env::args().nth(3).unwrap().clone());
166167
}
167168

168169
try!(fs::mkdir(&tgt, old_io::USER_DIR));

src/rustbook/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#![feature(core)]
1414
#![feature(io)]
1515
#![feature(os)]
16+
#![feature(env)]
1617
#![feature(path)]
1718
#![feature(rustdoc)]
1819

1920
extern crate rustdoc;
2021

21-
use std::os;
22+
use std::env;
2223
use subcommand::Subcommand;
2324
use term::Term;
2425

@@ -48,7 +49,7 @@ mod javascript;
4849
#[cfg(not(test))] // thanks #12327
4950
fn main() {
5051
let mut term = Term::new();
51-
let cmd = os::args();
52+
let cmd: Vec<_> = env::args().collect();
5253

5354
if cmd.len() <= 1 {
5455
help::usage()

src/rustbook/term.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! An abstraction of the terminal. Eventually, provide color and
1212
//! verbosity support. For now, just a wrapper around stdout/stderr.
1313
14-
use std::os;
14+
use std::env;
1515
use std::old_io::stdio;
1616

1717
pub struct Term {
@@ -28,6 +28,6 @@ impl Term {
2828
pub fn err(&mut self, msg: &str) {
2929
// swallow any errors
3030
let _ = self.err.write_line(msg);
31-
os::set_exit_status(101);
31+
env::set_exit_status(101);
3232
}
3333
}

src/test/bench/core-map.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![feature(unboxed_closures)]
1212

1313
use std::collections::{BTreeMap, HashMap, HashSet};
14-
use std::os;
14+
use std::env;
1515
use std::rand::{Rng, IsaacRng, SeedableRng};
1616
use std::time::Duration;
1717

@@ -20,33 +20,33 @@ fn timed<F>(label: &str, f: F) where F: FnMut() {
2020
}
2121

2222
trait MutableMap {
23-
fn insert(&mut self, k: uint, v: uint);
24-
fn remove(&mut self, k: &uint) -> bool;
25-
fn find(&self, k: &uint) -> Option<&uint>;
23+
fn insert(&mut self, k: usize, v: usize);
24+
fn remove(&mut self, k: &usize) -> bool;
25+
fn find(&self, k: &usize) -> Option<&usize>;
2626
}
2727

28-
impl MutableMap for BTreeMap<uint, uint> {
29-
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
30-
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
31-
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
28+
impl MutableMap for BTreeMap<usize, usize> {
29+
fn insert(&mut self, k: usize, v: usize) { self.insert(k, v); }
30+
fn remove(&mut self, k: &usize) -> bool { self.remove(k).is_some() }
31+
fn find(&self, k: &usize) -> Option<&usize> { self.get(k) }
3232
}
33-
impl MutableMap for HashMap<uint, uint> {
34-
fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); }
35-
fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() }
36-
fn find(&self, k: &uint) -> Option<&uint> { self.get(k) }
33+
impl MutableMap for HashMap<usize, usize> {
34+
fn insert(&mut self, k: usize, v: usize) { self.insert(k, v); }
35+
fn remove(&mut self, k: &usize) -> bool { self.remove(k).is_some() }
36+
fn find(&self, k: &usize) -> Option<&usize> { self.get(k) }
3737
}
3838

39-
fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
39+
fn ascending<M: MutableMap>(map: &mut M, n_keys: usize) {
4040
println!(" Ascending integers:");
4141

4242
timed("insert", || {
43-
for i in 0u..n_keys {
43+
for i in 0..n_keys {
4444
map.insert(i, i + 1);
4545
}
4646
});
4747

4848
timed("search", || {
49-
for i in 0u..n_keys {
49+
for i in 0..n_keys {
5050
assert_eq!(map.find(&i).unwrap(), &(i + 1));
5151
}
5252
});
@@ -58,7 +58,7 @@ fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) {
5858
});
5959
}
6060

61-
fn descending<M: MutableMap>(map: &mut M, n_keys: uint) {
61+
fn descending<M: MutableMap>(map: &mut M, n_keys: usize) {
6262
println!(" Descending integers:");
6363

6464
timed("insert", || {
@@ -80,32 +80,31 @@ fn descending<M: MutableMap>(map: &mut M, n_keys: uint) {
8080
});
8181
}
8282

83-
fn vector<M: MutableMap>(map: &mut M, n_keys: uint, dist: &[uint]) {
83+
fn vector<M: MutableMap>(map: &mut M, n_keys: usize, dist: &[usize]) {
8484
timed("insert", || {
85-
for i in 0u..n_keys {
85+
for i in 0..n_keys {
8686
map.insert(dist[i], i + 1);
8787
}
8888
});
8989

9090
timed("search", || {
91-
for i in 0u..n_keys {
91+
for i in 0..n_keys {
9292
assert_eq!(map.find(&dist[i]).unwrap(), &(i + 1));
9393
}
9494
});
9595

9696
timed("remove", || {
97-
for i in 0u..n_keys {
97+
for i in 0..n_keys {
9898
assert!(map.remove(&dist[i]));
9999
}
100100
});
101101
}
102102

103103
fn main() {
104-
let args = os::args();
105-
let args = args;
104+
let mut args = env::args();
106105
let n_keys = {
107106
if args.len() == 2 {
108-
args[1].parse::<uint>().unwrap()
107+
args.nth(1).unwrap().parse::<usize>().unwrap()
109108
} else {
110109
1000000
111110
}
@@ -131,37 +130,37 @@ fn main() {
131130
println!("{}", "\nBTreeMap:");
132131

133132
{
134-
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
133+
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
135134
ascending(&mut map, n_keys);
136135
}
137136

138137
{
139-
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
138+
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
140139
descending(&mut map, n_keys);
141140
}
142141

143142
{
144143
println!(" Random integers:");
145-
let mut map: BTreeMap<uint,uint> = BTreeMap::new();
144+
let mut map: BTreeMap<usize,usize> = BTreeMap::new();
146145
vector(&mut map, n_keys, &rand);
147146
}
148147

149148
// FIXME: #9970
150149
println!("{}", "\nHashMap:");
151150

152151
{
153-
let mut map: HashMap<uint,uint> = HashMap::new();
152+
let mut map: HashMap<usize,usize> = HashMap::new();
154153
ascending(&mut map, n_keys);
155154
}
156155

157156
{
158-
let mut map: HashMap<uint,uint> = HashMap::new();
157+
let mut map: HashMap<usize,usize> = HashMap::new();
159158
descending(&mut map, n_keys);
160159
}
161160

162161
{
163162
println!(" Random integers:");
164-
let mut map: HashMap<uint,uint> = HashMap::new();
163+
let mut map: HashMap<usize,usize> = HashMap::new();
165164
vector(&mut map, n_keys, &rand);
166165
}
167166
}

0 commit comments

Comments
 (0)