Commit 8be00519 authored by Ryan Hunt's avatar Ryan Hunt
Browse files

Improve errors and warnings

parent 01557287
......@@ -190,7 +190,7 @@ impl LibraryParseResult {
item: &syn::Item,
block: &syn::ForeignMod) {
if !block.abi.is_c() {
info!("skip {}::{} - (extern block must be extern C)", crate_name, &item.ident);
info!("Skip {}::{} - (extern block must be extern C).", crate_name, &item.ident);
return;
}
......@@ -199,7 +199,7 @@ impl LibraryParseResult {
syn::ForeignItemKind::Fn(ref decl,
ref _generic) => {
if crate_name != binding_crate_name {
info!("skip {}::{} - (fn's outside of the binding crate are not used)",
info!("Skip {}::{} - (fn's outside of the binding crate are not used).",
crate_name,
&foreign_item.ident);
return;
......@@ -211,12 +211,12 @@ impl LibraryParseResult {
&foreign_item.attrs,
mod_cfg) {
Ok(func) => {
info!("take {}::{}", crate_name, &foreign_item.ident);
info!("Take {}::{}.", crate_name, &foreign_item.ident);
self.functions.push(func);
}
Err(msg) => {
error!("Cannot use fn {}::{} ({})",
error!("Cannot use fn {}::{} ({}).",
crate_name,
&foreign_item.ident,
msg);
......@@ -237,7 +237,7 @@ impl LibraryParseResult {
decl: &syn::FnDecl,
abi: &Option<syn::Abi>) {
if crate_name != binding_crate_name {
info!("skip {}::{} - (fn's outside of the binding crate are not used)",
info!("Skip {}::{} - (fn's outside of the binding crate are not used).",
crate_name,
&item.ident);
return;
......@@ -250,12 +250,12 @@ impl LibraryParseResult {
&item.attrs,
mod_cfg) {
Ok(func) => {
info!("take {}::{}", crate_name, &item.ident);
info!("Take {}::{}.", crate_name, &item.ident);
self.functions.push(func);
}
Err(msg) => {
error!("cannot use fn {}::{} ({})",
error!("Cannot use fn {}::{} ({}).",
crate_name,
&item.ident,
msg);
......@@ -263,12 +263,12 @@ impl LibraryParseResult {
}
} else {
if (abi.is_omitted() || abi.is_c()) && !item.is_no_mangle() {
warn!("skip {}::{} - (`extern` but not `no_mangle`)",
warn!("Skip {}::{} - (`extern` but not `no_mangle`).",
crate_name,
&item.ident);
}
if abi.is_some() && !(abi.is_omitted() || abi.is_c()) {
warn!("skip {}::{} - (non `extern \"C\"`)",
warn!("Skip {}::{} - (non `extern \"C\"`).",
crate_name,
&item.ident);
}
......@@ -290,12 +290,12 @@ impl LibraryParseResult {
&item.attrs,
mod_cfg) {
Ok(st) => {
info!("take {}::{}", crate_name, &item.ident);
info!("Take {}::{}.", crate_name, &item.ident);
self.structs.try_insert(st);
}
Err(msg) => {
info!("take {}::{} - opaque ({})",
info!("Take {}::{} - opaque ({}).",
crate_name,
&item.ident,
msg);
......@@ -317,7 +317,7 @@ impl LibraryParseResult {
if !generics.lifetimes.is_empty() ||
!generics.ty_params.is_empty() ||
!generics.where_clause.predicates.is_empty() {
info!("skip {}::{} - (has generics or lifetimes or where bounds)",
info!("Skip {}::{} - (has generics or lifetimes or where bounds).",
crate_name,
&item.ident);
return;
......@@ -329,11 +329,11 @@ impl LibraryParseResult {
&item.attrs,
mod_cfg) {
Ok(en) => {
info!("take {}::{}", crate_name, &item.ident);
info!("Take {}::{}.", crate_name, &item.ident);
self.enums.try_insert(en);
}
Err(msg) => {
info!("take {}::{} - opaque ({})", crate_name, &item.ident, msg);
info!("Take {}::{} - opaque ({}).", crate_name, &item.ident, msg);
self.opaque_items.try_insert(OpaqueItem::new(enum_name,
generics,
&item.attrs,
......@@ -360,14 +360,14 @@ impl LibraryParseResult {
mod_cfg)
{
Ok(typedef) => {
info!("take {}::{}", crate_name, &item.ident);
info!("Take {}::{}.", crate_name, &item.ident);
self.typedefs.try_insert(typedef);
return;
}
Err(msg) => msg,
}
} else {
format!("cannot have generics in typedef")
format!("Cannot have generics in typedef.")
};
let fail2 = match Specialization::load(alias_name.clone(),
......@@ -376,14 +376,14 @@ impl LibraryParseResult {
&item.attrs,
mod_cfg) {
Ok(spec) => {
info!("take {}::{}", crate_name, &item.ident);
info!("Take {}::{}.", crate_name, &item.ident);
self.specializations.try_insert(spec);
return;
}
Err(msg) => msg,
};
info!("skip {}::{} - ({} and {})",
info!("Skip {}::{} - ({} and {}).",
crate_name,
&item.ident,
fail1,
......
......@@ -39,7 +39,7 @@ impl FromStr for Language {
"C++" => Ok(Language::Cxx),
"c" => Ok(Language::C),
"C" => Ok(Language::C),
_ => Err(format!("unrecognized Language: '{}'", s)),
_ => Err(format!("Unrecognized Language: '{}'.", s)),
}
}
}
......@@ -62,7 +62,7 @@ impl FromStr for Braces {
"same_line" => Ok(Braces::SameLine),
"NextLine" => Ok(Braces::NextLine),
"next_line" => Ok(Braces::NextLine),
_ => Err(format!("unrecognized Braces: '{}'", s)),
_ => Err(format!("Unrecognized Braces: '{}'.", s)),
}
}
}
......@@ -88,7 +88,7 @@ impl FromStr for Layout {
"vertical" => Ok(Layout::Vertical),
"Auto" => Ok(Layout::Auto),
"auto" => Ok(Layout::Auto),
_ => Err(format!("unrecognized Layout: '{}'", s)),
_ => Err(format!("Unrecognized Layout: '{}'.", s)),
}
}
}
......@@ -367,7 +367,7 @@ impl Config {
match toml::from_str::<Config>(&config_text) {
Ok(x) => Ok(x),
Err(e) => Err(format!("couldn't parse config file: {}", e)),
Err(e) => Err(format!("Couldn't parse config file: {}.", e)),
}
}
......
......@@ -81,7 +81,7 @@ impl AnnotationSet {
.collect();
if parts.len() > 2 {
return Err(format!("couldn't parse {}", line));
return Err(format!("Couldn't parse {}.", line));
}
// Grab the name that this annotation is modifying
......
......@@ -38,7 +38,7 @@ impl Enum {
repr != Repr::I32 &&
repr != Repr::I16 &&
repr != Repr::I8 {
return Err(format!("enum not marked with a valid repr(prim) or repr(C)"));
return Err("Enum not marked with a valid repr(prim) or repr(C).".to_owned());
}
let mut values = Vec::new();
......@@ -52,7 +52,7 @@ impl Enum {
current = i;
}
Some(_) => {
return Err(format!("unsupported discriminant"));
return Err("Unsupported discriminant.".to_owned());
}
None => { /* okay, we just use current */ }
}
......@@ -63,7 +63,7 @@ impl Enum {
current = current + 1;
}
_ => {
return Err(format!("unsupported variant"));
return Err("Unsupported variant.".to_owned());
}
}
}
......
......@@ -167,7 +167,7 @@ impl SynFnArgHelpers for syn::FnArg {
Ok(None)
}
}
_ => Err(format!("parameter has unexpected type")),
_ => Err("Parameter has an unsupported type.".to_owned()),
}
}
}
......@@ -80,7 +80,7 @@ impl Item for OpaqueItem {
fn specialize(&self, _: &Library, aliasee: &Specialization) -> Result<Box<Item>, String> {
if aliasee.aliased.generics.len() !=
self.generic_params.len() {
return Err(format!("incomplete specialization"));
return Err("Incomplete specialization, the amount of generics in the path doesn't match the amount of generics in the item.".to_owned());
}
Ok(Box::new(OpaqueItem {
......
......@@ -39,7 +39,7 @@ impl GenericPath {
.try_skip_map(|x| Type::load(x))?
}
&syn::PathParameters::Parenthesized(_) => {
return Err(format!("path contains parentheses"));
return Err("Path contains parentheses.".to_owned());
}
};
......
......@@ -38,7 +38,7 @@ impl Specialization {
let path = GenericPath::load(p)?;
if PrimitiveType::maybe(&path.name).is_some() {
return Err(format!("can't specialize a primitive"));
return Err("Definition is a primitive, which cannot be specialized.".to_owned());
}
Ok(Specialization {
......@@ -51,7 +51,7 @@ impl Specialization {
})
}
_ => {
Err(format!("not a path"))
Err("Definition is not a path.".to_owned())
}
}
}
......@@ -61,7 +61,7 @@ impl Specialization {
assert!(items.len() > 0);
if items.len() > 1 {
warn!("specializing an aliased type with multiple definitions");
warn!("Specializing an aliased type with multiple definitions is possible but unsupported currently.");
}
match items[0] {
......@@ -82,7 +82,7 @@ impl Specialization {
}
}
} else {
Err(format!("couldn't find aliased type"))
Err(format!("Couldn't find aliased type {:?} for specializing.", self.aliased))
}
}
}
......@@ -111,7 +111,7 @@ impl Item for Specialization {
fn specialize(&self, library: &Library, aliasee: &Specialization) -> Result<Box<Item>, String> {
if aliasee.aliased.generics.len() !=
self.generic_params.len() {
return Err(format!("incomplete specialization"));
return Err("Incomplete specialization, the amount of generics in the path doesn't match the amount of generics in the item.".to_owned());
}
let mappings = self.generic_params.iter()
......@@ -133,6 +133,6 @@ impl Item for Specialization {
}
fn add_dependencies(&self, _: &Library, _: &mut Dependencies) {
unreachable!("Specialization's must be specialized before dependency gathering.");
unreachable!("Specializations must be specialized before dependency gathering.");
}
}
......@@ -35,7 +35,7 @@ impl Struct {
mod_cfg: &Option<Cfg>) -> Result<Struct, String>
{
if Repr::load(attrs) != Repr::C {
return Err("struct is not marked #[repr(C)]".to_owned());
return Err("Struct is not marked #[repr(C)].".to_owned());
}
let (fields, tuple_struct) = match decl {
......@@ -186,7 +186,7 @@ impl Item for Struct {
fn specialize(&self, _: &Library, aliasee: &Specialization) -> Result<Box<Item>, String> {
if aliasee.aliased.generics.len() !=
self.generic_params.len() {
return Err(format!("incomplete specialization"));
return Err("Incomplete specialization, the amount of generics in the path doesn't match the amount of generics in the item.".to_owned());
}
let mappings = self.generic_params.iter()
......
......@@ -183,7 +183,7 @@ impl Type {
let converted = match converted {
Some(converted) => converted,
None => return Err(format!("cannot have a pointer to a zero sized type")),
None => return Err("Cannot have a pointer to a zero sized type. If you are trying to represent `void*` use `c_void*`.".to_owned()),
};
match mut_ty.mutability {
......@@ -196,7 +196,7 @@ impl Type {
let converted = match converted {
Some(converted) => converted,
None => return Err(format!("cannot have a pointer to a zero sized type")),
None => return Err("Cannot have a pointer to a zero sized type. If you are trying to represent `void*` use `c_void*`.".to_owned()),
};
match mut_ty.mutability {
......@@ -213,7 +213,7 @@ impl Type {
if let Some(prim) = PrimitiveType::maybe(&path.name) {
if path.generics.len() > 0 {
return Err(format!("primitive has generics"));
return Err("Primitive has generics.".to_owned());
}
Type::Primitive(prim)
} else {
......@@ -225,7 +225,7 @@ impl Type {
let converted = match converted {
Some(converted) => converted,
None => return Err(format!("cannot have an array of zero sized types")),
None => return Err("Cannot have an array of zero sized types.".to_owned()),
};
Type::Array(Box::new(converted), size)
......@@ -241,9 +241,9 @@ impl Type {
if fields.len() == 0 {
return Ok(None);
}
return Err(format!("tuples are not supported as types"))
return Err("Tuples are not supported types.".to_owned())
}
_ => return Err(format!("unexpected type")),
_ => return Err("Unsupported type.".to_owned()),
};
return Ok(Some(converted));
......@@ -332,7 +332,7 @@ impl Type {
}
}
} else {
warn!("can't find {}", path.name);
warn!("Can't find {}. This usually means that this type was incompatible or not found.", path.name);
}
}
}
......@@ -377,13 +377,13 @@ impl Type {
x.instantiate_monomorph(&path.generics, library, out);
},
ItemContainer::Enum(..) => {
warn!("cannot instantiate a generic enum")
warn!("Cannot instantiate a generic enum.")
},
ItemContainer::Typedef(..) => {
warn!("cannot instantiate a generic typedef")
warn!("Cannot instantiate a generic typedef.")
},
ItemContainer::Specialization(..) => {
warn!("cannot instantiate a generic specialization")
warn!("Cannot instantiate a generic specialization.")
},
}
}
......@@ -419,7 +419,7 @@ impl Type {
path.name = mangled.clone();
path.generics = Vec::new();
} else {
warn!("cannot find a monomorph for {:?}", path);
error!("Cannot find a mangling for generic path {:?}. This usually means that a type referenced by this generic was incompatible or not found.", path);
}
}
&mut Type::Primitive(_) => { }
......
......@@ -38,7 +38,7 @@ impl Typedef {
documentation: Documentation::load(attrs),
})
} else {
Err(format!("cannot have a typedef of a zero sized type"))
Err("Cannot have a typedef of a zero sized type.".to_owned())
}
}
......@@ -50,7 +50,7 @@ impl Typedef {
match self.aliased.get_root_path() {
Some(alias_path) => {
if out.contains_key(&alias_path) {
warn!("multiple typedef's with annotations for {}. ignoring annotations from {}.",
warn!("Multiple typedef's with annotations for {}. Ignoring annotations from {}.",
alias_path, self.name);
return;
}
......
......@@ -131,7 +131,7 @@ impl Library {
*x.annotations_mut() = annotations.clone();
transferred = true;
} else {
warn!("can't transfer annotations from typedef to alias ({}) that already has annotations.",
warn!("Can't transfer annotations from typedef to alias ({}) that already has annotations.",
alias_path);
}
});
......@@ -143,7 +143,7 @@ impl Library {
*x.annotations_mut() = annotations.clone();
transferred = true;
} else {
warn!("can't transfer annotations from typedef to alias ({}) that already has annotations.",
warn!("Can't transfer annotations from typedef to alias ({}) that already has annotations.",
alias_path);
}
});
......@@ -155,7 +155,7 @@ impl Library {
*x.annotations_mut() = annotations.clone();
transferred = true;
} else {
warn!("can't transfer annotations from typedef to alias ({}) that already has annotations.",
warn!("Can't transfer annotations from typedef to alias ({}) that already has annotations.",
alias_path);
}
});
......@@ -167,7 +167,7 @@ impl Library {
*x.annotations_mut() = annotations.clone();
transferred = true;
} else {
warn!("can't transfer annotations from typedef to alias ({}) that already has annotations.",
warn!("Can't transfer annotations from typedef to alias ({}) that already has annotations.",
alias_path);
}
});
......@@ -179,7 +179,7 @@ impl Library {
*x.annotations_mut() = annotations.clone();
transferred = true;
} else {
warn!("can't transfer annotations from typedef to alias ({}) that already has annotations.",
warn!("Can't transfer annotations from typedef to alias ({}) that already has annotations.",
alias_path);
}
});
......@@ -208,7 +208,7 @@ impl Library {
specializations.push(specialization);
}
Err(msg) => {
warn!("specializing {} failed - ({})", x.name.clone(), msg);
warn!("Specializing {} failed - ({}).", x.name.clone(), msg);
}
}
});
......
......@@ -233,7 +233,7 @@ impl FromStr for RenameRule {
"QualifiedScreamingSnakeCase" => Ok(RenameRule::QualifiedScreamingSnakeCase),
"qualified_screaming_snake_case" => Ok(RenameRule::QualifiedScreamingSnakeCase),
_ => Err(format!("unrecognized RenameRule: '{}'", s)),
_ => Err(format!("Unrecognized RenameRule: '{}'.", s)),
}
}
}
......
......@@ -28,9 +28,9 @@ pub fn parse_src<F>(src_file: &Path,
{
let src_parsed = {
let mut s = String::new();
let mut f = File::open(src_file).map_err(|_| format!("parsing: cannot open file `{:?}`", src_file))?;
f.read_to_string(&mut s).map_err(|_| format!("parsing: cannot open file `{:?}`", src_file))?;
syn::parse_crate(&s).map_err(|msg| format!("parsing:\n{}", msg))?
let mut f = File::open(src_file).map_err(|_| format!("Parsing: cannot open file `{:?}`.", src_file))?;
f.read_to_string(&mut s).map_err(|_| format!("Parsing: cannot open file `{:?}`.", src_file))?;
syn::parse_crate(&s).map_err(|msg| format!("Parsing:\n{}.", msg))?
};
items_callback("", &src_parsed.items);
......@@ -137,7 +137,7 @@ fn parse_crate<F>(pkg: &PackageRef, context: &mut ParseLibContext<F>) -> ParseRe
},
None => {
// This should be an error, but is common enough to just elicit a warning
warn!("parsing crate `{}`: can't find lib.rs with `cargo metadata`", pkg.name);
warn!("Parsing crate `{}`: can't find lib.rs with `cargo metadata`.", pkg.name);
Ok(())
},
}
......@@ -149,7 +149,7 @@ fn parse_expand_crate<F>(pkg: &PackageRef, context: &mut ParseLibContext<F>) ->
let mod_parsed = {
if !context.cache_expanded_crate.contains_key(&pkg.name) {
let s = context.lib.expand_crate(pkg)?;
let i = syn::parse_crate(&s).map_err(|msg| format!("parsing crate `{}`:\n{}", pkg.name, msg))?;
let i = syn::parse_crate(&s).map_err(|msg| format!("Parsing crate `{}`:\n{}.", pkg.name, msg))?;
context.cache_expanded_crate.insert(pkg.name.clone(), i.items);
}
......@@ -180,7 +180,7 @@ fn process_expanded_mod<F>(pkg: &PackageRef,
if let &Some(ref inline_items) = inline_items {
process_expanded_mod(pkg, inline_items, context)?;
} else {
error!("parsing crate `{}`: external mod found in expanded source", pkg.name);
error!("Parsing crate `{}`: external mod found in expanded source, this shouldn't be possible.", pkg.name);
}
if cfg.is_some() {
......@@ -201,7 +201,7 @@ fn process_expanded_mod<F>(pkg: &PackageRef,
if let Some(dep_pkg_ref) = dep_pkg_ref {
parse_crate(&dep_pkg_ref, context)?;
} else {
error!("parsing crate `{}`: can't find dependency version for {}`", pkg.name, dep_pkg_name);
error!("Parsing crate `{}`: can't find dependency version for {}`.", pkg.name, dep_pkg_name);
}
}
......@@ -226,9 +226,9 @@ fn parse_mod<F>(pkg: &PackageRef,
if !context.cache_src.contains_key(&owned_mod_path) {
let mut s = String::new();
let mut f = File::open(mod_path).map_err(|_| format!("parsing crate `{}`: cannot open file `{:?}`", pkg.name, mod_path))?;
f.read_to_string(&mut s).map_err(|_| format!("parsing crate `{}`: cannot open file `{:?}`", pkg.name, mod_path))?;
let i = syn::parse_crate(&s).map_err(|msg| format!("parsing crate `{}`:\n{}", pkg.name, msg))?;
let mut f = File::open(mod_path).map_err(|_| format!("Parsing crate `{}`: cannot open file `{:?}`.", pkg.name, mod_path))?;
f.read_to_string(&mut s).map_err(|_| format!("Parsing crate `{}`: cannot open file `{:?}`.", pkg.name, mod_path))?;
let i = syn::parse_crate(&s).map_err(|msg| format!("Parsing crate `{}`:\n{}.", pkg.name, msg))?;
context.cache_src.insert(owned_mod_path.clone(), i.items);
}
......@@ -283,7 +283,7 @@ fn process_mod<F>(pkg: &PackageRef,
context)?;
} else {
// This should be an error, but is common enough to just elicit a warning
warn!("parsing crate `{}`: can't find mod {}`", pkg.name, next_mod_name);
warn!("Parsing crate `{}`: can't find mod {}`.", pkg.name, next_mod_name);
}
}
......@@ -305,7 +305,7 @@ fn process_mod<F>(pkg: &PackageRef,
if let Some(dep_pkg_ref) = dep_pkg_ref {
parse_crate(&dep_pkg_ref, context)?;
} else {
error!("parsing crate `{}`: can't find dependency version for {}`", pkg.name, dep_pkg_name);
error!("Parsing crate `{}`: can't find dependency version for {}`.", pkg.name, dep_pkg_name);
}
}
......
......@@ -33,7 +33,7 @@ fn apply_config_overrides<'a>(config: &mut Config, matches: &ArgMatches<'a>) {
"C"=> Language::C,
"c"=> Language::C,
_ => {
error!("unknown language specified");
error!("Unknown language specified.");
return;
}
};
......@@ -146,7 +146,7 @@ fn main() {
Ok(library) => library,
Err(msg) => {
error!("{}", msg);
error!("couldn't generate bindings for {}", input.display());
error!("Couldn't generate bindings for {}.", input.display());
return;
}
};
......@@ -156,7 +156,7 @@ fn main() {
Ok(x) => x,
Err(msg) => {
error!("{}", msg);
error!("couldn't generate bindings for {}", input.display());
error!("Couldn't generate bindings for {}.", input.display());
return;
},
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment