about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-10-25 13:41:51 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2019-11-03 21:52:42 -0500
commitc68df7c503676a1f63c0fcc2a7f10597fb93c375 (patch)
tree170b18bab174d5a853861ef72aff81183965df03
parentc0fdddcb6001b6bd0cd7a6397b9e01e019e553ff (diff)
downloadrust-c68df7c503676a1f63c0fcc2a7f10597fb93c375.tar.gz
rust-c68df7c503676a1f63c0fcc2a7f10597fb93c375.zip
Delete lint buffer from Session
-rw-r--r--src/librustc/lint/context.rs26
-rw-r--r--src/librustc/lint/levels.rs16
-rw-r--r--src/librustc/lint/mod.rs2
-rw-r--r--src/librustc/session/mod.rs40
-rw-r--r--src/librustc_interface/passes.rs12
-rw-r--r--src/librustc_resolve/lib.rs11
6 files changed, 39 insertions, 68 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index 1cb53d754dc..eef1cee8db3 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -34,7 +34,6 @@ use crate::util::common::time;
 
 use errors::DiagnosticBuilder;
 use std::slice;
-use std::default::Default as StdDefault;
 use rustc_data_structures::sync::{self, ParallelIterator, join, par_iter};
 use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
 use syntax::ast;
@@ -584,12 +583,13 @@ impl<'a> EarlyContext<'a> {
         lint_store: &'a LintStore,
         krate: &'a ast::Crate,
         buffered: LintBuffer,
+        warn_about_weird_lints: bool,
     ) -> EarlyContext<'a> {
         EarlyContext {
             sess,
             krate,
             lint_store,
-            builder: LintLevelSets::builder(sess, lint_store),
+            builder: LintLevelSets::builder(sess, warn_about_weird_lints, lint_store),
             buffered,
         }
     }
@@ -1490,9 +1490,10 @@ fn early_lint_crate<T: EarlyLintPass>(
     krate: &ast::Crate,
     pass: T,
     buffered: LintBuffer,
+    warn_about_weird_lints: bool,
 ) -> LintBuffer {
     let mut cx = EarlyContextAndPass {
-        context: EarlyContext::new(sess, lint_store, krate, buffered),
+        context: EarlyContext::new(sess, lint_store, krate, buffered, warn_about_weird_lints),
         pass,
     };
 
@@ -1514,22 +1515,19 @@ pub fn check_ast_crate<T: EarlyLintPass>(
     lint_store: &LintStore,
     krate: &ast::Crate,
     pre_expansion: bool,
+    lint_buffer: Option<LintBuffer>,
     builtin_lints: T,
 ) {
-    let (mut passes, mut buffered): (Vec<_>, _) = if pre_expansion {
-        (
-            lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect(),
-            LintBuffer::default(),
-        )
+    let mut passes: Vec<_> = if pre_expansion {
+        lint_store.pre_expansion_passes.iter().map(|p| (p)()).collect()
     } else {
-        (
-            lint_store.early_passes.iter().map(|p| (p)()).collect(),
-            sess.buffered_lints.borrow_mut().take().unwrap(),
-        )
+        lint_store.early_passes.iter().map(|p| (p)()).collect()
     };
+    let mut buffered = lint_buffer.unwrap_or_default();
 
     if !sess.opts.debugging_opts.no_interleave_lints {
-        buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered);
+        buffered = early_lint_crate(sess, lint_store, krate, builtin_lints, buffered,
+            pre_expansion);
 
         if !passes.is_empty() {
             buffered = early_lint_crate(
@@ -1538,6 +1536,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
                 krate,
                 EarlyLintPassObjects { lints: &mut passes[..] },
                 buffered,
+                pre_expansion,
             );
         }
     } else {
@@ -1549,6 +1548,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
                     krate,
                     EarlyLintPassObjects { lints: slice::from_mut(pass) },
                     buffered,
+                    pre_expansion,
                 )
             });
         }
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 4c60492e470..e470dbdf323 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -44,8 +44,12 @@ impl LintLevelSets {
         return me
     }
 
-    pub fn builder<'a>(sess: &'a Session, store: &LintStore) -> LintLevelsBuilder<'a> {
-        LintLevelsBuilder::new(sess, LintLevelSets::new(sess, store))
+    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) {
@@ -160,14 +164,18 @@ pub struct BuilderPush {
 }
 
 impl<'a> LintLevelsBuilder<'a> {
-    pub fn new(sess: &'a Session, sets: LintLevelSets) -> LintLevelsBuilder<'a> {
+    pub fn new(
+        sess: &'a Session,
+        warn_about_weird_lints: bool,
+        sets: LintLevelSets,
+    ) -> LintLevelsBuilder<'a> {
         assert_eq!(sets.list.len(), 1);
         LintLevelsBuilder {
             sess,
             sets,
             cur: 0,
             id_to_set: Default::default(),
-            warn_about_weird_lints: sess.buffered_lints.borrow().is_some(),
+            warn_about_weird_lints,
         }
     }
 
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index 42f33740b23..11d0d0d90fa 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -795,7 +795,7 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
     assert_eq!(cnum, LOCAL_CRATE);
     let store = &tcx.lint_store;
     let mut builder = LintLevelMapBuilder {
-        levels: LintLevelSets::builder(tcx.sess, &store),
+        levels: LintLevelSets::builder(tcx.sess, false, &store),
         tcx: tcx,
         store: store,
     };
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 9ab5b9f13b1..13b76b79b3d 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -6,7 +6,6 @@ use crate::hir::def_id::CrateNum;
 use rustc_data_structures::fingerprint::Fingerprint;
 
 use crate::lint;
-use crate::lint::builtin::BuiltinLintDiagnostics;
 use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
 use crate::session::search_paths::{PathKind, SearchPath};
 use crate::util::nodemap::{FxHashMap, FxHashSet};
@@ -77,13 +76,6 @@ pub struct Session {
     /// if the value stored here has been affected by path remapping.
     pub working_dir: (PathBuf, bool),
 
-    /// This is intended to be used from a single thread.
-    ///
-    /// FIXME: there was a previous comment about this not being thread safe,
-    /// but it's not clear how or why that's the case. The LintBuffer itself is certainly thread
-    /// safe at least from a "Rust safety" standpoint.
-    pub buffered_lints: Lock<Option<lint::LintBuffer>>,
-
     /// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking
     /// (sub)diagnostics that have been set once, but should not be set again,
     /// in order to avoid redundantly verbose output (Issue #24690, #44953).
@@ -366,37 +358,6 @@ impl Session {
         self.diagnostic().span_note_without_error(sp, msg)
     }
 
-    pub fn buffer_lint_late<S: Into<MultiSpan>>(
-        &self,
-        lint: &'static lint::Lint,
-        id: ast::NodeId,
-        sp: S,
-        msg: &str,
-    ) {
-        match *self.buffered_lints.borrow_mut() {
-            Some(ref mut buffer) => {
-                buffer.buffer_lint(lint, id, sp, msg);
-            }
-            None => bug!("can't buffer lints after HIR lowering"),
-        }
-    }
-
-    pub fn buffer_lint_with_diagnostic_late<S: Into<MultiSpan>>(
-        &self,
-        lint: &'static lint::Lint,
-        id: ast::NodeId,
-        sp: S,
-        msg: &str,
-        diagnostic: BuiltinLintDiagnostics,
-    ) {
-        match *self.buffered_lints.borrow_mut() {
-            Some(ref mut buffer) => buffer.buffer_lint_with_diagnostic(
-                lint, id, sp.into(), msg, diagnostic,
-            ),
-            None => bug!("can't buffer lints after HIR lowering"),
-        }
-    }
-
     pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
         let id = self.next_node_id.get();
 
@@ -1220,7 +1181,6 @@ fn build_session_(
         sysroot,
         local_crate_source_file,
         working_dir,
-        buffered_lints: Lock::new(Some(Default::default())),
         one_time_diagnostics: Default::default(),
         plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
         plugin_attributes: Lock::new(Vec::new()),
diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs
index b6395ccb500..52332744d1a 100644
--- a/src/librustc_interface/passes.rs
+++ b/src/librustc_interface/passes.rs
@@ -267,17 +267,16 @@ fn configure_and_expand_inner<'a>(
             lint_store,
             &krate,
             true,
+            None,
             rustc_lint::BuiltinCombinedPreExpansionLintPass::new());
     });
 
-    let lint_buffer = lint::LintBuffer::default();
     let mut resolver = Resolver::new(
         sess,
         &krate,
         crate_name,
         metadata_loader,
         &resolver_arenas,
-        lint_buffer,
     );
     syntax_ext::register_builtin_macros(&mut resolver, sess.edition());
 
@@ -295,7 +294,7 @@ fn configure_and_expand_inner<'a>(
         krate
     });
 
-    util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer);
+    util::check_attr_crate_type(&krate.attrs, &mut resolver.lint_buffer());
 
     syntax_ext::plugin_macro_defs::inject(
         &mut krate, &mut resolver, plugin_info.syntax_exts, sess.edition()
@@ -370,7 +369,7 @@ fn configure_and_expand_inner<'a>(
         for span in missing_fragment_specifiers {
             let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
             let msg = "missing fragment specifier";
-            resolver.lint_buffer.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
+            resolver.lint_buffer().buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
         }
         if cfg!(windows) {
             env::set_var("PATH", &old_path);
@@ -399,7 +398,7 @@ fn configure_and_expand_inner<'a>(
     }
 
     let has_proc_macro_decls = time(sess, "AST validation", || {
-        ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer)
+        ast_validation::check_crate(sess, &krate, &mut resolver.lint_buffer())
     });
 
 
@@ -468,7 +467,7 @@ fn configure_and_expand_inner<'a>(
         info!("{} parse sess buffered_lints", buffered_lints.len());
         for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
             let lint = lint::Lint::from_parser_lint_id(lint_id);
-            resolver.lint_buffer.buffer_lint(lint, id, span, &msg);
+            resolver.lint_buffer().buffer_lint(lint, id, span, &msg);
         }
     });
 
@@ -500,6 +499,7 @@ pub fn lower_to_hir(
             lint_store,
             &krate,
             false,
+            Some(std::mem::take(resolver.lint_buffer())),
             rustc_lint::BuiltinCombinedEarlyLintPass::new(),
         )
     });
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index baeabbf3c1d..b45eb356bdb 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -963,7 +963,7 @@ pub struct Resolver<'a> {
     /// when visiting the correspondent variants.
     variant_vis: DefIdMap<ty::Visibility>,
 
-    pub lint_buffer: lint::LintBuffer,
+    lint_buffer: lint::LintBuffer,
 }
 
 /// Nothing really interesting here; it just provides memory for the rest of the crate.
@@ -1094,8 +1094,7 @@ impl<'a> Resolver<'a> {
                krate: &Crate,
                crate_name: &str,
                metadata_loader: &'a MetadataLoaderDyn,
-               arenas: &'a ResolverArenas<'a>,
-               lint_buffer: lint::LintBuffer)
+               arenas: &'a ResolverArenas<'a>)
                -> Resolver<'a> {
         let root_def_id = DefId::local(CRATE_DEF_INDEX);
         let root_module_kind = ModuleKind::Def(
@@ -1235,10 +1234,14 @@ impl<'a> Resolver<'a> {
                     .chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
                     .collect(),
             variant_vis: Default::default(),
-            lint_buffer,
+            lint_buffer: lint::LintBuffer::default(),
         }
     }
 
+    pub fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
+        &mut self.lint_buffer
+    }
+
     pub fn arenas() -> ResolverArenas<'a> {
         Default::default()
     }