Skip to content

Commit 2a6a5ad

Browse files
authored
Merge pull request #886 from ehuss/style-check
Add style checks.
2 parents 0f6b234 + dd1b9c3 commit 2a6a5ad

22 files changed

+253
-101
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
mdbook --version
2727
- name: Run tests
2828
run: mdbook test
29-
- name: Check for unstable features
30-
run: (cd stable-check && cargo run -- ../src)
29+
- name: Style checks
30+
run: (cd style-check && cargo run -- ../src)
3131
- name: Check for broken links
3232
run: |
3333
curl -sSLo linkcheck.sh \

STYLE.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Some conventions and content guidelines are specified in the [introduction].
44
This document serves as a guide for editors and reviewers.
55

6+
There is a [`style-check`](style-check/) tool which is run in CI to check some
7+
of these. To use it locally, run
8+
`cargo run --manifest-path=style-check/Cargo.toml src`.
9+
610
## Markdown formatting
711

812
* Use ATX-style heading with sentence case.

src/attributes/codegen.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ otherwise undefined behavior results.
157157

158158
### Behavior
159159

160-
Applying the attribute to a function `f` allows code within `f` to get a hint of the [`Location`] of
161-
the "topmost" tracked call that led to `f`'s invocation. At the point of observation, an
162-
implementation behaves as if it walks up the stack from `f`'s frame to find the nearest frame of an
160+
Applying the attribute to a function `f` allows code within `f` to get a hint of the [`Location`] of
161+
the "topmost" tracked call that led to `f`'s invocation. At the point of observation, an
162+
implementation behaves as if it walks up the stack from `f`'s frame to find the nearest frame of an
163163
*unattributed* function `outer`, and it returns the [`Location`] of the tracked call in `outer`.
164164

165165
```rust
@@ -190,7 +190,7 @@ fn calls_f() {
190190
```
191191

192192
When `f` is called by another attributed function `g` which is in turn called by `calls_g`, code in
193-
both `f` and `g` observes `g`'s callsite within `calls_g`:
193+
both `f` and `g` observes `g`'s callsite within `calls_g`:
194194

195195
```rust
196196
# #[track_caller]

src/comments.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
> **<sup>Lexer</sup>**\
44
> LINE_COMMENT :\
5-
> &nbsp;&nbsp; &nbsp;&nbsp; `//` (~[`/` `!`] | `//`) ~`\n`<sup>\*</sup>\
5+
> &nbsp;&nbsp; &nbsp;&nbsp; `//` (~\[`/` `!`] | `//`) ~`\n`<sup>\*</sup>\
66
> &nbsp;&nbsp; | `//`
77
>
88
> BLOCK_COMMENT :\
9-
> &nbsp;&nbsp; &nbsp;&nbsp; `/*` (~[`*` `!`] | `**` | _BlockCommentOrDoc_)
9+
> &nbsp;&nbsp; &nbsp;&nbsp; `/*` (~\[`*` `!`] | `**` | _BlockCommentOrDoc_)
1010
> (_BlockCommentOrDoc_ | ~`*/`)<sup>\*</sup> `*/`\
1111
> &nbsp;&nbsp; | `/**/`\
1212
> &nbsp;&nbsp; | `/***/`
1313
>
1414
> INNER_LINE_DOC :\
15-
> &nbsp;&nbsp; `//!` ~[`\n` _IsolatedCR_]<sup>\*</sup>
15+
> &nbsp;&nbsp; `//!` ~\[`\n` _IsolatedCR_]<sup>\*</sup>
1616
>
1717
> INNER_BLOCK_DOC :\
18-
> &nbsp;&nbsp; `/*!` ( _BlockCommentOrDoc_ | ~[`*/` _IsolatedCR_] )<sup>\*</sup> `*/`
18+
> &nbsp;&nbsp; `/*!` ( _BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_] )<sup>\*</sup> `*/`
1919
>
2020
> OUTER_LINE_DOC :\
21-
> &nbsp;&nbsp; `///` (~`/` ~[`\n` _IsolatedCR_]<sup>\*</sup>)<sup>?</sup>
21+
> &nbsp;&nbsp; `///` (~`/` ~\[`\n` _IsolatedCR_]<sup>\*</sup>)<sup>?</sup>
2222
>
2323
> OUTER_BLOCK_DOC :\
2424
> &nbsp;&nbsp; `/**` (~`*` | _BlockCommentOrDoc_ )
25-
> (_BlockCommentOrDoc_ | ~[`*/` _IsolatedCR_])<sup>\*</sup> `*/`
25+
> (_BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_])<sup>\*</sup> `*/`
2626
>
2727
> _BlockCommentOrDoc_ :\
2828
> &nbsp;&nbsp; &nbsp;&nbsp; BLOCK_COMMENT\

src/destructors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ smallest scope that contains the expression and is for one of the following:
166166
* The second operand of a [lazy boolean expression].
167167

168168
> **Notes**:
169-
>
169+
>
170170
> Temporaries that are created in the final expression of a function
171171
> body are dropped *after* any named variables bound in the function body, as
172172
> there is no smaller enclosing temporary scope.

src/expressions/closure-expr.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
> _ClosureParam_ :\
1313
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> [_Pattern_]&nbsp;( `:` [_Type_] )<sup>?</sup>
1414
15-
A _closure expression_, also know as a lambda expression or a lambda, defines a
16-
closure and denotes it as a value, in a single expression. A closure expression
17-
is a pipe-symbol-delimited (`|`) list of irrefutable [patterns] followed by an
18-
expression. Type annotations may optionally be added for the type of the
15+
A _closure expression_, also know as a lambda expression or a lambda, defines a
16+
closure and denotes it as a value, in a single expression. A closure expression
17+
is a pipe-symbol-delimited (`|`) list of irrefutable [patterns] followed by an
18+
expression. Type annotations may optionally be added for the type of the
1919
parameters or for the return type. If there is a return type, the expression
2020
used for the body of the closure must be a normal [block]. A closure expression
2121
also may begin with the `move` keyword before the initial `|`.

src/glossary.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ function* or a *free const*. Contrast to an [associated item].
7575

7676
### Fundamental traits
7777

78-
A fundamental trait is one where adding an impl of it for an existing type is a breaking change.
78+
A fundamental trait is one where adding an impl of it for an existing type is a breaking change.
7979
The `Fn` traits and `Sized` are fundamental.
8080

8181
### Fundamental type constructors
8282

83-
A fundamental type constructor is a type where implementing a [blanket implementation](#blanket-implementation) over it
84-
is a breaking change. `&`, `&mut`, `Box`, and `Pin` are fundamental.
83+
A fundamental type constructor is a type where implementing a [blanket implementation](#blanket-implementation) over it
84+
is a breaking change. `&`, `&mut`, `Box`, and `Pin` are fundamental.
8585

86-
Any time a type `T` is considered [local](#local-type), `&T`, `&mut T`, `Box<T>`, and `Pin<T>`
87-
are also considered local. Fundamental type constructors cannot [cover](#uncovered-type) other types.
88-
Any time the term "covered type" is used,
86+
Any time a type `T` is considered [local](#local-type), `&T`, `&mut T`, `Box<T>`, and `Pin<T>`
87+
are also considered local. Fundamental type constructors cannot [cover](#uncovered-type) other types.
88+
Any time the term "covered type" is used,
8989
the `T` in `&T`, `&mut T`, `Box<T>`, and `Pin<T>` is not considered covered.
9090

9191
### Inhabited
@@ -120,7 +120,7 @@ or not independent of applied type arguments. Given `trait Foo<T, U>`,
120120

121121
A `struct`, `enum`, or `union` which was defined in the current crate.
122122
This is not affected by applied type arguments. `struct Foo` is considered local, but
123-
`Vec<Foo>` is not. `LocalType<ForeignType>` is local. Type aliases do not
123+
`Vec<Foo>` is not. `LocalType<ForeignType>` is local. Type aliases do not
124124
affect locality.
125125

126126
### Nominal types

src/identifiers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
> **<sup>Lexer:<sup>**\
44
> IDENTIFIER_OR_KEYWORD :\
5-
> &nbsp;&nbsp; &nbsp;&nbsp; [`a`-`z` `A`-`Z`]&nbsp;[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>\*</sup>\
6-
> &nbsp;&nbsp; | `_` [`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>+</sup>
5+
> &nbsp;&nbsp; &nbsp;&nbsp; \[`a`-`z` `A`-`Z`]&nbsp;\[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>\*</sup>\
6+
> &nbsp;&nbsp; | `_` \[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>+</sup>
77
>
88
> RAW_IDENTIFIER : `r#` IDENTIFIER_OR_KEYWORD <sub>*Except `crate`, `self`, `super`, `Self`*</sub>
99
>

src/items/functions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ attributes][attributes] are allowed directly after the `{` inside its [block].
293293
This example shows an inner attribute on a function. The function will only be
294294
available while running tests.
295295

296-
```
296+
```rust
297297
fn test_only() {
298298
#![test]
299299
}

src/items/implementations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ least one of the following is true:
174174

175175
Only the appearance of *uncovered* type parameters is restricted.
176176
Note that for the purposes of coherence, [fundamental types] are
177-
special. The `T` in `Box<T>` is not considered covered, and `Box<LocalType>`
177+
special. The `T` in `Box<T>` is not considered covered, and `Box<LocalType>`
178178
is considered local.
179179

180180

src/macro-ambiguity.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ of this text is copied, and expanded upon in subsequent RFCs.
1616
"match").
1717
- `repetition` : a fragment that follows a regular repeating pattern
1818
- `NT`: non-terminal, the various "meta-variables" or repetition matchers
19-
that can appear in a matcher, specified in MBE syntax with a leading `$`
20-
character.
19+
that can appear in a matcher, specified in MBE syntax with a leading `$`
20+
character.
2121
- `simple NT`: a "meta-variable" non-terminal (further discussion below).
2222
- `complex NT`: a repetition matching non-terminal, specified via repetition
2323
operators (`\*`, `+`, `?`).
@@ -80,9 +80,9 @@ Greek letters "α" "β" "γ" "δ" stand for potentially empty token-tree sequen
8080
and does not stand for a token-tree sequence.)
8181

8282
* This Greek letter convention is usually just employed when the presence of
83-
a sequence is a technical detail; in particular, when we wish to *emphasize*
84-
that we are operating on a sequence of token-trees, we will use the notation
85-
"tt ..." for the sequence, not a Greek letter.
83+
a sequence is a technical detail; in particular, when we wish to *emphasize*
84+
that we are operating on a sequence of token-trees, we will use the notation
85+
"tt ..." for the sequence, not a Greek letter.
8686

8787
Note that a matcher is merely a token tree. A "simple NT", as mentioned above,
8888
is an meta-variable NT; thus it is a non-repetition. For example, `$foo:ty` is
@@ -108,7 +108,7 @@ of FIRST and FOLLOW are described later.
108108
tt uu ...`) with `uu ...` nonempty, we must have FOLLOW(`... tt`) ∪ {ε} ⊇
109109
FIRST(`uu ...`).
110110
1. For any separated complex NT in a matcher, `M = ... $(tt ...) SEP OP ...`,
111-
we must have `SEP` ∈ FOLLOW(`tt ...`).
111+
we must have `SEP` ∈ FOLLOW(`tt ...`).
112112
1. For an unseparated complex NT in a matcher, `M = ... $(tt ...) OP ...`, if
113113
OP = `\*` or `+`, we must have FOLLOW(`tt ...`) ⊇ FIRST(`tt ...`).
114114

src/notation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ The following notations are used by the *Lexer* and *Syntax* grammar snippets:
1515
| x<sup>+</sup> | _MacroMatch_<sup>+</sup> | 1 or more of x |
1616
| x<sup>a..b</sup> | HEX_DIGIT<sup>1..6</sup> | a to b repetitions of x |
1717
| \| | `u8` \| `u16`, Block \| Item | Either one or another |
18-
| [ ] | [`b` `B`] | Any of the characters listed |
19-
| [ - ] | [`a`-`z`] | Any of the characters in the range |
20-
| ~[ ] | ~[`b` `B`] | Any characters, except those listed |
18+
| \[ ] | \[`b` `B`] | Any of the characters listed |
19+
| \[ - ] | \[`a`-`z`] | Any of the characters in the range |
20+
| ~\[ ] | ~\[`b` `B`] | Any characters, except those listed |
2121
| ~`string` | ~`\n`, ~`*/` | Any characters, except this sequence |
2222
| ( ) | (`,` _Parameter_)<sup>?</sup> | Groups items |
2323

src/tokens.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ and numeric literal tokens are accepted only with suffixes from the list below.
115115

116116
> **<sup>Lexer</sup>**\
117117
> CHAR_LITERAL :\
118-
> &nbsp;&nbsp; `'` ( ~[`'` `\` \\n \\r \\t] | QUOTE_ESCAPE | ASCII_ESCAPE | UNICODE_ESCAPE ) `'`
118+
> &nbsp;&nbsp; `'` ( ~\[`'` `\` \\n \\r \\t] | QUOTE_ESCAPE | ASCII_ESCAPE | UNICODE_ESCAPE ) `'`
119119
>
120120
> QUOTE_ESCAPE :\
121121
> &nbsp;&nbsp; `\'` | `\"`
@@ -136,7 +136,7 @@ which must be _escaped_ by a preceding `U+005C` character (`\`).
136136
> **<sup>Lexer</sup>**\
137137
> STRING_LITERAL :\
138138
> &nbsp;&nbsp; `"` (\
139-
> &nbsp;&nbsp; &nbsp;&nbsp; ~[`"` `\` _IsolatedCR_]\
139+
> &nbsp;&nbsp; &nbsp;&nbsp; ~\[`"` `\` _IsolatedCR_]\
140140
> &nbsp;&nbsp; &nbsp;&nbsp; | QUOTE_ESCAPE\
141141
> &nbsp;&nbsp; &nbsp;&nbsp; | ASCII_ESCAPE\
142142
> &nbsp;&nbsp; &nbsp;&nbsp; | UNICODE_ESCAPE\
@@ -338,13 +338,13 @@ literal_. The grammar for recognizing the two kinds of literals is mixed.
338338
> HEX_LITERAL :\
339339
> &nbsp;&nbsp; `0x` (HEX_DIGIT|`_`)<sup>\*</sup> HEX_DIGIT (HEX_DIGIT|`_`)<sup>\*</sup>
340340
>
341-
> BIN_DIGIT : [`0`-`1`]
341+
> BIN_DIGIT : \[`0`-`1`]
342342
>
343-
> OCT_DIGIT : [`0`-`7`]
343+
> OCT_DIGIT : \[`0`-`7`]
344344
>
345-
> DEC_DIGIT : [`0`-`9`]
345+
> DEC_DIGIT : \[`0`-`9`]
346346
>
347-
> HEX_DIGIT : [`0`-`9` `a`-`f` `A`-`F`]
347+
> HEX_DIGIT : \[`0`-`9` `a`-`f` `A`-`F`]
348348
>
349349
> INTEGER_SUFFIX :\
350350
> &nbsp;&nbsp; &nbsp;&nbsp; `u8` | `u16` | `u32` | `u64` | `u128` | `usize`\

src/type-coercions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Type coercions
22

33
**Type coercions** are implicit operations that change the type of a value.
4-
They happen automatically at specific locations and are highly restricted in
4+
They happen automatically at specific locations and are highly restricted in
55
what types actually coerce.
66

77
Any conversions allowed by coercion can also be explicitly performed by the
@@ -55,7 +55,7 @@ sites are:
5555
Foo { x: &mut 42 };
5656
}
5757
```
58-
58+
5959
* Function results&mdash;either the final line of a block if it is not
6060
semicolon-terminated or any expression in a `return` statement
6161

src/type-layout.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ for interfacing with the C programming language.
177177
This representation can be applied to structs, unions, and enums. The exception
178178
is [zero-variant enums] for which the `C` representation is an error.
179179

180-
#### \#[repr(C)] Structs
180+
#### `#[repr(C)]` Structs
181181

182182
The alignment of the struct is the alignment of the most-aligned field in it.
183183

@@ -244,7 +244,7 @@ the sake of clarity. To perform memory layout computations in actual code, use
244244
> they are fields that have the `[[no_unique_address]]` attribute, in which
245245
> case they do not increase the overall size of the struct.
246246
247-
#### \#[repr(C)] Unions
247+
#### `#[repr(C)]` Unions
248248

249249
A union declared with `#[repr(C)]` will have the same size and alignment as an
250250
equivalent C union declaration in the C language for the target platform.
@@ -274,7 +274,7 @@ assert_eq!(std::mem::size_of::<SizeRoundedUp>(), 8); // Size of 6 from b,
274274
assert_eq!(std::mem::align_of::<SizeRoundedUp>(), 4); // From a
275275
```
276276

277-
#### \#[repr(C)] Field-less Enums
277+
#### `#[repr(C)]` Field-less Enums
278278

279279
For [field-less enums], the `C` representation has the size and alignment of
280280
the default `enum` size and alignment for the target platform's C ABI.
@@ -295,7 +295,7 @@ using a field-less enum in FFI to model a C `enum` is often wrong.
295295

296296
</div>
297297

298-
#### \#[repr(C)] Enums With Fields
298+
#### `#[repr(C)]` Enums With Fields
299299

300300
The representation of a `repr(C)` enum with fields is a `repr(C)` struct with
301301
two fields, also called a "tagged union" in C:
@@ -369,7 +369,7 @@ the primitive integer types. That is: `u8`, `u16`, `u32`, `u64`, `u128`,
369369

370370
Primitive representations can only be applied to enumerations and have
371371
different behavior whether the enum has fields or no fields. It is an error
372-
for [zero-variant enumerations] to have a primitive representation. Combining
372+
for [zero-variant enums] to have a primitive representation. Combining
373373
two primitive representations together is an error.
374374

375375
#### Primitive Representation of Field-less Enums
@@ -433,7 +433,7 @@ struct MyVariantD(MyEnumDiscriminant);
433433

434434
> Note: `union`s with non-`Copy` fields are unstable, see [55149].
435435
436-
#### Combining primitive representations of enums with fields and \#[repr(C)]
436+
#### Combining primitive representations of enums with fields and `#[repr(C)]`
437437

438438
For enums with fields, it is also possible to combine `repr(C)` and a
439439
primitive representation (e.g., `repr(C, u8)`). This modifies the [`repr(C)`] by

src/types/function-pointer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ restrictions as [regular function parameters].
6060
[extern function]: ../items/functions.md#extern-function-qualifier
6161
[function items]: function-item.md
6262
[unsafe function]: ../unsafe-functions.md
63-
[regular function parameters]: ../items/functions.md#attributes-on-function-parameters
63+
[regular function parameters]: ../items/functions.md#attributes-on-function-parameters

stable-check/Cargo.lock

-6
This file was deleted.

stable-check/src/main.rs

-42
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)