Skip to content
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

Generators are not supported by TokenStream #123191

Closed
QuentinPerez opened this issue Mar 29, 2024 · 5 comments
Closed

Generators are not supported by TokenStream #123191

QuentinPerez opened this issue Mar 29, 2024 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@QuentinPerez
Copy link

I tried this code:

#[proc_macro_attribute]
pub fn test_generatror(
    _: proc_macro::TokenStream,
    _: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    quote! {
        pub async gen fn my_gen_fn() -> u32 {
            0
        }
    }
    .into()
}

I expected to see this happen: No error

Instead, this happened: I got this error

#[test_generatror]
   | ^^^^^^^^^^^^ the visibility
   |
   = help: you likely meant to define an item, e.g., `pub fn foo() {}`
   = note: this error originates in the attribute macro `test_generatror` (in Nightly builds, run with -Z macro-backtrace for more info)

If bandwidth is limited, I'm willing to attempt integration. Could you please provide some guidance on how to proceed?

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (1388d7a06 2024-03-20)
binary: rustc
commit-hash: 1388d7a069d872bcfe5e5dd97ef61fa0a586fac0
commit-date: 2024-03-20
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2
@QuentinPerez QuentinPerez added the C-bug Category: This is a bug. label Mar 29, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 29, 2024
@Nilstrieb
Copy link
Member

That's not quite the entire error, could you post that, including a full reproduction? I don't think there is anything about proc macros that is wrong here... are you using syn?

@taiki-e
Copy link
Member

taiki-e commented Mar 29, 2024

pub async gen fn is not supported in the first place, right? The error can be reproduced without TokenStream: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9680400c367f31fd92047c1b422bee9a

@fmease
Copy link
Member

fmease commented Mar 29, 2024

You need to use Rust 2024.

@taiki-e
Copy link
Member

taiki-e commented Mar 29, 2024

Ah, I missed that. In that case, I guess the problem may be that the crate that defines macro is a pre-2024 edition since call_site span inherits its edition and the error message seems to be the same as the one that occurs when using it in older editions. (Although, I do not know what the edition actually is, as a complete reproduction is not provided.)

@QuentinPerez
Copy link
Author

You need to use Rust 2024.

You right, I forgot to add it in the proc macro lib. Thank you !

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants