Skip to content

fix: 'core' module conflict in Bindgen::emit#568

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
danbev:emit_core_mem_conflict
May 4, 2023
Merged

fix: 'core' module conflict in Bindgen::emit#568
alexcrichton merged 2 commits intobytecodealliance:mainfrom
danbev:emit_core_mem_conflict

Conversation

@danbev
Copy link
Copy Markdown
Contributor

@danbev danbev commented May 3, 2023

This commit is an attempt to avoid module name conflicts where a user library may have a module defined as follows:

mod core;

wit_bindgen::generate!("component");

This would currently clash with the 'core' module used in the Bindgen::emit function and result in a compilation error:

31 | wit_bindgen::generate!("component");
     |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `mem` in `core`

@danbev
Copy link
Copy Markdown
Contributor Author

danbev commented May 3, 2023

Sorry about the ci failures, I only ran cargo test locally. I'll take a look at the failures.

@danbev danbev force-pushed the emit_core_mem_conflict branch from 4017278 to f46d628 Compare May 3, 2023 14:59
Copy link
Copy Markdown
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Can we instead use a leading ::, i.e. ::core::mem::forget?

@danbev
Copy link
Copy Markdown
Contributor Author

danbev commented May 3, 2023

Can we instead use a leading ::, i.e. ::core::mem::forget?

Ah, that would be much better! I'll update shortly, thanks!

This commit is an attempt to avoid module name conflicts where a user
library may have a module defined as follows:
```rust
mod core;

wit_bindgen::generate!("component");
```
This would currently clash with the 'core' module used in the
`Bindgen::emit` function and result in a compilation error:
```console
31 | wit_bindgen::generate!("component");
     |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `mem` in `core`
```

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
@danbev danbev force-pushed the emit_core_mem_conflict branch from f46d628 to 9720678 Compare May 3, 2023 16:52
@alexcrichton
Copy link
Copy Markdown
Member

Oh also, could you add a test for this? Probably somewhere around tests/codegen.rs for the Rust bindgen.

@danbev
Copy link
Copy Markdown
Contributor Author

danbev commented May 3, 2023

Oh also, could you add a test for this? Probably somewhere around tests/codegen.rs for the Rust bindgen.

Absolutely, I'll take a look at adding one tomorrow.

This commit adds additional external crate prefixes (::) to 'core'
modules used in code generated from macros.

It also adds a "test" in that an empty module named 'core' has been
added to catch any future additions or modifications.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
@alexcrichton alexcrichton merged commit 41f388e into bytecodealliance:main May 4, 2023
@alexcrichton
Copy link
Copy Markdown
Member

Thanks!

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.

3 participants