Skip to content

Commit 9e3d0b0

Browse files
nikomatsakisalexcrichton
authored andcommitted
librustc: Remove the fallback to int from typechecking.
This breaks a fair amount of code. The typical patterns are: * `for _ in range(0, 10)`: change to `for _ in range(0u, 10)`; * `println!("{}", 3)`: change to `println!("{}", 3i)`; * `[1, 2, 3].len()`: change to `[1i, 2, 3].len()`. RFC #30. Closes #6023. [breaking-change]
1 parent f7f95c8 commit 9e3d0b0

File tree

362 files changed

+2229
-2050
lines changed

Some content is hidden

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

362 files changed

+2229
-2050
lines changed

src/doc/guide-container.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ invalidation*. As long as an iterator is still in scope, the compiler will preve
135135
modification of the container through another handle.
136136

137137
~~~
138-
let mut xs = [1, 2, 3];
138+
let mut xs = [1i, 2, 3];
139139
{
140140
let _it = xs.iter();
141141
@@ -155,16 +155,16 @@ example, the `fold` method will accumulate the items yielded by an `Iterator`
155155
into a single value:
156156

157157
~~~
158-
let xs = [1, 9, 2, 3, 14, 12];
158+
let xs = [1i, 9, 2, 3, 14, 12];
159159
let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
160160
assert_eq!(result, -41);
161161
~~~
162162

163163
Most adaptors return an adaptor object implementing the `Iterator` trait itself:
164164

165165
~~~
166-
let xs = [1, 9, 2, 3, 14, 12];
167-
let ys = [5, 2, 1, 8];
166+
let xs = [1i, 9, 2, 3, 14, 12];
167+
let ys = [5i, 2, 1, 8];
168168
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
169169
assert_eq!(sum, 57);
170170
~~~
@@ -180,8 +180,8 @@ iterator adaptor named `fuse()` is provided. This returns an iterator that will
180180
never call its underlying iterator again once `None` has been returned:
181181

182182
~~~
183-
let xs = [1,2,3,4,5];
184-
let mut calls = 0;
183+
let xs = [1i,2,3,4,5];
184+
let mut calls = 0i;
185185
186186
{
187187
let it = xs.iter().scan((), |_, x| {
@@ -209,11 +209,11 @@ assert_eq!(calls, 3);
209209
The function `range` (or `range_inclusive`) allows to simply iterate through a given range:
210210

211211
~~~
212-
for i in range(0, 5) {
212+
for i in range(0i, 5) {
213213
print!("{} ", i) // prints "0 1 2 3 4"
214214
}
215215
216-
for i in std::iter::range_inclusive(0, 5) { // needs explicit import
216+
for i in std::iter::range_inclusive(0i, 5) { // needs explicit import
217217
print!("{} ", i) // prints "0 1 2 3 4 5"
218218
}
219219
~~~
@@ -238,7 +238,7 @@ For loops are *often* used with a temporary iterator object, as above. They can
238238
also advance the state of an iterator in a mutable location:
239239

240240
~~~
241-
let xs = [1, 2, 3, 4, 5];
241+
let xs = [1i, 2, 3, 4, 5];
242242
let ys = ["foo", "bar", "baz", "foobar"];
243243
244244
// create an iterator yielding tuples of elements from both vectors
@@ -265,7 +265,7 @@ assert!(it.next().is_none());
265265
Iterators offer generic conversion to containers with the `collect` adaptor:
266266

267267
~~~
268-
let xs = [0, 1, 1, 2, 3, 5, 8];
268+
let xs = [0i, 1, 1, 2, 3, 5, 8];
269269
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<Vec<int>>();
270270
assert_eq!(ys, vec![10, 6, 4, 2, 2, 0]);
271271
~~~
@@ -347,7 +347,7 @@ A `DoubleEndedIterator` can have its direction changed with the `rev` adaptor,
347347
returning another `DoubleEndedIterator` with `next` and `next_back` exchanged.
348348

349349
~~~
350-
let xs = [1, 2, 3, 4, 5, 6];
350+
let xs = [1i, 2, 3, 4, 5, 6];
351351
let mut it = xs.iter();
352352
println!("{}", it.next()); // prints `Some(1)`
353353
println!("{}", it.next()); // prints `Some(2)`
@@ -363,8 +363,8 @@ The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
363363
`DoubleEndedIterator` implementations if the underlying iterators are.
364364

365365
~~~
366-
let xs = [1, 2, 3, 4];
367-
let ys = [5, 6, 7, 8];
366+
let xs = [1i, 2, 3, 4];
367+
let ys = [5i, 6, 7, 8];
368368
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
369369
370370
println!("{}", it.next()); // prints `Some(2)`
@@ -380,9 +380,9 @@ mutable references. It can be used to reverse a container in-place. Note that
380380
the trailing underscore is a workaround for issue #5898 and will be removed.
381381

382382
~~~
383-
let mut ys = [1, 2, 3, 4, 5];
383+
let mut ys = [1i, 2, 3, 4, 5];
384384
ys.mut_iter().reverse_();
385-
assert!(ys == [5, 4, 3, 2, 1]);
385+
assert!(ys == [5i, 4, 3, 2, 1]);
386386
~~~
387387

388388
## Random-access iterators
@@ -395,8 +395,8 @@ The `chain` adaptor is an implementation of `RandomAccessIterator` if the
395395
underlying iterators are.
396396

397397
~~~
398-
let xs = [1, 2, 3, 4, 5];
399-
let ys = [7, 9, 11];
398+
let xs = [1i, 2, 3, 4, 5];
399+
let ys = [7i, 9, 11];
400400
let mut it = xs.iter().chain(ys.iter());
401401
println!("{}", it.idx(0)); // prints `Some(1)`
402402
println!("{}", it.idx(5)); // prints `Some(7)`

src/doc/guide-lifetimes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ This is equivalent to the previous definition.
577577
Named lifetime notation can also be used to control the flow of execution:
578578

579579
~~~
580-
'h: for i in range(0,10) {
580+
'h: for i in range(0u, 10) {
581581
'g: loop {
582582
if i % 2 == 0 { continue 'h; }
583583
if i == 9 { break 'h; }

src/doc/guide-pointers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ duration a 'lifetime'. Let's try a more complex example:
315315

316316
~~~rust
317317
fn main() {
318-
let mut x = box 5;
318+
let mut x = box 5i;
319319
if *x < 10 {
320320
let y = &x;
321321
println!("Oh no: {}", y);
@@ -332,7 +332,7 @@ mutated, and therefore, lets us pass. This wouldn't work:
332332

333333
~~~rust{.ignore}
334334
fn main() {
335-
let mut x = box 5;
335+
let mut x = box 5i;
336336
if *x < 10 {
337337
let y = &x;
338338
*x -= 1;

src/doc/guide-testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ use test::Bencher;
269269
#[bench]
270270
fn bench_xor_1000_ints(b: &mut Bencher) {
271271
b.iter(|| {
272-
range(0, 1000).fold(0, |old, new| old ^ new);
272+
range(0u, 1000).fold(0, |old, new| old ^ new);
273273
});
274274
}
275275
~~~
@@ -293,7 +293,7 @@ example above by adjusting the `bh.iter` call to
293293
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
294294
b.iter(|| {
295295
// note lack of `;` (could also use an explicit `return`).
296-
range(0, 1000).fold(0, |old, new| old ^ new)
296+
range(0u, 1000).fold(0, |old, new| old ^ new)
297297
});
298298
~~~
299299

@@ -307,7 +307,7 @@ extern crate test;
307307
# fn main() {
308308
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
309309
b.iter(|| {
310-
test::black_box(range(0, 1000).fold(0, |old, new| old ^ new));
310+
test::black_box(range(0u, 1000).fold(0, |old, new| old ^ new));
311311
});
312312
# }
313313
~~~

src/doc/intro.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Typically, tasks do not share memory but instead communicate amongst each other
198198

199199
```
200200
fn main() {
201-
let numbers = vec![1,2,3];
201+
let numbers = vec![1i, 2i, 3i];
202202
203203
let (tx, rx) = channel();
204204
tx.send(numbers);
@@ -237,7 +237,7 @@ try to modify the previous example to continue using the variable `numbers`:
237237

238238
```ignore
239239
fn main() {
240-
let numbers = vec![1,2,3];
240+
let numbers = vec![1i, 2i, 3i];
241241
242242
let (tx, rx) = channel();
243243
tx.send(numbers);
@@ -267,9 +267,9 @@ Let's see an example that uses the `clone` method to create copies of the data:
267267

268268
```
269269
fn main() {
270-
let numbers = vec![1,2,3];
270+
let numbers = vec![1i, 2i, 3i];
271271
272-
for num in range(0, 3) {
272+
for num in range(0u, 3) {
273273
let (tx, rx) = channel();
274274
// Use `clone` to send a *copy* of the array
275275
tx.send(numbers.clone());
@@ -300,10 +300,10 @@ Here's some code:
300300
use std::sync::Arc;
301301
302302
fn main() {
303-
let numbers = vec![1,2,3];
303+
let numbers = vec![1i, 2i, 3i];
304304
let numbers = Arc::new(numbers);
305305
306-
for num in range(0, 3) {
306+
for num in range(0u, 3) {
307307
let (tx, rx) = channel();
308308
tx.send(numbers.clone());
309309
@@ -346,10 +346,10 @@ and modify it to mutate the shared state:
346346
use std::sync::{Arc, Mutex};
347347
348348
fn main() {
349-
let numbers = vec![1,2,3];
349+
let numbers = vec![1i, 2i, 3i];
350350
let numbers_lock = Arc::new(Mutex::new(numbers));
351351
352-
for num in range(0, 3) {
352+
for num in range(0u, 3) {
353353
let (tx, rx) = channel();
354354
tx.send(numbers_lock.clone());
355355

src/doc/rust.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,12 @@ use std::option::{Some, None};
955955
# fn foo<T>(_: T){}
956956
957957
fn main() {
958-
// Equivalent to 'std::iter::range_step(0, 10, 2);'
959-
range_step(0, 10, 2);
958+
// Equivalent to 'std::iter::range_step(0u, 10u, 2u);'
959+
range_step(0u, 10u, 2u);
960960
961-
// Equivalent to 'foo(vec![std::option::Some(1.0), std::option::None]);'
962-
foo(vec![Some(1.0), None]);
961+
// Equivalent to 'foo(vec![std::option::Some(1.0f64),
962+
// std::option::None]);'
963+
foo(vec![Some(1.0f64), None]);
963964
}
964965
~~~~
965966

@@ -1475,7 +1476,7 @@ to pointers to the trait name, used as a type.
14751476
~~~~
14761477
# trait Shape { }
14771478
# impl Shape for int { }
1478-
# let mycircle = 0;
1479+
# let mycircle = 0i;
14791480
let myshape: Box<Shape> = box mycircle as Box<Shape>;
14801481
~~~~
14811482

@@ -3613,7 +3614,7 @@ and no-return value closure has type `proc()`.
36133614
An example of creating and calling a closure:
36143615

36153616
```rust
3616-
let captured_var = 10;
3617+
let captured_var = 10i;
36173618

36183619
let closure_no_args = || println!("captured_var={}", captured_var);
36193620

@@ -3685,7 +3686,7 @@ fn print(a: Box<Printable>) {
36853686
}
36863687
36873688
fn main() {
3688-
print(box 10 as Box<Printable>);
3689+
print(box 10i as Box<Printable>);
36893690
}
36903691
~~~~
36913692

0 commit comments

Comments
 (0)