proc-macro2 icon indicating copy to clipboard operation
proc-macro2 copied to clipboard

Looking for forks that make `proc_macro::Span` Send + Sync

Open infiniteregrets opened this issue 1 year ago • 1 comments

Hi there, thanks for the amazing work on this library.

I am trying to experiment with processing multiple parsed file trees with syn using rayon, however Span is not Send and I get that it cannot be and I am trying to work on a fork where it is Send. I removed the marker for it:

pub(crate) struct ProcMacroAutoTraits();

pub(crate) const MARKER: ProcMacroAutoTraits = ProcMacroAutoTraits();

and I still get the same error that Span is not safe to send over threads. Any ideas as to what I can change to make the types Send? or any available forks already out there which have done this? Would appreciate any help (:

error for context:

error[E0277]: `proc_macro::Span` cannot be sent between threads safely
   --> medschool/src/file.rs:68:10
    |
68  |         .map(|path| {
    |          ^^^ `proc_macro::Span` cannot be sent between threads safely
    |
    = help: within `Attribute`, the trait `Send` is not implemented for `proc_macro::Span`, which is required by `Result<syn::File, syn::Error>: Send`
note: required because it appears within the type `proc_macro2::extra::DelimSpanEnum`
   --> /Users/mehularora/.cargo/git/checkouts/proc-macro2-b4d7743817db7bf3/1a8ebee/src/extra.rs:88:6
    |
88  | enum DelimSpanEnum {
    |      ^^^^^^^^^^^^^
note: required because it appears within the type `proc_macro2::extra::DelimSpan`
   --> /Users/mehularora/.cargo/git/checkouts/proc-macro2-b4d7743817db7bf3/1a8ebee/src/extra.rs:82:12
    |
82  | pub struct DelimSpan {
    |            ^^^^^^^^^
note: required because it appears within the type `syn::token::Bracket`
   --> /Users/mehularora/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-2.0.61/src/token.rs:842:30
    |
842 |     Bracket       pub struct Bracket      /// `[`&hellip;`]`
    |                              ^^^^^^^
note: required because it appears within the type `Attribute`
   --> /Users/mehularora/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-2.0.61/src/attr.rs:173:16
    |
173 |     pub struct Attribute {
    |                ^^^^^^^^^
    = note: required for `Unique<Attribute>` to implement `Send`
note: required because it appears within the type `alloc::raw_vec::RawVec<Attribute>`
   --> /Users/mehularora/.rustup/toolchains/nightly-2024-04-15-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs:69:19
    |
69  | pub(crate) struct RawVec<T, A: Allocator = Global> {
    |                   ^^^^^^
note: required because it appears within the type `Vec<Attribute>`
   --> /Users/mehularora/.rustup/toolchains/nightly-2024-04-15-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:398:12
    |
398 | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
    |            ^^^
note: required because it appears within the type `syn::File`
   --> /Users/mehularora/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-2.0.61/src/file.rs:84:16
    |
84  |     pub struct File {
    |                ^^^^
note: required because it appears within the type `Result<syn::File, syn::Error>`
   --> /Users/mehularora/.rustup/toolchains/nightly-2024-04-15-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:502:10
    |
502 | pub enum Result<T, E> {
    |          ^^^^^^
note: required by a bound in `rayon::iter::ParallelIterator::map`
   --> /Users/mehularora/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rayon-1.10.0/src/iter/mod.rs:604:12
    |
601 |     fn map<F, R>(self, map_op: F) -> Map<Self, F>
    |        --- required by a bound in this associated function
...
604 |         R: Send,
    |            ^^^^ required by this bound in `ParallelIterator::map`

infiniteregrets avatar May 08 '24 04:05 infiniteregrets

proc_macro2::Span either contains a proc_macro::Span or it's own type. proc_macro::Span is not thread safe as it references thread local storage, so proc_macro2::Span can't be thread safe either without ripping the entire proc_macro support out.

bjorn3 avatar May 14 '24 09:05 bjorn3

proc_macro2::Span either contains a proc_macro::Span or it's own type. proc_macro::Span is not thread safe as it references thread local storage, so proc_macro2::Span can't be thread safe either without ripping the entire proc_macro support out.

got it, i already knew about this issue but was wondering if there is a way out. thanks for the response!

infiniteregrets avatar May 17 '24 09:05 infiniteregrets