#![feature(rustc_diagnostic_macros)]
#![feature(set_stdio)]
-#![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
-#![cfg_attr(stage0, feature(rustc_private))]
-#![cfg_attr(stage0, feature(staged_api))]
-#![cfg_attr(stage0, feature(loop_break_value))]
-
extern crate arena;
extern crate getopts;
extern crate graphviz;
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));
fn save_analysis(sess: &Session) -> bool {
sess.opts.debugging_opts.save_analysis ||
- sess.opts.debugging_opts.save_analysis_csv ||
sess.opts.debugging_opts.save_analysis_api
}
fn save_analysis_format(sess: &Session) -> save::Format {
if sess.opts.debugging_opts.save_analysis {
save::Format::Json
- } else if sess.opts.debugging_opts.save_analysis_csv {
- save::Format::Csv
} else if sess.opts.debugging_opts.save_analysis_api {
save::Format::JsonApi
} else {
} else {
config::rustc_short_optgroups()
};
- let groups: Vec<_> = groups.into_iter()
- .filter(|x| include_unstable_options || x.is_stable())
- .map(|x| x.opt_group)
- .collect();
+ let mut options = getopts::Options::new();
+ for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
+ (option.apply)(&mut options);
+ }
let message = format!("Usage: rustc [OPTIONS] INPUT");
let extra_help = if verbose {
""
Print 'lint' options and default settings
-Z help Print internal \
options for debugging rustc{}\n",
- getopts::usage(&message, &groups),
+ options.usage(&message),
extra_help);
}
// Parse with *all* options defined in the compiler, we don't worry about
// option stability here we just want to parse as much as possible.
- let all_groups: Vec<getopts::OptGroup> = config::rustc_optgroups()
- .into_iter()
- .map(|x| x.opt_group)
- .collect();
- let matches = match getopts::getopts(&args, &all_groups) {
+ let mut options = getopts::Options::new();
+ for option in config::rustc_optgroups() {
+ (option.apply)(&mut options);
+ }
+ let matches = match options.parse(args) {
Ok(m) => m,
Err(f) => early_error(ErrorOutputType::default(), &f.to_string()),
};
}
let xs = ["the compiler unexpectedly panicked. this is a bug.".to_string(),
- format!("we would appreciate a bug report: {}", BUG_REPORT_URL)];
+ format!("we would appreciate a bug report: {}", BUG_REPORT_URL),
+ format!("rustc {} running on {}",
+ option_env!("CFG_VERSION").unwrap_or("unknown_version"),
+ config::host_triple())];
for note in &xs {
handler.emit(&MultiSpan::new(),
¬e,