Skip to content

lib: Return error early if there are any error diagnostics. #330

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 3 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion libbindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "BSD-3-Clause"
name = "libbindgen"
readme = "README.md"
repository = "https://github.com/servo/rust-bindgen"
version = "0.1.1"
version = "0.1.2"
workspace = ".."

[dev-dependencies]
Expand Down
11 changes: 9 additions & 2 deletions libbindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'ctx> Bindings<'ctx> {
let span = span.unwrap_or(DUMMY_SP);

let mut context = BindgenContext::new(options);
parse(&mut context);
try!(parse(&mut context));

let module = ast::Mod {
inner: span,
Expand Down Expand Up @@ -624,14 +624,20 @@ pub fn parse_one(ctx: &mut BindgenContext,
}

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

let mut any_error = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier to get context.translation_unit().diags() first, and if it is not empty, iterate it and return Err.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In diags there can be warnings too, so we'd need to filter them.

for d in context.translation_unit().diags().iter() {
let msg = d.format(Diagnostic::default_opts());
let is_err = d.severity() >= CXDiagnostic_Error;
println!("{}, err: {}", msg, is_err);
any_error |= is_err;
}

if any_error {
return Err(());
}

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

assert!(context.current_module() == context.root_module(),
"How did this happen?");
Ok(())
}

/// Extracted Clang version data
Expand Down
2 changes: 2 additions & 0 deletions libbindgen/tests/headers/empty_template_param_name.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// bindgen-flags: -- -std=c++11

template<typename...> using __void_t = void;

template<typename _Iterator, typename = __void_t<>>
Expand Down