diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 1456ff3ac..404459565 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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. + _ => (), } } diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index bdcd24929..47d5f9cd9 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -357,7 +357,7 @@ pub struct CliUnstable { pub separate_nightlies: bool, pub multitarget: bool, pub rustdoc_map: bool, - pub terminal_width: Option, + pub terminal_width: Option>, } 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), }