summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-04 21:06:34 -0700
committerbors <bors@rust-lang.org>2014-04-04 21:06:34 -0700
commit339d4002617d5b36d6125d8a1781a6ada2e0a3f8 (patch)
treeb7d7ca0b968561e2a70fa6bf39fd9ab62ad968b9 /src/libsyntax
parent4cf8d8ce69c1d1d10e90b04230d4c4e8dbb67bcc (diff)
parentf4cde4eddc04733da478ae1030ebc1ddeec04d80 (diff)
downloadrust-339d4002617d5b36d6125d8a1781a6ada2e0a3f8.tar.gz
rust-339d4002617d5b36d6125d8a1781a6ada2e0a3f8.zip
auto merge of #13284 : pnkfelix/rust/more-fs-info-on-crate-mismatch, r=alexcrichton
Fix #13266.

There is a little bit of acrobatics in the definition of `crate_paths`
to avoid calling `clone()` on the dylib/rlib unless we actually are
going to need them.

The other oddity is that I have replaced the `root_ident: Option<&str>`
parameter with a `root: &Option<CratePaths>`, which may surprise one
who was expecting to see something like: `root: Option<&CratePaths>`.
I went with the approach here because I could not come up with code for
the alternative that was acceptable to the borrow checker.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic.rs50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index fb0f458b88a..e3514b6f3f3 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -20,11 +20,37 @@ use term;
 // maximum number of lines we will print for each error; arbitrary.
 static MAX_LINES: uint = 6u;
 
+#[deriving(Clone)]
+pub enum RenderSpan {
+    /// A FullSpan renders with both with an initial line for the
+    /// message, prefixed by file:linenum, followed by a summary of
+    /// the source code covered by the span.
+    FullSpan(Span),
+
+    /// A FileLine renders with just a line for the message prefixed
+    /// by file:linenum.
+    FileLine(Span),
+}
+
+impl RenderSpan {
+    fn span(self) -> Span {
+        match self {
+            FullSpan(s) | FileLine(s) => s
+        }
+    }
+    fn is_full_span(&self) -> bool {
+        match self {
+            &FullSpan(..) => true,
+            &FileLine(..) => false,
+        }
+    }
+}
+
 pub trait Emitter {
     fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>,
             msg: &str, lvl: Level);
     fn custom_emit(&mut self, cm: &codemap::CodeMap,
-                   sp: Span, msg: &str, lvl: Level);
+                   sp: RenderSpan, msg: &str, lvl: Level);
 }
 
 /// This structure is used to signify that a task has failed with a fatal error
@@ -60,7 +86,10 @@ impl SpanHandler {
         self.handler.emit(Some((&self.cm, sp)), msg, Note);
     }
     pub fn span_end_note(&self, sp: Span, msg: &str) {
-        self.handler.custom_emit(&self.cm, sp, msg, Note);
+        self.handler.custom_emit(&self.cm, FullSpan(sp), msg, Note);
+    }
+    pub fn fileline_note(&self, sp: Span, msg: &str) {
+        self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note);
     }
     pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
         self.handler.emit(Some((&self.cm, sp)), msg, Bug);
@@ -132,7 +161,7 @@ impl Handler {
         self.emit.borrow_mut().emit(cmsp, msg, lvl);
     }
     pub fn custom_emit(&self, cm: &codemap::CodeMap,
-                       sp: Span, msg: &str, lvl: Level) {
+                       sp: RenderSpan, msg: &str, lvl: Level) {
         self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
     }
 }
@@ -258,7 +287,7 @@ impl Emitter for EmitterWriter {
             msg: &str,
             lvl: Level) {
         let error = match cmsp {
-            Some((cm, sp)) => emit(self, cm, sp, msg, lvl, false),
+            Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, lvl, false),
             None => print_diagnostic(self, "", lvl, msg),
         };
 
@@ -269,7 +298,7 @@ impl Emitter for EmitterWriter {
     }
 
     fn custom_emit(&mut self, cm: &codemap::CodeMap,
-                   sp: Span, msg: &str, lvl: Level) {
+                   sp: RenderSpan, msg: &str, lvl: Level) {
         match emit(self, cm, sp, msg, lvl, true) {
             Ok(()) => {}
             Err(e) => fail!("failed to print diagnostics: {}", e),
@@ -277,8 +306,9 @@ impl Emitter for EmitterWriter {
     }
 }
 
-fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span,
+fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
         msg: &str, lvl: Level, custom: bool) -> io::IoResult<()> {
+    let sp = rsp.span();
     let ss = cm.span_to_str(sp);
     let lines = cm.span_to_lines(sp);
     if custom {
@@ -288,10 +318,14 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span,
         let span_end = Span { lo: sp.hi, hi: sp.hi, expn_info: sp.expn_info};
         let ses = cm.span_to_str(span_end);
         try!(print_diagnostic(dst, ses, lvl, msg));
-        try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
+        if rsp.is_full_span() {
+            try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
+        }
     } else {
         try!(print_diagnostic(dst, ss, lvl, msg));
-        try!(highlight_lines(dst, cm, sp, lvl, lines));
+        if rsp.is_full_span() {
+            try!(highlight_lines(dst, cm, sp, lvl, lines));
+        }
     }
     print_macro_backtrace(dst, cm, sp)
 }