Skip to content

Commit

Permalink
Auto merge of #63402 - estebank:strip-margin, r=oli-obk
Browse files Browse the repository at this point in the history
Strip code to the left and right in diagnostics for long lines

Fix #62999.
  • Loading branch information
bors committed Aug 30, 2019
2 parents c7d4df0 + aaf4dc3 commit 19a38de
Show file tree
Hide file tree
Showing 26 changed files with 580 additions and 156 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,7 @@ dependencies = [
"rustc_data_structures",
"serialize",
"syntax_pos",
"term_size",
"termcolor",
"unicode-width",
]
Expand Down Expand Up @@ -4107,6 +4108,17 @@ dependencies = [
"winapi 0.3.6",
]

[[package]]
name = "term_size"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327"
dependencies = [
"kernel32-sys",
"libc",
"winapi 0.2.8",
]

[[package]]
name = "termcolor"
version = "1.0.4"
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,13 +1055,15 @@ fn default_emitter(
Some(source_map.clone()),
short,
sopts.debugging_opts.teach,
sopts.debugging_opts.terminal_width,
),
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
None, // no terminal width
),
};
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,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
Expand Down
1 change: 1 addition & 0 deletions src/librustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.6.1"
term_size = "0.3.1"
Loading

0 comments on commit 19a38de

Please sign in to comment.