-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add unstable --print=crate-root-lint-levels
#139184
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/doc/unstable-book/src/compiler-flags/print-crate-root-lint-levels.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# `print=crate-root-lint-levels` | ||
|
||
The tracking issue for this feature is: [#139180](https://github.com/rust-lang/rust/issues/139180). | ||
|
||
------------------------ | ||
|
||
This option of the `--print` flag print the list of lints with print out all the lints and their associated levels (`allow`, `warn`, `deny`, `forbid`) based on the regular Rust rules at crate root, that is *(roughly)*: | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- command line args (`-W`, `-A`, `--force-warn`, `--cap-lints`, ...) | ||
- crate root attributes (`#![allow]`, `#![warn]`, `#[expect]`, ...) | ||
- *the special `warnings` lint group* | ||
- the default lint level | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The output format is `LINT_NAME=LINT_LEVEL`, e.g.: | ||
```text | ||
unknown_lint=warn | ||
arithmetic_overflow=deny | ||
``` | ||
|
||
To be used like this: | ||
|
||
```bash | ||
rustc --print=crate-root-lint-levels -Zunstable-options lib.rs | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![allow(unexpected_cfgs)] | ||
#![expect(unused_mut)] | ||
|
||
#[deny(unknown_lints)] | ||
mod my_mod {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
//! This checks the output of `--print=crate-root-lint-levels` | ||
|
||
extern crate run_make_support; | ||
|
||
use std::collections::HashSet; | ||
use std::iter::FromIterator; | ||
|
||
use run_make_support::rustc; | ||
|
||
struct CrateRootLintLevels { | ||
args: &'static [&'static str], | ||
contains: Contains, | ||
} | ||
|
||
struct Contains { | ||
contains: &'static [&'static str], | ||
doesnt_contain: &'static [&'static str], | ||
} | ||
|
||
fn main() { | ||
check(CrateRootLintLevels { | ||
args: &[], | ||
contains: Contains { | ||
contains: &[ | ||
"unexpected_cfgs=allow", | ||
"unused_mut=expect", | ||
"warnings=warn", | ||
"stable_features=warn", | ||
"unknown_lints=warn", | ||
], | ||
doesnt_contain: &["unexpected_cfgs=warn", "unused_mut=warn"], | ||
}, | ||
}); | ||
check(CrateRootLintLevels { | ||
args: &["-Wunexpected_cfgs"], | ||
contains: Contains { | ||
contains: &["unexpected_cfgs=allow", "warnings=warn"], | ||
doesnt_contain: &["unexpected_cfgs=warn"], | ||
}, | ||
}); | ||
check(CrateRootLintLevels { | ||
args: &["-Dwarnings"], | ||
contains: Contains { | ||
contains: &[ | ||
"unexpected_cfgs=allow", | ||
"warnings=deny", | ||
"stable_features=deny", | ||
"unknown_lints=deny", | ||
], | ||
doesnt_contain: &["warnings=warn"], | ||
}, | ||
}); | ||
check(CrateRootLintLevels { | ||
args: &["-Dstable_features"], | ||
contains: Contains { | ||
contains: &["warnings=warn", "stable_features=deny", "unexpected_cfgs=allow"], | ||
doesnt_contain: &["warnings=deny"], | ||
}, | ||
}); | ||
check(CrateRootLintLevels { | ||
args: &["-Dwarnings", "--force-warn=stable_features"], | ||
contains: Contains { | ||
contains: &["warnings=deny", "stable_features=force-warn", "unknown_lints=deny"], | ||
doesnt_contain: &["warnings=warn"], | ||
}, | ||
}); | ||
check(CrateRootLintLevels { | ||
args: &["-Dwarnings", "--cap-lints=warn"], | ||
contains: Contains { | ||
contains: &[ | ||
"unexpected_cfgs=allow", | ||
"warnings=warn", | ||
"stable_features=warn", | ||
"unknown_lints=warn", | ||
], | ||
doesnt_contain: &["warnings=deny"], | ||
}, | ||
}); | ||
} | ||
|
||
#[track_caller] | ||
fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) { | ||
let output = rustc() | ||
.input("lib.rs") | ||
.arg("-Zunstable-options") | ||
.print("crate-root-lint-levels") | ||
.args(args) | ||
.run(); | ||
|
||
let stdout = output.stdout_utf8(); | ||
|
||
let mut found = HashSet::<String>::new(); | ||
|
||
for l in stdout.lines() { | ||
assert!(l == l.trim()); | ||
if let Some((left, right)) = l.split_once('=') { | ||
assert!(!left.contains("\"")); | ||
assert!(!right.contains("\"")); | ||
} else { | ||
assert!(l.contains('=')); | ||
} | ||
assert!(found.insert(l.to_string()), "{}", &l); | ||
} | ||
|
||
let Contains { contains, doesnt_contain } = contains; | ||
|
||
{ | ||
let should_found = HashSet::<String>::from_iter(contains.iter().map(|s| s.to_string())); | ||
let diff: Vec<_> = should_found.difference(&found).collect(); | ||
assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff); | ||
} | ||
{ | ||
let should_not_find = | ||
HashSet::<String>::from_iter(doesnt_contain.iter().map(|s| s.to_string())); | ||
let diff: Vec<_> = should_not_find.intersection(&found).collect(); | ||
assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Argument to option 'print' missing | ||
Usage: | ||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models] | ||
--print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models] | ||
Compiler information to print on stdout | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: unknown print request: `yyyy` | ||
| | ||
= help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` | ||
= help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` | ||
= help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
error: unknown print request: `lints` | ||
| | ||
= help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` | ||
= help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` | ||
= help: use `-Whelp` to print a list of lints | ||
= help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.