1 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3 #![feature(custom_attribute)]
4 #![allow(unused_attributes)]
5 #![cfg_attr(unix, feature(libc))]
7 #![feature(optin_builtin_traits)]
8 #![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};
19 use registry::Registry;
21 use rustc_data_structures::sync::{self, Lrc, Lock, AtomicUsize, AtomicBool, SeqCst};
22 use rustc_data_structures::fx::FxHashSet;
23 use rustc_data_structures::stable_hasher::StableHasher;
27 use std::{error, fmt};
31 use termcolor::{ColorSpec, Color};
34 mod diagnostic_builder;
41 use syntax_pos::{BytePos,
50 /// Indicates the confidence in the correctness of a suggestion.
52 /// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion
53 /// to determine whether it should be automatically applied or if the user should be consulted
54 /// before applying the suggestion.
55 #[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
56 pub enum Applicability {
57 /// The suggestion is definitely what the user intended. This suggestion should be
58 /// automatically applied.
61 /// The suggestion may be what the user intended, but it is uncertain. The suggestion should
62 /// result in valid Rust code if it is applied.
65 /// The suggestion contains placeholders like `(...)` or `{ /* fields */ }`. The suggestion
66 /// cannot be applied automatically because it will not result in valid Rust code. The user
67 /// will need to fill in the placeholders.
70 /// The applicability of the suggestion is unknown.
74 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, RustcEncodable, RustcDecodable)]
75 pub enum SuggestionStyle {
76 /// Hide the suggested code when displaying this suggestion inline.
78 /// Always hide the suggested code but display the message.
80 /// Do not display this suggestion in the cli output, it is only meant for tools.
82 /// Always show the suggested code.
83 /// This will *not* show the code if the suggestion is inline *and* the suggested code is
88 impl SuggestionStyle {
89 fn hide_inline(&self) -> bool {
91 SuggestionStyle::ShowCode => false,
97 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
98 pub struct CodeSuggestion {
99 /// Each substitute can have multiple variants due to multiple
100 /// applicable suggestions
102 /// `foo.bar` might be replaced with `a.b` or `x.y` by replacing
103 /// `foo` and `bar` on their own:
107 /// Substitution { parts: vec![(0..3, "a"), (4..7, "b")] },
108 /// Substitution { parts: vec![(0..3, "x"), (4..7, "y")] },
112 /// or by replacing the entire span:
116 /// Substitution { parts: vec![(0..7, "a.b")] },
117 /// Substitution { parts: vec![(0..7, "x.y")] },
120 pub substitutions: Vec<Substitution>,
122 /// Visual representation of this suggestion.
123 pub style: SuggestionStyle,
124 /// Whether or not the suggestion is approximate
126 /// Sometimes we may show suggestions with placeholders,
127 /// which are useful for users but not useful for
128 /// tools like rustfix
129 pub applicability: Applicability,
132 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
133 /// See the docs on `CodeSuggestion::substitutions`
134 pub struct Substitution {
135 pub parts: Vec<SubstitutionPart>,
138 #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
139 pub struct SubstitutionPart {
144 pub type SourceMapperDyn = dyn SourceMapper + sync::Send + sync::Sync;
146 pub trait SourceMapper {
147 fn lookup_char_pos(&self, pos: BytePos) -> Loc;
148 fn span_to_lines(&self, sp: Span) -> FileLinesResult;
149 fn span_to_string(&self, sp: Span) -> String;
150 fn span_to_filename(&self, sp: Span) -> FileName;
151 fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
152 fn call_span_if_macro(&self, sp: Span) -> Span;
153 fn ensure_source_file_source_present(&self, source_file: Lrc<SourceFile>) -> bool;
154 fn doctest_offset_line(&self, file: &FileName, line: usize) -> usize;
157 impl CodeSuggestion {
158 /// Returns the assembled code suggestions and whether they should be shown with an underline.
159 pub fn splice_lines(&self, cm: &SourceMapperDyn)
160 -> Vec<(String, Vec<SubstitutionPart>)> {
161 use syntax_pos::{CharPos, Pos};
163 fn push_trailing(buf: &mut String,
164 line_opt: Option<&Cow<'_, str>>,
166 hi_opt: Option<&Loc>) {
167 let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
168 if let Some(line) = line_opt {
169 if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
170 let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
172 Some(hi) if hi > lo => buf.push_str(&line[lo..hi]),
174 None => buf.push_str(&line[lo..]),
177 if let None = hi_opt {
183 assert!(!self.substitutions.is_empty());
185 self.substitutions.iter().cloned().map(|mut substitution| {
186 // Assumption: all spans are in the same file, and all spans
187 // are disjoint. Sort in ascending order.
188 substitution.parts.sort_by_key(|part| part.span.lo());
190 // Find the bounding span.
191 let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
192 let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
193 let bounding_span = Span::new(lo, hi, NO_EXPANSION);
194 let lines = cm.span_to_lines(bounding_span).unwrap();
195 assert!(!lines.lines.is_empty());
197 // To build up the result, we do this for each span:
198 // - push the line segment trailing the previous span
199 // (at the beginning a "phantom" span pointing at the start of the line)
200 // - push lines between the previous and current span (if any)
201 // - if the previous and current span are not on the same line
202 // push the line segment leading up to the current span
203 // - splice in the span substitution
205 // Finally push the trailing line segment of the last span
206 let fm = &lines.file;
207 let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
208 prev_hi.col = CharPos::from_usize(0);
210 let mut prev_line = fm.get_line(lines.lines[0].line_index);
211 let mut buf = String::new();
213 for part in &substitution.parts {
214 let cur_lo = cm.lookup_char_pos(part.span.lo());
215 if prev_hi.line == cur_lo.line {
216 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
218 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
219 // push lines between the previous and current span (if any)
220 for idx in prev_hi.line..(cur_lo.line - 1) {
221 if let Some(line) = fm.get_line(idx) {
222 buf.push_str(line.as_ref());
226 if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
227 buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
230 buf.push_str(&part.snippet);
231 prev_hi = cm.lookup_char_pos(part.span.hi());
232 prev_line = fm.get_line(prev_hi.line - 1);
234 // if the replacement already ends with a newline, don't print the next line
235 if !buf.ends_with('\n') {
236 push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
238 // remove trailing newlines
239 while buf.ends_with('\n') {
242 (buf, substitution.parts)
247 /// Used as a return value to signify a fatal error occurred. (It is also
248 /// used as the argument to panic at the moment, but that will eventually
250 #[derive(Copy, Clone, Debug)]
252 pub struct FatalError;
254 pub struct FatalErrorMarker;
256 // Don't implement Send on FatalError. This makes it impossible to panic!(FatalError).
257 // We don't want to invoke the panic handler and print a backtrace for fatal errors.
258 impl !Send for FatalError {}
261 pub fn raise(self) -> ! {
262 panic::resume_unwind(Box::new(FatalErrorMarker))
266 impl fmt::Display for FatalError {
267 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
268 write!(f, "parser fatal error")
272 impl error::Error for FatalError {
273 fn description(&self) -> &str {
274 "The parser has encountered a fatal error"
278 /// Signifies that the compiler died with an explicit call to `.bug`
279 /// or `.span_bug` rather than a failed assertion, etc.
280 #[derive(Copy, Clone, Debug)]
281 pub struct ExplicitBug;
283 impl fmt::Display for ExplicitBug {
284 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
285 write!(f, "parser internal bug")
289 impl error::Error for ExplicitBug {
290 fn description(&self) -> &str {
291 "The parser has encountered an internal bug"
295 pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
296 pub use diagnostic_builder::DiagnosticBuilder;
298 /// A handler deals with errors and other compiler output.
299 /// Certain errors (fatal, bug, unimpl) may cause immediate exit,
300 /// others log errors for later reporting.
302 pub flags: HandlerFlags,
304 err_count: AtomicUsize,
305 emitter: Lock<Box<dyn Emitter + sync::Send>>,
306 continue_after_error: AtomicBool,
307 delayed_span_bugs: Lock<Vec<Diagnostic>>,
309 /// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
310 /// emitting the same diagnostic with extended help (`--teach`) twice, which
311 /// would be uneccessary repetition.
312 taught_diagnostics: Lock<FxHashSet<DiagnosticId>>,
314 /// Used to suggest rustc --explain <error code>
315 emitted_diagnostic_codes: Lock<FxHashSet<DiagnosticId>>,
317 /// This set contains a hash of every diagnostic that has been emitted by
318 /// this handler. These hashes is used to avoid emitting the same error
320 emitted_diagnostics: Lock<FxHashSet<u128>>,
323 fn default_track_diagnostic(_: &Diagnostic) {}
325 thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> =
326 Cell::new(default_track_diagnostic));
329 pub struct HandlerFlags {
330 /// If false, warning-level lints are suppressed.
331 /// (rustc: see `--allow warnings` and `--cap-lints`)
332 pub can_emit_warnings: bool,
333 /// If true, error-level diagnostics are upgraded to bug-level.
334 /// (rustc: see `-Z treat-err-as-bug`)
335 pub treat_err_as_bug: Option<usize>,
336 /// If true, immediately emit diagnostics that would otherwise be buffered.
337 /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
338 pub dont_buffer_diagnostics: bool,
339 /// If true, immediately print bugs registered with `delay_span_bug`.
340 /// (rustc: see `-Z report-delayed-bugs`)
341 pub report_delayed_bugs: bool,
342 /// show macro backtraces even for non-local macros.
343 /// (rustc: see `-Z external-macro-backtrace`)
344 pub external_macro_backtrace: bool,
347 impl Drop for Handler {
349 if self.err_count() == 0 {
350 let mut bugs = self.delayed_span_bugs.borrow_mut();
351 let has_bugs = !bugs.is_empty();
352 for bug in bugs.drain(..) {
353 DiagnosticBuilder::new_diagnostic(self, bug).emit();
356 panic!("no errors encountered even though `delay_span_bug` issued");
363 pub fn with_tty_emitter(color_config: ColorConfig,
364 can_emit_warnings: bool,
365 treat_err_as_bug: Option<usize>,
366 cm: Option<Lrc<SourceMapperDyn>>)
368 Handler::with_tty_emitter_and_flags(
374 .. Default::default()
378 pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
379 cm: Option<Lrc<SourceMapperDyn>>,
382 let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
383 Handler::with_emitter_and_flags(emitter, flags)
386 pub fn with_emitter(can_emit_warnings: bool,
387 treat_err_as_bug: Option<usize>,
388 e: Box<dyn Emitter + sync::Send>)
390 Handler::with_emitter_and_flags(
395 .. Default::default()
399 pub fn with_emitter_and_flags(e: Box<dyn Emitter + sync::Send>, flags: HandlerFlags) -> Handler
403 err_count: AtomicUsize::new(0),
404 emitter: Lock::new(e),
405 continue_after_error: AtomicBool::new(true),
406 delayed_span_bugs: Lock::new(Vec::new()),
407 taught_diagnostics: Default::default(),
408 emitted_diagnostic_codes: Default::default(),
409 emitted_diagnostics: Default::default(),
413 pub fn set_continue_after_error(&self, continue_after_error: bool) {
414 self.continue_after_error.store(continue_after_error, SeqCst);
417 /// Resets the diagnostic error count as well as the cached emitted diagnostics.
419 /// NOTE: *do not* call this function from rustc. It is only meant to be called from external
420 /// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
421 /// the overall count of emitted error diagnostics.
422 pub fn reset_err_count(&self) {
423 // actually frees the underlying memory (which `clear` would not do)
424 *self.emitted_diagnostics.borrow_mut() = Default::default();
425 self.err_count.store(0, SeqCst);
428 pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
429 DiagnosticBuilder::new(self, Level::Cancelled, "")
432 pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
435 -> DiagnosticBuilder<'a> {
436 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
438 if !self.flags.can_emit_warnings {
443 pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
447 -> DiagnosticBuilder<'a> {
448 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
451 if !self.flags.can_emit_warnings {
456 pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
457 let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
458 if !self.flags.can_emit_warnings {
463 pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
466 -> DiagnosticBuilder<'a> {
467 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
471 pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
475 -> DiagnosticBuilder<'a> {
476 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
481 // FIXME: This method should be removed (every error should have an associated error code).
482 pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
483 DiagnosticBuilder::new(self, Level::Error, msg)
485 pub fn struct_err_with_code<'a>(
489 ) -> DiagnosticBuilder<'a> {
490 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
494 pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
497 -> DiagnosticBuilder<'a> {
498 let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
502 pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
506 -> DiagnosticBuilder<'a> {
507 let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
512 pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
513 DiagnosticBuilder::new(self, Level::Fatal, msg)
516 pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) {
520 fn panic_if_treat_err_as_bug(&self) {
521 if self.treat_err_as_bug() {
522 let s = match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
524 (1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(),
528 "aborting after {} errors due to `-Z treat-err-as-bug={}`",
538 pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
539 self.emit(&sp.into(), msg, Fatal);
542 pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
547 self.emit_with_code(&sp.into(), msg, code, Fatal);
550 pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
551 self.emit(&sp.into(), msg, Error);
553 pub fn mut_span_err<'a, S: Into<MultiSpan>>(&'a self,
556 -> DiagnosticBuilder<'a> {
557 let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
561 pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
562 self.emit_with_code(&sp.into(), msg, code, Error);
564 pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
565 self.emit(&sp.into(), msg, Warning);
567 pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
568 self.emit_with_code(&sp.into(), msg, code, Warning);
570 pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
571 self.emit(&sp.into(), msg, Bug);
574 pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
575 if self.treat_err_as_bug() {
576 // FIXME: don't abort here if report_delayed_bugs is off
577 self.span_bug(sp, msg);
579 let mut diagnostic = Diagnostic::new(Level::Bug, msg);
580 diagnostic.set_span(sp.into());
581 self.delay_as_bug(diagnostic);
583 fn delay_as_bug(&self, diagnostic: Diagnostic) {
584 if self.flags.report_delayed_bugs {
585 DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit();
587 self.delayed_span_bugs.borrow_mut().push(diagnostic);
589 pub fn span_bug_no_panic<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
590 self.emit(&sp.into(), msg, Bug);
592 pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
593 self.emit(&sp.into(), msg, Note);
595 pub fn span_note_diag<'a>(&'a self,
598 -> DiagnosticBuilder<'a> {
599 let mut db = DiagnosticBuilder::new(self, Note, msg);
603 pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
604 self.span_bug(sp, &format!("unimplemented {}", msg));
606 pub fn failure(&self, msg: &str) {
607 DiagnosticBuilder::new(self, FailureNote, msg).emit()
609 pub fn fatal(&self, msg: &str) -> FatalError {
610 if self.treat_err_as_bug() {
613 DiagnosticBuilder::new(self, Fatal, msg).emit();
616 pub fn err(&self, msg: &str) {
617 if self.treat_err_as_bug() {
620 let mut db = DiagnosticBuilder::new(self, Error, msg);
623 pub fn warn(&self, msg: &str) {
624 let mut db = DiagnosticBuilder::new(self, Warning, msg);
627 fn treat_err_as_bug(&self) -> bool {
628 self.flags.treat_err_as_bug.map(|c| self.err_count() >= c).unwrap_or(false)
630 pub fn note_without_error(&self, msg: &str) {
631 let mut db = DiagnosticBuilder::new(self, Note, msg);
634 pub fn bug(&self, msg: &str) -> ! {
635 let mut db = DiagnosticBuilder::new(self, Bug, msg);
639 pub fn unimpl(&self, msg: &str) -> ! {
640 self.bug(&format!("unimplemented {}", msg));
643 fn bump_err_count(&self) {
644 self.err_count.fetch_add(1, SeqCst);
645 self.panic_if_treat_err_as_bug();
648 pub fn err_count(&self) -> usize {
649 self.err_count.load(SeqCst)
652 pub fn has_errors(&self) -> bool {
656 pub fn print_error_count(&self, registry: &Registry) {
657 let s = match self.err_count() {
659 1 => "aborting due to previous error".to_string(),
660 _ => format!("aborting due to {} previous errors", self.err_count())
662 if self.treat_err_as_bug() {
666 let _ = self.fatal(&s);
668 let can_show_explain = self.emitter.borrow().should_show_explain();
669 let are_there_diagnostics = !self.emitted_diagnostic_codes.borrow().is_empty();
670 if can_show_explain && are_there_diagnostics {
671 let mut error_codes = self
672 .emitted_diagnostic_codes
675 .filter_map(|x| match &x {
676 DiagnosticId::Error(s) if registry.find_description(s).is_some() => {
681 .collect::<Vec<_>>();
682 if !error_codes.is_empty() {
684 if error_codes.len() > 1 {
685 let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
686 self.failure(&format!("Some errors have detailed explanations: {}{}",
687 error_codes[..limit].join(", "),
688 if error_codes.len() > 9 { "..." } else { "." }));
689 self.failure(&format!("For more information about an error, try \
690 `rustc --explain {}`.",
693 self.failure(&format!("For more information about this error, try \
694 `rustc --explain {}`.",
701 pub fn abort_if_errors(&self) {
702 if self.err_count() == 0 {
707 pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
708 if lvl == Warning && !self.flags.can_emit_warnings {
711 let mut db = DiagnosticBuilder::new(self, lvl, msg);
712 db.set_span(msp.clone());
714 if !self.continue_after_error.load(SeqCst) {
715 self.abort_if_errors();
718 pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) {
719 if lvl == Warning && !self.flags.can_emit_warnings {
722 let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg);
723 db.set_span(msp.clone());
725 if !self.continue_after_error.load(SeqCst) {
726 self.abort_if_errors();
730 /// `true` if we haven't taught a diagnostic with this code already.
731 /// The caller must then teach the user about such a diagnostic.
733 /// Used to suppress emitting the same error multiple times with extended explanation when
734 /// calling `-Zteach`.
735 pub fn must_teach(&self, code: &DiagnosticId) -> bool {
736 self.taught_diagnostics.borrow_mut().insert(code.clone())
739 pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
740 self.emitter.borrow_mut().emit_diagnostic(&db);
744 fn emit_db(&self, db: &DiagnosticBuilder<'_>) {
745 let diagnostic = &**db;
747 TRACK_DIAGNOSTICS.with(|track_diagnostics| {
748 track_diagnostics.get()(diagnostic);
751 if let Some(ref code) = diagnostic.code {
752 self.emitted_diagnostic_codes.borrow_mut().insert(code.clone());
755 let diagnostic_hash = {
757 let mut hasher = StableHasher::new();
758 diagnostic.hash(&mut hasher);
762 // Only emit the diagnostic if we haven't already emitted an equivalent
764 if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) {
765 self.emitter.borrow_mut().emit_diagnostic(db);
767 self.bump_err_count();
772 pub fn emit_artifact_notification(&self, path: &Path) {
773 self.emitter.borrow_mut().emit_artifact_notification(path);
777 #[derive(Copy, PartialEq, Clone, Hash, Debug, RustcEncodable, RustcDecodable)]
781 // An error which while not immediately fatal, should stop the compiler
782 // progressing beyond the current phase.
792 impl fmt::Display for Level {
793 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
799 fn color(self) -> ColorSpec {
800 let mut spec = ColorSpec::new();
802 Bug | Fatal | PhaseFatal | Error => {
803 spec.set_fg(Some(Color::Red))
807 spec.set_fg(Some(Color::Yellow))
808 .set_intense(cfg!(windows));
811 spec.set_fg(Some(Color::Green))
815 spec.set_fg(Some(Color::Cyan))
819 Cancelled => unreachable!(),
824 pub fn to_str(self) -> &'static str {
826 Bug => "error: internal compiler error",
827 Fatal | PhaseFatal | Error => "error",
828 Warning => "warning",
832 Cancelled => panic!("Shouldn't call on cancelled error"),
836 pub fn is_failure_note(&self) -> bool {