Skip to content

Commit 608fabf

Browse files
committed
---
yaml --- r: 190204 b: refs/heads/tmp c: fb0ee64 h: refs/heads/master v: v3
1 parent 90af3dd commit 608fabf

Some content is hidden

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

107 files changed

+561
-1482
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 49f7550a25722fbdb779eef80afa85f6d802f7e8
37+
refs/heads/tmp: fb0ee646e9be94a5031709073540e12139bcbda9
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3939
refs/tags/homu-tmp: d3c49d2140fc65e8bb7d7cf25bfe74dda6ce5ecf

branches/tmp/configure

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,8 @@ fi
760760
# Force bitrig to build with clang; gcc doesn't like us there
761761
if [ $CFG_OSTYPE = unknown-bitrig ]
762762
then
763-
step_msg "on Bitrig, forcing use of clang, disabling jemalloc"
763+
step_msg "on Bitrig, forcing use of clang"
764764
CFG_ENABLE_CLANG=1
765-
CFG_ENABLE_JEMALLOC=0
766765
fi
767766

768767
if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]

branches/tmp/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ifdef CFG_DISABLE_DEBUG
130130
CFG_RUSTC_FLAGS += --cfg ndebug
131131
else
132132
$(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
133-
CFG_RUSTC_FLAGS += --cfg debug -C debug-assertions=on
133+
CFG_RUSTC_FLAGS += --cfg debug
134134
endif
135135

136136
ifdef SAVE_TEMPS

branches/tmp/mk/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ TEST_SREQ$(1)_T_$(2)_H_$(3) = \
590590

591591
# The tests select when to use debug configuration on their own;
592592
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
593-
CTEST_RUSTC_FLAGS := $$(subst -C debug-assertions,,$$(subst -C debug-assertions=on,,$$(CFG_RUSTC_FLAGS)))
593+
CTEST_RUSTC_FLAGS := $$(subst -C debug-assertions,,$$(CFG_RUSTC_FLAGS))
594594

595595
# The tests cannot be optimized while the rest of the compiler is optimized, so
596596
# filter out the optimization (if any) from rustc and then figure out if we need

branches/tmp/src/doc/reference.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ cases mentioned in [Number literals](#number-literals) below.
229229

230230
##### Characters and strings
231231

232-
| | Example | # sets | Characters | Escapes |
233-
|----------------------------------------------|---------------|--------|-------------|---------------------|
234-
| [Character](#character-literals) | 'H' | N/A | All Unicode | \' & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) |
235-
| [String](#string-literals) | "hello" | N/A | All Unicode | \" & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) |
236-
| [Raw](#raw-string-literals) | r#"hello"# | 0... | All Unicode | N/A |
237-
| [Byte](#byte-literals) | b'H' | N/A | All ASCII | \' & [Byte](#byte-escapes) |
238-
| [Byte string](#byte-string-literals) | b"hello" | N/A | All ASCII | \" & [Byte](#byte-escapes) |
239-
| [Raw byte string](#raw-byte-string-literals) | br#"hello"# | 0... | All ASCII | N/A |
232+
| | Example | `#` sets | Characters | Escapes |
233+
|----------------------------------------------|-----------------|------------|-------------|---------------------|
234+
| [Character](#character-literals) | `'H'` | `N/A` | All Unicode | `\'` & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) |
235+
| [String](#string-literals) | `"hello"` | `N/A` | All Unicode | `\"` & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) |
236+
| [Raw](#raw-string-literals) | `r#"hello"#` | `0...` | All Unicode | `N/A` |
237+
| [Byte](#byte-literals) | `b'H'` | `N/A` | All ASCII | `\'` & [Byte](#byte-escapes) |
238+
| [Byte string](#byte-string-literals) | `b"hello"` | `N/A` | All ASCII | `\"` & [Byte](#byte-escapes) |
239+
| [Raw byte string](#raw-byte-string-literals) | `br#"hello"#` | `0...` | All ASCII | `N/A` |
240240

241241
##### Byte escapes
242242

branches/tmp/src/doc/trpl/comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The other kind of comment is a doc comment. Doc comments use `///` instead of
2828
///
2929
/// * `name` - The name of the person you'd like to greet.
3030
///
31-
/// # Examples
31+
/// # Example
3232
///
3333
/// ```rust
3434
/// let name = "Steve";

branches/tmp/src/doc/trpl/hello-cargo.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ Once you have this file in place, we should be ready to build! Try this:
7878
```bash
7979
$ cargo build
8080
Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world)
81-
$ ./target/debug/hello_world
81+
$ ./target/hello_world
8282
Hello, world!
8383
```
8484

8585
Bam! We build our project with `cargo build`, and run it with
86-
`./target/debug/hello_world`. This hasn't bought us a whole lot over our simple use
86+
`./target/hello_world`. This hasn't bought us a whole lot over our simple use
8787
of `rustc`, but think about the future: when our project has more than one
8888
file, we would need to call `rustc` more than once, and pass it a bunch of options to
8989
tell it to build everything together. With Cargo, as our project grows, we can
90-
just `cargo build` and it'll work the right way. When you're project is finally ready for release, you can use `cargo build --release` to compile your crates with optimizations.
90+
just `cargo build` and it'll work the right way.
9191

9292
You'll also notice that Cargo has created a new file: `Cargo.lock`.
9393

@@ -163,4 +163,4 @@ much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide
163163

164164
Now that you've got the tools down, let's actually learn more about the Rust
165165
language itself. These are the basics that will serve you well through the rest
166-
of your time with Rust.
166+
of your time with Rust.

branches/tmp/src/doc/trpl/installing-rust.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ rustc 1.0.0-nightly (f11f3e7ba 2015-01-04) (built 2015-01-06)
7878

7979
If you did, Rust has been installed successfully! Congrats!
8080

81-
This installer also installs a copy of the documentation locally, so you can
82-
read it offline. On UNIX systems, `/usr/local/share/doc/rust` is the location.
83-
On Windows, it's in a `share/doc` directory, inside wherever you installed Rust
84-
to.
85-
8681
If not, there are a number of places where you can get help. The easiest is
8782
[the #rust IRC channel on irc.mozilla.org](irc://irc.mozilla.org/#rust), which
8883
you can access through

branches/tmp/src/doc/trpl/static-and-dynamic-dispatch.md

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -102,87 +102,48 @@ reason.
102102
Rust provides dynamic dispatch through a feature called 'trait objects.' Trait
103103
objects, like `&Foo` or `Box<Foo>`, are normal values that store a value of
104104
*any* type that implements the given trait, where the precise type can only be
105-
known at runtime.
106-
107-
A trait object can be obtained from a pointer to a concrete type that
108-
implements the trait by *casting* it (e.g. `&x as &Foo`) or *coercing* it
109-
(e.g. using `&x` as an argument to a function that takes `&Foo`).
110-
111-
These trait object coercions and casts also work for pointers like `&mut T` to
112-
`&mut Foo` and `Box<T>` to `Box<Foo>`, but that's all at the moment. Coercions
113-
and casts are identical.
114-
115-
This operation can be seen as "erasing" the compiler's knowledge about the
116-
specific type of the pointer, and hence trait objects are sometimes referred to
117-
as "type erasure".
118-
119-
Coming back to the example above, we can use the same trait to perform dynamic
120-
dispatch with trait objects by casting:
121-
122-
```rust
123-
# trait Foo { fn method(&self) -> String; }
124-
# impl Foo for u8 { fn method(&self) -> String { format!("u8: {}", *self) } }
125-
# impl Foo for String { fn method(&self) -> String { format!("string: {}", *self) } }
126-
127-
fn do_something(x: &Foo) {
128-
x.method();
129-
}
130-
131-
fn main() {
132-
let x = 5u8;
133-
do_something(&x as &Foo);
134-
}
135-
```
136-
137-
or by coercing:
138-
139-
```rust
140-
# trait Foo { fn method(&self) -> String; }
141-
# impl Foo for u8 { fn method(&self) -> String { format!("u8: {}", *self) } }
142-
# impl Foo for String { fn method(&self) -> String { format!("string: {}", *self) } }
143-
144-
fn do_something(x: &Foo) {
145-
x.method();
146-
}
147-
148-
fn main() {
149-
let x = "Hello".to_string();
150-
do_something(&x);
151-
}
152-
```
105+
known at runtime. The methods of the trait can be called on a trait object via
106+
a special record of function pointers (created and managed by the compiler).
153107

154108
A function that takes a trait object is not specialized to each of the types
155109
that implements `Foo`: only one copy is generated, often (but not always)
156110
resulting in less code bloat. However, this comes at the cost of requiring
157111
slower virtual function calls, and effectively inhibiting any chance of
158112
inlining and related optimisations from occurring.
159113

160-
### Why pointers?
114+
Trait objects are both simple and complicated: their core representation and
115+
layout is quite straight-forward, but there are some curly error messages and
116+
surprising behaviors to discover.
161117

162-
Rust does not put things behind a pointer by default, unlike many managed
163-
languages, so types can have different sizes. Knowing the size of the value at
164-
compile time is important for things like passing it as an argument to a
165-
function, moving it about on the stack and allocating (and deallocating) space
166-
on the heap to store it.
118+
### Obtaining a trait object
167119

168-
For `Foo`, we would need to have a value that could be at least either a
169-
`String` (24 bytes) or a `u8` (1 byte), as well as any other type for which
170-
dependent crates may implement `Foo` (any number of bytes at all). There's no
171-
way to guarantee that this last point can work if the values are stored without
172-
a pointer, because those other types can be arbitrarily large.
120+
There's two similar ways to get a trait object value: casts and coercions. If
121+
`T` is a type that implements a trait `Foo` (e.g. `u8` for the `Foo` above),
122+
then the two ways to get a `Foo` trait object out of a pointer to `T` look
123+
like:
173124

174-
Putting the value behind a pointer means the size of the value is not relevant
175-
when we are tossing a trait object around, only the size of the pointer itself.
125+
```{rust,ignore}
126+
let ref_to_t: &T = ...;
176127
177-
### Representation
128+
// `as` keyword for casting
129+
let cast = ref_to_t as &Foo;
178130
179-
The methods of the trait can be called on a trait object via a special record
180-
of function pointers traditionally called a 'vtable' (created and managed by
181-
the compiler).
131+
// using a `&T` in a place that has a known type of `&Foo` will implicitly coerce:
132+
let coerce: &Foo = ref_to_t;
182133
183-
Trait objects are both simple and complicated: their core representation and
184-
layout is quite straight-forward, but there are some curly error messages and
185-
surprising behaviors to discover.
134+
fn also_coerce(_unused: &Foo) {}
135+
also_coerce(ref_to_t);
136+
```
137+
138+
These trait object coercions and casts also work for pointers like `&mut T` to
139+
`&mut Foo` and `Box<T>` to `Box<Foo>`, but that's all at the moment. Coercions
140+
and casts are identical.
141+
142+
This operation can be seen as "erasing" the compiler's knowledge about the
143+
specific type of the pointer, and hence trait objects are sometimes referred to
144+
as "type erasure".
145+
146+
### Representation
186147

187148
Let's start simple, with the runtime representation of a trait object. The
188149
`std::raw` module contains structs with layouts that are the same as the
@@ -304,3 +265,23 @@ let y = TraitObject {
304265
If `b` or `y` were owning trait objects (`Box<Foo>`), there would be a
305266
`(b.vtable.destructor)(b.data)` (respectively `y`) call when they went out of
306267
scope.
268+
269+
### Why pointers?
270+
271+
The use of language like "fat pointer" implies that a trait object is
272+
always a pointer of some form, but why?
273+
274+
Rust does not put things behind a pointer by default, unlike many managed
275+
languages, so types can have different sizes. Knowing the size of the value at
276+
compile time is important for things like passing it as an argument to a
277+
function, moving it about on the stack and allocating (and deallocating) space
278+
on the heap to store it.
279+
280+
For `Foo`, we would need to have a value that could be at least either a
281+
`String` (24 bytes) or a `u8` (1 byte), as well as any other type for which
282+
dependent crates may implement `Foo` (any number of bytes at all). There's no
283+
way to guarantee that this last point can work if the values are stored without
284+
a pointer, because those other types can be arbitrarily large.
285+
286+
Putting the value behind a pointer means the size of the value is not relevant
287+
when we are tossing a trait object around, only the size of the pointer itself.

branches/tmp/src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use heap::deallocate;
8888

8989
/// An atomically reference counted wrapper for shared state.
9090
///
91-
/// # Examples
91+
/// # Example
9292
///
9393
/// In this example, a large vector of floats is shared between several tasks.
9494
/// With simple pipes, without `Arc`, a copy would have to be made for each

branches/tmp/src/liballoc/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<T : ?Sized> Box<T> {
133133
/// automatically managed that may lead to memory or other resource
134134
/// leak.
135135
///
136-
/// # Examples
136+
/// # Example
137137
/// ```
138138
/// use std::boxed;
139139
///

branches/tmp/src/liballoc/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn is_unique<T>(rc: &Rc<T>) -> bool {
264264
///
265265
/// If the `Rc<T>` is not unique, an `Err` is returned with the same `Rc<T>`.
266266
///
267-
/// # Examples
267+
/// # Example
268268
///
269269
/// ```
270270
/// use std::rc::{self, Rc};
@@ -298,7 +298,7 @@ pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
298298
///
299299
/// Returns `None` if the `Rc<T>` is not unique.
300300
///
301-
/// # Examples
301+
/// # Example
302302
///
303303
/// ```
304304
/// use std::rc::{self, Rc};

branches/tmp/src/libcollections/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<T> ToOwned for T where T: Clone {
127127
/// is desired, `to_mut` will obtain a mutable references to an owned
128128
/// value, cloning if necessary.
129129
///
130-
/// # Examples
130+
/// # Example
131131
///
132132
/// ```rust
133133
/// use std::borrow::Cow;

branches/tmp/src/libcollections/btree/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
11771177
impl<K, V> BTreeMap<K, V> {
11781178
/// Gets an iterator over the entries of the map.
11791179
///
1180-
/// # Examples
1180+
/// # Example
11811181
///
11821182
/// ```
11831183
/// use std::collections::BTreeMap;

branches/tmp/src/libcollections/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ use string;
420420
///
421421
/// * args - a structure of arguments generated via the `format_args!` macro.
422422
///
423-
/// # Examples
423+
/// # Example
424424
///
425425
/// ```rust
426426
/// use std::fmt;

branches/tmp/src/libcollections/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ macro_rules! vec {
4848
/// Use the syntax described in `std::fmt` to create a value of type `String`.
4949
/// See `std::fmt` for more information.
5050
///
51-
/// # Examples
51+
/// # Example
5252
///
5353
/// ```
5454
/// format!("test");

0 commit comments

Comments
 (0)