-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
serde_macros incompatible with extern crate serde
not in toplevel module
#159
Comments
Unfortunately I'm not sure if there's much we can do in this circumstance. I'm not sure if it's possible to resolve the location of the serde crate, so the most reliable location to find it is in the toplevel crate namespace. |
Hm, good point. This might be worth bringing up whenever custom derivers are being stabilized. |
It's worse than that, I think we need name resolution to happen in order to find where the serde crate was imported, which may not get exposed to compiler plugins for a long time :( |
What if you did something like expanding it to... mod internal {
extern crate serde;
impl serde::whatever for dunno {}
}
use internal::*; but cleaner? Basically, hygiene for crate imports. |
hm, am I correct in understanding that |
It should work as long as The following works for me: #![feature(plugin, custom_derive)]
#![plugin(serde_macros)]
extern crate serde;
mod m {
#[derive(Serialize)]
pub struct Success;
}
fn main() {
fn assert<T: serde::Serialize>(_: T) {}
assert(m::Success);
} |
Thanks @dtolnay |
In line with @whitequark's idea, I started implementing this as: mod m {
struct A { ... }
#[derive(Serialize)]
struct B { a: A }
}
// -->
mod m {
struct A { ... }
struct B { a: A }
mod B_Serialize {
use /* ??? */;
extern crate serde;
impl serde::Serialize for B { ... }
}
} I ran into trouble on the line marked It works if I do
As far as I know, all of these "look" identical during macro expansion so it will be tricky to differentiate. |
I think I have a much more promising approach. Apparently this is allowed... const _IMPL_DESERIALIZE_FOR_S: () = {
extern crate serde as _serde;
impl _serde::Deserialize for S {
// ...
}
}; and it is way nicer than using a module to declare the impl because it does not affect the scope of imports. I will work on a PR today. |
@whitequark @erickt @oli-obk this was addressed in #298 and can be closed. |
thanks @dtolnay |
Unintended consequence: truly awful compiler diagnostics:
|
we could probably fix this (in rustc) by checking if a path goes into an external crate, and invent a new display syntax along the lines of |
Add Binary, Octal to BigUint. Add UpperHex, LowerHex, Binary, Octal to BigInt Is the testing for these enough? Any suggestions to improve them?
The 'dummy const' pattern was copied from SerDe[1], but it causes rustdoc not to generate documentation due to a [known bug][2]. Apparently SerDe [considered][3] using a dummy module instead of a dummy const, but decided against it due to private type issues. Since everything's public in `prost`, we shouldn't have such an issue. Also removes #[automatically_derived] annotations, since apparently the no longer do anything[4]. Fixes #11 [1]: https://github.com/serde-rs/serde/blob/775e8154e7151eb1576d65df539c4ac1612595c6/serde_derive/src/ser.rs#L28 [2]: rust-lang/rust#36922 [3]: serde-rs/serde#159 (comment) [4]: https://botbot.me/mozilla/rust/2017-07-11/?msg=88402326&page=3
The 'dummy const' pattern was copied from SerDe[1], but it causes rustdoc not to generate documentation due to a [known bug][2]. Apparently SerDe [considered][3] using a dummy module instead of a dummy const, but decided against it due to private type issues. Since everything's public in `prost`, we shouldn't have such an issue. Also removes #[automatically_derived] annotations, since apparently the no longer do anything[4]. Fixes #11 [1]: https://github.com/serde-rs/serde/blob/775e8154e7151eb1576d65df539c4ac1612595c6/serde_derive/src/ser.rs#L28 [2]: rust-lang/rust#36922 [3]: serde-rs/serde#159 (comment) [4]: https://botbot.me/mozilla/rust/2017-07-11/?msg=88402326&page=3
The 'dummy const' pattern was copied from SerDe[1], but it causes rustdoc not to generate documentation due to a [known bug][2]. Apparently SerDe [considered][3] using a dummy module instead of a dummy const, but decided against it due to private type issues. Since everything's public in `prost`, we shouldn't have such an issue. Also removes #[automatically_derived] annotations, since apparently the no longer do anything[4]. Fixes #11 [1]: https://github.com/serde-rs/serde/blob/775e8154e7151eb1576d65df539c4ac1612595c6/serde_derive/src/ser.rs#L28 [2]: rust-lang/rust#36922 [3]: serde-rs/serde#159 (comment) [4]: https://botbot.me/mozilla/rust/2017-07-11/?msg=88402326&page=3
To reproduce:
The text was updated successfully, but these errors were encountered: