Skip to content

Commit

Permalink
Auto merge of rust-lang#28258 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
- Successful merges: rust-lang#28225, rust-lang#28231, rust-lang#28234, rust-lang#28253
- Failed merges:
  • Loading branch information
bors committed Sep 5, 2015
2 parents 6b36e92 + 1bf060f commit 5c2cfdf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/doc/trpl/method-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ can be awkward. Consider this code:
baz(bar(foo));
```

We would read this left-to right, and so we see ‘baz bar foo’. But this isn’t the
We would read this left-to-right, and so we see ‘baz bar foo’. But this isn’t the
order that the functions would get called in, that’s inside-out: ‘foo bar baz’.
Wouldn’t it be nice if we could do this instead?

Expand Down Expand Up @@ -45,17 +45,17 @@ This will print `12.566371`.



We’ve made a struct that represents a circle. We then write an `impl` block,
We’ve made a `struct` that represents a circle. We then write an `impl` block,
and inside it, define a method, `area`.

Methods take a special first parameter, of which there are three variants:
Methods take a special first parameter, of which there are three variants:
`self`, `&self`, and `&mut self`. You can think of this first parameter as
being the `foo` in `foo.bar()`. The three variants correspond to the three
kinds of things `foo` could be: `self` if it’s just a value on the stack,
`&self` if it’s a reference, and `&mut self` if it’s a mutable reference.
Because we took the `&self` parameter to `area`, we can use it just like any
other parameter. Because we know it’s a `Circle`, we can access the `radius`
just like we would with any other struct.
just like we would with any other `struct`.

We should default to using `&self`, as you should prefer borrowing over taking
ownership, as well as taking immutable references over mutable ones. Here’s an
Expand Down Expand Up @@ -120,12 +120,12 @@ Check the return type:
```rust
# struct Circle;
# impl Circle {
fn grow(&self) -> Circle {
fn grow(&self, increment: f64) -> Circle {
# Circle } }
```

We just say we’re returning a `Circle`. With this method, we can grow a new
circle to any arbitrary size.
`Circle` to any arbitrary size.

# Associated functions

Expand Down Expand Up @@ -161,7 +161,7 @@ methods’.

# Builder Pattern

Let’s say that we want our users to be able to create Circles, but we will
Let’s say that we want our users to be able to create `Circle`s, but we will
allow them to only set the properties they care about. Otherwise, the `x`
and `y` attributes will be `0.0`, and the `radius` will be `1.0`. Rust doesn’t
have method overloading, named arguments, or variable arguments. We employ
Expand Down Expand Up @@ -224,7 +224,7 @@ fn main() {
}
```

What we’ve done here is make another struct, `CircleBuilder`. We’ve defined our
What we’ve done here is make another `struct`, `CircleBuilder`. We’ve defined our
builder methods on it. We’ve also defined our `area()` method on `Circle`. We
also made one more method on `CircleBuilder`: `finalize()`. This method creates
our final `Circle` from the builder. Now, we’ve used the type system to enforce
Expand Down
20 changes: 16 additions & 4 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ E0002: r##"
This error indicates that an empty match expression is invalid because the type
it is matching on is non-empty (there exist values of this type). In safe code
it is impossible to create an instance of an empty type, so empty match
expressions are almost never desired. This error is typically fixed by adding
expressions are almost never desired. This error is typically fixed by adding
one or more cases to the match expression.
An example of an empty type is `enum Empty { }`. So, the following will work:
Expand Down Expand Up @@ -218,7 +218,14 @@ match x {
E0010: r##"
The value of statics and constants must be known at compile time, and they live
for the entire lifetime of a program. Creating a boxed value allocates memory on
the heap at runtime, and therefore cannot be done at compile time.
the heap at runtime, and therefore cannot be done at compile time. Erroneous
code example:
```
#![feature(box_syntax)]
const CON : Box<i32> = box 0;
```
"##,

E0011: r##"
Expand Down Expand Up @@ -335,7 +342,6 @@ is not allowed.
If you really want global mutable state, try using `static mut` or a global
`UnsafeCell`.
"##,

E0018: r##"
Expand Down Expand Up @@ -399,7 +405,13 @@ fn main() {

E0020: r##"
This error indicates that an attempt was made to divide by zero (or take the
remainder of a zero divisor) in a static or constant expression.
remainder of a zero divisor) in a static or constant expression. Erroneous
code example:
```
const X: i32 = 42 / 0;
// error: attempted to divide by zero in a constant expression
```
"##,

E0022: r##"
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
span_err!(cx.tcx.sess, ex.span, E0002,
"non-exhaustive patterns: type {} is non-empty",
pat_ty);
span_help!(cx.tcx.sess, ex.span,
"Please ensure that all possible cases are being handled; \
possibly adding wildcards or more match arms.");
}
// If the type *is* empty, it's vacuously exhaustive
return;
Expand Down
19 changes: 18 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,24 @@ struct Bar<S, T> { x: Foo<S, T> }
```
"##,

//NB: not currently reachable
E0247: r##"
This error indicates an attempt to use a module name where a type is expected.
For example:
```
mod MyMod {
mod MySubMod { }
}
fn do_something(x: MyMod::MySubMod) { }
```
In this example, we're attempting to take a parameter of type `MyMod::MySubMod`
in the do_something function. This is not legal: `MyMod::MySubMod` is a module
name, not a type.
"##,

E0248: r##"
This error indicates an attempt to use a value where a type is expected. For
example:
Expand Down Expand Up @@ -3291,7 +3309,6 @@ register_diagnostics! {
E0242, // internal error looking up a definition
E0245, // not a trait
// E0246, // invalid recursive type
E0247, // found module name used as a type
// E0319, // trait impls for defaulted traits allowed just for structs/enums
E0320, // recursive overflow during dropck
E0321, // extended coherence rules for defaulted traits violated
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
//! `Some` and `None`.
//! * `std::result::Result::`{
//! [`self`](../result/enum.Result.html),
//! [`Some`](../result/enum.Result.html),
//! [`None`](../result/enum.Result.html)
//! [`Ok`](../result/enum.Result.html),
//! [`Err`](../result/enum.Result.html)
//! }.
//! The ubiquitous `Result` type and its two [variants][book-enums],
//! `Ok` and `Err`.
Expand Down

0 comments on commit 5c2cfdf

Please sign in to comment.