Skip to content

Commit 56c6fe6

Browse files
committed
---
yaml --- r: 178045 b: refs/heads/tmp c: 758a296 h: refs/heads/master i: 178043: 4b9788b v: v3
1 parent 61dabd7 commit 56c6fe6

File tree

241 files changed

+2198
-1319
lines changed

Some content is hidden

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

241 files changed

+2198
-1319
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 00a933f9ece4ef22f8651320e5f4fcfcbd37e0bf
37+
refs/heads/tmp: 758a296e2710746a31b36a2396047aad2367cfa5

branches/tmp/src/doc/intro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ Let's see an example. This Rust code will not compile:
424424
use std::thread::Thread;
425425
426426
fn main() {
427-
let mut numbers = vec![1is, 2, 3];
427+
let mut numbers = vec![1, 2, 3];
428428
429429
for i in 0..3 {
430430
Thread::spawn(move || {
@@ -478,7 +478,7 @@ use std::thread::Thread;
478478
use std::sync::{Arc,Mutex};
479479
480480
fn main() {
481-
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
481+
let numbers = Arc::new(Mutex::new(vec![1, 2, 3]));
482482
483483
for i in 0us..3 {
484484
let number = numbers.clone();
@@ -539,7 +539,7 @@ safety check that makes this an error about moved values:
539539
use std::thread::Thread;
540540
541541
fn main() {
542-
let vec = vec![1is, 2, 3];
542+
let vec = vec![1, 2, 3];
543543
544544
for i in 0us..3 {
545545
Thread::spawn(move || {

branches/tmp/src/doc/reference.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ cases mentioned in [Number literals](#number-literals) below.
268268
##### Suffixes
269269
| Integer | Floating-point |
270270
|---------|----------------|
271-
| `is` (`isize`), `us` (`usize`), `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64` | `f32`, `f64` |
271+
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `is` (`isize`), `us` (`usize`) | `f32`, `f64` |
272272

273273
#### Character and string literals
274274

@@ -468,27 +468,29 @@ Like any literal, an integer literal may be followed (immediately,
468468
without any spaces) by an _integer suffix_, which forcibly sets the
469469
type of the literal. There are 10 valid values for an integer suffix:
470470

471-
* The `is` and `us` suffixes give the literal type `isize` or `usize`,
472-
respectively.
473471
* Each of the signed and unsigned machine types `u8`, `i8`,
474472
`u16`, `i16`, `u32`, `i32`, `u64` and `i64`
475473
give the literal the corresponding machine type.
474+
* The `is` and `us` suffixes give the literal type `isize` or `usize`,
475+
respectively.
476476

477477
The type of an _unsuffixed_ integer literal is determined by type inference.
478478
If an integer type can be _uniquely_ determined from the surrounding program
479479
context, the unsuffixed integer literal has that type. If the program context
480-
underconstrains the type, it is considered a static type error; if the program
481-
context overconstrains the type, it is also considered a static type error.
480+
underconstrains the type, it defaults to the signed 32-bit integer `i32`; if
481+
the program context overconstrains the type, it is considered a static type
482+
error.
482483

483484
Examples of integer literals of various forms:
484485

485486
```
486-
123is; // type isize
487-
123us; // type usize
488-
123_us; // type usize
487+
123i32; // type i32
488+
123u32; // type u32
489+
123_u32; // type u32
489490
0xff_u8; // type u8
490491
0o70_i16; // type i16
491492
0b1111_1111_1001_0000_i32; // type i32
493+
0us; // type usize
492494
```
493495

494496
##### Floating-point literals
@@ -1135,8 +1137,8 @@ used as a type name.
11351137

11361138
When a generic function is referenced, its type is instantiated based on the
11371139
context of the reference. For example, calling the `iter` function defined
1138-
above on `[1, 2]` will instantiate type parameter `T` with `isize`, and require
1139-
the closure parameter to have type `fn(isize)`.
1140+
above on `[1, 2]` will instantiate type parameter `T` with `i32`, and require
1141+
the closure parameter to have type `fn(i32)`.
11401142

11411143
The type parameters can also be explicitly supplied in a trailing
11421144
[path](#paths) component after the function name. This might be necessary if
@@ -2746,9 +2748,9 @@ constant expression that can be evaluated at compile time, such as a
27462748
[literal](#literals) or a [static item](#static-items).
27472749

27482750
```
2749-
[1is, 2, 3, 4];
2751+
[1, 2, 3, 4];
27502752
["a", "b", "c", "d"];
2751-
[0is; 128]; // array with 128 zeros
2753+
[0; 128]; // array with 128 zeros
27522754
[0u8, 0u8, 0u8, 0u8];
27532755
```
27542756

@@ -2921,7 +2923,7 @@ moves](#moved-and-copied-types) its right-hand operand to its left-hand
29212923
operand.
29222924

29232925
```
2924-
# let mut x = 0is;
2926+
# let mut x = 0;
29252927
# let y = 0;
29262928
29272929
x = y;
@@ -3307,11 +3309,11 @@ fn main() {
33073309
```
33083310

33093311
Patterns can also dereference pointers by using the `&`, `&mut` and `box`
3310-
symbols, as appropriate. For example, these two matches on `x: &isize` are
3312+
symbols, as appropriate. For example, these two matches on `x: &i32` are
33113313
equivalent:
33123314

33133315
```
3314-
# let x = &3is;
3316+
# let x = &3;
33153317
let y = match *x { 0 => "zero", _ => "some" };
33163318
let z = match x { &0 => "zero", _ => "some" };
33173319
@@ -3332,7 +3334,7 @@ Multiple match patterns may be joined with the `|` operator. A range of values
33323334
may be specified with `...`. For example:
33333335

33343336
```
3335-
# let x = 2is;
3337+
# let x = 2;
33363338
33373339
let message = match x {
33383340
0 | 1 => "not many",
@@ -3673,16 +3675,16 @@ The type of a closure mapping an input of type `A` to an output of type `B` is
36733675
An example of creating and calling a closure:
36743676

36753677
```rust
3676-
let captured_var = 10is;
3678+
let captured_var = 10;
36773679

36783680
let closure_no_args = |&:| println!("captured_var={}", captured_var);
36793681

3680-
let closure_args = |&: arg: isize| -> isize {
3682+
let closure_args = |&: arg: i32| -> i32 {
36813683
println!("captured_var={}, arg={}", captured_var, arg);
36823684
arg // Note lack of semicolon after 'arg'
36833685
};
36843686

3685-
fn call_closure<F: Fn(), G: Fn(isize) -> isize>(c1: F, c2: G) {
3687+
fn call_closure<F: Fn(), G: Fn(i32) -> i32>(c1: F, c2: G) {
36863688
c1();
36873689
c2(2);
36883690
}
@@ -3714,7 +3716,7 @@ trait Printable {
37143716
fn stringify(&self) -> String;
37153717
}
37163718
3717-
impl Printable for isize {
3719+
impl Printable for i32 {
37183720
fn stringify(&self) -> String { self.to_string() }
37193721
}
37203722
@@ -3723,7 +3725,7 @@ fn print(a: Box<Printable>) {
37233725
}
37243726
37253727
fn main() {
3726-
print(Box::new(10is) as Box<Printable>);
3728+
print(Box::new(10) as Box<Printable>);
37273729
}
37283730
```
37293731

branches/tmp/src/liballoc/boxed.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,52 @@ impl<T> Box<T> {
102102
}
103103
}
104104

105+
impl<T : ?Sized> Box<T> {
106+
/// Constructs a box from the raw pointer.
107+
///
108+
/// After this function call, pointer is owned by resulting box.
109+
/// In particular, it means that `Box` destructor calls destructor
110+
/// of `T` and releases memory. Since the way `Box` allocates and
111+
/// releases memory is unspecified, so the only valid pointer to
112+
/// pass to this function is the one taken from another `Box` with
113+
/// `box::into_raw` function.
114+
///
115+
/// Function is unsafe, because improper use of this function may
116+
/// lead to memory problems like double-free, for example if the
117+
/// function is called twice on the same raw pointer.
118+
#[unstable(feature = "alloc",
119+
reason = "may be renamed or moved out of Box scope")]
120+
pub unsafe fn from_raw(raw: *mut T) -> Self {
121+
mem::transmute(raw)
122+
}
123+
}
124+
125+
/// Consumes the `Box`, returning the wrapped raw pointer.
126+
///
127+
/// After call to this function, caller is responsible for the memory
128+
/// previously managed by `Box`, in particular caller should properly
129+
/// destroy `T` and release memory. The proper way to do it is to
130+
/// convert pointer back to `Box` with `Box::from_raw` function, because
131+
/// `Box` does not specify, how memory is allocated.
132+
///
133+
/// Function is unsafe, because result of this function is no longer
134+
/// automatically managed that may lead to memory or other resource
135+
/// leak.
136+
///
137+
/// # Example
138+
/// ```
139+
/// use std::boxed;
140+
///
141+
/// let seventeen = Box::new(17u32);
142+
/// let raw = unsafe { boxed::into_raw(seventeen) };
143+
/// let boxed_again = unsafe { Box::from_raw(raw) };
144+
/// ```
145+
#[unstable(feature = "alloc",
146+
reason = "may be renamed")]
147+
pub unsafe fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T {
148+
mem::transmute(b)
149+
}
150+
105151
#[stable(feature = "rust1", since = "1.0.0")]
106152
impl<T: Default> Default for Box<T> {
107153
#[stable(feature = "rust1", since = "1.0.0")]

branches/tmp/src/liballoc/boxed_test.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use core::ops::Deref;
1515
use core::result::Result::{Ok, Err};
1616
use core::clone::Clone;
1717

18+
use std::boxed;
1819
use std::boxed::Box;
1920
use std::boxed::BoxAny;
2021

@@ -73,3 +74,44 @@ fn deref() {
7374
fn homura<T: Deref<Target=i32>>(_: T) { }
7475
homura(Box::new(765i32));
7576
}
77+
78+
#[test]
79+
fn raw_sized() {
80+
unsafe {
81+
let x = Box::new(17i32);
82+
let p = boxed::into_raw(x);
83+
assert_eq!(17, *p);
84+
*p = 19;
85+
let y = Box::from_raw(p);
86+
assert_eq!(19, *y);
87+
}
88+
}
89+
90+
#[test]
91+
fn raw_trait() {
92+
trait Foo {
93+
fn get(&self) -> u32;
94+
fn set(&mut self, value: u32);
95+
}
96+
97+
struct Bar(u32);
98+
99+
impl Foo for Bar {
100+
fn get(&self) -> u32 {
101+
self.0
102+
}
103+
104+
fn set(&mut self, value: u32) {
105+
self.0 = value;
106+
}
107+
}
108+
109+
unsafe {
110+
let x: Box<Foo> = Box::new(Bar(17));
111+
let p = boxed::into_raw(x);
112+
assert_eq!(17, (*p).get());
113+
(*p).set(19);
114+
let y: Box<Foo> = Box::from_raw(p);
115+
assert_eq!(19, y.get());
116+
}
117+
}

branches/tmp/src/libcollections/dlist.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<T> DList<T> {
333333
///
334334
/// let mut dl = DList::new();
335335
///
336-
/// dl.push_front(2is);
336+
/// dl.push_front(2);
337337
/// assert_eq!(dl.len(), 1);
338338
///
339339
/// dl.push_front(1);
@@ -360,10 +360,10 @@ impl<T> DList<T> {
360360
///
361361
/// let mut dl = DList::new();
362362
///
363-
/// dl.push_front(2is);
363+
/// dl.push_front(2);
364364
/// dl.push_front(1);
365365
/// assert_eq!(dl.len(), 2);
366-
/// assert_eq!(dl.front(), Some(&1is));
366+
/// assert_eq!(dl.front(), Some(&1));
367367
///
368368
/// dl.clear();
369369
/// assert_eq!(dl.len(), 0);
@@ -388,7 +388,7 @@ impl<T> DList<T> {
388388
/// assert_eq!(dl.front(), None);
389389
///
390390
/// dl.push_front(1);
391-
/// assert_eq!(dl.front(), Some(&1is));
391+
/// assert_eq!(dl.front(), Some(&1));
392392
///
393393
/// ```
394394
#[inline]
@@ -409,13 +409,13 @@ impl<T> DList<T> {
409409
/// assert_eq!(dl.front(), None);
410410
///
411411
/// dl.push_front(1);
412-
/// assert_eq!(dl.front(), Some(&1is));
412+
/// assert_eq!(dl.front(), Some(&1));
413413
///
414414
/// match dl.front_mut() {
415415
/// None => {},
416-
/// Some(x) => *x = 5is,
416+
/// Some(x) => *x = 5,
417417
/// }
418-
/// assert_eq!(dl.front(), Some(&5is));
418+
/// assert_eq!(dl.front(), Some(&5));
419419
///
420420
/// ```
421421
#[inline]
@@ -436,7 +436,7 @@ impl<T> DList<T> {
436436
/// assert_eq!(dl.back(), None);
437437
///
438438
/// dl.push_back(1);
439-
/// assert_eq!(dl.back(), Some(&1is));
439+
/// assert_eq!(dl.back(), Some(&1));
440440
///
441441
/// ```
442442
#[inline]
@@ -457,13 +457,13 @@ impl<T> DList<T> {
457457
/// assert_eq!(dl.back(), None);
458458
///
459459
/// dl.push_back(1);
460-
/// assert_eq!(dl.back(), Some(&1is));
460+
/// assert_eq!(dl.back(), Some(&1));
461461
///
462462
/// match dl.back_mut() {
463463
/// None => {},
464-
/// Some(x) => *x = 5is,
464+
/// Some(x) => *x = 5,
465465
/// }
466-
/// assert_eq!(dl.back(), Some(&5is));
466+
/// assert_eq!(dl.back(), Some(&5));
467467
///
468468
/// ```
469469
#[inline]
@@ -483,8 +483,8 @@ impl<T> DList<T> {
483483
///
484484
/// let mut dl = DList::new();
485485
///
486-
/// dl.push_front(2is);
487-
/// assert_eq!(dl.front().unwrap(), &2is);
486+
/// dl.push_front(2);
487+
/// assert_eq!(dl.front().unwrap(), &2);
488488
///
489489
/// dl.push_front(1);
490490
/// assert_eq!(dl.front().unwrap(), &1);
@@ -508,7 +508,7 @@ impl<T> DList<T> {
508508
/// let mut d = DList::new();
509509
/// assert_eq!(d.pop_front(), None);
510510
///
511-
/// d.push_front(1is);
511+
/// d.push_front(1);
512512
/// d.push_front(3);
513513
/// assert_eq!(d.pop_front(), Some(3));
514514
/// assert_eq!(d.pop_front(), Some(1));
@@ -568,7 +568,7 @@ impl<T> DList<T> {
568568
///
569569
/// let mut d = DList::new();
570570
///
571-
/// d.push_front(1is);
571+
/// d.push_front(1);
572572
/// d.push_front(2);
573573
/// d.push_front(3);
574574
///

0 commit comments

Comments
 (0)