use rustc_trans::back::write::{RELOC_MODEL_ARGS, CODE_GEN_MODEL_ARGS};
use rustc::dep_graph::DepGraph;
use rustc::session::{self, config, Session, build_session, CompileResult};
+use rustc::session::CompileIncomplete;
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
use rustc::session::config::nightly_options;
use rustc::session::{early_error, early_warn};
use rustc::lint;
use rustc_metadata::locator;
use rustc_metadata::cstore::CStore;
-use rustc::util::common::time;
+use rustc::util::common::{time, ErrorReported};
use serialize::json::ToJson;
const BUG_REPORT_URL: &'static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
md#bug-reports";
-#[inline]
-fn abort_msg(err_count: usize) -> String {
- match err_count {
- 0 => "aborting with no errors (maybe a bug?)".to_owned(),
- _ => "aborting due to previous error(s)".to_owned(),
- }
-}
-
-pub fn abort_on_err<T>(result: Result<T, usize>, sess: &Session) -> T {
+pub fn abort_on_err<T>(result: Result<T, CompileIncomplete>, sess: &Session) -> T {
match result {
- Err(err_count) => {
- sess.fatal(&abort_msg(err_count));
+ Err(CompileIncomplete::Errored(ErrorReported)) => {
+ sess.abort_if_errors();
+ panic!("error reported but abort_if_errors didn't abort???");
+ }
+ Err(CompileIncomplete::Stopped) => {
+ sess.fatal("compilation terminated");
}
Ok(x) => x,
}
{
monitor(move || {
let (result, session) = run_compiler();
- if let Err(err_count) = result {
- if err_count > 0 {
- match session {
- Some(sess) => sess.fatal(&abort_msg(err_count)),
- None => {
- let emitter =
- errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None);
- let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
- handler.emit(&MultiSpan::new(),
- &abort_msg(err_count),
- errors::Level::Fatal);
- exit_on_err();
- }
+ if let Err(CompileIncomplete::Errored(_)) = result {
+ match session {
+ Some(sess) => {
+ sess.abort_if_errors();
+ panic!("error reported but abort_if_errors didn't abort???");
+ }
+ None => {
+ let emitter =
+ errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto, None);
+ let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
+ handler.emit(&MultiSpan::new(),
+ "aborting due to previous error(s)",
+ errors::Level::Fatal);
+ exit_on_err();
}
}
}
};
match descriptions.find_description(&normalised) {
Some(ref description) => {
+ let mut is_in_code_block = false;
// Slice off the leading newline and print.
- print!("{}", &(&description[1..]).split("\n").map(|x| {
- format!("{}\n", if x.starts_with("```") {
- "```"
+ for line in description[1..].lines() {
+ let indent_level = line.find(|c: char| !c.is_whitespace())
+ .unwrap_or_else(|| line.len());
+ let dedented_line = &line[indent_level..];
+ if dedented_line.starts_with("```") {
+ is_in_code_block = !is_in_code_block;
+ println!("{}", &line[..(indent_level+3)]);
+ } else if is_in_code_block && dedented_line.starts_with("# ") {
+ continue;
} else {
- x
- })
- }).collect::<String>());
+ println!("{}", line);
+ }
+ }
}
None => {
early_error(output, &format!("no extended information for {}", code));