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
Changes from all commits
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
28 changes: 6 additions & 22 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
@@ -1089,10 +1089,11 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
),
opt::flag_s("", "test", "Build a test harness"),
opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
opt::multi_s("D", "deny", "Set lint denied", "OPT"),
opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"),
opt::multi_s("A", "allow", "Set lint allowed", "LINT"),
opt::multi_s("W", "warn", "Set lint warnings", "LINT"),
opt::multi_s("", "force-warn", "Set lint force-warn", "LINT"),
opt::multi_s("D", "deny", "Set lint denied", "LINT"),
opt::multi_s("F", "forbid", "Set lint forbidden", "LINT"),
opt::multi_s(
"",
"cap-lints",
@@ -1101,13 +1102,6 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
level",
"LEVEL",
),
opt::multi_s(
"",
"force-warn",
"Specifiy lints that should warn even if \
they are allowed somewhere else",
"LINT",
),
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
opt::flag_s("V", "version", "Print version info and exit"),
opt::flag_s("v", "verbose", "Use verbose output"),
@@ -1163,19 +1157,10 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
pub fn get_cmd_lint_options(
matches: &getopts::Matches,
error_format: ErrorOutputType,
debugging_opts: &DebuggingOptions,
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
let mut lint_opts_with_position = vec![];
let mut describe_lints = false;

if !debugging_opts.unstable_options && matches.opt_present("force-warn") {
early_error(
error_format,
"the `-Z unstable-options` flag must also be passed to enable \
the flag `--force-warn=lints`",
);
}

for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] {
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
if lint_name == "help" {
@@ -1965,8 +1950,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
.unwrap_or_else(|e| early_error(error_format, &e[..]));

let mut debugging_opts = DebuggingOptions::build(matches, error_format);
let (lint_opts, describe_lints, lint_cap) =
get_cmd_lint_options(matches, error_format, &debugging_opts);
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

check_debug_option_stability(&debugging_opts, error_format, json_rendered);

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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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:
@@ -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:
21 changes: 0 additions & 21 deletions src/doc/unstable-book/src/compiler-flags/force-warn.md

This file was deleted.

3 changes: 1 addition & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
@@ -671,8 +671,7 @@ impl Options {
return Err(1);
}

let (lint_opts, describe_lints, lint_cap) =
get_cmd_lint_options(matches, error_format, &debugging_opts);
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

Ok(Options {
input,
17 changes: 5 additions & 12 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
@@ -503,10 +503,11 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("disable-minification", |o| {
o.optflagmulti("", "disable-minification", "Disable minification applied on JS files")
}),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")),
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "OPT")),
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "OPT")),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")),
stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")),
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")),
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")),
stable("cap-lints", |o| {
o.optmulti(
"",
@@ -517,14 +518,6 @@ fn opts() -> Vec<RustcOptGroup> {
"LEVEL",
)
}),
unstable("force-warn", |o| {
o.optopt(
"",
"force-warn",
"Lints that will warn even if allowed somewhere else",
"LINTS",
)
}),
unstable("index-page", |o| {
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
}),
1 change: 0 additions & 1 deletion src/test/run-make/unstable-flag-required/Makefile
Original file line number Diff line number Diff line change
@@ -2,4 +2,3 @@

all:
$(RUSTDOC) --output-format=json x.html 2>&1 | diff - output-format-json.stderr
$(RUSTC) --force-warn dead_code x.rs 2>&1 | diff - force-warn.stderr
2 changes: 0 additions & 2 deletions src/test/run-make/unstable-flag-required/force-warn.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/ui/lint/cli-lint-override.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
//
//[warn_deny] compile-flags: --warn missing_abi --deny missing_abi
//[forbid_warn] compile-flags: --warn missing_abi --forbid missing_abi
//[force_warn_deny] compile-flags: -Z unstable-options --force-warn missing_abi --allow missing_abi
//[force_warn_deny] compile-flags: --force-warn missing_abi --allow missing_abi
//[force_warn_deny] check-pass


2 changes: 1 addition & 1 deletion src/test/ui/lint/cli-unknown-force-warn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Checks that rustc correctly errors when passed an invalid lint with
// `--force-warn`. This is a regression test for issue #86958.
//
// compile-flags: -Z unstable-options --force-warn foo-qux
// compile-flags: --force-warn foo-qux
// error-pattern: unknown lint: `foo_qux`

fn main() {}
6 changes: 1 addition & 5 deletions src/test/ui/lint/cli-unknown-force-warn.stderr
Original file line number Diff line number Diff line change
@@ -6,10 +6,6 @@ error[E0602]: unknown lint: `foo_qux`
|
= note: requested on the command line with `--force-warn foo_qux`

error[E0602]: unknown lint: `foo_qux`
|
= note: requested on the command line with `--force-warn foo_qux`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0602`.
2 changes: 1 addition & 1 deletion src/test/ui/lint/force-warn/allow-warnings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite allowing all warnings in module
// compile-flags: --force-warn dead_code -Zunstable-options
// compile-flags: --force-warn dead_code
// check-pass

#![allow(warnings)]
2 changes: 1 addition & 1 deletion src/test/ui/lint/force-warn/allowed-by-default-lint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --force-warn $LINT causes $LINT (which is allow-by-default) to warn
// compile-flags: --force-warn elided_lifetimes_in_paths -Zunstable-options
// compile-flags: --force-warn elided_lifetimes_in_paths
// check-pass

struct Foo<'a> {
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn const_err -Zunstable-options
// compile-flags: --force-warn const_err
// check-pass

#![allow(const_err)]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite $LINT_GROUP (which contains $LINT) being allowed
// compile-flags: --force-warn bare_trait_objects -Zunstable-options
// compile-flags: --force-warn bare_trait_objects
// check-pass

#![allow(rust_2018_idioms)]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn dead_code -Zunstable-options
// compile-flags: --force-warn dead_code
// check-pass

#![allow(dead_code)]
2 changes: 1 addition & 1 deletion src/test/ui/lint/force-warn/cap-lints-allow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT casuses $LINT to warn despite --cap-lints
// set to allow
// compile-flags: --cap-lints allow --force-warn bare_trait_objects -Zunstable-options
// compile-flags: --cap-lints allow --force-warn bare_trait_objects
// check-pass

pub trait SomeTrait {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT_GROUP causes $LINT to warn despite $LINT being
// allowed in module and cap-lints set to warn
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility -Zunstable-options
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility
// check-pass
#![allow(ellipsis_inclusive_range_patterns)]

2 changes: 1 addition & 1 deletion src/test/ui/lint/force-warn/deny-by-default-lint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// compile-flags: --force-warn const_err -Zunstable-options
// compile-flags: --force-warn const_err
// check-pass

const C: i32 = 1 / 0;
2 changes: 1 addition & 1 deletion src/test/ui/lint/force-warn/lint-group-allow-warnings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// --force-warn $LINT_GROUP causes $LINT in $LINT_GROUP to warn
// despite all warnings being allowed in module
// warn-by-default lint to warn
// compile-flags: --force-warn nonstandard_style -Zunstable-options
// compile-flags: --force-warn nonstandard_style
// check-pass

#![allow(warnings)]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT_GROUP causes $LINT to warn despite
// $LINT_GROUP being allowed in module
// compile-flags: --force-warn rust_2018_idioms -Zunstable-options
// compile-flags: --force-warn rust_2018_idioms
// check-pass

#![allow(rust_2018_idioms)]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn rust-2018-idioms -Zunstable-options
// compile-flags: --force-warn rust-2018-idioms
// check-pass

#![allow(bare_trait_objects)]