Skip to content

Commit 03bdfe9

Browse files
committed
move logic to LintLevelsBuilder
1 parent 6f1a79c commit 03bdfe9

File tree

3 files changed

+39
-54
lines changed

3 files changed

+39
-54
lines changed

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use self::TargetLint::*;
1818

1919
use crate::hir::map::definitions::{DefPathData, DisambiguatedDefPathData};
20-
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
20+
use crate::lint::levels::LintLevelsBuilder;
2121
use crate::lint::{EarlyLintPassObject, LateLintPassObject};
2222
use crate::middle::privacy::AccessLevels;
2323
use crate::middle::stability;
@@ -674,7 +674,7 @@ impl<'a> EarlyContext<'a> {
674674
sess,
675675
krate,
676676
lint_store,
677-
builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
677+
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store),
678678
buffered,
679679
}
680680
}

src/librustc/lint/levels.rs

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,8 @@ enum LintSet {
3737
}
3838

3939
impl LintLevelSets {
40-
pub fn new(sess: &Session, lint_store: &LintStore) -> LintLevelSets {
41-
let mut me = LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid };
42-
me.process_command_line(sess, lint_store);
43-
return me;
44-
}
45-
46-
pub fn builder<'a>(
47-
sess: &'a Session,
48-
warn_about_weird_lints: bool,
49-
store: &LintStore,
50-
) -> LintLevelsBuilder<'a> {
51-
LintLevelsBuilder::new(sess, warn_about_weird_lints, LintLevelSets::new(sess, store))
52-
}
53-
54-
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
55-
let mut specs = FxHashMap::default();
56-
self.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
57-
58-
for &(ref lint_name, level) in &sess.opts.lint_opts {
59-
store.check_lint_name_cmdline(sess, &lint_name, level);
60-
61-
// If the cap is less than this specified level, e.g., if we've got
62-
// `--cap-lints allow` but we've also got `-D foo` then we ignore
63-
// this specification as the lint cap will set it to allow anyway.
64-
let level = cmp::min(level, self.lint_cap);
65-
66-
let lint_flag_val = Symbol::intern(lint_name);
67-
let ids = match store.find_lints(&lint_name) {
68-
Ok(ids) => ids,
69-
Err(_) => continue, // errors handled in check_lint_name_cmdline above
70-
};
71-
for id in ids {
72-
let src = LintSource::CommandLine(lint_flag_val);
73-
specs.insert(id, (level, src));
74-
}
75-
}
76-
77-
self.list.push(LintSet::CommandLine { specs: specs });
40+
fn new() -> Self {
41+
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
7842
}
7943

8044
fn get_lint_level(
@@ -159,19 +123,43 @@ pub struct BuilderPush {
159123
}
160124

161125
impl<'a> LintLevelsBuilder<'a> {
162-
pub fn new(
163-
sess: &'a Session,
164-
warn_about_weird_lints: bool,
165-
sets: LintLevelSets,
166-
) -> LintLevelsBuilder<'a> {
167-
assert_eq!(sets.list.len(), 1);
168-
LintLevelsBuilder {
126+
pub fn new(sess: &'a Session, warn_about_weird_lints: bool, store: &LintStore) -> Self {
127+
let mut builder = LintLevelsBuilder {
169128
sess,
170-
sets,
129+
sets: LintLevelSets::new(),
171130
cur: 0,
172131
id_to_set: Default::default(),
173132
warn_about_weird_lints,
133+
};
134+
builder.process_command_line(sess, store);
135+
assert_eq!(builder.sets.list.len(), 1);
136+
builder
137+
}
138+
139+
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
140+
let mut specs = FxHashMap::default();
141+
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
142+
143+
for &(ref lint_name, level) in &sess.opts.lint_opts {
144+
store.check_lint_name_cmdline(sess, &lint_name, level);
145+
146+
// If the cap is less than this specified level, e.g., if we've got
147+
// `--cap-lints allow` but we've also got `-D foo` then we ignore
148+
// this specification as the lint cap will set it to allow anyway.
149+
let level = cmp::min(level, self.sets.lint_cap);
150+
151+
let lint_flag_val = Symbol::intern(lint_name);
152+
let ids = match store.find_lints(&lint_name) {
153+
Ok(ids) => ids,
154+
Err(_) => continue, // errors handled in check_lint_name_cmdline above
155+
};
156+
for id in ids {
157+
let src = LintSource::CommandLine(lint_flag_val);
158+
specs.insert(id, (level, src));
159+
}
174160
}
161+
162+
self.sets.list.push(LintSet::CommandLine { specs });
175163
}
176164

177165
/// Pushes a list of AST lint attributes onto this context.

src/librustc_lint/levels.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::late::unerased_lint_store;
22
use rustc::hir::map::Map;
3-
use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore};
3+
use rustc::lint::{LintLevelMap, LintLevelsBuilder, LintStore};
44
use rustc::ty::query::Providers;
55
use rustc::ty::TyCtxt;
66
use rustc_hir as hir;
@@ -13,11 +13,8 @@ pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId};
1313
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
1414
assert_eq!(cnum, LOCAL_CRATE);
1515
let store = unerased_lint_store(tcx);
16-
let mut builder = LintLevelMapBuilder {
17-
levels: LintLevelSets::builder(tcx.sess, false, &store),
18-
tcx: tcx,
19-
store,
20-
};
16+
let levels = LintLevelsBuilder::new(tcx.sess, false, &store);
17+
let mut builder = LintLevelMapBuilder { levels, tcx, store };
2118
let krate = tcx.hir().krate();
2219

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

0 commit comments

Comments
 (0)