Skip to content

Commit da56d1d

Browse files
Remove all borrows of lint store from Session from librustc
Access through tcx is fine -- by that point, the lint store is frozen, but direct access through Session will go away in future commits, as lint store is still mutable in early stages of Session, and will be removed completely.
1 parent c4475c7 commit da56d1d

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

src/librustc/lint/context.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ pub struct EarlyContext<'a> {
480480
builder: LintLevelsBuilder<'a>,
481481

482482
/// The store of registered lints and the lint levels.
483-
lint_store: ReadGuard<'a, LintStore>,
483+
lint_store: &'a LintStore,
484484

485485
buffered: LintBuffer,
486486
}
@@ -569,14 +569,15 @@ pub trait LintContext: Sized {
569569
impl<'a> EarlyContext<'a> {
570570
fn new(
571571
sess: &'a Session,
572+
lint_store: &'a LintStore,
572573
krate: &'a ast::Crate,
573574
buffered: LintBuffer,
574575
) -> EarlyContext<'a> {
575576
EarlyContext {
576577
sess,
577578
krate,
578-
lint_store: sess.lint_store.borrow(),
579-
builder: LintLevelSets::builder(sess),
579+
lint_store,
580+
builder: LintLevelSets::builder(sess, lint_store),
580581
buffered,
581582
}
582583
}
@@ -611,7 +612,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
611612
f: F)
612613
where F: FnOnce(&mut Self)
613614
{
614-
let push = self.context.builder.push(attrs);
615+
let push = self.context.builder.push(attrs, &self.context.lint_store);
615616
self.check_id(id);
616617
self.enter_attrs(attrs);
617618
f(self);
@@ -1473,12 +1474,13 @@ early_lint_methods!(early_lint_pass_impl, []);
14731474

14741475
fn early_lint_crate<T: EarlyLintPass>(
14751476
sess: &Session,
1477+
lint_store: &LintStore,
14761478
krate: &ast::Crate,
14771479
pass: T,
14781480
buffered: LintBuffer,
14791481
) -> LintBuffer {
14801482
let mut cx = EarlyContextAndPass {
1481-
context: EarlyContext::new(sess, krate, buffered),
1483+
context: EarlyContext::new(sess, lint_store, krate, buffered),
14821484
pass,
14831485
};
14841486

@@ -1497,28 +1499,30 @@ fn early_lint_crate<T: EarlyLintPass>(
14971499

14981500
pub fn check_ast_crate<T: EarlyLintPass>(
14991501
sess: &Session,
1502+
lint_store: &LintStore,
15001503
krate: &ast::Crate,
15011504
pre_expansion: bool,
15021505
builtin_lints: T,
15031506
) {
15041507
let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion {
15051508
(
1506-
sess.lint_store.borrow().pre_expansion_passes.iter().map(|p| (p)()).collect(),
1509+
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
15071510
LintBuffer::default(),
15081511
)
15091512
} else {
15101513
(
1511-
sess.lint_store.borrow().early_passes.iter().map(|p| (p)()).collect(),
1514+
lint_store.early_passes.iter().map(|p| (p)()).collect(),
15121515
sess.buffered_lints.borrow_mut().take().unwrap(),
15131516
)
15141517
};
15151518

15161519
if !sess.opts.debugging_opts.no_interleave_lints {
1517-
buffered = early_lint_crate(sess, krate, builtin_lints, buffered);
1520+
buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered);
15181521

15191522
if !passes.is_empty() {
15201523
buffered = early_lint_crate(
15211524
sess,
1525+
lint_store,
15221526
krate,
15231527
EarlyLintPassObjects { lints: &mut passes[..] },
15241528
buffered,
@@ -1529,6 +1533,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
15291533
buffered = time(sess, &format!("running lint: {}", pass.name()), || {
15301534
early_lint_crate(
15311535
sess,
1536+
lint_store,
15321537
krate,
15331538
EarlyLintPassObjects { lints: slice::from_mut(pass) },
15341539
buffered,

src/librustc/lint/levels.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp;
33
use crate::hir::HirId;
44
use crate::ich::StableHashingContext;
55
use crate::lint::builtin;
6-
use crate::lint::context::CheckLintNameResult;
6+
use crate::lint::context::{LintStore, CheckLintNameResult};
77
use crate::lint::{self, Lint, LintId, Level, LintSource};
88
use crate::session::Session;
99
use crate::util::nodemap::FxHashMap;
@@ -35,21 +35,20 @@ enum LintSet {
3535
}
3636

3737
impl LintLevelSets {
38-
pub fn new(sess: &Session) -> LintLevelSets {
38+
pub fn new(sess: &Session, lint_store: &LintStore) -> LintLevelSets {
3939
let mut me = LintLevelSets {
4040
list: Vec::new(),
4141
lint_cap: Level::Forbid,
4242
};
43-
me.process_command_line(sess);
43+
me.process_command_line(sess, lint_store);
4444
return me
4545
}
4646

47-
pub fn builder(sess: &Session) -> LintLevelsBuilder<'_> {
48-
LintLevelsBuilder::new(sess, LintLevelSets::new(sess))
47+
pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> {
48+
LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store))
4949
}
5050

51-
fn process_command_line(&mut self, sess: &Session) {
52-
let store = sess.lint_store.borrow();
51+
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
5352
let mut specs = FxHashMap::default();
5453
self.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
5554

@@ -186,9 +185,8 @@ impl<'a> LintLevelsBuilder<'a> {
186185
/// #[allow]
187186
///
188187
/// Don't forget to call `pop`!
189-
pub fn push(&mut self, attrs: &[ast::Attribute]) -> BuilderPush {
188+
pub fn push(&mut self, attrs: &[ast::Attribute], store: &LintStore) -> BuilderPush {
190189
let mut specs = FxHashMap::default();
191-
let store = self.sess.lint_store.borrow();
192190
let sess = self.sess;
193191
let bad_attr = |span| {
194192
struct_span_err!(sess, span, E0452, "malformed lint attribute input")

src/librustc/lint/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,15 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
777777

778778
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
779779
assert_eq!(cnum, LOCAL_CRATE);
780+
let store = tcx.sess.lint_store.borrow();
780781
let mut builder = LintLevelMapBuilder {
781-
levels: LintLevelSets::builder(tcx.sess),
782+
levels: LintLevelSets::builder(tcx.sess, &store),
782783
tcx: tcx,
784+
store: &*store,
783785
};
784786
let krate = tcx.hir().krate();
785787

786-
let push = builder.levels.push(&krate.attrs);
788+
let push = builder.levels.push(&krate.attrs, &store);
787789
builder.levels.register_id(hir::CRATE_HIR_ID);
788790
for macro_def in &krate.exported_macros {
789791
builder.levels.register_id(macro_def.hir_id);
@@ -794,19 +796,20 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
794796
tcx.arena.alloc(builder.levels.build_map())
795797
}
796798

797-
struct LintLevelMapBuilder<'tcx> {
799+
struct LintLevelMapBuilder<'a, 'tcx> {
798800
levels: levels::LintLevelsBuilder<'tcx>,
799801
tcx: TyCtxt<'tcx>,
802+
store: &'a LintStore,
800803
}
801804

802-
impl LintLevelMapBuilder<'tcx> {
805+
impl LintLevelMapBuilder<'_, '_> {
803806
fn with_lint_attrs<F>(&mut self,
804807
id: hir::HirId,
805808
attrs: &[ast::Attribute],
806809
f: F)
807810
where F: FnOnce(&mut Self)
808811
{
809-
let push = self.levels.push(attrs);
812+
let push = self.levels.push(attrs, self.store);
810813
if push.changed {
811814
self.levels.register_id(id);
812815
}
@@ -815,7 +818,7 @@ impl LintLevelMapBuilder<'tcx> {
815818
}
816819
}
817820

818-
impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> {
821+
impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
819822
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
820823
intravisit::NestedVisitorMap::All(&self.tcx.hir())
821824
}

src/librustc_interface/passes.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ fn configure_and_expand_inner<'a>(
329329
time(sess, "pre-AST-expansion lint checks", || {
330330
lint::check_ast_crate(
331331
sess,
332+
&*sess.lint_store.borrow(),
332333
&krate,
333334
true,
334335
rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
@@ -556,7 +557,13 @@ pub fn lower_to_hir(
556557
});
557558

558559
time(sess, "early lint checks", || {
559-
lint::check_ast_crate(sess, &krate, false, rustc_lint::BuiltinCombinedEarlyLintPass::new())
560+
lint::check_ast_crate(
561+
sess,
562+
&*sess.lint_store.borrow(),
563+
&krate,
564+
false,
565+
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
566+
)
560567
});
561568

562569
// Discard hygiene data, which isn't required after lowering to HIR.

0 commit comments

Comments
 (0)