@@ -17,7 +17,6 @@ use lint;
1717use metadata;
1818
1919use std:: any:: AnyRefExt ;
20- use std:: cmp;
2120use std:: io;
2221use std:: os;
2322use std:: str;
@@ -50,6 +49,12 @@ fn run_compiler(args: &[String]) {
5049 None => return
5150 } ;
5251
52+ let sopts = config:: build_session_options ( & matches) ;
53+ if sopts. describe_lints {
54+ describe_lints ( ) ;
55+ return ;
56+ }
57+
5358 let ( input, input_file_path) = match matches. free . len ( ) {
5459 0 u => early_error ( "no input filename given" ) ,
5560 1 u => {
@@ -66,7 +71,6 @@ fn run_compiler(args: &[String]) {
6671 _ => early_error ( "multiple input filenames provided" )
6772 } ;
6873
69- let sopts = config:: build_session_options ( & matches) ;
7074 let sess = build_session ( sopts, input_file_path) ;
7175 let cfg = config:: build_configuration ( & sess) ;
7276 let odir = matches. opt_str ( "out-dir" ) . map ( |o| Path :: new ( o) ) ;
@@ -124,7 +128,7 @@ Additional help:
124128 config:: optgroups( ) . as_slice( ) ) ) ;
125129}
126130
127- fn describe_warnings ( ) {
131+ fn describe_lints ( ) {
128132 println ! ( "
129133Available lint options:
130134 -W <foo> Warn about <foo>
@@ -133,30 +137,32 @@ Available lint options:
133137 -F <foo> Forbid <foo> (deny, and deny all overrides)
134138" ) ;
135139
136- let lint_dict = lint:: get_lint_dict ( ) ;
137- let mut lint_dict = lint_dict. move_iter ( )
138- . map ( |( k, v) | ( v, k) )
139- . collect :: < Vec < ( lint:: LintSpec , & ' static str ) > > ( ) ;
140- lint_dict. as_mut_slice ( ) . sort ( ) ;
140+ let mut builtin_specs = lint:: builtin_lint_specs ( ) ;
141+ builtin_specs. sort_by ( |x, y| {
142+ match x. default_level . cmp ( & y. default_level ) {
143+ Equal => x. name . cmp ( & y. name ) ,
144+ r => r,
145+ }
146+ } ) ;
147+
148+ // FIXME: What if someone uses combining characters or East Asian fullwidth
149+ // characters in a lint name?!?!?
150+ let max_name_len = builtin_specs. iter ( )
151+ . map ( |& s| s. name . char_len ( ) )
152+ . max ( ) . unwrap_or ( 0 ) ;
153+ let padded = |x : & str | {
154+ format ! ( "{}{}" , " " . repeat( max_name_len - x. char_len( ) ) , x)
155+ } ;
141156
142- let mut max_key = 0 ;
143- for & ( _, name) in lint_dict. iter ( ) {
144- max_key = cmp:: max ( name. len ( ) , max_key) ;
145- }
146- fn padded ( max : uint , s : & str ) -> String {
147- format ! ( "{}{}" , " " . repeat( max - s. len( ) ) , s)
148- }
149157 println ! ( "\n Available lint checks:\n " ) ;
150- println ! ( " {} {:7.7s} {}" ,
151- padded( max_key , "name ") , "default " , "meaning " ) ;
152- println ! ( " {} {:7.7s} {} \n " ,
153- padded ( max_key , "----" ) , "-------" , "-------" ) ;
154- for ( spec, name ) in lint_dict . move_iter ( ) {
155- let name = name. replace ( "_" , "-" ) ;
158+ println ! ( " {} {:7.7s} {}" , padded ( "name" ) , "default" , "meaning" ) ;
159+ println ! ( " {} {:7.7s} {}" , padded( "---- ") , "------- " , "------- " ) ;
160+ println ! ( "" ) ;
161+
162+ for spec in builtin_specs . move_iter ( ) {
163+ let name = spec . name . replace ( "_" , "-" ) ;
156164 println ! ( " {} {:7.7s} {}" ,
157- padded( max_key, name. as_slice( ) ) ,
158- lint:: level_to_str( spec. default ) ,
159- spec. desc) ;
165+ padded( name. as_slice( ) ) , spec. default_level. as_str( ) , spec. desc) ;
160166 }
161167 println ! ( "" ) ;
162168}
@@ -214,12 +220,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
214220 return None ;
215221 }
216222
217- let lint_flags = matches. opt_strs ( "W" ) . move_iter ( ) . collect :: < Vec < _ > > ( ) . append (
218- matches. opt_strs ( "warn" ) . as_slice ( ) ) ;
219- if lint_flags. iter ( ) . any ( |x| x. as_slice ( ) == "help" ) {
220- describe_warnings ( ) ;
221- return None ;
222- }
223+ // Don't handle -W help here, because we might first load plugins.
223224
224225 let r = matches. opt_strs ( "Z" ) ;
225226 if r. iter ( ) . any ( |x| x. as_slice ( ) == "help" ) {
0 commit comments