You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/types/generics/index.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -547,28 +547,28 @@ When there is ambiguity if a generic argument could be resolved as either a type
547
547
> ```
548
548
549
549
r[generics.parameters.attributes]
550
-
## Attributes
550
+
## Attributes on generic parameters
551
551
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].
555
553
556
554
> [!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);
565
563
> ```
566
564
565
+
[`cfg`]: cfg.attr
567
566
[array repeat expression]: expr.array
568
567
[arrays]: type.array
569
568
[associated const]: items.associated.const
570
569
[associated type]: items.associated.type
571
570
[block]: expr.block
571
+
[built-in attributes]: attributes.builtin
572
572
[const contexts]: const-eval.const-context
573
573
[const expression]: const-eval.const-expr
574
574
[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
0 commit comments