Skip to content

Commit 09c66d1

Browse files
committed
lib: Return error early if there are any error diagnostics.
1 parent 854aa11 commit 09c66d1

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

libbindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "BSD-3-Clause"
1212
name = "libbindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/servo/rust-bindgen"
15-
version = "0.1.1"
15+
version = "0.1.2"
1616
workspace = ".."
1717

1818
[dev-dependencies]

libbindgen/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl<'ctx> Bindings<'ctx> {
510510
let span = span.unwrap_or(DUMMY_SP);
511511

512512
let mut context = BindgenContext::new(options);
513-
parse(&mut context);
513+
try!(parse(&mut context));
514514

515515
let module = ast::Mod {
516516
inner: span,
@@ -624,14 +624,20 @@ pub fn parse_one(ctx: &mut BindgenContext,
624624
}
625625

626626
/// Parse the Clang AST into our `Item` internal representation.
627-
fn parse(context: &mut BindgenContext) {
627+
fn parse(context: &mut BindgenContext) -> Result<(), ()> {
628628
use clang::Diagnostic;
629629
use clangll::*;
630630

631+
let mut any_error = false;
631632
for d in context.translation_unit().diags().iter() {
632633
let msg = d.format(Diagnostic::default_opts());
633634
let is_err = d.severity() >= CXDiagnostic_Error;
634635
println!("{}, err: {}", msg, is_err);
636+
any_error |= is_err;
637+
}
638+
639+
if any_error {
640+
return Err(());
635641
}
636642

637643
let cursor = context.translation_unit().cursor();
@@ -646,6 +652,7 @@ fn parse(context: &mut BindgenContext) {
646652

647653
assert!(context.current_module() == context.root_module(),
648654
"How did this happen?");
655+
Ok(())
649656
}
650657

651658
/// Extracted Clang version data

libbindgen/tests/headers/empty_template_param_name.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// bindgen-flags: -- -std=c++11
2+
13
template<typename...> using __void_t = void;
24

35
template<typename _Iterator, typename = __void_t<>>

0 commit comments

Comments
 (0)