Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort lint attributes to print them in a more sane way #7843

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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