Skip to content

Commit 6157558

Browse files
committed
Describe warnings on command line if user says -W help.
1 parent 7eec6eb commit 6157558

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

src/rustc/driver/rustc.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ import core::*;
99
// -*- rust -*-
1010
import result::{ok, err};
1111
import std::getopts;
12-
import io::writer_util;
12+
import std::map::hashmap;
1313
import getopts::{opt_present};
1414
import rustc::driver::driver::*;
1515
import rustc::syntax::codemap;
1616
import rustc::driver::diagnostic;
17+
import rustc::middle::lint;
1718

1819
fn version(argv0: str) {
1920
let mut vers = "unknown version";
2021
let env_vers = #env["CFG_VERSION"];
2122
if str::len(env_vers) != 0u { vers = env_vers; }
22-
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
23-
io::stdout().write_str(#fmt["host: %s\n", host_triple()]);
23+
io::println(#fmt("%s %s", argv0, vers));
24+
io::println(#fmt("host: %s", host_triple()));
2425
}
2526

2627
fn usage(argv0: str) {
27-
io::stdout().write_str(#fmt["Usage: %s [options] <input>\n", argv0] +
28-
"
28+
io::println(#fmt("Usage: %s [options] <input>\n", argv0) +
29+
"
2930
Options:
3031
3132
--bin Compile an executable crate (default)
@@ -70,6 +71,8 @@ Options:
7071
-W no-<foo> disable warning <foo>
7172
-W err-<foo> enable warning <foo> as an error
7273
74+
-W help Print available warnings and default settings
75+
7376
--time-passes Time the individual phases of the compiler
7477
--time-llvm-passes Time the individual phases of the LLVM backend
7578
--count-llvm-insns Count and categorize generated LLVM instructions
@@ -78,6 +81,30 @@ Options:
7881
");
7982
}
8083

84+
fn describe_warnings() {
85+
let lint_dict = lint::get_lint_dict();
86+
let mut max_key = 0u;
87+
for lint_dict.each_key {|k| max_key = uint::max(k.len(), max_key); }
88+
fn padded(max: uint, s: str) -> str {
89+
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
90+
}
91+
io::println(#fmt("\nAvailable warnings:\n"));
92+
io::println(#fmt(" %s %7.7s %s",
93+
padded(max_key, "name"), "default", "meaning"));
94+
io::println(#fmt(" %s %7.7s %s\n",
95+
padded(max_key, "----"), "-------", "-------"));
96+
for lint_dict.each {|k, v|
97+
let k = str::replace(k, "_", "-");
98+
io::println(#fmt(" %s %7.7s %s",
99+
padded(max_key, k),
100+
alt v.default { lint::warn { "warn" }
101+
lint::error { "error" }
102+
lint::ignore { "ignore" } },
103+
v.desc));
104+
}
105+
io::println("");
106+
}
107+
81108
fn run_compiler(args: [str], demitter: diagnostic::emitter) {
82109
// Don't display log spew by default. Can override with RUST_LOG.
83110
logging::console_off();
@@ -94,10 +121,19 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) {
94121
early_error(demitter, getopts::fail_str(f))
95122
}
96123
};
124+
97125
if opt_present(match, "h") || opt_present(match, "help") {
98126
usage(binary);
99127
ret;
100128
}
129+
130+
let lint_flags = (getopts::opt_strs(match, "W")
131+
+ getopts::opt_strs(match, "warn"));
132+
if lint_flags.contains("help") {
133+
describe_warnings();
134+
ret;
135+
}
136+
101137
if opt_present(match, "v") || opt_present(match, "version") {
102138
version(binary);
103139
ret;

0 commit comments

Comments
 (0)