about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-05-01 15:27:36 +0800
committerkennytm <kennytm@gmail.com>2017-05-03 13:00:33 +0800
commit81bfdc83ca458eb330fc3afa6dfb38bfad4d4204 (patch)
tree198291fa0e5c53c541f249784bb9e3d46f93c450 /src
parent0634f0a30f94116ee13c16fb1a35c4c92253ab13 (diff)
downloadrust-81bfdc83ca458eb330fc3afa6dfb38bfad4d4204.tar.gz
rust-81bfdc83ca458eb330fc3afa6dfb38bfad4d4204.zip
Fix issue #41652.
Don't print the source code in emit_message_default() and
render_source_line() if the source code is None.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/emitter.rs11
-rw-r--r--src/test/ui/issue-41652/auxiliary/issue_41652_b.rs16
-rw-r--r--src/test/ui/issue-41652/issue_41652.rs26
-rw-r--r--src/test/ui/issue-41652/issue_41652.stderr12
4 files changed, 63 insertions, 2 deletions
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;
diff --git a/src/test/ui/issue-41652/auxiliary/issue_41652_b.rs b/src/test/ui/issue-41652/auxiliary/issue_41652_b.rs
new file mode 100644
index 00000000000..0b714432f16
--- /dev/null
+++ b/src/test/ui/issue-41652/auxiliary/issue_41652_b.rs
@@ -0,0 +1,16 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Tr {
+    // Note: The function needs to be declared over multiple lines to reproduce
+    // the crash. DO NOT reformat.
+    fn f()
+        where Self: Sized;
+}
diff --git a/src/test/ui/issue-41652/issue_41652.rs b/src/test/ui/issue-41652/issue_41652.rs
new file mode 100644
index 00000000000..1874ee6cd3a
--- /dev/null
+++ b/src/test/ui/issue-41652/issue_41652.rs
@@ -0,0 +1,26 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue_41652_b.rs
+
+extern crate issue_41652_b;
+
+struct S;
+
+impl issue_41652_b::Tr for S {
+    fn f() {
+        3.f()
+        //~^ ERROR no method named `f` found for type `{integer}` in the current scope
+        //~| NOTE found the following associated functions
+        //~| NOTE candidate #1 is defined in the trait `issue_41652_b::Tr`
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/issue-41652/issue_41652.stderr b/src/test/ui/issue-41652/issue_41652.stderr
new file mode 100644
index 00000000000..4d33a99f6a3
--- /dev/null
+++ b/src/test/ui/issue-41652/issue_41652.stderr
@@ -0,0 +1,12 @@
+error: no method named `f` found for type `{integer}` in the current scope
+  --> $DIR/issue_41652.rs:19:11
+   |
+19 |         3.f()
+   |           ^
+   |
+   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
+note: candidate #1 is defined in the trait `issue_41652_b::Tr`
+   = help: to disambiguate the method call, write `issue_41652_b::Tr::f(3)` instead
+
+error: aborting due to previous error
+