Skip to content

Commit 11a3584

Browse files
committed
emitter: column width defaults to 140
This commit modifies the column width computation in the emitter when `termize::dimensions` returns `None` so that it uses the default value of 140 (which is used in UI testing currently) instead of `usize::MAX` which just ends up causing overflows in later computations. This is hard to test but appears to produce the same output as using saturating functions instead. Signed-off-by: David Wood <[email protected]>
1 parent 67100f6 commit 11a3584

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/librustc_errors/emitter.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use std::path::Path;
3131
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
3232
use termcolor::{Buffer, Color, WriteColor};
3333

34+
/// Default column width, used in tests and when terminal dimensions cannot be determined.
35+
const DEFAULT_COLUMN_WIDTH: usize = 140;
36+
3437
/// Describes the way the content of the `rendered` field of the json output is generated
3538
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3639
pub enum HumanReadableErrorType {
@@ -74,7 +77,8 @@ struct Margin {
7477
pub computed_left: usize,
7578
/// The end of the line to be displayed.
7679
pub computed_right: usize,
77-
/// The current width of the terminal. 140 by default and in tests.
80+
/// The current width of the terminal. Uses value of `DEFAULT_COLUMN_WIDTH` constant by default
81+
/// and in tests.
7882
pub column_width: usize,
7983
/// The end column of a span label, including the span. Doesn't account for labels not in the
8084
/// same line as the span.
@@ -1414,11 +1418,11 @@ impl EmitterWriter {
14141418
let column_width = if let Some(width) = self.terminal_width {
14151419
width.saturating_sub(code_offset)
14161420
} else if self.ui_testing {
1417-
140
1421+
DEFAULT_COLUMN_WIDTH
14181422
} else {
14191423
termize::dimensions()
14201424
.map(|(w, _)| w.saturating_sub(code_offset))
1421-
.unwrap_or(usize::MAX)
1425+
.unwrap_or(DEFAULT_COLUMN_WIDTH)
14221426
};
14231427

14241428
let margin = Margin::new(

0 commit comments

Comments
 (0)