Skip to content

Derive helper attributes not working on type parameters  #114393

@Manishearth

Description

@Manishearth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions