about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Burge <michaelburge@pobox.com>2020-01-28 10:57:03 -0800
committerMichael Burge <michaelburge@pobox.com>2020-01-28 11:02:22 -0800
commit79d8c9beab960e81c73788208da4bbd39137d85b (patch)
tree6d63954711f2e24b6394cb0d53ba9d96bdd12559 /src
parentb181835a6bacfa449f55d46764a10e25d1c471dc (diff)
downloadrust-79d8c9beab960e81c73788208da4bbd39137d85b.tar.gz
rust-79d8c9beab960e81c73788208da4bbd39137d85b.zip
Correct ICE caused by macros generating invalid spans.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/emitter.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index bf660d188b2..7ef623807d0 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -19,6 +19,7 @@ use crate::{
     pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle,
 };
 
+use log::*;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::Lrc;
 use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> {
 /// Whether the original and suggested code are visually similar enough to warrant extra wording.
 pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
     // FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.
-    let found = sm.span_to_snippet(sp).unwrap();
+    let found = match sm.span_to_snippet(sp) {
+        Ok(snippet) => snippet,
+        Err(e) => {
+            warn!("Invalid span {:?}. Err={:?}", sp, e);
+            return false;
+        }
+    };
     let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
     // All the chars that differ in capitalization are confusable (above):
     let confusable = found