auto merge of #7843 : alexcrichton/rust/better-lint-help, r=huonw
Closes #7818
This commit is contained in:
commit
93c270c63d
|
@ -108,17 +108,22 @@ pub fn level_to_str(lv: level) -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, Ord)]
|
||||||
pub enum level {
|
pub enum level {
|
||||||
allow, warn, deny, forbid
|
allow, warn, deny, forbid
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LintSpec {
|
#[deriving(Eq)]
|
||||||
|
pub struct LintSpec {
|
||||||
lint: lint,
|
lint: lint,
|
||||||
desc: &'static str,
|
desc: &'static str,
|
||||||
default: level
|
default: level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ord for LintSpec {
|
||||||
|
fn lt(&self, other: &LintSpec) -> bool { self.default < other.default }
|
||||||
|
}
|
||||||
|
|
||||||
pub type LintDict = HashMap<&'static str, LintSpec>;
|
pub type LintDict = HashMap<&'static str, LintSpec>;
|
||||||
|
|
||||||
enum AttributedNode<'self> {
|
enum AttributedNode<'self> {
|
||||||
|
|
|
@ -144,6 +144,7 @@ Additional help:
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn describe_warnings() {
|
pub fn describe_warnings() {
|
||||||
|
use extra::sort::Sort;
|
||||||
io::println(fmt!("
|
io::println(fmt!("
|
||||||
Available lint options:
|
Available lint options:
|
||||||
-W <foo> Warn about <foo>
|
-W <foo> Warn about <foo>
|
||||||
|
@ -153,8 +154,15 @@ Available lint options:
|
||||||
"));
|
"));
|
||||||
|
|
||||||
let lint_dict = lint::get_lint_dict();
|
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;
|
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 {
|
fn padded(max: uint, s: &str) -> ~str {
|
||||||
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
||||||
}
|
}
|
||||||
|
@ -163,17 +171,12 @@ Available lint options:
|
||||||
padded(max_key, "name"), "default", "meaning"));
|
padded(max_key, "name"), "default", "meaning"));
|
||||||
io::println(fmt!(" %s %7.7s %s\n",
|
io::println(fmt!(" %s %7.7s %s\n",
|
||||||
padded(max_key, "----"), "-------", "-------"));
|
padded(max_key, "----"), "-------", "-------"));
|
||||||
for lint_dict.iter().advance |(k, v)| {
|
for lint_dict.consume_iter().advance |(spec, name)| {
|
||||||
let k = k.replace("_", "-");
|
let name = name.replace("_", "-");
|
||||||
io::println(fmt!(" %s %7.7s %s",
|
io::println(fmt!(" %s %7.7s %s",
|
||||||
padded(max_key, k),
|
padded(max_key, name),
|
||||||
match v.default {
|
lint::level_to_str(spec.default),
|
||||||
lint::allow => ~"allow",
|
spec.desc));
|
||||||
lint::warn => ~"warn",
|
|
||||||
lint::deny => ~"deny",
|
|
||||||
lint::forbid => ~"forbid"
|
|
||||||
},
|
|
||||||
v.desc));
|
|
||||||
}
|
}
|
||||||
io::println("");
|
io::println("");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue