Skip to content

Commit 21f2e93

Browse files
committed
Add terminal_width debugging flag
1 parent 9980796 commit 21f2e93

File tree

10 files changed

+50
-23
lines changed

10 files changed

+50
-23
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12921292
"show macro backtraces even for non-local macros"),
12931293
teach: bool = (false, parse_bool, [TRACKED],
12941294
"show extended diagnostic help"),
1295+
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
1296+
"set the current terminal width"),
12951297
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
12961298
"attempt to recover from parse errors (experimental)"),
12971299
dep_tasks: bool = (false, parse_bool, [UNTRACKED],

src/librustc/session/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,15 @@ fn default_emitter(
10551055
Some(source_map.clone()),
10561056
short,
10571057
sopts.debugging_opts.teach,
1058+
sopts.debugging_opts.terminal_width,
10581059
),
10591060
Some(dst) => EmitterWriter::new(
10601061
dst,
10611062
Some(source_map.clone()),
10621063
short,
10631064
false, // no teach messages when writing to a buffer
10641065
false, // no colors when writing to a buffer
1066+
None, // no terminal width
10651067
),
10661068
};
10671069
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
@@ -1375,7 +1377,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
13751377
let emitter: Box<dyn Emitter + sync::Send> = match output {
13761378
config::ErrorOutputType::HumanReadable(kind) => {
13771379
let (short, color_config) = kind.unzip();
1378-
Box::new(EmitterWriter::stderr(color_config, None, short, false))
1380+
Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
13791381
}
13801382
config::ErrorOutputType::Json { pretty, json_rendered } =>
13811383
Box::new(JsonEmitter::basic(pretty, json_rendered)),
@@ -1389,7 +1391,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
13891391
let emitter: Box<dyn Emitter + sync::Send> = match output {
13901392
config::ErrorOutputType::HumanReadable(kind) => {
13911393
let (short, color_config) = kind.unzip();
1392-
Box::new(EmitterWriter::stderr(color_config, None, short, false))
1394+
Box::new(EmitterWriter::stderr(color_config, None, short, false, None))
13931395
}
13941396
config::ErrorOutputType::Json { pretty, json_rendered } =>
13951397
Box::new(JsonEmitter::basic(pretty, json_rendered)),

src/librustc_driver/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,13 @@ pub fn report_ices_to_stderr_if_any<F: FnOnce() -> R, R>(f: F) -> Result<R, Erro
11351135
// Thread panicked without emitting a fatal diagnostic
11361136
eprintln!("");
11371137

1138-
let emitter =
1139-
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
1140-
None,
1141-
false,
1142-
false));
1138+
let emitter = Box::new(errors::emitter::EmitterWriter::stderr(
1139+
errors::ColorConfig::Auto,
1140+
None,
1141+
false,
1142+
false,
1143+
None,
1144+
));
11431145
let handler = errors::Handler::with_emitter(true, None, emitter);
11441146

11451147
// a .span_bug or .bug call has already printed what

src/librustc_errors/emitter.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ impl HumanReadableErrorType {
5151
dst: Box<dyn Write + Send>,
5252
source_map: Option<Lrc<SourceMapperDyn>>,
5353
teach: bool,
54+
terminal_width: Option<usize>,
5455
) -> EmitterWriter {
5556
let (short, color_config) = self.unzip();
56-
EmitterWriter::new(dst, source_map, short, teach, color_config.suggests_using_colors())
57+
let color = color_config.suggests_using_colors();
58+
EmitterWriter::new(dst, source_map, short, teach, color, terminal_width)
5759
}
5860
}
5961

@@ -296,6 +298,7 @@ pub struct EmitterWriter {
296298
short_message: bool,
297299
teach: bool,
298300
ui_testing: bool,
301+
terminal_width: Option<usize>,
299302
}
300303

301304
#[derive(Debug)]
@@ -306,18 +309,21 @@ pub struct FileWithAnnotatedLines {
306309
}
307310

308311
impl EmitterWriter {
309-
pub fn stderr(color_config: ColorConfig,
310-
source_map: Option<Lrc<SourceMapperDyn>>,
311-
short_message: bool,
312-
teach: bool)
313-
-> EmitterWriter {
312+
pub fn stderr(
313+
color_config: ColorConfig,
314+
source_map: Option<Lrc<SourceMapperDyn>>,
315+
short_message: bool,
316+
teach: bool,
317+
terminal_width: Option<usize>,
318+
) -> EmitterWriter {
314319
let dst = Destination::from_stderr(color_config);
315320
EmitterWriter {
316321
dst,
317322
sm: source_map,
318323
short_message,
319324
teach,
320325
ui_testing: false,
326+
terminal_width,
321327
}
322328
}
323329

@@ -327,13 +333,15 @@ impl EmitterWriter {
327333
short_message: bool,
328334
teach: bool,
329335
colored: bool,
336+
terminal_width: Option<usize>,
330337
) -> EmitterWriter {
331338
EmitterWriter {
332339
dst: Raw(dst, colored),
333340
sm: source_map,
334341
short_message,
335342
teach,
336343
ui_testing: false,
344+
terminal_width,
337345
}
338346
}
339347

@@ -1295,7 +1303,9 @@ impl EmitterWriter {
12951303
width_offset + annotated_file.multiline_depth + 1
12961304
};
12971305

1298-
let column_width = if self.ui_testing {
1306+
let column_width = if let Some(width) = self.terminal_width {
1307+
width
1308+
} else if self.ui_testing {
12991309
140
13001310
} else {
13011311
term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl Handler {
383383
cm: Option<Lrc<SourceMapperDyn>>,
384384
flags: HandlerFlags)
385385
-> Handler {
386-
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
386+
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false, None));
387387
Handler::with_emitter_and_flags(emitter, flags)
388388
}
389389

src/librustdoc/core.rs

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
193193
source_map.map(|cm| cm as _),
194194
short,
195195
sessopts.debugging_opts.teach,
196+
sessopts.debugging_opts.terminal_width,
196197
).ui_testing(ui_testing)
197198
)
198199
},

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub fn make_test(s: &str,
427427
// Any errors in parsing should also appear when the doctest is compiled for real, so just
428428
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
429429
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
430-
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false);
430+
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None);
431431
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
432432
let handler = Handler::with_emitter(false, None, box emitter);
433433
let sess = ParseSess::with_span_handler(handler, cm);

src/libsyntax/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Diagnostic {
219219
}
220220
let buf = BufWriter::default();
221221
let output = buf.clone();
222-
je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false)
222+
je.json_rendered.new_emitter(Box::new(buf), Some(je.sm.clone()), false, None)
223223
.ui_testing(je.ui_testing).emit_diagnostic(db);
224224
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
225225
let output = String::from_utf8(output).unwrap();

src/libsyntax/parse/lexer/tests.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ use errors::{Handler, emitter::EmitterWriter};
1010
use syntax_pos::{BytePos, Span};
1111

1212
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
13-
let emitter = EmitterWriter::new(Box::new(io::sink()), Some(sm.clone()), false, false, false);
13+
let emitter = errors::emitter::EmitterWriter::new(
14+
Box::new(io::sink()),
15+
Some(sm.clone()),
16+
false,
17+
false,
18+
false,
19+
None,
20+
);
1421
ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
1522
}
1623

src/libsyntax/tests.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,14 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
144144
println!("text: {:?}", source_map.span_to_snippet(span));
145145
}
146146

147-
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
148-
Some(source_map.clone()),
149-
false,
150-
false,
151-
false);
147+
let emitter = EmitterWriter::new(
148+
Box::new(Shared { data: output.clone() }),
149+
Some(source_map.clone()),
150+
false,
151+
false,
152+
false,
153+
None,
154+
);
152155
let handler = Handler::with_emitter(true, None, Box::new(emitter));
153156
handler.span_err(msp, "foo");
154157

0 commit comments

Comments
 (0)