Skip to content

Commit 89d71af

Browse files
committed
---
yaml --- r: 217053 b: refs/heads/stable c: a96f09b h: refs/heads/master i: 217051: 6d396c7 v: v3
1 parent 292f811 commit 89d71af

File tree

16 files changed

+334
-41
lines changed

16 files changed

+334
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: f6e5369e53f5444240aa983c6e6be6725932e399
32+
refs/heads/stable: a96f09bf52b169e1ddcb7edf4e7bdd257da3725d
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/src/doc/reference.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,8 @@ vtable when the trait is used as a [trait object](#trait-objects).
13461346
Traits are implemented for specific types through separate
13471347
[implementations](#implementations).
13481348

1349+
Consider the following trait:
1350+
13491351
```
13501352
# type Surface = i32;
13511353
# type BoundingBox = i32;
@@ -1360,6 +1362,20 @@ This defines a trait with two methods. All values that have
13601362
`draw` and `bounding_box` methods called, using `value.bounding_box()`
13611363
[syntax](#method-call-expressions).
13621364

1365+
Traits can include default implementations of methods, as in:
1366+
1367+
```
1368+
trait Foo {
1369+
fn bar(&self);
1370+
1371+
fn baz(&self) { println!("We called baz."); }
1372+
}
1373+
```
1374+
1375+
Here the `baz` method has a default implementation, so types that implement
1376+
`Foo` need only implement `bar`. It is also possible for implementing types
1377+
to override a method that has a default implementation.
1378+
13631379
Type parameters can be specified for a trait to make it generic. These appear
13641380
after the trait name, using the same syntax used in [generic
13651381
functions](#generic-functions).
@@ -1372,6 +1388,30 @@ trait Seq<T> {
13721388
}
13731389
```
13741390

1391+
It is also possible to define associated types for a trait. Consider the
1392+
following example of a `Container` trait. Notice how the type is available
1393+
for use in the method signatures:
1394+
1395+
```
1396+
trait Container {
1397+
type E;
1398+
fn empty() -> Self;
1399+
fn insert(&mut self, Self::E);
1400+
}
1401+
```
1402+
1403+
In order for a type to implement this trait, it must not only provide
1404+
implementations for every method, but it must specify the type `E`. Here's
1405+
an implementation of `Container` for the standard library type `Vec`:
1406+
1407+
```
1408+
impl<T> Container for Vec<T> {
1409+
type E = T;
1410+
fn empty() -> Vec<T> { Vec::new() }
1411+
fn insert(&mut self, x: T) { self.push(x); }
1412+
}
1413+
```
1414+
13751415
Generic functions may use traits as _bounds_ on their type parameters. This
13761416
will have two effects: only types that have the trait may instantiate the
13771417
parameter, and within the generic function, the methods of the trait can be
@@ -3470,13 +3510,21 @@ more of the closure traits:
34703510

34713511
### Trait objects
34723512

3473-
Every trait item (see [traits](#traits)) defines a type with the same name as
3474-
the trait. This type is called the _trait object_ of the trait. Trait objects
3475-
permit "late binding" of methods, dispatched using _virtual method tables_
3476-
("vtables"). Whereas most calls to trait methods are "early bound" (statically
3477-
resolved) to specific implementations at compile time, a call to a method on an
3478-
trait objects is only resolved to a vtable entry at compile time. The actual
3479-
implementation for each vtable entry can vary on an object-by-object basis.
3513+
In Rust, a type like `&SomeTrait` or `Box<SomeTrait>` is called a _trait object_.
3514+
Each instance of a trait object includes:
3515+
3516+
- a pointer to an instance of a type `T` that implements `SomeTrait`
3517+
- a _virtual method table_, often just called a _vtable_, which contains, for
3518+
each method of `SomeTrait` that `T` implements, a pointer to `T`'s
3519+
implementation (i.e. a function pointer).
3520+
3521+
The purpose of trait objects is to permit "late binding" of methods. A call to
3522+
a method on a trait object is only resolved to a vtable entry at compile time.
3523+
The actual implementation for each vtable entry can vary on an object-by-object
3524+
basis.
3525+
3526+
Note that for a trait object to be instantiated, the trait must be
3527+
_object-safe_. Object safety rules are defined in [RFC 255][rfc255].
34803528

34813529
Given a pointer-typed expression `E` of type `&T` or `Box<T>`, where `T`
34823530
implements trait `R`, casting `E` to the corresponding pointer type `&R` or

branches/stable/src/doc/trpl/dining-philosophers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ which blocks execution until the thread has completed execution. This ensures
450450
that the threads complete their work before the program exits.
451451

452452
If you run this program, you’ll see that the philosophers eat out of order!
453-
We have mult-threading!
453+
We have multi-threading!
454454

455455
```text
456456
Gilles Deleuze is eating.

branches/stable/src/libcollections/vec.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,41 @@
1818
//! You can explicitly create a `Vec<T>` with `new()`:
1919
//!
2020
//! ```
21-
//! let xs: Vec<i32> = Vec::new();
21+
//! let v: Vec<i32> = Vec::new();
2222
//! ```
2323
//!
2424
//! ...or by using the `vec!` macro:
2525
//!
2626
//! ```
27-
//! let ys: Vec<i32> = vec![];
27+
//! let v: Vec<i32> = vec![];
2828
//!
29-
//! let zs = vec![1i32, 2, 3, 4, 5];
29+
//! let v = vec![1, 2, 3, 4, 5];
30+
//!
31+
//! let v = vec![0; 10]; // ten zeroes
3032
//! ```
3133
//!
3234
//! You can `push` values onto the end of a vector (which will grow the vector as needed):
3335
//!
3436
//! ```
35-
//! let mut xs = vec![1i32, 2];
37+
//! let mut v = vec![1, 2];
3638
//!
37-
//! xs.push(3);
39+
//! v.push(3);
3840
//! ```
3941
//!
4042
//! Popping values works in much the same way:
4143
//!
4244
//! ```
43-
//! let mut xs = vec![1i32, 2];
45+
//! let mut v = vec![1, 2];
4446
//!
45-
//! let two = xs.pop();
47+
//! let two = v.pop();
4648
//! ```
4749
//!
4850
//! Vectors also support indexing (through the `Index` and `IndexMut` traits):
4951
//!
5052
//! ```
51-
//! let mut xs = vec![1i32, 2, 3];
52-
//! let three = xs[2];
53-
//! xs[1] = xs[1] + 5;
53+
//! let mut v = vec![1, 2, 3];
54+
//! let three = v[2];
55+
//! v[1] = v[1] + 5;
5456
//! ```
5557
5658
#![stable(feature = "rust1", since = "1.0.0")]

branches/stable/src/libcore/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ macro_rules! try {
167167
})
168168
}
169169

170-
/// Use the `format!` syntax to write data into a buffer of type `&mut Writer`.
170+
/// Use the `format!` syntax to write data into a buffer of type `&mut Write`.
171171
/// See `std::fmt` for more information.
172172
///
173173
/// # Examples

branches/stable/src/librustc/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ be taken.
427427

428428
E0271: r##"
429429
This is because of a type mismatch between the associated type of some
430-
trait (e.g. T::Bar, where T implements trait Quux { type Bar; })
431-
and another type U that is required to be equal to T::Bar, but is not.
430+
trait (e.g. `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
431+
and another type `U` that is required to be equal to `T::Bar`, but is not.
432432
Examples follow.
433433
434434
Here is a basic example:

branches/stable/src/librustc/middle/infer/freshen.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
129129
.probe(v)
130130
.map(|v| v.to_type(tcx)),
131131
ty::FloatVar(v),
132-
ty::FreshIntTy)
132+
ty::FreshFloatTy)
133133
}
134134

135135
ty::ty_infer(ty::FreshTy(c)) |
136-
ty::ty_infer(ty::FreshIntTy(c)) => {
136+
ty::ty_infer(ty::FreshIntTy(c)) |
137+
ty::ty_infer(ty::FreshFloatTy(c)) => {
137138
if c >= self.freshen_count {
138139
tcx.sess.bug(
139140
&format!("Encountered a freshend type with id {} \

branches/stable/src/librustc/middle/traits/select.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17731773
ty::ty_err => ok_if(Vec::new()),
17741774

17751775
ty::ty_infer(ty::FreshTy(_))
1776-
| ty::ty_infer(ty::FreshIntTy(_)) => {
1776+
| ty::ty_infer(ty::FreshIntTy(_))
1777+
| ty::ty_infer(ty::FreshFloatTy(_)) => {
17771778
self.tcx().sess.bug(
17781779
&format!(
17791780
"asked to assemble builtin bounds of unexpected type: {}",
@@ -1835,7 +1836,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18351836
ty::ty_projection(..) |
18361837
ty::ty_infer(ty::TyVar(_)) |
18371838
ty::ty_infer(ty::FreshTy(_)) |
1838-
ty::ty_infer(ty::FreshIntTy(_)) => {
1839+
ty::ty_infer(ty::FreshIntTy(_)) |
1840+
ty::ty_infer(ty::FreshFloatTy(_)) => {
18391841
self.tcx().sess.bug(
18401842
&format!(
18411843
"asked to assemble constituent types of unexpected type: {}",

branches/stable/src/librustc/middle/ty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,11 +1697,8 @@ pub enum InferTy {
16971697
/// unbound type variable. This is convenient for caching etc. See
16981698
/// `middle::infer::freshen` for more details.
16991699
FreshTy(u32),
1700-
1701-
// FIXME -- once integral fallback is impl'd, we should remove
1702-
// this type. It's only needed to prevent spurious errors for
1703-
// integers whose type winds up never being constrained.
17041700
FreshIntTy(u32),
1701+
FreshFloatTy(u32)
17051702
}
17061703

17071704
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -1773,6 +1770,7 @@ impl fmt::Debug for InferTy {
17731770
FloatVar(ref v) => v.fmt(f),
17741771
FreshTy(v) => write!(f, "FreshTy({:?})", v),
17751772
FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
1773+
FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
17761774
}
17771775
}
17781776
}
@@ -3775,7 +3773,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37753773
}
37763774

37773775
// Scalar and unique types are sendable, and durable
3778-
ty_infer(ty::FreshIntTy(_)) |
3776+
ty_infer(ty::FreshIntTy(_)) | ty_infer(ty::FreshFloatTy(_)) |
37793777
ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
37803778
ty_bare_fn(..) | ty::ty_char => {
37813779
TC::None
@@ -4325,6 +4323,7 @@ pub fn type_is_fresh(ty: Ty) -> bool {
43254323
match ty.sty {
43264324
ty_infer(FreshTy(_)) => true,
43274325
ty_infer(FreshIntTy(_)) => true,
4326+
ty_infer(FreshFloatTy(_)) => true,
43284327
_ => false
43294328
}
43304329
}
@@ -5026,6 +5025,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
50265025
ty_infer(FloatVar(_)) => "floating-point variable".to_string(),
50275026
ty_infer(FreshTy(_)) => "skolemized type".to_string(),
50285027
ty_infer(FreshIntTy(_)) => "skolemized integral type".to_string(),
5028+
ty_infer(FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
50295029
ty_projection(_) => "associated type".to_string(),
50305030
ty_param(ref p) => {
50315031
if p.space == subst::SelfSpace {

branches/stable/src/librustc/middle/ty_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
6767

6868
match (&a.sty, &b.sty) {
6969
(_, &ty::ty_infer(ty::FreshTy(_))) |
70-
(_, &ty::ty_infer(ty::FreshIntTy(_))) => {
70+
(_, &ty::ty_infer(ty::FreshIntTy(_))) |
71+
(_, &ty::ty_infer(ty::FreshFloatTy(_))) => {
7172
Ok(a)
7273
}
7374

branches/stable/src/librustc/util/ppaux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
349349
ty::FloatVar(ref vid) if print_var_ids => vid.repr(cx),
350350
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => format!("_"),
351351
ty::FreshTy(v) => format!("FreshTy({})", v),
352-
ty::FreshIntTy(v) => format!("FreshIntTy({})", v)
352+
ty::FreshIntTy(v) => format!("FreshIntTy({})", v),
353+
ty::FreshFloatTy(v) => format!("FreshFloatTy({})", v)
353354
}
354355
}
355356

branches/stable/src/librustc_resolve/diagnostics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Imports (`use` statements) are not allowed after non-item statements, such as
2020
variable declarations and expression statements.
2121
2222
Here is an example that demonstrates the error:
23+
2324
```
2425
fn f() {
2526
// Variable declaration before import
@@ -33,6 +34,7 @@ The solution is to declare the imports at the top of the block, function, or
3334
file.
3435
3536
Here is the previous example again, with the correct order:
37+
3638
```
3739
fn f() {
3840
use std::io::Read;
@@ -52,6 +54,7 @@ The name chosen for an external crate conflicts with another external crate that
5254
has been imported into the current module.
5355
5456
Wrong example:
57+
5558
```
5659
extern crate a;
5760
extern crate crate_a as a;
@@ -61,6 +64,7 @@ The solution is to choose a different name that doesn't conflict with any
6164
external crate imported into the current module.
6265
6366
Correct example:
67+
6468
```
6569
extern crate a;
6670
extern crate crate_a as other_name;
@@ -71,6 +75,7 @@ E0260: r##"
7175
The name for an item declaration conflicts with an external crate's name.
7276
7377
For instance,
78+
7479
```
7580
extern crate abc;
7681

0 commit comments

Comments
 (0)