Skip to content

Commit 0fd4d5d

Browse files
committed
Sort lint attributes to print them in a more sane way
Closes #7818
1 parent 9db1903 commit 0fd4d5d

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/librustc/middle/lint.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ pub fn level_to_str(lv: level) -> &'static str {
108108
}
109109
}
110110

111-
#[deriving(Eq)]
111+
#[deriving(Eq, Ord)]
112112
pub enum level {
113113
allow, warn, deny, forbid
114114
}
115115

116-
struct LintSpec {
116+
#[deriving(Eq)]
117+
pub struct LintSpec {
117118
lint: lint,
118119
desc: &'static str,
119120
default: level
120121
}
121122

123+
impl Ord for LintSpec {
124+
fn lt(&self, other: &LintSpec) -> bool { self.default < other.default }
125+
}
126+
122127
pub type LintDict = HashMap<&'static str, LintSpec>;
123128

124129
enum AttributedNode<'self> {

src/librustc/rustc.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Additional help:
144144
}
145145

146146
pub fn describe_warnings() {
147+
use extra::sort::Sort;
147148
io::println(fmt!("
148149
Available lint options:
149150
-W <foo> Warn about <foo>
@@ -153,8 +154,15 @@ Available lint options:
153154
"));
154155

155156
let lint_dict = lint::get_lint_dict();
157+
let mut lint_dict = lint_dict.consume_iter()
158+
.transform(|(k, v)| (v, k))
159+
.collect::<~[(lint::LintSpec, &'static str)]>();
160+
lint_dict.qsort();
161+
156162
let mut max_key = 0;
157-
for lint_dict.each_key |k| { max_key = num::max(k.len(), max_key); }
163+
for lint_dict.iter().advance |&(_, name)| {
164+
max_key = num::max(name.len(), max_key);
165+
}
158166
fn padded(max: uint, s: &str) -> ~str {
159167
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
160168
}
@@ -163,17 +171,12 @@ Available lint options:
163171
padded(max_key, "name"), "default", "meaning"));
164172
io::println(fmt!(" %s %7.7s %s\n",
165173
padded(max_key, "----"), "-------", "-------"));
166-
for lint_dict.iter().advance |(k, v)| {
167-
let k = k.replace("_", "-");
174+
for lint_dict.consume_iter().advance |(spec, name)| {
175+
let name = name.replace("_", "-");
168176
io::println(fmt!(" %s %7.7s %s",
169-
padded(max_key, k),
170-
match v.default {
171-
lint::allow => ~"allow",
172-
lint::warn => ~"warn",
173-
lint::deny => ~"deny",
174-
lint::forbid => ~"forbid"
175-
},
176-
v.desc));
177+
padded(max_key, name),
178+
lint::level_to_str(spec.default),
179+
spec.desc));
177180
}
178181
io::println("");
179182
}

0 commit comments

Comments
 (0)