Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a85c9f7

Browse files
authoredMay 17, 2024··
Merge branch 'rust-lang:master' into again-again-again
2 parents a26329f + e356977 commit a85c9f7

14 files changed

+236
-34
lines changed
 

‎src/attributes.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct S {
196196
pub fn f() {}
197197
```
198198

199-
> Note: `rustc` currently recognizes the tools "clippy" and "rustfmt".
199+
> Note: `rustc` currently recognizes the tools "clippy", "rustfmt" and "diagnostic".
200200
201201
## Built-in attributes index
202202

@@ -224,6 +224,8 @@ The following is an index of all built-in attributes.
224224
- [`allow`], [`warn`], [`deny`], [`forbid`] — Alters the default lint level.
225225
- [`deprecated`] — Generates deprecation notices.
226226
- [`must_use`] — Generates a lint for unused values.
227+
- [`diagnostic::on_unimplemented`] — Hints the compiler to emit a certain error
228+
message if a trait is not implemented.
227229
- ABI, linking, symbols, and FFI
228230
- [`link`] — Specifies a native library to link with an `extern` block.
229231
- [`link_name`] — Specifies the name of the symbol for functions or statics
@@ -273,6 +275,7 @@ The following is an index of all built-in attributes.
273275
added in future.
274276
- Debugger
275277
- [`debugger_visualizer`] — Embeds a file that specifies debugger output for a type.
278+
- [`collapse_debuginfo`] — Controls how macro invocations are encoded in debuginfo.
276279

277280
[Doc comments]: comments.md#doc-comments
278281
[ECMA-334]: https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
@@ -291,6 +294,7 @@ The following is an index of all built-in attributes.
291294
[`cfg_attr`]: conditional-compilation.md#the-cfg_attr-attribute
292295
[`cfg`]: conditional-compilation.md#the-cfg-attribute
293296
[`cold`]: attributes/codegen.md#the-cold-attribute
297+
[`collapse_debuginfo`]: attributes/debugger.md#the-collapse_debuginfo-attribute
294298
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
295299
[`crate_type`]: linkage.md
296300
[`debugger_visualizer`]: attributes/debugger.md#the-debugger_visualizer-attribute
@@ -352,3 +356,4 @@ The following is an index of all built-in attributes.
352356
[closure]: expressions/closure-expr.md
353357
[function pointer]: types/function-pointer.md
354358
[variadic functions]: items/external-blocks.html#variadic-functions
359+
[`diagnostic::on_unimplemented`]: attributes/diagnostics.md#the-diagnosticon_unimplemented-attribute

‎src/attributes/codegen.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Feature | Implicitly Enables | Description
262262
[rv-zks]: https://github.com/riscv/riscv-crypto/blob/e2dd7d98b7f34d477e38cb5fd7a3af4379525189/doc/scalar/riscv-crypto-scalar-zks.adoc
263263
[rv-zksed]: https://github.com/riscv/riscv-crypto/blob/e2dd7d98b7f34d477e38cb5fd7a3af4379525189/doc/scalar/riscv-crypto-scalar-zksed.adoc
264264
[rv-zksh]: https://github.com/riscv/riscv-crypto/blob/e2dd7d98b7f34d477e38cb5fd7a3af4379525189/doc/scalar/riscv-crypto-scalar-zksh.adoc
265-
[rv-zkt]: https://github.com/riscv/riscv-crypto/blob/e2dd7d98b7f34d477e38cb5fd7a3af4379525189/doc/scalar/riscv-crypto-scalar-zkr.adoc
265+
[rv-zkt]: https://github.com/riscv/riscv-crypto/blob/e2dd7d98b7f34d477e38cb5fd7a3af4379525189/doc/scalar/riscv-crypto-scalar-zkt.adoc
266266

267267
#### `wasm32` or `wasm64`
268268

@@ -273,10 +273,20 @@ attempting to use instructions unsupported by the Wasm engine will fail at load
273273
time without the risk of being interpreted in a way different from what the
274274
compiler expected.
275275

276-
Feature | Description
277-
------------|-------------------
278-
`simd128` | [WebAssembly simd proposal][simd128]
279-
276+
Feature | Description
277+
----------------------|-------------------
278+
`bulk-memory` | [WebAssembly bulk memory operations proposal][bulk-memory]
279+
`extended-const` | [WebAssembly extended const expressions proposal][extended-const]
280+
`mutable-globals` | [WebAssembly mutable global proposal][mutable-globals]
281+
`nontrapping-fptoint` | [WebAssembly non-trapping float-to-int conversion proposal][nontrapping-fptoint]
282+
`sign-ext` | [WebAssembly sign extension operators Proposal][sign-ext]
283+
`simd128` | [WebAssembly simd proposal][simd128]
284+
285+
[bulk-memory]: https://github.com/WebAssembly/bulk-memory-operations
286+
[extended-const]: https://github.com/WebAssembly/extended-const
287+
[mutable-globals]: https://github.com/WebAssembly/mutable-global
288+
[nontrapping-fptoint]: https://github.com/WebAssembly/nontrapping-float-to-int-conversions
289+
[sign-ext]: https://github.com/WebAssembly/sign-extension-ops
280290
[simd128]: https://github.com/webassembly/simd
281291

282292
### Additional information

‎src/attributes/debugger.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,32 @@ When the crate's debug executable is passed into GDB[^rust-gdb], `print bob` wil
139139
[Natvis documentation]: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects
140140
[pretty printing documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html
141141
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
142+
143+
## The `collapse_debuginfo` attribute
144+
145+
The *`collapse_debuginfo` [attribute]* controls whether code locations from a macro definition are collapsed into a single location associated with the macro's call site,
146+
when generating debuginfo for code calling this macro.
147+
148+
The attribute uses the [_MetaListIdents_] syntax to specify its inputs, and can only be applied to macro definitions.
149+
150+
Accepted options:
151+
- `#[collapse_debuginfo(yes)]` — code locations in debuginfo are collapsed.
152+
- `#[collapse_debuginfo(no)]` — code locations in debuginfo are not collapsed.
153+
- `#[collapse_debuginfo(external)]` — code locations in debuginfo are collapsed only if the macro comes from a different crate.
154+
155+
The `external` behavior is the default for macros that don't have this attribute, unless they are built-in macros.
156+
For built-in macros the default is `yes`.
157+
158+
> **Note**: `rustc` has a `-C collapse-macro-debuginfo` CLI option to override both the default collapsing behavior and `#[collapse_debuginfo]` attributes.
159+
160+
```rust
161+
#[collapse_debuginfo(yes)]
162+
macro_rules! example {
163+
() => {
164+
println!("hello!");
165+
};
166+
}
167+
```
168+
169+
[attribute]: ../attributes.md
170+
[_MetaListIdents_]: ../attributes.md#meta-item-attribute-syntax

‎src/attributes/diagnostics.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,76 @@ When used on a function in a trait implementation, the attribute does nothing.
301301
> let _ = five();
302302
> ```
303303
304+
## The `diagnostic` tool attribute namespace
305+
306+
The `#[diagnostic]` attribute namespace is a home for attributes to influence compile-time error messages.
307+
The hints provided by these attributes are not guaranteed to be used.
308+
Unknown attributes in this namespace are accepted, though they may emit warnings for unused attributes.
309+
Additionally, invalid inputs to known attributes will typically be a warning (see the attribute definitions for details).
310+
This is meant to allow adding or discarding attributes and changing inputs in the future to allow changes without the need to keep the non-meaningful attributes or options working.
311+
312+
### The `diagnostic::on_unimplemented` attribute
313+
314+
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to supplement the error message that would normally be generated in scenarios where a trait is required but not implemented on a type.
315+
The attribute should be placed on a [trait declaration], though it is not an error to be located in other positions.
316+
The attribute uses the [_MetaListNameValueStr_] syntax to specify its inputs, though any malformed input to the attribute is not considered as an error to provide both forwards and backwards compatibility.
317+
The following keys have the given meaning:
318+
319+
* `message` — The text for the top level error message.
320+
* `label` — The text for the label shown inline in the broken code in the error message.
321+
* `note` — Provides additional notes.
322+
323+
The `note` option can appear several times, which results in several note messages being emitted.
324+
If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value.
325+
Any other occurrence generates an lint warning.
326+
For any other non-existing option a lint-warning is generated.
327+
328+
All three options accept a string as an argument, interpreted using the same formatting as a [`std::fmt`] string.
329+
Format parameters with the given named parameter will be replaced with the following text:
330+
331+
* `{Self}` — The name of the type implementing the trait.
332+
* `{` *GenericParameterName* `}` — The name of the generic argument's type for the given generic parameter.
333+
334+
Any other format parameter will generate a warning, but will otherwise be included in the string as-is.
335+
336+
Invalid format strings may generate a warning, but are otherwise allowed, but may not display as intended.
337+
Format specifiers may generate a warning, but are otherwise ignored.
338+
339+
In this example:
340+
341+
```rust,compile_fail,E0277
342+
#[diagnostic::on_unimplemented(
343+
message = "My Message for `ImportantTrait<{A}>` implemented for `{Self}`",
344+
label = "My Label",
345+
note = "Note 1",
346+
note = "Note 2"
347+
)]
348+
trait ImportantTrait<A> {}
349+
350+
fn use_my_trait(_: impl ImportantTrait<i32>) {}
351+
352+
fn main() {
353+
use_my_trait(String::new());
354+
}
355+
```
356+
357+
the compiler may generate an error message which looks like this:
358+
359+
```text
360+
error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
361+
--> src/main.rs:14:18
362+
|
363+
14 | use_my_trait(String::new());
364+
| ------------ ^^^^^^^^^^^^^ My Label
365+
| |
366+
| required by a bound introduced by this call
367+
|
368+
= help: the trait `ImportantTrait<i32>` is not implemented for `String`
369+
= note: Note 1
370+
= note: Note 2
371+
```
372+
373+
[`std::fmt`]: ../../std/fmt/index.html
304374
[Clippy]: https://github.com/rust-lang/rust-clippy
305375
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
306376
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax

‎src/attributes/type_system.md

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub struct Config {
2020
pub window_height: u16,
2121
}
2222

23+
#[non_exhaustive]
24+
pub struct Token;
25+
26+
#[non_exhaustive]
27+
pub struct Id(pub u64);
28+
2329
#[non_exhaustive]
2430
pub enum Error {
2531
Message(String),
@@ -34,11 +40,13 @@ pub enum Message {
3440

3541
// Non-exhaustive structs can be constructed as normal within the defining crate.
3642
let config = Config { window_width: 640, window_height: 480 };
43+
let token = Token;
44+
let id = Id(4);
3745

3846
// Non-exhaustive structs can be matched on exhaustively within the defining crate.
39-
if let Config { window_width, window_height } = config {
40-
// ...
41-
}
47+
let Config { window_width, window_height } = config;
48+
let Token = token;
49+
let Id(id_number) = id;
4250

4351
let error = Error::Other;
4452
let message = Message::Reaction(3);
@@ -64,47 +72,68 @@ Non-exhaustive types cannot be constructed outside of the defining crate:
6472

6573
- Non-exhaustive variants ([`struct`][struct] or [`enum` variant][enum]) cannot be constructed
6674
with a [_StructExpression_] \(including with [functional update syntax]).
75+
- The implicitly defined same-named constant of a [unit-like struct][struct],
76+
or the same-named constructor function of a [tuple struct][struct],
77+
has a [visibility] no greater than `pub(crate)`.
78+
That is, if the struct’s visibility is `pub`, then the constant or constructor’s visibility
79+
is `pub(crate)`, and otherwise the visibility of the two items is the same
80+
(as is the case without `#[non_exhaustive]`).
6781
- [`enum`][enum] instances can be constructed.
6882

83+
The following examples of construction do not compile when outside the defining crate:
84+
6985
<!-- ignore: requires external crates -->
7086
```rust,ignore
71-
// `Config`, `Error`, and `Message` are types defined in an upstream crate that have been
72-
// annotated as `#[non_exhaustive]`.
73-
use upstream::{Config, Error, Message};
87+
// These are types defined in an upstream crate that have been annotated as
88+
// `#[non_exhaustive]`.
89+
use upstream::{Config, Token, Id, Error, Message};
7490
75-
// Cannot construct an instance of `Config`, if new fields were added in
91+
// Cannot construct an instance of `Config`; if new fields were added in
7692
// a new version of `upstream` then this would fail to compile, so it is
7793
// disallowed.
7894
let config = Config { window_width: 640, window_height: 480 };
7995
80-
// Can construct an instance of `Error`, new variants being introduced would
96+
// Cannot construct an instance of `Token`; if new fields were added, then
97+
// it would not be a unit-like struct any more, so the same-named constant
98+
// created by it being a unit-like struct is not public outside the crate;
99+
// this code fails to compile.
100+
let token = Token;
101+
102+
// Cannot construct an instance of `Id`; if new fields were added, then
103+
// its constructor function signature would change, so its constructor
104+
// function is not public outside the crate; this code fails to compile.
105+
let id = Id(5);
106+
107+
// Can construct an instance of `Error`; new variants being introduced would
81108
// not result in this failing to compile.
82109
let error = Error::Message("foo".to_string());
83110
84-
// Cannot construct an instance of `Message::Send` or `Message::Reaction`,
111+
// Cannot construct an instance of `Message::Send` or `Message::Reaction`;
85112
// if new fields were added in a new version of `upstream` then this would
86113
// fail to compile, so it is disallowed.
87114
let message = Message::Send { from: 0, to: 1, contents: "foo".to_string(), };
88115
let message = Message::Reaction(0);
89116
90-
// Cannot construct an instance of `Message::Quit`, if this were converted to
117+
// Cannot construct an instance of `Message::Quit`; if this were converted to
91118
// a tuple-variant `upstream` then this would fail to compile.
92119
let message = Message::Quit;
93120
```
94121

95122
There are limitations when matching on non-exhaustive types outside of the defining crate:
96123

97124
- When pattern matching on a non-exhaustive variant ([`struct`][struct] or [`enum` variant][enum]),
98-
a [_StructPattern_] must be used which must include a `..`. Tuple variant constructor visibility
99-
is lowered to `min($vis, pub(crate))`.
125+
a [_StructPattern_] must be used which must include a `..`. A tuple variant's constructor's
126+
[visibility] is reduced to be no greater than `pub(crate)`.
100127
- When pattern matching on a non-exhaustive [`enum`][enum], matching on a variant does not
101128
contribute towards the exhaustiveness of the arms.
102129

130+
The following examples of matching do not compile when outside the defining crate:
131+
103132
<!-- ignore: requires external crates -->
104133
```rust, ignore
105-
// `Config`, `Error`, and `Message` are types defined in an upstream crate that have been
106-
// annotated as `#[non_exhaustive]`.
107-
use upstream::{Config, Error, Message};
134+
// These are types defined in an upstream crate that have been annotated as
135+
// `#[non_exhaustive]`.
136+
use upstream::{Config, Token, Id, Error, Message};
108137
109138
// Cannot match on a non-exhaustive enum without including a wildcard arm.
110139
match error {
@@ -118,6 +147,13 @@ if let Ok(Config { window_width, window_height }) = config {
118147
// would compile with: `..`
119148
}
120149
150+
// Cannot match a non-exhaustive unit-like or tuple struct except by using
151+
// braced struct syntax with a wildcard.
152+
// This would compile as `let Token { .. } = token;`
153+
let Token = token;
154+
// This would compile as `let Id { 0: id_number, .. } = id;`
155+
let Id(id_number) = id;
156+
121157
match message {
122158
// Cannot match on a non-exhaustive struct enum variant without including a wildcard.
123159
Message::Send { from, to, contents } => { },
@@ -147,3 +183,4 @@ Non-exhaustive types are always considered inhabited in downstream crates.
147183
[enum]: ../items/enumerations.md
148184
[functional update syntax]: ../expressions/struct-expr.md#functional-update-syntax
149185
[struct]: ../items/structs.md
186+
[visibility]: ../visibility-and-privacy.md

‎src/const_eval.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ to be run.
2727
* [Tuple expressions].
2828
* [Array expressions].
2929
* [Struct] expressions.
30-
* [Block expressions], including `unsafe` blocks.
30+
* [Block expressions], including `unsafe` and `const` blocks.
3131
* [let statements] and thus irrefutable [patterns], including mutable bindings
3232
* [assignment expressions]
3333
* [compound assignment expressions]
@@ -59,6 +59,7 @@ A _const context_ is one of the following:
5959
* [statics]
6060
* [enum discriminants]
6161
* A [const generic argument]
62+
* A [const block]
6263

6364
## Const Functions
6465

@@ -106,6 +107,7 @@ Conversely, the following are possible in a const function, but not in a const c
106107
[cast]: expressions/operator-expr.md#type-cast-expressions
107108
[closure expressions]: expressions/closure-expr.md
108109
[comparison]: expressions/operator-expr.md#comparison-operators
110+
[const block]: expressions/block-expr.md#const-blocks
109111
[const functions]: items/functions.md#const-functions
110112
[const generic argument]: items/generics.md#const-generics
111113
[const generic parameters]: items/generics.md#const-generics

‎src/expressions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>[](#expression-attributes)\
3636
> &nbsp;&nbsp; (\
3737
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [_BlockExpression_]\
38+
> &nbsp;&nbsp; &nbsp;&nbsp; | [_ConstBlockExpression_]\
3839
> &nbsp;&nbsp; &nbsp;&nbsp; | [_UnsafeBlockExpression_]\
3940
> &nbsp;&nbsp; &nbsp;&nbsp; | [_LoopExpression_]\
4041
> &nbsp;&nbsp; &nbsp;&nbsp; | [_IfExpression_]\
@@ -311,6 +312,7 @@ They are never allowed before:
311312
[_ClosureExpression_]: expressions/closure-expr.md
312313
[_ComparisonExpression_]: expressions/operator-expr.md#comparison-operators
313314
[_CompoundAssignmentExpression_]: expressions/operator-expr.md#compound-assignment-expressions
315+
[_ConstBlockExpression_]: expressions/block-expr.md#const-blocks
314316
[_ContinueExpression_]: expressions/loop-expr.md#continue-expressions
315317
[_FieldExpression_]: expressions/field-expr.md
316318
[_GroupedExpression_]: expressions/grouped-expr.md

‎src/expressions/block-expr.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,44 @@ loop {
117117
}
118118
```
119119
120+
## `const` blocks
121+
122+
> **<sup>Syntax</sup>**\
123+
> _ConstBlockExpression_ :\
124+
> &nbsp;&nbsp; `const` _BlockExpression_
125+
126+
A *const block* is a variant of a block expression which evaluates at compile-time instead of at runtime.
127+
128+
Const blocks allows you to define a constant value without having to define new [constant items], and thus they are also sometimes referred as *inline consts*.
129+
It also supports type inference so there is no need to specify the type, unlike [constant items].
130+
131+
Const blocks have the ability to reference generic parameters in scope, unlike [free][free item] constant items.
132+
They are desugared to associated constant items with generic parameters in scope.
133+
For example, this code:
134+
135+
```rust
136+
fn foo<T>() -> usize {
137+
const { std::mem::size_of::<T>() + 1 }
138+
}
139+
```
140+
141+
is equivalent to:
142+
143+
```rust
144+
fn foo<T>() -> usize {
145+
{
146+
struct Const<T>(T);
147+
impl<T> Const<T> {
148+
const CONST: usize = std::mem::size_of::<T>() + 1;
149+
}
150+
Const::<T>::CONST
151+
}
152+
}
153+
```
154+
155+
This also means that const blocks are treated similarly to associated constants.
156+
For example, they are not guaranteed to be evaluated when the enclosing function is unused.
157+
120158
## `unsafe` blocks
121159

122160
> **<sup>Syntax</sup>**\
@@ -181,6 +219,8 @@ fn is_unix_platform() -> bool {
181219
[array expressions]: array-expr.md
182220
[call expressions]: call-expr.md
183221
[capture modes]: ../types/closure.md#capture-modes
222+
[constant items]: ../items/constant-items.md
223+
[free item]: ../glossary.md#free-item
184224
[function]: ../items/functions.md
185225
[inner attributes]: ../attributes.md
186226
[method]: ../items/associated-items.md#methods

‎src/input-format.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Other occurrences of the character `U+000D` (CR) are left in place (they are tre
2121

2222
## Shebang removal
2323

24-
If the remaining sequence begins with the characters `!#`, the characters up to and including the first `U+000A` (LF) are removed from the sequence.
24+
If the remaining sequence begins with the characters `#!`, the characters up to and including the first `U+000A` (LF) are removed from the sequence.
2525

2626
For example, the first line of the following file would be ignored:
2727

‎src/macros-by-example.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ For reasons of backwards compatibility, though `_` [is also an
146146
expression][_UnderscoreExpression_], a standalone underscore is not matched by
147147
the `expr` fragment specifier. However, `_` is matched by the `expr` fragment
148148
specifier when it appears as a subexpression.
149+
For the same reason, a standalone [const block] is not matched but it is matched when appearing as a subexpression.
149150

150151
> **Edition Differences**: Starting with the 2021 edition, `pat` fragment-specifiers match top-level or-patterns (that is, they accept [_Pattern_]).
151152
>
@@ -706,6 +707,7 @@ expansions, taking separators into account. This means:
706707

707708
For more detail, see the [formal specification].
708709

710+
[const block]: expressions/block-expr.md#const-blocks
709711
[Hygiene]: #hygiene
710712
[IDENTIFIER]: identifiers.md
711713
[IDENTIFIER_OR_KEYWORD]: identifiers.md

‎src/patterns.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ match tuple {
397397
> &nbsp;&nbsp; | _RangeToInclusivePattern_\
398398
> &nbsp;&nbsp; | _ObsoleteRangePattern_
399399
>
400+
> _RangeExclusivePattern_ :\
401+
> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..` _RangePatternBound_
402+
>
400403
> _RangeInclusivePattern_ :\
401404
> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..=` _RangePatternBound_
402405
>
@@ -422,10 +425,11 @@ A bound on the left of the sigil is a *lower bound*.
422425
A bound on the right is an *upper bound*.
423426

424427
A range pattern with both a lower and upper bound will match all values between and including both of its bounds.
425-
It is written as its lower bound, followed by `..=`, followed by its upper bound.
428+
It is written as its lower bound, followed by `..` for end-exclusive or `..=` for end-inclusive, followed by its upper bound.
426429
The type of the range pattern is the type unification of its upper and lower bounds.
427430

428431
For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`.
432+
Similarly, `'m'..'p'` will match only `'m'`, `'n'` and `'o'`, specifically **not** including `'p'`.
429433

430434
The lower bound cannot be greater than the upper bound.
431435
That is, in `a..=b`, a &le; b must be the case.
@@ -467,7 +471,7 @@ let valid_variable = match c {
467471

468472
# let ph = 10;
469473
println!("{}", match ph {
470-
0..=6 => "acid",
474+
0..7 => "acid",
471475
7 => "neutral",
472476
8..=14 => "base",
473477
_ => unreachable!(),
@@ -539,9 +543,6 @@ See [issue #41620](https://github.com/rust-lang/rust/issues/41620) for more info
539543

540544
> **Edition Differences**: Before the 2021 edition, range patterns with both a lower and upper bound may also be written using `...` in place of `..=`, with the same meaning.
541545
542-
> **Note**: Although range patterns use the same syntax as [range expressions], there are no exclusive range patterns.
543-
> That is, neither `x .. y` nor `.. x` are valid range patterns.
544-
545546
## Reference patterns
546547

547548
> **<sup>Syntax</sup>**\

‎src/procedural-macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ shown in the comments after the function prefixed with "out:".
234234
235235
#[proc_macro_attribute]
236236
pub fn show_streams(attr: TokenStream, item: TokenStream) -> TokenStream {
237-
println!("attr: \"{}\"", attr.to_string());
238-
println!("item: \"{}\"", item.to_string());
237+
println!("attr: \"{attr}\"");
238+
println!("item: \"{item}\"");
239239
item
240240
}
241241
```

‎src/special-types-and-traits.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ types:
8080

8181
* Types with a built-in `Copy` implementation (see above)
8282
* [Tuples] of `Clone` types
83+
* [Closures] that only capture values of `Clone` types or capture no values from the environment
8384

8485
## `Send`
8586

‎src/type-layout.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,20 @@ The size of most primitives is given in this table.
4444
| `u32` / `i32` | 4 |
4545
| `u64` / `i64` | 8 |
4646
| `u128` / `i128` | 16 |
47+
| `usize` / `isize` | See below |
4748
| `f32` | 4 |
4849
| `f64` | 8 |
4950
| `char` | 4 |
5051

5152
`usize` and `isize` have a size big enough to contain every address on the
52-
target platform. For example, on a 32 bit target, this is 4 bytes and on a 64
53+
target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64
5354
bit target, this is 8 bytes.
5455

55-
Most primitives are generally aligned to their size, although this is
56-
platform-specific behavior. In particular, on x86 u64 and f64 are only
57-
aligned to 32 bits.
56+
The alignment of primitives is platform-specific.
57+
In most cases, their alignment is equal to their size, but it may be less.
58+
In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though
59+
their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only
60+
aligned to 4 bytes, not 8.
5861

5962
## Pointers and References Layout
6063

0 commit comments

Comments
 (0)
Please sign in to comment.