diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-09 04:06:33 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-11 07:42:26 +0100 |
| commit | 03bdfe9db3c7814e474413c4238f3eca7c2bf39a (patch) | |
| tree | febce3ed69326383f42e4f78aee689634ec5fa73 | |
| parent | 6f1a79cabe011c7487652e61130275a2940c47bc (diff) | |
| download | rust-03bdfe9db3c7814e474413c4238f3eca7c2bf39a.tar.gz rust-03bdfe9db3c7814e474413c4238f3eca7c2bf39a.zip | |
move logic to LintLevelsBuilder
| -rw-r--r-- | src/librustc/lint/context.rs | 4 | ||||
| -rw-r--r-- | src/librustc/lint/levels.rs | 80 | ||||
| -rw-r--r-- | src/librustc_lint/levels.rs | 9 |
3 files changed, 39 insertions, 54 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 867eb5a1937..779077f1ff4 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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; @@ -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, } } diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index fdd2a8d0778..04028c03d43 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -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( @@ -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); + 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. diff --git a/src/librustc_lint/levels.rs b/src/librustc_lint/levels.rs index a4910a02590..46ea04e5ccf 100644 --- a/src/librustc_lint/levels.rs +++ b/src/librustc_lint/levels.rs @@ -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; @@ -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); |
