2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
use codemap::{Pos, Span};
|
2012-12-23 16:41:37 -06:00
|
|
|
use codemap;
|
|
|
|
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io;
|
2013-07-11 02:56:26 -05:00
|
|
|
use std::local_data;
|
2013-05-18 14:39:17 -05:00
|
|
|
use extra::term;
|
2012-01-13 18:05:58 -06:00
|
|
|
|
2013-10-21 14:10:57 -05:00
|
|
|
static BUG_REPORT_URL: &'static str =
|
|
|
|
"https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report";
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
pub trait Emitter {
|
|
|
|
fn emit(&self,
|
|
|
|
cmsp: Option<(@codemap::CodeMap, Span)>,
|
|
|
|
msg: &str,
|
|
|
|
lvl: level);
|
|
|
|
}
|
2012-01-13 21:00:09 -06:00
|
|
|
|
2013-02-11 15:36:24 -06:00
|
|
|
// a handler deals with errors; certain errors
|
|
|
|
// (fatal, bug, unimpl) may cause immediate exit,
|
|
|
|
// others log errors for later reporting.
|
2013-01-29 15:54:06 -06:00
|
|
|
pub trait handler {
|
2013-02-04 16:02:01 -06:00
|
|
|
fn fatal(@mut self, msg: &str) -> !;
|
|
|
|
fn err(@mut self, msg: &str);
|
|
|
|
fn bump_err_count(@mut self);
|
2013-05-06 08:00:37 -05:00
|
|
|
fn err_count(@mut self) -> uint;
|
2013-02-04 16:02:01 -06:00
|
|
|
fn has_errors(@mut self) -> bool;
|
|
|
|
fn abort_if_errors(@mut self);
|
|
|
|
fn warn(@mut self, msg: &str);
|
|
|
|
fn note(@mut self, msg: &str);
|
2013-02-11 15:36:24 -06:00
|
|
|
// used to indicate a bug in the compiler:
|
2013-02-04 16:02:01 -06:00
|
|
|
fn bug(@mut self, msg: &str) -> !;
|
|
|
|
fn unimpl(@mut self, msg: &str) -> !;
|
|
|
|
fn emit(@mut self,
|
2013-08-31 11:13:04 -05:00
|
|
|
cmsp: Option<(@codemap::CodeMap, Span)>,
|
2013-02-04 16:02:01 -06:00
|
|
|
msg: &str,
|
|
|
|
lvl: level);
|
|
|
|
}
|
|
|
|
|
2013-02-11 15:36:24 -06:00
|
|
|
// a span-handler is like a handler but also
|
|
|
|
// accepts span information for source-location
|
|
|
|
// reporting.
|
|
|
|
pub trait span_handler {
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_fatal(@mut self, sp: Span, msg: &str) -> !;
|
|
|
|
fn span_err(@mut self, sp: Span, msg: &str);
|
|
|
|
fn span_warn(@mut self, sp: Span, msg: &str);
|
|
|
|
fn span_note(@mut self, sp: Span, msg: &str);
|
|
|
|
fn span_bug(@mut self, sp: Span, msg: &str) -> !;
|
|
|
|
fn span_unimpl(@mut self, sp: Span, msg: &str) -> !;
|
2013-08-11 12:23:40 -05:00
|
|
|
fn handler(@mut self) -> @mut handler;
|
2013-02-11 15:36:24 -06:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
struct HandlerT {
|
|
|
|
err_count: uint,
|
2013-08-29 20:34:09 -05:00
|
|
|
emit: @Emitter,
|
2013-02-04 16:02:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CodemapT {
|
2013-08-11 12:23:40 -05:00
|
|
|
handler: @mut handler,
|
2013-01-17 10:55:28 -06:00
|
|
|
cm: @codemap::CodeMap,
|
|
|
|
}
|
2012-01-13 19:03:51 -06:00
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl span_handler for CodemapT {
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_fatal(@mut self, sp: Span, msg: &str) -> ! {
|
2012-08-20 14:23:37 -05:00
|
|
|
self.handler.emit(Some((self.cm, sp)), msg, fatal);
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!();
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_err(@mut self, sp: Span, msg: &str) {
|
2012-08-20 14:23:37 -05:00
|
|
|
self.handler.emit(Some((self.cm, sp)), msg, error);
|
2012-01-24 23:42:54 -06:00
|
|
|
self.handler.bump_err_count();
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_warn(@mut self, sp: Span, msg: &str) {
|
2013-04-22 19:47:49 -05:00
|
|
|
self.handler.emit(Some((self.cm, sp)), msg, warning);
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_note(@mut self, sp: Span, msg: &str) {
|
2012-08-20 14:23:37 -05:00
|
|
|
self.handler.emit(Some((self.cm, sp)), msg, note);
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_bug(@mut self, sp: Span, msg: &str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_fatal(sp, ice_msg(msg));
|
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
fn span_unimpl(@mut self, sp: Span, msg: &str) -> ! {
|
2012-07-14 00:57:48 -05:00
|
|
|
self.span_bug(sp, ~"unimplemented " + msg);
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
2013-08-11 12:23:40 -05:00
|
|
|
fn handler(@mut self) -> @mut handler {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.handler
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl handler for HandlerT {
|
2013-02-04 16:02:01 -06:00
|
|
|
fn fatal(@mut self, msg: &str) -> ! {
|
2013-08-29 20:34:09 -05:00
|
|
|
self.emit.emit(None, msg, fatal);
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!();
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn err(@mut self, msg: &str) {
|
2013-08-29 20:34:09 -05:00
|
|
|
self.emit.emit(None, msg, error);
|
2012-01-25 01:07:16 -06:00
|
|
|
self.bump_err_count();
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn bump_err_count(@mut self) {
|
2012-01-13 19:03:51 -06:00
|
|
|
self.err_count += 1u;
|
|
|
|
}
|
2013-05-06 08:00:37 -05:00
|
|
|
fn err_count(@mut self) -> uint {
|
|
|
|
self.err_count
|
|
|
|
}
|
|
|
|
fn has_errors(@mut self) -> bool {
|
|
|
|
self.err_count > 0u
|
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn abort_if_errors(@mut self) {
|
2012-06-06 16:28:59 -05:00
|
|
|
let s;
|
2012-08-06 14:34:08 -05:00
|
|
|
match self.err_count {
|
2012-08-03 21:59:04 -05:00
|
|
|
0u => return,
|
|
|
|
1u => s = ~"aborting due to previous error",
|
|
|
|
_ => {
|
2013-09-27 23:01:58 -05:00
|
|
|
s = format!("aborting due to {} previous errors",
|
2012-08-22 19:24:52 -05:00
|
|
|
self.err_count);
|
2012-08-03 21:59:04 -05:00
|
|
|
}
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2012-06-06 16:28:59 -05:00
|
|
|
self.fatal(s);
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn warn(@mut self, msg: &str) {
|
2013-08-29 20:34:09 -05:00
|
|
|
self.emit.emit(None, msg, warning);
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn note(@mut self, msg: &str) {
|
2013-08-29 20:34:09 -05:00
|
|
|
self.emit.emit(None, msg, note);
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn bug(@mut self, msg: &str) -> ! {
|
2012-01-14 02:35:16 -06:00
|
|
|
self.fatal(ice_msg(msg));
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2013-02-04 16:02:01 -06:00
|
|
|
fn unimpl(@mut self, msg: &str) -> ! {
|
|
|
|
self.bug(~"unimplemented " + msg);
|
|
|
|
}
|
|
|
|
fn emit(@mut self,
|
2013-08-31 11:13:04 -05:00
|
|
|
cmsp: Option<(@codemap::CodeMap, Span)>,
|
2013-02-04 16:02:01 -06:00
|
|
|
msg: &str,
|
|
|
|
lvl: level) {
|
2013-08-29 20:34:09 -05:00
|
|
|
self.emit.emit(cmsp, msg, lvl);
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 15:54:06 -06:00
|
|
|
pub fn ice_msg(msg: &str) -> ~str {
|
2013-10-21 14:10:57 -05:00
|
|
|
format!("internal compiler error: {}\nThis message reflects a bug in the Rust compiler. \
|
|
|
|
\nWe would appreciate a bug report: {}", msg, BUG_REPORT_URL)
|
2012-01-14 02:35:16 -06:00
|
|
|
}
|
|
|
|
|
2013-08-11 12:23:40 -05:00
|
|
|
pub fn mk_span_handler(handler: @mut handler, cm: @codemap::CodeMap)
|
|
|
|
-> @mut span_handler {
|
2013-08-29 20:34:09 -05:00
|
|
|
@mut CodemapT {
|
|
|
|
handler: handler,
|
|
|
|
cm: cm,
|
|
|
|
} as @mut span_handler
|
2012-01-24 23:42:54 -06:00
|
|
|
}
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
pub fn mk_handler(emitter: Option<@Emitter>) -> @mut handler {
|
|
|
|
let emit: @Emitter = match emitter {
|
2013-02-04 16:02:01 -06:00
|
|
|
Some(e) => e,
|
2013-08-29 20:34:09 -05:00
|
|
|
None => @DefaultEmitter as @Emitter
|
2012-01-13 21:00:09 -06:00
|
|
|
};
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
@mut HandlerT {
|
|
|
|
err_count: 0,
|
|
|
|
emit: emit,
|
|
|
|
} as @mut handler
|
2012-01-13 19:03:51 -06:00
|
|
|
}
|
2012-01-13 18:05:58 -06:00
|
|
|
|
2013-03-20 10:52:45 -05:00
|
|
|
#[deriving(Eq)]
|
2013-01-29 15:54:06 -06:00
|
|
|
pub enum level {
|
2012-01-19 19:56:05 -06:00
|
|
|
fatal,
|
|
|
|
error,
|
|
|
|
warning,
|
|
|
|
note,
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn diagnosticstr(lvl: level) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match lvl {
|
2013-02-04 16:02:01 -06:00
|
|
|
fatal => ~"error",
|
|
|
|
error => ~"error",
|
|
|
|
warning => ~"warning",
|
|
|
|
note => ~"note"
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:38:32 -05:00
|
|
|
fn diagnosticcolor(lvl: level) -> term::color::Color {
|
2012-08-06 14:34:08 -05:00
|
|
|
match lvl {
|
2013-06-30 22:51:13 -05:00
|
|
|
fatal => term::color::BRIGHT_RED,
|
|
|
|
error => term::color::BRIGHT_RED,
|
|
|
|
warning => term::color::BRIGHT_YELLOW,
|
|
|
|
note => term::color::BRIGHT_GREEN
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 01:35:13 -05:00
|
|
|
fn print_maybe_styled(msg: &str, color: term::attr::Attr) {
|
2013-09-17 01:34:40 -05:00
|
|
|
local_data_key!(tls_terminal: @Option<term::Terminal>)
|
2013-07-11 02:56:26 -05:00
|
|
|
|
2013-10-13 20:48:47 -05:00
|
|
|
let stderr = @mut io::stderr() as @mut io::Writer;
|
|
|
|
fn is_stderr_screen() -> bool {
|
|
|
|
use std::libc;
|
|
|
|
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
|
|
|
|
}
|
2013-05-30 01:13:35 -05:00
|
|
|
|
2013-10-13 20:48:47 -05:00
|
|
|
if is_stderr_screen() {
|
2013-09-20 01:08:47 -05:00
|
|
|
let t = match local_data::get(tls_terminal, |v| v.map(|k| *k)) {
|
2013-07-11 02:56:26 -05:00
|
|
|
None => {
|
|
|
|
let t = term::Terminal::new(stderr);
|
|
|
|
let tls = @match t {
|
|
|
|
Ok(t) => Some(t),
|
|
|
|
Err(_) => None
|
|
|
|
};
|
|
|
|
local_data::set(tls_terminal, tls);
|
|
|
|
&*tls
|
|
|
|
}
|
|
|
|
Some(tls) => &*tls
|
|
|
|
};
|
2013-05-30 01:13:35 -05:00
|
|
|
|
2013-07-11 01:35:13 -05:00
|
|
|
match t {
|
2013-07-11 02:56:26 -05:00
|
|
|
&Some(ref term) => {
|
2013-07-11 01:35:13 -05:00
|
|
|
term.attr(color);
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(stderr, "{}", msg);
|
2013-05-30 18:14:40 -05:00
|
|
|
term.reset();
|
2013-07-11 01:35:13 -05:00
|
|
|
},
|
2013-10-13 20:48:47 -05:00
|
|
|
_ => write!(stderr, "{}", msg)
|
2013-07-11 01:35:13 -05:00
|
|
|
}
|
|
|
|
} else {
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(stderr, "{}", msg);
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:42:47 -05:00
|
|
|
fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
|
2013-10-13 20:48:47 -05:00
|
|
|
let mut stderr = io::stderr();
|
2013-06-19 06:42:47 -05:00
|
|
|
|
|
|
|
if !topic.is_empty() {
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(&mut stderr as &mut io::Writer, "{} ", topic);
|
2013-06-19 06:42:47 -05:00
|
|
|
}
|
|
|
|
|
2013-09-27 23:01:58 -05:00
|
|
|
print_maybe_styled(format!("{}: ", diagnosticstr(lvl)),
|
2013-07-11 01:35:13 -05:00
|
|
|
term::attr::ForegroundColor(diagnosticcolor(lvl)));
|
2013-09-27 23:01:58 -05:00
|
|
|
print_maybe_styled(format!("{}\n", msg), term::attr::Bold);
|
2013-06-19 06:42:47 -05:00
|
|
|
}
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
pub struct DefaultEmitter;
|
|
|
|
|
|
|
|
impl Emitter for DefaultEmitter {
|
|
|
|
fn emit(&self,
|
|
|
|
cmsp: Option<(@codemap::CodeMap, Span)>,
|
|
|
|
msg: &str,
|
|
|
|
lvl: level) {
|
|
|
|
match cmsp {
|
|
|
|
Some((cm, sp)) => {
|
|
|
|
let sp = cm.adjust_span(sp);
|
|
|
|
let ss = cm.span_to_str(sp);
|
|
|
|
let lines = cm.span_to_lines(sp);
|
|
|
|
print_diagnostic(ss, lvl, msg);
|
|
|
|
highlight_lines(cm, sp, lvl, lines);
|
|
|
|
print_macro_backtrace(cm, sp);
|
|
|
|
}
|
|
|
|
None => print_diagnostic("", lvl, msg),
|
|
|
|
}
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:47:49 -05:00
|
|
|
fn highlight_lines(cm: @codemap::CodeMap,
|
2013-08-29 20:34:09 -05:00
|
|
|
sp: Span,
|
|
|
|
lvl: level,
|
2012-11-12 20:59:37 -06:00
|
|
|
lines: @codemap::FileLines) {
|
2012-02-01 03:18:59 -06:00
|
|
|
let fm = lines.file;
|
2013-10-13 20:48:47 -05:00
|
|
|
let mut err = io::stderr();
|
|
|
|
let err = &mut err as &mut io::Writer;
|
2012-01-13 18:05:58 -06:00
|
|
|
|
|
|
|
// arbitrarily only print up to six lines of the error
|
|
|
|
let max_lines = 6u;
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut elided = false;
|
2013-07-02 14:47:32 -05:00
|
|
|
let mut display_lines = /* FIXME (#2543) */ lines.lines.clone();
|
2013-05-14 04:52:12 -05:00
|
|
|
if display_lines.len() > max_lines {
|
2013-06-27 04:48:50 -05:00
|
|
|
display_lines = display_lines.slice(0u, max_lines).to_owned();
|
2012-01-13 18:05:58 -06:00
|
|
|
elided = true;
|
|
|
|
}
|
|
|
|
// Print the offending lines
|
2013-08-03 11:45:23 -05:00
|
|
|
for line in display_lines.iter() {
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(err, "{}:{} {}\n", fm.name, *line + 1, fm.get_line(*line as int));
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
if elided {
|
2013-05-14 04:52:12 -05:00
|
|
|
let last_line = display_lines[display_lines.len() - 1u];
|
2013-09-27 23:01:58 -05:00
|
|
|
let s = format!("{}:{} ", fm.name, last_line + 1u);
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(err, "{0:1$}...\n", "", s.len());
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
|
2013-02-08 18:01:39 -06:00
|
|
|
// FIXME (#3260)
|
2012-01-13 18:05:58 -06:00
|
|
|
// If there's one line at fault we can easily point to the problem
|
2013-05-14 04:52:12 -05:00
|
|
|
if lines.lines.len() == 1u {
|
2012-11-12 20:24:56 -06:00
|
|
|
let lo = cm.lookup_char_pos(sp.lo);
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut digits = 0u;
|
|
|
|
let mut num = (lines.lines[0] + 1u) / 10u;
|
2012-01-13 18:05:58 -06:00
|
|
|
|
|
|
|
// how many digits must be indent past?
|
|
|
|
while num > 0u { num /= 10u; digits += 1u; }
|
|
|
|
|
|
|
|
// indent past |name:## | and the 0-offset column location
|
2013-06-09 09:44:58 -05:00
|
|
|
let left = fm.name.len() + digits + lo.col.to_uint() + 3u;
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut s = ~"";
|
2013-02-08 17:45:00 -06:00
|
|
|
// Skip is the number of characters we need to skip because they are
|
|
|
|
// part of the 'filename:line ' part of the previous line.
|
2013-06-09 09:44:58 -05:00
|
|
|
let skip = fm.name.len() + digits + 3u;
|
2013-07-31 21:18:19 -05:00
|
|
|
do skip.times() {
|
2013-06-11 21:13:42 -05:00
|
|
|
s.push_char(' ');
|
2013-02-08 17:45:00 -06:00
|
|
|
}
|
|
|
|
let orig = fm.get_line(lines.lines[0] as int);
|
2013-08-03 11:45:23 -05:00
|
|
|
for pos in range(0u, left-skip) {
|
2013-02-08 17:45:00 -06:00
|
|
|
let curChar = (orig[pos] as char);
|
2013-06-11 21:13:42 -05:00
|
|
|
// Whenever a tab occurs on the previous line, we insert one on
|
|
|
|
// the error-point-squiggly-line as well (instead of a space).
|
|
|
|
// That way the squiggly line will usually appear in the correct
|
|
|
|
// position.
|
|
|
|
match curChar {
|
|
|
|
'\t' => s.push_char('\t'),
|
|
|
|
_ => s.push_char(' '),
|
|
|
|
};
|
|
|
|
}
|
2013-10-13 20:48:47 -05:00
|
|
|
write!(err, "{}", s);
|
2013-06-19 06:42:47 -05:00
|
|
|
let mut s = ~"^";
|
2012-11-12 20:24:56 -06:00
|
|
|
let hi = cm.lookup_char_pos(sp.hi);
|
2012-01-13 18:05:58 -06:00
|
|
|
if hi.col != lo.col {
|
|
|
|
// the ^ already takes up one space
|
2013-06-25 17:36:48 -05:00
|
|
|
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
|
2013-07-31 21:18:19 -05:00
|
|
|
do num_squigglies.times() {
|
2013-06-11 21:13:42 -05:00
|
|
|
s.push_char('~')
|
|
|
|
}
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
2013-07-11 01:35:13 -05:00
|
|
|
print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl)));
|
2012-01-13 18:05:58 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-04 19:37:24 -06:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for ei in sp.expn_info.iter() {
|
2013-09-20 01:08:47 -05:00
|
|
|
let ss = ei.callee.span.as_ref().map_default(~"", |span| cm.span_to_str(*span));
|
2013-06-12 12:02:55 -05:00
|
|
|
print_diagnostic(ss, note,
|
2013-09-27 23:01:58 -05:00
|
|
|
format!("in expansion of {}!", ei.callee.name));
|
2012-11-12 20:24:56 -06:00
|
|
|
let ss = cm.span_to_str(ei.call_site);
|
2013-05-19 00:07:44 -05:00
|
|
|
print_diagnostic(ss, note, "expansion site");
|
2013-04-22 19:47:49 -05:00
|
|
|
print_macro_backtrace(cm, ei.call_site);
|
2012-02-04 19:37:24 -06:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 16:55:39 -05:00
|
|
|
|
2013-08-11 12:23:40 -05:00
|
|
|
pub fn expect<T:Clone>(diag: @mut span_handler,
|
2013-01-29 15:54:06 -06:00
|
|
|
opt: Option<T>,
|
2013-03-07 16:38:38 -06:00
|
|
|
msg: &fn() -> ~str) -> T {
|
2012-08-06 14:34:08 -05:00
|
|
|
match opt {
|
2013-07-02 14:47:32 -05:00
|
|
|
Some(ref t) => (*t).clone(),
|
|
|
|
None => diag.handler().bug(msg()),
|
2012-05-22 16:55:39 -05:00
|
|
|
}
|
|
|
|
}
|