Skip to content

Commit de92bf1

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 e8a624a commit de92bf1

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
@@ -547,28 +547,28 @@ When there is ambiguity if a generic argument could be resolved as either a type
547547
> ```
548548
549549
r[generics.parameters.attributes]
550-
## Attributes
550+
## Attributes on generic parameters
551551
552-
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.
553-
554-
This example shows using a custom derive attribute to modify the meaning of a generic parameter.
552+
The [built-in attributes] that have meaning on a generic parameter are [`cfg`] and [the lint check attributes].
555553
556554
> [!EXAMPLE]
557-
> <!-- ignore: requires proc macro derive -->
558-
> ```rust,ignore
559-
> // Assume that the derive for MyFlexibleClone declared `my_flexible_clone` as
560-
> // an attribute it understands.
561-
> #[derive(MyFlexibleClone)]
562-
> struct Foo<#[my_flexible_clone(unbounded)] H> {
563-
> a: *const H
564-
> }
555+
> ```rust
556+
> use std::fmt::Debug;
557+
>
558+
> struct Wrapper<
559+
> T,
560+
> #[cfg(feature = "debug")] U: Debug,
561+
> #[cfg(not(feature = "debug"))] U,
562+
> > (T, U);
565563
> ```
566564
565+
[`cfg`]: cfg.attr
567566
[array repeat expression]: expr.array
568567
[arrays]: type.array
569568
[associated const]: items.associated.const
570569
[associated type]: items.associated.type
571570
[block]: expr.block
571+
[built-in attributes]: attributes.builtin
572572
[const contexts]: const-eval.const-context
573573
[const expression]: const-eval.const-expr
574574
[const generic argument]: generics.const.argument
@@ -595,6 +595,7 @@ This example shows using a custom derive attribute to modify the meaning of a ge
595595
[references]: type.pointer.reference
596596
[slices]: type.slice
597597
[structs]: items.struct
598+
[the lint check attributes]: attributes.diagnostics.lint
598599
[trait bound]: bound
599600
[Trait bounds]: bound
600601
[trait object]: type.trait-object

0 commit comments

Comments
 (0)