Skip to content

Commit d059833

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 a236955 commit d059833

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/types/generics.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -548,26 +548,25 @@ The inferred const cannot be used in item signatures.
548548
> ```
549549
550550
r[generics.parameters.attributes]
551-
## Attributes
551+
## Attributes on generic parameters
552552
553-
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.
554-
555-
This example shows using a custom derive attribute to modify the meaning of a generic parameter.
553+
The [built-in attributes] that have meaning on a generic parameter are [`cfg`] and [the lint check attributes].
556554
557555
> [!EXAMPLE]
558-
> <!-- ignore: requires proc macro derive -->
559-
> ```rust,ignore
560-
> // Assume that the derive for MyFlexibleClone declared `my_flexible_clone` as
561-
> // an attribute it understands.
562-
> #[derive(MyFlexibleClone)]
563-
> struct Foo<#[my_flexible_clone(unbounded)] H> {
564-
> a: *const H
565-
> }
556+
> ```rust
557+
> use std::fmt::Debug;
558+
>
559+
> struct Wrapper<
560+
> T,
561+
> #[cfg(feature = "debug")] U: Debug,
562+
> #[cfg(not(feature = "debug"))] U,
563+
> > (T, U);
566564
> ```
567565
566+
[`cfg`]: cfg.attr
568567
[array repeat expression]: ../expressions/array-expr.md
569568
[arrays]: array.md
570-
[slices]: slice.md
569+
[built-in attributes]: attributes.builtin
571570
[associated const]: ../items/associated-items.md#associated-constants
572571
[associated type]: ../items/associated-items.md#associated-types
573572
[attributes]: ../attributes.md
@@ -595,7 +594,9 @@ This example shows using a custom derive attribute to modify the meaning of a ge
595594
[qualified path]: paths.qualified
596595
[raw pointers]: pointer.md#raw-pointers-const-and-mut
597596
[references]: pointer.md#shared-references-
597+
[slices]: slice.md
598598
[structs]: ../items/structs.md
599+
[the lint check attributes]: attributes.diagnostics.lint
599600
[Trait bounds]: bound
600601
[trait object]: trait-object.md
601602
[traits]: ../items/traits.md

0 commit comments

Comments
 (0)