Skip to content

"nightly" feature of proc-macro2 is not working #88

Closed
@ngg

Description

@ngg

I have a project that tries to use prost and I have another dependency that uses the "nightly" feature of proc-macro2 which makes it a wrapper around the compiler's inner proc-macro crate.

The biggest difference is in handling spans.
While in the current version Span::def_site() and Span::call_site() is the same, it's really different in the nightly version.
I think at most of the places prost cannot use the quote! macro and Ident::from because that makes them "hygienic" so they cannot use anything from outside the macros and they cannot export anything outside of the macro.
If you run cargo build inside the tests dir, you get thousands of errors because of this.

To fix this prost should use quote_spanned!(Span::call_site()=> ...) and Ident::new(&..., Span::call_site()) at most places.

Please take a look at the discussion here about this difference: rust-lang/rust#45934

I found a quick and dirty workaround to try to use call_site() in all quote!s by overriding the macro like this:

// prost-derive/src/lib.rs
use proc_macro2::Span;
macro_rules! quote {
    ($($tt:tt)*) => (quote_spanned!(Span::call_site()=> $($tt)*));
}

The thousands of errors disappear after this, but there are a few new ones:

   Compiling tests v0.0.0 (file:///home/ngg/git/prost/tests)
error: int literal is too large
 --> /home/ngg/git/prost/target/debug/build/tests-b935ebcf576482e1/out/protobuf_unittest.rs:3:28
  |
3 | #[derive(Clone, PartialEq, Message)]
  |                            ^^^^^^^

error: proc-macro derive produced unparseable tokens
 --> /home/ngg/git/prost/target/debug/build/tests-b935ebcf576482e1/out/protobuf_unittest.rs:3:28
  |
3 | #[derive(Clone, PartialEq, Message)]
  |                            ^^^^^^^

error: Could not compile `tests`.

I've tried to change the few explicit Span::def_site() references into Span::call_site() and all Ident::from(...) into Ident::new(&..., Span::call_site()) but unfortunately these didn't fix the problem.

I have not yet debugged it further, I'd like to ask for your opinion before.
I don't think this is really urgent, but it will need to be handled somehow.

My current changes can be found here: danburkert/prost@master...ngg:nightly-proc-macro2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions