1 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3 #![feature(custom_attribute)]
4 #![allow(unused_attributes)]
5 #![feature(range_contains)]
6 #![cfg_attr(unix, feature(libc))]
8 #![feature(optin_builtin_traits)]
9 #![deny(rust_2018_idioms)]
11 #[allow(unused_extern_crates)]
12 extern crate serialize as rustc_serialize; // used by deriving
14 pub use emitter::ColorConfig;
18 use emitter::{Emitter, EmitterWriter};
20 use rustc_data_structures::sync::{self, Lrc, Lock, AtomicUsize, AtomicBool, SeqCst};
21 use rustc_data_structures::fx::FxHashSet;
22 use rustc_data_structures::stable_hasher::StableHasher;
26 use std::{error, fmt};
29 use termcolor::{ColorSpec, Color};
32 mod diagnostic_builder;
39 use syntax_pos::{BytePos,
48 /// Indicates the confidence in the correctness of a suggestion.
50 /// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion
51 /// to determine whether it should be automatically applied or if the user should be consulted
52 /// before applying the suggestion.
53 #[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
54 pub enum Applicability {
55 /// The suggestion is definitely what the user intended. This suggestion should be
56 /// automatically applied.
59 /// The suggestion may be what the user intended, but it is uncertain. The suggestion should
60 /// result in valid Rust code if it is applied.
63 /// The suggestion contains placeholders like `(...)` or `{ /* fields */ }`. The suggestion
64 /// cannot be applied automatically because it will not result in valid Rust code. The user
65 /// will need to fill in the placeholders.
68 /// The applicability of the suggestion is unknown.
72 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, RustcEncodable, RustcDecodable)]
73 pub enum SuggestionStyle {
74 /// Hide the suggested code when displaying this suggestion inline.
76 /// Always hide the suggested code but display the message.
78 /// Do not display this suggestion in the cli output, it is only meant for tools.
80 /// Always show the suggested code.
81 /// This will *not* show the code if the suggestion is inline *and* the suggested code is
86 impl SuggestionStyle {
87 fn hide_inline(&self) -> bool {
89 SuggestionStyle::ShowCode => false,
95 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
96 pub struct CodeSuggestion {
97 /// Each substitute can have multiple variants due to multiple
98 /// applicable suggestions
100 /// `foo.bar` might be replaced with `a.b` or `x.y` by replacing
101 /// `foo` and `bar` on their own:
105 /// Substitution { parts: vec![(0..3, "a"), (4..7, "b")] },
106 /// Substitution { parts: vec![(0..3, "x"), (4..7, "y")] },
110 /// or by replacing the entire span:
114 /// Substitution { parts: vec![(0..7, "a.b")] },
115 /// Substitution { parts: vec![(0..7, "x.y")] },
118 pub substitutions: Vec<Substitution>,
120 /// Visual representation of this suggestion.
121 pub style: SuggestionStyle,
122 /// Whether or not the suggestion is approximate
124 /// Sometimes we may show suggestions with placeholders,
125 /// which are useful for users but not useful for
126 /// tools like rustfix
127 pub applicability: Applicability,
130 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
131 /// See the docs on `CodeSuggestion::substitutions`
132 pub struct Substitution {
133 pub parts: Vec<SubstitutionPart>,
136 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
137 pub struct SubstitutionPart {
142 pub type SourceMapperDyn = dyn SourceMapper + sync::Send + sync::Sync;
144 pub trait SourceMapper {
145 fn lookup_char_pos(&self, pos: BytePos) -> Loc;
146 fn span_to_lines(&self, sp: Span) -> FileLinesResult;
147 fn span_to_string(&self, sp: Span) -> String;
148 fn span_to_filename(&self, sp: Span) -> FileName;
149 fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
150 fn call_span_if_macro(&self, sp: Span) -> Span;
151 fn ensure_source_file_source_present(&self, source_file: Lrc<SourceFile>) -> bool;
152 fn doctest_offset_line(&self, file: &FileName, line: usize) -> usize;
155 impl CodeSuggestion {
156 /// Returns the assembled code suggestions and whether they should be shown with an underline.
157 pub fn splice_lines(&self, cm: &SourceMapperDyn)
158 -> Vec<(String, Vec<SubstitutionPart>)> {
159 use syntax_pos::{CharPos, Loc, Pos};
161 fn push_trailing(buf: &mut String,
162 line_opt: Option<&Cow<'_, str>>,
164 hi_opt: Option<&Loc>) {
165 let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
166 if let Some(line) = line_opt {
167 if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
168 let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
170 Some(hi) if hi > lo => buf.push_str(&line[lo..hi]),
172 None => buf.push_str(&line[lo..]),
175 if let None = hi_opt {
181 assert!(!self.substitutions.is_empty());
183 self.substitutions.iter().cloned().map(|mut substitution| {
184 // Assumption: all spans are in the same file, and all spans
185 // are disjoint. Sort in ascending order.
186 substitution.parts.sort_by_key(|part| part.span.lo());
188 // Find the bounding span.
189 let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
190 let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
191 let bounding_span = Span::new(lo, hi, NO_EXPANSION);
192 let lines = cm.span_to_lines(bounding_span).unwrap();
193 assert!(!lines.lines.is_empty());
195 // To build up the result, we do this for each span:
196 // - push the line segment trailing the previous span
197 // (at the beginning a "phantom" span pointing at the start of the line)
198 // - push lines between the previous and current span (if any)
199 // - if the previous and current span are not on the same line
200 // push the line segment leading up to the current span
201 // - splice in the span substitution
203 // Finally push the trailing line segment of the last span
204 let fm = &lines.file;
205 let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
206 prev_hi.col = CharPos::from_usize(0);
208 let mut prev_line = fm.get_line(lines.lines[0].line_index);
209 let mut buf = String::new();
211 for part in &substitution.parts {
212 let cur_lo = cm.lookup_char_pos(part.span.lo());
213 if prev_hi.line == cur_lo.line {
214 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
216 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
217 // push lines between the previous and current span (if any)
218 for idx in prev_hi.line..(cur_lo.line - 1) {
219 if let Some(line) = fm.get_line(idx) {
220 buf.push_str(line.as_ref());
224 if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
225 buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
228 buf.push_str(&part.snippet);
229 prev_hi = cm.lookup_char_pos(part.span.hi());
230 prev_line = fm.get_line(prev_hi.line - 1);
232 // if the replacement already ends with a newline, don't print the next line
233 if !buf.ends_with('\n') {
234 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
236 // remove trailing newlines
237 while buf.ends_with('\n') {
240 (buf, substitution.parts)
245 /// Used as a return value to signify a fatal error occurred. (It is also
246 /// used as the argument to panic at the moment, but that will eventually
248 #[derive(Copy, Clone, Debug)]
250 pub struct FatalError;
252 pub struct FatalErrorMarker;
254 // Don't implement Send on FatalError. This makes it impossible to panic!(FatalError).
255 // We don't want to invoke the panic handler and print a backtrace for fatal errors.
256 impl !Send for FatalError {}
259 pub fn raise(self) -> ! {
260 panic::resume_unwind(Box::new(FatalErrorMarker))
264 impl fmt::Display for FatalError {
265 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
266 write!(f, "parser fatal error")
270 impl error::Error for FatalError {
271 fn description(&self) -> &str {
272 "The parser has encountered a fatal error"
276 /// Signifies that the compiler died with an explicit call to `.bug`
277 /// or `.span_bug` rather than a failed assertion, etc.
278 #[derive(Copy, Clone, Debug)]
279 pub struct ExplicitBug;
281 impl fmt::Display for ExplicitBug {
282 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
283 write!(f, "parser internal bug")
287 impl error::Error for ExplicitBug {
288 fn description(&self) -> &str {
289 "The parser has encountered an internal bug"
293 pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
294 pub use diagnostic_builder::DiagnosticBuilder;
296 /// A handler deals with errors; certain errors
297 /// (fatal, bug, unimpl) may cause immediate exit,
298 /// others log errors for later reporting.
300 pub flags: HandlerFlags,
302 err_count: AtomicUsize,
303 emitter: Lock<Box<dyn Emitter + sync::Send>>,
304 continue_after_error: AtomicBool,
305 delayed_span_bugs: Lock<Vec<Diagnostic>>,
307 // This set contains the `DiagnosticId` of all emitted diagnostics to avoid
308 // emitting the same diagnostic with extended help (`--teach`) twice, which
309 // would be uneccessary repetition.
310 taught_diagnostics: Lock<FxHashSet<DiagnosticId>>,
312 /// Used to suggest rustc --explain <error code>
313 emitted_diagnostic_codes: Lock<FxHashSet<DiagnosticId>>,
315 // This set contains a hash of every diagnostic that has been emitted by
316 // this handler. These hashes is used to avoid emitting the same error
318 emitted_diagnostics: Lock<FxHashSet<u128>>,
321 fn default_track_diagnostic(_: &Diagnostic) {}
323 thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> =
324 Cell::new(default_track_diagnostic));
327 pub struct HandlerFlags {
328 /// If false, warning-level lints are suppressed.
329 /// (rustc: see `--allow warnings` and `--cap-lints`)
330 pub can_emit_warnings: bool,
331 /// If true, error-level diagnostics are upgraded to bug-level.
332 /// (rustc: see `-Z treat-err-as-bug`)
333 pub treat_err_as_bug: Option<usize>,
334 /// If true, immediately emit diagnostics that would otherwise be buffered.
335 /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
336 pub dont_buffer_diagnostics: bool,
337 /// If true, immediately print bugs registered with `delay_span_bug`.
338 /// (rustc: see `-Z report-delayed-bugs`)
339 pub report_delayed_bugs: bool,
340 /// show macro backtraces even for non-local macros.
341 /// (rustc: see `-Z external-macro-backtrace`)
342 pub external_macro_backtrace: bool,
345 impl Drop for Handler {
347 if self.err_count() == 0 {
348 let mut bugs = self.delayed_span_bugs.borrow_mut();
349 let has_bugs = !bugs.is_empty();
350 for bug in bugs.drain(..) {
351 DiagnosticBuilder::new_diagnostic(self, bug).emit();
354 panic!("no errors encountered even though `delay_span_bug` issued");
361 pub fn with_tty_emitter(color_config: ColorConfig,
362 can_emit_warnings: bool,
363 treat_err_as_bug: Option<usize>,
364 cm: Option<Lrc<SourceMapperDyn>>)
366 Handler::with_tty_emitter_and_flags(
372 .. Default::default()
376 pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
377 cm: Option<Lrc<SourceMapperDyn>>,
380 let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
381 Handler::with_emitter_and_flags(emitter, flags)
384 pub fn with_emitter(can_emit_warnings: bool,
385 treat_err_as_bug: Option<usize>,
386 e: Box<dyn Emitter + sync::Send>)
388 Handler::with_emitter_and_flags(
393 .. Default::default()
397 pub fn with_emitter_and_flags(e: Box<dyn Emitter + sync::Send>, flags: HandlerFlags) -> Handler
401 err_count: AtomicUsize::new(0),
402 emitter: Lock::new(e),
403 continue_after_error: AtomicBool::new(true),
404 delayed_span_bugs: Lock::new(Vec::new()),
405 taught_diagnostics: Default::default(),
406 emitted_diagnostic_codes: Default::default(),
407 emitted_diagnostics: Default::default(),
411 pub fn set_continue_after_error(&self, continue_after_error: bool) {
412 self.continue_after_error.store(continue_after_error, SeqCst);
415 /// Resets the diagnostic error count as well as the cached emitted diagnostics.
417 /// NOTE: *do not* call this function from rustc. It is only meant to be called from external
418 /// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
419 /// the overall count of emitted error diagnostics.
420 pub fn reset_err_count(&self) {
421 // actually frees the underlying memory (which `clear` would not do)
422 *self.emitted_diagnostics.borrow_mut() = Default::default();
423 self.err_count.store(0, SeqCst);
426 pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
427 DiagnosticBuilder::new(self, Level::Cancelled, "")
430 pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
433 -> DiagnosticBuilder<'a> {
434 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
436 if !self.flags.can_emit_warnings {
441 pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
445 -> DiagnosticBuilder<'a> {
446 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
449 if !self.flags.can_emit_warnings {
454 pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
455 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
456 if !self.flags.can_emit_warnings {
461 pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
464 -> DiagnosticBuilder<'a> {
465 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
469 pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
473 -> DiagnosticBuilder<'a> {
474 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
479 // FIXME: This method should be removed (every error should have an associated error code).
480 pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
481 DiagnosticBuilder::new(self, Level::Error, msg)
483 pub fn struct_err_with_code<'a>(
487 ) -> DiagnosticBuilder<'a> {
488 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
492 pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
495 -> DiagnosticBuilder<'a> {
496 let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
500 pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
504 -> DiagnosticBuilder<'a> {
505 let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
510 pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
511 DiagnosticBuilder::new(self, Level::Fatal, msg)
514 pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) {
518 fn panic_if_treat_err_as_bug(&self) {
519 if self.treat_err_as_bug() {
520 let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
522 (1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(),
526 "aborting after {} errors due to `-Z treat-err-as-bug={}`",
536 pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
537 self.emit(&sp.into(), msg, Fatal);
540 pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
545 self.emit_with_code(&sp.into(), msg, code, Fatal);
548 pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
549 self.emit(&sp.into(), msg, Error);
551 pub fn mut_span_err<'a, S: Into<MultiSpan>>(&'a self,
554 -> DiagnosticBuilder<'a> {
555 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
559 pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
560 self.emit_with_code(&sp.into(), msg, code, Error);
562 pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
563 self.emit(&sp.into(), msg, Warning);
565 pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
566 self.emit_with_code(&sp.into(), msg, code, Warning);
568 pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
569 self.emit(&sp.into(), msg, Bug);
572 pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
573 if self.treat_err_as_bug() {
574 // FIXME: don't abort here if report_delayed_bugs is off
575 self.span_bug(sp, msg);
577 let mut diagnostic = Diagnostic::new(Level::Bug, msg);
578 diagnostic.set_span(sp.into());
579 self.delay_as_bug(diagnostic);
581 fn delay_as_bug(&self, diagnostic: Diagnostic) {
582 if self.flags.report_delayed_bugs {
583 DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit();
585 self.delayed_span_bugs.borrow_mut().push(diagnostic);
587 pub fn span_bug_no_panic<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
588 self.emit(&sp.into(), msg, Bug);
590 pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
591 self.emit(&sp.into(), msg, Note);
593 pub fn span_note_diag<'a>(&'a self,
596 -> DiagnosticBuilder<'a> {
597 let mut db = DiagnosticBuilder::new(self, Note, msg);
601 pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
602 self.span_bug(sp, &format!("unimplemented {}", msg));
604 pub fn failure(&self, msg: &str) {
605 DiagnosticBuilder::new(self, FailureNote, msg).emit()
607 pub fn fatal(&self, msg: &str) -> FatalError {
608 if self.treat_err_as_bug() {
611 DiagnosticBuilder::new(self, Fatal, msg).emit();
614 pub fn err(&self, msg: &str) {
615 if self.treat_err_as_bug() {
618 let mut db = DiagnosticBuilder::new(self, Error, msg);
621 pub fn warn(&self, msg: &str) {
622 let mut db = DiagnosticBuilder::new(self, Warning, msg);
625 fn treat_err_as_bug(&self) -> bool {
626 self.flags.treat_err_as_bug.map(|c| self.err_count() >= c).unwrap_or(false)
628 pub fn note_without_error(&self, msg: &str) {
629 let mut db = DiagnosticBuilder::new(self, Note, msg);
632 pub fn bug(&self, msg: &str) -> ! {
633 let mut db = DiagnosticBuilder::new(self, Bug, msg);
637 pub fn unimpl(&self, msg: &str) -> ! {
638 self.bug(&format!("unimplemented {}", msg));
641 fn bump_err_count(&self) {
642 self.err_count.fetch_add(1, SeqCst);
643 self.panic_if_treat_err_as_bug();
646 pub fn err_count(&self) -> usize {
647 self.err_count.load(SeqCst)
650 pub fn has_errors(&self) -> bool {
654 pub fn print_error_count(&self) {
655 let s = match self.err_count() {
657 1 => "aborting due to previous error".to_string(),
658 _ => format!("aborting due to {} previous errors", self.err_count())
660 let err_as_bug = self.flags.treat_err_as_bug.unwrap_or(0);
661 if self.err_count() >= err_as_bug {
665 let _ = self.fatal(&s);
667 let can_show_explain = self.emitter.borrow().should_show_explain();
668 let are_there_diagnostics = !self.emitted_diagnostic_codes.borrow().is_empty();
669 if can_show_explain && are_there_diagnostics {
670 let mut error_codes =
671 self.emitted_diagnostic_codes.borrow()
673 .filter_map(|x| match *x {
674 DiagnosticId::Error(ref s) => Some(s.clone()),
677 .collect::<Vec<_>>();
678 if !error_codes.is_empty() {
680 if error_codes.len() > 1 {
681 let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
682 self.failure(&format!("Some errors occurred: {}{}",
683 error_codes[..limit].join(", "),
684 if error_codes.len() > 9 { "..." } else { "." }));
685 self.failure(&format!("For more information about an error, try \
686 `rustc --explain {}`.",
689 self.failure(&format!("For more information about this error, try \
690 `rustc --explain {}`.",
697 pub fn abort_if_errors(&self) {
698 if self.err_count() == 0 {
703 pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
704 if lvl == Warning && !self.flags.can_emit_warnings {
707 let mut db = DiagnosticBuilder::new(self, lvl, msg);
708 db.set_span(msp.clone());
710 if !self.continue_after_error.load(SeqCst) {
711 self.abort_if_errors();
714 pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) {
715 if lvl == Warning && !self.flags.can_emit_warnings {
718 let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg);
719 db.set_span(msp.clone());
721 if !self.continue_after_error.load(SeqCst) {
722 self.abort_if_errors();
726 /// `true` if we haven't taught a diagnostic with this code already.
727 /// The caller must then teach the user about such a diagnostic.
729 /// Used to suppress emitting the same error multiple times with extended explanation when
730 /// calling `-Zteach`.
731 pub fn must_teach(&self, code: &DiagnosticId) -> bool {
732 self.taught_diagnostics.borrow_mut().insert(code.clone())
735 pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
736 self.emitter.borrow_mut().emit(&db);
740 fn emit_db(&self, db: &DiagnosticBuilder<'_>) {
741 let diagnostic = &**db;
743 TRACK_DIAGNOSTICS.with(|track_diagnostics| {
744 track_diagnostics.get()(diagnostic);
747 if let Some(ref code) = diagnostic.code {
748 self.emitted_diagnostic_codes.borrow_mut().insert(code.clone());
751 let diagnostic_hash = {
753 let mut hasher = StableHasher::new();
754 diagnostic.hash(&mut hasher);
758 // Only emit the diagnostic if we haven't already emitted an equivalent
760 if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
761 self.emitter.borrow_mut().emit(db);
763 self.bump_err_count();
770 #[derive(Copy, PartialEq, Clone, Hash, Debug, RustcEncodable, RustcDecodable)]
774 // An error which while not immediately fatal, should stop the compiler
775 // progressing beyond the current phase.
785 impl fmt::Display for Level {
786 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
792 fn color(self) -> ColorSpec {
793 let mut spec = ColorSpec::new();
795 Bug | Fatal | PhaseFatal | Error => {
796 spec.set_fg(Some(Color::Red))
800 spec.set_fg(Some(Color::Yellow))
801 .set_intense(cfg!(windows));
804 spec.set_fg(Some(Color::Green))
808 spec.set_fg(Some(Color::Cyan))
812 Cancelled => unreachable!(),
817 pub fn to_str(self) -> &'static str {
819 Bug => "error: internal compiler error",
820 Fatal | PhaseFatal | Error => "error",
821 Warning => "warning",
825 Cancelled => panic!("Shouldn't call on cancelled error"),
829 pub fn is_failure_note(&self) -> bool {