Skip to content
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

Use the generated root module via a relative path #309

Merged
merged 1 commit into from Dec 2, 2016

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Dec 1, 2016

We previously generated uses of the root module with absolute paths:

use root;

However this only works if the generated bindings are the root of the
crate. If they were in some submodule then that path would not be
valid. They are now generated relative to the current module, like this:

use self::super::super::root;

Fixes #96

r? @emilio

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

I'm not sure the self:: is necessary, but this looks great anyway. r=me with the nits addressed :)

.ancestors(ctx)
.filter(|id| ctx.resolve_item(*id).is_module())
.map(|_| super_.clone())
.chain(iter::once(super_.clone()));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think you need this clone.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, thanks.

use std::mem;
use std::ops;
use syntax::abi::Abi;
use syntax::ast;
use syntax::codemap::{Span, respan};
use syntax::ptr::P;

fn root_import(ctx: &BindgenContext) -> P<ast::Item> {
fn root_import(ctx: &BindgenContext, module: &Item) -> P<ast::Item> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably assert!(module.is_module())?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea.

@fitzgen
Copy link
Member Author

fitzgen commented Dec 2, 2016

Thanks, @emilio !

We previously generated uses of the root module with absolute paths:

    use root;

However this only works if the generated bindings are the root of the
crate. If they were in some submodule then that path would not be
valid. They are now generated relative to the current module, like this:

    use self::super::super::root;

Fixes rust-lang#96
@fitzgen
Copy link
Member Author

fitzgen commented Dec 2, 2016

@bors-servo r=emilio

@bors-servo
Copy link

📌 Commit 8091fd6 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 8091fd6 with merge b8014b1...

bors-servo pushed a commit that referenced this pull request Dec 2, 2016
Use the generated root module via a relative path

We previously generated uses of the root module with absolute paths:

    use root;

However this only works if the generated bindings are the root of the
crate. If they were in some submodule then that path would not be
valid. They are now generated relative to the current module, like this:

    use self::super::super::root;

Fixes #96

r? @emilio
@bors-servo
Copy link

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit 8091fd6 into rust-lang:master Dec 2, 2016
@fitzgen fitzgen deleted the use-root-relative branch December 2, 2016 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants