Make -Z terminal-width opt-in.

This commit modifies the parsing of `-Z terminal-width` so that it can
optionally take a value and only uses `accurate_err_width` when the user
does not provide a value - therefore making the emission of `-Z
terminal-width` opt-in.

Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
David Wood 2020-06-30 20:29:09 +01:00
parent c46b9a70bd
commit 6d740aa2e6
No known key found for this signature in database
GPG Key ID: 2592E76C87381FD9
2 changed files with 14 additions and 7 deletions

View File

@ -720,11 +720,18 @@ fn add_error_format_and_color(
cmd.arg(json);
if nightly_features_allowed() {
if let (Some(width), _) | (_, Some(width)) = (
cx.bcx.config.cli_unstable().terminal_width,
cx.bcx.config.shell().accurate_err_width(),
) {
cmd.arg(format!("-Zterminal-width={}", width));
let config = cx.bcx.config;
match (config.cli_unstable().terminal_width, config.shell().accurate_err_width()) {
// Terminal width explicitly provided - only useful for testing.
(Some(Some(width)), _) => {
cmd.arg(format!("-Zterminal-width={}", width));
}
// Terminal width was not explicitly provided but flag was provided - common case.
(Some(None), Some(width)) => {
cmd.arg(format!("-Zterminal-width={}", width));
}
// User didn't opt-in.
_ => (),
}
}

View File

@ -357,7 +357,7 @@ pub struct CliUnstable {
pub separate_nightlies: bool,
pub multitarget: bool,
pub rustdoc_map: bool,
pub terminal_width: Option<usize>,
pub terminal_width: Option<Option<usize>>,
}
impl CliUnstable {
@ -448,7 +448,7 @@ impl CliUnstable {
"separate-nightlies" => self.separate_nightlies = parse_empty(k, v)?,
"multitarget" => self.multitarget = parse_empty(k, v)?,
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
"terminal-width" => self.terminal_width = parse_usize_opt(v)?,
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
_ => bail!("unknown `-Z` flag specified: {}", k),
}