Skip to content

Commit f076237

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 152784 b: refs/heads/try2 c: 442fbc4 h: refs/heads/master v: v3
1 parent 5a02e13 commit f076237

File tree

17 files changed

+745
-767
lines changed

17 files changed

+745
-767
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 69b6bc5eee9174d0f2ef1e4ff60a6ed06aedf455
8+
refs/heads/try2: 442fbc473e10d1efe3359b19f342d11097259fc4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/driver/config.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ pub struct Options {
7070
pub gc: bool,
7171
pub optimize: OptLevel,
7272
pub debuginfo: DebugInfoLevel,
73-
pub lint_opts: Vec<(lint::LintId, lint::Level)> ,
73+
pub lint_opts: Vec<(String, lint::Level)>,
74+
pub describe_lints: bool,
7475
pub output_types: Vec<back::link::OutputType> ,
7576
// This was mutable for rustpkg, which updates search paths based on the
7677
// parsed code. It remains mutable in case its replacements wants to use
@@ -104,6 +105,7 @@ pub fn basic_options() -> Options {
104105
optimize: No,
105106
debuginfo: NoDebugInfo,
106107
lint_opts: Vec::new(),
108+
describe_lints: false,
107109
output_types: Vec::new(),
108110
addl_lib_search_paths: RefCell::new(HashSet::new()),
109111
maybe_sysroot: None,
@@ -585,30 +587,15 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
585587
let no_trans = matches.opt_present("no-trans");
586588
let no_analysis = matches.opt_present("no-analysis");
587589

588-
let lint_levels = [lint::Allow, lint::Warn,
589-
lint::Deny, lint::Forbid];
590-
let mut lint_opts = Vec::new();
591-
let lint_dict = lint::get_lint_dict();
592-
for level in lint_levels.iter() {
593-
let level_name = lint::level_to_str(*level);
594-
595-
let level_short = level_name.slice_chars(0, 1);
596-
let level_short = level_short.to_ascii().to_upper().into_str();
597-
let flags = matches.opt_strs(level_short.as_slice())
598-
.move_iter()
599-
.collect::<Vec<_>>()
600-
.append(matches.opt_strs(level_name).as_slice());
601-
for lint_name in flags.iter() {
602-
let lint_name = lint_name.replace("-", "_").into_string();
603-
match lint_dict.find_equiv(&lint_name) {
604-
None => {
605-
early_error(format!("unknown {} flag: {}",
606-
level_name,
607-
lint_name).as_slice());
608-
}
609-
Some(lint) => {
610-
lint_opts.push((lint.lint, *level));
611-
}
590+
let mut lint_opts = vec!();
591+
let mut describe_lints = false;
592+
593+
for &level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid].iter() {
594+
for lint_name in matches.opt_strs(level.as_str()).move_iter() {
595+
if lint_name.as_slice() == "help" {
596+
describe_lints = true;
597+
} else {
598+
lint_opts.push((lint_name.replace("-", "_").into_string(), level));
612599
}
613600
}
614601
}
@@ -752,6 +739,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
752739
optimize: opt_level,
753740
debuginfo: debuginfo,
754741
lint_opts: lint_opts,
742+
describe_lints: describe_lints,
755743
output_types: output_types,
756744
addl_lib_search_paths: RefCell::new(addl_lib_search_paths),
757745
maybe_sysroot: sysroot_opt,

branches/try2/src/librustc/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,15 @@ pub fn collect_crate_types(session: &Session,
767767
}
768768
Some(ref n) if n.equiv(&("bin")) => Some(config::CrateTypeExecutable),
769769
Some(_) => {
770-
session.add_lint(lint::UnknownCrateType,
770+
session.add_lint(lint::builtin::unknown_crate_type,
771771
ast::CRATE_NODE_ID,
772772
a.span,
773773
"invalid `crate_type` \
774774
value".to_string());
775775
None
776776
}
777777
_ => {
778-
session.add_lint(lint::UnknownCrateType,
778+
session.add_lint(lint::builtin::unknown_crate_type,
779779
ast::CRATE_NODE_ID,
780780
a.span,
781781
"`crate_type` requires a \

branches/try2/src/librustc/driver/mod.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use lint;
1717
use metadata;
1818

1919
use std::any::AnyRefExt;
20-
use std::cmp;
2120
use std::io;
2221
use std::os;
2322
use std::str;
@@ -50,6 +49,12 @@ fn run_compiler(args: &[String]) {
5049
None => return
5150
};
5251

52+
let sopts = config::build_session_options(&matches);
53+
if sopts.describe_lints {
54+
describe_lints();
55+
return;
56+
}
57+
5358
let (input, input_file_path) = match matches.free.len() {
5459
0u => early_error("no input filename given"),
5560
1u => {
@@ -66,7 +71,6 @@ fn run_compiler(args: &[String]) {
6671
_ => early_error("multiple input filenames provided")
6772
};
6873

69-
let sopts = config::build_session_options(&matches);
7074
let sess = build_session(sopts, input_file_path);
7175
let cfg = config::build_configuration(&sess);
7276
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
@@ -124,7 +128,7 @@ Additional help:
124128
config::optgroups().as_slice()));
125129
}
126130

127-
fn describe_warnings() {
131+
fn describe_lints() {
128132
println!("
129133
Available lint options:
130134
-W <foo> Warn about <foo>
@@ -133,30 +137,32 @@ Available lint options:
133137
-F <foo> Forbid <foo> (deny, and deny all overrides)
134138
");
135139

136-
let lint_dict = lint::get_lint_dict();
137-
let mut lint_dict = lint_dict.move_iter()
138-
.map(|(k, v)| (v, k))
139-
.collect::<Vec<(lint::LintSpec, &'static str)> >();
140-
lint_dict.as_mut_slice().sort();
140+
let mut builtin_specs = lint::builtin_lint_specs();
141+
builtin_specs.sort_by(|x, y| {
142+
match x.default_level.cmp(&y.default_level) {
143+
Equal => x.name.cmp(&y.name),
144+
r => r,
145+
}
146+
});
147+
148+
// FIXME: What if someone uses combining characters or East Asian fullwidth
149+
// characters in a lint name?!?!?
150+
let max_name_len = builtin_specs.iter()
151+
.map(|&s| s.name.char_len())
152+
.max().unwrap_or(0);
153+
let padded = |x: &str| {
154+
format!("{}{}", " ".repeat(max_name_len - x.char_len()), x)
155+
};
141156

142-
let mut max_key = 0;
143-
for &(_, name) in lint_dict.iter() {
144-
max_key = cmp::max(name.len(), max_key);
145-
}
146-
fn padded(max: uint, s: &str) -> String {
147-
format!("{}{}", " ".repeat(max - s.len()), s)
148-
}
149157
println!("\nAvailable lint checks:\n");
150-
println!(" {} {:7.7s} {}",
151-
padded(max_key, "name"), "default", "meaning");
152-
println!(" {} {:7.7s} {}\n",
153-
padded(max_key, "----"), "-------", "-------");
154-
for (spec, name) in lint_dict.move_iter() {
155-
let name = name.replace("_", "-");
158+
println!(" {} {:7.7s} {}", padded("name"), "default", "meaning");
159+
println!(" {} {:7.7s} {}", padded("----"), "-------", "-------");
160+
println!("");
161+
162+
for spec in builtin_specs.move_iter() {
163+
let name = spec.name.replace("_", "-");
156164
println!(" {} {:7.7s} {}",
157-
padded(max_key, name.as_slice()),
158-
lint::level_to_str(spec.default),
159-
spec.desc);
165+
padded(name.as_slice()), spec.default_level.as_str(), spec.desc);
160166
}
161167
println!("");
162168
}
@@ -214,12 +220,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
214220
return None;
215221
}
216222

217-
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
218-
matches.opt_strs("warn").as_slice());
219-
if lint_flags.iter().any(|x| x.as_slice() == "help") {
220-
describe_warnings();
221-
return None;
222-
}
223+
// Don't handle -W help here, because we might first load plugins.
223224

224225
let r = matches.opt_strs("Z");
225226
if r.iter().any(|x| x.as_slice() == "help") {

branches/try2/src/librustc/driver/session.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,17 @@ impl Session {
106106
self.diagnostic().handler().unimpl(msg)
107107
}
108108
pub fn add_lint(&self,
109-
lint: lint::LintId,
109+
lint: &'static lint::Lint,
110110
id: ast::NodeId,
111111
sp: Span,
112112
msg: String) {
113+
let lint_id = lint::LintId::of(lint);
113114
let mut lints = self.lints.borrow_mut();
114115
match lints.find_mut(&id) {
115-
Some(arr) => { arr.push((lint, sp, msg)); return; }
116+
Some(arr) => { arr.push((lint_id, sp, msg)); return; }
116117
None => {}
117118
}
118-
lints.insert(id, vec!((lint, sp, msg)));
119+
lints.insert(id, vec!((lint_id, sp, msg)));
119120
}
120121
pub fn next_node_id(&self) -> ast::NodeId {
121122
self.reserve_node_ids(1)

branches/try2/src/librustc/front/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
409409
directive not necessary");
410410
}
411411
None => {
412-
sess.add_lint(lint::UnknownFeatures,
412+
sess.add_lint(lint::builtin::unknown_features,
413413
ast::CRATE_NODE_ID,
414414
mi.span,
415415
"unknown feature".to_string());

branches/try2/src/librustc/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ pub mod lib {
127127
pub mod llvmdeps;
128128
}
129129

130+
// A private module so that macro-expanded idents like
131+
// `::rustc::lint::Lint` will also work in `rustc` itself.
132+
//
133+
// `libstd` uses the same trick.
134+
#[doc(hidden)]
135+
mod rustc {
136+
pub use lint;
137+
}
138+
130139
pub fn main() {
131140
let args = std::os::args().iter()
132141
.map(|x| x.to_string())

0 commit comments

Comments
 (0)