Skip to content

Commit 0599f34

Browse files
committed
Auto merge of #87472 - inquisitivecrystal:stabilize-force-warn, r=Mark-Simulacrum
Stabilize and document `--force-warn` This PR will stabilize and document the `--force-warn` command line option. It is currently a draft, pending an FCP. I've taken the liberty of tidying up the lint level command line options a bit as part of this. The changes are quite minor and should only affect rustc's help output. I'm making them here because they're trivial and, in one case, necessary to unify the way `--force-warn` with the way the other options are displayed. I also want to mention that `@rylev` has done a ton of work on moving this along and deserves most of the credit. I'm just the one who landed up writing this particular PR. Resolves #86516.
2 parents b5fe3bc + 1f3170c commit 0599f34

21 files changed

+53
-90
lines changed

compiler/rustc_session/src/config.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,11 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
10891089
),
10901090
opt::flag_s("", "test", "Build a test harness"),
10911091
opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
1092-
opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
1093-
opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
1094-
opt::multi_s("D", "deny", "Set lint denied", "OPT"),
1095-
opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"),
1092+
opt::multi_s("A", "allow", "Set lint allowed", "LINT"),
1093+
opt::multi_s("W", "warn", "Set lint warnings", "LINT"),
1094+
opt::multi_s("", "force-warn", "Set lint force-warn", "LINT"),
1095+
opt::multi_s("D", "deny", "Set lint denied", "LINT"),
1096+
opt::multi_s("F", "forbid", "Set lint forbidden", "LINT"),
10961097
opt::multi_s(
10971098
"",
10981099
"cap-lints",
@@ -1101,13 +1102,6 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11011102
level",
11021103
"LEVEL",
11031104
),
1104-
opt::multi_s(
1105-
"",
1106-
"force-warn",
1107-
"Specifiy lints that should warn even if \
1108-
they are allowed somewhere else",
1109-
"LINT",
1110-
),
11111105
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
11121106
opt::flag_s("V", "version", "Print version info and exit"),
11131107
opt::flag_s("v", "verbose", "Use verbose output"),
@@ -1163,19 +1157,10 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
11631157
pub fn get_cmd_lint_options(
11641158
matches: &getopts::Matches,
11651159
error_format: ErrorOutputType,
1166-
debugging_opts: &DebuggingOptions,
11671160
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
11681161
let mut lint_opts_with_position = vec![];
11691162
let mut describe_lints = false;
11701163

1171-
if !debugging_opts.unstable_options && matches.opt_present("force-warn") {
1172-
early_error(
1173-
error_format,
1174-
"the `-Z unstable-options` flag must also be passed to enable \
1175-
the flag `--force-warn=lints`",
1176-
);
1177-
}
1178-
11791164
for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] {
11801165
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
11811166
if lint_name == "help" {
@@ -1965,8 +1950,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
19651950
.unwrap_or_else(|e| early_error(error_format, &e[..]));
19661951

19671952
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
1968-
let (lint_opts, describe_lints, lint_cap) =
1969-
get_cmd_lint_options(matches, error_format, &debugging_opts);
1953+
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
19701954

19711955
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
19721956

src/doc/rustc/src/lints/levels.md

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Lint levels
22

3-
In `rustc`, lints are divided into four *levels*:
3+
In `rustc`, lints are divided into five *levels*:
44

55
1. allow
66
2. warn
7-
3. deny
8-
4. forbid
7+
3. force-warn
8+
4. deny
9+
5. forbid
910

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

61+
## force-warn
62+
63+
'force-warn' is a special lint level. It's the same as 'warn' in that a lint
64+
at this level will produce a warning, but unlike the 'warn' level, the
65+
'force-warn' level cannot be overridden. If a lint is set to 'force-warn', it
66+
is guaranteed to warn: no more, no less. This is true even if the overall lint
67+
level is capped via cap-lints.
68+
6069
## deny
6170

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

8897
## forbid
8998

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

97107
## Configuring warning levels
@@ -113,8 +123,8 @@ certain lint levels. We'll talk about that last.
113123
114124
### Via compiler flag
115125
116-
The `-A`, `-W`, `-D`, and `-F` flags let you turn one or more lints
117-
into allowed, warning, deny, or forbid levels, like this:
126+
The `-A`, `-W`, `--force-warn` `-D`, and `-F` flags let you turn one or more lints
127+
into allowed, warning, force-warn, deny, or forbid levels, like this:
118128
119129
```bash
120130
$ rustc lib.rs --crate-type=lib -W missing-docs
@@ -158,7 +168,7 @@ You can also pass each flag more than once for changing multiple lints:
158168
$ rustc lib.rs --crate-type=lib -D missing-docs -D unused-variables
159169
```
160170
161-
And of course, you can mix these four flags together:
171+
And of course, you can mix these five flags together:
162172
163173
```bash
164174
$ rustc lib.rs --crate-type=lib -D missing-docs -A unused-variables
@@ -176,6 +186,10 @@ You can make use of this behavior by overriding the level of one specific lint o
176186
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
177187
```
178188
189+
Since `force-warn` and `forbid` cannot be overridden, setting
190+
one of them will prevent any later level for the same lint from
191+
taking effect.
192+
179193
### Via an attribute
180194
181195
You can also modify the lint level with a crate-wide attribute:
@@ -207,7 +221,8 @@ warning: missing documentation for a function
207221
| ^^^^^^^^^^^^
208222
```
209223
210-
All four, `warn`, `allow`, `deny`, and `forbid` all work this way.
224+
`warn`, `allow`, `deny`, and `forbid` all work this way. There is
225+
no way to set a lint to `force-warn` using an attribute.
211226
212227
You can also pass in multiple lints per attribute:
213228

src/doc/unstable-book/src/compiler-flags/force-warn.md

-21
This file was deleted.

src/librustdoc/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ impl Options {
671671
return Err(1);
672672
}
673673

674-
let (lint_opts, describe_lints, lint_cap) =
675-
get_cmd_lint_options(matches, error_format, &debugging_opts);
674+
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
676675

677676
Ok(Options {
678677
input,

src/librustdoc/lib.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,11 @@ fn opts() -> Vec<RustcOptGroup> {
503503
unstable("disable-minification", |o| {
504504
o.optflagmulti("", "disable-minification", "Disable minification applied on JS files")
505505
}),
506-
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")),
507-
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")),
508-
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "OPT")),
509-
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "OPT")),
506+
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")),
507+
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")),
508+
stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")),
509+
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")),
510+
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")),
510511
stable("cap-lints", |o| {
511512
o.optmulti(
512513
"",
@@ -517,14 +518,6 @@ fn opts() -> Vec<RustcOptGroup> {
517518
"LEVEL",
518519
)
519520
}),
520-
unstable("force-warn", |o| {
521-
o.optopt(
522-
"",
523-
"force-warn",
524-
"Lints that will warn even if allowed somewhere else",
525-
"LINTS",
526-
)
527-
}),
528521
unstable("index-page", |o| {
529522
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
530523
}),

src/test/run-make/unstable-flag-required/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
all:
44
$(RUSTDOC) --output-format=json x.html 2>&1 | diff - output-format-json.stderr
5-
$(RUSTC) --force-warn dead_code x.rs 2>&1 | diff - force-warn.stderr

src/test/run-make/unstable-flag-required/force-warn.stderr

-2
This file was deleted.

src/test/ui/lint/cli-lint-override.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
//[warn_deny] compile-flags: --warn missing_abi --deny missing_abi
77
//[forbid_warn] compile-flags: --warn missing_abi --forbid missing_abi
8-
//[force_warn_deny] compile-flags: -Z unstable-options --force-warn missing_abi --allow missing_abi
8+
//[force_warn_deny] compile-flags: --force-warn missing_abi --allow missing_abi
99
//[force_warn_deny] check-pass
1010

1111

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Checks that rustc correctly errors when passed an invalid lint with
22
// `--force-warn`. This is a regression test for issue #86958.
33
//
4-
// compile-flags: -Z unstable-options --force-warn foo-qux
4+
// compile-flags: --force-warn foo-qux
55
// error-pattern: unknown lint: `foo_qux`
66

77
fn main() {}

src/test/ui/lint/cli-unknown-force-warn.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ error[E0602]: unknown lint: `foo_qux`
66
|
77
= note: requested on the command line with `--force-warn foo_qux`
88

9-
error[E0602]: unknown lint: `foo_qux`
10-
|
11-
= note: requested on the command line with `--force-warn foo_qux`
12-
13-
error: aborting due to 3 previous errors
9+
error: aborting due to 2 previous errors
1410

1511
For more information about this error, try `rustc --explain E0602`.

src/test/ui/lint/force-warn/allow-warnings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
22
// despite allowing all warnings in module
3-
// compile-flags: --force-warn dead_code -Zunstable-options
3+
// compile-flags: --force-warn dead_code
44
// check-pass
55

66
#![allow(warnings)]

src/test/ui/lint/force-warn/allowed-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// --force-warn $LINT causes $LINT (which is allow-by-default) to warn
2-
// compile-flags: --force-warn elided_lifetimes_in_paths -Zunstable-options
2+
// compile-flags: --force-warn elided_lifetimes_in_paths
33
// check-pass
44

55
struct Foo<'a> {

src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
22
// despite $LINT being allowed in module
3-
// compile-flags: --force-warn const_err -Zunstable-options
3+
// compile-flags: --force-warn const_err
44
// check-pass
55

66
#![allow(const_err)]

src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
22
// despite $LINT_GROUP (which contains $LINT) being allowed
3-
// compile-flags: --force-warn bare_trait_objects -Zunstable-options
3+
// compile-flags: --force-warn bare_trait_objects
44
// check-pass
55

66
#![allow(rust_2018_idioms)]

src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
22
// despite $LINT being allowed in module
3-
// compile-flags: --force-warn dead_code -Zunstable-options
3+
// compile-flags: --force-warn dead_code
44
// check-pass
55

66
#![allow(dead_code)]

src/test/ui/lint/force-warn/cap-lints-allow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT casuses $LINT to warn despite --cap-lints
22
// set to allow
3-
// compile-flags: --cap-lints allow --force-warn bare_trait_objects -Zunstable-options
3+
// compile-flags: --cap-lints allow --force-warn bare_trait_objects
44
// check-pass
55

66
pub trait SomeTrait {}

src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT_GROUP causes $LINT to warn despite $LINT being
22
// allowed in module and cap-lints set to warn
3-
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility -Zunstable-options
3+
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility
44
// check-pass
55
#![allow(ellipsis_inclusive_range_patterns)]
66

src/test/ui/lint/force-warn/deny-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
2-
// compile-flags: --force-warn const_err -Zunstable-options
2+
// compile-flags: --force-warn const_err
33
// check-pass
44

55
const C: i32 = 1 / 0;

src/test/ui/lint/force-warn/lint-group-allow-warnings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// --force-warn $LINT_GROUP causes $LINT in $LINT_GROUP to warn
22
// despite all warnings being allowed in module
33
// warn-by-default lint to warn
4-
// compile-flags: --force-warn nonstandard_style -Zunstable-options
4+
// compile-flags: --force-warn nonstandard_style
55
// check-pass
66

77
#![allow(warnings)]

src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT_GROUP causes $LINT to warn despite
22
// $LINT_GROUP being allowed in module
3-
// compile-flags: --force-warn rust_2018_idioms -Zunstable-options
3+
// compile-flags: --force-warn rust_2018_idioms
44
// check-pass
55

66
#![allow(rust_2018_idioms)]

src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
22
// despite $LINT being allowed in module
3-
// compile-flags: --force-warn rust-2018-idioms -Zunstable-options
3+
// compile-flags: --force-warn rust-2018-idioms
44
// check-pass
55

66
#![allow(bare_trait_objects)]

0 commit comments

Comments
 (0)