-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow reexporting proc macro output in the 2018 edition #1359
Conversation
Trying to use a proc macro from a 2018 edition crate in a 2018 edition crate that reexports wasm bindgen's output failed before this commit with "could not find `wasm_bindgen` in `{{root}}`". This commit was made with rg " ::wasm_bindgen::" --files-with-matches | xargs sed -i 's/::wasm_bindgen::/wasm_bindgen::/g'
Thanks for the PR! Can you elaborate a bit though on where this failed in the wild? The leading |
It's not really in the wild, but in a crate of mine which contains a proc macro that re-exports the code generated by wasm-bindgen. In my test crate, which uses the re-exporting crate through a proc macro attribute, the version without leading |
Oh I think I understand what you mean, sorry I think I didn't fully get what was being reexported before. I'm actually pretty surprised that this works at all, if the leading |
Yes, wasm-bindgen still needs to be in scope, but now I can hide it in a I've made a minimal reproduction of my architecture in https://github.com/konstin/wasm-bindgen-1359. The structure essentially is the following:
extern crate proc_macro;
use crate::proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn some_attribute(attr: TokenStream, input: TokenStream) -> TokenStream {
wasm_bindgen_macro_support::expand(attr.into(), input.into()).unwrap().into()
}
pub mod prelude {
pub use wasm_bindgen;
pub use lib_backend::some_attribute;
}
extern crate lib_frontend;
use lib_frontend::prelude::*;
#[some_attribute]
struct FooBar {
_x: usize
}
With the last three lines commented out it works neither in the 2015 nor in the 2018 edition, while it works in both editions if the |
Ok that makes sense, thanks for the clarification! Unfortunately though I'm not sure there's a great way to solve this. Although it's intended that you do Similarly though it can't really assume that FWIW on a somewhat unrelated note I wouldn't recommend using the |
I made this change because I thought it would be an easy win that supports that special macro usage. So if we can't gaurantee this doesn't break anyone else's code, I think I can find another workaround for this problem.
It seems to currently already assume that. For example the following 2018 crate fails to compile: [dependencies]
other_name = { package = "wasm-bindgen", version = "=0.2.40" } #[other_name::prelude::wasm_bindgen]
pub struct Bar {
pub x: usize
}
#[other_name::prelude::wasm_bindgen]
impl Bar {
fn get_x(&self) -> usize {
self.x
}
} This results in a bunch of errors like:
(Sidenote: I think that As far as I can tell there is no proper solution to this problem because rust doesn't have any way to link proc macro code to cargo dependencies.
I'm aware of that and I'll change that before the crate leaves the pet stage. Currently I simply pin wasm-bindgen. |
Hm ok, so given all that, I think I'm tempted to agree and say that we should remove all the leading
I wonder if we could get |
I tried some combinations, and I'm now 90% sure that the edition of the generated code is the edition of the declaring crate, i.e. always the 2018 edition. Unfortunately, there's nothing about the proc macro / edition interaction in the docs or in the sources for |
Interesting! I think what may actually be happening is that the new name resolution rules have been applied backwards compatibly to the 2015 edition, and I agree it's working! In that case seems like a universally good change to me, thanks again for this! |
Trying to use a proc macro from a 2018 edition crate in a 2018 edition crate that reexports wasm bindgen's output failed before this commit with "could not find
wasm_bindgen
in{{root}}
".This commit was made with