Skip to content

Commit 1e5a797

Browse files
committed
docs(ref): Copy over guide-level explanation
The implementation doesn't match this yet but this reflects what we'll be working towards.
1 parent 281a0f3 commit 1e5a797

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

src/doc/src/reference/unstable.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Each new feature described below should explain how to use it.
9393
* [codegen-backend](#codegen-backend) --- Select the codegen backend used by rustc.
9494
* [per-package-target](#per-package-target) --- Sets the `--target` to use for each individual package.
9595
* [artifact dependencies](#artifact-dependencies) --- Allow build artifacts to be included into other build artifacts and build them for different targets.
96-
* [`[lints]`](#lints) --- Configure lint levels for various linter tools
96+
* [`[lints]`](#lints) --- Configure lint levels for various linter tools.
9797
* Information and metadata
9898
* [Build-plan](#build-plan) --- Emits JSON information on which commands will be run.
9999
* [unit-graph](#unit-graph) --- Emits JSON for Cargo's internal graph structure.
@@ -1396,6 +1396,100 @@ Valid operations are the following:
13961396

13971397
* Tracking Issue: [#12115](https://github.com/rust-lang/cargo/issues/12115)
13981398

1399+
A new `lints` table would be added to configure lints:
1400+
```toml
1401+
cargo-features = ["lints"]
1402+
1403+
[lints.rust]
1404+
unsafe = "forbid"
1405+
```
1406+
and `cargo` would pass these along as flags to `rustc`, `clippy`, or other lint tools.
1407+
1408+
This would work with
1409+
[RFC 2906 `workspace-deduplicate`](https://rust-lang.github.io/rfcs/2906-cargo-workspace-deduplicate.html):
1410+
```toml
1411+
cargo-features = ["lints"]
1412+
1413+
[lints]
1414+
workspace = true
1415+
1416+
[workspace.lints.rust]
1417+
unsafe = "forbid"
1418+
```
1419+
1420+
#### Documentation Updates
1421+
1422+
##### The `lints` section
1423+
1424+
*as a new ["Manifest Format" entry](./manifest.html#the-manifest-format)*
1425+
1426+
Override the default level of lints from different tools by assigning them to a new level in a
1427+
table, for example:
1428+
```toml
1429+
[lints.rust]
1430+
unsafe = "forbid"
1431+
```
1432+
1433+
This is short-hand for:
1434+
```toml
1435+
[lints.rust]
1436+
unsafe = { level = "forbid", priority = 0 }
1437+
```
1438+
1439+
`level` corresponds to the lint levels in `rustc`:
1440+
- `forbid`
1441+
- `deny`
1442+
- `warn`
1443+
- `allow`
1444+
1445+
`priority` is a signed integer that controls which lints or lint groups override other lint groups:
1446+
- lower (particularly negative) numbers have lower priority, being overridden
1447+
by higher numbers, and show up first on the command-line to tools like
1448+
`rustc`
1449+
1450+
To know which table under `[lints]` a particular lint belongs under, it is the part before `::` in the lint
1451+
name. If there isn't a `::`, then the tool is `rust`. For example a warning
1452+
about `unsafe` would be `lints.rust.unsafe` but a lint about
1453+
`clippy::enum_glob_use` would be `lints.clippy.enum_glob_use`.
1454+
1455+
For example:
1456+
```toml
1457+
[lints.rust]
1458+
unsafe = "forbid"
1459+
1460+
[lints.clippy]
1461+
enum_glob_use = "deny"
1462+
```
1463+
1464+
##### The `lints` table
1465+
1466+
*as a new [`[workspace]` entry](./workspaces.html#the-workspace-section)*
1467+
1468+
The `workspace.lints` table is where you define lint configuration to be inherited by members of a workspace.
1469+
1470+
Specifying a workspace lint configuration is similar to package lints.
1471+
1472+
Example:
1473+
1474+
```toml
1475+
# [PROJECT_DIR]/Cargo.toml
1476+
[workspace]
1477+
members = ["crates/*"]
1478+
1479+
[workspace.lints.rust]
1480+
unsafe = "forbid"
1481+
```
1482+
1483+
```toml
1484+
# [PROJECT_DIR]/crates/bar/Cargo.toml
1485+
[package]
1486+
name = "bar"
1487+
version = "0.1.0"
1488+
1489+
[lints]
1490+
workspace = true
1491+
```
1492+
13991493
## Stabilized and removed features
14001494

14011495
### Compile progress

0 commit comments

Comments
 (0)