Skip to content

Commit c69f8ea

Browse files
committed
auto merge of #6093 : alexcrichton/rust/issue-2647, r=thestinger
Closes #2647 This way it's much easier to add lints throughout compilation correctly, and functions on impls can alter the way lints are emitted. This involved pretty much rewriting how lints are emitted. Beforehand, only items could alter the lint settings, so whenever a lint was added it had to be associated with whatever item id it was coming from. I removed this (possibly questionably) in favor of just specifying a span and a message when adding a lint. When lint checking comes around, it looks at all the lints and sees which node with attributes best encloses it and uses that level of linting. This means that all consumer code doesn't have to deal with what item things came from (especially because functions on impls aren't items). More details of this can be found in the code (and comments). As a bonus, I managed to greatly simplify emission of lints in resolve.rs about unused imports. Now instead of it manually tracking what the lint level is, it's all moved over into the lint module (as is to be expected).
2 parents 918bfa7 + 4d44abd commit c69f8ea

16 files changed

+613
-632
lines changed

src/libcore/hashmap.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use container::{Container, Mutable, Map, Set};
1717
use cmp::{Eq, Equiv};
1818
use hash::Hash;
1919
use old_iter::BaseIter;
20-
use hash::Hash;
2120
use old_iter;
2221
use option::{None, Option, Some};
2322
use rand::RngUtil;

src/librustc/back/link.rs

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ pub mod write {
171171
use back::link::{output_type_assembly, output_type_bitcode};
172172
use back::link::{output_type_exe, output_type_llvm_assembly};
173173
use back::link::{output_type_object};
174-
use back::link::output_type;
175174
use driver::session::Session;
176175
use driver::session;
177176
use lib::llvm::llvm;

src/librustc/driver/driver.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use middle;
2222
use util::common::time;
2323
use util::ppaux;
2424

25+
use core::hashmap::HashMap;
2526
use core::int;
2627
use core::io;
2728
use core::os;
@@ -200,9 +201,6 @@ pub fn compile_rest(sess: Session,
200201
crate = time(time_passes, ~"core injection", ||
201202
front::core_inject::maybe_inject_libcore_ref(sess, crate));
202203

203-
time(time_passes, ~"building lint settings table", ||
204-
lint::build_settings_crate(sess, crate));
205-
206204
let ast_map = time(time_passes, ~"ast indexing", ||
207205
syntax::ast_map::map_crate(sess.diagnostic(), crate));
208206

@@ -709,7 +707,6 @@ pub fn build_session_(sopts: @session::options,
709707
&sopts.maybe_sysroot,
710708
sopts.target_triple,
711709
/*bad*/copy sopts.addl_lib_search_paths);
712-
let lint_settings = lint::mk_lint_settings();
713710
@Session_ {
714711
targ_cfg: target_cfg,
715712
opts: sopts,
@@ -723,7 +720,7 @@ pub fn build_session_(sopts: @session::options,
723720
filesearch: filesearch,
724721
building_library: @mut false,
725722
working_dir: os::getcwd(),
726-
lint_settings: lint_settings
723+
lints: @mut HashMap::new(),
727724
}
728725
}
729726

src/librustc/driver/session.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use syntax::{ast, codemap};
2626
use syntax::abi;
2727
use syntax;
2828

29+
use core::hashmap::HashMap;
30+
2931
#[deriving(Eq)]
3032
pub enum os { os_win32, os_macos, os_linux, os_android, os_freebsd, }
3133

@@ -170,7 +172,7 @@ pub struct Session_ {
170172
filesearch: @filesearch::FileSearch,
171173
building_library: @mut bool,
172174
working_dir: Path,
173-
lint_settings: lint::LintSettings
175+
lints: @mut HashMap<ast::node_id, ~[(lint::lint, codemap::span, ~str)]>,
174176
}
175177

176178
pub type Session = @Session_;
@@ -221,24 +223,12 @@ pub impl Session_ {
221223
fn unimpl(@self, msg: &str) -> ! {
222224
self.span_diagnostic.handler().unimpl(msg)
223225
}
224-
fn span_lint_level(@self, level: lint::level, sp: span, msg: &str) {
225-
match level {
226-
lint::allow => { },
227-
lint::warn => self.span_warn(sp, msg),
228-
lint::deny | lint::forbid => {
229-
self.span_err(sp, msg);
230-
}
226+
fn add_lint(@self, lint: lint::lint, id: ast::node_id, sp: span, msg: ~str) {
227+
match self.lints.find_mut(&id) {
228+
Some(arr) => { arr.push((lint, sp, msg)); return; }
229+
None => {}
231230
}
232-
}
233-
fn span_lint(@self, lint_mode: lint::lint,
234-
expr_id: ast::node_id,
235-
item_id: ast::node_id,
236-
span: span,
237-
msg: &str) {
238-
let level = lint::get_lint_settings_level(
239-
self.lint_settings, lint_mode, expr_id, item_id);
240-
let msg = fmt!("%s [-W %s]", msg, lint::get_lint_name(lint_mode));
241-
self.span_lint_level(level, span, msg);
231+
self.lints.insert(id, ~[(lint, sp, msg)]);
242232
}
243233
fn next_node_id(@self) -> ast::node_id {
244234
return syntax::parse::next_node_id(self.parse_sess);

0 commit comments

Comments
 (0)