Skip to content

Commit a166d2e

Browse files
committed
---
yaml --- r: 129022 b: refs/heads/auto c: 08a3453 h: refs/heads/master v: v3
1 parent 8c645c8 commit a166d2e

Some content is hidden

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

65 files changed

+342
-1133
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 5fe5e3947bc1dbc7551941aedcd01ec4e45fb00d
16+
refs/heads/auto: 08a34531111ce02e0db9c7deed291f65508593bd
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/guide-ffi.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,12 @@ Rust code:
263263
264264
~~~~no_run
265265
266-
#[repr(C)]
267266
struct RustObject {
268267
a: i32,
269268
// other members
270269
}
271270
272-
extern "C" fn callback(target: *mut RustObject, a:i32) {
271+
extern fn callback(target: *mut RustObject, a:i32) {
273272
println!("I'm called from C with value {0}", a);
274273
unsafe {
275274
// Update the value in RustObject with the value received from the callback
@@ -507,16 +506,16 @@ to define a block for all windows systems, not just x86 ones.
507506
508507
# Interoperability with foreign code
509508
510-
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C
511-
only if the `#[repr(C)]` attribute is applied to it. `#[repr(C, packed)]` can be used to lay out
512-
struct members without padding. `#[repr(C)]` can also be applied to an enum.
509+
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C.
510+
A `#[packed]` attribute is available, which will lay out the struct members without padding.
511+
However, there are currently no guarantees about the layout of an `enum`.
513512
514-
Rust's owned boxes (`Box<T>`) use non-nullable pointers as handles which point to the contained
513+
Rust's owned and managed boxes use non-nullable pointers as handles which point to the contained
515514
object. However, they should not be manually created because they are managed by internal
516-
allocators. References can safely be assumed to be non-nullable pointers directly to the type.
517-
However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so prefer
518-
using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions about
519-
them.
515+
allocators. References can safely be assumed to be non-nullable pointers directly to the
516+
type. However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so
517+
prefer using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions
518+
about them.
520519
521520
Vectors and strings share the same basic memory layout, and utilities are available in the `vec` and
522521
`str` modules for working with C APIs. However, strings are not terminated with `\0`. If you need a

branches/auto/src/doc/guide.md

Lines changed: 5 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ destructuring `let`.
10731073
## Enums
10741074

10751075
Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful
1076-
feature of Rust, and are used throughout the standard library. This is an enum
1077-
that is provided by the Rust standard library:
1076+
feature of Rust, and are used throughout the standard library. Enums look
1077+
like this:
10781078

10791079
```{rust}
10801080
enum Ordering {
@@ -1084,8 +1084,9 @@ enum Ordering {
10841084
}
10851085
```
10861086

1087-
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
1088-
time. Here's an example:
1087+
This is an enum that is provided by the Rust standard library. An `Ordering`
1088+
can only be _one_ of `Less`, `Equal`, or `Greater` at any given time. Here's
1089+
an example:
10891090

10901091
```{rust}
10911092
fn cmp(a: int, b: int) -> Ordering {
@@ -3667,173 +3668,6 @@ In order to truly understand this error, we have to learn a few new concepts:
36673668

36683669
## Ownership, borrowing, and lifetimes
36693670

3670-
Whenever a resource of some kind is created, something must be responsible
3671-
for destroying that resource as well. Given that we're discussing pointers
3672-
right now, let's discuss this in the context of memory allocation, though
3673-
it applies to other resources as well.
3674-
3675-
When you allocate heap memory, you need a mechanism to free that memory. Many
3676-
languages let the programmer control the allocation, and then use a garbage
3677-
collector to handle the deallocation. This is a valid, time-tested strategy,
3678-
but it's not without its drawbacks. Because the programmer does not have to
3679-
think as much about deallocation, allocation becomes something commonplace,
3680-
because it's easy. And if you need precise control over when something is
3681-
deallocated, leaving it up to your runtime can make this difficult.
3682-
3683-
Rust chooses a different path, and that path is called **ownership**. Any
3684-
binding that creates a resource is the **owner** of that resource. Being an
3685-
owner gives you three privileges, with two restrictions:
3686-
3687-
1. You control when that resource is deallocated.
3688-
2. You may lend that resource, immutably, to as many borrowers as you'd like.
3689-
3. You may lend that resource, mutably, to a single borrower. **BUT**
3690-
4. Once you've done so, you may not also lend it out otherwise, mutably or
3691-
immutably.
3692-
5. You may not lend it out mutably if you're currently lending it to someone.
3693-
3694-
What's up with all this 'lending' and 'borrowing'? When you allocate memory,
3695-
you get a pointer to that memory. This pointer allows you to manipulate said
3696-
memory. If you are the owner of a pointer, then you may allow another
3697-
binding to temporarily borrow that pointer, and then they can manipulate the
3698-
memory. The length of time that the borrower is borrowing the pointer
3699-
from you is called a **lifetime**.
3700-
3701-
If two distinct bindings share a pointer, and the memory that pointer points to
3702-
is immutable, then there are no problems. But if it's mutable, both pointers
3703-
can attempt to write to the memory at the same time, causing a **race
3704-
condition**. Therefore, if someone wants to mutate something that they've
3705-
borrowed from you, you must not have lent out that pointer to anyone else.
3706-
3707-
Rust has a sophisticated system called the **borrow checker** to make sure that
3708-
everyone plays by these rules. At compile time, it verifies that none of these
3709-
rules are broken. If there's no problem, our program compiles successfully, and
3710-
there is no runtime overhead for any of this. The borrow checker works only at
3711-
compile time. If the borrow checker did find a problem, it will report a
3712-
**lifetime error**, and your program will refuse to compile.
3713-
3714-
That's a lot to take in. It's also one of the _most_ important concepts in
3715-
all of Rust. Let's see this syntax in action:
3716-
3717-
```{rust}
3718-
{
3719-
let x = 5i; // x is the owner of this integer, which is memory on the stack.
3720-
3721-
// other code here...
3722-
3723-
} // privilege 1: when x goes out of scope, this memory is deallocated
3724-
3725-
/// this function borrows an integer. It's given back automatically when the
3726-
/// function returns.
3727-
fn foo(x: &int) -> &int { x }
3728-
3729-
{
3730-
let x = 5i; // x is the owner of this integer, which is memory on the stack.
3731-
3732-
// privilege 2: you may lend that resource, to as many borrowers as you'd like
3733-
let y = &x;
3734-
let z = &x;
3735-
3736-
foo(&x); // functions can borrow too!
3737-
3738-
let a = &x; // we can do this alllllll day!
3739-
}
3740-
3741-
{
3742-
let mut x = 5i; // x is the owner of this integer, which is memory on the stack.
3743-
3744-
let y = &mut x; // privilege 3: you may lend that resource to a single borrower,
3745-
// mutably
3746-
}
3747-
```
3748-
3749-
If you are a borrower, you get a few privileges as well, but must also obey a
3750-
restriction:
3751-
3752-
1. If the borrow is immutable, you may read the data the pointer points to.
3753-
2. If the borrow is mutable, you may read and write the data the pointer points to.
3754-
3. You may lend the pointer to someone else in an immutable fashion, **BUT**
3755-
4. When you do so, they must return it to you before you must give your own
3756-
borrow back.
3757-
3758-
This last requirement can seem odd, but it also makes sense. If you have to
3759-
return something, and you've lent it to someone, they need to give it back to
3760-
you for you to give it back! If we didn't, then the owner could deallocate
3761-
the memory, and the person we've loaned it out to would have a pointer to
3762-
invalid memory. This is called a 'dangling pointer.'
3763-
3764-
Let's re-examine the error that led us to talk about all of this, which was a
3765-
violation of the restrictions placed on owners who lend something out mutably.
3766-
The code:
3767-
3768-
```{rust,ignore}
3769-
let mut x = 5i;
3770-
let y = &mut x;
3771-
let z = &mut x;
3772-
```
3773-
3774-
The error:
3775-
3776-
```{notrust,ignore}
3777-
error: cannot borrow `x` as mutable more than once at a time
3778-
let z = &mut x;
3779-
^
3780-
note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends
3781-
let y = &mut x;
3782-
^
3783-
note: previous borrow ends here
3784-
fn main() {
3785-
let mut x = 5i;
3786-
let y = &mut x;
3787-
let z = &mut x;
3788-
}
3789-
^
3790-
```
3791-
3792-
This error comes in three parts. Let's go over each in turn.
3793-
3794-
```{notrust,ignore}
3795-
error: cannot borrow `x` as mutable more than once at a time
3796-
let z = &mut x;
3797-
^
3798-
```
3799-
3800-
This error states the restriction: you cannot lend out something mutable more
3801-
than once at the same time. The borrow checker knows the rules!
3802-
3803-
```{notrust,ignore}
3804-
note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends
3805-
let y = &mut x;
3806-
^
3807-
```
3808-
3809-
Some compiler errors come with notes to help you fix the error. This error comes
3810-
with two notes, and this is the first. This note informs us of exactly where
3811-
the first mutable borrow occurred. The error showed us the second. So now we
3812-
see both parts of the problem. It also alludes to rule #3, by reminding us that
3813-
we can't change `x` until the borrow is over.
3814-
3815-
```{notrust,ignore}
3816-
note: previous borrow ends here
3817-
fn main() {
3818-
let mut x = 5i;
3819-
let y = &mut x;
3820-
let z = &mut x;
3821-
}
3822-
^
3823-
```
3824-
3825-
Here's the second note, which lets us know where the first borrow would be over.
3826-
This is useful, because if we wait to try to borrow `x` after this borrow is
3827-
over, then everything will work.
3828-
3829-
These rules are very simple, but that doesn't mean that they're easy. For more
3830-
advanced patterns, please consult the [Lifetime Guide](guide-lifetimes.html).
3831-
You'll also learn what this type signature with the `'a` syntax is:
3832-
3833-
```{rust,ignore}
3834-
pub fn as_maybe_owned(&self) -> MaybeOwned<'a> { ... }
3835-
```
3836-
38373671
## Boxes
38383672

38393673
All of our references so far have been to variables we've created on the stack.

branches/auto/src/doc/rust.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,6 @@ struct Cookie;
13081308
let c = [Cookie, Cookie, Cookie, Cookie];
13091309
~~~~
13101310

1311-
The precise memory layout of a structure is not specified. One can specify a
1312-
particular layout using the [`repr` attribute](#ffi-attributes).
1313-
13141311
By using the `struct_inherit` feature gate, structures may use single inheritance. A Structure may only
13151312
inherit from a single other structure, called the _super-struct_. The inheriting structure (sub-struct)
13161313
acts as if all fields in the super-struct were present in the sub-struct. Fields declared in a sub-struct
@@ -1944,23 +1941,6 @@ interpreted:
19441941
- `linkage` - on a static, this specifies the [linkage
19451942
type](http://llvm.org/docs/LangRef.html#linkage-types).
19461943

1947-
On `enum`s:
1948-
1949-
- `repr` - on C-like enums, this sets the underlying type used for
1950-
representation. Takes one argument, which is the primitive
1951-
type this enum should be represented for, or `C`, which specifies that it
1952-
should be the default `enum` size of the C ABI for that platform. Note that
1953-
enum representation in C is undefined, and this may be incorrect when the C
1954-
code is compiled with certain flags.
1955-
1956-
On `struct`s:
1957-
1958-
- `repr` - specifies the representation to use for this struct. Takes a list
1959-
of options. The currently accepted ones are `C` and `packed`, which may be
1960-
combined. `C` will use a C ABI comptible struct layout, and `packed` will
1961-
remove any padding between fields (note that this is very fragile and may
1962-
break platforms which require aligned access).
1963-
19641944
### Miscellaneous attributes
19651945

19661946
- `export_name` - on statics and functions, this determines the name of the
@@ -1978,6 +1958,12 @@ On `struct`s:
19781958
crate at compile-time and use any syntax extensions or lints that the crate
19791959
defines. They can both be specified, `#[phase(link, plugin)]` to use a crate
19801960
both at runtime and compiletime.
1961+
- `repr` - on C-like enums, this sets the underlying type used for
1962+
representation. Useful for FFI. Takes one argument, which is the primitive
1963+
type this enum should be represented for, or `C`, which specifies that it
1964+
should be the default `enum` size of the C ABI for that platform. Note that
1965+
enum representation in C is undefined, and this may be incorrect when the C
1966+
code is compiled with certain flags.
19811967
- `simd` - on certain tuple structs, derive the arithmetic operators, which
19821968
lower to the target's SIMD instructions, if any; the `simd` feature gate
19831969
is necessary to use this attribute.

branches/auto/src/libcore/mem.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ use ptr;
1919

2020
pub use intrinsics::transmute;
2121

22-
/// Moves a thing into the void.
23-
///
24-
/// The forget function will take ownership of the provided value but neglect
25-
/// to run any required cleanup or memory management operations on it.
26-
///
27-
/// This function is the unsafe version of the `drop` function because it does
28-
/// not run any destructors.
29-
#[stable]
30-
pub use intrinsics::forget;
31-
3222
/// Returns the size of a type in bytes.
3323
#[inline]
3424
#[stable]
@@ -347,6 +337,17 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
347337
#[stable]
348338
pub fn drop<T>(_x: T) { }
349339

340+
/// Moves a thing into the void.
341+
///
342+
/// The forget function will take ownership of the provided value but neglect
343+
/// to run any required cleanup or memory management operations on it.
344+
///
345+
/// This function is the unsafe version of the `drop` function because it does
346+
/// not run any destructors.
347+
#[inline]
348+
#[stable]
349+
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
350+
350351
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
351352
/// value.
352353
///

branches/auto/src/libcore/simd.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#[experimental]
4141
#[simd]
4242
#[deriving(Show)]
43-
#[repr(C)]
4443
pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4544
pub i8, pub i8, pub i8, pub i8,
4645
pub i8, pub i8, pub i8, pub i8,
@@ -49,26 +48,22 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4948
#[experimental]
5049
#[simd]
5150
#[deriving(Show)]
52-
#[repr(C)]
5351
pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
5452
pub i16, pub i16, pub i16, pub i16);
5553

5654
#[experimental]
5755
#[simd]
5856
#[deriving(Show)]
59-
#[repr(C)]
6057
pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
6158

6259
#[experimental]
6360
#[simd]
6461
#[deriving(Show)]
65-
#[repr(C)]
6662
pub struct i64x2(pub i64, pub i64);
6763

6864
#[experimental]
6965
#[simd]
7066
#[deriving(Show)]
71-
#[repr(C)]
7267
pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
7368
pub u8, pub u8, pub u8, pub u8,
7469
pub u8, pub u8, pub u8, pub u8,
@@ -77,30 +72,25 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
7772
#[experimental]
7873
#[simd]
7974
#[deriving(Show)]
80-
#[repr(C)]
8175
pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
8276
pub u16, pub u16, pub u16, pub u16);
8377

8478
#[experimental]
8579
#[simd]
8680
#[deriving(Show)]
87-
#[repr(C)]
8881
pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
8982

9083
#[experimental]
9184
#[simd]
9285
#[deriving(Show)]
93-
#[repr(C)]
9486
pub struct u64x2(pub u64, pub u64);
9587

9688
#[experimental]
9789
#[simd]
9890
#[deriving(Show)]
99-
#[repr(C)]
10091
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
10192

10293
#[experimental]
10394
#[simd]
10495
#[deriving(Show)]
105-
#[repr(C)]
10696
pub struct f64x2(pub f64, pub f64);

0 commit comments

Comments
 (0)