Skip to content

Commit 5c2cfdf

Browse files
committed
Auto merge of #28258 - Manishearth:rollup, r=Manishearth
- Successful merges: #28225, #28231, #28234, #28253 - Failed merges:
2 parents 6b36e92 + 1bf060f commit 5c2cfdf

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

src/doc/trpl/method-syntax.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ can be awkward. Consider this code:
77
baz(bar(foo));
88
```
99

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

@@ -45,17 +45,17 @@ This will print `12.566371`.
4545

4646

4747

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

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

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

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

130130
# Associated functions
131131

@@ -161,7 +161,7 @@ methods’.
161161

162162
# Builder Pattern
163163

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

227-
What we’ve done here is make another struct, `CircleBuilder`. We’ve defined our
227+
What we’ve done here is make another `struct`, `CircleBuilder`. We’ve defined our
228228
builder methods on it. We’ve also defined our `area()` method on `Circle`. We
229229
also made one more method on `CircleBuilder`: `finalize()`. This method creates
230230
our final `Circle` from the builder. Now, we’ve used the type system to enforce

src/librustc/diagnostics.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ E0002: r##"
4444
This error indicates that an empty match expression is invalid because the type
4545
it is matching on is non-empty (there exist values of this type). In safe code
4646
it is impossible to create an instance of an empty type, so empty match
47-
expressions are almost never desired. This error is typically fixed by adding
47+
expressions are almost never desired. This error is typically fixed by adding
4848
one or more cases to the match expression.
4949
5050
An example of an empty type is `enum Empty { }`. So, the following will work:
@@ -218,7 +218,14 @@ match x {
218218
E0010: r##"
219219
The value of statics and constants must be known at compile time, and they live
220220
for the entire lifetime of a program. Creating a boxed value allocates memory on
221-
the heap at runtime, and therefore cannot be done at compile time.
221+
the heap at runtime, and therefore cannot be done at compile time. Erroneous
222+
code example:
223+
224+
```
225+
#![feature(box_syntax)]
226+
227+
const CON : Box<i32> = box 0;
228+
```
222229
"##,
223230

224231
E0011: r##"
@@ -335,7 +342,6 @@ is not allowed.
335342
336343
If you really want global mutable state, try using `static mut` or a global
337344
`UnsafeCell`.
338-
339345
"##,
340346

341347
E0018: r##"
@@ -399,7 +405,13 @@ fn main() {
399405

400406
E0020: r##"
401407
This error indicates that an attempt was made to divide by zero (or take the
402-
remainder of a zero divisor) in a static or constant expression.
408+
remainder of a zero divisor) in a static or constant expression. Erroneous
409+
code example:
410+
411+
```
412+
const X: i32 = 42 / 0;
413+
// error: attempted to divide by zero in a constant expression
414+
```
403415
"##,
404416

405417
E0022: r##"

src/librustc/middle/check_match.rs

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
218218
span_err!(cx.tcx.sess, ex.span, E0002,
219219
"non-exhaustive patterns: type {} is non-empty",
220220
pat_ty);
221+
span_help!(cx.tcx.sess, ex.span,
222+
"Please ensure that all possible cases are being handled; \
223+
possibly adding wildcards or more match arms.");
221224
}
222225
// If the type *is* empty, it's vacuously exhaustive
223226
return;

src/librustc_typeck/diagnostics.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,24 @@ struct Bar<S, T> { x: Foo<S, T> }
24752475
```
24762476
"##,
24772477

2478+
//NB: not currently reachable
2479+
E0247: r##"
2480+
This error indicates an attempt to use a module name where a type is expected.
2481+
For example:
2482+
2483+
```
2484+
mod MyMod {
2485+
mod MySubMod { }
2486+
}
2487+
2488+
fn do_something(x: MyMod::MySubMod) { }
2489+
```
2490+
2491+
In this example, we're attempting to take a parameter of type `MyMod::MySubMod`
2492+
in the do_something function. This is not legal: `MyMod::MySubMod` is a module
2493+
name, not a type.
2494+
"##,
2495+
24782496
E0248: r##"
24792497
This error indicates an attempt to use a value where a type is expected. For
24802498
example:
@@ -3291,7 +3309,6 @@ register_diagnostics! {
32913309
E0242, // internal error looking up a definition
32923310
E0245, // not a trait
32933311
// E0246, // invalid recursive type
3294-
E0247, // found module name used as a type
32953312
// E0319, // trait impls for defaulted traits allowed just for structs/enums
32963313
E0320, // recursive overflow during dropck
32973314
E0321, // extended coherence rules for defaulted traits violated

src/libstd/prelude/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
//! `Some` and `None`.
104104
//! * `std::result::Result::`{
105105
//! [`self`](../result/enum.Result.html),
106-
//! [`Some`](../result/enum.Result.html),
107-
//! [`None`](../result/enum.Result.html)
106+
//! [`Ok`](../result/enum.Result.html),
107+
//! [`Err`](../result/enum.Result.html)
108108
//! }.
109109
//! The ubiquitous `Result` type and its two [variants][book-enums],
110110
//! `Ok` and `Err`.

0 commit comments

Comments
 (0)