Skip to content

Commit

Permalink
Merge pull request #886 from ehuss/style-check
Browse files Browse the repository at this point in the history
Add style checks.
  • Loading branch information
Havvy authored Oct 6, 2020
2 parents 0f6b234 + dd1b9c3 commit 2a6a5ad
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
mdbook --version
- name: Run tests
run: mdbook test
- name: Check for unstable features
run: (cd stable-check && cargo run -- ../src)
- name: Style checks
run: (cd style-check && cargo run -- ../src)
- name: Check for broken links
run: |
curl -sSLo linkcheck.sh \
Expand Down
4 changes: 4 additions & 0 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Some conventions and content guidelines are specified in the [introduction].
This document serves as a guide for editors and reviewers.

There is a [`style-check`](style-check/) tool which is run in CI to check some
of these. To use it locally, run
`cargo run --manifest-path=style-check/Cargo.toml src`.

## Markdown formatting

* Use ATX-style heading with sentence case.
Expand Down
8 changes: 4 additions & 4 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ otherwise undefined behavior results.

### Behavior

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

```rust
Expand Down Expand Up @@ -190,7 +190,7 @@ fn calls_f() {
```

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

```rust
# #[track_caller]
Expand Down
12 changes: 6 additions & 6 deletions src/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

> **<sup>Lexer</sup>**\
> LINE_COMMENT :\
> &nbsp;&nbsp; &nbsp;&nbsp; `//` (~[`/` `!`] | `//`) ~`\n`<sup>\*</sup>\
> &nbsp;&nbsp; &nbsp;&nbsp; `//` (~\[`/` `!`] | `//`) ~`\n`<sup>\*</sup>\
> &nbsp;&nbsp; | `//`
>
> BLOCK_COMMENT :\
> &nbsp;&nbsp; &nbsp;&nbsp; `/*` (~[`*` `!`] | `**` | _BlockCommentOrDoc_)
> &nbsp;&nbsp; &nbsp;&nbsp; `/*` (~\[`*` `!`] | `**` | _BlockCommentOrDoc_)
> (_BlockCommentOrDoc_ | ~`*/`)<sup>\*</sup> `*/`\
> &nbsp;&nbsp; | `/**/`\
> &nbsp;&nbsp; | `/***/`
>
> INNER_LINE_DOC :\
> &nbsp;&nbsp; `//!` ~[`\n` _IsolatedCR_]<sup>\*</sup>
> &nbsp;&nbsp; `//!` ~\[`\n` _IsolatedCR_]<sup>\*</sup>
>
> INNER_BLOCK_DOC :\
> &nbsp;&nbsp; `/*!` ( _BlockCommentOrDoc_ | ~[`*/` _IsolatedCR_] )<sup>\*</sup> `*/`
> &nbsp;&nbsp; `/*!` ( _BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_] )<sup>\*</sup> `*/`
>
> OUTER_LINE_DOC :\
> &nbsp;&nbsp; `///` (~`/` ~[`\n` _IsolatedCR_]<sup>\*</sup>)<sup>?</sup>
> &nbsp;&nbsp; `///` (~`/` ~\[`\n` _IsolatedCR_]<sup>\*</sup>)<sup>?</sup>
>
> OUTER_BLOCK_DOC :\
> &nbsp;&nbsp; `/**` (~`*` | _BlockCommentOrDoc_ )
> (_BlockCommentOrDoc_ | ~[`*/` _IsolatedCR_])<sup>\*</sup> `*/`
> (_BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_])<sup>\*</sup> `*/`
>
> _BlockCommentOrDoc_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; BLOCK_COMMENT\
Expand Down
2 changes: 1 addition & 1 deletion src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ smallest scope that contains the expression and is for one of the following:
* The second operand of a [lazy boolean expression].

> **Notes**:
>
>
> Temporaries that are created in the final expression of a function
> body are dropped *after* any named variables bound in the function body, as
> there is no smaller enclosing temporary scope.
Expand Down
8 changes: 4 additions & 4 deletions src/expressions/closure-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
> _ClosureParam_ :\
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> [_Pattern_]&nbsp;( `:` [_Type_] )<sup>?</sup>
A _closure expression_, also know as a lambda expression or a lambda, defines a
closure and denotes it as a value, in a single expression. A closure expression
is a pipe-symbol-delimited (`|`) list of irrefutable [patterns] followed by an
expression. Type annotations may optionally be added for the type of the
A _closure expression_, also know as a lambda expression or a lambda, defines a
closure and denotes it as a value, in a single expression. A closure expression
is a pipe-symbol-delimited (`|`) list of irrefutable [patterns] followed by an
expression. Type annotations may optionally be added for the type of the
parameters or for the return type. If there is a return type, the expression
used for the body of the closure must be a normal [block]. A closure expression
also may begin with the `move` keyword before the initial `|`.
Expand Down
14 changes: 7 additions & 7 deletions src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ function* or a *free const*. Contrast to an [associated item].

### Fundamental traits

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

### Fundamental type constructors

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

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

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

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

### Nominal types
Expand Down
4 changes: 2 additions & 2 deletions src/identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

> **<sup>Lexer:<sup>**\
> IDENTIFIER_OR_KEYWORD :\
> &nbsp;&nbsp; &nbsp;&nbsp; [`a`-`z` `A`-`Z`]&nbsp;[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>\*</sup>\
> &nbsp;&nbsp; | `_` [`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>+</sup>
> &nbsp;&nbsp; &nbsp;&nbsp; \[`a`-`z` `A`-`Z`]&nbsp;\[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>\*</sup>\
> &nbsp;&nbsp; | `_` \[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>+</sup>
>
> RAW_IDENTIFIER : `r#` IDENTIFIER_OR_KEYWORD <sub>*Except `crate`, `self`, `super`, `Self`*</sub>
>
Expand Down
2 changes: 1 addition & 1 deletion src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ attributes][attributes] are allowed directly after the `{` inside its [block].
This example shows an inner attribute on a function. The function will only be
available while running tests.

```
```rust
fn test_only() {
#![test]
}
Expand Down
2 changes: 1 addition & 1 deletion src/items/implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ least one of the following is true:

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


Expand Down
12 changes: 6 additions & 6 deletions src/macro-ambiguity.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ of this text is copied, and expanded upon in subsequent RFCs.
"match").
- `repetition` : a fragment that follows a regular repeating pattern
- `NT`: non-terminal, the various "meta-variables" or repetition matchers
that can appear in a matcher, specified in MBE syntax with a leading `$`
character.
that can appear in a matcher, specified in MBE syntax with a leading `$`
character.
- `simple NT`: a "meta-variable" non-terminal (further discussion below).
- `complex NT`: a repetition matching non-terminal, specified via repetition
operators (`\*`, `+`, `?`).
Expand Down Expand Up @@ -80,9 +80,9 @@ Greek letters "α" "β" "γ" "δ" stand for potentially empty token-tree sequen
and does not stand for a token-tree sequence.)

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/notation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The following notations are used by the *Lexer* and *Syntax* grammar snippets:
| x<sup>+</sup> | _MacroMatch_<sup>+</sup> | 1 or more of x |
| x<sup>a..b</sup> | HEX_DIGIT<sup>1..6</sup> | a to b repetitions of x |
| \| | `u8` \| `u16`, Block \| Item | Either one or another |
| [ ] | [`b` `B`] | Any of the characters listed |
| [ - ] | [`a`-`z`] | Any of the characters in the range |
| ~[ ] | ~[`b` `B`] | Any characters, except those listed |
| \[ ] | \[`b` `B`] | Any of the characters listed |
| \[ - ] | \[`a`-`z`] | Any of the characters in the range |
| ~\[ ] | ~\[`b` `B`] | Any characters, except those listed |
| ~`string` | ~`\n`, ~`*/` | Any characters, except this sequence |
| ( ) | (`,` _Parameter_)<sup>?</sup> | Groups items |

Expand Down
12 changes: 6 additions & 6 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ and numeric literal tokens are accepted only with suffixes from the list below.

> **<sup>Lexer</sup>**\
> CHAR_LITERAL :\
> &nbsp;&nbsp; `'` ( ~[`'` `\` \\n \\r \\t] | QUOTE_ESCAPE | ASCII_ESCAPE | UNICODE_ESCAPE ) `'`
> &nbsp;&nbsp; `'` ( ~\[`'` `\` \\n \\r \\t] | QUOTE_ESCAPE | ASCII_ESCAPE | UNICODE_ESCAPE ) `'`
>
> QUOTE_ESCAPE :\
> &nbsp;&nbsp; `\'` | `\"`
Expand All @@ -136,7 +136,7 @@ which must be _escaped_ by a preceding `U+005C` character (`\`).
> **<sup>Lexer</sup>**\
> STRING_LITERAL :\
> &nbsp;&nbsp; `"` (\
> &nbsp;&nbsp; &nbsp;&nbsp; ~[`"` `\` _IsolatedCR_]\
> &nbsp;&nbsp; &nbsp;&nbsp; ~\[`"` `\` _IsolatedCR_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | QUOTE_ESCAPE\
> &nbsp;&nbsp; &nbsp;&nbsp; | ASCII_ESCAPE\
> &nbsp;&nbsp; &nbsp;&nbsp; | UNICODE_ESCAPE\
Expand Down Expand Up @@ -338,13 +338,13 @@ literal_. The grammar for recognizing the two kinds of literals is mixed.
> HEX_LITERAL :\
> &nbsp;&nbsp; `0x` (HEX_DIGIT|`_`)<sup>\*</sup> HEX_DIGIT (HEX_DIGIT|`_`)<sup>\*</sup>
>
> BIN_DIGIT : [`0`-`1`]
> BIN_DIGIT : \[`0`-`1`]
>
> OCT_DIGIT : [`0`-`7`]
> OCT_DIGIT : \[`0`-`7`]
>
> DEC_DIGIT : [`0`-`9`]
> DEC_DIGIT : \[`0`-`9`]
>
> HEX_DIGIT : [`0`-`9` `a`-`f` `A`-`F`]
> HEX_DIGIT : \[`0`-`9` `a`-`f` `A`-`F`]
>
> INTEGER_SUFFIX :\
> &nbsp;&nbsp; &nbsp;&nbsp; `u8` | `u16` | `u32` | `u64` | `u128` | `usize`\
Expand Down
4 changes: 2 additions & 2 deletions src/type-coercions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Type coercions

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

Any conversions allowed by coercion can also be explicitly performed by the
Expand Down Expand Up @@ -55,7 +55,7 @@ sites are:
Foo { x: &mut 42 };
}
```

* Function results&mdash;either the final line of a block if it is not
semicolon-terminated or any expression in a `return` statement

Expand Down
12 changes: 6 additions & 6 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ for interfacing with the C programming language.
This representation can be applied to structs, unions, and enums. The exception
is [zero-variant enums] for which the `C` representation is an error.

#### \#[repr(C)] Structs
#### `#[repr(C)]` Structs

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

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

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

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

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

</div>

#### \#[repr(C)] Enums With Fields
#### `#[repr(C)]` Enums With Fields

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

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

#### Primitive Representation of Field-less Enums
Expand Down Expand Up @@ -433,7 +433,7 @@ struct MyVariantD(MyEnumDiscriminant);

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

For enums with fields, it is also possible to combine `repr(C)` and a
primitive representation (e.g., `repr(C, u8)`). This modifies the [`repr(C)`] by
Expand Down
2 changes: 1 addition & 1 deletion src/types/function-pointer.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ restrictions as [regular function parameters].
[extern function]: ../items/functions.md#extern-function-qualifier
[function items]: function-item.md
[unsafe function]: ../unsafe-functions.md
[regular function parameters]: ../items/functions.md#attributes-on-function-parameters
[regular function parameters]: ../items/functions.md#attributes-on-function-parameters
6 changes: 0 additions & 6 deletions stable-check/Cargo.lock

This file was deleted.

42 changes: 0 additions & 42 deletions stable-check/src/main.rs

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 2a6a5ad

Please sign in to comment.