about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2014-12-11 01:48:23 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-01-08 13:40:50 +0530
commit0bd022c893b00e0bb76d84bbbf8ccf7f685aad9c (patch)
tree2661376204e573d7c1e6251f30c70d2a33edfe6d /src/libsyntax
parentc41cafb10c3e1cd5063bcacd663d0fc17fddc8c3 (diff)
downloadrust-0bd022c893b00e0bb76d84bbbf8ccf7f685aad9c.tar.gz
rust-0bd022c893b00e0bb76d84bbbf8ccf7f685aad9c.zip
libsyntax: add COMMAND_LINE_SP and use it for spans generated from the command line
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs7
-rw-r--r--src/libsyntax/diagnostic.rs20
2 files changed, 21 insertions, 6 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index d1768867f0d..9a422e17bb4 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -105,6 +105,11 @@ pub struct Span {
 
 pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION };
 
+// Generic span to be used for code originating from the command line
+pub const COMMAND_LINE_SP: Span = Span { lo: BytePos(0),
+                                         hi: BytePos(0),
+                                         expn_id: COMMAND_LINE_EXPN };
+
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
 pub struct Spanned<T> {
     pub node: T,
@@ -235,6 +240,8 @@ pub struct ExpnInfo {
 pub struct ExpnId(u32);
 
 pub const NO_EXPANSION: ExpnId = ExpnId(-1);
+// For code appearing from the command line
+pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(-2);
 
 impl ExpnId {
     pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index 7e57709f33d..64fdb61f2ec 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -13,7 +13,7 @@ pub use self::RenderSpan::*;
 pub use self::ColorConfig::*;
 use self::Destination::*;
 
-use codemap::{Pos, Span};
+use codemap::{COMMAND_LINE_SP, Pos, Span};
 use codemap;
 use diagnostics;
 
@@ -368,6 +368,9 @@ impl Emitter for EmitterWriter {
             cmsp: Option<(&codemap::CodeMap, Span)>,
             msg: &str, code: Option<&str>, lvl: Level) {
         let error = match cmsp {
+            Some((cm, COMMAND_LINE_SP)) => emit(self, cm,
+                                                FileLine(COMMAND_LINE_SP),
+                                                msg, code, lvl, false),
             Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, code, lvl, false),
             None => print_diagnostic(self, "", lvl, msg, code),
         };
@@ -390,8 +393,11 @@ impl Emitter for EmitterWriter {
 fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
         msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::IoResult<()> {
     let sp = rsp.span();
-    let ss = cm.span_to_string(sp);
-    let lines = cm.span_to_lines(sp);
+    let ss = if sp == COMMAND_LINE_SP {
+        "<command line option>".to_string()
+    } else {
+        cm.span_to_string(sp)
+    };
     if custom {
         // we want to tell compiletest/runtest to look at the last line of the
         // span (since `custom_highlight_lines` displays an arrow to the end of
@@ -400,15 +406,17 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
         let ses = cm.span_to_string(span_end);
         try!(print_diagnostic(dst, &ses[], lvl, msg, code));
         if rsp.is_full_span() {
-            try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
+            try!(custom_highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
         }
     } else {
         try!(print_diagnostic(dst, &ss[], lvl, msg, code));
         if rsp.is_full_span() {
-            try!(highlight_lines(dst, cm, sp, lvl, lines));
+            try!(highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
         }
     }
-    try!(print_macro_backtrace(dst, cm, sp));
+    if sp != COMMAND_LINE_SP {
+        try!(print_macro_backtrace(dst, cm, sp));
+    }
     match code {
         Some(code) =>
             match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) {