From cdd805506e7a01d60906f8b153afb697d687609d Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 7 Sep 2019 09:57:11 -0400 Subject: Replace DiagnosticBuilder with Diagnostic when emitting error --- src/libsyntax/parse/lexer/tests.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/lexer/tests.rs b/src/libsyntax/parse/lexer/tests.rs index c1ec41902e2..de301b1fc49 100644 --- a/src/libsyntax/parse/lexer/tests.rs +++ b/src/libsyntax/parse/lexer/tests.rs @@ -18,6 +18,7 @@ fn mk_sess(sm: Lrc) -> ParseSess { false, false, None, + false, ); ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm) } -- cgit 1.4.1-3-g733a5 From 2a3930d43ced5204f53a6e1eebd741a81c4c1e9a Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 7 Sep 2019 10:20:56 -0400 Subject: Privatize DiagnosticBuilder constructors --- src/librustc/dep_graph/graph.rs | 4 ++-- src/librustc/ty/query/plumbing.rs | 7 +++---- src/librustc_errors/diagnostic_builder.rs | 5 +++-- src/librustc_errors/lib.rs | 5 ++--- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_typeck/check/writeback.rs | 3 +-- src/libsyntax/ext/proc_macro_server.rs | 4 ++-- src/libsyntax/lib.rs | 4 ++-- src/libsyntax/parse/mod.rs | 2 +- 9 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 7eea336cbbf..e76a70350b3 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -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 @@ impl DepGraph { 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 diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index d199a26475b..a1828bb5ab7 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -330,14 +330,13 @@ impl<'tcx> TyCtxt<'tcx> { 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; diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 25ffb146da7..e85388bfea2 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -346,7 +346,7 @@ impl<'a> DiagnosticBuilder<'a> { /// 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 @@ impl<'a> DiagnosticBuilder<'a> { /// 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, diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 11e2265cf36..51309f37e17 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -742,12 +742,11 @@ impl Handler { 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; } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 1d3576244c4..32c6dd67a4b 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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); } } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 487dc8ec2ae..1cc71ea5649 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -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 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { 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); } } } diff --git a/src/libsyntax/ext/proc_macro_server.rs b/src/libsyntax/ext/proc_macro_server.rs index 544ec789d80..dfec9ee2880 100644 --- a/src/libsyntax/ext/proc_macro_server.rs +++ b/src/libsyntax/ext/proc_macro_server.rs @@ -4,7 +4,7 @@ use crate::parse::{self, token, ParseSess}; 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 @@ impl server::Diagnostic for Rustc<'_> { 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); } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index aaf6f3e537e..b4ae1e87bca 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -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() } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2441a027f99..c4f31bcd9b0 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -306,7 +306,7 @@ fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option) 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(); } } -- cgit 1.4.1-3-g733a5 From 998df0d70b0c837d52a1c8100773409390df840c Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 7 Sep 2019 10:38:02 -0400 Subject: Remove Handler::cancel --- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc_errors/lib.rs | 4 ---- src/libsyntax/parse/attr.rs | 4 ++-- src/libsyntax/parse/diagnostics.rs | 8 +------- src/libsyntax/parse/parser/expr.rs | 2 +- src/libsyntax/parse/parser/pat.rs | 2 +- src/libsyntax/parse/parser/stmt.rs | 2 +- 7 files changed, 7 insertions(+), 17 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index ab24b3f2f05..0b6740d7bbb 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1119,7 +1119,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { Some((expected, found)) => Some((expected, found)), None => { // Derived error. Cancel the emitter. - self.tcx.sess.diagnostic().cancel(diag); + diag.cancel(); return; } }; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 51309f37e17..47ac2e5a667 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -520,10 +520,6 @@ impl Handler { DiagnosticBuilder::new(self, Level::Fatal, msg) } - pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) { - err.cancel(); - } - fn panic_if_treat_err_as_bug(&self) { if self.treat_err_as_bug() { let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 9aa1ec0b14f..9fbed66854c 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -309,14 +309,14 @@ impl<'a> Parser<'a> { Ok(lit) => { return Ok(ast::NestedMetaItem::Literal(lit)) } - Err(ref mut err) => self.diagnostic().cancel(err) + Err(ref mut err) => err.cancel(), } match self.parse_meta_item() { Ok(mi) => { return Ok(ast::NestedMetaItem::MetaItem(mi)) } - Err(ref mut err) => self.diagnostic().cancel(err) + Err(ref mut err) => err.cancel(), } let found = self.this_token_to_string(); diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index b74f2492c35..1e7058ff715 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -197,10 +197,6 @@ impl<'a> Parser<'a> { self.sess.span_diagnostic.span_bug(sp, m) } - crate fn cancel(&self, err: &mut DiagnosticBuilder<'_>) { - self.sess.span_diagnostic.cancel(err) - } - crate fn diagnostic(&self) -> &'a errors::Handler { &self.sess.span_diagnostic } @@ -426,15 +422,13 @@ impl<'a> Parser<'a> { /// Eats and discards tokens until one of `kets` is encountered. Respects token trees, /// passes through any errors encountered. Used for error recovery. crate fn eat_to_tokens(&mut self, kets: &[&TokenKind]) { - let handler = self.diagnostic(); - if let Err(ref mut err) = self.parse_seq_to_before_tokens( kets, SeqSep::none(), TokenExpectType::Expect, |p| Ok(p.parse_token_tree()), ) { - handler.cancel(err); + err.cancel(); } } diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index 31b28443abb..5764934b3cd 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -770,7 +770,7 @@ impl<'a> Parser<'a> { ex = ExprKind::Lit(literal); } Err(mut err) => { - self.cancel(&mut err); + err.cancel(); return Err(self.expected_expression_found()); } } diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs index 08ee3a6bd86..3c624959ead 100644 --- a/src/libsyntax/parse/parser/pat.rs +++ b/src/libsyntax/parse/parser/pat.rs @@ -537,7 +537,7 @@ impl<'a> Parser<'a> { mut err: DiagnosticBuilder<'a>, expected: Expected, ) -> PResult<'a, P> { - self.cancel(&mut err); + err.cancel(); let expected = expected.unwrap_or("pattern"); let msg = format!("expected {}, found {}", expected, self.this_token_descr()); diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index 04bd61a4cfb..02da56f6e35 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -361,7 +361,7 @@ impl<'a> Parser<'a> { } Err(mut e) => { self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore); - self.cancel(&mut e); + e.cancel(); } _ => () } -- cgit 1.4.1-3-g733a5