Repository: tokio-rs/prost (language: rust)

Issue:
"nightly" feature of proc-macro2 is not working
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: https://github.com/rust-lang/rust/issues/45934

I found a quick and dirty workaround to try to use call_site() in all `quote!`s by overriding the macro like this:
```rust
// 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: https://github.com/danburkert/prost/compare/master...ngg:nightly-proc-macro2


Discussion / hints:

Fix patch:
diff --git a/prost-derive/Cargo.toml b/prost-derive/Cargo.toml
index 8eb33f54c..7305d54b7 100644
--- a/prost-derive/Cargo.toml
+++ b/prost-derive/Cargo.toml
@@ -15,6 +15,6 @@ proc_macro = true
 [dependencies]
 failure = { version = "0.1", default-features = false, features = ["std"] }
 itertools = "0.7"
-proc-macro2 = "0.2"
-quote = "0.4"
-syn = { version = "0.12", features = [ "extra-traits" ] }
+proc-macro2 = "0.3"
+quote = "0.5"
+syn = { version = "0.13", features = [ "extra-traits" ] }
diff --git a/prost-derive/src/field/scalar.rs b/prost-derive/src/field/scalar.rs
index 9bc8677bd..2f4b4d3b5 100644
--- a/prost-derive/src/field/scalar.rs
+++ b/prost-derive/src/field/scalar.rs
@@ -696,7 +696,7 @@ impl DefaultValue {
             DefaultValue::String(ref value) => quote!(#value.to_owned()),
             DefaultValue::Bytes(ref value) if value.is_empty() => quote!(::std::vec::Vec::new()),
             DefaultValue::Bytes(ref value) => {
-                let lit = LitByteStr::new(value, Span::def_site());
+                let lit = LitByteStr::new(value, Span::call_site());
                 quote!(#lit.to_owned())
             },
 
@@ -724,7 +724,7 @@ impl quote::ToTokens for DefaultValue {
             DefaultValue::U64(value) => value.to_tokens(tokens),
             DefaultValue::Bool(value) => value.to_tokens(tokens),
             DefaultValue::String(ref value) => value.to_tokens(tokens),
-            DefaultValue::Bytes(ref value) => LitByteStr::new(value, Span::def_site()).to_tokens(tokens),
+            DefaultValue::Bytes(ref value) => LitByteStr::new(value, Span::call_site()).to_tokens(tokens),
             DefaultValue::Enumeration(ref value) => {
                 value.to_tokens(tokens)
             },


Test patch: