mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
move error handling from libsyntax/diagnostics.rs to libsyntax/errors/*
Also split out emitters into their own module.
This commit is contained in:
parent
073b0f9b85
commit
6309b0f5bb
@ -47,7 +47,7 @@ use rustc_front::hir;
|
|||||||
use rustc_front::util;
|
use rustc_front::util;
|
||||||
use rustc_front::intravisit as hir_visit;
|
use rustc_front::intravisit as hir_visit;
|
||||||
use syntax::visit as ast_visit;
|
use syntax::visit as ast_visit;
|
||||||
use syntax::diagnostic;
|
use syntax::errors;
|
||||||
|
|
||||||
/// Information about the registered lints.
|
/// Information about the registered lints.
|
||||||
///
|
///
|
||||||
@ -167,7 +167,7 @@ impl LintStore {
|
|||||||
match (sess, from_plugin) {
|
match (sess, from_plugin) {
|
||||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||||
// Use early_error when handling -W help with no crate.
|
// Use early_error when handling -W help with no crate.
|
||||||
(None, _) => early_error(diagnostic::Auto, &msg[..]),
|
(None, _) => early_error(errors::ColorConfig::Auto, &msg[..]),
|
||||||
(Some(sess), false) => sess.bug(&msg[..]),
|
(Some(sess), false) => sess.bug(&msg[..]),
|
||||||
|
|
||||||
// A duplicate name from a plugin is a user error.
|
// A duplicate name from a plugin is a user error.
|
||||||
@ -191,7 +191,7 @@ impl LintStore {
|
|||||||
match (sess, from_plugin) {
|
match (sess, from_plugin) {
|
||||||
// We load builtin lints first, so a duplicate is a compiler bug.
|
// We load builtin lints first, so a duplicate is a compiler bug.
|
||||||
// Use early_error when handling -W help with no crate.
|
// Use early_error when handling -W help with no crate.
|
||||||
(None, _) => early_error(diagnostic::Auto, &msg[..]),
|
(None, _) => early_error(errors::ColorConfig::Auto, &msg[..]),
|
||||||
(Some(sess), false) => sess.bug(&msg[..]),
|
(Some(sess), false) => sess.bug(&msg[..]),
|
||||||
|
|
||||||
// A duplicate name from a plugin is a user error.
|
// A duplicate name from a plugin is a user error.
|
||||||
|
@ -27,7 +27,7 @@ use middle::cstore;
|
|||||||
use syntax::ast::{self, IntTy, UintTy};
|
use syntax::ast::{self, IntTy, UintTy};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
use syntax::diagnostic::{ColorConfig, Auto, Always, Never, SpanHandler};
|
use syntax::errors::{ColorConfig, Handler};
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::parse::token::InternedString;
|
||||||
use syntax::feature_gate::UnstableFeatures;
|
use syntax::feature_gate::UnstableFeatures;
|
||||||
@ -238,7 +238,7 @@ pub fn basic_options() -> Options {
|
|||||||
debugging_opts: basic_debugging_options(),
|
debugging_opts: basic_debugging_options(),
|
||||||
prints: Vec::new(),
|
prints: Vec::new(),
|
||||||
cg: basic_codegen_options(),
|
cg: basic_codegen_options(),
|
||||||
color: Auto,
|
color: ColorConfig::Auto,
|
||||||
show_span: None,
|
show_span: None,
|
||||||
externs: HashMap::new(),
|
externs: HashMap::new(),
|
||||||
crate_name: None,
|
crate_name: None,
|
||||||
@ -687,19 +687,19 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
|||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
||||||
let target = match Target::search(&opts.target_triple) {
|
let target = match Target::search(&opts.target_triple) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!(sp.handler().fatal(&format!("Error loading target specification: {}", e)));
|
panic!(sp.fatal(&format!("Error loading target specification: {}", e)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
||||||
"32" => (ast::TyI32, ast::TyU32),
|
"32" => (ast::TyI32, ast::TyU32),
|
||||||
"64" => (ast::TyI64, ast::TyU64),
|
"64" => (ast::TyI64, ast::TyU64),
|
||||||
w => panic!(sp.handler().fatal(&format!("target specification was invalid: \
|
w => panic!(sp.fatal(&format!("target specification was invalid: \
|
||||||
unrecognized target-pointer-width {}", w))),
|
unrecognized target-pointer-width {}", w))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
@ -884,16 +884,16 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
|
|||||||
|
|
||||||
pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
|
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
|
||||||
Some("auto") => Auto,
|
Some("auto") => ColorConfig::Auto,
|
||||||
Some("always") => Always,
|
Some("always") => ColorConfig::Always,
|
||||||
Some("never") => Never,
|
Some("never") => ColorConfig::Never,
|
||||||
|
|
||||||
None => Auto,
|
None => ColorConfig::Auto,
|
||||||
|
|
||||||
Some(arg) => {
|
Some(arg) => {
|
||||||
early_error(Auto, &format!("argument for --color must be auto, always \
|
early_error(ColorConfig::Auto, &format!("argument for --color must be auto, always \
|
||||||
or never (instead was `{}`)",
|
or never (instead was `{}`)",
|
||||||
arg))
|
arg))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ use util::nodemap::{NodeMap, FnvHashMap};
|
|||||||
|
|
||||||
use syntax::ast::{NodeId, NodeIdAssigner, Name};
|
use syntax::ast::{NodeId, NodeIdAssigner, Name};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::diagnostic::{self, Emitter};
|
use syntax::errors;
|
||||||
|
use syntax::errors::emitter::{Emitter, BasicEmitter};
|
||||||
use syntax::diagnostics;
|
use syntax::diagnostics;
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
@ -99,7 +100,7 @@ impl Session {
|
|||||||
if self.opts.treat_err_as_bug {
|
if self.opts.treat_err_as_bug {
|
||||||
self.bug(msg);
|
self.bug(msg);
|
||||||
}
|
}
|
||||||
panic!(self.diagnostic().handler().fatal(msg))
|
panic!(self.diagnostic().fatal(msg))
|
||||||
}
|
}
|
||||||
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
|
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
|
||||||
if is_warning {
|
if is_warning {
|
||||||
@ -137,16 +138,16 @@ impl Session {
|
|||||||
if self.opts.treat_err_as_bug {
|
if self.opts.treat_err_as_bug {
|
||||||
self.bug(msg);
|
self.bug(msg);
|
||||||
}
|
}
|
||||||
self.diagnostic().handler().err(msg)
|
self.diagnostic().err(msg)
|
||||||
}
|
}
|
||||||
pub fn err_count(&self) -> usize {
|
pub fn err_count(&self) -> usize {
|
||||||
self.diagnostic().handler().err_count()
|
self.diagnostic().err_count()
|
||||||
}
|
}
|
||||||
pub fn has_errors(&self) -> bool {
|
pub fn has_errors(&self) -> bool {
|
||||||
self.diagnostic().handler().has_errors()
|
self.diagnostic().has_errors()
|
||||||
}
|
}
|
||||||
pub fn abort_if_errors(&self) {
|
pub fn abort_if_errors(&self) {
|
||||||
self.diagnostic().handler().abort_if_errors();
|
self.diagnostic().abort_if_errors();
|
||||||
|
|
||||||
let delayed_bug = self.delayed_span_bug.borrow();
|
let delayed_bug = self.delayed_span_bug.borrow();
|
||||||
match *delayed_bug {
|
match *delayed_bug {
|
||||||
@ -177,7 +178,7 @@ impl Session {
|
|||||||
}
|
}
|
||||||
pub fn warn(&self, msg: &str) {
|
pub fn warn(&self, msg: &str) {
|
||||||
if self.can_print_warnings {
|
if self.can_print_warnings {
|
||||||
self.diagnostic().handler().warn(msg)
|
self.diagnostic().warn(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
|
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
|
||||||
@ -195,7 +196,7 @@ impl Session {
|
|||||||
|
|
||||||
/// Prints out a message with a suggested edit of the code.
|
/// Prints out a message with a suggested edit of the code.
|
||||||
///
|
///
|
||||||
/// See `diagnostic::RenderSpan::Suggestion` for more information.
|
/// See `errors::RenderSpan::Suggestion` for more information.
|
||||||
pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
|
pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
|
||||||
self.diagnostic().span_suggestion(sp, msg, suggestion)
|
self.diagnostic().span_suggestion(sp, msg, suggestion)
|
||||||
}
|
}
|
||||||
@ -209,10 +210,10 @@ impl Session {
|
|||||||
self.diagnostic().fileline_help(sp, msg)
|
self.diagnostic().fileline_help(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn note(&self, msg: &str) {
|
pub fn note(&self, msg: &str) {
|
||||||
self.diagnostic().handler().note(msg)
|
self.diagnostic().note(msg)
|
||||||
}
|
}
|
||||||
pub fn help(&self, msg: &str) {
|
pub fn help(&self, msg: &str) {
|
||||||
self.diagnostic().handler().help(msg)
|
self.diagnostic().help(msg)
|
||||||
}
|
}
|
||||||
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
|
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
|
||||||
match opt_sp {
|
match opt_sp {
|
||||||
@ -229,13 +230,13 @@ impl Session {
|
|||||||
self.diagnostic().span_bug(sp, msg)
|
self.diagnostic().span_bug(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn bug(&self, msg: &str) -> ! {
|
pub fn bug(&self, msg: &str) -> ! {
|
||||||
self.diagnostic().handler().bug(msg)
|
self.diagnostic().bug(msg)
|
||||||
}
|
}
|
||||||
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
|
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
|
||||||
self.diagnostic().span_unimpl(sp, msg)
|
self.diagnostic().span_unimpl(sp, msg)
|
||||||
}
|
}
|
||||||
pub fn unimpl(&self, msg: &str) -> ! {
|
pub fn unimpl(&self, msg: &str) -> ! {
|
||||||
self.diagnostic().handler().unimpl(msg)
|
self.diagnostic().unimpl(msg)
|
||||||
}
|
}
|
||||||
pub fn add_lint(&self,
|
pub fn add_lint(&self,
|
||||||
lint: &'static lint::Lint,
|
lint: &'static lint::Lint,
|
||||||
@ -260,7 +261,7 @@ impl Session {
|
|||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
|
pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler {
|
||||||
&self.parse_sess.span_diagnostic
|
&self.parse_sess.span_diagnostic
|
||||||
}
|
}
|
||||||
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
|
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
|
||||||
@ -414,29 +415,27 @@ pub fn build_session(sopts: config::Options,
|
|||||||
.last()
|
.last()
|
||||||
.unwrap_or(true);
|
.unwrap_or(true);
|
||||||
|
|
||||||
let codemap = codemap::CodeMap::new();
|
let codemap = Rc::new(codemap::CodeMap::new());
|
||||||
let diagnostic_handler =
|
let diagnostic_handler =
|
||||||
diagnostic::Handler::new(sopts.color, Some(registry), can_print_warnings);
|
errors::Handler::new(sopts.color, Some(registry), can_print_warnings, codemap.clone());
|
||||||
let span_diagnostic_handler =
|
|
||||||
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
|
|
||||||
|
|
||||||
build_session_(sopts, local_crate_source_file, span_diagnostic_handler, cstore)
|
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_session_(sopts: config::Options,
|
pub fn build_session_(sopts: config::Options,
|
||||||
local_crate_source_file: Option<PathBuf>,
|
local_crate_source_file: Option<PathBuf>,
|
||||||
span_diagnostic: diagnostic::SpanHandler,
|
span_diagnostic: errors::Handler,
|
||||||
|
codemap: Rc<codemap::CodeMap>,
|
||||||
cstore: Rc<for<'a> CrateStore<'a>>)
|
cstore: Rc<for<'a> CrateStore<'a>>)
|
||||||
-> Session {
|
-> Session {
|
||||||
let host = match Target::search(config::host_triple()) {
|
let host = match Target::search(config::host_triple()) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!(span_diagnostic.handler()
|
panic!(span_diagnostic.fatal(&format!("Error loading host specification: {}", e)));
|
||||||
.fatal(&format!("Error loading host specification: {}", e)));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
||||||
let p_s = parse::ParseSess::with_span_handler(span_diagnostic);
|
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, codemap);
|
||||||
let default_sysroot = match sopts.maybe_sysroot {
|
let default_sysroot = match sopts.maybe_sysroot {
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(filesearch::get_or_default_sysroot())
|
None => Some(filesearch::get_or_default_sysroot())
|
||||||
@ -494,16 +493,16 @@ pub fn build_session_(sopts: config::Options,
|
|||||||
pub fn expect<T, M>(sess: &Session, opt: Option<T>, msg: M) -> T where
|
pub fn expect<T, M>(sess: &Session, opt: Option<T>, msg: M) -> T where
|
||||||
M: FnOnce() -> String,
|
M: FnOnce() -> String,
|
||||||
{
|
{
|
||||||
diagnostic::expect(sess.diagnostic(), opt, msg)
|
errors::expect(sess.diagnostic(), opt, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn early_error(color: diagnostic::ColorConfig, msg: &str) -> ! {
|
pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
|
||||||
let mut emitter = diagnostic::EmitterWriter::stderr(color, None);
|
let mut emitter = BasicEmitter::stderr(color);
|
||||||
emitter.emit(None, msg, None, diagnostic::Fatal);
|
emitter.emit(None, msg, None, errors::Level::Fatal);
|
||||||
panic!(diagnostic::FatalError);
|
panic!(errors::FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn early_warn(color: diagnostic::ColorConfig, msg: &str) {
|
pub fn early_warn(color: errors::ColorConfig, msg: &str) {
|
||||||
let mut emitter = diagnostic::EmitterWriter::stderr(color, None);
|
let mut emitter = BasicEmitter::stderr(color);
|
||||||
emitter.emit(None, msg, None, diagnostic::Warning);
|
emitter.emit(None, msg, None, errors::Level::Warning);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
use std::slice;
|
use std::slice;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use session::early_error;
|
use session::early_error;
|
||||||
use syntax::diagnostic;
|
use syntax::errors;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SearchPaths {
|
pub struct SearchPaths {
|
||||||
@ -38,7 +38,7 @@ impl SearchPaths {
|
|||||||
SearchPaths { paths: Vec::new() }
|
SearchPaths { paths: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_path(&mut self, path: &str, color: diagnostic::ColorConfig) {
|
pub fn add_path(&mut self, path: &str, color: errors::ColorConfig) {
|
||||||
let (kind, path) = if path.starts_with("native=") {
|
let (kind, path) = if path.starts_with("native=") {
|
||||||
(PathKind::Native, &path["native=".len()..])
|
(PathKind::Native, &path["native=".len()..])
|
||||||
} else if path.starts_with("crate=") {
|
} else if path.starts_with("crate=") {
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
use serialize::json::Json;
|
use serialize::json::Json;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use syntax::{diagnostic, abi};
|
use syntax::abi;
|
||||||
|
|
||||||
mod android_base;
|
mod android_base;
|
||||||
mod apple_base;
|
mod apple_base;
|
||||||
@ -263,17 +263,13 @@ impl Target {
|
|||||||
pub fn from_json(obj: Json) -> Target {
|
pub fn from_json(obj: Json) -> Target {
|
||||||
// this is 1. ugly, 2. error prone.
|
// this is 1. ugly, 2. error prone.
|
||||||
|
|
||||||
|
|
||||||
let handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
|
|
||||||
|
|
||||||
let get_req_field = |name: &str| {
|
let get_req_field = |name: &str| {
|
||||||
match obj.find(name)
|
match obj.find(name)
|
||||||
.map(|s| s.as_string())
|
.map(|s| s.as_string())
|
||||||
.and_then(|os| os.map(|s| s.to_string())) {
|
.and_then(|os| os.map(|s| s.to_string())) {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => {
|
None => {
|
||||||
panic!(handler.fatal(&format!("Field {} in target specification is required",
|
panic!("Field {} in target specification is required", name)
|
||||||
name)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -59,8 +59,6 @@ extern crate log;
|
|||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate syntax_ext;
|
extern crate syntax_ext;
|
||||||
|
|
||||||
pub use syntax::diagnostic;
|
|
||||||
|
|
||||||
use driver::CompileController;
|
use driver::CompileController;
|
||||||
use pretty::{PpMode, UserIdentifiedItem};
|
use pretty::{PpMode, UserIdentifiedItem};
|
||||||
|
|
||||||
@ -91,7 +89,8 @@ use rustc::session::early_error;
|
|||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
use syntax::diagnostic::Emitter;
|
use syntax::errors;
|
||||||
|
use syntax::errors::emitter::Emitter;
|
||||||
use syntax::diagnostics;
|
use syntax::diagnostics;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
|
||||||
@ -239,7 +238,7 @@ pub trait CompilerCalls<'a> {
|
|||||||
fn early_callback(&mut self,
|
fn early_callback(&mut self,
|
||||||
_: &getopts::Matches,
|
_: &getopts::Matches,
|
||||||
_: &diagnostics::registry::Registry,
|
_: &diagnostics::registry::Registry,
|
||||||
_: diagnostic::ColorConfig)
|
_: errors::ColorConfig)
|
||||||
-> Compilation {
|
-> Compilation {
|
||||||
Compilation::Continue
|
Compilation::Continue
|
||||||
}
|
}
|
||||||
@ -315,7 +314,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||||||
fn early_callback(&mut self,
|
fn early_callback(&mut self,
|
||||||
matches: &getopts::Matches,
|
matches: &getopts::Matches,
|
||||||
descriptions: &diagnostics::registry::Registry,
|
descriptions: &diagnostics::registry::Registry,
|
||||||
color: diagnostic::ColorConfig)
|
color: errors::ColorConfig)
|
||||||
-> Compilation {
|
-> Compilation {
|
||||||
match matches.opt_str("explain") {
|
match matches.opt_str("explain") {
|
||||||
Some(ref code) => {
|
Some(ref code) => {
|
||||||
@ -774,7 +773,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
|
|||||||
&opt.opt_group.short_name
|
&opt.opt_group.short_name
|
||||||
};
|
};
|
||||||
if m.opt_present(opt_name) {
|
if m.opt_present(opt_name) {
|
||||||
early_error(diagnostic::Auto,
|
early_error(errors::ColorConfig::Auto,
|
||||||
&format!("use of unstable option '{}' requires -Z \
|
&format!("use of unstable option '{}' requires -Z \
|
||||||
unstable-options",
|
unstable-options",
|
||||||
opt_name));
|
opt_name));
|
||||||
@ -783,7 +782,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
|
|||||||
}
|
}
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
Err(f) => early_error(diagnostic::Auto, &f.to_string()),
|
Err(f) => early_error(errors::ColorConfig::Auto, &f.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -895,25 +894,25 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
|
|||||||
}
|
}
|
||||||
Err(value) => {
|
Err(value) => {
|
||||||
// Thread panicked without emitting a fatal diagnostic
|
// Thread panicked without emitting a fatal diagnostic
|
||||||
if !value.is::<diagnostic::FatalError>() {
|
if !value.is::<errors::FatalError>() {
|
||||||
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto, None);
|
let mut emitter = errors::emitter::BasicEmitter::stderr(errors::ColorConfig::Auto);
|
||||||
|
|
||||||
// a .span_bug or .bug call has already printed what
|
// a .span_bug or .bug call has already printed what
|
||||||
// it wants to print.
|
// it wants to print.
|
||||||
if !value.is::<diagnostic::ExplicitBug>() {
|
if !value.is::<errors::ExplicitBug>() {
|
||||||
emitter.emit(None, "unexpected panic", None, diagnostic::Bug);
|
emitter.emit(None, "unexpected panic", None, errors::Level::Bug);
|
||||||
}
|
}
|
||||||
|
|
||||||
let xs = ["the compiler unexpectedly panicked. this is a bug.".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)];
|
||||||
for note in &xs {
|
for note in &xs {
|
||||||
emitter.emit(None, ¬e[..], None, diagnostic::Note)
|
emitter.emit(None, ¬e[..], None, errors::Level::Note)
|
||||||
}
|
}
|
||||||
if let None = env::var_os("RUST_BACKTRACE") {
|
if let None = env::var_os("RUST_BACKTRACE") {
|
||||||
emitter.emit(None,
|
emitter.emit(None,
|
||||||
"run with `RUST_BACKTRACE=1` for a backtrace",
|
"run with `RUST_BACKTRACE=1` for a backtrace",
|
||||||
None,
|
None,
|
||||||
diagnostic::Note);
|
errors::Level::Note);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap());
|
println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap());
|
||||||
|
@ -14,7 +14,7 @@ use syntax::abi;
|
|||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::owned_slice::OwnedSlice;
|
use syntax::owned_slice::OwnedSlice;
|
||||||
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
|
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
|
||||||
use syntax::diagnostic;
|
use syntax::errors;
|
||||||
use syntax::parse::token::{self, BinOpToken};
|
use syntax::parse::token::{self, BinOpToken};
|
||||||
use syntax::parse::lexer::comments;
|
use syntax::parse::lexer::comments;
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
@ -121,7 +121,7 @@ pub const default_columns: usize = 78;
|
|||||||
/// it can scan the input text for comments and literals to
|
/// it can scan the input text for comments and literals to
|
||||||
/// copy forward.
|
/// copy forward.
|
||||||
pub fn print_crate<'a>(cm: &'a CodeMap,
|
pub fn print_crate<'a>(cm: &'a CodeMap,
|
||||||
span_diagnostic: &diagnostic::SpanHandler,
|
span_diagnostic: &errors::Handler,
|
||||||
krate: &hir::Crate,
|
krate: &hir::Crate,
|
||||||
filename: String,
|
filename: String,
|
||||||
input: &mut Read,
|
input: &mut Read,
|
||||||
@ -142,7 +142,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
|
|||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new_from_input(cm: &'a CodeMap,
|
pub fn new_from_input(cm: &'a CodeMap,
|
||||||
span_diagnostic: &diagnostic::SpanHandler,
|
span_diagnostic: &errors::Handler,
|
||||||
filename: String,
|
filename: String,
|
||||||
input: &mut Read,
|
input: &mut Read,
|
||||||
out: Box<Write + 'a>,
|
out: Box<Write + 'a>,
|
||||||
|
@ -44,7 +44,7 @@ use syntax::abi;
|
|||||||
use syntax::ast::{self, NodeId, Name, CRATE_NODE_ID, CrateNum};
|
use syntax::ast::{self, NodeId, Name, CRATE_NODE_ID, CrateNum};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
use syntax::diagnostic::SpanHandler;
|
use syntax::errors::Handler;
|
||||||
use syntax::parse::token::special_idents;
|
use syntax::parse::token::special_idents;
|
||||||
use syntax;
|
use syntax;
|
||||||
use rbml::writer::Encoder;
|
use rbml::writer::Encoder;
|
||||||
@ -57,7 +57,7 @@ pub type EncodeInlinedItem<'a> =
|
|||||||
Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>;
|
Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>;
|
||||||
|
|
||||||
pub struct EncodeParams<'a, 'tcx: 'a> {
|
pub struct EncodeParams<'a, 'tcx: 'a> {
|
||||||
pub diag: &'a SpanHandler,
|
pub diag: &'a Handler,
|
||||||
pub tcx: &'a ty::ctxt<'tcx>,
|
pub tcx: &'a ty::ctxt<'tcx>,
|
||||||
pub reexports: &'a def::ExportMap,
|
pub reexports: &'a def::ExportMap,
|
||||||
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
||||||
@ -69,7 +69,7 @@ pub struct EncodeParams<'a, 'tcx: 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct EncodeContext<'a, 'tcx: 'a> {
|
pub struct EncodeContext<'a, 'tcx: 'a> {
|
||||||
pub diag: &'a SpanHandler,
|
pub diag: &'a Handler,
|
||||||
pub tcx: &'a ty::ctxt<'tcx>,
|
pub tcx: &'a ty::ctxt<'tcx>,
|
||||||
pub reexports: &'a def::ExportMap,
|
pub reexports: &'a def::ExportMap,
|
||||||
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
pub item_symbols: &'a RefCell<NodeMap<String>>,
|
||||||
@ -275,8 +275,7 @@ fn encode_symbol(ecx: &EncodeContext,
|
|||||||
rbml_w.wr_tagged_str(tag_items_data_item_symbol, x);
|
rbml_w.wr_tagged_str(tag_items_data_item_symbol, x);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
ecx.diag.handler().bug(
|
ecx.diag.bug(&format!("encode_symbol: id not found {}", id));
|
||||||
&format!("encode_symbol: id not found {}", id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ use rustc_llvm as llvm;
|
|||||||
use rustc_llvm::{False, ObjectFile, mk_section_iter};
|
use rustc_llvm::{False, ObjectFile, mk_section_iter};
|
||||||
use rustc_llvm::archive_ro::ArchiveRO;
|
use rustc_llvm::archive_ro::ArchiveRO;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::diagnostic::SpanHandler;
|
use syntax::errors::Handler;
|
||||||
use rustc_back::target::Target;
|
use rustc_back::target::Target;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
@ -697,8 +697,8 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn note_crate_name(diag: &SpanHandler, name: &str) {
|
pub fn note_crate_name(diag: &Handler, name: &str) {
|
||||||
diag.handler().note(&format!("crate name: {}", name));
|
diag.note(&format!("crate name: {}", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArchiveMetadata {
|
impl ArchiveMetadata {
|
||||||
|
@ -29,14 +29,14 @@ use rustc_front::hir;
|
|||||||
|
|
||||||
use syntax::abi::Abi;
|
use syntax::abi::Abi;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::diagnostic::SpanHandler;
|
use syntax::errors::Handler;
|
||||||
|
|
||||||
use rbml::writer::{self, Encoder};
|
use rbml::writer::{self, Encoder};
|
||||||
|
|
||||||
macro_rules! mywrite { ($w:expr, $($arg:tt)*) => ({ write!($w.writer, $($arg)*); }) }
|
macro_rules! mywrite { ($w:expr, $($arg:tt)*) => ({ write!($w.writer, $($arg)*); }) }
|
||||||
|
|
||||||
pub struct ctxt<'a, 'tcx: 'a> {
|
pub struct ctxt<'a, 'tcx: 'a> {
|
||||||
pub diag: &'a SpanHandler,
|
pub diag: &'a Handler,
|
||||||
// Def -> str Callback:
|
// Def -> str Callback:
|
||||||
pub ds: fn(DefId) -> String,
|
pub ds: fn(DefId) -> String,
|
||||||
// The type context.
|
// The type context.
|
||||||
@ -136,7 +136,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
|
|||||||
enc_bare_fn_ty(w, cx, f);
|
enc_bare_fn_ty(w, cx, f);
|
||||||
}
|
}
|
||||||
ty::TyInfer(_) => {
|
ty::TyInfer(_) => {
|
||||||
cx.diag.handler().bug("cannot encode inference variable types");
|
cx.diag.bug("cannot encode inference variable types");
|
||||||
}
|
}
|
||||||
ty::TyParam(ParamTy {space, idx, name}) => {
|
ty::TyParam(ParamTy {space, idx, name}) => {
|
||||||
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), name)
|
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), name)
|
||||||
@ -279,7 +279,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
|
|||||||
}
|
}
|
||||||
ty::ReVar(_) | ty::ReSkolemized(..) => {
|
ty::ReVar(_) | ty::ReSkolemized(..) => {
|
||||||
// these should not crop up after typeck
|
// these should not crop up after typeck
|
||||||
cx.diag.handler().bug("cannot encode region variables");
|
cx.diag.bug("cannot encode region variables");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::diagnostic;
|
use syntax::errors;
|
||||||
use rustc_front::intravisit::Visitor;
|
use rustc_front::intravisit::Visitor;
|
||||||
use rustc_front::hir;
|
use rustc_front::hir;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ impl<'v> Visitor<'v> for RegistrarFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find the function marked with `#[plugin_registrar]`, if any.
|
/// Find the function marked with `#[plugin_registrar]`, if any.
|
||||||
pub fn find_plugin_registrar(diagnostic: &diagnostic::SpanHandler,
|
pub fn find_plugin_registrar(diagnostic: &errors::Handler,
|
||||||
krate: &hir::Crate)
|
krate: &hir::Crate)
|
||||||
-> Option<ast::NodeId> {
|
-> Option<ast::NodeId> {
|
||||||
let mut finder = RegistrarFinder { registrars: Vec::new() };
|
let mut finder = RegistrarFinder { registrars: Vec::new() };
|
||||||
@ -46,11 +46,11 @@ pub fn find_plugin_registrar(diagnostic: &diagnostic::SpanHandler,
|
|||||||
Some(node_id)
|
Some(node_id)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
diagnostic.handler().err("multiple plugin registration functions found");
|
diagnostic.err("multiple plugin registration functions found");
|
||||||
for &(_, span) in &finder.registrars {
|
for &(_, span) in &finder.registrars {
|
||||||
diagnostic.span_note(span, "one is here");
|
diagnostic.span_note(span, "one is here");
|
||||||
}
|
}
|
||||||
diagnostic.handler().abort_if_errors();
|
diagnostic.abort_if_errors();
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
|
|||||||
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
|
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
|
||||||
ptr as *const libc::c_char,
|
ptr as *const libc::c_char,
|
||||||
bc_decoded.len() as libc::size_t) {
|
bc_decoded.len() as libc::size_t) {
|
||||||
write::llvm_err(sess.diagnostic().handler(),
|
write::llvm_err(sess.diagnostic(),
|
||||||
format!("failed to load bc of `{}`",
|
format!("failed to load bc of `{}`",
|
||||||
&name[..]));
|
&name[..]));
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ use trans::{CrateTranslation, ModuleTranslation};
|
|||||||
use util::common::time;
|
use util::common::time;
|
||||||
use util::common::path2cstr;
|
use util::common::path2cstr;
|
||||||
use syntax::codemap;
|
use syntax::codemap;
|
||||||
use syntax::diagnostic;
|
use syntax::errors::{self, Handler, Level};
|
||||||
use syntax::diagnostic::{Emitter, Handler, Level};
|
use syntax::errors::emitter::Emitter;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
@ -34,7 +34,7 @@ use std::sync::mpsc::channel;
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use libc::{self, c_uint, c_int, c_void};
|
use libc::{self, c_uint, c_int, c_void};
|
||||||
|
|
||||||
pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
|
pub fn llvm_err(handler: &errors::Handler, msg: String) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cstr = llvm::LLVMRustGetLastError();
|
let cstr = llvm::LLVMRustGetLastError();
|
||||||
if cstr == ptr::null() {
|
if cstr == ptr::null() {
|
||||||
@ -49,7 +49,7 @@ pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_output_file(
|
pub fn write_output_file(
|
||||||
handler: &diagnostic::Handler,
|
handler: &errors::Handler,
|
||||||
target: llvm::TargetMachineRef,
|
target: llvm::TargetMachineRef,
|
||||||
pm: llvm::PassManagerRef,
|
pm: llvm::PassManagerRef,
|
||||||
m: ModuleRef,
|
m: ModuleRef,
|
||||||
@ -109,9 +109,9 @@ impl SharedEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for SharedEmitter {
|
impl Emitter for SharedEmitter {
|
||||||
fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, codemap::Span)>,
|
fn emit(&mut self, sp: Option<codemap::Span>,
|
||||||
msg: &str, code: Option<&str>, lvl: Level) {
|
msg: &str, code: Option<&str>, lvl: Level) {
|
||||||
assert!(cmsp.is_none(), "SharedEmitter doesn't support spans");
|
assert!(sp.is_none(), "SharedEmitter doesn't support spans");
|
||||||
|
|
||||||
self.buffer.lock().unwrap().push(Diagnostic {
|
self.buffer.lock().unwrap().push(Diagnostic {
|
||||||
msg: msg.to_string(),
|
msg: msg.to_string(),
|
||||||
@ -120,8 +120,7 @@ impl Emitter for SharedEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn custom_emit(&mut self, _cm: &codemap::CodeMap,
|
fn custom_emit(&mut self, _sp: errors::RenderSpan, _msg: &str, _lvl: Level) {
|
||||||
_sp: diagnostic::RenderSpan, _msg: &str, _lvl: Level) {
|
|
||||||
panic!("SharedEmitter doesn't support custom_emit");
|
panic!("SharedEmitter doesn't support custom_emit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +225,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if tm.is_null() {
|
if tm.is_null() {
|
||||||
llvm_err(sess.diagnostic().handler(),
|
llvm_err(sess.diagnostic(),
|
||||||
format!("Could not create LLVM TargetMachine for triple: {}",
|
format!("Could not create LLVM TargetMachine for triple: {}",
|
||||||
triple).to_string());
|
triple).to_string());
|
||||||
} else {
|
} else {
|
||||||
@ -333,7 +332,7 @@ impl<'a> CodegenContext<'a> {
|
|||||||
fn new_with_session(sess: &'a Session, reachable: &'a [String]) -> CodegenContext<'a> {
|
fn new_with_session(sess: &'a Session, reachable: &'a [String]) -> CodegenContext<'a> {
|
||||||
CodegenContext {
|
CodegenContext {
|
||||||
lto_ctxt: Some((sess, reachable)),
|
lto_ctxt: Some((sess, reachable)),
|
||||||
handler: sess.diagnostic().handler(),
|
handler: sess.diagnostic(),
|
||||||
plugin_passes: sess.plugin_llvm_passes.borrow().clone(),
|
plugin_passes: sess.plugin_llvm_passes.borrow().clone(),
|
||||||
remark: sess.opts.cg.remark.clone(),
|
remark: sess.opts.cg.remark.clone(),
|
||||||
worker: 0,
|
worker: 0,
|
||||||
@ -903,7 +902,7 @@ fn run_work_multithreaded(sess: &Session,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Display any new diagnostics.
|
// Display any new diagnostics.
|
||||||
diag_emitter.dump(sess.diagnostic().handler());
|
diag_emitter.dump(sess.diagnostic());
|
||||||
}
|
}
|
||||||
if panicked {
|
if panicked {
|
||||||
sess.fatal("aborting due to worker thread panic");
|
sess.fatal("aborting due to worker thread panic");
|
||||||
|
@ -22,7 +22,8 @@ use rustc_resolve as resolve;
|
|||||||
use rustc_front::lowering::{lower_crate, LoweringContext};
|
use rustc_front::lowering::{lower_crate, LoweringContext};
|
||||||
use rustc_metadata::cstore::CStore;
|
use rustc_metadata::cstore::CStore;
|
||||||
|
|
||||||
use syntax::{ast, codemap, diagnostic};
|
use syntax::{ast, codemap, errors};
|
||||||
|
use syntax::errors::emitter::ColorConfig;
|
||||||
use syntax::feature_gate::UnstableFeatures;
|
use syntax::feature_gate::UnstableFeatures;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
|
||||||
@ -116,15 +117,16 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
|||||||
..config::basic_options().clone()
|
..config::basic_options().clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let codemap = codemap::CodeMap::new();
|
let codemap = Rc::new(codemap::CodeMap::new());
|
||||||
let diagnostic_handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
|
let diagnostic_handler = errors::Handler::new(ColorConfig::Auto,
|
||||||
let span_diagnostic_handler =
|
None,
|
||||||
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
|
true,
|
||||||
|
false,
|
||||||
|
codemap.clone());
|
||||||
|
|
||||||
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
||||||
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
||||||
let sess = session::build_session_(sessopts, cpath,
|
let sess = session::build_session_(sessopts, cpath, diagnostic_handler, codemap, cstore_);
|
||||||
span_diagnostic_handler, cstore_);
|
|
||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
|
|
||||||
let mut cfg = config::build_configuration(&sess);
|
let mut cfg = config::build_configuration(&sess);
|
||||||
|
@ -65,7 +65,7 @@ use externalfiles::ExternalHtml;
|
|||||||
use serialize::Decodable;
|
use serialize::Decodable;
|
||||||
use serialize::json::{self, Json};
|
use serialize::json::{self, Json};
|
||||||
use rustc::session::search_paths::SearchPaths;
|
use rustc::session::search_paths::SearchPaths;
|
||||||
use syntax::diagnostic;
|
use syntax::errors::emitter::ColorConfig;
|
||||||
|
|
||||||
// reexported from `clean` so it can be easily updated with the mod itself
|
// reexported from `clean` so it can be easily updated with the mod itself
|
||||||
pub use clean::SCHEMA_VERSION;
|
pub use clean::SCHEMA_VERSION;
|
||||||
@ -228,7 +228,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||||||
|
|
||||||
let mut libs = SearchPaths::new();
|
let mut libs = SearchPaths::new();
|
||||||
for s in &matches.opt_strs("L") {
|
for s in &matches.opt_strs("L") {
|
||||||
libs.add_path(s, diagnostic::Auto);
|
libs.add_path(s, ColorConfig::Auto);
|
||||||
}
|
}
|
||||||
let externs = match parse_externs(&matches) {
|
let externs = match parse_externs(&matches) {
|
||||||
Ok(ex) => ex,
|
Ok(ex) => ex,
|
||||||
@ -363,7 +363,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
|
|||||||
// First, parse the crate and extract all relevant information.
|
// First, parse the crate and extract all relevant information.
|
||||||
let mut paths = SearchPaths::new();
|
let mut paths = SearchPaths::new();
|
||||||
for s in &matches.opt_strs("L") {
|
for s in &matches.opt_strs("L") {
|
||||||
paths.add_path(s, diagnostic::Auto);
|
paths.add_path(s, ColorConfig::Auto);
|
||||||
}
|
}
|
||||||
let cfgs = matches.opt_strs("cfg");
|
let cfgs = matches.opt_strs("cfg");
|
||||||
let triple = matches.opt_str("target");
|
let triple = matches.opt_str("target");
|
||||||
|
@ -34,7 +34,8 @@ use rustc_back::tempdir::TempDir;
|
|||||||
use rustc_driver::{driver, Compilation};
|
use rustc_driver::{driver, Compilation};
|
||||||
use rustc_metadata::cstore::CStore;
|
use rustc_metadata::cstore::CStore;
|
||||||
use syntax::codemap::CodeMap;
|
use syntax::codemap::CodeMap;
|
||||||
use syntax::diagnostic;
|
use syntax::errors;
|
||||||
|
use syntax::errors::emitter::ColorConfig;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
|
||||||
use core;
|
use core;
|
||||||
@ -71,16 +72,19 @@ pub fn run(input: &str,
|
|||||||
..config::basic_options().clone()
|
..config::basic_options().clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let codemap = CodeMap::new();
|
let codemap = Rc::new(CodeMap::new());
|
||||||
let diagnostic_handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
|
let diagnostic_handler = errors::Handler::new(ColorConfig::Auto,
|
||||||
let span_diagnostic_handler =
|
None,
|
||||||
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
|
true,
|
||||||
|
false,
|
||||||
|
codemap.clone());
|
||||||
|
|
||||||
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
||||||
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
||||||
let sess = session::build_session_(sessopts,
|
let sess = session::build_session_(sessopts,
|
||||||
Some(input_path.clone()),
|
Some(input_path.clone()),
|
||||||
span_diagnostic_handler,
|
diagnostic_handler,
|
||||||
|
codemap,
|
||||||
cstore_);
|
cstore_);
|
||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
|
|
||||||
@ -220,21 +224,20 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let data = Arc::new(Mutex::new(Vec::new()));
|
let data = Arc::new(Mutex::new(Vec::new()));
|
||||||
let emitter = diagnostic::EmitterWriter::new(box Sink(data.clone()), None);
|
let codemap = Rc::new(CodeMap::new());
|
||||||
|
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()), None, codemap.clone());
|
||||||
let old = io::set_panic(box Sink(data.clone()));
|
let old = io::set_panic(box Sink(data.clone()));
|
||||||
let _bomb = Bomb(data, old.unwrap_or(box io::stdout()));
|
let _bomb = Bomb(data, old.unwrap_or(box io::stdout()));
|
||||||
|
|
||||||
// Compile the code
|
// Compile the code
|
||||||
let codemap = CodeMap::new();
|
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
|
||||||
let diagnostic_handler = diagnostic::Handler::with_emitter(true, box emitter);
|
|
||||||
let span_diagnostic_handler =
|
|
||||||
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
|
|
||||||
|
|
||||||
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
|
||||||
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone());
|
||||||
let sess = session::build_session_(sessopts,
|
let sess = session::build_session_(sessopts,
|
||||||
None,
|
None,
|
||||||
span_diagnostic_handler,
|
diagnostic_handler,
|
||||||
|
codemap,
|
||||||
cstore_);
|
cstore_);
|
||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use ast::{Expr, Item, Local, Decl};
|
|||||||
use codemap::{Span, Spanned, spanned, dummy_spanned};
|
use codemap::{Span, Spanned, spanned, dummy_spanned};
|
||||||
use codemap::BytePos;
|
use codemap::BytePos;
|
||||||
use config::CfgDiag;
|
use config::CfgDiag;
|
||||||
use diagnostic::SpanHandler;
|
use errors::Handler;
|
||||||
use feature_gate::{GatedCfg, GatedCfgAttr};
|
use feature_gate::{GatedCfg, GatedCfgAttr};
|
||||||
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||||
use parse::token::{InternedString, intern_and_get_ident};
|
use parse::token::{InternedString, intern_and_get_ident};
|
||||||
@ -299,14 +299,14 @@ pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find the value of #[export_name=*] attribute and check its validity.
|
/// Find the value of #[export_name=*] attribute and check its validity.
|
||||||
pub fn find_export_name_attr(diag: &SpanHandler, attrs: &[Attribute]) -> Option<InternedString> {
|
pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute]) -> Option<InternedString> {
|
||||||
attrs.iter().fold(None, |ia,attr| {
|
attrs.iter().fold(None, |ia,attr| {
|
||||||
if attr.check_name("export_name") {
|
if attr.check_name("export_name") {
|
||||||
if let s@Some(_) = attr.value_str() {
|
if let s@Some(_) = attr.value_str() {
|
||||||
s
|
s
|
||||||
} else {
|
} else {
|
||||||
diag.span_err(attr.span, "export_name attribute has invalid format");
|
diag.span_err(attr.span, "export_name attribute has invalid format");
|
||||||
diag.handler.help("use #[export_name=\"*\"]");
|
diag.help("use #[export_name=\"*\"]");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -324,7 +324,7 @@ pub enum InlineAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Determine what `#[inline]` attribute is present in `attrs`, if any.
|
/// Determine what `#[inline]` attribute is present in `attrs`, if any.
|
||||||
pub fn find_inline_attr(diagnostic: Option<&SpanHandler>, attrs: &[Attribute]) -> InlineAttr {
|
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
|
||||||
attrs.iter().fold(InlineAttr::None, |ia,attr| {
|
attrs.iter().fold(InlineAttr::None, |ia,attr| {
|
||||||
match attr.node.value.node {
|
match attr.node.value.node {
|
||||||
MetaWord(ref n) if *n == "inline" => {
|
MetaWord(ref n) if *n == "inline" => {
|
||||||
@ -426,7 +426,7 @@ impl StabilityLevel {
|
|||||||
pub fn is_stable(&self) -> bool { if let Stable {..} = *self { true } else { false }}
|
pub fn is_stable(&self) -> bool { if let Stable {..} = *self { true } else { false }}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_stability_generic<'a, I>(diagnostic: &SpanHandler,
|
fn find_stability_generic<'a, I>(diagnostic: &Handler,
|
||||||
attrs_iter: I,
|
attrs_iter: I,
|
||||||
item_sp: Span)
|
item_sp: Span)
|
||||||
-> Option<Stability>
|
-> Option<Stability>
|
||||||
@ -612,10 +612,10 @@ fn find_stability_generic<'a, I>(diagnostic: &SpanHandler,
|
|||||||
stab
|
stab
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_deprecation_generic<'a, I>(diagnostic: &SpanHandler,
|
fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
|
||||||
attrs_iter: I,
|
attrs_iter: I,
|
||||||
item_sp: Span)
|
item_sp: Span)
|
||||||
-> Option<Deprecation>
|
-> Option<Deprecation>
|
||||||
where I: Iterator<Item = &'a Attribute>
|
where I: Iterator<Item = &'a Attribute>
|
||||||
{
|
{
|
||||||
let mut depr: Option<Deprecation> = None;
|
let mut depr: Option<Deprecation> = None;
|
||||||
@ -672,18 +672,18 @@ fn find_deprecation_generic<'a, I>(diagnostic: &SpanHandler,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find the first stability attribute. `None` if none exists.
|
/// Find the first stability attribute. `None` if none exists.
|
||||||
pub fn find_stability(diagnostic: &SpanHandler, attrs: &[Attribute],
|
pub fn find_stability(diagnostic: &Handler, attrs: &[Attribute],
|
||||||
item_sp: Span) -> Option<Stability> {
|
item_sp: Span) -> Option<Stability> {
|
||||||
find_stability_generic(diagnostic, attrs.iter(), item_sp)
|
find_stability_generic(diagnostic, attrs.iter(), item_sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the deprecation attribute. `None` if none exists.
|
/// Find the deprecation attribute. `None` if none exists.
|
||||||
pub fn find_deprecation(diagnostic: &SpanHandler, attrs: &[Attribute],
|
pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute],
|
||||||
item_sp: Span) -> Option<Deprecation> {
|
item_sp: Span) -> Option<Deprecation> {
|
||||||
find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
|
find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[P<MetaItem>]) {
|
pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
|
||||||
let mut set = HashSet::new();
|
let mut set = HashSet::new();
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
let name = meta.name();
|
let name = meta.name();
|
||||||
@ -702,7 +702,7 @@ pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[P<MetaItem>]) {
|
|||||||
/// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
|
/// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
|
||||||
/// the same discriminant size that the corresponding C enum would or C
|
/// the same discriminant size that the corresponding C enum would or C
|
||||||
/// structure layout, and `packed` to remove padding.
|
/// structure layout, and `packed` to remove padding.
|
||||||
pub fn find_repr_attrs(diagnostic: &SpanHandler, attr: &Attribute) -> Vec<ReprAttr> {
|
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
|
||||||
let mut acc = Vec::new();
|
let mut acc = Vec::new();
|
||||||
match attr.node.value.node {
|
match attr.node.value.node {
|
||||||
ast::MetaList(ref s, ref items) if *s == "repr" => {
|
ast::MetaList(ref s, ref items) if *s == "repr" => {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use attr::AttrMetaMethods;
|
use attr::AttrMetaMethods;
|
||||||
use diagnostic::SpanHandler;
|
use errors::Handler;
|
||||||
use feature_gate::GatedCfgAttr;
|
use feature_gate::GatedCfgAttr;
|
||||||
use fold::Folder;
|
use fold::Folder;
|
||||||
use {ast, fold, attr};
|
use {ast, fold, attr};
|
||||||
@ -23,12 +23,12 @@ use util::small_vector::SmallVector;
|
|||||||
/// configuration.
|
/// configuration.
|
||||||
struct Context<'a, F> where F: FnMut(&[ast::Attribute]) -> bool {
|
struct Context<'a, F> where F: FnMut(&[ast::Attribute]) -> bool {
|
||||||
in_cfg: F,
|
in_cfg: F,
|
||||||
diagnostic: &'a SpanHandler,
|
diagnostic: &'a Handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support conditional compilation by transforming the AST, stripping out
|
// Support conditional compilation by transforming the AST, stripping out
|
||||||
// any items that do not belong in the current configuration
|
// any items that do not belong in the current configuration
|
||||||
pub fn strip_unconfigured_items(diagnostic: &SpanHandler, krate: ast::Crate,
|
pub fn strip_unconfigured_items(diagnostic: &Handler, krate: ast::Crate,
|
||||||
feature_gated_cfgs: &mut Vec<GatedCfgAttr>)
|
feature_gated_cfgs: &mut Vec<GatedCfgAttr>)
|
||||||
-> ast::Crate
|
-> ast::Crate
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ impl<'a, F> fold::Folder for Context<'a, F> where F: FnMut(&[ast::Attribute]) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strip_items<'a, F>(diagnostic: &'a SpanHandler,
|
pub fn strip_items<'a, F>(diagnostic: &'a Handler,
|
||||||
krate: ast::Crate, in_cfg: F) -> ast::Crate where
|
krate: ast::Crate, in_cfg: F) -> ast::Crate where
|
||||||
F: FnMut(&[ast::Attribute]) -> bool,
|
F: FnMut(&[ast::Attribute]) -> bool,
|
||||||
{
|
{
|
||||||
@ -291,7 +291,7 @@ struct CfgAttrFolder<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process `#[cfg_attr]`.
|
// Process `#[cfg_attr]`.
|
||||||
fn process_cfg_attr(diagnostic: &SpanHandler, krate: ast::Crate,
|
fn process_cfg_attr(diagnostic: &Handler, krate: ast::Crate,
|
||||||
feature_gated_cfgs: &mut Vec<GatedCfgAttr>) -> ast::Crate {
|
feature_gated_cfgs: &mut Vec<GatedCfgAttr>) -> ast::Crate {
|
||||||
let mut fld = CfgAttrFolder {
|
let mut fld = CfgAttrFolder {
|
||||||
diag: CfgDiagReal {
|
diag: CfgDiagReal {
|
||||||
@ -463,17 +463,17 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait CfgDiag {
|
pub trait CfgDiag {
|
||||||
fn emit_error<F>(&mut self, f: F) where F: FnMut(&SpanHandler);
|
fn emit_error<F>(&mut self, f: F) where F: FnMut(&Handler);
|
||||||
fn flag_gated<F>(&mut self, f: F) where F: FnMut(&mut Vec<GatedCfgAttr>);
|
fn flag_gated<F>(&mut self, f: F) where F: FnMut(&mut Vec<GatedCfgAttr>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CfgDiagReal<'a, 'b> {
|
pub struct CfgDiagReal<'a, 'b> {
|
||||||
pub diag: &'a SpanHandler,
|
pub diag: &'a Handler,
|
||||||
pub feature_gated_cfgs: &'b mut Vec<GatedCfgAttr>,
|
pub feature_gated_cfgs: &'b mut Vec<GatedCfgAttr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> CfgDiag for CfgDiagReal<'a, 'b> {
|
impl<'a, 'b> CfgDiag for CfgDiagReal<'a, 'b> {
|
||||||
fn emit_error<F>(&mut self, mut f: F) where F: FnMut(&SpanHandler) {
|
fn emit_error<F>(&mut self, mut f: F) where F: FnMut(&Handler) {
|
||||||
f(self.diag)
|
f(self.diag)
|
||||||
}
|
}
|
||||||
fn flag_gated<F>(&mut self, mut f: F) where F: FnMut(&mut Vec<GatedCfgAttr>) {
|
fn flag_gated<F>(&mut self, mut f: F) where F: FnMut(&mut Vec<GatedCfgAttr>) {
|
||||||
@ -486,7 +486,7 @@ struct CfgDiagSilent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CfgDiag for CfgDiagSilent {
|
impl CfgDiag for CfgDiagSilent {
|
||||||
fn emit_error<F>(&mut self, _: F) where F: FnMut(&SpanHandler) {
|
fn emit_error<F>(&mut self, _: F) where F: FnMut(&Handler) {
|
||||||
self.error = true;
|
self.error = true;
|
||||||
}
|
}
|
||||||
fn flag_gated<F>(&mut self, _: F) where F: FnMut(&mut Vec<GatedCfgAttr>) {}
|
fn flag_gated<F>(&mut self, _: F) where F: FnMut(&mut Vec<GatedCfgAttr>) {}
|
||||||
|
@ -1,900 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
pub use self::Level::*;
|
|
||||||
pub use self::RenderSpan::*;
|
|
||||||
pub use self::ColorConfig::*;
|
|
||||||
use self::Destination::*;
|
|
||||||
|
|
||||||
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
|
|
||||||
use diagnostics;
|
|
||||||
|
|
||||||
use std::cell::{RefCell, Cell};
|
|
||||||
use std::{cmp, error, fmt};
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::io;
|
|
||||||
use term;
|
|
||||||
|
|
||||||
/// maximum number of lines we will print for each error; arbitrary.
|
|
||||||
const MAX_LINES: usize = 6;
|
|
||||||
|
|
||||||
#[derive(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),
|
|
||||||
|
|
||||||
/// Similar to a FullSpan, but the cited position is the end of
|
|
||||||
/// the span, instead of the start. Used, at least, for telling
|
|
||||||
/// compiletest/runtest to look at the last line of the span
|
|
||||||
/// (since `end_highlight_lines` displays an arrow to the end
|
|
||||||
/// of the span).
|
|
||||||
EndSpan(Span),
|
|
||||||
|
|
||||||
/// A suggestion renders with both with an initial line for the
|
|
||||||
/// message, prefixed by file:linenum, followed by a summary
|
|
||||||
/// of hypothetical source code, where the `String` is spliced
|
|
||||||
/// into the lines in place of the code covered by the span.
|
|
||||||
Suggestion(Span, String),
|
|
||||||
|
|
||||||
/// 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) |
|
|
||||||
Suggestion(s, _) |
|
|
||||||
EndSpan(s) |
|
|
||||||
FileLine(s) =>
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
pub enum ColorConfig {
|
|
||||||
Auto,
|
|
||||||
Always,
|
|
||||||
Never
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Emitter {
|
|
||||||
fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>,
|
|
||||||
msg: &str, code: Option<&str>, lvl: Level);
|
|
||||||
fn custom_emit(&mut self, cm: &codemap::CodeMap,
|
|
||||||
sp: RenderSpan, msg: &str, lvl: Level);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used as a return value to signify a fatal error occurred. (It is also
|
|
||||||
/// used as the argument to panic at the moment, but that will eventually
|
|
||||||
/// not be true.)
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
#[must_use]
|
|
||||||
pub struct FatalError;
|
|
||||||
|
|
||||||
impl fmt::Display for FatalError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
||||||
write!(f, "parser fatal error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl error::Error for FatalError {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
"The parser has encountered a fatal error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signifies that the compiler died with an explicit call to `.bug`
|
|
||||||
/// or `.span_bug` rather than a failed assertion, etc.
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub struct ExplicitBug;
|
|
||||||
|
|
||||||
impl fmt::Display for ExplicitBug {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
||||||
write!(f, "parser internal bug")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl error::Error for ExplicitBug {
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
"The parser has encountered an internal bug"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A span-handler is like a handler but also
|
|
||||||
/// accepts span information for source-location
|
|
||||||
/// reporting.
|
|
||||||
pub struct SpanHandler {
|
|
||||||
pub handler: Handler,
|
|
||||||
pub cm: codemap::CodeMap,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SpanHandler {
|
|
||||||
pub fn new(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
|
|
||||||
SpanHandler {
|
|
||||||
handler: handler,
|
|
||||||
cm: cm,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn span_fatal(&self, sp: Span, msg: &str) -> FatalError {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Fatal);
|
|
||||||
return FatalError;
|
|
||||||
}
|
|
||||||
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> FatalError {
|
|
||||||
self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Fatal);
|
|
||||||
return FatalError;
|
|
||||||
}
|
|
||||||
pub fn span_err(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Error);
|
|
||||||
self.handler.bump_err_count();
|
|
||||||
}
|
|
||||||
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
|
|
||||||
self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Error);
|
|
||||||
self.handler.bump_err_count();
|
|
||||||
}
|
|
||||||
pub fn span_warn(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Warning);
|
|
||||||
}
|
|
||||||
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
|
|
||||||
self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Warning);
|
|
||||||
}
|
|
||||||
pub fn span_note(&self, sp: Span, msg: &str) {
|
|
||||||
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, EndSpan(sp), msg, Note);
|
|
||||||
}
|
|
||||||
pub fn span_help(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Help);
|
|
||||||
}
|
|
||||||
/// Prints out a message with a suggested edit of the code.
|
|
||||||
///
|
|
||||||
/// See `diagnostic::RenderSpan::Suggestion` for more information.
|
|
||||||
pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
|
|
||||||
self.handler.custom_emit(&self.cm, Suggestion(sp, suggestion), msg, Help);
|
|
||||||
}
|
|
||||||
pub fn fileline_note(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note);
|
|
||||||
}
|
|
||||||
pub fn fileline_help(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.custom_emit(&self.cm, FileLine(sp), msg, Help);
|
|
||||||
}
|
|
||||||
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Bug);
|
|
||||||
panic!(ExplicitBug);
|
|
||||||
}
|
|
||||||
pub fn span_bug_no_panic(&self, sp: Span, msg: &str) {
|
|
||||||
self.handler.emit(Some((&self.cm, sp)), msg, Bug);
|
|
||||||
self.handler.bump_err_count();
|
|
||||||
}
|
|
||||||
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
|
|
||||||
self.span_bug(sp, &format!("unimplemented {}", msg));
|
|
||||||
}
|
|
||||||
pub fn handler<'a>(&'a self) -> &'a Handler {
|
|
||||||
&self.handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A handler deals with errors; certain errors
|
|
||||||
/// (fatal, bug, unimpl) may cause immediate exit,
|
|
||||||
/// others log errors for later reporting.
|
|
||||||
pub struct Handler {
|
|
||||||
err_count: Cell<usize>,
|
|
||||||
emit: RefCell<Box<Emitter + Send>>,
|
|
||||||
pub can_emit_warnings: bool
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Handler {
|
|
||||||
pub fn new(color_config: ColorConfig,
|
|
||||||
registry: Option<diagnostics::registry::Registry>,
|
|
||||||
can_emit_warnings: bool) -> Handler {
|
|
||||||
let emitter = Box::new(EmitterWriter::stderr(color_config, registry));
|
|
||||||
Handler::with_emitter(can_emit_warnings, emitter)
|
|
||||||
}
|
|
||||||
pub fn with_emitter(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
|
|
||||||
Handler {
|
|
||||||
err_count: Cell::new(0),
|
|
||||||
emit: RefCell::new(e),
|
|
||||||
can_emit_warnings: can_emit_warnings
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn fatal(&self, msg: &str) -> FatalError {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Fatal);
|
|
||||||
FatalError
|
|
||||||
}
|
|
||||||
pub fn err(&self, msg: &str) {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Error);
|
|
||||||
self.bump_err_count();
|
|
||||||
}
|
|
||||||
pub fn bump_err_count(&self) {
|
|
||||||
self.err_count.set(self.err_count.get() + 1);
|
|
||||||
}
|
|
||||||
pub fn err_count(&self) -> usize {
|
|
||||||
self.err_count.get()
|
|
||||||
}
|
|
||||||
pub fn has_errors(&self) -> bool {
|
|
||||||
self.err_count.get() > 0
|
|
||||||
}
|
|
||||||
pub fn abort_if_errors(&self) {
|
|
||||||
let s;
|
|
||||||
match self.err_count.get() {
|
|
||||||
0 => return,
|
|
||||||
1 => s = "aborting due to previous error".to_string(),
|
|
||||||
_ => {
|
|
||||||
s = format!("aborting due to {} previous errors",
|
|
||||||
self.err_count.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
panic!(self.fatal(&s[..]));
|
|
||||||
}
|
|
||||||
pub fn warn(&self, msg: &str) {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Warning);
|
|
||||||
}
|
|
||||||
pub fn note(&self, msg: &str) {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Note);
|
|
||||||
}
|
|
||||||
pub fn help(&self, msg: &str) {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Help);
|
|
||||||
}
|
|
||||||
pub fn bug(&self, msg: &str) -> ! {
|
|
||||||
self.emit.borrow_mut().emit(None, msg, None, Bug);
|
|
||||||
panic!(ExplicitBug);
|
|
||||||
}
|
|
||||||
pub fn unimpl(&self, msg: &str) -> ! {
|
|
||||||
self.bug(&format!("unimplemented {}", msg));
|
|
||||||
}
|
|
||||||
pub fn emit(&self,
|
|
||||||
cmsp: Option<(&codemap::CodeMap, Span)>,
|
|
||||||
msg: &str,
|
|
||||||
lvl: Level) {
|
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
|
||||||
self.emit.borrow_mut().emit(cmsp, msg, None, lvl);
|
|
||||||
}
|
|
||||||
pub fn emit_with_code(&self,
|
|
||||||
cmsp: Option<(&codemap::CodeMap, Span)>,
|
|
||||||
msg: &str,
|
|
||||||
code: &str,
|
|
||||||
lvl: Level) {
|
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
|
||||||
self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl);
|
|
||||||
}
|
|
||||||
pub fn custom_emit(&self, cm: &codemap::CodeMap,
|
|
||||||
sp: RenderSpan, msg: &str, lvl: Level) {
|
|
||||||
if lvl == Warning && !self.can_emit_warnings { return }
|
|
||||||
self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, PartialEq, Clone, Debug)]
|
|
||||||
pub enum Level {
|
|
||||||
Bug,
|
|
||||||
Fatal,
|
|
||||||
Error,
|
|
||||||
Warning,
|
|
||||||
Note,
|
|
||||||
Help,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Level {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
match *self {
|
|
||||||
Bug => "error: internal compiler error".fmt(f),
|
|
||||||
Fatal | Error => "error".fmt(f),
|
|
||||||
Warning => "warning".fmt(f),
|
|
||||||
Note => "note".fmt(f),
|
|
||||||
Help => "help".fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Level {
|
|
||||||
fn color(self) -> term::color::Color {
|
|
||||||
match self {
|
|
||||||
Bug | Fatal | Error => term::color::BRIGHT_RED,
|
|
||||||
Warning => term::color::BRIGHT_YELLOW,
|
|
||||||
Note => term::color::BRIGHT_GREEN,
|
|
||||||
Help => term::color::BRIGHT_CYAN,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EmitterWriter {
|
|
||||||
dst: Destination,
|
|
||||||
registry: Option<diagnostics::registry::Registry>
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Destination {
|
|
||||||
Terminal(Box<term::StderrTerminal>),
|
|
||||||
Raw(Box<Write + Send>),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Do not use this for messages that end in `\n` – use `println_maybe_styled` instead. See
|
|
||||||
/// `EmitterWriter::print_maybe_styled` for details.
|
|
||||||
macro_rules! print_maybe_styled {
|
|
||||||
($writer: expr, $style: expr, $($arg: tt)*) => {
|
|
||||||
$writer.print_maybe_styled(format_args!($($arg)*), $style, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! println_maybe_styled {
|
|
||||||
($writer: expr, $style: expr, $($arg: tt)*) => {
|
|
||||||
$writer.print_maybe_styled(format_args!($($arg)*), $style, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmitterWriter {
|
|
||||||
pub fn stderr(color_config: ColorConfig,
|
|
||||||
registry: Option<diagnostics::registry::Registry>) -> EmitterWriter {
|
|
||||||
let stderr = io::stderr();
|
|
||||||
|
|
||||||
let use_color = match color_config {
|
|
||||||
Always => true,
|
|
||||||
Never => false,
|
|
||||||
Auto => stderr_isatty(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if use_color {
|
|
||||||
let dst = match term::stderr() {
|
|
||||||
Some(t) => Terminal(t),
|
|
||||||
None => Raw(Box::new(stderr)),
|
|
||||||
};
|
|
||||||
EmitterWriter { dst: dst, registry: registry }
|
|
||||||
} else {
|
|
||||||
EmitterWriter { dst: Raw(Box::new(stderr)), registry: registry }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(dst: Box<Write + Send>,
|
|
||||||
registry: Option<diagnostics::registry::Registry>) -> EmitterWriter {
|
|
||||||
EmitterWriter { dst: Raw(dst), registry: registry }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_maybe_styled(&mut self,
|
|
||||||
args: fmt::Arguments,
|
|
||||||
color: term::Attr,
|
|
||||||
print_newline_at_end: bool) -> io::Result<()> {
|
|
||||||
match self.dst {
|
|
||||||
Terminal(ref mut t) => {
|
|
||||||
try!(t.attr(color));
|
|
||||||
// If `msg` ends in a newline, we need to reset the color before
|
|
||||||
// the newline. We're making the assumption that we end up writing
|
|
||||||
// to a `LineBufferedWriter`, which means that emitting the reset
|
|
||||||
// after the newline ends up buffering the reset until we print
|
|
||||||
// another line or exit. Buffering the reset is a problem if we're
|
|
||||||
// sharing the terminal with any other programs (e.g. other rustc
|
|
||||||
// instances via `make -jN`).
|
|
||||||
//
|
|
||||||
// Note that if `msg` contains any internal newlines, this will
|
|
||||||
// result in the `LineBufferedWriter` flushing twice instead of
|
|
||||||
// once, which still leaves the opportunity for interleaved output
|
|
||||||
// to be miscolored. We assume this is rare enough that we don't
|
|
||||||
// have to worry about it.
|
|
||||||
try!(t.write_fmt(args));
|
|
||||||
try!(t.reset());
|
|
||||||
if print_newline_at_end {
|
|
||||||
t.write_all(b"\n")
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Raw(ref mut w) => {
|
|
||||||
try!(w.write_fmt(args));
|
|
||||||
if print_newline_at_end {
|
|
||||||
w.write_all(b"\n")
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_diagnostic(&mut self, topic: &str, lvl: Level,
|
|
||||||
msg: &str, code: Option<&str>) -> io::Result<()> {
|
|
||||||
if !topic.is_empty() {
|
|
||||||
try!(write!(&mut self.dst, "{} ", topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(print_maybe_styled!(self, term::Attr::ForegroundColor(lvl.color()),
|
|
||||||
"{}: ", lvl.to_string()));
|
|
||||||
try!(print_maybe_styled!(self, term::Attr::Bold, "{}", msg));
|
|
||||||
|
|
||||||
match code {
|
|
||||||
Some(code) => {
|
|
||||||
let style = term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA);
|
|
||||||
try!(print_maybe_styled!(self, style, " [{}]", code.clone()));
|
|
||||||
}
|
|
||||||
None => ()
|
|
||||||
}
|
|
||||||
try!(write!(&mut self.dst, "\n"));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn emit_(&mut self, cm: &codemap::CodeMap, rsp: RenderSpan,
|
|
||||||
msg: &str, code: Option<&str>, lvl: Level) -> io::Result<()> {
|
|
||||||
let sp = rsp.span();
|
|
||||||
|
|
||||||
// We cannot check equality directly with COMMAND_LINE_SP
|
|
||||||
// since PartialEq is manually implemented to ignore the ExpnId
|
|
||||||
let ss = if sp.expn_id == COMMAND_LINE_EXPN {
|
|
||||||
"<command line option>".to_string()
|
|
||||||
} else if let EndSpan(_) = rsp {
|
|
||||||
let span_end = Span { lo: sp.hi, hi: sp.hi, expn_id: sp.expn_id};
|
|
||||||
cm.span_to_string(span_end)
|
|
||||||
} else {
|
|
||||||
cm.span_to_string(sp)
|
|
||||||
};
|
|
||||||
|
|
||||||
try!(self.print_diagnostic(&ss[..], lvl, msg, code));
|
|
||||||
|
|
||||||
match rsp {
|
|
||||||
FullSpan(_) => {
|
|
||||||
try!(self.highlight_lines(cm, sp, lvl, cm.span_to_lines(sp)));
|
|
||||||
try!(self.print_macro_backtrace(cm, sp));
|
|
||||||
}
|
|
||||||
EndSpan(_) => {
|
|
||||||
try!(self.end_highlight_lines(cm, sp, lvl, cm.span_to_lines(sp)));
|
|
||||||
try!(self.print_macro_backtrace(cm, sp));
|
|
||||||
}
|
|
||||||
Suggestion(_, ref suggestion) => {
|
|
||||||
try!(self.highlight_suggestion(cm, sp, suggestion));
|
|
||||||
try!(self.print_macro_backtrace(cm, sp));
|
|
||||||
}
|
|
||||||
FileLine(..) => {
|
|
||||||
// no source text in this case!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match code {
|
|
||||||
Some(code) =>
|
|
||||||
match self.registry.as_ref().and_then(|registry| registry.find_description(code)) {
|
|
||||||
Some(_) => {
|
|
||||||
try!(self.print_diagnostic(&ss[..], Help,
|
|
||||||
&format!("run `rustc --explain {}` to see a \
|
|
||||||
detailed explanation", code), None));
|
|
||||||
}
|
|
||||||
None => ()
|
|
||||||
},
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn highlight_suggestion(&mut self,
|
|
||||||
cm: &codemap::CodeMap,
|
|
||||||
sp: Span,
|
|
||||||
suggestion: &str)
|
|
||||||
-> io::Result<()>
|
|
||||||
{
|
|
||||||
let lines = cm.span_to_lines(sp).unwrap();
|
|
||||||
assert!(!lines.lines.is_empty());
|
|
||||||
|
|
||||||
// To build up the result, we want to take the snippet from the first
|
|
||||||
// line that precedes the span, prepend that with the suggestion, and
|
|
||||||
// then append the snippet from the last line that trails the span.
|
|
||||||
let fm = &lines.file;
|
|
||||||
|
|
||||||
let first_line = &lines.lines[0];
|
|
||||||
let prefix = fm.get_line(first_line.line_index)
|
|
||||||
.map(|l| &l[..first_line.start_col.0])
|
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
let last_line = lines.lines.last().unwrap();
|
|
||||||
let suffix = fm.get_line(last_line.line_index)
|
|
||||||
.map(|l| &l[last_line.end_col.0..])
|
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
let complete = format!("{}{}{}", prefix, suggestion, suffix);
|
|
||||||
|
|
||||||
// print the suggestion without any line numbers, but leave
|
|
||||||
// space for them. This helps with lining up with previous
|
|
||||||
// snippets from the actual error being reported.
|
|
||||||
let fm = &*lines.file;
|
|
||||||
let mut lines = complete.lines();
|
|
||||||
for (line, line_index) in lines.by_ref().take(MAX_LINES).zip(first_line.line_index..) {
|
|
||||||
let elided_line_num = format!("{}", line_index+1);
|
|
||||||
try!(write!(&mut self.dst, "{0}:{1:2$} {3}\n",
|
|
||||||
fm.name, "", elided_line_num.len(), line));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we elided some lines, add an ellipsis
|
|
||||||
if lines.next().is_some() {
|
|
||||||
let elided_line_num = format!("{}", first_line.line_index + MAX_LINES + 1);
|
|
||||||
try!(write!(&mut self.dst, "{0:1$} {0:2$} ...\n",
|
|
||||||
"", fm.name.len(), elided_line_num.len()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn highlight_lines(&mut self,
|
|
||||||
cm: &codemap::CodeMap,
|
|
||||||
sp: Span,
|
|
||||||
lvl: Level,
|
|
||||||
lines: codemap::FileLinesResult)
|
|
||||||
-> io::Result<()>
|
|
||||||
{
|
|
||||||
let lines = match lines {
|
|
||||||
Ok(lines) => lines,
|
|
||||||
Err(_) => {
|
|
||||||
try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n"));
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let fm = &*lines.file;
|
|
||||||
|
|
||||||
let line_strings: Option<Vec<&str>> =
|
|
||||||
lines.lines.iter()
|
|
||||||
.map(|info| fm.get_line(info.line_index))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let line_strings = match line_strings {
|
|
||||||
None => { return Ok(()); }
|
|
||||||
Some(line_strings) => line_strings
|
|
||||||
};
|
|
||||||
|
|
||||||
// Display only the first MAX_LINES lines.
|
|
||||||
let all_lines = lines.lines.len();
|
|
||||||
let display_lines = cmp::min(all_lines, MAX_LINES);
|
|
||||||
let display_line_infos = &lines.lines[..display_lines];
|
|
||||||
let display_line_strings = &line_strings[..display_lines];
|
|
||||||
|
|
||||||
// Calculate the widest number to format evenly and fix #11715
|
|
||||||
assert!(display_line_infos.len() > 0);
|
|
||||||
let mut max_line_num = display_line_infos[display_line_infos.len() - 1].line_index + 1;
|
|
||||||
let mut digits = 0;
|
|
||||||
while max_line_num > 0 {
|
|
||||||
max_line_num /= 10;
|
|
||||||
digits += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print the offending lines
|
|
||||||
for (line_info, line) in display_line_infos.iter().zip(display_line_strings) {
|
|
||||||
try!(write!(&mut self.dst, "{}:{:>width$} {}\n",
|
|
||||||
fm.name,
|
|
||||||
line_info.line_index + 1,
|
|
||||||
line,
|
|
||||||
width=digits));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we elided something, put an ellipsis.
|
|
||||||
if display_lines < all_lines {
|
|
||||||
let last_line_index = display_line_infos.last().unwrap().line_index;
|
|
||||||
let s = format!("{}:{} ", fm.name, last_line_index + 1);
|
|
||||||
try!(write!(&mut self.dst, "{0:1$}...\n", "", s.len()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME (#3260)
|
|
||||||
// If there's one line at fault we can easily point to the problem
|
|
||||||
if lines.lines.len() == 1 {
|
|
||||||
let lo = cm.lookup_char_pos(sp.lo);
|
|
||||||
let mut digits = 0;
|
|
||||||
let mut num = (lines.lines[0].line_index + 1) / 10;
|
|
||||||
|
|
||||||
// how many digits must be indent past?
|
|
||||||
while num > 0 { num /= 10; digits += 1; }
|
|
||||||
|
|
||||||
let mut s = String::new();
|
|
||||||
// Skip is the number of characters we need to skip because they are
|
|
||||||
// part of the 'filename:line ' part of the previous line.
|
|
||||||
let skip = fm.name.chars().count() + digits + 3;
|
|
||||||
for _ in 0..skip {
|
|
||||||
s.push(' ');
|
|
||||||
}
|
|
||||||
if let Some(orig) = fm.get_line(lines.lines[0].line_index) {
|
|
||||||
let mut col = skip;
|
|
||||||
let mut lastc = ' ';
|
|
||||||
let mut iter = orig.chars().enumerate();
|
|
||||||
for (pos, ch) in iter.by_ref() {
|
|
||||||
lastc = ch;
|
|
||||||
if pos >= lo.col.to_usize() { break; }
|
|
||||||
// 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 ch {
|
|
||||||
'\t' => {
|
|
||||||
col += 8 - col%8;
|
|
||||||
s.push('\t');
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
col += 1;
|
|
||||||
s.push(' ');
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(write!(&mut self.dst, "{}", s));
|
|
||||||
let mut s = String::from("^");
|
|
||||||
let count = match lastc {
|
|
||||||
// Most terminals have a tab stop every eight columns by default
|
|
||||||
'\t' => 8 - col%8,
|
|
||||||
_ => 1,
|
|
||||||
};
|
|
||||||
col += count;
|
|
||||||
s.extend(::std::iter::repeat('~').take(count));
|
|
||||||
|
|
||||||
let hi = cm.lookup_char_pos(sp.hi);
|
|
||||||
if hi.col != lo.col {
|
|
||||||
for (pos, ch) in iter {
|
|
||||||
if pos >= hi.col.to_usize() { break; }
|
|
||||||
let count = match ch {
|
|
||||||
'\t' => 8 - col%8,
|
|
||||||
_ => 1,
|
|
||||||
};
|
|
||||||
col += count;
|
|
||||||
s.extend(::std::iter::repeat('~').take(count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.len() > 1 {
|
|
||||||
// One extra squiggly is replaced by a "^"
|
|
||||||
s.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(println_maybe_styled!(self, term::Attr::ForegroundColor(lvl.color()),
|
|
||||||
"{}", s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Here are the differences between this and the normal `highlight_lines`:
|
|
||||||
/// `end_highlight_lines` will always put arrow on the last byte of the
|
|
||||||
/// span (instead of the first byte). Also, when the span is too long (more
|
|
||||||
/// than 6 lines), `end_highlight_lines` will print the first line, then
|
|
||||||
/// dot dot dot, then last line, whereas `highlight_lines` prints the first
|
|
||||||
/// six lines.
|
|
||||||
#[allow(deprecated)]
|
|
||||||
fn end_highlight_lines(&mut self,
|
|
||||||
cm: &codemap::CodeMap,
|
|
||||||
sp: Span,
|
|
||||||
lvl: Level,
|
|
||||||
lines: codemap::FileLinesResult)
|
|
||||||
-> io::Result<()> {
|
|
||||||
let lines = match lines {
|
|
||||||
Ok(lines) => lines,
|
|
||||||
Err(_) => {
|
|
||||||
try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n"));
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let fm = &*lines.file;
|
|
||||||
|
|
||||||
let lines = &lines.lines[..];
|
|
||||||
if lines.len() > MAX_LINES {
|
|
||||||
if let Some(line) = fm.get_line(lines[0].line_index) {
|
|
||||||
try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
|
|
||||||
lines[0].line_index + 1, line));
|
|
||||||
}
|
|
||||||
try!(write!(&mut self.dst, "...\n"));
|
|
||||||
let last_line_index = lines[lines.len() - 1].line_index;
|
|
||||||
if let Some(last_line) = fm.get_line(last_line_index) {
|
|
||||||
try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
|
|
||||||
last_line_index + 1, last_line));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for line_info in lines {
|
|
||||||
if let Some(line) = fm.get_line(line_info.line_index) {
|
|
||||||
try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
|
|
||||||
line_info.line_index + 1, line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let last_line_start = format!("{}:{} ", fm.name, lines[lines.len()-1].line_index + 1);
|
|
||||||
let hi = cm.lookup_char_pos(sp.hi);
|
|
||||||
let skip = last_line_start.chars().count();
|
|
||||||
let mut s = String::new();
|
|
||||||
for _ in 0..skip {
|
|
||||||
s.push(' ');
|
|
||||||
}
|
|
||||||
if let Some(orig) = fm.get_line(lines[0].line_index) {
|
|
||||||
let iter = orig.chars().enumerate();
|
|
||||||
for (pos, ch) in iter {
|
|
||||||
// Span seems to use half-opened interval, so subtract 1
|
|
||||||
if pos >= hi.col.to_usize() - 1 { break; }
|
|
||||||
// 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 ch {
|
|
||||||
'\t' => s.push('\t'),
|
|
||||||
_ => s.push(' '),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.push('^');
|
|
||||||
println_maybe_styled!(self, term::Attr::ForegroundColor(lvl.color()),
|
|
||||||
"{}", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_macro_backtrace(&mut self,
|
|
||||||
cm: &codemap::CodeMap,
|
|
||||||
sp: Span)
|
|
||||||
-> io::Result<()> {
|
|
||||||
let mut last_span = codemap::DUMMY_SP;
|
|
||||||
let mut sp_opt = Some(sp);
|
|
||||||
|
|
||||||
while let Some(sp) = sp_opt {
|
|
||||||
sp_opt = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> io::Result<_> {
|
|
||||||
match expn_info {
|
|
||||||
Some(ei) => {
|
|
||||||
let (pre, post) = match ei.callee.format {
|
|
||||||
codemap::MacroAttribute(..) => ("#[", "]"),
|
|
||||||
codemap::MacroBang(..) => ("", "!"),
|
|
||||||
};
|
|
||||||
// Don't print recursive invocations
|
|
||||||
if ei.call_site != last_span {
|
|
||||||
last_span = ei.call_site;
|
|
||||||
|
|
||||||
let mut diag_string = format!("in this expansion of {}{}{}",
|
|
||||||
pre,
|
|
||||||
ei.callee.name(),
|
|
||||||
post);
|
|
||||||
|
|
||||||
if let Some(def_site_span) = ei.callee.span {
|
|
||||||
diag_string.push_str(&format!(" (defined in {})",
|
|
||||||
cm.span_to_filename(def_site_span)));
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(self.print_diagnostic(&cm.span_to_string(ei.call_site),
|
|
||||||
Note,
|
|
||||||
&diag_string,
|
|
||||||
None));
|
|
||||||
}
|
|
||||||
Ok(Some(ei.call_site))
|
|
||||||
}
|
|
||||||
None => Ok(None)
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
fn stderr_isatty() -> bool {
|
|
||||||
use libc;
|
|
||||||
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
|
|
||||||
}
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stderr_isatty() -> bool {
|
|
||||||
type DWORD = u32;
|
|
||||||
type BOOL = i32;
|
|
||||||
type HANDLE = *mut u8;
|
|
||||||
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
|
|
||||||
extern "system" {
|
|
||||||
fn GetStdHandle(which: DWORD) -> HANDLE;
|
|
||||||
fn GetConsoleMode(hConsoleHandle: HANDLE,
|
|
||||||
lpMode: *mut DWORD) -> BOOL;
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
let handle = GetStdHandle(STD_ERROR_HANDLE);
|
|
||||||
let mut out = 0;
|
|
||||||
GetConsoleMode(handle, &mut out) != 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Write for Destination {
|
|
||||||
fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {
|
|
||||||
match *self {
|
|
||||||
Terminal(ref mut t) => t.write(bytes),
|
|
||||||
Raw(ref mut w) => w.write(bytes),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
match *self {
|
|
||||||
Terminal(ref mut t) => t.flush(),
|
|
||||||
Raw(ref mut w) => w.flush(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Emitter for EmitterWriter {
|
|
||||||
fn emit(&mut self,
|
|
||||||
cmsp: Option<(&codemap::CodeMap, Span)>,
|
|
||||||
msg: &str, code: Option<&str>, lvl: Level) {
|
|
||||||
let error = match cmsp {
|
|
||||||
Some((cm, COMMAND_LINE_SP)) => self.emit_(cm,
|
|
||||||
FileLine(COMMAND_LINE_SP),
|
|
||||||
msg, code, lvl),
|
|
||||||
Some((cm, sp)) => self.emit_(cm, FullSpan(sp), msg, code, lvl),
|
|
||||||
None => self.print_diagnostic("", lvl, msg, code),
|
|
||||||
};
|
|
||||||
|
|
||||||
match error {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(e) => panic!("failed to print diagnostics: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn custom_emit(&mut self, cm: &codemap::CodeMap,
|
|
||||||
sp: RenderSpan, msg: &str, lvl: Level) {
|
|
||||||
match self.emit_(cm, sp, msg, None, lvl) {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(e) => panic!("failed to print diagnostics: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn expect<T, M>(diag: &SpanHandler, opt: Option<T>, msg: M) -> T where
|
|
||||||
M: FnOnce() -> String,
|
|
||||||
{
|
|
||||||
match opt {
|
|
||||||
Some(t) => t,
|
|
||||||
None => diag.handler().bug(&msg()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::{EmitterWriter, Level};
|
|
||||||
use codemap::{mk_sp, CodeMap};
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::str::from_utf8;
|
|
||||||
|
|
||||||
// Diagnostic doesn't align properly in span where line number increases by one digit
|
|
||||||
#[test]
|
|
||||||
fn test_hilight_suggestion_issue_11715() {
|
|
||||||
struct Sink(Arc<Mutex<Vec<u8>>>);
|
|
||||||
impl Write for Sink {
|
|
||||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
|
||||||
Write::write(&mut *self.0.lock().unwrap(), data)
|
|
||||||
}
|
|
||||||
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
|
||||||
}
|
|
||||||
let data = Arc::new(Mutex::new(Vec::new()));
|
|
||||||
let mut ew = EmitterWriter::new(Box::new(Sink(data.clone())), None);
|
|
||||||
let cm = CodeMap::new();
|
|
||||||
let content = "abcdefg
|
|
||||||
koksi
|
|
||||||
line3
|
|
||||||
line4
|
|
||||||
cinq
|
|
||||||
line6
|
|
||||||
line7
|
|
||||||
line8
|
|
||||||
line9
|
|
||||||
line10
|
|
||||||
e-lä-vän
|
|
||||||
tolv
|
|
||||||
dreizehn
|
|
||||||
";
|
|
||||||
let file = cm.new_filemap_and_lines("dummy.txt", content);
|
|
||||||
let start = file.lines.borrow()[7];
|
|
||||||
let end = file.lines.borrow()[11];
|
|
||||||
let sp = mk_sp(start, end);
|
|
||||||
let lvl = Level::Error;
|
|
||||||
println!("span_to_lines");
|
|
||||||
let lines = cm.span_to_lines(sp);
|
|
||||||
println!("highlight_lines");
|
|
||||||
ew.highlight_lines(&cm, sp, lvl, lines).unwrap();
|
|
||||||
println!("done");
|
|
||||||
let vec = data.lock().unwrap().clone();
|
|
||||||
let vec: &[u8] = &vec;
|
|
||||||
let str = from_utf8(vec).unwrap();
|
|
||||||
println!("{}", str);
|
|
||||||
assert_eq!(str, "dummy.txt: 8 line8\n\
|
|
||||||
dummy.txt: 9 line9\n\
|
|
||||||
dummy.txt:10 line10\n\
|
|
||||||
dummy.txt:11 e-lä-vän\n\
|
|
||||||
dummy.txt:12 tolv\n");
|
|
||||||
}
|
|
||||||
}
|
|
@ -720,7 +720,7 @@ impl<'a> ExtCtxt<'a> {
|
|||||||
self.parse_sess.span_diagnostic.fileline_help(sp, msg);
|
self.parse_sess.span_diagnostic.fileline_help(sp, msg);
|
||||||
}
|
}
|
||||||
pub fn bug(&self, msg: &str) -> ! {
|
pub fn bug(&self, msg: &str) -> ! {
|
||||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
self.parse_sess.span_diagnostic.bug(msg);
|
||||||
}
|
}
|
||||||
pub fn trace_macros(&self) -> bool {
|
pub fn trace_macros(&self) -> bool {
|
||||||
self.ecfg.trace_mac
|
self.ecfg.trace_mac
|
||||||
|
@ -1301,7 +1301,7 @@ pub fn expand_crate(mut cx: ExtCtxt,
|
|||||||
|
|
||||||
let mut ret = expander.fold_crate(c);
|
let mut ret = expander.fold_crate(c);
|
||||||
ret.exported_macros = expander.cx.exported_macros.clone();
|
ret.exported_macros = expander.cx.exported_macros.clone();
|
||||||
cx.parse_sess.span_diagnostic.handler().abort_if_errors();
|
cx.parse_sess.span_diagnostic.abort_if_errors();
|
||||||
ret
|
ret
|
||||||
};
|
};
|
||||||
return (ret, cx.syntax_env.names);
|
return (ret, cx.syntax_env.names);
|
||||||
|
@ -12,7 +12,7 @@ use self::LockstepIterSize::*;
|
|||||||
use ast;
|
use ast;
|
||||||
use ast::{TokenTree, Ident, Name};
|
use ast::{TokenTree, Ident, Name};
|
||||||
use codemap::{Span, DUMMY_SP};
|
use codemap::{Span, DUMMY_SP};
|
||||||
use diagnostic::SpanHandler;
|
use errors::Handler;
|
||||||
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
|
||||||
use parse::token::{Eof, DocComment, Interpolated, MatchNt, SubstNt};
|
use parse::token::{Eof, DocComment, Interpolated, MatchNt, SubstNt};
|
||||||
use parse::token::{Token, NtIdent, SpecialMacroVar};
|
use parse::token::{Token, NtIdent, SpecialMacroVar};
|
||||||
@ -34,7 +34,7 @@ struct TtFrame {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TtReader<'a> {
|
pub struct TtReader<'a> {
|
||||||
pub sp_diag: &'a SpanHandler,
|
pub sp_diag: &'a Handler,
|
||||||
/// the unzipped tree:
|
/// the unzipped tree:
|
||||||
stack: Vec<TtFrame>,
|
stack: Vec<TtFrame>,
|
||||||
/* for MBE-style macro transcription */
|
/* for MBE-style macro transcription */
|
||||||
@ -55,7 +55,7 @@ pub struct TtReader<'a> {
|
|||||||
/// This can do Macro-By-Example transcription. On the other hand, if
|
/// This can do Macro-By-Example transcription. On the other hand, if
|
||||||
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
|
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
|
||||||
/// (and should) be None.
|
/// (and should) be None.
|
||||||
pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
|
pub fn new_tt_reader<'a>(sp_diag: &'a Handler,
|
||||||
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
|
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
|
||||||
imported_from: Option<Ident>,
|
imported_from: Option<Ident>,
|
||||||
src: Vec<ast::TokenTree>)
|
src: Vec<ast::TokenTree>)
|
||||||
@ -69,7 +69,7 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
|
|||||||
/// This can do Macro-By-Example transcription. On the other hand, if
|
/// This can do Macro-By-Example transcription. On the other hand, if
|
||||||
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
|
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
|
||||||
/// (and should) be None.
|
/// (and should) be None.
|
||||||
pub fn new_tt_reader_with_doc_flag<'a>(sp_diag: &'a SpanHandler,
|
pub fn new_tt_reader_with_doc_flag<'a>(sp_diag: &'a Handler,
|
||||||
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
|
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
|
||||||
imported_from: Option<Ident>,
|
imported_from: Option<Ident>,
|
||||||
src: Vec<ast::TokenTree>,
|
src: Vec<ast::TokenTree>,
|
||||||
|
@ -32,7 +32,7 @@ use ast;
|
|||||||
use attr;
|
use attr;
|
||||||
use attr::AttrMetaMethods;
|
use attr::AttrMetaMethods;
|
||||||
use codemap::{CodeMap, Span};
|
use codemap::{CodeMap, Span};
|
||||||
use diagnostic::SpanHandler;
|
use errors::Handler;
|
||||||
use visit;
|
use visit;
|
||||||
use visit::{FnKind, Visitor};
|
use visit::{FnKind, Visitor};
|
||||||
use parse::token::InternedString;
|
use parse::token::InternedString;
|
||||||
@ -446,7 +446,7 @@ impl PartialOrd for GatedCfgAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GatedCfgAttr {
|
impl GatedCfgAttr {
|
||||||
pub fn check_and_emit(&self, diagnostic: &SpanHandler, features: &Features) {
|
pub fn check_and_emit(&self, diagnostic: &Handler, features: &Features) {
|
||||||
match *self {
|
match *self {
|
||||||
GatedCfgAttr::GatedCfg(ref cfg) => {
|
GatedCfgAttr::GatedCfg(ref cfg) => {
|
||||||
cfg.check_and_emit(diagnostic, features);
|
cfg.check_and_emit(diagnostic, features);
|
||||||
@ -476,7 +476,7 @@ impl GatedCfg {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn check_and_emit(&self, diagnostic: &SpanHandler, features: &Features) {
|
fn check_and_emit(&self, diagnostic: &Handler, features: &Features) {
|
||||||
let (cfg, feature, has_feature) = GATED_CFGS[self.index];
|
let (cfg, feature, has_feature) = GATED_CFGS[self.index];
|
||||||
if !has_feature(features) {
|
if !has_feature(features) {
|
||||||
let explain = format!("`cfg({})` is experimental and subject to change", cfg);
|
let explain = format!("`cfg({})` is experimental and subject to change", cfg);
|
||||||
@ -595,21 +595,21 @@ const EXPLAIN_PUSHPOP_UNSAFE: &'static str =
|
|||||||
const EXPLAIN_STMT_ATTR_SYNTAX: &'static str =
|
const EXPLAIN_STMT_ATTR_SYNTAX: &'static str =
|
||||||
"attributes on non-item statements and expressions are experimental.";
|
"attributes on non-item statements and expressions are experimental.";
|
||||||
|
|
||||||
pub fn check_for_box_syntax(f: Option<&Features>, diag: &SpanHandler, span: Span) {
|
pub fn check_for_box_syntax(f: Option<&Features>, diag: &Handler, span: Span) {
|
||||||
if let Some(&Features { allow_box: true, .. }) = f {
|
if let Some(&Features { allow_box: true, .. }) = f {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit_feature_err(diag, "box_syntax", span, GateIssue::Language, EXPLAIN_BOX_SYNTAX);
|
emit_feature_err(diag, "box_syntax", span, GateIssue::Language, EXPLAIN_BOX_SYNTAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_placement_in(f: Option<&Features>, diag: &SpanHandler, span: Span) {
|
pub fn check_for_placement_in(f: Option<&Features>, diag: &Handler, span: Span) {
|
||||||
if let Some(&Features { allow_placement_in: true, .. }) = f {
|
if let Some(&Features { allow_placement_in: true, .. }) = f {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit_feature_err(diag, "placement_in_syntax", span, GateIssue::Language, EXPLAIN_PLACEMENT_IN);
|
emit_feature_err(diag, "placement_in_syntax", span, GateIssue::Language, EXPLAIN_PLACEMENT_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &SpanHandler, span: Span) {
|
pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &Handler, span: Span) {
|
||||||
if let Some(&Features { allow_pushpop_unsafe: true, .. }) = f {
|
if let Some(&Features { allow_pushpop_unsafe: true, .. }) = f {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -618,7 +618,7 @@ pub fn check_for_pushpop_syntax(f: Option<&Features>, diag: &SpanHandler, span:
|
|||||||
|
|
||||||
struct Context<'a> {
|
struct Context<'a> {
|
||||||
features: Vec<&'static str>,
|
features: Vec<&'static str>,
|
||||||
span_handler: &'a SpanHandler,
|
span_handler: &'a Handler,
|
||||||
cm: &'a CodeMap,
|
cm: &'a CodeMap,
|
||||||
plugin_attributes: &'a [(String, AttributeType)],
|
plugin_attributes: &'a [(String, AttributeType)],
|
||||||
}
|
}
|
||||||
@ -704,7 +704,7 @@ pub enum GateIssue {
|
|||||||
Library(Option<u32>)
|
Library(Option<u32>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, issue: GateIssue,
|
pub fn emit_feature_err(diag: &Handler, feature: &str, span: Span, issue: GateIssue,
|
||||||
explain: &str) {
|
explain: &str) {
|
||||||
let issue = match issue {
|
let issue = match issue {
|
||||||
GateIssue::Language => find_lang_feature_issue(feature),
|
GateIssue::Language => find_lang_feature_issue(feature),
|
||||||
@ -1064,7 +1064,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
|
fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
|
||||||
krate: &ast::Crate,
|
krate: &ast::Crate,
|
||||||
plugin_attributes: &[(String, AttributeType)],
|
plugin_attributes: &[(String, AttributeType)],
|
||||||
check: F)
|
check: F)
|
||||||
@ -1161,13 +1161,13 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate_macros(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate)
|
pub fn check_crate_macros(cm: &CodeMap, span_handler: &Handler, krate: &ast::Crate)
|
||||||
-> Features {
|
-> Features {
|
||||||
check_crate_inner(cm, span_handler, krate, &[] as &'static [_],
|
check_crate_inner(cm, span_handler, krate, &[] as &'static [_],
|
||||||
|ctx, krate| visit::walk_crate(&mut MacroVisitor { context: ctx }, krate))
|
|ctx, krate| visit::walk_crate(&mut MacroVisitor { context: ctx }, krate))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
|
pub fn check_crate(cm: &CodeMap, span_handler: &Handler, krate: &ast::Crate,
|
||||||
plugin_attributes: &[(String, AttributeType)],
|
plugin_attributes: &[(String, AttributeType)],
|
||||||
unstable: UnstableFeatures) -> Features
|
unstable: UnstableFeatures) -> Features
|
||||||
{
|
{
|
||||||
@ -1192,7 +1192,7 @@ pub enum UnstableFeatures {
|
|||||||
Cheat
|
Cheat
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_stage_features(span_handler: &SpanHandler, krate: &ast::Crate,
|
fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
|
||||||
unstable: UnstableFeatures) {
|
unstable: UnstableFeatures) {
|
||||||
let allow_features = match unstable {
|
let allow_features = match unstable {
|
||||||
UnstableFeatures::Allow => true,
|
UnstableFeatures::Allow => true,
|
||||||
|
@ -52,7 +52,7 @@ extern crate serialize as rustc_serialize; // used by deriving
|
|||||||
macro_rules! panictry {
|
macro_rules! panictry {
|
||||||
($e:expr) => ({
|
($e:expr) => ({
|
||||||
use std::result::Result::{Ok, Err};
|
use std::result::Result::{Ok, Err};
|
||||||
use diagnostic::FatalError;
|
use errors::FatalError;
|
||||||
match $e {
|
match $e {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(FatalError) => panic!(FatalError)
|
Err(FatalError) => panic!(FatalError)
|
||||||
@ -78,6 +78,8 @@ pub mod diagnostics {
|
|||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod errors;
|
||||||
|
|
||||||
pub mod syntax {
|
pub mod syntax {
|
||||||
pub use ext;
|
pub use ext;
|
||||||
pub use parse;
|
pub use parse;
|
||||||
@ -90,7 +92,6 @@ pub mod ast_util;
|
|||||||
pub mod attr;
|
pub mod attr;
|
||||||
pub mod codemap;
|
pub mod codemap;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod diagnostic;
|
|
||||||
pub mod entry;
|
pub mod entry;
|
||||||
pub mod feature_gate;
|
pub mod feature_gate;
|
||||||
pub mod fold;
|
pub mod fold;
|
||||||
|
@ -12,7 +12,7 @@ pub use self::CommentStyle::*;
|
|||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{BytePos, CharPos, CodeMap, Pos};
|
use codemap::{BytePos, CharPos, CodeMap, Pos};
|
||||||
use diagnostic;
|
use errors;
|
||||||
use parse::lexer::is_block_doc_comment;
|
use parse::lexer::is_block_doc_comment;
|
||||||
use parse::lexer::{StringReader, TokenAndSpan};
|
use parse::lexer::{StringReader, TokenAndSpan};
|
||||||
use parse::lexer::{is_whitespace, Reader};
|
use parse::lexer::{is_whitespace, Reader};
|
||||||
@ -334,7 +334,7 @@ pub struct Literal {
|
|||||||
|
|
||||||
// it appears this function is called only from pprust... that's
|
// it appears this function is called only from pprust... that's
|
||||||
// probably not a good thing.
|
// probably not a good thing.
|
||||||
pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler,
|
pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
|
||||||
path: String,
|
path: String,
|
||||||
srdr: &mut Read)
|
srdr: &mut Read)
|
||||||
-> (Vec<Comment>, Vec<Literal>) {
|
-> (Vec<Comment>, Vec<Literal>) {
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
use ast;
|
use ast;
|
||||||
use codemap::{BytePos, CharPos, CodeMap, Pos, Span};
|
use codemap::{BytePos, CharPos, CodeMap, Pos, Span};
|
||||||
use codemap;
|
use codemap;
|
||||||
use diagnostic::FatalError;
|
use errors::{FatalError, Handler};
|
||||||
use diagnostic::SpanHandler;
|
|
||||||
use ext::tt::transcribe::tt_next_token;
|
use ext::tt::transcribe::tt_next_token;
|
||||||
use parse::token::str_to_ident;
|
use parse::token::str_to_ident;
|
||||||
use parse::token;
|
use parse::token;
|
||||||
@ -58,7 +57,7 @@ pub struct TokenAndSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct StringReader<'a> {
|
pub struct StringReader<'a> {
|
||||||
pub span_diagnostic: &'a SpanHandler,
|
pub span_diagnostic: &'a Handler,
|
||||||
/// The absolute offset within the codemap of the next character to read
|
/// The absolute offset within the codemap of the next character to read
|
||||||
pub pos: BytePos,
|
pub pos: BytePos,
|
||||||
/// The absolute offset within the codemap of the last character read(curr)
|
/// The absolute offset within the codemap of the last character read(curr)
|
||||||
@ -128,10 +127,10 @@ impl<'a> Reader for TtReader<'a> {
|
|||||||
|
|
||||||
impl<'a> StringReader<'a> {
|
impl<'a> StringReader<'a> {
|
||||||
/// For comments.rs, which hackily pokes into pos and curr
|
/// For comments.rs, which hackily pokes into pos and curr
|
||||||
pub fn new_raw<'b>(span_diagnostic: &'b SpanHandler,
|
pub fn new_raw<'b>(span_diagnostic: &'b Handler,
|
||||||
filemap: Rc<codemap::FileMap>) -> StringReader<'b> {
|
filemap: Rc<codemap::FileMap>) -> StringReader<'b> {
|
||||||
if filemap.src.is_none() {
|
if filemap.src.is_none() {
|
||||||
span_diagnostic.handler.bug(&format!("Cannot lex filemap without source: {}",
|
span_diagnostic.bug(&format!("Cannot lex filemap without source: {}",
|
||||||
filemap.name)[..]);
|
filemap.name)[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ impl<'a> StringReader<'a> {
|
|||||||
sr
|
sr
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'b>(span_diagnostic: &'b SpanHandler,
|
pub fn new<'b>(span_diagnostic: &'b Handler,
|
||||||
filemap: Rc<codemap::FileMap>) -> StringReader<'b> {
|
filemap: Rc<codemap::FileMap>) -> StringReader<'b> {
|
||||||
let mut sr = StringReader::new_raw(span_diagnostic, filemap);
|
let mut sr = StringReader::new_raw(span_diagnostic, filemap);
|
||||||
sr.advance_token();
|
sr.advance_token();
|
||||||
@ -1428,15 +1427,15 @@ mod tests {
|
|||||||
use parse::token::{str_to_ident};
|
use parse::token::{str_to_ident};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
fn mk_sh() -> diagnostic::SpanHandler {
|
fn mk_sh() -> diagnostic::Handler {
|
||||||
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
|
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
|
||||||
let emitter = diagnostic::EmitterWriter::new(Box::new(io::sink()), None);
|
let emitter = diagnostic::EmitterWriter::new(Box::new(io::sink()), None);
|
||||||
let handler = diagnostic::Handler::with_emitter(true, Box::new(emitter));
|
let handler = diagnostic::Handler::with_emitter(true, Box::new(emitter));
|
||||||
diagnostic::SpanHandler::new(handler, CodeMap::new())
|
diagnostic::Handler::new(handler, CodeMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// open a string reader for the given string
|
// open a string reader for the given string
|
||||||
fn setup<'a>(span_handler: &'a diagnostic::SpanHandler,
|
fn setup<'a>(span_handler: &'a diagnostic::Handler,
|
||||||
teststr: String) -> StringReader<'a> {
|
teststr: String) -> StringReader<'a> {
|
||||||
let fm = span_handler.cm.new_filemap("zebra.rs".to_string(), teststr);
|
let fm = span_handler.cm.new_filemap("zebra.rs".to_string(), teststr);
|
||||||
StringReader::new(span_handler, fm)
|
StringReader::new(span_handler, fm)
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{self, Span, CodeMap, FileMap};
|
use codemap::{self, Span, CodeMap, FileMap};
|
||||||
use diagnostic::{SpanHandler, Handler, Auto, FatalError};
|
use errors::{Handler, ColorConfig, FatalError};
|
||||||
use parse::parser::Parser;
|
use parse::parser::Parser;
|
||||||
use parse::token::InternedString;
|
use parse::token::InternedString;
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
@ -40,26 +40,29 @@ pub mod obsolete;
|
|||||||
|
|
||||||
/// Info about a parsing session.
|
/// Info about a parsing session.
|
||||||
pub struct ParseSess {
|
pub struct ParseSess {
|
||||||
pub span_diagnostic: SpanHandler, // better be the same as the one in the reader!
|
pub span_diagnostic: Handler, // better be the same as the one in the reader!
|
||||||
/// Used to determine and report recursive mod inclusions
|
/// Used to determine and report recursive mod inclusions
|
||||||
included_mod_stack: RefCell<Vec<PathBuf>>,
|
included_mod_stack: RefCell<Vec<PathBuf>>,
|
||||||
|
code_map: Rc<CodeMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParseSess {
|
impl ParseSess {
|
||||||
pub fn new() -> ParseSess {
|
pub fn new() -> ParseSess {
|
||||||
let handler = SpanHandler::new(Handler::new(Auto, None, true), CodeMap::new());
|
let cm = Rc::new(CodeMap::new());
|
||||||
ParseSess::with_span_handler(handler)
|
let handler = Handler::new(ColorConfig::Auto, None, true, cm.clone());
|
||||||
|
ParseSess::with_span_handler(handler, cm)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_span_handler(sh: SpanHandler) -> ParseSess {
|
pub fn with_span_handler(handler: Handler, code_map: Rc<CodeMap>) -> ParseSess {
|
||||||
ParseSess {
|
ParseSess {
|
||||||
span_diagnostic: sh,
|
span_diagnostic: handler,
|
||||||
included_mod_stack: RefCell::new(vec![])
|
included_mod_stack: RefCell::new(vec![]),
|
||||||
|
code_map: code_map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn codemap(&self) -> &CodeMap {
|
pub fn codemap(&self) -> &CodeMap {
|
||||||
&self.span_diagnostic.cm
|
&self.code_map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +238,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
|
|||||||
let msg = format!("couldn't read {:?}: {}", path.display(), e);
|
let msg = format!("couldn't read {:?}: {}", path.display(), e);
|
||||||
match spanopt {
|
match spanopt {
|
||||||
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
|
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
|
||||||
None => panic!(sess.span_diagnostic.handler().fatal(&msg))
|
None => panic!(sess.span_diagnostic.fatal(&msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,7 +441,7 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
|
fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
|
||||||
sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
sd: &Handler, sp: Span) -> ast::Lit_ {
|
||||||
debug!("filtered_float_lit: {}, {:?}", data, suffix);
|
debug!("filtered_float_lit: {}, {:?}", data, suffix);
|
||||||
match suffix.as_ref().map(|s| &**s) {
|
match suffix.as_ref().map(|s| &**s) {
|
||||||
Some("f32") => ast::LitFloat(data, ast::TyF32),
|
Some("f32") => ast::LitFloat(data, ast::TyF32),
|
||||||
@ -459,7 +462,7 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn float_lit(s: &str, suffix: Option<InternedString>,
|
pub fn float_lit(s: &str, suffix: Option<InternedString>,
|
||||||
sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
sd: &Handler, sp: Span) -> ast::Lit_ {
|
||||||
debug!("float_lit: {:?}, {:?}", s, suffix);
|
debug!("float_lit: {:?}, {:?}", s, suffix);
|
||||||
// FIXME #2252: bounds checking float literals is deferred until trans
|
// FIXME #2252: bounds checking float literals is deferred until trans
|
||||||
let s = s.chars().filter(|&c| c != '_').collect::<String>();
|
let s = s.chars().filter(|&c| c != '_').collect::<String>();
|
||||||
@ -561,7 +564,7 @@ pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> {
|
|||||||
|
|
||||||
pub fn integer_lit(s: &str,
|
pub fn integer_lit(s: &str,
|
||||||
suffix: Option<InternedString>,
|
suffix: Option<InternedString>,
|
||||||
sd: &SpanHandler,
|
sd: &Handler,
|
||||||
sp: Span)
|
sp: Span)
|
||||||
-> ast::Lit_ {
|
-> ast::Lit_ {
|
||||||
// s can only be ascii, byte indexing is fine
|
// s can only be ascii, byte indexing is fine
|
||||||
|
@ -66,10 +66,9 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !self.obsolete_set.contains(&kind) &&
|
if !self.obsolete_set.contains(&kind) &&
|
||||||
(error || self.sess.span_diagnostic.handler().can_emit_warnings) {
|
(error || self.sess.span_diagnostic.can_emit_warnings) {
|
||||||
self.sess
|
self.sess
|
||||||
.span_diagnostic
|
.span_diagnostic
|
||||||
.handler()
|
|
||||||
.note(&format!("{}", desc));
|
.note(&format!("{}", desc));
|
||||||
self.obsolete_set.insert(kind);
|
self.obsolete_set.insert(kind);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ use attr::{ThinAttributes, ThinAttributesExt, AttributesExt};
|
|||||||
use ast;
|
use ast;
|
||||||
use ast_util::{self, ident_to_path};
|
use ast_util::{self, ident_to_path};
|
||||||
use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap};
|
use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap};
|
||||||
use diagnostic;
|
use errors::{self, FatalError};
|
||||||
use ext::tt::macro_parser;
|
use ext::tt::macro_parser;
|
||||||
use parse;
|
use parse;
|
||||||
use parse::classify;
|
use parse::classify;
|
||||||
@ -75,7 +75,6 @@ use print::pprust;
|
|||||||
use ptr::P;
|
use ptr::P;
|
||||||
use owned_slice::OwnedSlice;
|
use owned_slice::OwnedSlice;
|
||||||
use parse::PResult;
|
use parse::PResult;
|
||||||
use diagnostic::FatalError;
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@ -983,16 +982,16 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
f(&self.buffer[((self.buffer_start + dist - 1) & 3) as usize].tok)
|
f(&self.buffer[((self.buffer_start + dist - 1) & 3) as usize].tok)
|
||||||
}
|
}
|
||||||
pub fn fatal(&self, m: &str) -> diagnostic::FatalError {
|
pub fn fatal(&self, m: &str) -> errors::FatalError {
|
||||||
self.sess.span_diagnostic.span_fatal(self.span, m)
|
self.sess.span_diagnostic.span_fatal(self.span, m)
|
||||||
}
|
}
|
||||||
pub fn span_fatal(&self, sp: Span, m: &str) -> diagnostic::FatalError {
|
pub fn span_fatal(&self, sp: Span, m: &str) -> errors::FatalError {
|
||||||
self.sess.span_diagnostic.span_fatal(sp, m)
|
self.sess.span_diagnostic.span_fatal(sp, m)
|
||||||
}
|
}
|
||||||
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> diagnostic::FatalError {
|
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> errors::FatalError {
|
||||||
self.span_err(sp, m);
|
self.span_err(sp, m);
|
||||||
self.fileline_help(sp, help);
|
self.fileline_help(sp, help);
|
||||||
diagnostic::FatalError
|
errors::FatalError
|
||||||
}
|
}
|
||||||
pub fn span_note(&self, sp: Span, m: &str) {
|
pub fn span_note(&self, sp: Span, m: &str) {
|
||||||
self.sess.span_diagnostic.span_note(sp, m)
|
self.sess.span_diagnostic.span_note(sp, m)
|
||||||
@ -1022,7 +1021,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.sess.span_diagnostic.span_bug(sp, m)
|
self.sess.span_diagnostic.span_bug(sp, m)
|
||||||
}
|
}
|
||||||
pub fn abort_if_errors(&self) {
|
pub fn abort_if_errors(&self) {
|
||||||
self.sess.span_diagnostic.handler().abort_if_errors();
|
self.sess.span_diagnostic.abort_if_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id_to_interned_str(&mut self, id: Ident) -> InternedString {
|
pub fn id_to_interned_str(&mut self, id: Ident) -> InternedString {
|
||||||
|
@ -20,7 +20,7 @@ use attr;
|
|||||||
use owned_slice::OwnedSlice;
|
use owned_slice::OwnedSlice;
|
||||||
use attr::{AttrMetaMethods, AttributeMethods};
|
use attr::{AttrMetaMethods, AttributeMethods};
|
||||||
use codemap::{self, CodeMap, BytePos};
|
use codemap::{self, CodeMap, BytePos};
|
||||||
use diagnostic;
|
use errors;
|
||||||
use parse::token::{self, BinOpToken, Token, InternedString};
|
use parse::token::{self, BinOpToken, Token, InternedString};
|
||||||
use parse::lexer::comments;
|
use parse::lexer::comments;
|
||||||
use parse;
|
use parse;
|
||||||
@ -99,7 +99,7 @@ pub const DEFAULT_COLUMNS: usize = 78;
|
|||||||
/// it can scan the input text for comments and literals to
|
/// it can scan the input text for comments and literals to
|
||||||
/// copy forward.
|
/// copy forward.
|
||||||
pub fn print_crate<'a>(cm: &'a CodeMap,
|
pub fn print_crate<'a>(cm: &'a CodeMap,
|
||||||
span_diagnostic: &diagnostic::SpanHandler,
|
span_diagnostic: &errors::Handler,
|
||||||
krate: &ast::Crate,
|
krate: &ast::Crate,
|
||||||
filename: String,
|
filename: String,
|
||||||
input: &mut Read,
|
input: &mut Read,
|
||||||
@ -139,7 +139,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
|
|||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new_from_input(cm: &'a CodeMap,
|
pub fn new_from_input(cm: &'a CodeMap,
|
||||||
span_diagnostic: &diagnostic::SpanHandler,
|
span_diagnostic: &errors::Handler,
|
||||||
filename: String,
|
filename: String,
|
||||||
input: &mut Read,
|
input: &mut Read,
|
||||||
out: Box<Write+'a>,
|
out: Box<Write+'a>,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use diagnostic;
|
use errors;
|
||||||
use visit;
|
use visit;
|
||||||
use visit::Visitor;
|
use visit::Visitor;
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ impl FromStr for Mode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ShowSpanVisitor<'a> {
|
struct ShowSpanVisitor<'a> {
|
||||||
span_diagnostic: &'a diagnostic::SpanHandler,
|
span_diagnostic: &'a errors::Handler,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(span_diagnostic: &diagnostic::SpanHandler,
|
pub fn run(span_diagnostic: &errors::Handler,
|
||||||
mode: &str,
|
mode: &str,
|
||||||
krate: &ast::Crate) {
|
krate: &ast::Crate) {
|
||||||
let mode = match mode.parse().ok() {
|
let mode = match mode.parse().ok() {
|
||||||
|
@ -23,7 +23,7 @@ use attr::AttrMetaMethods;
|
|||||||
use attr;
|
use attr;
|
||||||
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
|
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
|
||||||
use codemap;
|
use codemap;
|
||||||
use diagnostic;
|
use errors;
|
||||||
use config;
|
use config;
|
||||||
use entry::{self, EntryPointType};
|
use entry::{self, EntryPointType};
|
||||||
use ext::base::ExtCtxt;
|
use ext::base::ExtCtxt;
|
||||||
@ -55,7 +55,7 @@ struct Test {
|
|||||||
|
|
||||||
struct TestCtxt<'a> {
|
struct TestCtxt<'a> {
|
||||||
sess: &'a ParseSess,
|
sess: &'a ParseSess,
|
||||||
span_diagnostic: &'a diagnostic::SpanHandler,
|
span_diagnostic: &'a errors::Handler,
|
||||||
path: Vec<ast::Ident>,
|
path: Vec<ast::Ident>,
|
||||||
ext_cx: ExtCtxt<'a>,
|
ext_cx: ExtCtxt<'a>,
|
||||||
testfns: Vec<Test>,
|
testfns: Vec<Test>,
|
||||||
@ -72,7 +72,7 @@ struct TestCtxt<'a> {
|
|||||||
pub fn modify_for_testing(sess: &ParseSess,
|
pub fn modify_for_testing(sess: &ParseSess,
|
||||||
cfg: &ast::CrateConfig,
|
cfg: &ast::CrateConfig,
|
||||||
krate: ast::Crate,
|
krate: ast::Crate,
|
||||||
span_diagnostic: &diagnostic::SpanHandler) -> ast::Crate {
|
span_diagnostic: &errors::Handler) -> ast::Crate {
|
||||||
// We generate the test harness when building in the 'test'
|
// We generate the test harness when building in the 'test'
|
||||||
// configuration, either with the '--test' or '--cfg test'
|
// configuration, either with the '--test' or '--cfg test'
|
||||||
// command line options.
|
// command line options.
|
||||||
@ -275,7 +275,7 @@ fn generate_test_harness(sess: &ParseSess,
|
|||||||
reexport_test_harness_main: Option<InternedString>,
|
reexport_test_harness_main: Option<InternedString>,
|
||||||
krate: ast::Crate,
|
krate: ast::Crate,
|
||||||
cfg: &ast::CrateConfig,
|
cfg: &ast::CrateConfig,
|
||||||
sd: &diagnostic::SpanHandler) -> ast::Crate {
|
sd: &errors::Handler) -> ast::Crate {
|
||||||
// Remove the entry points
|
// Remove the entry points
|
||||||
let mut cleaner = EntryPointCleaner { depth: 0 };
|
let mut cleaner = EntryPointCleaner { depth: 0 };
|
||||||
let krate = cleaner.fold_crate(krate);
|
let krate = cleaner.fold_crate(krate);
|
||||||
@ -315,7 +315,7 @@ fn generate_test_harness(sess: &ParseSess,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strip_test_functions(diagnostic: &diagnostic::SpanHandler, krate: ast::Crate)
|
fn strip_test_functions(diagnostic: &errors::Handler, krate: ast::Crate)
|
||||||
-> ast::Crate {
|
-> ast::Crate {
|
||||||
// When not compiling with --test we should not compile the
|
// When not compiling with --test we should not compile the
|
||||||
// #[test] functions
|
// #[test] functions
|
||||||
@ -688,7 +688,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
|
|||||||
Some(id) => vec![id],
|
Some(id) => vec![id],
|
||||||
None => {
|
None => {
|
||||||
let diag = cx.span_diagnostic;
|
let diag = cx.span_diagnostic;
|
||||||
diag.handler.bug("expected to find top-level re-export name, but found None");
|
diag.bug("expected to find top-level re-export name, but found None");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
visible_path.extend(path);
|
visible_path.extend(path);
|
||||||
|
@ -203,7 +203,7 @@ use syntax::ext::base::{ExtCtxt, Annotatable};
|
|||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::codemap::{self, DUMMY_SP};
|
use syntax::codemap::{self, DUMMY_SP};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::diagnostic::SpanHandler;
|
use syntax::errors::Handler;
|
||||||
use syntax::util::move_map::MoveMap;
|
use syntax::util::move_map::MoveMap;
|
||||||
use syntax::owned_slice::OwnedSlice;
|
use syntax::owned_slice::OwnedSlice;
|
||||||
use syntax::parse::token::{intern, InternedString};
|
use syntax::parse::token::{intern, InternedString};
|
||||||
@ -742,7 +742,7 @@ impl<'a> TraitDef<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_repr_type_name(diagnostic: &SpanHandler,
|
fn find_repr_type_name(diagnostic: &Handler,
|
||||||
type_attrs: &[ast::Attribute]) -> &'static str {
|
type_attrs: &[ast::Attribute]) -> &'static str {
|
||||||
let mut repr_type_name = "i32";
|
let mut repr_type_name = "i32";
|
||||||
for a in type_attrs {
|
for a in type_attrs {
|
||||||
|
Loading…
Reference in New Issue
Block a user