about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-09-01 11:39:26 +0200
committerGitHub <noreply@github.com>2019-09-01 11:39:26 +0200
commitbccf49ffc824fa55d8e60c4ff1868bb105c096e5 (patch)
tree94750b71958e60e4313c3629ef194d28cd43717a /src
parent064b7041c509d5004a5e7b027f56202e1eb13167 (diff)
parent84567190e0d36f9a61f9bc833bd9fa559aeb0089 (diff)
downloadrust-bccf49ffc824fa55d8e60c4ff1868bb105c096e5.tar.gz
rust-bccf49ffc824fa55d8e60c4ff1868bb105c096e5.zip
Rollup merge of #64029 - estebank:fix-miri, r=RalfJung
Account for rounding errors when deciding the diagnostic boundaries

Fix Miri by fixing the bug raised in https://github.com/rust-lang/rust/pull/63402#discussion_r319485328.

Fixes https://github.com/rust-lang/rust/issues/64020
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/emitter.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 77d373e7a8c..a0ce761cfa2 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -146,12 +146,12 @@ impl Margin {
             } else if self.label_right - self.span_left <= self.column_width {
                 // Attempt to fit the code window considering only the spans and labels.
                 let padding_left = (self.column_width - (self.label_right - self.span_left)) / 2;
-                self.computed_left = self.span_left - padding_left;
+                self.computed_left = self.span_left.saturating_sub(padding_left);
                 self.computed_right = self.computed_left + self.column_width;
             } else if self.span_right - self.span_left <= self.column_width {
                 // Attempt to fit the code window considering the spans and labels plus padding.
                 let padding_left = (self.column_width - (self.span_right - self.span_left)) / 5 * 2;
-                self.computed_left = self.span_left - padding_left;
+                self.computed_left = self.span_left.saturating_sub(padding_left);
                 self.computed_right = self.computed_left + self.column_width;
             } else { // Mostly give up but still don't show the full line.
                 self.computed_left = self.span_left;
@@ -1304,11 +1304,13 @@ impl EmitterWriter {
                 };
 
                 let column_width = if let Some(width) = self.terminal_width {
-                    width
+                    width.saturating_sub(code_offset)
                 } else if self.ui_testing {
                     140
                 } else {
-                    term_size::dimensions().map(|(w, _)| w - code_offset).unwrap_or(140)
+                    term_size::dimensions()
+                        .map(|(w, _)| w.saturating_sub(code_offset))
+                        .unwrap_or(std::usize::MAX)
                 };
 
                 let margin = Margin::new(