diff options
| author | bors <bors@rust-lang.org> | 2020-11-26 18:51:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-26 18:51:45 +0000 |
| commit | 72da5a9d85a522b11e80d0fdd1fd95247d442604 (patch) | |
| tree | a8bb60c04cf42d64d9e8bbf5a56b0bed0cdf69c1 /compiler | |
| parent | 65ecc481fac7ceced57d973a580d0a7ccbdcb192 (diff) | |
| parent | e54c0600b4ba25b0f7af582d9878bfd5c88736bc (diff) | |
Auto merge of #77671 - flip1995:lint_list_always_plugins, r=oli-obk,Manishearth
Always print lints from plugins, if they're available Currently you can get a list of lints and lint groups by running `rustc -Whelp`. This prints an additional line at the end: ``` Compiler plugins can provide additional lints and lint groups. To see a listing of these, re-run `rustc -W help` with a crate filename. ``` Clippy is such a "compiler plugin", that provides additional lints. Running `clippy-driver -Whelp` (`rustc` wrapper) still only prints the rustc lints with the above message at the end. But when running `clippy-driver -Whelp main.rs`, where `main.rs` is any rust file, it also prints Clippy lints. I don't think this is a good approach from a UX perspective: Why is a random file necessary to print a help message? This PR changes this behavior: Whenever a compiler callback registers lints, it is assumed that these lints come from a plugin and are printed without having to specify a Rust source file. Fixes rust-lang/rust-clippy#6122 cc `@Manishearth` `@ebroto` for the Clippy changes.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 3 |
2 files changed, 13 insertions, 6 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index e87d8b7ab45..c1741bfaaba 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -248,11 +248,18 @@ fn run_compiler( interface::run_compiler(config, |compiler| { let sopts = &compiler.session().opts; if sopts.describe_lints { - let lint_store = rustc_lint::new_lint_store( + let mut lint_store = rustc_lint::new_lint_store( sopts.debugging_opts.no_interleave_lints, compiler.session().unstable_options(), ); - describe_lints(compiler.session(), &lint_store, false); + let registered_lints = + if let Some(register_lints) = compiler.register_lints() { + register_lints(compiler.session(), &mut lint_store); + true + } else { + false + }; + describe_lints(compiler.session(), &lint_store, registered_lints); return; } let should_stop = RustcDefaultCalls::print_crate_info( @@ -954,10 +961,7 @@ Available lint options: match (loaded_plugins, plugin.len(), plugin_groups.len()) { (false, 0, _) | (false, _, 0) => { - println!( - "Compiler plugins can provide additional lints and lint groups. To see a \ - listing of these, re-run `rustc -W help` with a crate filename." - ); + println!("Lint tools like Clippy can provide additional lints and lint groups."); } (false, ..) => panic!("didn't load lint plugins but got them anyway!"), (true, 0, 0) => println!("This crate does not load any lint plugins or lint groups."), diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 73a51ad477b..11dd6ec32c0 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -56,6 +56,9 @@ impl Compiler { pub fn output_file(&self) -> &Option<PathBuf> { &self.output_file } + pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> { + &self.register_lints + } pub fn build_output_filenames( &self, sess: &Session, |
