Skip to content
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

Give all fatals, errors, and warnings unique diagnostic codes #12144

Closed
wants to merge 7 commits into from
Closed
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
10 changes: 5 additions & 5 deletions src/librustc/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
Ok(mut prog) => {
let o = prog.finish_with_output();
if !o.status.success() {
sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
o.status));
alert_err!(sess, A0344, "{} {} failed with: {}", ar, args.connect(" "),
o.status);
sess.note(format!("stdout ---\n{}", str::from_utf8(o.output).unwrap()));
sess.note(format!("stderr ---\n{}", str::from_utf8(o.error).unwrap()));
sess.abort_if_errors();
}
o
},
Err(e) => {
sess.err(format!("could not exec `{}`: {}", ar, e));
alert_err!(sess, A0345, "could not exec `{}`: {}", ar, e);
sess.abort_if_errors();
fail!("rustc::back::archive::run_ar() should not reach this point");
}
Expand Down Expand Up @@ -206,8 +206,8 @@ impl Archive {
if test.exists() { return test }
}
}
self.sess.fatal(format!("could not find native static library `{}`, \
perhaps an -L flag is missing?", name));
alert_fatal!(self.sess, A0051, "could not find native static library `{}`, \
perhaps an -L flag is missing?", name);
}
}

Expand Down
53 changes: 28 additions & 25 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ pub enum OutputType {
}

pub fn llvm_err(sess: Session, msg: ~str) -> ! {
unsafe {
let msg = unsafe {
let cstr = llvm::LLVMRustGetLastError();
if cstr == ptr::null() {
sess.fatal(msg);
msg
} else {
sess.fatal(msg + ": " + str::raw::from_c_str(cstr));
format!("{}: {}", msg, str::raw::from_c_str(cstr))
}
}
};
alert_fatal!(sess, A0052, "LLVM error: {}", msg);
}

pub fn WriteOutputFile(
Expand Down Expand Up @@ -189,7 +190,7 @@ pub mod write {
for pass in sess.opts.custom_passes.iter() {
pass.with_c_str(|s| {
if !llvm::LLVMRustAddPass(mpm, s) {
sess.warn(format!("unknown pass {}, ignoring", *pass));
alert_warn!(sess, A0335, "unknown pass {}, ignoring", *pass);
}
})
}
Expand Down Expand Up @@ -334,14 +335,14 @@ pub mod write {
match run::process_output(cc, args) {
Ok(prog) => {
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
alert_err!(sess, A0346, "linking with `{}` failed: {}", cc, prog.status);
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
sess.abort_if_errors();
}
},
Err(e) => {
sess.err(format!("could not exec the linker `{}`: {}", cc, e));
alert_err!(sess, A0347, "could not exec the linker `{}`: {}", cc, e);
sess.abort_if_errors();
}
}
Expand Down Expand Up @@ -782,8 +783,8 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
format!("{}/bin/arm-linux-androideabi-{}", *path, tool_str)
}
None => {
sess.fatal(format!("need Android NDK path for the '{}' tool \
(--android-cross-path)", tool))
alert_fatal!(sess, A0053, "need Android NDK path for the '{}' tool \
(--android-cross-path)", tool)
}
},
_ => tool.to_owned(),
Expand All @@ -794,7 +795,7 @@ fn remove(sess: Session, path: &Path) {
match fs::unlink(path) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to remove {}: {}", path.display(), e));
alert_err!(sess, A0356, "failed to remove {}: {}", path.display(), e);
}
}
}
Expand Down Expand Up @@ -876,12 +877,14 @@ fn link_binary_output(sess: Session,
let obj_is_writeable = is_writeable(&obj_filename);
let out_is_writeable = is_writeable(&out_filename);
if !out_is_writeable {
sess.fatal(format!("output file {} is not writeable -- check its permissions.",
out_filename.display()));
alert_fatal!(sess, A0054,
"output file {} is not writeable -- check its permissions.",
out_filename.display());
}
else if !obj_is_writeable {
sess.fatal(format!("object file {} is not writeable -- check its permissions.",
obj_filename.display()));
alert_fatal!(sess, A0055,
"object file {} is not writeable -- check its permissions.",
obj_filename.display());
}

match crate_type {
Expand Down Expand Up @@ -957,8 +960,8 @@ fn link_rlib(sess: Session,
match fs::File::create(&metadata).write(trans.metadata) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to write {}: {}",
metadata.display(), e));
alert_err!(sess, A0348, "failed to write {}: {}",
metadata.display(), e);
sess.abort_if_errors();
}
}
Expand Down Expand Up @@ -1009,7 +1012,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
let name = sess.cstore.get_crate_data(cnum).name.clone();
let p = match *path {
Some(ref p) => p.clone(), None => {
sess.err(format!("could not find rlib for: `{}`", name));
alert_err!(sess, A0349, "could not find rlib for: `{}`", name);
continue
}
};
Expand All @@ -1021,7 +1024,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
cstore::NativeUnknown => "library",
cstore::NativeFramework => "framework",
};
sess.warn(format!("unlinked native {}: {}", name, *lib));
alert_warn!(sess, A0336, "unlinked native {}: {}", name, *lib);
}
}
}
Expand Down Expand Up @@ -1052,14 +1055,14 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
match prog {
Ok(prog) => {
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
alert_err!(sess, A0350, "linking with `{}` failed: {}", cc_prog, prog.status);
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
sess.abort_if_errors();
}
},
Err(e) => {
sess.err(format!("could not exec the linker `{}`: {}", cc_prog, e));
alert_err!(sess, A0351, "could not exec the linker `{}`: {}", cc_prog, e);
sess.abort_if_errors();
}
}
Expand All @@ -1073,7 +1076,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
[out_filename.as_str().unwrap().to_owned()]) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to run dsymutil: {}", e));
alert_err!(sess, A0352, "failed to run dsymutil: {}", e);
sess.abort_if_errors();
}
}
Expand Down Expand Up @@ -1273,10 +1276,10 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
match fs::copy(&cratepath, &dst) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to copy {} to {}: {}",
alert_err!(sess, A0353, "failed to copy {} to {}: {}",
cratepath.display(),
dst.display(),
e));
e);
sess.abort_if_errors();
}
}
Expand Down Expand Up @@ -1313,8 +1316,8 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
let cratepath = match *path {
Some(ref p) => p.clone(),
None => {
sess.err(format!("could not find dynamic library for: `{}`",
sess.cstore.get_crate_data(cnum).name));
alert_err!(sess, A0354, "could not find dynamic library for: `{}`",
sess.cstore.get_crate_data(cnum).name);
return
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::libc;
pub fn run(sess: session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[~str]) {
if sess.prefer_dynamic() {
sess.err("cannot prefer dynamic linking when performing LTO");
alert_err!(sess, A0355, "cannot prefer dynamic linking when performing LTO");
sess.note("only 'staticlib' and 'bin' outputs are supported with LTO");
sess.abort_if_errors();
}
Expand All @@ -31,7 +31,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
match *crate_type {
session::CrateTypeExecutable | session::CrateTypeStaticlib => {}
_ => {
sess.fatal("lto can only be run for executables and \
alert_fatal!(sess, A0049, "lto can only be run for executables and \
static library outputs");
}
}
Expand All @@ -46,7 +46,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
let path = match path {
Some(p) => p,
None => {
sess.fatal(format!("could not find rlib for: `{}`", name));
alert_fatal!(sess, A0050, "could not find rlib for: `{}`", name);
}
};

Expand Down
27 changes: 27 additions & 0 deletions src/librustc/diag_db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2014 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.

//! The diagnostic database.
//!
//! Extended information about Rust diagnostics is included in the
//! diag_db.md file and can be loaded at runtime with the `load`
//! function.

use syntax::diag_db::DiagnosticDb;

/// Load the database of extended diagnostic descriptions
pub fn load() -> DiagnosticDb {
DiagnosticDb::new(~[load_raw, ::syntax::diag_db::load_raw])
}

pub fn load_raw() -> ~[(&'static str, &'static str, &'static str)] {
include!("diag_db_data.rs")
}

25 changes: 25 additions & 0 deletions src/librustc/diag_db_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2014 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.

diag_db!(

(A0001, "

Placeholder.

"),

(A0002, "

Placeholder.

")

)
Loading