Skip to content

Rollup of 12 pull requests #30457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2a1efca
Fix typo
jwworth Dec 15, 2015
d91b256
change macro ambiguity example from ty to ident
durka Dec 16, 2015
6309b0f
move error handling from libsyntax/diagnostics.rs to libsyntax/errors/*
nrc Dec 13, 2015
a478811
Move a bunch of stuff from Session to syntax::errors
nrc Dec 14, 2015
7a03349
Add the files I fogot about earlier
nrc Dec 15, 2015
e237151
A little more refactoring inside emitter.rs
nrc Dec 15, 2015
ff0c74f
test errors
nrc Dec 15, 2015
ccb2186
Trivial cleanup
mmcco Dec 17, 2015
09d4a43
libsyntax: Merge OwnedSlice into ptr::P
petrochenkov Dec 16, 2015
0d298f9
Deprecate name `OwnedSlice` and don't use it
petrochenkov Dec 16, 2015
6c87b19
Abstract away differences between Vec and ptr::P in HIR
petrochenkov Dec 17, 2015
2a23e4a
Clarified shadowing example
Xmasreturns Dec 17, 2015
88ffb26
Fix emitting asm and object file output at the same time
dotdash Dec 18, 2015
cb319fc
Rollup merge of #30286 - oli-obk:const_error_span, r=nikomatsakis
Manishearth Dec 18, 2015
c290296
Rollup merge of #30384 - nrc:diagnostics, r=@nikomatsakis
Manishearth Dec 18, 2015
7eb7bc2
Rollup merge of #30398 - jwworth:pull-request-1450205451, r=sanxiyn
Manishearth Dec 18, 2015
158a1bd
Rollup merge of #30406 - durka:patch-13, r=sanxiyn
Manishearth Dec 18, 2015
9e953df
Rollup merge of #30420 - petrochenkov:owned2, r=nrc
Manishearth Dec 18, 2015
e916676
Rollup merge of #30431 - mmcco:cleanup, r=alexcrichton
Manishearth Dec 18, 2015
4f8b32c
Rollup merge of #30447 - Xmasreturns:Docu, r=steveklabnik
Manishearth Dec 18, 2015
a8e4246
Rollup merge of #30452 - dotdash:24876_take_2, r=alexcrichton
Manishearth Dec 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move error handling from libsyntax/diagnostics.rs to libsyntax/errors/*
Also split out emitters into their own module.
  • Loading branch information
nrc committed Dec 16, 2015
commit 6309b0f5bb558b844f45b2d313d2078fd7b7614c
6 changes: 3 additions & 3 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use rustc_front::hir;
use rustc_front::util;
use rustc_front::intravisit as hir_visit;
use syntax::visit as ast_visit;
use syntax::diagnostic;
use syntax::errors;

/// Information about the registered lints.
///
Expand Down Expand Up @@ -167,7 +167,7 @@ impl LintStore {
match (sess, from_plugin) {
// We load builtin lints first, so a duplicate is a compiler bug.
// 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[..]),

// A duplicate name from a plugin is a user error.
Expand All @@ -191,7 +191,7 @@ impl LintStore {
match (sess, from_plugin) {
// We load builtin lints first, so a duplicate is a compiler bug.
// 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[..]),

// A duplicate name from a plugin is a user error.
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use middle::cstore;
use syntax::ast::{self, IntTy, UintTy};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::diagnostic::{ColorConfig, Auto, Always, Never, SpanHandler};
use syntax::errors::{ColorConfig, Handler};
use syntax::parse;
use syntax::parse::token::InternedString;
use syntax::feature_gate::UnstableFeatures;
Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn basic_options() -> Options {
debugging_opts: basic_debugging_options(),
prints: Vec::new(),
cg: basic_codegen_options(),
color: Auto,
color: ColorConfig::Auto,
show_span: None,
externs: HashMap::new(),
crate_name: None,
Expand Down Expand Up @@ -687,19 +687,19 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
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) {
Ok(t) => t,
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[..] {
"32" => (ast::TyI32, ast::TyU32),
"64" => (ast::TyI64, ast::TyU64),
w => panic!(sp.handler().fatal(&format!("target specification was invalid: \
unrecognized target-pointer-width {}", w))),
w => panic!(sp.fatal(&format!("target specification was invalid: \
unrecognized target-pointer-width {}", w))),
};

Config {
Expand Down Expand Up @@ -884,16 +884,16 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {

pub fn build_session_options(matches: &getopts::Matches) -> Options {
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
Some("auto") => Auto,
Some("always") => Always,
Some("never") => Never,
Some("auto") => ColorConfig::Auto,
Some("always") => ColorConfig::Always,
Some("never") => ColorConfig::Never,

None => Auto,
None => ColorConfig::Auto,

Some(arg) => {
early_error(Auto, &format!("argument for --color must be auto, always \
or never (instead was `{}`)",
arg))
early_error(ColorConfig::Auto, &format!("argument for --color must be auto, always \
or never (instead was `{}`)",
arg))
}
};

Expand Down
59 changes: 29 additions & 30 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use util::nodemap::{NodeMap, FnvHashMap};

use syntax::ast::{NodeId, NodeIdAssigner, Name};
use syntax::codemap::Span;
use syntax::diagnostic::{self, Emitter};
use syntax::errors;
use syntax::errors::emitter::{Emitter, BasicEmitter};
use syntax::diagnostics;
use syntax::feature_gate;
use syntax::parse;
Expand Down Expand Up @@ -99,7 +100,7 @@ impl Session {
if self.opts.treat_err_as_bug {
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) {
if is_warning {
Expand Down Expand Up @@ -137,16 +138,16 @@ impl Session {
if self.opts.treat_err_as_bug {
self.bug(msg);
}
self.diagnostic().handler().err(msg)
self.diagnostic().err(msg)
}
pub fn err_count(&self) -> usize {
self.diagnostic().handler().err_count()
self.diagnostic().err_count()
}
pub fn has_errors(&self) -> bool {
self.diagnostic().handler().has_errors()
self.diagnostic().has_errors()
}
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();
match *delayed_bug {
Expand Down Expand Up @@ -177,7 +178,7 @@ impl Session {
}
pub fn warn(&self, msg: &str) {
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) {
Expand All @@ -195,7 +196,7 @@ impl Session {

/// 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) {
self.diagnostic().span_suggestion(sp, msg, suggestion)
}
Expand All @@ -209,10 +210,10 @@ impl Session {
self.diagnostic().fileline_help(sp, msg)
}
pub fn note(&self, msg: &str) {
self.diagnostic().handler().note(msg)
self.diagnostic().note(msg)
}
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) -> ! {
match opt_sp {
Expand All @@ -229,13 +230,13 @@ impl Session {
self.diagnostic().span_bug(sp, msg)
}
pub fn bug(&self, msg: &str) -> ! {
self.diagnostic().handler().bug(msg)
self.diagnostic().bug(msg)
}
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
self.diagnostic().span_unimpl(sp, msg)
}
pub fn unimpl(&self, msg: &str) -> ! {
self.diagnostic().handler().unimpl(msg)
self.diagnostic().unimpl(msg)
}
pub fn add_lint(&self,
lint: &'static lint::Lint,
Expand All @@ -260,7 +261,7 @@ impl Session {

id
}
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler {
&self.parse_sess.span_diagnostic
}
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
Expand Down Expand Up @@ -414,29 +415,27 @@ pub fn build_session(sopts: config::Options,
.last()
.unwrap_or(true);

let codemap = codemap::CodeMap::new();
let codemap = Rc::new(codemap::CodeMap::new());
let diagnostic_handler =
diagnostic::Handler::new(sopts.color, Some(registry), can_print_warnings);
let span_diagnostic_handler =
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
errors::Handler::new(sopts.color, Some(registry), can_print_warnings, codemap.clone());

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,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: diagnostic::SpanHandler,
span_diagnostic: errors::Handler,
codemap: Rc<codemap::CodeMap>,
cstore: Rc<for<'a> CrateStore<'a>>)
-> Session {
let host = match Target::search(config::host_triple()) {
Ok(t) => t,
Err(e) => {
panic!(span_diagnostic.handler()
.fatal(&format!("Error loading host specification: {}", e)));
panic!(span_diagnostic.fatal(&format!("Error loading host specification: {}", e)));
}
};
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 {
Some(_) => None,
None => Some(filesearch::get_or_default_sysroot())
Expand Down Expand Up @@ -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
M: FnOnce() -> String,
{
diagnostic::expect(sess.diagnostic(), opt, msg)
errors::expect(sess.diagnostic(), opt, msg)
}

pub fn early_error(color: diagnostic::ColorConfig, msg: &str) -> ! {
let mut emitter = diagnostic::EmitterWriter::stderr(color, None);
emitter.emit(None, msg, None, diagnostic::Fatal);
panic!(diagnostic::FatalError);
pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
let mut emitter = BasicEmitter::stderr(color);
emitter.emit(None, msg, None, errors::Level::Fatal);
panic!(errors::FatalError);
}

pub fn early_warn(color: diagnostic::ColorConfig, msg: &str) {
let mut emitter = diagnostic::EmitterWriter::stderr(color, None);
emitter.emit(None, msg, None, diagnostic::Warning);
pub fn early_warn(color: errors::ColorConfig, msg: &str) {
let mut emitter = BasicEmitter::stderr(color);
emitter.emit(None, msg, None, errors::Level::Warning);
}
4 changes: 2 additions & 2 deletions src/librustc/session/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::slice;
use std::path::{Path, PathBuf};
use session::early_error;
use syntax::diagnostic;
use syntax::errors;

#[derive(Clone, Debug)]
pub struct SearchPaths {
Expand All @@ -38,7 +38,7 @@ impl SearchPaths {
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=") {
(PathKind::Native, &path["native=".len()..])
} else if path.starts_with("crate=") {
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
use serialize::json::Json;
use std::default::Default;
use std::io::prelude::*;
use syntax::{diagnostic, abi};
use syntax::abi;

mod android_base;
mod apple_base;
Expand Down Expand Up @@ -263,17 +263,13 @@ impl Target {
pub fn from_json(obj: Json) -> Target {
// this is 1. ugly, 2. error prone.


let handler = diagnostic::Handler::new(diagnostic::Auto, None, true);

let get_req_field = |name: &str| {
match obj.find(name)
.map(|s| s.as_string())
.and_then(|os| os.map(|s| s.to_string())) {
Some(val) => val,
None => {
panic!(handler.fatal(&format!("Field {} in target specification is required",
name)))
panic!("Field {} in target specification is required", name)
}
}
};
Expand Down
25 changes: 12 additions & 13 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ extern crate log;
extern crate syntax;
extern crate syntax_ext;

pub use syntax::diagnostic;

use driver::CompileController;
use pretty::{PpMode, UserIdentifiedItem};

Expand Down Expand Up @@ -91,7 +89,8 @@ use rustc::session::early_error;

use syntax::ast;
use syntax::parse;
use syntax::diagnostic::Emitter;
use syntax::errors;
use syntax::errors::emitter::Emitter;
use syntax::diagnostics;
use syntax::parse::token;

Expand Down Expand Up @@ -239,7 +238,7 @@ pub trait CompilerCalls<'a> {
fn early_callback(&mut self,
_: &getopts::Matches,
_: &diagnostics::registry::Registry,
_: diagnostic::ColorConfig)
_: errors::ColorConfig)
-> Compilation {
Compilation::Continue
}
Expand Down Expand Up @@ -315,7 +314,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
fn early_callback(&mut self,
matches: &getopts::Matches,
descriptions: &diagnostics::registry::Registry,
color: diagnostic::ColorConfig)
color: errors::ColorConfig)
-> Compilation {
match matches.opt_str("explain") {
Some(ref code) => {
Expand Down Expand Up @@ -774,7 +773,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
&opt.opt_group.short_name
};
if m.opt_present(opt_name) {
early_error(diagnostic::Auto,
early_error(errors::ColorConfig::Auto,
&format!("use of unstable option '{}' requires -Z \
unstable-options",
opt_name));
Expand All @@ -783,7 +782,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
}
m
}
Err(f) => early_error(diagnostic::Auto, &f.to_string()),
Err(f) => early_error(errors::ColorConfig::Auto, &f.to_string()),
}
}

Expand Down Expand Up @@ -895,25 +894,25 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
}
Err(value) => {
// Thread panicked without emitting a fatal diagnostic
if !value.is::<diagnostic::FatalError>() {
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto, None);
if !value.is::<errors::FatalError>() {
let mut emitter = errors::emitter::BasicEmitter::stderr(errors::ColorConfig::Auto);

// a .span_bug or .bug call has already printed what
// it wants to print.
if !value.is::<diagnostic::ExplicitBug>() {
emitter.emit(None, "unexpected panic", None, diagnostic::Bug);
if !value.is::<errors::ExplicitBug>() {
emitter.emit(None, "unexpected panic", None, errors::Level::Bug);
}

let xs = ["the compiler unexpectedly panicked. this is a bug.".to_string(),
format!("we would appreciate a bug report: {}", BUG_REPORT_URL)];
for note in &xs {
emitter.emit(None, &note[..], None, diagnostic::Note)
emitter.emit(None, &note[..], None, errors::Level::Note)
}
if let None = env::var_os("RUST_BACKTRACE") {
emitter.emit(None,
"run with `RUST_BACKTRACE=1` for a backtrace",
None,
diagnostic::Note);
errors::Level::Note);
}

println!("{}", str::from_utf8(&data.lock().unwrap()).unwrap());
Expand Down
Loading