Skip to content

Commit 0e36558

Browse files
authored
Rollup merge of rust-lang#68611 - MichaelBurge:master, r=estebank
Correct ICE caused by macros generating invalid spans. Closes rust-lang#68605
2 parents 288cabd + 79d8c9b commit 0e36558

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/librustc_errors/emitter.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle,
2020
};
2121

22+
use log::*;
2223
use rustc_data_structures::fx::FxHashMap;
2324
use rustc_data_structures::sync::Lrc;
2425
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> {
21082109
/// Whether the original and suggested code are visually similar enough to warrant extra wording.
21092110
pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
21102111
// FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.
2111-
let found = sm.span_to_snippet(sp).unwrap();
2112+
let found = match sm.span_to_snippet(sp) {
2113+
Ok(snippet) => snippet,
2114+
Err(e) => {
2115+
warn!("Invalid span {:?}. Err={:?}", sp, e);
2116+
return false;
2117+
}
2118+
};
21122119
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
21132120
// All the chars that differ in capitalization are confusable (above):
21142121
let confusable = found

0 commit comments

Comments
 (0)