Skip to content

Commit 837840c

Browse files
committed
Auto merge of #28516 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28400, #28430, #28443, #28483, #28485, #28496, #28511, #28515 - Failed merges:
2 parents 6db1a0e + 234f81c commit 837840c

File tree

16 files changed

+192
-83
lines changed

16 files changed

+192
-83
lines changed

COMPILER_TESTS.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Compiler Test Documentation
22

3-
In the Rust project, we use a special set of comands imbedded in
3+
In the Rust project, we use a special set of comands embedded in
44
comments to test the Rust compiler. There are two groups of commands:
55

66
1. Header commands
@@ -29,11 +29,11 @@ The error levels that you can have are:
2929
3. `NOTE`
3030
4. `HELP` and `SUGGESTION`*
3131

32-
\* **Note**: `SUGGESTION` must follow emediatly after `HELP`.
32+
\* **Note**: `SUGGESTION` must follow immediately after `HELP`.
3333

3434
## Summary of Header Commands
3535

36-
Header commands specify something about the entire test file, as a
36+
Header commands specify something about the entire test file as a
3737
whole, instead of just a few lines inside the test.
3838

3939
* `ignore-X` where `X` is an architecture, OS or stage will ignore the test accordingly

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#
2727
# * check - Run the complete test suite
2828
#
29-
# * clean - Clean the build repertory. It is advised to run this
29+
# * clean - Clean the build repository. It is advised to run this
3030
# command if you want to build Rust again, after an update
3131
# of the git repository.
3232
#

src/doc/trpl/error-handling.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ systems may want to jump around.
2828
* [The `Result` type](#the-result-type)
2929
* [Parsing integers](#parsing-integers)
3030
* [The `Result` type alias idiom](#the-result-type-alias-idiom)
31-
* [A brief interlude: unwrapping isn't evil](#a-brief-interlude-unwrapping-isnt-evil)
31+
* [A brief interlude: unwrapping isn't evil](#a-brief-interlude:-unwrapping-isn't-evil)
3232
* [Working with multiple error types](#working-with-multiple-error-types)
3333
* [Composing `Option` and `Result`](#composing-option-and-result)
3434
* [The limits of combinators](#the-limits-of-combinators)
@@ -41,11 +41,11 @@ systems may want to jump around.
4141
* [The real `try!` macro](#the-real-try!-macro)
4242
* [Composing custom error types](#composing-custom-error-types)
4343
* [Advice for library writers](#advice-for-library-writers)
44-
* [Case study: A program to read population data](#case-study-a-program-to-read-population-data)
44+
* [Case study: A program to read population data](#case-study:-a-program-to-read-population-data)
4545
* [Initial setup](#initial-setup)
4646
* [Argument parsing](#argument-parsing)
4747
* [Writing the logic](#writing-the-logic)
48-
* [Error handling with `Box<Error>`](#error-handling-with-box<error>)
48+
* [Error handling with `Box<Error>`](#error-handling-with-box%3Cerror%3E)
4949
* [Reading from stdin](#reading-from-stdin)
5050
* [Error handling with a custom type](#error-handling-with-a-custom-type)
5151
* [Adding functionality](#adding-functionality)
@@ -87,9 +87,9 @@ thread '<main>' panicked at 'Invalid number: 11', src/bin/panic-simple.rs:5
8787
Here's another example that is slightly less contrived. A program that accepts
8888
an integer as an argument, doubles it and prints it.
8989

90-
<div id="code-unwrap-double">
91-
```rust,should_panic
90+
<a name="code-unwrap-double"></a>
9291

92+
```rust,should_panic
9393
use std::env;
9494
9595
fn main() {
@@ -99,7 +99,6 @@ fn main() {
9999
println!("{}", 2 * n);
100100
}
101101
```
102-
</div>
103102

104103
If you give this program zero arguments (error 1) or if the first argument
105104
isn't an integer (error 2), the program will panic just like in the first
@@ -140,7 +139,8 @@ system is an important concept because it will cause the compiler to force the
140139
programmer to handle that absence. Let's take a look at an example that tries
141140
to find a character in a string:
142141

143-
<div id="code-option-ex-string-find">
142+
<a name="code-option-ex-string-find"></a>
143+
144144
```rust
145145
// Searches `haystack` for the Unicode character `needle`. If one is found, the
146146
// byte offset of the character is returned. Otherwise, `None` is returned.
@@ -153,7 +153,6 @@ fn find(haystack: &str, needle: char) -> Option<usize> {
153153
None
154154
}
155155
```
156-
</div>
157156

158157
Notice that when this function finds a matching character, it doen't just
159158
return the `offset`. Instead, it returns `Some(offset)`. `Some` is a variant or
@@ -187,6 +186,8 @@ But wait, what about `unwrap` used in [`unwrap-double`](#code-unwrap-double)?
187186
There was no case analysis there! Instead, the case analysis was put inside the
188187
`unwrap` method for you. You could define it yourself if you want:
189188

189+
<a name="code-option-def-unwrap"></a>
190+
190191
```rust
191192
enum Option<T> {
192193
None,
@@ -210,7 +211,7 @@ that makes `unwrap` ergonomic to use. Unfortunately, that `panic!` means that
210211

211212
### Composing `Option<T>` values
212213

213-
In [`option-ex-string-find`](#code-option-ex-string-find-2)
214+
In [`option-ex-string-find`](#code-option-ex-string-find)
214215
we saw how to use `find` to discover the extension in a file name. Of course,
215216
not all file names have a `.` in them, so it's possible that the file name has
216217
no extension. This *possibility of absence* is encoded into the types using
@@ -252,6 +253,8 @@ option is `None`, in which case, just return `None`.
252253
Rust has parametric polymorphism, so it is very easy to define a combinator
253254
that abstracts this pattern:
254255

256+
<a name="code-option-map"></a>
257+
255258
```rust
256259
fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A {
257260
match option {
@@ -391,6 +394,8 @@ remove choices because they will panic if `Option<T>` is `None`.
391394
The `Result` type is also
392395
[defined in the standard library][6]:
393396

397+
<a name="code-result-def-1"></a>
398+
394399
```rust
395400
enum Result<T, E> {
396401
Ok(T),
@@ -667,6 +672,8 @@ with both an `Option` and a `Result`, the solution is *usually* to convert the
667672
(from `env::args()`) means the user didn't invoke the program correctly. We
668673
could just use a `String` to describe the error. Let's try:
669674

675+
<a name="code-error-double-string"></a>
676+
670677
```rust
671678
use std::env;
672679

@@ -899,6 +906,8 @@ seen above.
899906

900907
Here is a simplified definition of a `try!` macro:
901908

909+
<a nama name="code-try-def-simple"></a>
910+
902911
```rust
903912
macro_rules! try {
904913
($e:expr) => (match $e {
@@ -1159,6 +1168,8 @@ The `std::convert::From` trait is
11591168
[defined in the standard
11601169
library](../std/convert/trait.From.html):
11611170

1171+
<a name="code-from-def"></a>
1172+
11621173
```rust
11631174
trait From<T> {
11641175
fn from(T) -> Self;
@@ -1236,9 +1247,11 @@ macro_rules! try {
12361247
}
12371248
```
12381249

1239-
This is not it's real definition. It's real definition is
1250+
This is not its real definition. Its real definition is
12401251
[in the standard library](../std/macro.try!.html):
12411252

1253+
<a name="code-try-def"></a>
1254+
12421255
```rust
12431256
macro_rules! try {
12441257
($e:expr) => (match $e {
@@ -1457,7 +1470,7 @@ representation. But certainly, this will vary depending on use cases.
14571470
At a minimum, you should probably implement the
14581471
[`Error`](../std/error/trait.Error.html)
14591472
trait. This will give users of your library some minimum flexibility for
1460-
[composing errors](#the-real-try-macro). Implementing the `Error` trait also
1473+
[composing errors](#the-real-try!-macro). Implementing the `Error` trait also
14611474
means that users are guaranteed the ability to obtain a string representation
14621475
of an error (because it requires impls for both `fmt::Debug` and
14631476
`fmt::Display`).

src/doc/trpl/guessing-game.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ a few tricks up their sleeves.
147147

148148
For example, they’re [immutable][immutable] by default. That’s why our example
149149
uses `mut`: it makes a binding mutable, rather than immutable. `let` doesn’t
150-
take a name on the left hand side, it actually accepts a
150+
take a name on the left hand side of the assignment, it actually accepts a
151151
[pattern][patterns]’. We’ll use patterns later. It’s easy enough
152152
to use for now:
153153

src/librustc_borrowck/borrowck/check_loans.rs

+34-40
Original file line numberDiff line numberDiff line change
@@ -464,40 +464,36 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
464464

465465
match (new_loan.kind, old_loan.kind) {
466466
(ty::MutBorrow, ty::MutBorrow) => {
467-
self.bccx.span_err(
468-
new_loan.span,
469-
&format!("cannot borrow `{}`{} as mutable \
470-
more than once at a time",
471-
nl, new_loan_msg))
467+
span_err!(self.bccx, new_loan.span, E0499,
468+
"cannot borrow `{}`{} as mutable \
469+
more than once at a time",
470+
nl, new_loan_msg);
472471
}
473472

474473
(ty::UniqueImmBorrow, _) => {
475-
self.bccx.span_err(
476-
new_loan.span,
477-
&format!("closure requires unique access to `{}` \
478-
but {} is already borrowed{}",
479-
nl, ol_pronoun, old_loan_msg));
474+
span_err!(self.bccx, new_loan.span, E0500,
475+
"closure requires unique access to `{}` \
476+
but {} is already borrowed{}",
477+
nl, ol_pronoun, old_loan_msg);
480478
}
481479

482480
(_, ty::UniqueImmBorrow) => {
483-
self.bccx.span_err(
484-
new_loan.span,
485-
&format!("cannot borrow `{}`{} as {} because \
486-
previous closure requires unique access",
487-
nl, new_loan_msg, new_loan.kind.to_user_str()));
481+
span_err!(self.bccx, new_loan.span, E0501,
482+
"cannot borrow `{}`{} as {} because \
483+
previous closure requires unique access",
484+
nl, new_loan_msg, new_loan.kind.to_user_str());
488485
}
489486

490487
(_, _) => {
491-
self.bccx.span_err(
492-
new_loan.span,
493-
&format!("cannot borrow `{}`{} as {} because \
494-
{} is also borrowed as {}{}",
495-
nl,
496-
new_loan_msg,
497-
new_loan.kind.to_user_str(),
498-
ol_pronoun,
499-
old_loan.kind.to_user_str(),
500-
old_loan_msg));
488+
span_err!(self.bccx, new_loan.span, E0502,
489+
"cannot borrow `{}`{} as {} because \
490+
{} is also borrowed as {}{}",
491+
nl,
492+
new_loan_msg,
493+
new_loan.kind.to_user_str(),
494+
ol_pronoun,
495+
old_loan.kind.to_user_str(),
496+
old_loan_msg);
501497
}
502498
}
503499

@@ -617,11 +613,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
617613
match self.analyze_restrictions_on_use(id, copy_path, ty::ImmBorrow) {
618614
UseOk => { }
619615
UseWhileBorrowed(loan_path, loan_span) => {
620-
self.bccx.span_err(
621-
span,
622-
&format!("cannot use `{}` because it was mutably borrowed",
623-
&self.bccx.loan_path_to_string(copy_path))
624-
);
616+
span_err!(self.bccx, span, E0503,
617+
"cannot use `{}` because it was mutably borrowed",
618+
&self.bccx.loan_path_to_string(copy_path));
625619
self.bccx.span_note(
626620
loan_span,
627621
&format!("borrow of `{}` occurs here",
@@ -642,18 +636,19 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
642636
match self.analyze_restrictions_on_use(id, move_path, ty::MutBorrow) {
643637
UseOk => { }
644638
UseWhileBorrowed(loan_path, loan_span) => {
645-
let err_message = match move_kind {
639+
match move_kind {
646640
move_data::Captured =>
647-
format!("cannot move `{}` into closure because it is borrowed",
648-
&self.bccx.loan_path_to_string(move_path)),
641+
span_err!(self.bccx, span, E0504,
642+
"cannot move `{}` into closure because it is borrowed",
643+
&self.bccx.loan_path_to_string(move_path)),
649644
move_data::Declared |
650645
move_data::MoveExpr |
651646
move_data::MovePat =>
652-
format!("cannot move out of `{}` because it is borrowed",
653-
&self.bccx.loan_path_to_string(move_path))
647+
span_err!(self.bccx, span, E0505,
648+
"cannot move out of `{}` because it is borrowed",
649+
&self.bccx.loan_path_to_string(move_path))
654650
};
655651

656-
self.bccx.span_err(span, &err_message[..]);
657652
self.bccx.span_note(
658653
loan_span,
659654
&format!("borrow of `{}` occurs here",
@@ -820,10 +815,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
820815
span: Span,
821816
loan_path: &LoanPath<'tcx>,
822817
loan: &Loan) {
823-
self.bccx.span_err(
824-
span,
825-
&format!("cannot assign to `{}` because it is borrowed",
826-
self.bccx.loan_path_to_string(loan_path)));
818+
span_err!(self.bccx, span, E0506,
819+
"cannot assign to `{}` because it is borrowed",
820+
self.bccx.loan_path_to_string(loan_path));
827821
self.bccx.span_note(
828822
loan.span,
829823
&format!("borrow of `{}` occurs here",

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,18 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
119119
mc::cat_deref(_, _, mc::Implicit(..)) |
120120
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
121121
mc::cat_static_item => {
122-
bccx.span_err(move_from.span,
123-
&format!("cannot move out of {}",
124-
move_from.descriptive_string(bccx.tcx)));
122+
span_err!(bccx, move_from.span, E0507,
123+
"cannot move out of {}",
124+
move_from.descriptive_string(bccx.tcx));
125125
}
126126

127127
mc::cat_interior(ref b, mc::InteriorElement(Kind::Index, _)) => {
128128
let expr = bccx.tcx.map.expect_expr(move_from.id);
129129
if let hir::ExprIndex(..) = expr.node {
130-
bccx.span_err(move_from.span,
131-
&format!("cannot move out of type `{}`, \
132-
a non-copy fixed-size array",
133-
b.ty));
130+
span_err!(bccx, move_from.span, E0508,
131+
"cannot move out of type `{}`, \
132+
a non-copy fixed-size array",
133+
b.ty);
134134
}
135135
}
136136

@@ -139,11 +139,10 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
139139
match b.ty.sty {
140140
ty::TyStruct(def, _) |
141141
ty::TyEnum(def, _) if def.has_dtor() => {
142-
bccx.span_err(
143-
move_from.span,
144-
&format!("cannot move out of type `{}`, \
145-
which defines the `Drop` trait",
146-
b.ty));
142+
span_err!(bccx, move_from.span, E0509,
143+
"cannot move out of type `{}`, \
144+
which defines the `Drop` trait",
145+
b.ty);
147146
},
148147
_ => {
149148
bccx.span_bug(move_from.span, "this path should not cause illegal move")

src/librustc_borrowck/borrowck/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
803803
self.tcx.sess.span_err(s, m);
804804
}
805805

806+
pub fn span_err_with_code(&self, s: Span, msg: &str, code: &str) {
807+
self.tcx.sess.span_err_with_code(s, msg, code);
808+
}
809+
806810
pub fn span_bug(&self, s: Span, m: &str) {
807811
self.tcx.sess.span_bug(s, m);
808812
}

0 commit comments

Comments
 (0)