]> git.lizzy.rs Git - rust.git/commitdiff
Add new error-format value to use annotate-snippet output
authorPhilipp Hansch <dev@phansch.net>
Fri, 31 May 2019 19:15:59 +0000 (21:15 +0200)
committerPhilipp Hansch <dev@phansch.net>
Tue, 4 Jun 2019 16:46:00 +0000 (18:46 +0200)
src/librustc/session/config.rs
src/librustc/session/mod.rs
src/test/ui/annotate-snippet/missing-type.rs [new file with mode: 0644]

index d8efa17defe3d06e6bed593c225a2f65a89548ff..6a35906d20c2f531dbd9a011d3c74a0652c2523b 100644 (file)
@@ -2002,6 +2002,9 @@ pub fn build_session_options_and_crate_config(
         match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
             None |
             Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)),
+            Some("human-annotate-rs") => {
+                ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(color))
+            },
             Some("json") => ErrorOutputType::Json { pretty: false, json_rendered },
             Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
             Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)),
@@ -2038,6 +2041,13 @@ pub fn build_session_options_and_crate_config(
                 "--error-format=pretty-json is unstable",
             );
         }
+        if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateRs(_)) =
+            error_format {
+            early_error(
+                ErrorOutputType::Json { pretty: false, json_rendered },
+                "--error-format=human-annotate-rs is unstable",
+            );
+        }
     }
 
     if debugging_opts.pgo_gen.enabled() && debugging_opts.pgo_use.is_some() {
index 40af5b45f9c35ebc1a00727022a5d7240d6757bd..b3a9d764b1db01cc4b9766187f253eaf802815c0 100644 (file)
@@ -23,6 +23,8 @@
 
 use errors::{DiagnosticBuilder, DiagnosticId, Applicability};
 use errors::emitter::{Emitter, EmitterWriter};
+use errors::emitter::HumanReadableErrorType;
+use errors::annotate_rs_emitter::{AnnotateRsEmitterWriter};
 use syntax::ast::{self, NodeId};
 use syntax::edition::Edition;
 use syntax::feature_gate::{self, AttributeType};
@@ -1031,22 +1033,31 @@ fn default_emitter(
     match (sopts.error_format, emitter_dest) {
         (config::ErrorOutputType::HumanReadable(kind), dst) => {
             let (short, color_config) = kind.unzip();
-            let emitter = match dst {
-                None => EmitterWriter::stderr(
-                    color_config,
-                    Some(source_map.clone()),
-                    short,
-                    sopts.debugging_opts.teach,
-                ),
-                Some(dst) => EmitterWriter::new(
-                    dst,
+
+            if let HumanReadableErrorType::AnnotateRs(_) = kind {
+                let emitter = AnnotateRsEmitterWriter::new(
                     Some(source_map.clone()),
                     short,
-                    false, // no teach messages when writing to a buffer
-                    false, // no colors when writing to a buffer
-                ),
-            };
-            Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
+                );
+                Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
+            } else {
+                let emitter = match dst {
+                    None => EmitterWriter::stderr(
+                        color_config,
+                        Some(source_map.clone()),
+                        short,
+                        sopts.debugging_opts.teach,
+                    ),
+                    Some(dst) => EmitterWriter::new(
+                        dst,
+                        Some(source_map.clone()),
+                        short,
+                        false, // no teach messages when writing to a buffer
+                        false, // no colors when writing to a buffer
+                    ),
+                };
+                Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
+            }
         },
         (config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
             JsonEmitter::stderr(
diff --git a/src/test/ui/annotate-snippet/missing-type.rs b/src/test/ui/annotate-snippet/missing-type.rs
new file mode 100644 (file)
index 0000000..e52a81e
--- /dev/null
@@ -0,0 +1,5 @@
+// compile-flags: --error-format human-annotate-rs
+
+pub fn main() {
+    let x: Iter;
+}