Skip to content

Commit c68df7c

Browse files
Delete lint buffer from Session
1 parent c0fdddc commit c68df7c

File tree

6 files changed

+39
-68
lines changed

6 files changed

+39
-68
lines changed

src/librustc/lint/context.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::util::common::time;
3434

3535
use errors::DiagnosticBuilder;
3636
use std::slice;
37-
use std::default::Default as StdDefault;
3837
use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter};
3938
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
4039
use syntax::ast;
@@ -584,12 +583,13 @@ impl<'a> EarlyContext<'a> {
584583
lint_store: &'a LintStore,
585584
krate: &'a ast::Crate,
586585
buffered: LintBuffer,
586+
warn_about_weird_lints: bool,
587587
) -> EarlyContext<'a> {
588588
EarlyContext {
589589
sess,
590590
krate,
591591
lint_store,
592-
builder: LintLevelSets::builder(sess, lint_store),
592+
builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
593593
buffered,
594594
}
595595
}
@@ -1490,9 +1490,10 @@ fn early_lint_crate<T: EarlyLintPass>(
14901490
krate: &ast::Crate,
14911491
pass: T,
14921492
buffered: LintBuffer,
1493+
warn_about_weird_lints: bool,
14931494
) -> LintBuffer {
14941495
let mut cx = EarlyContextAndPass {
1495-
context: EarlyContext::new(sess, lint_store, krate, buffered),
1496+
context: EarlyContext::new(sess, lint_store, krate, buffered, warn_about_weird_lints),
14961497
pass,
14971498
};
14981499

@@ -1514,22 +1515,19 @@ pub fn check_ast_crate<T: EarlyLintPass>(
15141515
lint_store: &LintStore,
15151516
krate: &ast::Crate,
15161517
pre_expansion: bool,
1518+
lint_buffer: Option<LintBuffer>,
15171519
builtin_lints: T,
15181520
) {
1519-
let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion {
1520-
(
1521-
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
1522-
LintBuffer::default(),
1523-
)
1521+
let mut passes: Vec<_> = if pre_expansion {
1522+
lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
15241523
} else {
1525-
(
1526-
lint_store.early_passes.iter().map(|p| (p)()).collect(),
1527-
sess.buffered_lints.borrow_mut().take().unwrap(),
1528-
)
1524+
lint_store.early_passes.iter().map(|p| (p)()).collect()
15291525
};
1526+
let mut buffered = lint_buffer.unwrap_or_default();
15301527

15311528
if !sess.opts.debugging_opts.no_interleave_lints {
1532-
buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered);
1529+
buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered,
1530+
pre_expansion);
15331531

15341532
if !passes.is_empty() {
15351533
buffered = early_lint_crate(
@@ -1538,6 +1536,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
15381536
krate,
15391537
EarlyLintPassObjects { lints: &mut passes[..] },
15401538
buffered,
1539+
pre_expansion,
15411540
);
15421541
}
15431542
} else {
@@ -1549,6 +1548,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
15491548
krate,
15501549
EarlyLintPassObjects { lints: slice::from_mut(pass) },
15511550
buffered,
1551+
pre_expansion,
15521552
)
15531553
});
15541554
}

src/librustc/lint/levels.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ impl LintLevelSets {
4444
return me
4545
}
4646

47-
pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> {
48-
LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store))
47+
pub fn builder<'a>(
48+
sess: &'a Session,
49+
warn_about_weird_lints: bool,
50+
store: &LintStore,
51+
) -> LintLevelsBuilder<'a> {
52+
LintLevelsBuilder::new(sess, warn_about_weird_lints, LintLevelSets::new(sess, store))
4953
}
5054

5155
fn process_command_line(&mut self, sess: &Session, store: &LintStore) {
@@ -160,14 +164,18 @@ pub struct BuilderPush {
160164
}
161165

162166
impl<'a> LintLevelsBuilder<'a> {
163-
pub fn new(sess: &'a Session, sets: LintLevelSets) -> LintLevelsBuilder<'a> {
167+
pub fn new(
168+
sess: &'a Session,
169+
warn_about_weird_lints: bool,
170+
sets: LintLevelSets,
171+
) -> LintLevelsBuilder<'a> {
164172
assert_eq!(sets.list.len(), 1);
165173
LintLevelsBuilder {
166174
sess,
167175
sets,
168176
cur: 0,
169177
id_to_set: Default::default(),
170-
warn_about_weird_lints: sess.buffered_lints.borrow().is_some(),
178+
warn_about_weird_lints,
171179
}
172180
}
173181

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
795795
assert_eq!(cnum, LOCAL_CRATE);
796796
let store = &tcx.lint_store;
797797
let mut builder = LintLevelMapBuilder {
798-
levels: LintLevelSets::builder(tcx.sess, &store),
798+
levels: LintLevelSets::builder(tcx.sess, false, &store),
799799
tcx: tcx,
800800
store: store,
801801
};

src/librustc/session/mod.rs

-40
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::hir::def_id::CrateNum;
66
use rustc_data_structures::fingerprint::Fingerprint;
77

88
use crate::lint;
9-
use crate::lint::builtin::BuiltinLintDiagnostics;
109
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
1110
use crate::session::search_paths::{PathKind, SearchPath};
1211
use crate::util::nodemap::{FxHashMap, FxHashSet};
@@ -77,13 +76,6 @@ pub struct Session {
7776
/// if the value stored here has been affected by path remapping.
7877
pub working_dir: (PathBuf, bool),
7978

80-
/// This is intended to be used from a single thread.
81-
///
82-
/// FIXME: there was a previous comment about this not being thread safe,
83-
/// but it's not clear how or why that's the case. The LintBuffer itself is certainly thread
84-
/// safe at least from a "Rust safety" standpoint.
85-
pub buffered_lints: Lock<Option<lint::LintBuffer>>,
86-
8779
/// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking
8880
/// (sub)diagnostics that have been set once, but should not be set again,
8981
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
@@ -366,37 +358,6 @@ impl Session {
366358
self.diagnostic().span_note_without_error(sp, msg)
367359
}
368360

369-
pub fn buffer_lint_late<S: Into<MultiSpan>>(
370-
&self,
371-
lint: &'static lint::Lint,
372-
id: ast::NodeId,
373-
sp: S,
374-
msg: &str,
375-
) {
376-
match *self.buffered_lints.borrow_mut() {
377-
Some(ref mut buffer) => {
378-
buffer.buffer_lint(lint, id, sp, msg);
379-
}
380-
None => bug!("can't buffer lints after HIR lowering"),
381-
}
382-
}
383-
384-
pub fn buffer_lint_with_diagnostic_late<S: Into<MultiSpan>>(
385-
&self,
386-
lint: &'static lint::Lint,
387-
id: ast::NodeId,
388-
sp: S,
389-
msg: &str,
390-
diagnostic: BuiltinLintDiagnostics,
391-
) {
392-
match *self.buffered_lints.borrow_mut() {
393-
Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic(
394-
lint, id, sp.into(), msg, diagnostic,
395-
),
396-
None => bug!("can't buffer lints after HIR lowering"),
397-
}
398-
}
399-
400361
pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
401362
let id = self.next_node_id.get();
402363

@@ -1220,7 +1181,6 @@ fn build_session_(
12201181
sysroot,
12211182
local_crate_source_file,
12221183
working_dir,
1223-
buffered_lints: Lock::new(Some(Default::default())),
12241184
one_time_diagnostics: Default::default(),
12251185
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
12261186
plugin_attributes: Lock::new(Vec::new()),

src/librustc_interface/passes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,16 @@ fn configure_and_expand_inner<'a>(
267267
lint_store,
268268
&krate,
269269
true,
270+
None,
270271
rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
271272
});
272273

273-
let lint_buffer = lint::LintBuffer::default();
274274
let mut resolver = Resolver::new(
275275
sess,
276276
&krate,
277277
crate_name,
278278
metadata_loader,
279279
&resolver_arenas,
280-
lint_buffer,
281280
);
282281
syntax_ext::register_builtin_macros(&mut resolver, sess.edition());
283282

@@ -295,7 +294,7 @@ fn configure_and_expand_inner<'a>(
295294
krate
296295
});
297296

298-
util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer);
297+
util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer());
299298

300299
syntax_ext::plugin_macro_defs::inject(
301300
&mut krate, &mut resolver, plugin_info.syntax_exts, sess.edition()
@@ -370,7 +369,7 @@ fn configure_and_expand_inner<'a>(
370369
for span in missing_fragment_specifiers {
371370
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
372371
let msg = "missing fragment specifier";
373-
resolver.lint_buffer.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
372+
resolver.lint_buffer().buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
374373
}
375374
if cfg!(windows) {
376375
env::set_var("PATH", &old_path);
@@ -399,7 +398,7 @@ fn configure_and_expand_inner<'a>(
399398
}
400399

401400
let has_proc_macro_decls = time(sess, "AST validation", || {
402-
ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer)
401+
ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer())
403402
});
404403

405404

@@ -468,7 +467,7 @@ fn configure_and_expand_inner<'a>(
468467
info!("{} parse sess buffered_lints", buffered_lints.len());
469468
for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
470469
let lint = lint::Lint::from_parser_lint_id(lint_id);
471-
resolver.lint_buffer.buffer_lint(lint, id, span, &msg);
470+
resolver.lint_buffer().buffer_lint(lint, id, span, &msg);
472471
}
473472
});
474473

@@ -500,6 +499,7 @@ pub fn lower_to_hir(
500499
lint_store,
501500
&krate,
502501
false,
502+
Some(std::mem::take(resolver.lint_buffer())),
503503
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
504504
)
505505
});

src/librustc_resolve/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ pub struct Resolver<'a> {
963963
/// when visiting the correspondent variants.
964964
variant_vis: DefIdMap<ty::Visibility>,
965965

966-
pub lint_buffer: lint::LintBuffer,
966+
lint_buffer: lint::LintBuffer,
967967
}
968968

969969
/// Nothing really interesting here; it just provides memory for the rest of the crate.
@@ -1094,8 +1094,7 @@ impl<'a> Resolver<'a> {
10941094
krate: &Crate,
10951095
crate_name: &str,
10961096
metadata_loader: &'a MetadataLoaderDyn,
1097-
arenas: &'a ResolverArenas<'a>,
1098-
lint_buffer: lint::LintBuffer)
1097+
arenas: &'a ResolverArenas<'a>)
10991098
-> Resolver<'a> {
11001099
let root_def_id = DefId::local(CRATE_DEF_INDEX);
11011100
let root_module_kind = ModuleKind::Def(
@@ -1235,10 +1234,14 @@ impl<'a> Resolver<'a> {
12351234
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
12361235
.collect(),
12371236
variant_vis: Default::default(),
1238-
lint_buffer,
1237+
lint_buffer: lint::LintBuffer::default(),
12391238
}
12401239
}
12411240

1241+
pub fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
1242+
&mut self.lint_buffer
1243+
}
1244+
12421245
pub fn arenas() -> ResolverArenas<'a> {
12431246
Default::default()
12441247
}

0 commit comments

Comments
 (0)