Skip to content

Refactor error handling #30384

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 5 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
32 changes: 16 additions & 16 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 Expand Up @@ -1224,7 +1224,7 @@ mod tests {
let sessopts = build_session_options(&matches);
let sess = build_session(sessopts, None, registry,
Rc::new(DummyCrateStore));
assert!(!sess.can_print_warnings);
assert!(!sess.diagnostic().can_emit_warnings);
}

{
Expand All @@ -1236,7 +1236,7 @@ mod tests {
let sessopts = build_session_options(&matches);
let sess = build_session(sessopts, None, registry,
Rc::new(DummyCrateStore));
assert!(sess.can_print_warnings);
assert!(sess.diagnostic().can_emit_warnings);
}

{
Expand All @@ -1247,7 +1247,7 @@ mod tests {
let sessopts = build_session_options(&matches);
let sess = build_session(sessopts, None, registry,
Rc::new(DummyCrateStore));
assert!(sess.can_print_warnings);
assert!(sess.diagnostic().can_emit_warnings);
}
}
}
Loading