Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
72b3347
use correct location for type tests in promoted consts
b-naber Sep 23, 2022
29cc36f
add test
b-naber Sep 23, 2022
39484ac
Move style guide to rust-lang/rust
joshtriplett Sep 24, 2022
9a9e827
triagebot.toml: Add autolabel for T-style
joshtriplett Sep 24, 2022
283c0e4
style-guide: Remove trailing space
joshtriplett Sep 24, 2022
9a72a66
style-guide: Fix broken links
joshtriplett Sep 24, 2022
69cafc0
always panic for invalid integer logarithm
Oct 2, 2022
6acc29f
add tests for panicking integer logarithms
Oct 2, 2022
b7dae8a
remove unneeded attributes
Oct 2, 2022
bde80f7
Add lint for diagnostic migration
naritanara Aug 22, 2022
2f74d1d
Migrate weak_lang_items.rs
naritanara Aug 22, 2022
17a4a68
Migrate derivable diagnostics in lang_items.rs
naritanara Sep 1, 2022
0315d7c
Migrate derivable diagnostics in check_attr.rs
naritanara Sep 2, 2022
2c3351c
Migrate InvalidAttrAtCrateLevel
naritanara Sep 2, 2022
c24a873
always put ftl message on next line, resolve all but 1 output compari…
CleanCut Sep 21, 2022
b8e03cf
use consistent names
CleanCut Sep 22, 2022
1222541
resolve merge conflict from cherry-picking 6a47326a0452cc8d5cb5767650…
diegooliveira Sep 14, 2022
c103c30
migrate the rest of weak_lang_items.rs to translateable diagnostics
CleanCut Sep 22, 2022
1e86226
migrate debugger_visualizer.rs to translateable diagnostics
CleanCut Sep 22, 2022
f8ebc72
errors: add `emit_note`/`create_note`
davidtwco Sep 1, 2022
3a74833
use cherry-picked commit from #100754 to emit note without error
CleanCut Sep 22, 2022
0609c0f
migrate diagnostic_items.rs to translateable diagnostics
CleanCut Sep 23, 2022
40d5f00
migrate layout_test.rs to translateable diagnostics
CleanCut Sep 23, 2022
c457abe
migrate lib_features.rs to translateable diagnostics
CleanCut Sep 24, 2022
572f341
migrate check_const.rs to translateable diagnostics
CleanCut Sep 24, 2022
69766e4
migrate loops.rs to translateable diagnostics
CleanCut Sep 26, 2022
96f92ea
migrate naked_functions.rs to translateable diagnostics
CleanCut Sep 27, 2022
b17ec43
migrate entry.rs to translateable diagnostics
CleanCut Sep 28, 2022
f0afb88
migrate lang_items.rs to translateable diagnostics
CleanCut Oct 1, 2022
a7aa185
migrate dead.rs to translateable diagnostics
CleanCut Oct 2, 2022
3fe8e00
migrate the rest of check_attr.rs to translateable diagnostics
CleanCut Oct 2, 2022
be4059d
migrate stability.rs to translateable diagnostics
CleanCut Oct 3, 2022
965dbf6
First batch of review feedback changes from #102110
CleanCut Oct 3, 2022
8e07a85
Remove code that was removed in master, and the corresponding diagnostic
CleanCut Oct 5, 2022
57eba4f
avoid string dispatch in fluent
CleanCut Oct 5, 2022
31c269a
avoid string dispatch in fluent
CleanCut Oct 7, 2022
b9e4a1c
use memset to initialize a readbuf
the8472 Oct 8, 2022
50e2795
remove out-of-date fixme
CleanCut Oct 10, 2022
5ef1c03
make up your mind, rustfmt
CleanCut Oct 10, 2022
d933092
Check representability in adt_sized_constraint
camsteffen Oct 10, 2022
b5963f0
rustdoc: remove unused classes from sidebar
notriddle Oct 11, 2022
062284a
rustdoc: remove unneeded `.content` selector from link colors
notriddle Oct 11, 2022
a7f58af
unify `IsPattern` and `IsImport` enum
SparrowLii Oct 12, 2022
32471a7
Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, …
Dylan-DPC Oct 12, 2022
5e04567
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
Dylan-DPC Oct 12, 2022
f8723f9
Rollup merge of #102239 - joshtriplett:style-guide, r=calebcartwright
Dylan-DPC Oct 12, 2022
d8091f8
Rollup merge of #102578 - lukas-code:ilog-panic, r=m-ou-se
Dylan-DPC Oct 12, 2022
658169b
Rollup merge of #102811 - the8472:bufread-memset, r=m-ou-se
Dylan-DPC Oct 12, 2022
c8a8e7d
Rollup merge of #102890 - camsteffen:adt-sized-representability, r=cj…
Dylan-DPC Oct 12, 2022
252ce10
Rollup merge of #102913 - SparrowLii:import-candidate, r=compiler-errors
Dylan-DPC Oct 12, 2022
96bcced
Rollup merge of #102924 - notriddle:notriddle/sidebar-link-class, r=G…
Dylan-DPC Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move style guide to rust-lang/rust
  • Loading branch information
joshtriplett committed Sep 24, 2022
commit 39484ac3b0b80c1c98c4d46a9f88336c02f24da6
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ impl<'a> Builder<'a> {
doc::Miri,
doc::EmbeddedBook,
doc::EditionGuide,
doc::StyleGuide,
),
Kind::Dist => describe!(
dist::Docs,
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ book!(
Reference, "src/doc/reference", "reference", submodule;
RustByExample, "src/doc/rust-by-example", "rust-by-example", submodule;
RustdocBook, "src/doc/rustdoc", "rustdoc";
StyleGuide, "src/doc/style-guide", "style-guide";
);

fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
Expand Down
6 changes: 6 additions & 0 deletions src/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ resources useful.
[The Reference](reference/index.html) is not a formal spec, but is more detailed and
comprehensive than the book.

## The Style Guide

[The Rust Style Guide](style-guide/index.html) describes the standard formatting of Rust
code. Most developers use rustfmt to format their code, and rustfmt's default
formatting matches this style guide.

## The Rustonomicon

[The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of unsafe
Expand Down
8 changes: 8 additions & 0 deletions src/doc/style-guide/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[book]
title = "The Rust Style Guide"
author = "The Rust Style Team"
multilingual = false
src = "src"

[output.html]
git-repository-url = "https://github.com/rust-lang/rust/tree/HEAD/src/doc/style-guide/"
190 changes: 190 additions & 0 deletions src/doc/style-guide/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# Rust Style Guide

## Motivation - why use a formatting tool?

Formatting code is a mostly mechanical task which takes both time and mental
effort. By using an automatic formatting tool, a programmer is relieved of
this task and can concentrate on more important things.

Furthermore, by sticking to an established style guide (such as this one),
programmers don't need to formulate ad hoc style rules, nor do they need to
debate with other programmers what style rules should be used, saving time,
communication overhead, and mental energy.

Humans comprehend information through pattern matching. By ensuring that all
Rust code has similar formatting, less mental effort is required to comprehend a
new project, lowering the barrier to entry for new developers.

Thus, there are productivity benefits to using a formatting tool (such as
rustfmt), and even larger benefits by using a community-consistent formatting,
typically by using a formatting tool's default settings.


## Formatting conventions

### Indentation and line width

* Use spaces, not tabs.
* Each level of indentation must be four spaces (that is, all indentation
outside of string literals and comments must be a multiple of four).
* The maximum width for a line is 100 characters.
* A tool should be configurable for all three of these variables.


### Blank lines

Separate items and statements by either zero or one blank lines (i.e., one or
two newlines). E.g,

```rust
fn foo() {
let x = ...;

let y = ...;
let z = ...;
}

fn bar() {}
fn baz() {}
```

Formatting tools should make the bounds on blank lines configurable: there
should be separate minimum and maximum numbers of newlines between both
statements and (top-level) items (i.e., four options). As described above, the
defaults for both statements and items should be minimum: 1, maximum: 2.


### [Module-level items](items.md)
### [Statements](statements.md)
### [Expressions](expressions.md)
### [Types](types.md)


### Comments

The following guidelines for comments are recommendations only, a mechanical
formatter might skip formatting of comments.

Prefer line comments (`//`) to block comments (`/* ... */`).

When using line comments there should be a single space after the opening sigil.

When using single-line block comments there should be a single space after the
opening sigil and before the closing sigil. Multi-line block comments should
have a newline after the opening sigil and before the closing sigil.

Prefer to put a comment on its own line. Where a comment follows code, there
should be a single space before it. Where a block comment is inline, there
should be surrounding whitespace as if it were an identifier or keyword. There
should be no trailing whitespace after a comment or at the end of any line in a
multi-line comment. Examples:

```rust
// A comment on an item.
struct Foo { ... }

fn foo() {} // A comment after an item.

pub fn foo(/* a comment before an argument */ x: T) {...}
```

Comments should usually be complete sentences. Start with a capital letter, end
with a period (`.`). An inline block comment may be treated as a note without
punctuation.

Source lines which are entirely a comment should be limited to 80 characters
in length (including comment sigils, but excluding indentation) or the maximum
width of the line (including comment sigils and indentation), whichever is
smaller:

```rust
// This comment goes up to the ................................. 80 char margin.

{
// This comment is .............................................. 80 chars wide.
}

{
{
{
{
{
{
// This comment is limited by the ......................... 100 char margin.
}
}
}
}
}
}
```

#### Doc comments

Prefer line comments (`///`) to block comments (`/** ... */`).

Prefer outer doc comments (`///` or `/** ... */`), only use inner doc comments
(`//!` and `/*! ... */`) to write module-level or crate-level documentation.

Doc comments should come before attributes.

### Attributes

Put each attribute on its own line, indented to the level of the item.
In the case of inner attributes (`#!`), indent it to the level of the inside of
the item. Prefer outer attributes, where possible.

For attributes with argument lists, format like functions.

```rust
#[repr(C)]
#[foo(foo, bar)]
struct CRepr {
#![repr(C)]
x: f32,
y: f32,
}
```

For attributes with an equal sign, there should be a single space before and
after the `=`, e.g., `#[foo = 42]`.

There must only be a single `derive` attribute. Note for tool authors: if
combining multiple `derive` attributes into a single attribute, the ordering of
the derived names should be preserved. E.g., `#[derive(bar)] #[derive(foo)]
struct Baz;` should be formatted to `#[derive(bar, foo)] struct Baz;`.

### *small* items

In many places in this guide we specify that a formatter may format an item
differently if it is *small*, for example struct literals:

```rust
// Normal formatting
Foo {
f1: an_expression,
f2: another_expression(),
}

// *small* formatting
Foo { f1, f2 }
```

We leave it to individual tools to decide on exactly what *small* means. In
particular, tools are free to use different definitions in different
circumstances.

Some suitable heuristics are the size of the item (in characters) or the
complexity of an item (for example, that all components must be simple names,
not more complex sub-expressions). For more discussion on suitable heuristics,
see [this issue](https://github.com/rust-lang-nursery/fmt-rfcs/issues/47).

Tools should give the user an option to ignore such heuristics and always use
the normal formatting.


## [Non-formatting conventions](advice.md)

## [Cargo.toml conventions](cargo.md)

## [Principles used for deciding these guidelines](principles.md)
11 changes: 11 additions & 0 deletions src/doc/style-guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Summary

[Introduction](README.md)

- [Module-level items](items.md)
- [Statements](statements.md)
- [Expressions](expressions.md)
- [Types](types.md)
- [Non-formatting conventions](advice.md)
- [`Cargo.toml` conventions](cargo.md)
- [Principles used for deciding these guidelines](principles.md)
34 changes: 34 additions & 0 deletions src/doc/style-guide/src/advice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Other style advice

## Expressions

Prefer to use Rust's expression oriented nature where possible;

```rust
// use
let x = if y { 1 } else { 0 };
// not
let x;
if y {
x = 1;
} else {
x = 0;
}
```

## Names

* Types shall be `UpperCamelCase`,
* Enum variants shall be `UpperCamelCase`,
* Struct fields shall be `snake_case`,
* Function and method names shall be `snake_case`,
* Local variables shall be `snake_case`,
* Macro names shall be `snake_case`,
* Constants (`const`s and immutable `static`s) shall be `SCREAMING_SNAKE_CASE`.
* When a name is forbidden because it is a reserved word (e.g., `crate`), use a
trailing underscore to make the name legal (e.g., `crate_`), or use raw
identifiers if possible.

### Modules

Avoid `#[path]` annotations where possible.
78 changes: 78 additions & 0 deletions src/doc/style-guide/src/cargo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Cargo.toml conventions

## Formatting conventions

Use the same line width and indentation as Rust code.

Put a blank line between the last key-value pair in a section and the header of
the next section. Do not place a blank line between section headers and the
key-value pairs in that section, or between key-value pairs in a section.

Sort key names alphabetically within each section, with the exception of the
`[package]` section. Put the `[package]` section at the top of the file; put
the `name` and `version` keys in that order at the top of that section,
followed by the remaining keys other than `description` in alphabetical order,
followed by the `description` at the end of that section.

Don't use quotes around any standard key names; use bare keys. Only use quoted
keys for non-standard keys whose names require them, and avoid introducing such
key names when possible. See the [TOML
specification](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md#table)
for details.

Put a single space both before and after the `=` between a key and value. Do
not indent any key names; start all key names at the start of a line.

Use multi-line strings (rather than newline escape sequences) for any string
values that include multiple lines, such as the crate description.

For array values, such as a list of authors, put the entire list on the same
line as the key, if it fits. Otherwise, use block indentation: put a newline
after the opening square bracket, indent each item by one indentation level,
put a comma after each item (including the last), and put the closing square
bracket at the start of a line by itself after the last item.

```rust
authors = [
"A Uthor <[email protected]>",
"Another Author <[email protected]>",
]
```

For table values, such as a crate dependency with a path, write the entire
table using curly braces and commas on the same line as the key if it fits. If
the entire table does not fit on the same line as the key, separate it out into
a separate section with key-value pairs:

```toml
[dependencies]
crate1 = { path = "crate1", version = "1.2.3" }

[dependencies.extremely_long_crate_name_goes_here]
path = "extremely_long_path_name_goes_right_here"
version = "4.5.6"
```

## Metadata conventions

The authors list should consist of strings that each contain an author name
followed by an email address in angle brackets: `Full Name <email@address>`.
It should not contain bare email addresses, or names without email addresses.
(The authors list may also include a mailing list address without an associated
name.)

The license field must contain a valid [SPDX
expression](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60),
using valid [SPDX license names](https://spdx.org/licenses/). (As an exception,
by widespread convention, the license field may use `/` in place of ` OR `; for
example, `MIT/Apache-2.0`.)

The homepage field, if present, must consist of a single URL, including the
scheme (e.g. `https://example.org/`, not just `example.org`.)

Within the description field, wrap text at 80 columns. Don't start the
description field with the name of the crate (e.g. "cratename is a ..."); just
describe the crate itself. If providing a multi-sentence description, the first
sentence should go on a line by itself and summarize the crate, like the
subject of an email or commit message; subsequent sentences can then describe
the crate in more detail.
Loading