about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-14 17:57:28 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-08-21 11:58:24 -0700
commit21f2e9334567b64436f4e6525c5c98adafd16ca2 (patch)
tree0e43136339829eaf74a710779a90f688e26ebb30
parent9980796d6d29f532e9a49a5b3767285e2a5e2d02 (diff)
downloadrust-21f2e9334567b64436f4e6525c5c98adafd16ca2.tar.gz
rust-21f2e9334567b64436f4e6525c5c98adafd16ca2.zip
Add terminal_width debugging flag
-rw-r--r--src/librustc/session/config.rs2
-rw-r--r--src/librustc/session/mod.rs6
-rw-r--r--src/librustc_driver/lib.rs12
-rw-r--r--src/librustc_errors/emitter.rs24
-rw-r--r--src/librustc_errors/lib.rs2
-rw-r--r--src/librustdoc/core.rs1
-rw-r--r--src/librustdoc/test.rs2
-rw-r--r--src/libsyntax/json.rs2
-rw-r--r--src/libsyntax/parse/lexer/tests.rs9
-rw-r--r--src/libsyntax/tests.rs13
10 files changed, 50 insertions, 23 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 8e3b910e0da..89481e9eafd 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -1292,6 +1292,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
         "show macro backtraces even for non-local macros"),
     teach: bool = (false, parse_bool, [TRACKED],
         "show extended diagnostic help"),
+    terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
+        "set the current terminal width"),
     continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
         "attempt to recover from parse errors (experimental)"),
     dep_tasks: bool = (false, parse_bool, [UNTRACKED],
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 61dac678912..f01883d9634 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -1055,6 +1055,7 @@ fn default_emitter(
                         Some(source_map.clone()),
                         short,
                         sopts.debugging_opts.teach,
+                        sopts.debugging_opts.terminal_width,
                     ),
                     Some(dst) => EmitterWriter::new(
                         dst,
@@ -1062,6 +1063,7 @@ fn default_emitter(
                         short,
                         false, // no teach messages when writing to a buffer
                         false, // no colors when writing to a buffer
+                        None,  // no terminal width
                     ),
                 };
                 Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
@@ -1375,7 +1377,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
     let emitter: Box<dyn Emitter + sync::Send> = match output {
         config::ErrorOutputType::HumanReadable(kind) => {
             let (short, color_config) = kind.unzip();
-            Box::new(EmitterWriter::stderr(color_config, None, short, false))
+            Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
         }
         config::ErrorOutputType::Json { pretty, json_rendered } =>
             Box::new(JsonEmitter::basic(pretty, json_rendered)),
@@ -1389,7 +1391,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
     let emitter: Box<dyn Emitter + sync::Send> = match output {
         config::ErrorOutputType::HumanReadable(kind) => {
             let (short, color_config) = kind.unzip();
-            Box::new(EmitterWriter::stderr(color_config, None, short, false))
+            Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
         }
         config::ErrorOutputType::Json { pretty, json_rendered } =>
             Box::new(JsonEmitter::basic(pretty, json_rendered)),
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index b19ea513b75..3d94d51f17e 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -1135,11 +1135,13 @@ pub fn report_ices_to_stderr_if_any<F: FnOnce() -> R, R>(f: F) -> Result<R, Erro
             // Thread panicked without emitting a fatal diagnostic
             eprintln!("");
 
-            let emitter =
-                Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
-                                                                None,
-                                                                false,
-                                                                false));
+            let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
+                errors::ColorConfig::Auto,
+                None,
+                false,
+                false,
+                None,
+            ));
             let handler = errors::Handler::with_emitter(true, None, emitter);
 
             // a .span_bug or .bug call has already printed what
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 83c55c0da2b..77d373e7a8c 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -51,9 +51,11 @@ impl HumanReadableErrorType {
         dst: Box<dyn Write + Send>,
         source_map: Option<Lrc<SourceMapperDyn>>,
         teach: bool,
+        terminal_width: Option<usize>,
     ) -> EmitterWriter {
         let (short, color_config) = self.unzip();
-        EmitterWriter::new(dst, source_map, short, teach, color_config.suggests_using_colors())
+        let color = color_config.suggests_using_colors();
+        EmitterWriter::new(dst, source_map, short, teach, color, terminal_width)
     }
 }
 
@@ -296,6 +298,7 @@ pub struct EmitterWriter {
     short_message: bool,
     teach: bool,
     ui_testing: bool,
+    terminal_width: Option<usize>,
 }
 
 #[derive(Debug)]
@@ -306,11 +309,13 @@ pub struct FileWithAnnotatedLines {
 }
 
 impl EmitterWriter {
-    pub fn stderr(color_config: ColorConfig,
-                  source_map: Option<Lrc<SourceMapperDyn>>,
-                  short_message: bool,
-                  teach: bool)
-                  -> EmitterWriter {
+    pub fn stderr(
+        color_config: ColorConfig,
+        source_map: Option<Lrc<SourceMapperDyn>>,
+        short_message: bool,
+        teach: bool,
+        terminal_width: Option<usize>,
+    ) -> EmitterWriter {
         let dst = Destination::from_stderr(color_config);
         EmitterWriter {
             dst,
@@ -318,6 +323,7 @@ impl EmitterWriter {
             short_message,
             teach,
             ui_testing: false,
+            terminal_width,
         }
     }
 
@@ -327,6 +333,7 @@ impl EmitterWriter {
         short_message: bool,
         teach: bool,
         colored: bool,
+        terminal_width: Option<usize>,
     ) -> EmitterWriter {
         EmitterWriter {
             dst: Raw(dst, colored),
@@ -334,6 +341,7 @@ impl EmitterWriter {
             short_message,
             teach,
             ui_testing: false,
+            terminal_width,
         }
     }
 
@@ -1295,7 +1303,9 @@ impl EmitterWriter {
                     width_offset + annotated_file.multiline_depth + 1
                 };
 
-                let column_width = if self.ui_testing {
+                let column_width = if let Some(width) = self.terminal_width {
+                    width
+                } else if self.ui_testing {
                     140
                 } else {
                     term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 4018a667bf2..6585633e00a 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -383,7 +383,7 @@ impl Handler {
                                       cm: Option<Lrc<SourceMapperDyn>>,
                                       flags: HandlerFlags)
                                       -> Handler {
-        let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
+        let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false, None));
         Handler::with_emitter_and_flags(emitter, flags)
     }
 
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index 87381f224d0..98362464771 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
                     source_map.map(|cm| cm as _),
                     short,
                     sessopts.debugging_opts.teach,
+                    sessopts.debugging_opts.terminal_width,
                 ).ui_testing(ui_testing)
             )
         },
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs
index 83a8d3fc109..8db0eb15929 100644
--- a/src/librustdoc/test.rs
+++ b/src/librustdoc/test.rs
@@ -427,7 +427,7 @@ pub fn make_test(s: &str,
         // Any errors in parsing should also appear when the doctest is compiled for real, so just
         // send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
         let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
-        let emitter = EmitterWriter::new(box io::sink(), None, false, false, false);
+        let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None);
         // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
         let handler = Handler::with_emitter(false, None, box emitter);
         let sess = ParseSess::with_span_handler(handler, cm);
diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs
index 83c9c692bd3..ada46f7bc5a 100644
--- a/src/libsyntax/json.rs
+++ b/src/libsyntax/json.rs
@@ -219,7 +219,7 @@ impl Diagnostic {
         }
         let buf = BufWriter::default();
         let output = buf.clone();
-        je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false)
+        je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false, None)
             .ui_testing(je.ui_testing).emit_diagnostic(db);
         let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
         let output = String::from_utf8(output).unwrap();
diff --git a/src/libsyntax/parse/lexer/tests.rs b/src/libsyntax/parse/lexer/tests.rs
index a915aa42fd1..963ad2c0b8f 100644
--- a/src/libsyntax/parse/lexer/tests.rs
+++ b/src/libsyntax/parse/lexer/tests.rs
@@ -10,7 +10,14 @@ use errors::{Handler, emitter::EmitterWriter};
 use syntax_pos::{BytePos, Span};
 
 fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
-    let emitter = EmitterWriter::new(Box::new(io::sink()), Some(sm.clone()), false, false, false);
+    let emitter = errors::emitter::EmitterWriter::new(
+        Box::new(io::sink()),
+        Some(sm.clone()),
+        false,
+        false,
+        false,
+        None,
+    );
     ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
 }
 
diff --git a/src/libsyntax/tests.rs b/src/libsyntax/tests.rs
index 4c0e1e3704d..c472212bc20 100644
--- a/src/libsyntax/tests.rs
+++ b/src/libsyntax/tests.rs
@@ -144,11 +144,14 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
             println!("text: {:?}", source_map.span_to_snippet(span));
         }
 
-        let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
-                                        Some(source_map.clone()),
-                                        false,
-                                        false,
-                                        false);
+        let emitter = EmitterWriter::new(
+            Box::new(Shared { data: output.clone() }),
+            Some(source_map.clone()),
+            false,
+            false,
+            false,
+            None,
+        );
         let handler = Handler::with_emitter(true, None, Box::new(emitter));
         handler.span_err(msp, "foo");