Skip to content

Commit bf4af7a

Browse files
committed
---
yaml --- r: 128687 b: refs/heads/try c: 0c158b4 h: refs/heads/master i: 128685: b1f9352 128683: fed406a 128679: 4934aa5 128671: 840f8f1 v: v3
1 parent 8537550 commit bf4af7a

Some content is hidden

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

51 files changed

+340
-1342
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 4136d5f44d739391a60f8e51429dd30f2d96aae8
5+
refs/heads/try: 0c158b4fbfcec7d6f18859661047dff2109fdfe4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/doc/guide.md

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,86 +1432,6 @@ building our guessing game, but we need to know how to do one last thing first:
14321432
get input from the keyboard. You can't have a guessing game without the ability
14331433
to guess!
14341434

1435-
# Strings
1436-
1437-
Strings are an important concept for any programmer to master. Rust's string
1438-
handling system is a bit different than in other languages, due to its systems
1439-
focus. Any time you have a data structure of variable size, things can get
1440-
tricky, and strings are a re-sizable data structure. That said, Rust's strings
1441-
also work differently than in some other systems languages, such as C.
1442-
1443-
Let's dig into the details. A **string** is a sequence of unicode scalar values
1444-
encoded as a stream of UTF-8 bytes. All strings are guaranteed to be
1445-
validly-encoded UTF-8 sequences. Additionally, strings are not null-terminated
1446-
and can contain null bytes.
1447-
1448-
Rust has two main types of strings: `&str` and `String`.
1449-
1450-
The first kind is a `&str`. This is pronounced a 'string slice.' String literals
1451-
are of the type `&str`:
1452-
1453-
```{rust}
1454-
let string = "Hello there.";
1455-
```
1456-
1457-
This string is statically allocated, meaning that it's saved inside our
1458-
compiled program, and exists for the entire duration it runs. The `string`
1459-
binding is a reference to this statically allocated string. String slices
1460-
have a fixed size, and cannot be mutated.
1461-
1462-
A `String`, on the other hand, is an in-memory string. This string is
1463-
growable, and is also guaranteed to be UTF-8.
1464-
1465-
```{rust}
1466-
let mut s = "Hello".to_string();
1467-
println!("{}", s);
1468-
1469-
s.push_str(", world.");
1470-
println!("{}", s);
1471-
```
1472-
1473-
You can coerce a `String` into a `&str` with the `as_slice()` method:
1474-
1475-
```{rust}
1476-
fn takes_slice(slice: &str) {
1477-
println!("Got: {}", slice);
1478-
}
1479-
1480-
fn main() {
1481-
let s = "Hello".to_string();
1482-
takes_slice(s.as_slice());
1483-
}
1484-
```
1485-
1486-
To compare a String to a constant string, prefer `as_slice()`...
1487-
1488-
```{rust}
1489-
fn compare(string: String) {
1490-
if string.as_slice() == "Hello" {
1491-
println!("yes");
1492-
}
1493-
}
1494-
```
1495-
1496-
... over `to_string()`:
1497-
1498-
```{rust}
1499-
fn compare(string: String) {
1500-
if string == "Hello".to_string() {
1501-
println!("yes");
1502-
}
1503-
}
1504-
```
1505-
1506-
Converting a `String` to a `&str` is cheap, but converting the `&str` to a
1507-
`String` involves allocating memory. No reason to do that unless you have to!
1508-
1509-
That's the basics of strings in Rust! They're probably a bit more complicated
1510-
than you are used to, if you come from a scripting language, but when the
1511-
low-level details matter, they really matter. Just remember that `String`s
1512-
allocate memory and control their data, while `&str`s are a reference to
1513-
another string, and you'll be all set.
1514-
15151435
# Standard Input
15161436

15171437
Getting input from the keyboard is pretty easy, but uses some things
@@ -3694,94 +3614,6 @@ guide](http://doc.rust-lang.org/guide-pointers.html#rc-and-arc).
36943614

36953615
# Patterns
36963616

3697-
# Method Syntax
3698-
3699-
Functions are great, but if you want to call a bunch of them on some data, it
3700-
can be awkward. Consider this code:
3701-
3702-
```{rust,ignore}
3703-
baz(bar(foo(x)));
3704-
```
3705-
3706-
We would read this left-to right, and so we see 'baz bar foo.' But this isn't the
3707-
order that the functions would get called in, that's inside-out: 'foo bar baz.'
3708-
Wouldn't it be nice if we could do this instead?
3709-
3710-
```{rust,ignore}
3711-
x.foo().bar().baz();
3712-
```
3713-
3714-
Luckily, as you may have guessed with the leading question, you can! Rust provides
3715-
the ability to use this **method call syntax** via the `impl` keyword.
3716-
3717-
Here's how it works:
3718-
3719-
```
3720-
struct Circle {
3721-
x: f64,
3722-
y: f64,
3723-
radius: f64,
3724-
}
3725-
3726-
impl Circle {
3727-
fn area(&self) -> f64 {
3728-
std::f64::consts::PI * (self.radius * self.radius)
3729-
}
3730-
}
3731-
3732-
fn main() {
3733-
let c = Circle { x: 0.0, y: 0.0, radius: 2.0 };
3734-
println!("{}", c.area());
3735-
}
3736-
```
3737-
3738-
This will print `12.566371`.
3739-
3740-
We've made a struct that represents a circle. We then write an `impl` block,
3741-
and inside it, define a method, `area`. Methods take a special first
3742-
parameter, `&self`. There are three variants: `self`, `&self`, and `&mut self`.
3743-
You can think of this first parameter as being the `x` in `x.foo()`. The three
3744-
variants correspond to the three kinds of thing `x` could be: `self` if it's
3745-
just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
3746-
a mutable reference. We should default to using `&self`, as it's the most
3747-
common.
3748-
3749-
Finally, as you may remember, the value of the area of a circle is `π*r²`.
3750-
Because we took the `&self` parameter to `area`, we can use it just like any
3751-
other parameter. Because we know it's a `Circle`, we can access the `radius`
3752-
just like we would with any other struct. An import of π and some
3753-
multiplications later, and we have our area.
3754-
3755-
You can also define methods that do not take a `self` parameter. Here's a
3756-
pattern that's very common in Rust code:
3757-
3758-
```
3759-
struct Circle {
3760-
x: f64,
3761-
y: f64,
3762-
radius: f64,
3763-
}
3764-
3765-
impl Circle {
3766-
fn new(x: f64, y: f64, radius: f64) -> Circle {
3767-
Circle {
3768-
x: x,
3769-
y: y,
3770-
radius: radius,
3771-
}
3772-
}
3773-
}
3774-
3775-
fn main() {
3776-
let c = Circle::new(0.0, 0.0, 2.0);
3777-
}
3778-
```
3779-
3780-
This **static method** builds a new `Circle` for us. Note that static methods
3781-
are called with the `Struct::method()` syntax, rather than the `ref.method()`
3782-
syntax.
3783-
3784-
37853617
# Closures
37863618

37873619
So far, we've made lots of functions in Rust. But we've given them all names.

branches/try/src/libcollections/ringbuf.rs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ impl<'a, T> ExactSize<&'a mut T> for MutItems<'a, T> {}
403403
fn grow<T>(nelts: uint, loptr: &mut uint, elts: &mut Vec<Option<T>>) {
404404
assert_eq!(nelts, elts.len());
405405
let lo = *loptr;
406-
elts.reserve(nelts * 2);
407-
let newlen = elts.capacity();
406+
let newlen = nelts * 2;
407+
elts.reserve(newlen);
408408

409409
/* fill with None */
410-
for _ in range(elts.len(), newlen) {
410+
for _ in range(elts.len(), elts.capacity()) {
411411
elts.push(None);
412412
}
413413

@@ -750,47 +750,6 @@ mod tests {
750750
assert_eq!(d.len(), 1);
751751
}
752752

753-
#[test]
754-
fn test_with_capacity_non_power_two() {
755-
let mut d3 = RingBuf::with_capacity(3);
756-
d3.push(1i);
757-
758-
// X = None, | = lo
759-
// [|1, X, X]
760-
assert_eq!(d3.pop_front(), Some(1));
761-
// [X, |X, X]
762-
assert_eq!(d3.front(), None);
763-
764-
// [X, |3, X]
765-
d3.push(3);
766-
// [X, |3, 6]
767-
d3.push(6);
768-
// [X, X, |6]
769-
assert_eq!(d3.pop_front(), Some(3));
770-
771-
// Pushing the lo past half way point to trigger
772-
// the 'B' scenario for growth
773-
// [9, X, |6]
774-
d3.push(9);
775-
// [9, 12, |6]
776-
d3.push(12);
777-
778-
d3.push(15);
779-
// There used to be a bug here about how the
780-
// RingBuf made growth assumptions about the
781-
// underlying Vec which didn't hold and lead
782-
// to corruption.
783-
// (Vec grows to next power of two)
784-
//good- [9, 12, 15, X, X, X, X, |6]
785-
//bug- [15, 12, X, X, X, |6, X, X]
786-
assert_eq!(d3.pop_front(), Some(6));
787-
788-
// Which leads us to the following state which
789-
// would be a failure case.
790-
//bug- [15, 12, X, X, X, X, |X, X]
791-
assert_eq!(d3.front(), Some(&9));
792-
}
793-
794753
#[test]
795754
fn test_reserve_exact() {
796755
let mut d = RingBuf::new();

branches/try/src/libcore/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Float for f32 {
293293
#[inline]
294294
fn frac_pi_8() -> f32 { consts::FRAC_PI_8 }
295295

296-
/// 1.0 / pi
296+
/// 1 .0/ pi
297297
#[inline]
298298
fn frac_1_pi() -> f32 { consts::FRAC_1_PI }
299299

branches/try/src/liblibc/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,16 +1142,18 @@ pub mod types {
11421142
pub mod os {
11431143
pub mod common {
11441144
pub mod posix01 {
1145-
use types::os::arch::c95::{c_short, time_t, c_long};
1145+
use types::os::arch::c95::{c_short, time_t, suseconds_t,
1146+
c_long};
11461147
use types::os::arch::extra::{int64, time64_t};
11471148
use types::os::arch::posix88::{dev_t, ino_t};
1149+
use types::os::arch::posix88::mode_t;
11481150

11491151
// pub Note: this is the struct called stat64 in win32. Not stat,
11501152
// nor stati64.
11511153
pub struct stat {
11521154
pub st_dev: dev_t,
11531155
pub st_ino: ino_t,
1154-
pub st_mode: u16,
1156+
pub st_mode: mode_t,
11551157
pub st_nlink: c_short,
11561158
pub st_uid: c_short,
11571159
pub st_gid: c_short,
@@ -1169,8 +1171,8 @@ pub mod types {
11691171
}
11701172

11711173
pub struct timeval {
1172-
pub tv_sec: c_long,
1173-
pub tv_usec: c_long,
1174+
pub tv_sec: time_t,
1175+
pub tv_usec: suseconds_t,
11741176
}
11751177

11761178
pub struct timespec {
@@ -1184,7 +1186,7 @@ pub mod types {
11841186
pub mod bsd44 {
11851187
use types::os::arch::c95::{c_char, c_int, c_uint, size_t};
11861188

1187-
pub type SOCKET = uint;
1189+
pub type SOCKET = c_uint;
11881190
pub type socklen_t = c_int;
11891191
pub type sa_family_t = u16;
11901192
pub type in_port_t = u16;
@@ -1195,7 +1197,6 @@ pub mod types {
11951197
}
11961198
pub struct sockaddr_storage {
11971199
pub ss_family: sa_family_t,
1198-
pub __ss_pad1: [u8, ..6],
11991200
pub __ss_align: i64,
12001201
pub __ss_pad2: [u8, ..112],
12011202
}
@@ -1292,9 +1293,12 @@ pub mod types {
12921293
pub mod posix88 {
12931294
pub type off_t = i32;
12941295
pub type dev_t = u32;
1295-
pub type ino_t = u16;
1296+
pub type ino_t = i16;
12961297

1297-
pub type pid_t = u32;
1298+
#[cfg(target_arch = "x86")]
1299+
pub type pid_t = i32;
1300+
#[cfg(target_arch = "x86_64")]
1301+
pub type pid_t = i64;
12981302

12991303
pub type useconds_t = u32;
13001304
pub type mode_t = u16;
@@ -1411,7 +1415,7 @@ pub mod types {
14111415
pub dwPageSize: DWORD,
14121416
pub lpMinimumApplicationAddress: LPVOID,
14131417
pub lpMaximumApplicationAddress: LPVOID,
1414-
pub dwActiveProcessorMask: uint,
1418+
pub dwActiveProcessorMask: DWORD,
14151419
pub dwNumberOfProcessors: DWORD,
14161420
pub dwProcessorType: DWORD,
14171421
pub dwAllocationGranularity: DWORD,
@@ -1946,7 +1950,7 @@ pub mod consts {
19461950
}
19471951
pub mod extra {
19481952
use types::os::arch::c95::c_int;
1949-
use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE};
1953+
use types::os::arch::extra::{WORD, DWORD, BOOL};
19501954

19511955
pub static TRUE : BOOL = 1;
19521956
pub static FALSE : BOOL = 0;
@@ -1975,7 +1979,7 @@ pub mod consts {
19751979
pub static ERROR_IO_PENDING: c_int = 997;
19761980
pub static ERROR_FILE_INVALID : c_int = 1006;
19771981
pub static ERROR_NOT_FOUND: c_int = 1168;
1978-
pub static INVALID_HANDLE_VALUE: HANDLE = -1 as HANDLE;
1982+
pub static INVALID_HANDLE_VALUE : c_int = -1;
19791983

19801984
pub static DELETE : DWORD = 0x00010000;
19811985
pub static READ_CONTROL : DWORD = 0x00020000;

branches/try/src/libnative/io/c_win32.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1;
2828
pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40;
2929

3030
#[repr(C)]
31-
#[cfg(target_arch = "x86")]
3231
pub struct WSADATA {
3332
pub wVersion: libc::WORD,
3433
pub wHighVersion: libc::WORD,
@@ -38,17 +37,6 @@ pub struct WSADATA {
3837
pub iMaxUdpDg: u16,
3938
pub lpVendorInfo: *mut u8,
4039
}
41-
#[repr(C)]
42-
#[cfg(target_arch = "x86_64")]
43-
pub struct WSADATA {
44-
pub wVersion: libc::WORD,
45-
pub wHighVersion: libc::WORD,
46-
pub iMaxSockets: u16,
47-
pub iMaxUdpDg: u16,
48-
pub lpVendorInfo: *mut u8,
49-
pub szDescription: [u8, ..WSADESCRIPTION_LEN + 1],
50-
pub szSystemStatus: [u8, ..WSASYS_STATUS_LEN + 1],
51-
}
5240

5341
pub type LPWSADATA = *mut WSADATA;
5442

0 commit comments

Comments
 (0)