Skip to content

Commit

Permalink
Re-implement lint with less emphasis on item ids
Browse files Browse the repository at this point in the history
This way it's much easier to add lints throughout compilation correctly, and
functions on impls can alter the way lints are emitted.
  • Loading branch information
alexcrichton committed May 17, 2013
1 parent 77c98f0 commit 030c666
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 600 deletions.
1 change: 0 additions & 1 deletion src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use container::{Container, Mutable, Map, Set};
use cmp::{Eq, Equiv};
use hash::Hash;
use old_iter::BaseIter;
use hash::Hash;
use old_iter;
use option::{None, Option, Some};
use rand::RngUtil;
Expand Down
1 change: 0 additions & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub mod write {
use back::link::{output_type_assembly, output_type_bitcode};
use back::link::{output_type_exe, output_type_llvm_assembly};
use back::link::{output_type_object};
use back::link::output_type;
use driver::session::Session;
use driver::session;
use lib::llvm::llvm;
Expand Down
7 changes: 2 additions & 5 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use middle;
use util::common::time;
use util::ppaux;

use core::hashmap::HashMap;
use core::int;
use core::io;
use core::os;
Expand Down Expand Up @@ -200,9 +201,6 @@ pub fn compile_rest(sess: Session,
crate = time(time_passes, ~"core injection", ||
front::core_inject::maybe_inject_libcore_ref(sess, crate));

time(time_passes, ~"building lint settings table", ||
lint::build_settings_crate(sess, crate));

let ast_map = time(time_passes, ~"ast indexing", ||
syntax::ast_map::map_crate(sess.diagnostic(), crate));

Expand Down Expand Up @@ -709,7 +707,6 @@ pub fn build_session_(sopts: @session::options,
&sopts.maybe_sysroot,
sopts.target_triple,
/*bad*/copy sopts.addl_lib_search_paths);
let lint_settings = lint::mk_lint_settings();
@Session_ {
targ_cfg: target_cfg,
opts: sopts,
Expand All @@ -723,7 +720,7 @@ pub fn build_session_(sopts: @session::options,
filesearch: filesearch,
building_library: @mut false,
working_dir: os::getcwd(),
lint_settings: lint_settings
lints: @mut HashMap::new(),
}
}

Expand Down
19 changes: 9 additions & 10 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use syntax::{ast, codemap};
use syntax::abi;
use syntax;

use core::hashmap::HashMap;

#[deriving(Eq)]
pub enum os { os_win32, os_macos, os_linux, os_android, os_freebsd, }

Expand Down Expand Up @@ -170,7 +172,7 @@ pub struct Session_ {
filesearch: @filesearch::FileSearch,
building_library: @mut bool,
working_dir: Path,
lint_settings: lint::LintSettings
lints: @mut HashMap<ast::node_id, ~[(lint::lint, codemap::span, ~str)]>,
}

pub type Session = @Session_;
Expand Down Expand Up @@ -230,15 +232,12 @@ pub impl Session_ {
}
}
}
fn span_lint(@self, lint_mode: lint::lint,
expr_id: ast::node_id,
item_id: ast::node_id,
span: span,
msg: &str) {
let level = lint::get_lint_settings_level(
self.lint_settings, lint_mode, expr_id, item_id);
let msg = fmt!("%s [-W %s]", msg, lint::get_lint_name(lint_mode));
self.span_lint_level(level, span, msg);
fn add_lint(@self, lint: lint::lint, id: ast::node_id, sp: span, msg: ~str) {
match self.lints.find_mut(&id) {
Some(arr) => { arr.push((lint, sp, msg)); return; }
None => {}
}
self.lints.insert(id, ~[(lint, sp, msg)]);
}
fn next_node_id(@self) -> ast::node_id {
return syntax::parse::next_node_id(self.parse_sess);
Expand Down
Loading

0 comments on commit 030c666

Please sign in to comment.