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

Derive helper attributes not working on type parameters #114393

Open
Manishearth opened this issue Aug 2, 2023 · 1 comment
Open

Derive helper attributes not working on type parameters #114393

Manishearth opened this issue Aug 2, 2023 · 1 comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Manishearth
Copy link
Member

I've got the following custom derive impl:

#[proc_macro_derive(ZeroFrom, attributes(zerofrom))]
pub fn zf_derive(input: TokenStream) -> TokenStream {
    // ...
}

We already have code where #[zerofrom(clone)] works on fields just fine.

However, the following does not work:

#[derive(zerofrom::ZeroFrom)]
pub struct FormatWidthsV1<#[zerofrom(may_borrow)] SymbolsV1> {
    pub abbreviated: SymbolsV1,
    // ...
}

which throws up the following error:

error: cannot find attribute `zerofrom` in this scope
   --> components/datetime/src/provider/calendar/symbols.rs:147:29
    |
147 | pub struct FormatWidthsV1<#[zerofrom(may_borrow)] SymbolsV1> {
    |                             ^^^^^^^^
    |

It seems like the attributes only get checked on fields and the struct itself, but this is deep in resolver code that I don't understand.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2023
@Manishearth
Copy link
Member Author

cc @cjgillot @petrochenkov

@Nilstrieb Nilstrieb added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-proc-macros Area: Procedural macros and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants