Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Remove the fallback to int for integers and f64 for floating point numbers for real. #15234

Merged
merged 1 commit into from
Jun 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ impl<T: Send> Drop for Unique<T> {
// A comparison between the built-in `Box` and this reimplementation
fn main() {
{
let mut x = box 5;
let mut x = box 5i;
*x = 10;
} // `x` is freed here

{
let mut y = Unique::new(5);
let mut y = Unique::new(5i);
*y.borrow_mut() = 10;
} // `y` is freed here
}
Expand Down Expand Up @@ -678,7 +678,7 @@ unsafe fn deallocate(ptr: *mut u8, _size: uint, _align: uint) {

#[start]
fn main(argc: int, argv: *const *const u8) -> int {
let x = box 1;
let x = box 1i;

0
}
Expand Down
8 changes: 4 additions & 4 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Check it out:
```

fn dangling() -> Box<int> {
let i = box 1234;
let i = box 1234i;
return i;
}

Expand All @@ -143,16 +143,16 @@ fn add_one() -> int {
}
```

Now instead of a stack allocated `1234`,
we have a heap allocated `box 1234`.
Now instead of a stack allocated `1234i`,
we have a heap allocated `box 1234i`.
Whereas `&` borrows a pointer to existing memory,
creating an owned box allocates memory on the heap and places a value in it,
giving you the sole pointer to that memory.
You can roughly compare these two lines:

```
// Rust
let i = box 1234;
let i = box 1234i;
```

```cpp
Expand Down
35 changes: 17 additions & 18 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,14 @@ of integer literal suffix:
The type of an _unsuffixed_ integer literal is determined by type inference.
If an integer type can be _uniquely_ determined from the surrounding program
context, the unsuffixed integer literal has that type. If the program context
underconstrains the type, the unsuffixed integer literal's type is `int`; if
the program context overconstrains the type, it is considered a static type
error.
underconstrains the type, it is considered a static type error;
if the program context overconstrains the type,
it is also considered a static type error.

Examples of integer literals of various forms:

~~~~
123; 0xff00; // type determined by program context
// defaults to int in absence of type
// information

123i; // type int
123u; // type uint
123_u; // type uint
0xff_u8; // type u8
Expand All @@ -469,17 +466,19 @@ A _floating-point literal_ has one of two forms:
second decimal literal.
* A single _decimal literal_ followed by an _exponent_.

By default, a floating-point literal has a generic type, but will fall back to
`f64`. A floating-point literal may be followed (immediately, without any
By default, a floating-point literal has a generic type,
and, like integer literals, the type must be uniquely determined
from the context.
A floating-point literal may be followed (immediately, without any
spaces) by a _floating-point suffix_, which changes the type of the literal.
There are two floating-point suffixes: `f32`, and `f64` (the 32-bit and 64-bit
floating point types).

Examples of floating-point literals of various forms:

~~~~
123.0; // type f64
0.1; // type f64
123.0f64; // type f64
0.1f64; // type f64
0.1f32; // type f32
12E+99_f64; // type f64
~~~~
Expand Down Expand Up @@ -2700,9 +2699,9 @@ must be a constant expression that can be evaluated at compile time, such
as a [literal](#literals) or a [static item](#static-items).

~~~~
[1, 2, 3, 4];
[1i, 2, 3, 4];
["a", "b", "c", "d"];
[0, ..128]; // vector with 128 zeros
[0i, ..128]; // vector with 128 zeros
[0u8, 0u8, 0u8, 0u8];
~~~~

Expand Down Expand Up @@ -2881,7 +2880,7 @@ equals sign (`=`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
Evaluating an assignment expression [either copies or moves](#moved-and-copied-types) its right-hand operand to its left-hand operand.

~~~~
# let mut x = 0;
# let mut x = 0i;
# let y = 0;

x = y;
Expand Down Expand Up @@ -2932,7 +2931,7 @@ paren_expr : '(' expr ')' ;
An example of a parenthesized expression:

~~~~
let x = (2 + 3) * 4;
let x: int = (2 + 3) * 4;
~~~~


Expand Down Expand Up @@ -3016,7 +3015,7 @@ conditional expression evaluates to `false`, the `while` expression completes.
An example:

~~~~
let mut i = 0;
let mut i = 0u;

while i < 10 {
println!("hello");
Expand Down Expand Up @@ -3262,7 +3261,7 @@ Patterns can also dereference pointers by using the `&`,
on `x: &int` are equivalent:

~~~~
# let x = &3;
# let x = &3i;
let y = match *x { 0 => "zero", _ => "some" };
let z = match x { &0 => "zero", _ => "some" };

Expand All @@ -3285,7 +3284,7 @@ A range of values may be specified with `..`.
For example:

~~~~
# let x = 2;
# let x = 2i;

let message = match x {
0 | 1 => "not many",
Expand Down
49 changes: 24 additions & 25 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ write function, variable, and module names with lowercase letters, using
underscores where they help readability, while writing types in camel case.

~~~
let my_variable = 100;
let my_variable = 100i;
type MyType = int; // primitive types are _not_ camel case
~~~

Expand All @@ -276,7 +276,7 @@ write a piece of code like this:

~~~~
# let item = "salad";
let price;
let price: f64;
if item == "salad" {
price = 3.50;
} else if item == "muffin" {
Expand All @@ -290,7 +290,7 @@ But, in Rust, you don't have to repeat the name `price`:

~~~~
# let item = "salad";
let price =
let price: f64 =
if item == "salad" {
3.50
} else if item == "muffin" {
Expand Down Expand Up @@ -337,11 +337,10 @@ suffix that can be used to indicate the type of a literal: `i` for `int`,
In the absence of an integer literal suffix, Rust will infer the
integer type based on type annotations and function signatures in the
surrounding program. In the absence of any type information at all,
Rust will assume that an unsuffixed integer literal has type
`int`.
Rust will report an error and request that the type be specified explicitly.

~~~~
let a = 1; // `a` is an `int`
let a: int = 1; // `a` is an `int`
let b = 10i; // `b` is an `int`, due to the `i` suffix
let c = 100u; // `c` is a `uint`
let d = 1000i32; // `d` is an `i32`
Expand Down Expand Up @@ -475,7 +474,7 @@ against each pattern in order until one matches. The matching pattern
executes its corresponding arm.

~~~~
let my_number = 1;
let my_number = 1i;
match my_number {
0 => println!("zero"),
1 | 2 => println!("one or two"),
Expand All @@ -501,7 +500,7 @@ matches any single value. (`..`) is a different wildcard that can match
one or more fields in an `enum` variant.

~~~
# let my_number = 1;
# let my_number = 1i;
match my_number {
0 => { println!("zero") }
_ => { println!("something else") }
Expand Down Expand Up @@ -584,7 +583,7 @@ keyword `break` aborts the loop, and `continue` aborts the current
iteration and continues with the next.

~~~~
let mut cake_amount = 8;
let mut cake_amount = 8i;
while cake_amount > 0 {
cake_amount -= 1;
}
Expand Down Expand Up @@ -944,7 +943,7 @@ The `box` operator performs memory allocation on the heap:
~~~~
{
// an integer allocated on the heap
let y = box 10;
let y = box 10i;
}
// the destructor frees the heap memory as soon as `y` goes out of scope
~~~~
Expand Down Expand Up @@ -1165,7 +1164,7 @@ let z = x;
The mutability of a value may be changed by moving it to a new owner:

~~~~
let r = box 13;
let r = box 13i;
let mut s = r; // box becomes mutable
*s += 1;
let t = s; // box becomes immutable
Expand Down Expand Up @@ -1285,9 +1284,9 @@ Using the generic `List<T>` works much like before, thanks to type inference:
# Cons(value, box xs)
# }
let mut xs = Nil; // Unknown type! This is a `List<T>`, but `T` can be anything.
xs = prepend(xs, 10); // Here the compiler infers `xs`'s type as `List<int>`.
xs = prepend(xs, 15);
xs = prepend(xs, 20);
xs = prepend(xs, 10i); // Here the compiler infers `xs`'s type as `List<int>`.
xs = prepend(xs, 15i);
xs = prepend(xs, 20i);
~~~

The code sample above demonstrates type inference making most type annotations optional. It is
Expand Down Expand Up @@ -1410,12 +1409,12 @@ Beyond the properties granted by the size, an owned box behaves as a regular
value by inheriting the mutability and lifetime of the owner:

~~~~
let x = 5; // immutable
let mut y = 5; // mutable
let x = 5i; // immutable
let mut y = 5i; // mutable
y += 2;

let x = box 5; // immutable
let mut y = box 5; // mutable
let x = box 5i; // immutable
let mut y = box 5i; // mutable
*y += 2; // the `*` operator is needed to access the contained value
~~~~

Expand Down Expand Up @@ -1507,7 +1506,7 @@ freezing enforced statically at compile-time. An example of a non-`Freeze` type
is [`RefCell<T>`][refcell].

~~~~
let mut x = 5;
let mut x = 5i;
{
let y = &x; // `x` is now frozen. It cannot be modified or re-assigned.
}
Expand All @@ -1523,8 +1522,8 @@ Rust uses the unary star operator (`*`) to access the contents of a
box or pointer, similarly to C.

~~~
let owned = box 10;
let borrowed = &20;
let owned = box 10i;
let borrowed = &20i;

let sum = *owned + *borrowed;
~~~
Expand All @@ -1534,9 +1533,9 @@ assignments. Such an assignment modifies the value that the pointer
points to.

~~~
let mut owned = box 10;
let mut owned = box 10i;

let mut value = 20;
let mut value = 20i;
let borrowed = &mut value;

*owned = *borrowed + 100;
Expand Down Expand Up @@ -1654,12 +1653,12 @@ Unicode code points, so they cannot be freely mutated without the ability to
alter the length.

~~~
let mut xs = [1, 2, 3];
let mut xs = [1i, 2i, 3i];
let view = xs.mut_slice(0, 2);
view[0] = 5;

// The type of a mutable slice is written as `&mut [T]`
let ys: &mut [int] = &mut [1, 2, 3];
let ys: &mut [int] = &mut [1i, 2i, 3i];
~~~

Square brackets denote indexing into a slice or fixed-size vector:
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ mod tests {

#[test]
fn test_live() {
let x = Arc::new(5);
let x = Arc::new(5i);
let y = x.downgrade();
assert!(y.upgrade().is_some());
}

#[test]
fn test_dead() {
let x = Arc::new(5);
let x = Arc::new(5i);
let y = x.downgrade();
drop(x);
assert!(y.upgrade().is_none());
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mod bench {
#[bench]
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
box 10
box 10i
})
}
}
4 changes: 2 additions & 2 deletions src/libcollections/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ mod tests {
assert_eq!(hasher.hash(& &[1u8, 2u8, 3u8]), 9);

unsafe {
let ptr: *const int = mem::transmute(5);
let ptr: *const int = mem::transmute(5i);
assert_eq!(hasher.hash(&ptr), 5);
}

unsafe {
let ptr: *mut int = mem::transmute(5);
let ptr: *mut int = mem::transmute(5i);
assert_eq!(hasher.hash(&ptr), 5);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,15 @@ mod tests {
fn bench_push_back(b: &mut test::Bencher) {
let mut deq = RingBuf::new();
b.iter(|| {
deq.push_back(0);
deq.push_back(0i);
})
}

#[bench]
fn bench_push_front(b: &mut test::Bencher) {
let mut deq = RingBuf::new();
b.iter(|| {
deq.push_front(0);
deq.push_front(0i);
})
}

Expand All @@ -589,7 +589,7 @@ mod tests {
let mut deq = RingBuf::new();
b.iter(|| {
for _ in range(0i, 65) {
deq.push_front(1);
deq.push_front(1i);
}
})
}
Expand Down Expand Up @@ -651,10 +651,10 @@ mod tests {
#[test]
fn test_with_capacity() {
let mut d = RingBuf::with_capacity(0);
d.push_back(1);
d.push_back(1i);
assert_eq!(d.len(), 1);
let mut d = RingBuf::with_capacity(50);
d.push_back(1);
d.push_back(1i);
assert_eq!(d.len(), 1);
}

Expand Down
Loading