summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:04 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:47 -0500
commita06baa56b95674fc626b3c3fd680d6a65357fe60 (patch)
treecd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/librustc_errors
parent8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff)
downloadrust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz
rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip
Format the world
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/annotate_snippet_emitter_writer.rs126
-rw-r--r--src/librustc_errors/diagnostic.rs154
-rw-r--r--src/librustc_errors/diagnostic_builder.rs89
-rw-r--r--src/librustc_errors/json.rs221
-rw-r--r--src/librustc_errors/json/tests.rs4
-rw-r--r--src/librustc_errors/lib.rs222
-rw-r--r--src/librustc_errors/lock.rs27
-rw-r--r--src/librustc_errors/snippet.rs30
-rw-r--r--src/librustc_errors/styled_buffer.rs29
9 files changed, 413 insertions, 489 deletions
diff --git a/src/librustc_errors/annotate_snippet_emitter_writer.rs b/src/librustc_errors/annotate_snippet_emitter_writer.rs
index 4c5d0178b2c..e63e124fbc5 100644
--- a/src/librustc_errors/annotate_snippet_emitter_writer.rs
+++ b/src/librustc_errors/annotate_snippet_emitter_writer.rs
@@ -5,19 +5,15 @@
 //!
 //! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
 
-use syntax_pos::{SourceFile, MultiSpan, Loc};
-use syntax_pos::source_map::SourceMap;
-use crate::{
-    Level, CodeSuggestion, Diagnostic, Emitter,
-    SubDiagnostic, DiagnosticId
-};
 use crate::emitter::FileWithAnnotatedLines;
-use rustc_data_structures::sync::Lrc;
 use crate::snippet::Line;
-use annotate_snippets::snippet::*;
+use crate::{CodeSuggestion, Diagnostic, DiagnosticId, Emitter, Level, SubDiagnostic};
 use annotate_snippets::display_list::DisplayList;
 use annotate_snippets::formatter::DisplayListFormatter;
-
+use annotate_snippets::snippet::*;
+use rustc_data_structures::sync::Lrc;
+use syntax_pos::source_map::SourceMap;
+use syntax_pos::{Loc, MultiSpan, SourceFile};
 
 /// Generates diagnostics using annotate-snippet
 pub struct AnnotateSnippetEmitterWriter {
@@ -36,18 +32,22 @@ impl Emitter for AnnotateSnippetEmitterWriter {
         let mut children = diag.children.clone();
         let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
 
-        self.fix_multispans_in_std_macros(&self.source_map,
-                                          &mut primary_span,
-                                          &mut children,
-                                          &diag.level,
-                                          self.external_macro_backtrace);
-
-        self.emit_messages_default(&diag.level,
-                                   diag.message(),
-                                   &diag.code,
-                                   &primary_span,
-                                   &children,
-                                   &suggestions);
+        self.fix_multispans_in_std_macros(
+            &self.source_map,
+            &mut primary_span,
+            &mut children,
+            &diag.level,
+            self.external_macro_backtrace,
+        );
+
+        self.emit_messages_default(
+            &diag.level,
+            diag.message(),
+            &diag.code,
+            &primary_span,
+            &children,
+            &suggestions,
+        );
     }
 
     fn source_map(&self) -> Option<&Lrc<SourceMap>> {
@@ -70,35 +70,30 @@ struct DiagnosticConverter<'a> {
     #[allow(dead_code)]
     children: &'a [SubDiagnostic],
     #[allow(dead_code)]
-    suggestions: &'a [CodeSuggestion]
+    suggestions: &'a [CodeSuggestion],
 }
 
-impl<'a>  DiagnosticConverter<'a> {
+impl<'a> DiagnosticConverter<'a> {
     /// Turns rustc Diagnostic information into a `annotate_snippets::snippet::Snippet`.
     fn to_annotation_snippet(&self) -> Option<Snippet> {
         if let Some(source_map) = &self.source_map {
             // Make sure our primary file comes first
-            let primary_lo = if let Some(ref primary_span) =
-                self.msp.primary_span().as_ref() {
+            let primary_lo = if let Some(ref primary_span) = self.msp.primary_span().as_ref() {
                 source_map.lookup_char_pos(primary_span.lo())
             } else {
                 // FIXME(#59346): Not sure when this is the case and what
                 // should be done if it happens
-                return None
+                return None;
             };
-            let annotated_files = FileWithAnnotatedLines::collect_annotations(
-                &self.msp,
-                &self.source_map
-            );
+            let annotated_files =
+                FileWithAnnotatedLines::collect_annotations(&self.msp, &self.source_map);
             let slices = self.slices_for_files(annotated_files, primary_lo);
 
             Some(Snippet {
                 title: Some(Annotation {
                     label: Some(self.message.to_string()),
-                    id: self.code.clone().map(|c| {
-                        match c {
-                            DiagnosticId::Error(val) | DiagnosticId::Lint(val) => val
-                        }
+                    id: self.code.clone().map(|c| match c {
+                        DiagnosticId::Error(val) | DiagnosticId::Lint(val) => val,
                     }),
                     annotation_type: Self::annotation_type_for_level(self.level),
                 }),
@@ -114,43 +109,49 @@ impl<'a>  DiagnosticConverter<'a> {
     fn slices_for_files(
         &self,
         annotated_files: Vec<FileWithAnnotatedLines>,
-        primary_lo: Loc
+        primary_lo: Loc,
     ) -> Vec<Slice> {
         // FIXME(#64205): Provide a test case where `annotated_files` is > 1
-        annotated_files.iter().flat_map(|annotated_file| {
-            annotated_file.lines.iter().map(|line| {
-                let line_source = Self::source_string(annotated_file.file.clone(), &line);
-                Slice {
-                    source: line_source,
-                    line_start: line.line_index,
-                    origin: Some(primary_lo.file.name.to_string()),
-                    // FIXME(#59346): Not really sure when `fold` should be true or false
-                    fold: false,
-                    annotations: line.annotations.iter().map(|a| {
-                        self.annotation_to_source_annotation(a.clone())
-                    }).collect(),
-                }
-            }).collect::<Vec<Slice>>()
-        }).collect::<Vec<Slice>>()
+        annotated_files
+            .iter()
+            .flat_map(|annotated_file| {
+                annotated_file
+                    .lines
+                    .iter()
+                    .map(|line| {
+                        let line_source = Self::source_string(annotated_file.file.clone(), &line);
+                        Slice {
+                            source: line_source,
+                            line_start: line.line_index,
+                            origin: Some(primary_lo.file.name.to_string()),
+                            // FIXME(#59346): Not really sure when `fold` should be true or false
+                            fold: false,
+                            annotations: line
+                                .annotations
+                                .iter()
+                                .map(|a| self.annotation_to_source_annotation(a.clone()))
+                                .collect(),
+                        }
+                    })
+                    .collect::<Vec<Slice>>()
+            })
+            .collect::<Vec<Slice>>()
     }
 
     /// Turns a `crate::snippet::Annotation` into a `SourceAnnotation`
     fn annotation_to_source_annotation(
         &self,
-        annotation: crate::snippet::Annotation
+        annotation: crate::snippet::Annotation,
     ) -> SourceAnnotation {
         SourceAnnotation {
             range: (annotation.start_col, annotation.end_col),
             label: annotation.label.unwrap_or("".to_string()),
-            annotation_type: Self::annotation_type_for_level(self.level)
+            annotation_type: Self::annotation_type_for_level(self.level),
         }
     }
 
     /// Provides the source string for the given `line` of `file`
-    fn source_string(
-        file: Lrc<SourceFile>,
-        line: &Line
-    ) -> String {
+    fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
         file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or(String::new())
     }
 
@@ -162,7 +163,7 @@ impl<'a>  DiagnosticConverter<'a> {
             Level::Note => AnnotationType::Note,
             Level::Help => AnnotationType::Help,
             // FIXME(#59346): Not sure how to map these two levels
-            Level::Cancelled | Level::FailureNote => AnnotationType::Error
+            Level::Cancelled | Level::FailureNote => AnnotationType::Error,
         }
     }
 }
@@ -173,12 +174,7 @@ impl AnnotateSnippetEmitterWriter {
         short_message: bool,
         external_macro_backtrace: bool,
     ) -> Self {
-        Self {
-            source_map,
-            short_message,
-            ui_testing: false,
-            external_macro_backtrace,
-        }
+        Self { source_map, short_message, ui_testing: false, external_macro_backtrace }
     }
 
     /// Allows to modify `Self` to enable or disable the `ui_testing` flag.
@@ -196,7 +192,7 @@ impl AnnotateSnippetEmitterWriter {
         code: &Option<DiagnosticId>,
         msp: &MultiSpan,
         children: &[SubDiagnostic],
-        suggestions: &[CodeSuggestion]
+        suggestions: &[CodeSuggestion],
     ) {
         let converter = DiagnosticConverter {
             source_map: self.source_map.clone(),
@@ -205,7 +201,7 @@ impl AnnotateSnippetEmitterWriter {
             code: code.clone(),
             msp: msp.clone(),
             children,
-            suggestions
+            suggestions,
         };
         if let Some(snippet) = converter.to_annotation_snippet() {
             let dl = DisplayList::from(snippet);
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index 744f4a47b60..6112269ef7f 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -1,10 +1,10 @@
-use crate::CodeSuggestion;
-use crate::SuggestionStyle;
-use crate::SubstitutionPart;
-use crate::Substitution;
+use crate::snippet::Style;
 use crate::Applicability;
+use crate::CodeSuggestion;
 use crate::Level;
-use crate::snippet::Style;
+use crate::Substitution;
+use crate::SubstitutionPart;
+use crate::SuggestionStyle;
 use std::fmt;
 use syntax_pos::{MultiSpan, Span, DUMMY_SP};
 
@@ -81,7 +81,7 @@ pub enum StringPart {
 impl StringPart {
     pub fn content(&self) -> &str {
         match self {
-            &StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s
+            &StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
         }
     }
 }
@@ -105,19 +105,9 @@ impl Diagnostic {
 
     pub fn is_error(&self) -> bool {
         match self.level {
-            Level::Bug |
-            Level::Fatal |
-            Level::Error |
-            Level::FailureNote => {
-                true
-            }
+            Level::Bug | Level::Fatal | Level::Error | Level::FailureNote => true,
 
-            Level::Warning |
-            Level::Note |
-            Level::Help |
-            Level::Cancelled => {
-                false
-            }
+            Level::Warning | Level::Note | Level::Help | Level::Cancelled => false,
         }
     }
 
@@ -177,19 +167,16 @@ impl Diagnostic {
         found: DiagnosticStyledString,
     ) -> &mut Self {
         let mut msg: Vec<_> =
-            vec![(format!("required when trying to coerce from type `"),
-                  Style::NoStyle)];
-        msg.extend(expected.0.iter()
-                   .map(|x| match *x {
-                       StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-                       StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
-                   }));
+            vec![(format!("required when trying to coerce from type `"), Style::NoStyle)];
+        msg.extend(expected.0.iter().map(|x| match *x {
+            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+        }));
         msg.push((format!("` to type '"), Style::NoStyle));
-        msg.extend(found.0.iter()
-                   .map(|x| match *x {
-                       StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-                       StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
-                   }));
+        msg.extend(found.0.iter().map(|x| match *x {
+            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+        }));
         msg.push((format!("`"), Style::NoStyle));
 
         // For now, just attach these as notes
@@ -213,22 +200,18 @@ impl Diagnostic {
         } else {
             (0, found_label.len() - expected_label.len())
         };
-        let mut msg: Vec<_> = vec![(
-            format!("{}{} `", " ".repeat(expected_padding), expected_label),
-            Style::NoStyle,
-        )];
-        msg.extend(expected.0.iter()
-            .map(|x| match *x {
-                StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-                StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
-            }));
+        let mut msg: Vec<_> =
+            vec![(format!("{}{} `", " ".repeat(expected_padding), expected_label), Style::NoStyle)];
+        msg.extend(expected.0.iter().map(|x| match *x {
+            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+        }));
         msg.push((format!("`{}\n", expected_extra), Style::NoStyle));
         msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
-        msg.extend(found.0.iter()
-            .map(|x| match *x {
-                StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-                StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
-            }));
+        msg.extend(found.0.iter().map(|x| match *x {
+            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+        }));
         msg.push((format!("`{}", found_extra), Style::NoStyle));
 
         // For now, just attach these as notes.
@@ -240,7 +223,8 @@ impl Diagnostic {
         self.highlighted_note(vec![
             (format!("`{}` from trait: `", name), Style::NoStyle),
             (signature, Style::Highlight),
-            ("`".to_string(), Style::NoStyle)]);
+            ("`".to_string(), Style::NoStyle),
+        ]);
         self
     }
 
@@ -255,10 +239,7 @@ impl Diagnostic {
     }
 
     /// Prints the span with a note above it.
-    pub fn span_note<S: Into<MultiSpan>>(&mut self,
-                                         sp: S,
-                                         msg: &str)
-                                         -> &mut Self {
+    pub fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
         self.sub(Level::Note, msg, sp.into(), None);
         self
     }
@@ -269,24 +250,18 @@ impl Diagnostic {
     }
 
     /// Prints the span with a warn above it.
-    pub fn span_warn<S: Into<MultiSpan>>(&mut self,
-                                         sp: S,
-                                         msg: &str)
-                                         -> &mut Self {
+    pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
         self.sub(Level::Warning, msg, sp.into(), None);
         self
     }
 
-    pub fn help(&mut self , msg: &str) -> &mut Self {
+    pub fn help(&mut self, msg: &str) -> &mut Self {
         self.sub(Level::Help, msg, MultiSpan::new(), None);
         self
     }
 
     /// Prints the span with some help above it.
-    pub fn span_help<S: Into<MultiSpan>>(&mut self,
-                                         sp: S,
-                                         msg: &str)
-                                         -> &mut Self {
+    pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
         self.sub(Level::Help, msg, sp.into(), None);
         self
     }
@@ -381,10 +356,7 @@ impl Diagnostic {
     ) -> &mut Self {
         self.suggestions.push(CodeSuggestion {
             substitutions: vec![Substitution {
-                parts: vec![SubstitutionPart {
-                    snippet: suggestion,
-                    span: sp,
-                }],
+                parts: vec![SubstitutionPart { snippet: suggestion, span: sp }],
             }],
             msg: msg.to_owned(),
             style,
@@ -419,12 +391,9 @@ impl Diagnostic {
         applicability: Applicability,
     ) -> &mut Self {
         self.suggestions.push(CodeSuggestion {
-            substitutions: suggestions.map(|snippet| Substitution {
-                parts: vec![SubstitutionPart {
-                    snippet,
-                    span: sp,
-                }],
-            }).collect(),
+            substitutions: suggestions
+                .map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
+                .collect(),
             msg: msg.to_owned(),
             style: SuggestionStyle::ShowCode,
             applicability,
@@ -437,7 +406,11 @@ impl Diagnostic {
     ///
     /// See `CodeSuggestion` for more information.
     pub fn span_suggestion_short(
-        &mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
+        &mut self,
+        sp: Span,
+        msg: &str,
+        suggestion: String,
+        applicability: Applicability,
     ) -> &mut Self {
         self.span_suggestion_with_style(
             sp,
@@ -456,7 +429,11 @@ impl Diagnostic {
     /// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
     /// improve understandability.
     pub fn span_suggestion_hidden(
-        &mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
+        &mut self,
+        sp: Span,
+        msg: &str,
+        suggestion: String,
+        applicability: Applicability,
     ) -> &mut Self {
         self.span_suggestion_with_style(
             sp,
@@ -473,7 +450,11 @@ impl Diagnostic {
     /// This is intended to be used for suggestions that are *very* obvious in what the changes
     /// need to be from the message, but we still want other tools to be able to apply them.
     pub fn tool_only_span_suggestion(
-        &mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
+        &mut self,
+        sp: Span,
+        msg: &str,
+        suggestion: String,
+        applicability: Applicability,
     ) -> &mut Self {
         self.span_suggestion_with_style(
             sp,
@@ -530,11 +511,13 @@ impl Diagnostic {
 
     /// Convenience function for internal use, clients should use one of the
     /// public methods above.
-    pub fn sub(&mut self,
-           level: Level,
-           message: &str,
-           span: MultiSpan,
-           render_span: Option<MultiSpan>) {
+    pub fn sub(
+        &mut self,
+        level: Level,
+        message: &str,
+        span: MultiSpan,
+        render_span: Option<MultiSpan>,
+    ) {
         let sub = SubDiagnostic {
             level,
             message: vec![(message.to_owned(), Style::NoStyle)],
@@ -546,17 +529,14 @@ impl Diagnostic {
 
     /// Convenience function for internal use, clients should use one of the
     /// public methods above.
-    fn sub_with_highlights(&mut self,
-                           level: Level,
-                           message: Vec<(String, Style)>,
-                           span: MultiSpan,
-                           render_span: Option<MultiSpan>) {
-        let sub = SubDiagnostic {
-            level,
-            message,
-            span,
-            render_span,
-        };
+    fn sub_with_highlights(
+        &mut self,
+        level: Level,
+        message: Vec<(String, Style)>,
+        span: MultiSpan,
+        render_span: Option<MultiSpan>,
+    ) {
+        let sub = SubDiagnostic { level, message, span, render_span };
         self.children.push(sub);
     }
 }
diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs
index a95c29f8c27..ef3a4a9a708 100644
--- a/src/librustc_errors/diagnostic_builder.rs
+++ b/src/librustc_errors/diagnostic_builder.rs
@@ -1,11 +1,11 @@
+use crate::{Applicability, Handler, Level, StashKey};
 use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString};
-use crate::{Applicability, Level, Handler, StashKey};
 
+use log::debug;
 use std::fmt::{self, Debug};
 use std::ops::{Deref, DerefMut};
 use std::thread::panicking;
 use syntax_pos::{MultiSpan, Span};
-use log::debug;
 
 /// Used for emitting structured error messages and other diagnostic information.
 ///
@@ -106,11 +106,7 @@ impl<'a> DiagnosticBuilder<'a> {
     ///
     /// See `emit` and `delay_as_bug` for details.
     pub fn emit_unless(&mut self, delay: bool) {
-        if delay {
-            self.delay_as_bug()
-        } else {
-            self.emit()
-        }
+        if delay { self.delay_as_bug() } else { self.emit() }
     }
 
     /// Stashes diagnostic for possible later improvement in a different,
@@ -127,8 +123,8 @@ impl<'a> DiagnosticBuilder<'a> {
     /// Converts the builder to a `Diagnostic` for later emission,
     /// unless handler has disabled such buffering.
     pub fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a Handler)> {
-        if self.0.handler.flags.dont_buffer_diagnostics ||
-            self.0.handler.flags.treat_err_as_bug.is_some()
+        if self.0.handler.flags.dont_buffer_diagnostics
+            || self.0.handler.flags.treat_err_as_bug.is_some()
         {
             self.emit();
             return None;
@@ -241,13 +237,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.multipart_suggestion(
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.multipart_suggestion(msg, suggestion, applicability);
         self
     }
 
@@ -258,13 +250,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.tool_only_multipart_suggestion(
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.tool_only_multipart_suggestion(msg, suggestion, applicability);
         self
     }
 
@@ -276,14 +264,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.span_suggestion(
-            sp,
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.span_suggestion(sp, msg, suggestion, applicability);
         self
     }
 
@@ -295,14 +278,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.span_suggestions(
-            sp,
-            msg,
-            suggestions,
-            applicability,
-        );
+        self.0.diagnostic.span_suggestions(sp, msg, suggestions, applicability);
         self
     }
 
@@ -314,14 +292,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.span_suggestion_short(
-            sp,
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.span_suggestion_short(sp, msg, suggestion, applicability);
         self
     }
 
@@ -333,14 +306,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.span_suggestion_hidden(
-            sp,
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.span_suggestion_hidden(sp, msg, suggestion, applicability);
         self
     }
 
@@ -352,14 +320,9 @@ impl<'a> DiagnosticBuilder<'a> {
         applicability: Applicability,
     ) -> &mut Self {
         if !self.0.allow_suggestions {
-            return self
+            return self;
         }
-        self.0.diagnostic.tool_only_span_suggestion(
-            sp,
-            msg,
-            suggestion,
-            applicability,
-        );
+        self.0.diagnostic.tool_only_span_suggestion(sp, msg, suggestion, applicability);
         self
     }
 
@@ -379,19 +342,19 @@ impl<'a> DiagnosticBuilder<'a> {
 
     /// Convenience function for internal use, clients should use one of the
     /// struct_* methods on Handler.
-    crate fn new_with_code(handler: &'a Handler,
-                         level: Level,
-                         code: Option<DiagnosticId>,
-                         message: &str)
-                         -> DiagnosticBuilder<'a> {
+    crate fn new_with_code(
+        handler: &'a Handler,
+        level: Level,
+        code: Option<DiagnosticId>,
+        message: &str,
+    ) -> DiagnosticBuilder<'a> {
         let diagnostic = Diagnostic::new_with_code(level, code, message);
         DiagnosticBuilder::new_diagnostic(handler, diagnostic)
     }
 
     /// Creates a new `DiagnosticBuilder` with an already constructed
     /// diagnostic.
-    crate 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/json.rs b/src/librustc_errors/json.rs
index ebbd49bd84a..5f529c08c78 100644
--- a/src/librustc_errors/json.rs
+++ b/src/librustc_errors/json.rs
@@ -9,19 +9,19 @@
 
 // FIXME: spec the JSON output properly.
 
-use syntax_pos::source_map::{SourceMap, FilePathMapping};
+use syntax_pos::source_map::{FilePathMapping, SourceMap};
 
-use crate::registry::Registry;
-use crate::{SubDiagnostic, CodeSuggestion};
-use crate::{DiagnosticId, Applicability};
 use crate::emitter::{Emitter, HumanReadableErrorType};
+use crate::registry::Registry;
+use crate::{Applicability, DiagnosticId};
+use crate::{CodeSuggestion, SubDiagnostic};
 
-use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan};
 use rustc_data_structures::sync::Lrc;
 use std::io::{self, Write};
 use std::path::Path;
-use std::vec;
 use std::sync::{Arc, Mutex};
+use std::vec;
+use syntax_pos::{MacroBacktrace, MultiSpan, Span, SpanLabel};
 
 use rustc_serialize::json::{as_json, as_pretty_json};
 
@@ -63,8 +63,13 @@ impl JsonEmitter {
         external_macro_backtrace: bool,
     ) -> JsonEmitter {
         let file_path_mapping = FilePathMapping::empty();
-        JsonEmitter::stderr(None, Lrc::new(SourceMap::new(file_path_mapping)),
-                            pretty, json_rendered, external_macro_backtrace)
+        JsonEmitter::stderr(
+            None,
+            Lrc::new(SourceMap::new(file_path_mapping)),
+            pretty,
+            json_rendered,
+            external_macro_backtrace,
+        )
     }
 
     pub fn new(
@@ -212,18 +217,14 @@ struct ArtifactNotification<'a> {
 }
 
 impl Diagnostic {
-    fn from_errors_diagnostic(diag: &crate::Diagnostic,
-                               je: &JsonEmitter)
-                               -> Diagnostic {
-        let sugg = diag.suggestions.iter().map(|sugg| {
-            Diagnostic {
-                message: sugg.msg.clone(),
-                code: None,
-                level: "help",
-                spans: DiagnosticSpan::from_suggestion(sugg, je),
-                children: vec![],
-                rendered: None,
-            }
+    fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
+        let sugg = diag.suggestions.iter().map(|sugg| Diagnostic {
+            message: sugg.msg.clone(),
+            code: None,
+            level: "help",
+            spans: DiagnosticSpan::from_suggestion(sugg, je),
+            children: vec![],
+            rendered: None,
         });
 
         // generate regular command line output and store it in the json
@@ -242,9 +243,16 @@ impl Diagnostic {
         }
         let buf = BufWriter::default();
         let output = buf.clone();
-        je.json_rendered.new_emitter(
-            Box::new(buf), Some(je.sm.clone()), false, None, je.external_macro_backtrace
-        ).ui_testing(je.ui_testing).emit_diagnostic(diag);
+        je.json_rendered
+            .new_emitter(
+                Box::new(buf),
+                Some(je.sm.clone()),
+                false,
+                None,
+                je.external_macro_backtrace,
+            )
+            .ui_testing(je.ui_testing)
+            .emit_diagnostic(diag);
         let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
         let output = String::from_utf8(output).unwrap();
 
@@ -253,9 +261,12 @@ impl Diagnostic {
             code: DiagnosticCode::map_opt_string(diag.code.clone(), je),
             level: diag.level.to_str(),
             spans: DiagnosticSpan::from_multispan(&diag.span, je),
-            children: diag.children.iter().map(|c| {
-                Diagnostic::from_sub_diagnostic(c, je)
-            }).chain(sugg).collect(),
+            children: diag
+                .children
+                .iter()
+                .map(|c| Diagnostic::from_sub_diagnostic(c, je))
+                .chain(sugg)
+                .collect(),
             rendered: Some(output),
         }
     }
@@ -265,9 +276,11 @@ impl Diagnostic {
             message: diag.message(),
             code: None,
             level: diag.level.to_str(),
-            spans: diag.render_span.as_ref()
-                     .map(|sp| DiagnosticSpan::from_multispan(sp, je))
-                     .unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, je)),
+            spans: diag
+                .render_span
+                .as_ref()
+                .map(|sp| DiagnosticSpan::from_multispan(sp, je))
+                .unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, je)),
             children: vec![],
             rendered: None,
         }
@@ -275,61 +288,44 @@ impl Diagnostic {
 }
 
 impl DiagnosticSpan {
-    fn from_span_label(span: SpanLabel,
-                       suggestion: Option<(&String, Applicability)>,
-                       je: &JsonEmitter)
-                       -> DiagnosticSpan {
-        Self::from_span_etc(span.span,
-                            span.is_primary,
-                            span.label,
-                            suggestion,
-                            je)
+    fn from_span_label(
+        span: SpanLabel,
+        suggestion: Option<(&String, Applicability)>,
+        je: &JsonEmitter,
+    ) -> DiagnosticSpan {
+        Self::from_span_etc(span.span, span.is_primary, span.label, suggestion, je)
     }
 
-    fn from_span_etc(span: Span,
-                     is_primary: bool,
-                     label: Option<String>,
-                     suggestion: Option<(&String, Applicability)>,
-                     je: &JsonEmitter)
-                     -> DiagnosticSpan {
+    fn from_span_etc(
+        span: Span,
+        is_primary: bool,
+        label: Option<String>,
+        suggestion: Option<(&String, Applicability)>,
+        je: &JsonEmitter,
+    ) -> DiagnosticSpan {
         // obtain the full backtrace from the `macro_backtrace`
         // helper; in some ways, it'd be better to expand the
         // backtrace ourselves, but the `macro_backtrace` helper makes
         // some decision, such as dropping some frames, and I don't
         // want to duplicate that logic here.
         let backtrace = span.macro_backtrace().into_iter();
-        DiagnosticSpan::from_span_full(span,
-                                       is_primary,
-                                       label,
-                                       suggestion,
-                                       backtrace,
-                                       je)
+        DiagnosticSpan::from_span_full(span, is_primary, label, suggestion, backtrace, je)
     }
 
-    fn from_span_full(span: Span,
-                      is_primary: bool,
-                      label: Option<String>,
-                      suggestion: Option<(&String, Applicability)>,
-                      mut backtrace: vec::IntoIter<MacroBacktrace>,
-                      je: &JsonEmitter)
-                      -> DiagnosticSpan {
+    fn from_span_full(
+        span: Span,
+        is_primary: bool,
+        label: Option<String>,
+        suggestion: Option<(&String, Applicability)>,
+        mut backtrace: vec::IntoIter<MacroBacktrace>,
+        je: &JsonEmitter,
+    ) -> DiagnosticSpan {
         let start = je.sm.lookup_char_pos(span.lo());
         let end = je.sm.lookup_char_pos(span.hi());
         let backtrace_step = backtrace.next().map(|bt| {
-            let call_site =
-                Self::from_span_full(bt.call_site,
-                                     false,
-                                     None,
-                                     None,
-                                     backtrace,
-                                     je);
+            let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
             let def_site_span =
-                Self::from_span_full(bt.def_site_span,
-                                     false,
-                                     None,
-                                     None,
-                                     vec![].into_iter(),
-                                     je);
+                Self::from_span_full(bt.def_site_span, false, None, None, vec![].into_iter(), je);
             Box::new(DiagnosticSpanMacroExpansion {
                 span: call_site,
                 macro_decl_name: bt.macro_decl_name,
@@ -356,38 +352,37 @@ impl DiagnosticSpan {
 
     fn from_multispan(msp: &MultiSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
         msp.span_labels()
-           .into_iter()
-           .map(|span_str| Self::from_span_label(span_str, None, je))
-           .collect()
+            .into_iter()
+            .map(|span_str| Self::from_span_label(span_str, None, je))
+            .collect()
     }
 
-    fn from_suggestion(suggestion: &CodeSuggestion, je: &JsonEmitter)
-                       -> Vec<DiagnosticSpan> {
-        suggestion.substitutions
-                      .iter()
-                      .flat_map(|substitution| {
-                          substitution.parts.iter().map(move |suggestion_inner| {
-                              let span_label = SpanLabel {
-                                  span: suggestion_inner.span,
-                                  is_primary: true,
-                                  label: None,
-                              };
-                              DiagnosticSpan::from_span_label(span_label,
-                                                              Some((&suggestion_inner.snippet,
-                                                                   suggestion.applicability)),
-                                                              je)
-                          })
-                      })
-                      .collect()
+    fn from_suggestion(suggestion: &CodeSuggestion, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
+        suggestion
+            .substitutions
+            .iter()
+            .flat_map(|substitution| {
+                substitution.parts.iter().map(move |suggestion_inner| {
+                    let span_label =
+                        SpanLabel { span: suggestion_inner.span, is_primary: true, label: None };
+                    DiagnosticSpan::from_span_label(
+                        span_label,
+                        Some((&suggestion_inner.snippet, suggestion.applicability)),
+                        je,
+                    )
+                })
+            })
+            .collect()
     }
 }
 
 impl DiagnosticSpanLine {
-    fn line_from_source_file(fm: &syntax_pos::SourceFile,
-                         index: usize,
-                         h_start: usize,
-                         h_end: usize)
-                         -> DiagnosticSpanLine {
+    fn line_from_source_file(
+        fm: &syntax_pos::SourceFile,
+        index: usize,
+        h_start: usize,
+        h_end: usize,
+    ) -> DiagnosticSpanLine {
         DiagnosticSpanLine {
             text: fm.get_line(index).map_or(String::new(), |l| l.into_owned()),
             highlight_start: h_start,
@@ -399,18 +394,24 @@ impl DiagnosticSpanLine {
     /// of `span` gets a DiagnosticSpanLine, with the highlight indicating the
     /// `span` within the line.
     fn from_span(span: Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
-        je.sm.span_to_lines(span)
+        je.sm
+            .span_to_lines(span)
             .map(|lines| {
                 let fm = &*lines.file;
-                lines.lines
+                lines
+                    .lines
                     .iter()
-                    .map(|line| DiagnosticSpanLine::line_from_source_file(
-                        fm,
-                        line.line_index,
-                        line.start_col.0 + 1,
-                        line.end_col.0 + 1,
-                    )).collect()
-            }).unwrap_or_else(|_| vec![])
+                    .map(|line| {
+                        DiagnosticSpanLine::line_from_source_file(
+                            fm,
+                            line.line_index,
+                            line.start_col.0 + 1,
+                            line.end_col.0 + 1,
+                        )
+                    })
+                    .collect()
+            })
+            .unwrap_or_else(|_| vec![])
     }
 }
 
@@ -421,14 +422,10 @@ impl DiagnosticCode {
                 DiagnosticId::Error(s) => s,
                 DiagnosticId::Lint(s) => s,
             };
-            let explanation = je.registry
-                                .as_ref()
-                                .and_then(|registry| registry.find_description(&s));
+            let explanation =
+                je.registry.as_ref().and_then(|registry| registry.find_description(&s));
 
-            DiagnosticCode {
-                code: s,
-                explanation,
-            }
+            DiagnosticCode { code: s, explanation }
         })
     }
 }
diff --git a/src/librustc_errors/json/tests.rs b/src/librustc_errors/json/tests.rs
index 4ab5cd21b0b..a96bf715858 100644
--- a/src/librustc_errors/json/tests.rs
+++ b/src/librustc_errors/json/tests.rs
@@ -41,9 +41,7 @@ impl<T: Write> Write for Shared<T> {
 
 fn with_default_globals(f: impl FnOnce()) {
     let globals = syntax_pos::Globals::new(syntax_pos::edition::DEFAULT_EDITION);
-    syntax_pos::GLOBALS.set(&globals, || {
-        syntax_pos::GLOBALS.set(&globals, f)
-    })
+    syntax_pos::GLOBALS.set(&globals, || syntax_pos::GLOBALS.set(&globals, f))
 }
 
 /// Test the span yields correct positions in JSON.
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index ae587684818..8f1437ee49c 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -3,7 +3,6 @@
 //! This module contains the code for creating and emitting diagnostics.
 
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
-
 #![feature(crate_visibility_modifier)]
 #![cfg_attr(unix, feature(libc))]
 #![feature(nll)]
@@ -13,31 +12,31 @@ pub use emitter::ColorConfig;
 
 use Level::*;
 
-use emitter::{Emitter, EmitterWriter, is_case_difference};
+use emitter::{is_case_difference, Emitter, EmitterWriter};
 use registry::Registry;
-use rustc_data_structures::sync::{self, Lrc, Lock};
 use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
 use rustc_data_structures::stable_hasher::StableHasher;
+use rustc_data_structures::sync::{self, Lock, Lrc};
 use syntax_pos::source_map::SourceMap;
-use syntax_pos::{Loc, Span, MultiSpan};
+use syntax_pos::{Loc, MultiSpan, Span};
 
 use std::borrow::Cow;
 use std::cell::Cell;
-use std::{error, fmt};
 use std::panic;
 use std::path::Path;
+use std::{error, fmt};
 
-use termcolor::{ColorSpec, Color};
+use termcolor::{Color, ColorSpec};
 
+pub mod annotate_snippet_emitter_writer;
 mod diagnostic;
 mod diagnostic_builder;
 pub mod emitter;
-pub mod annotate_snippet_emitter_writer;
-mod snippet;
+pub mod json;
+mod lock;
 pub mod registry;
+mod snippet;
 mod styled_buffer;
-mod lock;
-pub mod json;
 pub use snippet::Style;
 
 pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;
@@ -146,16 +145,15 @@ pub struct SubstitutionPart {
 impl CodeSuggestion {
     /// Returns the assembled code suggestions, whether they should be shown with an underline
     /// and whether the substitution only differs in capitalization.
-    pub fn splice_lines(
-        &self,
-        cm: &SourceMap,
-    ) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
+    pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
         use syntax_pos::{CharPos, Pos};
 
-        fn push_trailing(buf: &mut String,
-                         line_opt: Option<&Cow<'_, str>>,
-                         lo: &Loc,
-                         hi_opt: Option<&Loc>) {
+        fn push_trailing(
+            buf: &mut String,
+            line_opt: Option<&Cow<'_, str>>,
+            lo: &Loc,
+            hi_opt: Option<&Loc>,
+        ) {
             let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
             if let Some(line) = line_opt {
                 if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
@@ -174,67 +172,71 @@ impl CodeSuggestion {
 
         assert!(!self.substitutions.is_empty());
 
-        self.substitutions.iter().cloned().map(|mut substitution| {
-            // Assumption: all spans are in the same file, and all spans
-            // are disjoint. Sort in ascending order.
-            substitution.parts.sort_by_key(|part| part.span.lo());
-
-            // Find the bounding span.
-            let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
-            let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
-            let bounding_span = Span::with_root_ctxt(lo, hi);
-            let lines = cm.span_to_lines(bounding_span).unwrap();
-            assert!(!lines.lines.is_empty());
-
-            // To build up the result, we do this for each span:
-            // - push the line segment trailing the previous span
-            //   (at the beginning a "phantom" span pointing at the start of the line)
-            // - push lines between the previous and current span (if any)
-            // - if the previous and current span are not on the same line
-            //   push the line segment leading up to the current span
-            // - splice in the span substitution
-            //
-            // Finally push the trailing line segment of the last span
-            let fm = &lines.file;
-            let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
-            prev_hi.col = CharPos::from_usize(0);
-
-            let mut prev_line = fm.get_line(lines.lines[0].line_index);
-            let mut buf = String::new();
-
-            for part in &substitution.parts {
-                let cur_lo = cm.lookup_char_pos(part.span.lo());
-                if prev_hi.line == cur_lo.line {
-                    push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
-                } else {
-                    push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
-                    // push lines between the previous and current span (if any)
-                    for idx in prev_hi.line..(cur_lo.line - 1) {
-                        if let Some(line) = fm.get_line(idx) {
-                            buf.push_str(line.as_ref());
-                            buf.push('\n');
+        self.substitutions
+            .iter()
+            .cloned()
+            .map(|mut substitution| {
+                // Assumption: all spans are in the same file, and all spans
+                // are disjoint. Sort in ascending order.
+                substitution.parts.sort_by_key(|part| part.span.lo());
+
+                // Find the bounding span.
+                let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
+                let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
+                let bounding_span = Span::with_root_ctxt(lo, hi);
+                let lines = cm.span_to_lines(bounding_span).unwrap();
+                assert!(!lines.lines.is_empty());
+
+                // To build up the result, we do this for each span:
+                // - push the line segment trailing the previous span
+                //   (at the beginning a "phantom" span pointing at the start of the line)
+                // - push lines between the previous and current span (if any)
+                // - if the previous and current span are not on the same line
+                //   push the line segment leading up to the current span
+                // - splice in the span substitution
+                //
+                // Finally push the trailing line segment of the last span
+                let fm = &lines.file;
+                let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
+                prev_hi.col = CharPos::from_usize(0);
+
+                let mut prev_line = fm.get_line(lines.lines[0].line_index);
+                let mut buf = String::new();
+
+                for part in &substitution.parts {
+                    let cur_lo = cm.lookup_char_pos(part.span.lo());
+                    if prev_hi.line == cur_lo.line {
+                        push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
+                    } else {
+                        push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
+                        // push lines between the previous and current span (if any)
+                        for idx in prev_hi.line..(cur_lo.line - 1) {
+                            if let Some(line) = fm.get_line(idx) {
+                                buf.push_str(line.as_ref());
+                                buf.push('\n');
+                            }
+                        }
+                        if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
+                            let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
+                            buf.push_str(&cur_line[..end]);
                         }
                     }
-                    if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
-                        let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
-                        buf.push_str(&cur_line[..end]);
-                    }
+                    buf.push_str(&part.snippet);
+                    prev_hi = cm.lookup_char_pos(part.span.hi());
+                    prev_line = fm.get_line(prev_hi.line - 1);
                 }
-                buf.push_str(&part.snippet);
-                prev_hi = cm.lookup_char_pos(part.span.hi());
-                prev_line = fm.get_line(prev_hi.line - 1);
-            }
-            let only_capitalization = is_case_difference(cm, &buf, bounding_span);
-            // if the replacement already ends with a newline, don't print the next line
-            if !buf.ends_with('\n') {
-                push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
-            }
-            // remove trailing newlines
-            while buf.ends_with('\n') {
-                buf.pop();
-            }
-            (buf, substitution.parts, only_capitalization)
-        }).collect()
+                let only_capitalization = is_case_difference(cm, &buf, bounding_span);
+                // if the replacement already ends with a newline, don't print the next line
+                if !buf.ends_with('\n') {
+                    push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
+                }
+                // remove trailing newlines
+                while buf.ends_with('\n') {
+                    buf.pop();
+                }
+                (buf, substitution.parts, only_capitalization)
+            })
+            .collect()
     }
 }
 
@@ -257,7 +259,7 @@ impl error::Error for ExplicitBug {
     }
 }
 
-pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
+pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic};
 pub use diagnostic_builder::DiagnosticBuilder;
 
 /// A handler deals with errors and other compiler output.
@@ -360,11 +362,7 @@ impl Handler {
         Self::with_tty_emitter_and_flags(
             color_config,
             cm,
-            HandlerFlags {
-                can_emit_warnings,
-                treat_err_as_bug,
-                .. Default::default()
-            },
+            HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
         )
     }
 
@@ -391,17 +389,13 @@ impl Handler {
     ) -> Self {
         Handler::with_emitter_and_flags(
             emitter,
-            HandlerFlags {
-                can_emit_warnings,
-                treat_err_as_bug,
-                .. Default::default()
-            },
+            HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
         )
     }
 
     pub fn with_emitter_and_flags(
         emitter: Box<dyn Emitter + sync::Send>,
-        flags: HandlerFlags
+        flags: HandlerFlags,
     ) -> Self {
         Self {
             flags,
@@ -457,7 +451,10 @@ impl Handler {
             old_diag.level = Bug;
             old_diag.note(&format!(
                 "{}:{}: already existing stashed diagnostic with (span = {:?}, key = {:?})",
-                file!(), line!(), span, key
+                file!(),
+                line!(),
+                span,
+                key
             ));
             inner.emit_diag_at_span(old_diag, span);
             panic!(ExplicitBug);
@@ -779,7 +776,7 @@ impl HandlerInner {
         let s = match self.deduplicated_err_count {
             0 => return,
             1 => "aborting due to previous error".to_string(),
-            count => format!("aborting due to {} previous errors", count)
+            count => format!("aborting due to {} previous errors", count),
         };
         if self.treat_err_as_bug() {
             return;
@@ -804,16 +801,22 @@ impl HandlerInner {
                 error_codes.sort();
                 if error_codes.len() > 1 {
                     let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
-                    self.failure(&format!("Some errors have detailed explanations: {}{}",
-                                          error_codes[..limit].join(", "),
-                                          if error_codes.len() > 9 { "..." } else { "." }));
-                    self.failure(&format!("For more information about an error, try \
+                    self.failure(&format!(
+                        "Some errors have detailed explanations: {}{}",
+                        error_codes[..limit].join(", "),
+                        if error_codes.len() > 9 { "..." } else { "." }
+                    ));
+                    self.failure(&format!(
+                        "For more information about an error, try \
                                            `rustc --explain {}`.",
-                                          &error_codes[0]));
+                        &error_codes[0]
+                    ));
                 } else {
-                    self.failure(&format!("For more information about this error, try \
+                    self.failure(&format!(
+                        "For more information about this error, try \
                                            `rustc --explain {}`.",
-                                          &error_codes[0]));
+                        &error_codes[0]
+                    ));
                 }
             }
         }
@@ -880,7 +883,7 @@ impl HandlerInner {
     }
 
     /// Emit an error; level should be `Error` or `Fatal`.
-    fn emit_error(&mut self, level: Level, msg: &str,) {
+    fn emit_error(&mut self, level: Level, msg: &str) {
         if self.treat_err_as_bug() {
             self.bug(msg);
         }
@@ -910,13 +913,10 @@ impl HandlerInner {
                 (0, _) => return,
                 (1, 1) => "aborting due to `-Z treat-err-as-bug=1`".to_string(),
                 (1, _) => return,
-                (count, as_bug) => {
-                    format!(
-                        "aborting after {} errors due to `-Z treat-err-as-bug={}`",
-                        count,
-                        as_bug,
-                    )
-                }
+                (count, as_bug) => format!(
+                    "aborting after {} errors due to `-Z treat-err-as-bug={}`",
+                    count, as_bug,
+                ),
             };
             panic!(s);
         }
@@ -946,20 +946,16 @@ impl Level {
         let mut spec = ColorSpec::new();
         match self {
             Bug | Fatal | Error => {
-                spec.set_fg(Some(Color::Red))
-                    .set_intense(true);
+                spec.set_fg(Some(Color::Red)).set_intense(true);
             }
             Warning => {
-                spec.set_fg(Some(Color::Yellow))
-                    .set_intense(cfg!(windows));
+                spec.set_fg(Some(Color::Yellow)).set_intense(cfg!(windows));
             }
             Note => {
-                spec.set_fg(Some(Color::Green))
-                    .set_intense(true);
+                spec.set_fg(Some(Color::Green)).set_intense(true);
             }
             Help => {
-                spec.set_fg(Some(Color::Cyan))
-                    .set_intense(true);
+                spec.set_fg(Some(Color::Cyan)).set_intense(true);
             }
             FailureNote => {}
             Cancelled => unreachable!(),
diff --git a/src/librustc_errors/lock.rs b/src/librustc_errors/lock.rs
index 25a27d2cbd8..198a9c12406 100644
--- a/src/librustc_errors/lock.rs
+++ b/src/librustc_errors/lock.rs
@@ -28,10 +28,11 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
     const WAIT_ABANDONED: DWORD = 0x00000080;
 
     extern "system" {
-        fn CreateMutexA(lpMutexAttributes: LPSECURITY_ATTRIBUTES,
-                        bInitialOwner: BOOL,
-                        lpName: LPCSTR)
-                        -> HANDLE;
+        fn CreateMutexA(
+            lpMutexAttributes: LPSECURITY_ATTRIBUTES,
+            bInitialOwner: BOOL,
+            lpName: LPCSTR,
+        ) -> HANDLE;
         fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
         fn ReleaseMutex(hMutex: HANDLE) -> BOOL;
         fn CloseHandle(hObject: HANDLE) -> BOOL;
@@ -66,9 +67,11 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
         // open up a handle to one if it already exists.
         let mutex = CreateMutexA(std::ptr::null_mut(), 0, cname.as_ptr() as *const u8);
         if mutex.is_null() {
-            panic!("failed to create global mutex named `{}`: {}",
-                   name,
-                   io::Error::last_os_error());
+            panic!(
+                "failed to create global mutex named `{}`: {}",
+                name,
+                io::Error::last_os_error()
+            );
         }
         let mutex = Handle(mutex);
 
@@ -86,11 +89,13 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
         match WaitForSingleObject(mutex.0, INFINITE) {
             WAIT_OBJECT_0 | WAIT_ABANDONED => {}
             code => {
-                panic!("WaitForSingleObject failed on global mutex named \
+                panic!(
+                    "WaitForSingleObject failed on global mutex named \
                         `{}`: {} (ret={:x})",
-                       name,
-                       io::Error::last_os_error(),
-                       code);
+                    name,
+                    io::Error::last_os_error(),
+                    code
+                );
             }
         }
 
diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs
index 47ba22d3d25..a39e19f0bf7 100644
--- a/src/librustc_errors/snippet.rs
+++ b/src/librustc_errors/snippet.rs
@@ -8,7 +8,6 @@ pub struct Line {
     pub annotations: Vec<Annotation>,
 }
 
-
 #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
 pub struct MultilineAnnotation {
     pub depth: usize,
@@ -28,8 +27,10 @@ impl MultilineAnnotation {
 
     /// Compare two `MultilineAnnotation`s considering only the `Span` they cover.
     pub fn same_span(&self, other: &MultilineAnnotation) -> bool {
-        self.line_start == other.line_start && self.line_end == other.line_end
-            && self.start_col == other.start_col && self.end_col == other.end_col
+        self.line_start == other.line_start
+            && self.line_end == other.line_end
+            && self.start_col == other.start_col
+            && self.end_col == other.end_col
     }
 
     pub fn as_start(&self) -> Annotation {
@@ -38,7 +39,7 @@ impl MultilineAnnotation {
             end_col: self.start_col + 1,
             is_primary: self.is_primary,
             label: None,
-            annotation_type: AnnotationType::MultilineStart(self.depth)
+            annotation_type: AnnotationType::MultilineStart(self.depth),
         }
     }
 
@@ -48,7 +49,7 @@ impl MultilineAnnotation {
             end_col: self.end_col,
             is_primary: self.is_primary,
             label: self.label.clone(),
-            annotation_type: AnnotationType::MultilineEnd(self.depth)
+            annotation_type: AnnotationType::MultilineEnd(self.depth),
         }
     }
 
@@ -58,7 +59,7 @@ impl MultilineAnnotation {
             end_col: 0,
             is_primary: self.is_primary,
             label: None,
-            annotation_type: AnnotationType::MultilineLine(self.depth)
+            annotation_type: AnnotationType::MultilineLine(self.depth),
         }
     }
 }
@@ -117,19 +118,15 @@ pub struct Annotation {
 impl Annotation {
     /// Whether this annotation is a vertical line placeholder.
     pub fn is_line(&self) -> bool {
-        if let AnnotationType::MultilineLine(_) = self.annotation_type {
-            true
-        } else {
-            false
-        }
+        if let AnnotationType::MultilineLine(_) = self.annotation_type { true } else { false }
     }
 
     pub fn is_multiline(&self) -> bool {
         match self.annotation_type {
-            AnnotationType::Multiline(_) |
-            AnnotationType::MultilineStart(_) |
-            AnnotationType::MultilineLine(_) |
-            AnnotationType::MultilineEnd(_) => true,
+            AnnotationType::Multiline(_)
+            | AnnotationType::MultilineStart(_)
+            | AnnotationType::MultilineLine(_)
+            | AnnotationType::MultilineEnd(_) => true,
             _ => false,
         }
     }
@@ -164,8 +161,7 @@ impl Annotation {
     pub fn takes_space(&self) -> bool {
         // Multiline annotations always have to keep vertical space.
         match self.annotation_type {
-            AnnotationType::MultilineStart(_) |
-            AnnotationType::MultilineEnd(_) => true,
+            AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_) => true,
             _ => false,
         }
     }
diff --git a/src/librustc_errors/styled_buffer.rs b/src/librustc_errors/styled_buffer.rs
index b12ab9e4576..f2d255d7d95 100644
--- a/src/librustc_errors/styled_buffer.rs
+++ b/src/librustc_errors/styled_buffer.rs
@@ -10,10 +10,7 @@ pub struct StyledBuffer {
 
 impl StyledBuffer {
     pub fn new() -> StyledBuffer {
-        StyledBuffer {
-            text: vec![],
-            styles: vec![],
-        }
+        StyledBuffer { text: vec![], styles: vec![] }
     }
 
     fn replace_tabs(&mut self) {
@@ -51,10 +48,7 @@ impl StyledBuffer {
             for (&c, &s) in row.iter().zip(row_style) {
                 if s != current_style {
                     if !current_text.is_empty() {
-                        styled_vec.push(StyledString {
-                            text: current_text,
-                            style: current_style,
-                        });
+                        styled_vec.push(StyledString { text: current_text, style: current_style });
                     }
                     current_style = s;
                     current_text = String::new();
@@ -62,10 +56,7 @@ impl StyledBuffer {
                 current_text.push(c);
             }
             if !current_text.is_empty() {
-                styled_vec.push(StyledString {
-                    text: current_text,
-                    style: current_style,
-                });
+                styled_vec.push(StyledString { text: current_text, style: current_style });
             }
 
             // We're done with the row, push and keep going
@@ -135,12 +126,14 @@ impl StyledBuffer {
         self.text.len()
     }
 
-    pub fn set_style_range(&mut self,
-                           line: usize,
-                           col_start: usize,
-                           col_end: usize,
-                           style: Style,
-                           overwrite: bool) {
+    pub fn set_style_range(
+        &mut self,
+        line: usize,
+        col_start: usize,
+        col_end: usize,
+        style: Style,
+        overwrite: bool,
+    ) {
         for col in col_start..col_end {
             self.set_style(line, col, style, overwrite);
         }