From 81bfdc83ca458eb330fc3afa6dfb38bfad4d4204 Mon Sep 17 00:00:00 2001 From: kennytm Date: Mon, 1 May 2017 15:27:36 +0800 Subject: Fix issue #41652. Don't print the source code in emit_message_default() and render_source_line() if the source code is None. --- src/librustc_errors/emitter.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 1a38018e1b3..53999eb9138 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -270,8 +270,10 @@ impl EmitterWriter { line: &Line, width_offset: usize, code_offset: usize) -> Vec<(usize, Style)> { - let source_string = file.get_line(line.line_index - 1) - .unwrap_or(""); + let source_string = match file.get_line(line.line_index - 1) { + Some(s) => s, + None => return Vec::new(), + }; let line_offset = buffer.num_lines(); @@ -909,6 +911,11 @@ impl EmitterWriter { // Print out the annotate source lines that correspond with the error for annotated_file in annotated_files { + // we can't annotate anything if the source is unavailable. + if annotated_file.file.src.is_none() { + continue; + } + // print out the span location and spacer before we print the annotated source // to do this, we need to know if this span will be primary let is_primary = primary_lo.file.name == annotated_file.file.name; -- cgit 1.4.1-3-g733a5