Skip to content

Commit c513608

Browse files
authored
Auto merge of #35036 - steveklabnik:rollup, r=steveklabnik
Rollup of 13 pull requests - Successful merges: #34461, #34609, #34732, #34850, #34894, #34935, #34974, #34990, #34995, #35001, #35009, #35010, #35028 - Failed merges:
2 parents 9316ae5 + e3e138b commit c513608

File tree

11 files changed

+714
-406
lines changed

11 files changed

+714
-406
lines changed

Diff for: src/doc/book/syntax-index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
* `|` (`|…| expr`): closures. See [Closures].
9595
* `|=` (`var |= expr`): bitwise or & assignment. Overloadable (`BitOrAssign`).
9696
* `||` (`expr || expr`): logical or.
97-
* `_`: "ignored" pattern binding. See [Patterns (Ignoring bindings)].
97+
* `_`: "ignored" pattern binding (see [Patterns (Ignoring bindings)]). Also used to make integer-literals readable (see [Reference (Integer literals)]).
9898

9999
## Other Syntax
100100

@@ -231,6 +231,7 @@
231231
[Primitive Types (Tuples)]: primitive-types.html#tuples
232232
[Raw Pointers]: raw-pointers.html
233233
[Reference (Byte String Literals)]: ../reference.html#byte-string-literals
234+
[Reference (Integer literals)]: ../reference.html#integer-literals
234235
[Reference (Raw Byte String Literals)]: ../reference.html#raw-byte-string-literals
235236
[Reference (Raw String Literals)]: ../reference.html#raw-string-literals
236237
[References and Borrowing]: references-and-borrowing.html

Diff for: src/doc/nomicon/phantom-data.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct Vec<T> {
5050
}
5151
```
5252

53-
Unlike the previous example it *appears* that everything is exactly as we
53+
Unlike the previous example, it *appears* that everything is exactly as we
5454
want. Every generic argument to Vec shows up in at least one field.
5555
Good to go!
5656

@@ -84,4 +84,3 @@ standard library made a utility for itself called `Unique<T>` which:
8484
* includes a `PhantomData<T>`
8585
* auto-derives Send/Sync as if T was contained
8686
* marks the pointer as NonZero for the null-pointer optimization
87-

Diff for: src/doc/reference.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -1653,14 +1653,43 @@ the Rust ABI and the foreign ABI.
16531653
A number of [attributes](#ffi-attributes) control the behavior of external blocks.
16541654

16551655
By default external blocks assume that the library they are calling uses the
1656-
standard C "cdecl" ABI. Other ABIs may be specified using an `abi` string, as
1657-
shown here:
1656+
standard C ABI on the specific platform. Other ABIs may be specified using an
1657+
`abi` string, as shown here:
16581658

16591659
```ignore
16601660
// Interface to the Windows API
16611661
extern "stdcall" { }
16621662
```
16631663

1664+
There are three ABI strings which are cross-platform, and which all compilers
1665+
are guaranteed to support:
1666+
1667+
* `extern "Rust"` -- The default ABI when you write a normal `fn foo()` in any
1668+
Rust code.
1669+
* `extern "C"` -- This is the same as `extern fn foo()`; whatever the default
1670+
your C compiler supports.
1671+
* `extern "system"` -- Usually the same as `extern "C"`, except on Win32, in
1672+
which case it's `"stdcall"`, or what you should use to link to the Windows API
1673+
itself
1674+
1675+
There are also some platform-specific ABI strings:
1676+
1677+
* `extern "cdecl"` -- The default for x86\_32 C code.
1678+
* `extern "stdcall"` -- The default for the Win32 API on x86\_32.
1679+
* `extern "win64"` -- The default for C code on x86\_64 Windows.
1680+
* `extern "aapcs"` -- The default for ARM.
1681+
* `extern "fastcall"` -- The `fastcall` ABI -- corresponds to MSVC's
1682+
`__fastcall` and GCC and clang's `__attribute__((fastcall))`
1683+
* `extern "vectorcall"` -- The `vectorcall` ABI -- corresponds to MSVC's
1684+
`__vectorcall` and clang's `__attribute__((vectorcall))`
1685+
1686+
Finally, there are some rustc-specific ABI strings:
1687+
1688+
* `extern "rust-intrinsic"` -- The ABI of rustc intrinsics.
1689+
* `extern "rust-call"` -- The ABI of the Fn::call trait functions.
1690+
* `extern "platform-intrinsic"` -- Specific platform intrinsics -- like, for
1691+
example, `sqrt` -- have this ABI. You should never have to deal with it.
1692+
16641693
The `link` attribute allows the name of the library to be specified. When
16651694
specified the compiler will attempt to link against the native library of the
16661695
specified name.

Diff for: src/doc/rustc-ux-guidelines.md

+122
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Error explanations are long form descriptions of error messages provided with
5656
the compiler. They are accessible via the `--explain` flag. Each explanation
5757
comes with an example of how to trigger it and advice on how to fix it.
5858

59+
Long error codes explanations are a very important part of Rust. Having an
60+
explanation of what failed helps to understand the error and is appreciated by
61+
Rust developers of all skill levels.
62+
5963
* All of them are accessible [online](http://doc.rust-lang.org/error-index.html),
6064
which are auto-generated from rustc source code in different places:
6165
[librustc](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs),
@@ -74,6 +78,124 @@ code with backticks.
7478
* When talking about the compiler, call it `the compiler`, not `Rust` or
7579
`rustc`.
7680

81+
Note: The following sections are mostly a repaste of [RFC 1567](https://github.com/rust-lang/rfcs/blob/master/text/1567-long-error-codes-explanation-normalization.md).
82+
83+
### Template
84+
85+
Long error descriptions should match the following template. The next few
86+
sections of this document describe what each section is about.
87+
88+
```rust
89+
E000: r##"
90+
[Error description]
91+
92+
Example of erroneous code:
93+
94+
\```compile_fail
95+
[Minimal example]
96+
\```
97+
98+
[Error explanation]
99+
100+
\```
101+
[How to fix the problem]
102+
\```
103+
104+
[Optional Additional information]
105+
```
106+
107+
### Error description
108+
109+
Provide a more detailed error message. For example:
110+
111+
```rust
112+
extern crate a;
113+
extern crate b as a;
114+
```
115+
116+
We get the `E0259` error code which says "an extern crate named `a` has already been imported in this module" and the error explanation says: "The name chosen for an external crate conflicts with another external crate that has been imported into the current module.".
117+
118+
### Minimal example
119+
120+
Provide an erroneous code example which directly follows `Error description`. The erroneous example will be helpful for the `How to fix the problem`. Making it as simple as possible is really important in order to help readers to understand what the error is about. A comment should be added with the error on the same line where the errors occur. Example:
121+
122+
```rust
123+
type X = u32<i32>; // error: type parameters are not allowed on this type
124+
```
125+
126+
If the error comments is too long to fit 80 columns, split it up like this, so the next line start at the same column of the previous line:
127+
128+
```rust
129+
type X = u32<'static>; // error: lifetime parameters are not allowed on
130+
// this type
131+
```
132+
133+
And if the sample code is too long to write an effective comment, place your comment on the line before the sample code:
134+
135+
```rust
136+
// error: lifetime parameters are not allowed on this type
137+
fn super_long_function_name_and_thats_problematic() {}
138+
```
139+
140+
Of course, it the comment is too long, the split rules still applies.
141+
142+
### Error explanation
143+
144+
Provide a full explanation about "__why__ you get the error" and some leads on __how__ to fix it. If needed, use additional code snippets to improve your explanations.
145+
146+
### How to fix the problem
147+
148+
This part will show how to fix the error that we saw previously in the `Minimal example`, with comments explaining how it was fixed.
149+
150+
### Additional information
151+
152+
Some details which might be useful for the users, let's take back `E0109` example. At the end, the supplementary explanation is the following: "Note that type parameters for enum-variant constructors go after the variant, not after the enum (`Option::None::<u32>`, not `Option::<u32>::None`).". It provides more information, not directly linked to the error, but it might help user to avoid doing another error.
153+
154+
### Full Example
155+
156+
Now let's take a full example:
157+
158+
> E0409: r##"
159+
> An "or" pattern was used where the variable bindings are not consistently bound
160+
> across patterns.
161+
>
162+
> Example of erroneous code:
163+
>
164+
> ```compile_fail
165+
> let x = (0, 2);
166+
> match x {
167+
> (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
168+
> // different mode in pattern #2
169+
> // than in pattern #1
170+
> _ => ()
171+
> }
172+
> ```
173+
>
174+
> Here, `y` is bound by-value in one case and by-reference in the other.
175+
>
176+
> To fix this error, just use the same mode in both cases.
177+
> Generally using `ref` or `ref mut` where not already used will fix this:
178+
>
179+
> ```ignore
180+
> let x = (0, 2);
181+
> match x {
182+
> (0, ref y) | (ref y, 0) => { /* use y */}
183+
> _ => ()
184+
> }
185+
> ```
186+
>
187+
> Alternatively, split the pattern:
188+
>
189+
> ```
190+
> let x = (0, 2);
191+
> match x {
192+
> (y, 0) => { /* use y */ }
193+
> (0, ref y) => { /* use y */}
194+
> _ => ()
195+
> }
196+
> ```
197+
> "##,
198+
77199
## Compiler Flags
78200

79201
* Flags should be orthogonal to each other. For example, if we'd have a

Diff for: src/libcollections/vec_deque.rs

+16
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ impl<T> VecDeque<T> {
402402

403403
/// Retrieves an element in the `VecDeque` by index.
404404
///
405+
/// Element at index 0 is the front of the queue.
406+
///
405407
/// # Examples
406408
///
407409
/// ```
@@ -425,6 +427,8 @@ impl<T> VecDeque<T> {
425427

426428
/// Retrieves an element in the `VecDeque` mutably by index.
427429
///
430+
/// Element at index 0 is the front of the queue.
431+
///
428432
/// # Examples
429433
///
430434
/// ```
@@ -456,6 +460,8 @@ impl<T> VecDeque<T> {
456460
///
457461
/// Fails if there is no element with either index.
458462
///
463+
/// Element at index 0 is the front of the queue.
464+
///
459465
/// # Examples
460466
///
461467
/// ```
@@ -1180,6 +1186,8 @@ impl<T> VecDeque<T> {
11801186
///
11811187
/// Returns `None` if `index` is out of bounds.
11821188
///
1189+
/// Element at index 0 is the front of the queue.
1190+
///
11831191
/// # Examples
11841192
///
11851193
/// ```
@@ -1214,6 +1222,8 @@ impl<T> VecDeque<T> {
12141222
///
12151223
/// Returns `None` if `index` is out of bounds.
12161224
///
1225+
/// Element at index 0 is the front of the queue.
1226+
///
12171227
/// # Examples
12181228
///
12191229
/// ```
@@ -1245,6 +1255,8 @@ impl<T> VecDeque<T> {
12451255
/// end is closer to the insertion point will be moved to make room,
12461256
/// and all the affected elements will be moved to new positions.
12471257
///
1258+
/// Element at index 0 is the front of the queue.
1259+
///
12481260
/// # Panics
12491261
///
12501262
/// Panics if `index` is greater than `VecDeque`'s length
@@ -1472,6 +1484,8 @@ impl<T> VecDeque<T> {
14721484
/// room, and all the affected elements will be moved to new positions.
14731485
/// Returns `None` if `index` is out of bounds.
14741486
///
1487+
/// Element at index 0 is the front of the queue.
1488+
///
14751489
/// # Examples
14761490
///
14771491
/// ```
@@ -1651,6 +1665,8 @@ impl<T> VecDeque<T> {
16511665
///
16521666
/// Note that the capacity of `self` does not change.
16531667
///
1668+
/// Element at index 0 is the front of the queue.
1669+
///
16541670
/// # Panics
16551671
///
16561672
/// Panics if `at > len`

0 commit comments

Comments
 (0)