Skip to content

Commit a6e34d8

Browse files
committed
Document attributes on generic parameters
This was stabilized in 1.37 (via rust-lang/rust#61547), but the documentation here was never updated. There is a longer history of these being stabilized and then `cfg` being removed and then added again, see rust-lang/rust#48848 rust-lang/rust#51279 rust-lang/rust#51283.
1 parent 3250ddf commit a6e34d8

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/types/generics/index.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -541,28 +541,28 @@ When there is ambiguity if a generic argument could be resolved as either a type
541541
> ```
542542
543543
r[generics.parameters.attributes]
544-
## Attributes
544+
## Attributes on generic parameters
545545
546-
Generic parameters allow [attributes] on them. There are no built-in attributes that do anything in this position, although custom derive attributes may give meaning to it.
547-
548-
This example shows using a custom derive attribute to modify the meaning of a generic parameter.
546+
The [built-in attributes] that have meaning on a generic parameter are [`cfg`] and [the lint check attributes].
549547
550548
> [!EXAMPLE]
551-
> <!-- ignore: requires proc macro derive -->
552-
> ```rust,ignore
553-
> // Assume that the derive for MyFlexibleClone declared `my_flexible_clone` as
554-
> // an attribute it understands.
555-
> #[derive(MyFlexibleClone)]
556-
> struct Foo<#[my_flexible_clone(unbounded)] H> {
557-
> a: *const H
558-
> }
549+
> ```rust
550+
> use std::fmt::Debug;
551+
>
552+
> struct Wrapper<
553+
> T,
554+
> #[cfg(feature = "debug")] U: Debug,
555+
> #[cfg(not(feature = "debug"))] U,
556+
> > (T, U);
559557
> ```
560558
559+
[`cfg`]: cfg.attr
561560
[array repeat expression]: expr.array
562561
[arrays]: type.array
563562
[associated const]: items.associated.const
564563
[associated type]: items.associated.type
565564
[block]: expr.block
565+
[built-in attributes]: attributes.builtin
566566
[const contexts]: const-eval.const-context
567567
[const expression]: const-eval.const-expr
568568
[const generic argument]: generics.const.argument
@@ -589,6 +589,7 @@ This example shows using a custom derive attribute to modify the meaning of a ge
589589
[references]: type.pointer.reference
590590
[slices]: type.slice
591591
[structs]: items.struct
592+
[the lint check attributes]: attributes.diagnostics.lint
592593
[trait bound]: bound
593594
[Trait bounds]: bound
594595
[trait object]: type.trait-object

0 commit comments

Comments
 (0)