about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-07-25 15:59:38 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-07-25 16:06:24 -0700
commiteeb1bd18dc172c2ba80c116d711214c2cdac3e32 (patch)
treebe6aee3b26371df55302ed69492f5b97abb2fa0f /src/librustc_errors
parent03f19f7ff128a3b01eeab3f87f04cce22883f006 (diff)
downloadrust-eeb1bd18dc172c2ba80c116d711214c2cdac3e32.tar.gz
rust-eeb1bd18dc172c2ba80c116d711214c2cdac3e32.zip
Avoid ICE when suggestion span is at Eof
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/lib.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 3269b85d0dd..67fae1f6769 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -229,7 +229,8 @@ impl CodeSuggestion {
                         }
                     }
                     if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
-                        buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
+                        let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
+                        buf.push_str(&cur_line[..end]);
                     }
                 }
                 buf.push_str(&part.snippet);