Skip to content

Commit

Permalink
Sort lint attributes to print them in a more sane way
Browse files Browse the repository at this point in the history
Closes #7818
  • Loading branch information
alexcrichton committed Jul 17, 2013
1 parent 9db1903 commit 0fd4d5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
25 changes: 14 additions & 11 deletions src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Additional help:
}

pub fn describe_warnings() {
use extra::sort::Sort;
io::println(fmt!("
Available lint options:
-W <foo> Warn about <foo>
Expand All @@ -153,8 +154,15 @@ Available lint options:
"));

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
}
Expand All @@ -163,17 +171,12 @@ Available lint options:
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("");
}
Expand Down

5 comments on commit 0fd4d5d

@bors
Copy link
Contributor

@bors bors commented on 0fd4d5d Jul 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at alexcrichton@0fd4d5d

@bors
Copy link
Contributor

@bors bors commented on 0fd4d5d Jul 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/better-lint-help = 0fd4d5d into auto

@bors
Copy link
Contributor

@bors bors commented on 0fd4d5d Jul 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/better-lint-help = 0fd4d5d merged ok, testing candidate = 93c270c

@bors
Copy link
Contributor

@bors bors commented on 0fd4d5d Jul 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 93c270c

Please sign in to comment.