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
10 changes: 7 additions & 3 deletions libbindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ impl Builder {
/// Set the input C/C++ header.
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
let header = header.into();
self.options.input_header = Some(header.clone());
self.clang_arg(header)
self.options.input_header = Some(header);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the only effect of this function is setting input_header, I guess it probably makes sense to assert that input_header is None before assigning it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't quite fit with the rest of the builder methods, I think overriding it, albeit uncommon, should be fine?

self
}

/// Generate a C/C++ file that includes the header and has dummy uses of
Expand Down Expand Up @@ -504,11 +504,15 @@ impl<'ctx> Bindings<'ctx> {
///
/// Deprecated - use a `Builder` instead
#[deprecated]
pub fn generate(options: BindgenOptions,
pub fn generate(mut options: BindgenOptions,
span: Option<Span>)
-> Result<Bindings<'ctx>, ()> {
let span = span.unwrap_or(DUMMY_SP);

if let Some(h) = options.input_header.as_ref() {
options.clang_args.push(h.clone())
}

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

Expand Down
12 changes: 12 additions & 0 deletions libbindgen/tests/expectations/tests/dash_language.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Foo<T> {
pub bar: ::std::os::raw::c_int,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
6 changes: 6 additions & 0 deletions libbindgen/tests/headers/dash_language.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// bindgen-flags: -- -x c++ --std=c++11
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how this test is related to this commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is related because before that, that gives an error due to us sending the header before -x c++, and treats it as C because it's a .h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That being said that's probably a clang bug.


template<typename T>
struct Foo {
int bar;
};