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

proc_macro attribue fails to expand when combined with cfg_attr #13360

Open
TheButlah opened this issue Oct 6, 2022 · 10 comments
Open

proc_macro attribue fails to expand when combined with cfg_attr #13360

TheButlah opened this issue Oct 6, 2022 · 10 comments
Labels
A-proc-macro proc macro C-bug Category: bug

Comments

@TheButlah
Copy link

TheButlah commented Oct 6, 2022

I have found that mixing certain atribute style proc macros fails when combined with cfg_attr and feature flags.
Link to minimally reproducible example

// This one works
#[safer_ffi::derive_ReprC]
#[ReprC::opaque]
pub struct NotGated {
    bar: String,
}

// This one doesn't work
#[cfg_attr(feature = "c_api", safer_ffi::derive_ReprC, ReprC::opaque)]
pub struct Gated {
    bar: String,
}

rust-analyzer version: rust-analyzer version: 0.4.1227-standalone

rustc version: rustc 1.66.0-nightly (ce7f0f1aa 2022-09-28) (please note its been broken for months, its not a recent regression)

relevant settings: "rust-analyzer.cargo.features": [ "c_api" ], and c_api is a default feature.

Original post before I got a minimal example (outdated) Unfortunately I haven't been able to make a minimal reproducible example yet, but at least by making this issue I can bring some awareness.

I have a medium sized rust codebase, which uses macros quite a bit. There is one type here that never has autocomplete.

It is using proc-macros from safer-ffi and is cfg-gated. I haven't been able to figure out the root cause of the problem. I'll try to work a bit more on finding a minimal reproduction.

@bjorn3
Copy link
Member

bjorn3 commented Oct 6, 2022

Have you told rust-analyzer to enable the c_api cargo feature? (using the rust-analyzer.cargo.features config if I recall correctly)

@TheButlah
Copy link
Author

TheButlah commented Oct 6, 2022

The feature is a default feature, so I shouldn't have to. But just to be sure, I checked my vscode workspace settings:
image

So it should work but doesn't

@bjorn3
Copy link
Member

bjorn3 commented Oct 6, 2022

I see. Default features should remain enabled under rust-analyzer unless you explicitly disable them, so that is probably not the issue. Can you show a screenshot of the line with the derive? And can you also place the cursor at derive_ReprC and invoke the rust analyzer: expand macro command to check if macro expansion worked or not.

@TheButlah

This comment was marked as outdated.

@TheButlah

This comment was marked as outdated.

@TheButlah

This comment was marked as outdated.

TheButlah added a commit to TheButlah/bugs that referenced this issue Oct 6, 2022
@TheButlah
Copy link
Author

TheButlah commented Oct 6, 2022

OK, I've created a minimally reproducible example, turns out it was easier than expected to minify. I've updated the original post.

@TheButlah TheButlah changed the title proc_macro has been broken for a long time proc_macro attribue fails to expand when combined with cfg_attr Oct 6, 2022
@Veykril
Copy link
Member

Veykril commented Oct 6, 2022

I believe the issue here is our expansion of the cfg_attr, we are most likely stripping the cfg_attr alltogether when transforming the struct to the token tree representation, so the macro doesn't get to see the ReprC::opaque.

@Dominator008
Copy link

Any fix / workaround for this? This makes vscode almost useless for a project I'm working on.

@mbuerki
Copy link

mbuerki commented Sep 11, 2023

also still experiencing this problem. is some kind of fix already available? or in the making?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

5 participants