[Pre-RFC] Allow attributes to be applied to generic arguments
Rust Internals [Unofficial]
March 27, 2026
eebop:
If the allocator_api was enabled, you could automatically support it in your struct.
struct MyCollection<#[cfg(feature = "allocator_api")] A: Allocator>{ // .. alloc: A }
This is, I think, a bad motivating example because that's a non-additive feature when you're changing the generics.
(Compare private fields where adding or removing the field doesn't break the caller.)
Might as well just leave the type there all the time, and either ignore it or only support one particular type if the feature is off.
Discussion in the ATmosphere