]> git.lizzy.rs Git - rust.git/commitdiff
Sort lint attributes to print them in a more sane way
authorAlex Crichton <alex@alexcrichton.com>
Wed, 17 Jul 2013 04:12:16 +0000 (21:12 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 17 Jul 2013 04:28:10 +0000 (21:28 -0700)
Closes #7818

src/librustc/middle/lint.rs
src/librustc/rustc.rs

index b679da714a174f4614d55f58d99eed8be2ee245d..d18fbada009a1441fdf977af05b03560771aea75 100644 (file)
@@ -108,17 +108,22 @@ pub fn level_to_str(lv: level) -> &'static str {
     }
 }
 
-#[deriving(Eq)]
+#[deriving(Eq, Ord)]
 pub enum level {
     allow, warn, deny, forbid
 }
 
-struct LintSpec {
+#[deriving(Eq)]
+pub struct LintSpec {
     lint: lint,
     desc: &'static str,
     default: level
 }
 
+impl Ord for LintSpec {
+    fn lt(&self, other: &LintSpec) -> bool { self.default < other.default }
+}
+
 pub type LintDict = HashMap<&'static str, LintSpec>;
 
 enum AttributedNode<'self> {
index 787d8d5685a34b9357e3baf6f15dcf9d527c8b1a..6f638959bc83002f28cbdb32d7af317db7992e09 100644 (file)
@@ -144,6 +144,7 @@ pub fn usage(argv0: &str) {
 }
 
 pub fn describe_warnings() {
+    use extra::sort::Sort;
     io::println(fmt!("
 Available lint options:
     -W <foo>           Warn about <foo>
@@ -153,8 +154,15 @@ pub fn describe_warnings() {
 "));
 
     let lint_dict = lint::get_lint_dict();
+    let mut lint_dict = lint_dict.consume_iter()
+                                 .transform(|(k, v)| (v, k))
+                                 .collect::<~[(lint::LintSpec, &'static str)]>();
+    lint_dict.qsort();
+
     let mut max_key = 0;
-    for lint_dict.each_key |k| { max_key = num::max(k.len(), max_key); }
+    for lint_dict.iter().advance |&(_, name)| {
+        max_key = num::max(name.len(), max_key);
+    }
     fn padded(max: uint, s: &str) -> ~str {
         str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
     }
@@ -163,17 +171,12 @@ fn padded(max: uint, s: &str) -> ~str {
                      padded(max_key, "name"), "default", "meaning"));
     io::println(fmt!("    %s  %7.7s  %s\n",
                      padded(max_key, "----"), "-------", "-------"));
-    for lint_dict.iter().advance |(k, v)| {
-        let k = k.replace("_", "-");
+    for lint_dict.consume_iter().advance |(spec, name)| {
+        let name = name.replace("_", "-");
         io::println(fmt!("    %s  %7.7s  %s",
-                         padded(max_key, k),
-                         match v.default {
-                             lint::allow => ~"allow",
-                             lint::warn => ~"warn",
-                             lint::deny => ~"deny",
-                             lint::forbid => ~"forbid"
-                         },
-                         v.desc));
+                         padded(max_key, name),
+                         lint::level_to_str(spec.default),
+                         spec.desc));
     }
     io::println("");
 }