@@ -9,23 +9,24 @@ import core::*;
9
9
// -*- rust -*-
10
10
import result:: { ok, err} ;
11
11
import std:: getopts;
12
- import io :: writer_util ;
12
+ import std :: map :: hashmap ;
13
13
import getopts:: { opt_present} ;
14
14
import rustc:: driver:: driver:: * ;
15
15
import rustc:: syntax:: codemap;
16
16
import rustc:: driver:: diagnostic;
17
+ import rustc:: middle:: lint;
17
18
18
19
fn version ( argv0 : str ) {
19
20
let mut vers = "unknown version" ;
20
21
let env_vers = #env[ "CFG_VERSION" ] ;
21
22
if str:: len ( env_vers) != 0 u { 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 ( ) ) ) ;
24
25
}
25
26
26
27
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
+ "
29
30
Options:
30
31
31
32
--bin Compile an executable crate (default)
@@ -70,6 +71,8 @@ Options:
70
71
-W no-<foo> disable warning <foo>
71
72
-W err-<foo> enable warning <foo> as an error
72
73
74
+ -W help Print available warnings and default settings
75
+
73
76
--time-passes Time the individual phases of the compiler
74
77
--time-llvm-passes Time the individual phases of the LLVM backend
75
78
--count-llvm-insns Count and categorize generated LLVM instructions
@@ -78,6 +81,30 @@ Options:
78
81
" ) ;
79
82
}
80
83
84
+ fn describe_warnings ( ) {
85
+ let lint_dict = lint:: get_lint_dict ( ) ;
86
+ let mut max_key = 0 u;
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 ( "\n Available 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
+
81
108
fn run_compiler( args : [ str ] , demitter : diagnostic:: emitter ) {
82
109
// Don't display log spew by default. Can override with RUST_LOG.
83
110
logging:: console_off ( ) ;
@@ -94,10 +121,19 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) {
94
121
early_error ( demitter, getopts:: fail_str ( f) )
95
122
}
96
123
} ;
124
+
97
125
if opt_present( match , "h" ) || opt_present( match , "help" ) {
98
126
usage( binary) ;
99
127
ret;
100
128
}
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
+
101
137
if opt_present( match , "v" ) || opt_present( match , "version" ) {
102
138
version( binary) ;
103
139
ret;
0 commit comments