Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more of rustc::lint into rustc_lint #68045

Merged
merged 14 commits into from
Jan 12, 2020
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use self::TargetLint::*;

use crate::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
use crate::lint::levels::LintLevelsBuilder;
use crate::lint::{EarlyLintPassObject, LateLintPassObject};
use crate::middle::privacy::AccessLevels;
use crate::middle::stability;
Expand Down Expand Up @@ -674,7 +674,7 @@ impl<'a> EarlyContext<'a> {
sess,
krate,
lint_store,
builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store),
buffered,
}
}
Expand Down
80 changes: 34 additions & 46 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,8 @@ enum LintSet {
}

impl LintLevelSets {
pub fn new(sess: &Session, lint_store: &LintStore) -> LintLevelSets {
let mut me = LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid };
me.process_command_line(sess, lint_store);
return me;
}

pub fn builder<'a>(
sess: &'a Session,
warn_about_weird_lints: bool,
store: &LintStore,
) -> LintLevelsBuilder<'a> {
LintLevelsBuilder::new(sess, warn_about_weird_lints, LintLevelSets::new(sess, store))
}

fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
let mut specs = FxHashMap::default();
self.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);

for &(ref lint_name, level) in &sess.opts.lint_opts {
store.check_lint_name_cmdline(sess, &lint_name, level);

// If the cap is less than this specified level, e.g., if we've got
// `--cap-lints allow` but we've also got `-D foo` then we ignore
// this specification as the lint cap will set it to allow anyway.
let level = cmp::min(level, self.lint_cap);

let lint_flag_val = Symbol::intern(lint_name);
let ids = match store.find_lints(&lint_name) {
Ok(ids) => ids,
Err(_) => continue, // errors handled in check_lint_name_cmdline above
};
for id in ids {
let src = LintSource::CommandLine(lint_flag_val);
specs.insert(id, (level, src));
}
}

self.list.push(LintSet::CommandLine { specs: specs });
fn new() -> Self {
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
}

fn get_lint_level(
Expand Down Expand Up @@ -159,19 +123,43 @@ pub struct BuilderPush {
}

impl<'a> LintLevelsBuilder<'a> {
pub fn new(
sess: &'a Session,
warn_about_weird_lints: bool,
sets: LintLevelSets,
) -> LintLevelsBuilder<'a> {
assert_eq!(sets.list.len(), 1);
LintLevelsBuilder {
pub fn new(sess: &'a Session, warn_about_weird_lints: bool, store: &LintStore) -> Self {
let mut builder = LintLevelsBuilder {
sess,
sets,
sets: LintLevelSets::new(),
cur: 0,
id_to_set: Default::default(),
warn_about_weird_lints,
};
builder.process_command_line(sess, store);
assert_eq!(builder.sets.list.len(), 1);
Centril marked this conversation as resolved.
Show resolved Hide resolved
builder
}

fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
let mut specs = FxHashMap::default();
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);

for &(ref lint_name, level) in &sess.opts.lint_opts {
store.check_lint_name_cmdline(sess, &lint_name, level);

// If the cap is less than this specified level, e.g., if we've got
// `--cap-lints allow` but we've also got `-D foo` then we ignore
// this specification as the lint cap will set it to allow anyway.
let level = cmp::min(level, self.sets.lint_cap);

let lint_flag_val = Symbol::intern(lint_name);
let ids = match store.find_lints(&lint_name) {
Ok(ids) => ids,
Err(_) => continue, // errors handled in check_lint_name_cmdline above
};
for id in ids {
let src = LintSource::CommandLine(lint_flag_val);
specs.insert(id, (level, src));
}
}

self.sets.list.push(LintSet::CommandLine { specs });
}

/// Pushes a list of AST lint attributes onto this context.
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_lint/levels.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::late::unerased_lint_store;
use rustc::hir::map::Map;
use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore};
use rustc::lint::{LintLevelMap, LintLevelsBuilder, LintStore};
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc_hir as hir;
Expand All @@ -13,11 +13,8 @@ pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId};
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = unerased_lint_store(tcx);
let mut builder = LintLevelMapBuilder {
levels: LintLevelSets::builder(tcx.sess, false, &store),
tcx: tcx,
store,
};
let levels = LintLevelsBuilder::new(tcx.sess, false, &store);
let mut builder = LintLevelMapBuilder { levels, tcx, store };
let krate = tcx.hir().krate();

let push = builder.levels.push(&krate.attrs, &store);
Expand Down