Skip to content

Commit b304e60

Browse files
Remove Handler::{emit, emit_with_code}
1 parent 998df0d commit b304e60

File tree

4 files changed

+40
-53
lines changed

4 files changed

+40
-53
lines changed

src/librustc/session/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
13941394
Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
13951395
};
13961396
let handler = errors::Handler::with_emitter(true, None, emitter);
1397-
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
1397+
handler.struct_fatal(msg).emit();
13981398
errors::FatalError.raise();
13991399
}
14001400

@@ -1408,7 +1408,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
14081408
Box::new(JsonEmitter::basic(pretty, json_rendered, false)),
14091409
};
14101410
let handler = errors::Handler::with_emitter(true, None, emitter);
1411-
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
1411+
handler.struct_warn(msg).emit();
14121412
}
14131413

14141414
pub type CompileResult = Result<(), ErrorReported>;

src/librustc_codegen_ssa/back/write.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_errors::emitter::{Emitter};
2727
use rustc_target::spec::MergeFunctions;
2828
use syntax::attr;
2929
use syntax::ext::hygiene::ExpnId;
30-
use syntax_pos::MultiSpan;
3130
use syntax_pos::symbol::{Symbol, sym};
3231
use jobserver::{Client, Acquired};
3332

@@ -1760,19 +1759,12 @@ impl SharedEmitterMain {
17601759
match message {
17611760
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
17621761
let handler = sess.diagnostic();
1763-
match diag.code {
1764-
Some(ref code) => {
1765-
handler.emit_with_code(&MultiSpan::new(),
1766-
&diag.msg,
1767-
code.clone(),
1768-
diag.lvl);
1769-
}
1770-
None => {
1771-
handler.emit(&MultiSpan::new(),
1772-
&diag.msg,
1773-
diag.lvl);
1774-
}
1762+
let mut d = rustc_errors::Diagnostic::new(diag.lvl, &diag.msg);
1763+
if let Some(code) = diag.code {
1764+
d.code(code);
17751765
}
1766+
handler.emit_diagnostic(&d);
1767+
handler.abort_if_errors_and_should_abort();
17761768
}
17771769
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
17781770
sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg)

src/librustc_driver/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use syntax::source_map::FileLoader;
6666
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
6767
use syntax::parse::{self, PResult};
6868
use syntax::symbol::sym;
69-
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
69+
use syntax_pos::{DUMMY_SP, FileName};
7070

7171
pub mod pretty;
7272
mod args;
@@ -1203,9 +1203,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12031203
// a .span_bug or .bug call has already printed what
12041204
// it wants to print.
12051205
if !info.payload().is::<errors::ExplicitBug>() {
1206-
handler.emit(&MultiSpan::new(),
1207-
"unexpected panic",
1208-
errors::Level::Bug);
1206+
let d = errors::Diagnostic::new(errors::Level::Bug, "unexpected panic");
1207+
handler.emit_diagnostic(&d);
1208+
handler.abort_if_errors_and_should_abort();
12091209
}
12101210

12111211
let mut xs: Vec<Cow<'static, str>> = vec![
@@ -1225,9 +1225,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12251225
}
12261226

12271227
for note in &xs {
1228-
handler.emit(&MultiSpan::new(),
1229-
note,
1230-
errors::Level::Note);
1228+
handler.note_without_error(&note);
12311229
}
12321230

12331231
// If backtraces are enabled, also print the query stack

src/librustc_errors/lib.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,22 @@ impl Handler {
539539
}
540540

541541
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
542-
self.emit(&sp.into(), msg, Fatal);
542+
self.emit_diagnostic(Diagnostic::new(Fatal, msg).set_span(sp));
543+
self.abort_if_errors_and_should_abort();
543544
FatalError
544545
}
545546
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
546547
sp: S,
547548
msg: &str,
548549
code: DiagnosticId)
549550
-> FatalError {
550-
self.emit_with_code(&sp.into(), msg, code, Fatal);
551+
self.emit_diagnostic(Diagnostic::new_with_code(Fatal, Some(code), msg).set_span(sp));
552+
self.abort_if_errors_and_should_abort();
551553
FatalError
552554
}
553555
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
554-
self.emit(&sp.into(), msg, Error);
556+
self.emit_diagnostic(Diagnostic::new(Error, msg).set_span(sp));
557+
self.abort_if_errors_and_should_abort();
555558
}
556559
pub fn mut_span_err<S: Into<MultiSpan>>(&self,
557560
sp: S,
@@ -562,16 +565,20 @@ impl Handler {
562565
result
563566
}
564567
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
565-
self.emit_with_code(&sp.into(), msg, code, Error);
568+
self.emit_diagnostic(Diagnostic::new_with_code(Error, Some(code), msg).set_span(sp));
569+
self.abort_if_errors_and_should_abort();
566570
}
567571
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
568-
self.emit(&sp.into(), msg, Warning);
572+
self.emit_diagnostic(Diagnostic::new(Warning, msg).set_span(sp));
573+
self.abort_if_errors_and_should_abort();
569574
}
570575
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
571-
self.emit_with_code(&sp.into(), msg, code, Warning);
576+
self.emit_diagnostic(Diagnostic::new_with_code(Warning, Some(code), msg).set_span(sp));
577+
self.abort_if_errors_and_should_abort();
572578
}
573579
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
574-
self.emit(&sp.into(), msg, Bug);
580+
self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(sp));
581+
self.abort_if_errors_and_should_abort();
575582
panic!(ExplicitBug);
576583
}
577584
pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
@@ -590,10 +597,12 @@ impl Handler {
590597
self.delayed_span_bugs.borrow_mut().push(diagnostic);
591598
}
592599
pub fn span_bug_no_panic<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
593-
self.emit(&sp.into(), msg, Bug);
600+
self.emit_diagnostic(Diagnostic::new(Bug, msg).set_span(sp));
601+
self.abort_if_errors_and_should_abort();
594602
}
595603
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
596-
self.emit(&sp.into(), msg, Note);
604+
self.emit_diagnostic(Diagnostic::new(Note, msg).set_span(sp));
605+
self.abort_if_errors_and_should_abort();
597606
}
598607
pub fn span_note_diag(&self,
599608
sp: Span,
@@ -701,31 +710,15 @@ impl Handler {
701710
}
702711
}
703712

704-
pub fn abort_if_errors(&self) {
705-
if self.has_errors() {
713+
pub fn abort_if_errors_and_should_abort(&self) {
714+
if self.has_errors() && !self.continue_after_error.load(SeqCst) {
706715
FatalError.raise();
707716
}
708717
}
709-
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
710-
if lvl == Warning && !self.flags.can_emit_warnings {
711-
return;
712-
}
713-
let mut db = DiagnosticBuilder::new(self, lvl, msg);
714-
db.set_span(msp.clone());
715-
db.emit();
716-
if !self.continue_after_error.load(SeqCst) {
717-
self.abort_if_errors();
718-
}
719-
}
720-
pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) {
721-
if lvl == Warning && !self.flags.can_emit_warnings {
722-
return;
723-
}
724-
let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg);
725-
db.set_span(msp.clone());
726-
db.emit();
727-
if !self.continue_after_error.load(SeqCst) {
728-
self.abort_if_errors();
718+
719+
pub fn abort_if_errors(&self) {
720+
if self.has_errors() {
721+
FatalError.raise();
729722
}
730723
}
731724

@@ -747,6 +740,10 @@ impl Handler {
747740
return;
748741
}
749742

743+
if diagnostic.level == Warning && !self.flags.can_emit_warnings {
744+
return;
745+
}
746+
750747
TRACK_DIAGNOSTICS.with(|track_diagnostics| {
751748
track_diagnostics.get()(diagnostic);
752749
});

0 commit comments

Comments
 (0)