{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiayikbbxbxx7o4tfvl7wqiindpw5udwnsugmcnf2jb6wfqawcpauy",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mhwwwxhvo2f2"
  },
  "path": "/t/pre-rfc-allow-attributes-to-be-applied-to-generic-arguments/24111#post_1",
  "publishedAt": "2026-03-26T03:10:43.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "(1)",
    "(2)",
    "(3)"
  ],
  "textContent": "Currently, rust allows the following.\n\n\n    struct MyStruct<#[cfg(feature)] Arg>();\n\n\nThis is useful in certain circumstances. For instance, suppose you wanted to make a crate with a custom collection. If the allocator_api was enabled, you could automatically support it in your struct.\n\n\n    struct MyCollection<#[cfg(feature = \"allocator_api\")] A: Allocator>{\n        // ..\n        alloc: A\n    }\n\n\nYou can even use it in `impl` blocks:\n\n\n    impl<#[cfg(feature)] Arg> MyStruct\n\n\nWhat you can't do, however, which makes the above nearly pointless, and what I want to change, is the following\n\n\n    impl<#[cfg(feature)] Arg> MyStruct<#[cfg(feature)] Arg>\n\n\nThis results in the error `attributes cannot be applied to generic arguments`\n\nThis has been a major headache for crate developers in the past. In many cases, the choice is between essentially duplicating all relevant code (I've seen recommendations to create duplicate modules that have identical-other-than-this code), choosing to whether to support nightly or stable, or evil macro hacks. (1) (2) (3)\n\nAs far as I know, implementing this shouldn't be too hard,as it would be quite similar to the current way the other inline attributes work. I think this would be a major ergonomics improvement for implementing collection crates.\n\n(P. S. I searched, but if I missed a prior conversation where this option was discussed and rejected, I apologize. The pr that created that error was simply consolidating that error from a generic syntax error)",
  "title": "[Pre-RFC] Allow attributes to be applied to generic arguments"
}