]> git.lizzy.rs Git - rust.git/commitdiff
Privatize DiagnosticBuilder constructors
authorMark Rousskov <mark.simulacrum@gmail.com>
Sat, 7 Sep 2019 14:20:56 +0000 (10:20 -0400)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 17 Sep 2019 13:30:44 +0000 (09:30 -0400)
src/librustc/dep_graph/graph.rs
src/librustc/ty/query/plumbing.rs
src/librustc_errors/diagnostic_builder.rs
src/librustc_errors/lib.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_typeck/check/writeback.rs
src/libsyntax/ext/proc_macro_server.rs
src/libsyntax/lib.rs
src/libsyntax/parse/mod.rs

index 7eea336cbbfa1e3804f0c7fc6c68e533433a1695..e76a70350b33eb4b4c80c590e07a6d866f6dc202 100644 (file)
@@ -1,4 +1,4 @@
-use errors::{Diagnostic, DiagnosticBuilder};
+use errors::Diagnostic;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
@@ -819,7 +819,7 @@ fn emit_diagnostics<'tcx>(
             let handle = tcx.sess.diagnostic();
 
             for diagnostic in diagnostics {
-                DiagnosticBuilder::new_diagnostic(handle, diagnostic).emit();
+                handle.emit_diagnostic(&diagnostic);
             }
 
             // Mark the node as green now that diagnostics are emitted
index d199a26475be706b891010fe7100d95ae0aeae40..a1828bb5ab7a7cacbf6fb1692deb2e2da7bd8d21 100644 (file)
@@ -330,14 +330,13 @@ pub fn try_print_query_stack() {
                 let mut i = 0;
 
                 while let Some(query) = current_query {
-                    let mut db = DiagnosticBuilder::new(icx.tcx.sess.diagnostic(),
-                        Level::FailureNote,
+                    let mut diag = Diagnostic::new(Level::FailureNote,
                         &format!("#{} [{}] {}",
                                  i,
                                  query.info.query.name(),
                                  query.info.query.describe(icx.tcx)));
-                    db.set_span(icx.tcx.sess.source_map().def_span(query.info.span));
-                    icx.tcx.sess.diagnostic().force_print_db(db);
+                    diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into();
+                    icx.tcx.sess.diagnostic().force_print_diagnostic(diag);
 
                     current_query = query.parent.clone();
                     i += 1;
index 25ffb146da7568a4b4b3480b61509b7c9271ccaa..e85388bfea29c51aa60ecc282f756093fc7e6af7 100644 (file)
@@ -346,7 +346,7 @@ pub fn allow_suggestions(&mut self, allow: bool) -> &mut Self {
 
     /// Convenience function for internal use, clients should use one of the
     /// struct_* methods on Handler.
-    pub fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
+    crate fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
         DiagnosticBuilder::new_with_code(handler, level, None, message)
     }
 
@@ -363,7 +363,8 @@ pub fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuild
 
     /// Creates a new `DiagnosticBuilder` with an already constructed
     /// diagnostic.
-    pub fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> DiagnosticBuilder<'a> {
+    crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic)
+                         -> DiagnosticBuilder<'a> {
         DiagnosticBuilder(Box::new(DiagnosticBuilderInner {
             handler,
             diagnostic,
index 11e2265cf3618962b95e01f82139be606b2e1f68..51309f37e174f6c41f00c1a7de115406eaa85c84 100644 (file)
@@ -742,12 +742,11 @@ pub fn must_teach(&self, code: &DiagnosticId) -> bool {
         self.taught_diagnostics.borrow_mut().insert(code.clone())
     }
 
-    pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
+    pub fn force_print_diagnostic(&self, db: Diagnostic) {
         self.emitter.borrow_mut().emit_diagnostic(&db);
-        db.cancel();
     }
 
-    fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
+    pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
         if diagnostic.cancelled() {
             return;
         }
index 1d3576244c4afc0d597389a18b5231e0a32fbf6d..32c6dd67a4b5af42a6c6b58828b0d6d7e7da26a6 100644 (file)
@@ -402,7 +402,7 @@ fn do_mir_borrowck<'a, 'tcx>(
         }
 
         for diag in mbcx.errors_buffer.drain(..) {
-            DiagnosticBuilder::new_diagnostic(mbcx.infcx.tcx.sess.diagnostic(), diag).emit();
+            mbcx.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
         }
     }
 
index 487dc8ec2ae0ca75adc7230e72c3dcb308cee827..1cc71ea5649de23e056dc3a559a7643702e79149 100644 (file)
@@ -3,7 +3,6 @@
 // substitutions.
 
 use crate::check::FnCtxt;
-use errors::DiagnosticBuilder;
 use rustc::hir;
 use rustc::hir::def_id::{DefId, DefIndex};
 use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -407,7 +406,7 @@ fn visit_user_provided_tys(&mut self) {
         if !errors_buffer.is_empty() {
             errors_buffer.sort_by_key(|diag| diag.span.primary_span());
             for diag in errors_buffer.drain(..) {
-                DiagnosticBuilder::new_diagnostic(self.tcx().sess.diagnostic(), diag).emit();
+                self.tcx().sess.diagnostic().emit_diagnostic(&diag);
             }
         }
     }
index 544ec789d80a9d62d7ed9a74465adfb4c67a3008..dfec9ee28809a098d38d9a2459c077758e856052 100644 (file)
@@ -4,7 +4,7 @@
 use crate::parse::lexer::comments;
 use crate::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
 
-use errors::{Diagnostic, DiagnosticBuilder};
+use errors::Diagnostic;
 use rustc_data_structures::sync::Lrc;
 use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
 use syntax_pos::symbol::{kw, sym, Symbol};
@@ -650,7 +650,7 @@ fn sub(
         diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
     }
     fn emit(&mut self, diag: Self::Diagnostic) {
-        DiagnosticBuilder::new_diagnostic(&self.sess.span_diagnostic, diag).emit()
+        self.sess.span_diagnostic.emit_diagnostic(&diag);
     }
 }
 
index aaf6f3e537eb6693de0c926ec4af6517c5561b26..b4ae1e87bca28fb65e63b525742a2c132bb198a8 100644 (file)
@@ -60,12 +60,12 @@ macro_rules! panictry {
 macro_rules! panictry_buffer {
     ($handler:expr, $e:expr) => ({
         use std::result::Result::{Ok, Err};
-        use errors::{FatalError, DiagnosticBuilder};
+        use errors::FatalError;
         match $e {
             Ok(e) => e,
             Err(errs) => {
                 for e in errs {
-                    DiagnosticBuilder::new_diagnostic($handler, e).emit();
+                    $handler.emit_diagnostic(&e);
                 }
                 FatalError.raise()
             }
index 2441a027f9940b7e2f6faf53521753f7833ac491..c4f31bcd9b041fc40d676de9faea946c3a8c6a73 100644 (file)
@@ -306,7 +306,7 @@ fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
     match try_file_to_source_file(sess, path, spanopt) {
         Ok(source_file) => source_file,
         Err(d) => {
-            DiagnosticBuilder::new_diagnostic(&sess.span_diagnostic, d).emit();
+            sess.span_diagnostic.emit_diagnostic(&d);
             FatalError.raise();
         }
     }