summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clang.rs4
-rw-r--r--src/codegen/struct_layout.rs5
-rw-r--r--src/ir/comp.rs2
-rw-r--r--src/ir/context.rs23
-rw-r--r--src/ir/dot.rs18
-rw-r--r--src/ir/function.rs12
-rw-r--r--src/ir/item.rs4
-rw-r--r--src/ir/item_kind.rs4
-rw-r--r--src/ir/traversal.rs5
-rw-r--r--src/ir/ty.rs12
-rw-r--r--src/ir/var.rs20
-rw-r--r--src/lib.rs12
-rw-r--r--src/options.rs2
13 files changed, 52 insertions, 71 deletions
diff --git a/src/clang.rs b/src/clang.rs
index c0c96e5e..cb873994 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -903,8 +903,8 @@ impl Type {
/// have a valid layout.
pub fn fallible_layout(&self) -> Result<::ir::layout::Layout, LayoutError> {
use ir::layout::Layout;
- let size = try!(self.fallible_size());
- let align = try!(self.fallible_align());
+ let size = self.fallible_size()?;
+ let align = self.fallible_align()?;
Ok(Layout::new(size, align))
}
diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs
index 32b48965..a538c35f 100644
--- a/src/codegen/struct_layout.rs
+++ b/src/codegen/struct_layout.rs
@@ -155,10 +155,7 @@ impl<'a> StructLayoutTracker<'a> {
field_ty: &Type,
field_offset: Option<usize>,
) -> Option<quote::Tokens> {
- let mut field_layout = match field_ty.layout(self.ctx) {
- Some(l) => l,
- None => return None,
- };
+ let mut field_layout = field_ty.layout(self.ctx)?;
if let TypeKind::Array(inner, len) =
*field_ty.canonical_type(self.ctx).kind()
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 50d0ddb1..24909cb5 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1169,7 +1169,7 @@ impl CompInfo {
}
}
- let kind = try!(kind);
+ let kind = kind?;
debug!("CompInfo::from_ty({:?}, {:?})", kind, cursor);
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 0a914523..df8a84ef 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -475,13 +475,13 @@ impl<'ctx> Iterator for WhitelistedItemsTraversal<'ctx> {
fn next(&mut self) -> Option<ItemId> {
loop {
- match self.traversal.next() {
- None => return None,
- Some(id) if self.ctx.resolve_item(id).is_blacklisted(self.ctx) => {
- continue
- }
- Some(id) => return Some(id),
+ let id = self.traversal.next()?;
+
+ if self.ctx.resolve_item(id).is_blacklisted(self.ctx) {
+ continue
}
+
+ return Some(id);
}
}
}
@@ -1009,10 +1009,8 @@ impl BindgenContext {
let comp_item_ids: Vec<ItemId> = self.items
.iter()
.filter_map(|(id, item)| {
- if let Some(ty) = item.kind().as_type() {
- if let Some(_comp) = ty.as_comp() {
- return Some(id);
- }
+ if item.kind().as_type()?.is_comp() {
+ return Some(id);
}
None
})
@@ -1673,10 +1671,7 @@ impl BindgenContext {
}
clang_sys::CXCursor_TemplateRef => {
let (template_decl_cursor, template_decl_id, num_expected_template_args) =
- match self.get_declaration_info_for_template_instantiation(child) {
- Some(info) => info,
- None => return None,
- };
+ self.get_declaration_info_for_template_instantiation(child)?;
if num_expected_template_args == 0 ||
child.has_at_least_num_children(
diff --git a/src/ir/dot.rs b/src/ir/dot.rs
index 1181c32c..48bd1d91 100644
--- a/src/ir/dot.rs
+++ b/src/ir/dot.rs
@@ -25,16 +25,16 @@ pub fn write_dot_file<P>(ctx: &BindgenContext, path: P) -> io::Result<()>
where
P: AsRef<Path>,
{
- let file = try!(File::create(path));
+ let file = File::create(path)?;
let mut dot_file = io::BufWriter::new(file);
- try!(writeln!(&mut dot_file, "digraph {{"));
+ writeln!(&mut dot_file, "digraph {{")?;
let mut err: Option<io::Result<_>> = None;
for (id, item) in ctx.items() {
let is_whitelisted = ctx.whitelisted_items().contains(id);
- try!(writeln!(
+ writeln!(
&mut dot_file,
r#"{} [fontname="courier", color={}, label=< <table border="0" align="left">"#,
id.as_usize(),
@@ -43,9 +43,9 @@ where
} else {
"gray"
}
- ));
- try!(item.dot_attributes(ctx, &mut dot_file));
- try!(writeln!(&mut dot_file, r#"</table> >];"#));
+ )?;
+ item.dot_attributes(ctx, &mut dot_file)?;
+ writeln!(&mut dot_file, r#"</table> >];"#)?;
item.trace(
ctx,
@@ -79,16 +79,16 @@ where
if let Some(module) = item.as_module() {
for child in module.children() {
- try!(writeln!(
+ writeln!(
&mut dot_file,
"{} -> {} [style=dotted, color=gray]",
item.id().as_usize(),
child.as_usize()
- ));
+ )?;
}
}
}
- try!(writeln!(&mut dot_file, "}}"));
+ writeln!(&mut dot_file, "}}")?;
Ok(())
}
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 481ab9f7..588090ac 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -151,11 +151,11 @@ impl DotAttributes for Function {
if let Some(ref mangled) = self.mangled_name {
let mangled: String =
mangled.chars().flat_map(|c| c.escape_default()).collect();
- try!(writeln!(
+ writeln!(
out,
"<tr><td>mangled name</td><td>{}</td></tr>",
mangled
- ));
+ )?;
}
Ok(())
@@ -422,11 +422,11 @@ impl FunctionSig {
let ty_ret_type = if cursor.kind() == CXCursor_ObjCInstanceMethodDecl ||
cursor.kind() == CXCursor_ObjCClassMethodDecl
{
- try!(ty.ret_type().or_else(|| cursor.ret_type()).ok_or(
+ ty.ret_type().or_else(|| cursor.ret_type()).ok_or(
ParseError::Continue,
- ))
+ )?
} else {
- try!(ty.ret_type().ok_or(ParseError::Continue))
+ ty.ret_type().ok_or(ParseError::Continue)?
};
let ret = Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx);
let call_conv = ty.call_conv();
@@ -521,7 +521,7 @@ impl ClangSubItemParser for Function {
// Grab the signature using Item::from_ty.
let sig =
- try!(Item::from_ty(&cursor.cur_type(), cursor, None, context));
+ Item::from_ty(&cursor.cur_type(), cursor, None, context)?;
let mut name = cursor.spelling();
assert!(!name.is_empty(), "Empty function name?");
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 89ab2569..2b3c1b8c 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -1089,13 +1089,13 @@ impl DotAttributes for Item {
where
W: io::Write,
{
- try!(writeln!(
+ writeln!(
out,
"<tr><td>{:?}</td></tr>
<tr><td>name</td><td>{}</td></tr>",
self.id,
self.name(ctx).get()
- ));
+ )?;
if self.is_opaque(ctx, &()) {
writeln!(out, "<tr><td>opaque</td><td>true</td></tr>")?;
diff --git a/src/ir/item_kind.rs b/src/ir/item_kind.rs
index 58f99d0c..1e755e24 100644
--- a/src/ir/item_kind.rs
+++ b/src/ir/item_kind.rs
@@ -135,11 +135,11 @@ impl DotAttributes for ItemKind {
where
W: io::Write,
{
- try!(writeln!(
+ writeln!(
out,
"<tr><td>kind</td><td>{}</td></tr>",
self.kind_name()
- ));
+ )?;
match *self {
ItemKind::Module(ref module) => module.dot_attributes(ctx, out),
diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs
index b9b3179a..491a15f8 100644
--- a/src/ir/traversal.rs
+++ b/src/ir/traversal.rs
@@ -469,10 +469,7 @@ where
type Item = ItemId;
fn next(&mut self) -> Option<Self::Item> {
- let id = match self.queue.next() {
- None => return None,
- Some(id) => id,
- };
+ let id = self.queue.next()?;
let newly_discovered = self.seen.add(None, id);
debug_assert!(
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index e14860c2..2fab41be 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -423,20 +423,20 @@ impl DotAttributes for Type {
W: io::Write,
{
if let Some(ref layout) = self.layout {
- try!(writeln!(
+ writeln!(
out,
"<tr><td>size</td><td>{}</td></tr>
<tr><td>align</td><td>{}</td></tr>",
layout.size,
layout.align
- ));
+ )?;
if layout.packed {
- try!(writeln!(out, "<tr><td>packed</td><td>true</td></tr>"));
+ writeln!(out, "<tr><td>packed</td><td>true</td></tr>")?;
}
}
if self.is_const {
- try!(writeln!(out, "<tr><td>const</td><td>true</td></tr>"));
+ writeln!(out, "<tr><td>const</td><td>true</td></tr>")?;
}
self.kind.dot_attributes(ctx, out)
@@ -818,7 +818,7 @@ impl Type {
// trying to see if it has a valid return type.
if ty.ret_type().is_some() {
let signature =
- try!(FunctionSig::from_ty(ty, &location, ctx));
+ FunctionSig::from_ty(ty, &location, ctx)?;
TypeKind::Function(signature)
// Same here, with template specialisations we can safely
// assume this is a Comp(..)
@@ -1122,7 +1122,7 @@ impl Type {
CXType_FunctionNoProto |
CXType_FunctionProto => {
let signature =
- try!(FunctionSig::from_ty(ty, &location, ctx));
+ FunctionSig::from_ty(ty, &location, ctx)?;
TypeKind::Function(signature)
}
CXType_Typedef => {
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 84d6d9a0..25ac56d2 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -98,15 +98,15 @@ impl DotAttributes for Var {
W: io::Write,
{
if self.is_const {
- try!(writeln!(out, "<tr><td>const</td><td>true</td></tr>"));
+ writeln!(out, "<tr><td>const</td><td>true</td></tr>")?;
}
if let Some(ref mangled) = self.mangled_name {
- try!(writeln!(
+ writeln!(
out,
"<tr><td>mangled name</td><td>{}</td></tr>",
mangled
- ));
+ )?;
}
Ok(())
@@ -307,10 +307,7 @@ fn parse_macro(
) -> Option<(Vec<u8>, cexpr::expr::EvalResult)> {
use cexpr::{expr, nom};
- let mut cexpr_tokens = match cursor.cexpr_tokens() {
- None => return None,
- Some(tokens) => tokens,
- };
+ let mut cexpr_tokens = cursor.cexpr_tokens()?;
let parser = expr::IdentifierParser::new(ctx.parsed_macros());
@@ -327,9 +324,7 @@ fn parse_macro(
// See:
// https://bugs.llvm.org//show_bug.cgi?id=9069
// https://reviews.llvm.org/D26446
- if cexpr_tokens.pop().is_none() {
- return None;
- }
+ cexpr_tokens.pop()?;
match parser.macro_definition(&cexpr_tokens) {
nom::IResult::Done(_, (id, val)) => Some((id.into(), val)),
@@ -341,10 +336,7 @@ fn parse_int_literal_tokens(cursor: &clang::Cursor) -> Option<i64> {
use cexpr::{expr, nom};
use cexpr::expr::EvalResult;
- let cexpr_tokens = match cursor.cexpr_tokens() {
- None => return None,
- Some(tokens) => tokens,
- };
+ let cexpr_tokens = cursor.cexpr_tokens()?;
// TODO(emilio): We can try to parse other kinds of literals.
match expr::expr(&cexpr_tokens) {
diff --git a/src/lib.rs b/src/lib.rs
index 8665c2cd..db58f6f4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -147,13 +147,13 @@ impl Default for CodegenConfig {
/// use bindgen::builder;
///
/// // Configure and generate bindings.
-/// let bindings = try!(builder().header("path/to/input/header")
-/// .whitelisted_type("SomeCoolClass")
-/// .whitelisted_function("do_some_cool_thing")
-/// .generate());
+/// let bindings = builder().header("path/to/input/header")
+/// .whitelisted_type("SomeCoolClass")
+/// .whitelisted_function("do_some_cool_thing")
+/// .generate()?;
///
/// // Write the generated bindings to an output file.
-/// try!(bindings.write_to_file("path/to/output.rs"));
+/// bindings.write_to_file("path/to/output.rs")?;
/// ```
#[derive(Debug, Default)]
pub struct Builder {
@@ -1648,7 +1648,7 @@ impl Bindings {
{
let _t = time::Timer::new("parse")
.with_output(time_phases);
- try!(parse(&mut context));
+ parse(&mut context)?;
}
let (items, options) = codegen::codegen(context);
diff --git a/src/options.rs b/src/options.rs
index 4079603c..dbd7c17e 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -545,7 +545,7 @@ where
}
let output = if let Some(path) = matches.value_of("output") {
- let file = try!(File::create(path));
+ let file = File::create(path)?;
Box::new(io::BufWriter::new(file)) as Box<io::Write>
} else {
Box::new(io::BufWriter::new(io::stdout())) as Box<io::Write>