Skip to content

Commit 2a3930d

Browse files
Privatize DiagnosticBuilder constructors
1 parent 0b586b4 commit 2a3930d

File tree

9 files changed

+17
-19
lines changed

9 files changed

+17
-19
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use errors::{Diagnostic, DiagnosticBuilder};
1+
use errors::Diagnostic;
22
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
@@ -819,7 +819,7 @@ impl DepGraph {
819819
let handle = tcx.sess.diagnostic();
820820

821821
for diagnostic in diagnostics {
822-
DiagnosticBuilder::new_diagnostic(handle, diagnostic).emit();
822+
handle.emit_diagnostic(&diagnostic);
823823
}
824824

825825
// Mark the node as green now that diagnostics are emitted

src/librustc/ty/query/plumbing.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,13 @@ impl<'tcx> TyCtxt<'tcx> {
330330
let mut i = 0;
331331

332332
while let Some(query) = current_query {
333-
let mut db = DiagnosticBuilder::new(icx.tcx.sess.diagnostic(),
334-
Level::FailureNote,
333+
let mut diag = Diagnostic::new(Level::FailureNote,
335334
&format!("#{} [{}] {}",
336335
i,
337336
query.info.query.name(),
338337
query.info.query.describe(icx.tcx)));
339-
db.set_span(icx.tcx.sess.source_map().def_span(query.info.span));
340-
icx.tcx.sess.diagnostic().force_print_db(db);
338+
diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into();
339+
icx.tcx.sess.diagnostic().force_print_diagnostic(diag);
341340

342341
current_query = query.parent.clone();
343342
i += 1;

src/librustc_errors/diagnostic_builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'a> DiagnosticBuilder<'a> {
346346

347347
/// Convenience function for internal use, clients should use one of the
348348
/// struct_* methods on Handler.
349-
pub fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
349+
crate fn new(handler: &'a Handler, level: Level, message: &str) -> DiagnosticBuilder<'a> {
350350
DiagnosticBuilder::new_with_code(handler, level, None, message)
351351
}
352352

@@ -363,7 +363,8 @@ impl<'a> DiagnosticBuilder<'a> {
363363

364364
/// Creates a new `DiagnosticBuilder` with an already constructed
365365
/// diagnostic.
366-
pub fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> DiagnosticBuilder<'a> {
366+
crate fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic)
367+
-> DiagnosticBuilder<'a> {
367368
DiagnosticBuilder(Box::new(DiagnosticBuilderInner {
368369
handler,
369370
diagnostic,

src/librustc_errors/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,11 @@ impl Handler {
742742
self.taught_diagnostics.borrow_mut().insert(code.clone())
743743
}
744744

745-
pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
745+
pub fn force_print_diagnostic(&self, db: Diagnostic) {
746746
self.emitter.borrow_mut().emit_diagnostic(&db);
747-
db.cancel();
748747
}
749748

750-
fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
749+
pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) {
751750
if diagnostic.cancelled() {
752751
return;
753752
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn do_mir_borrowck<'a, 'tcx>(
402402
}
403403

404404
for diag in mbcx.errors_buffer.drain(..) {
405-
DiagnosticBuilder::new_diagnostic(mbcx.infcx.tcx.sess.diagnostic(), diag).emit();
405+
mbcx.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
406406
}
407407
}
408408

src/librustc_typeck/check/writeback.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// substitutions.
44

55
use crate::check::FnCtxt;
6-
use errors::DiagnosticBuilder;
76
use rustc::hir;
87
use rustc::hir::def_id::{DefId, DefIndex};
98
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -407,7 +406,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
407406
if !errors_buffer.is_empty() {
408407
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
409408
for diag in errors_buffer.drain(..) {
410-
DiagnosticBuilder::new_diagnostic(self.tcx().sess.diagnostic(), diag).emit();
409+
self.tcx().sess.diagnostic().emit_diagnostic(&diag);
411410
}
412411
}
413412
}

src/libsyntax/ext/proc_macro_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::parse::{self, token, ParseSess};
44
use crate::parse::lexer::comments;
55
use crate::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
66

7-
use errors::{Diagnostic, DiagnosticBuilder};
7+
use errors::Diagnostic;
88
use rustc_data_structures::sync::Lrc;
99
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
1010
use syntax_pos::symbol::{kw, sym, Symbol};
@@ -650,7 +650,7 @@ impl server::Diagnostic for Rustc<'_> {
650650
diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
651651
}
652652
fn emit(&mut self, diag: Self::Diagnostic) {
653-
DiagnosticBuilder::new_diagnostic(&self.sess.span_diagnostic, diag).emit()
653+
self.sess.span_diagnostic.emit_diagnostic(&diag);
654654
}
655655
}
656656

src/libsyntax/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ macro_rules! panictry {
6060
macro_rules! panictry_buffer {
6161
($handler:expr, $e:expr) => ({
6262
use std::result::Result::{Ok, Err};
63-
use errors::{FatalError, DiagnosticBuilder};
63+
use errors::FatalError;
6464
match $e {
6565
Ok(e) => e,
6666
Err(errs) => {
6767
for e in errs {
68-
DiagnosticBuilder::new_diagnostic($handler, e).emit();
68+
$handler.emit_diagnostic(&e);
6969
}
7070
FatalError.raise()
7171
}

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
306306
match try_file_to_source_file(sess, path, spanopt) {
307307
Ok(source_file) => source_file,
308308
Err(d) => {
309-
DiagnosticBuilder::new_diagnostic(&sess.span_diagnostic, d).emit();
309+
sess.span_diagnostic.emit_diagnostic(&d);
310310
FatalError.raise();
311311
}
312312
}

0 commit comments

Comments
 (0)