From c97c7bfcf377a37f400f1e1a3e25ace2eba85316 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Tue, 6 Mar 2018 00:01:30 -0500 Subject: [PATCH 1/3] Add info message for -Wall command Users coming from other languages (namely C and C++) often expect to use a -Wall flag. Rustc doesn't support that, and previously it simply printed that it didn't recognize the "all" lint. This change makes rustc print out a help message, explaining: - Why there is no -Wall flag - How to view all the available warnings - Point out that the most commonly used warning is -Wunused - Instead of using a command-line flag, the user should consider a !#[warn(unused)] directive in the root of their crate. --- src/librustc_driver/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index d89a3e9d907ea..b9b36616e69f6 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1136,6 +1136,16 @@ fn usage(verbose: bool, include_unstable_options: bool) { verbose_help); } +fn print_wall_help() { + println!(" +The flag -Wall does not exist in rustc. Most useful lints are enabled by default. +Use `rustc -W help` to see all available lints. The most used lints that are not +enabled by default covered by -Wunused; however, the best practice is to put +warning settings in the crate root using `#![warn(unused)]` instead of using +the command line flag directly. +"); +} + fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins: bool) { println!(" Available lint options: @@ -1379,6 +1389,13 @@ pub fn handle_options(args: &[String]) -> Option { nightly_options::is_unstable_enabled(&matches)); return None; } + + // Handle the special case of -Wall. + let wall = matches.opt_strs("W"); + if wall.iter().any(|x| *x == "all") { + print_wall_help(); + return None; + } // Don't handle -W help here, because we might first load plugins. let r = matches.opt_strs("Z"); From 1246eef9a9508e6eb5ecbf9718f3b320b07aab05 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Tue, 6 Mar 2018 17:24:58 -0500 Subject: [PATCH 2/3] Fix trailing whitespace --- src/librustc_driver/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index b9b36616e69f6..47168cb955a0e 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1389,7 +1389,7 @@ pub fn handle_options(args: &[String]) -> Option { nightly_options::is_unstable_enabled(&matches)); return None; } - + // Handle the special case of -Wall. let wall = matches.opt_strs("W"); if wall.iter().any(|x| *x == "all") { From c1337cda4ccf349b8a5a80156e32c2499520b621 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Mon, 12 Mar 2018 21:26:51 -0400 Subject: [PATCH 3/3] Update -Wall message based on feedback The reference to -Wunused was removed, and some phrasing was changed. --- src/librustc_driver/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 47168cb955a0e..4b3315cf8d7ac 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1138,10 +1138,9 @@ fn usage(verbose: bool, include_unstable_options: bool) { fn print_wall_help() { println!(" -The flag -Wall does not exist in rustc. Most useful lints are enabled by default. -Use `rustc -W help` to see all available lints. The most used lints that are not -enabled by default covered by -Wunused; however, the best practice is to put -warning settings in the crate root using `#![warn(unused)]` instead of using +The flag `-Wall` does not exist in `rustc`. Most useful lints are enabled by +default. Use `rustc -W help` to see all available lints. It's more common to put +warning settings in the crate root using `#![warn(LINT_NAME)]` instead of using the command line flag directly. "); }