Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize and document --force-warn #87472

Merged
merged 4 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Document force-warn
Co-authored-by: Mark Rousskov <[email protected]>
  • Loading branch information
inquisitivecrystal and Mark-Simulacrum committed Aug 24, 2021
commit 228a5f40966de084fe4a81cf3aff9c531fa51799
39 changes: 27 additions & 12 deletions src/doc/rustc/src/lints/levels.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Lint levels

In `rustc`, lints are divided into four *levels*:
In `rustc`, lints are divided into five *levels*:

1. allow
2. warn
3. deny
4. forbid
3. force-warn
4. deny
5. forbid

Each lint has a default level (explained in the lint listing later in this
chapter), and the compiler has a default warning level. First, let's explain
Expand Down Expand Up @@ -57,6 +58,14 @@ warning: unused variable: `x`
= note: to avoid this warning, consider using `_x` instead
```

## force-warn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is in no way an actual blocker, but the lack of symmetry in naming between "forbid" and "force-warn" is kinda sad. Maybe I should open a proposal for "force-deny", heh.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force-deny would have a slightly different meaning: it would deny things in dependencies even if cap-lints is set.


'force-warn' is a special lint level. It's the same as 'warn' in that a lint
at this level will produce a warning, but unlike the 'warn' level, the
'force-warn' level cannot be overridden. If a lint is set to 'force-warn', it
is guaranteed to warn: no more, no less. This is true even if the overall lint
level is capped via cap-lints.

## deny

A 'deny' lint produces an error if you violate it. For example, this code
Expand Down Expand Up @@ -87,11 +96,12 @@ This lint level gives you that.

## forbid

'forbid' is a special lint level that's stronger than 'deny'. It's the same
as 'deny' in that a lint at this level will produce an error, but unlike the
'deny' level, the 'forbid' level can not be overridden to be anything lower
than an error. However, lint levels may still be capped with `--cap-lints`
(see below) so `rustc --cap-lints warn` will make lints set to 'forbid' just
'forbid' is a special lint level that fills the same role for 'deny' that
'force-warn' does for 'warn'. It's the same as 'deny' in that a lint at this
level will produce an error, but unlike the 'deny' level, the 'forbid' level
can not be overridden to be anything lower than an error. However, lint
levels may still be capped with `--cap-lints` (see below) so `rustc --cap-
lints warn` will make lints set to 'forbid' just
warn.

## Configuring warning levels
Expand All @@ -113,8 +123,8 @@ certain lint levels. We'll talk about that last.

### Via compiler flag

The `-A`, `-W`, `-D`, and `-F` flags let you turn one or more lints
into allowed, warning, deny, or forbid levels, like this:
The `-A`, `-W`, `--force-warn` `-D`, and `-F` flags let you turn one or more lints
into allowed, warning, force-warn, deny, or forbid levels, like this:

```bash
$ rustc lib.rs --crate-type=lib -W missing-docs
Expand Down Expand Up @@ -158,7 +168,7 @@ You can also pass each flag more than once for changing multiple lints:
$ rustc lib.rs --crate-type=lib -D missing-docs -D unused-variables
```

And of course, you can mix these four flags together:
And of course, you can mix these five flags together:

```bash
$ rustc lib.rs --crate-type=lib -D missing-docs -A unused-variables
Expand All @@ -176,6 +186,10 @@ You can make use of this behavior by overriding the level of one specific lint o
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
```

Since `force-warn` and `forbid` cannot be overridden, setting
one of them will prevent any later level for the same lint from
taking effect.

### Via an attribute

You can also modify the lint level with a crate-wide attribute:
Expand Down Expand Up @@ -207,7 +221,8 @@ warning: missing documentation for a function
| ^^^^^^^^^^^^
```

All four, `warn`, `allow`, `deny`, and `forbid` all work this way.
`warn`, `allow`, `deny`, and `forbid` all work this way. There is
no way to set a lint to `force-warn` using an attribute.

You can also pass in multiple lints per attribute:

Expand Down
21 changes: 0 additions & 21 deletions src/doc/unstable-book/src/compiler-flags/force-warn.md

This file was deleted.