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
@@ -541,28 +541,28 @@ When there is ambiguity if a generic argument could be resolved as either a type
541
541
> ```
542
542
543
543
r[generics.parameters.attributes]
544
-
## Attributes
544
+
## Attributes on generic parameters
545
545
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].
549
547
550
548
> [!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);
559
557
> ```
560
558
559
+
[`cfg`]: cfg.attr
561
560
[array repeat expression]: expr.array
562
561
[arrays]: type.array
563
562
[associated const]: items.associated.const
564
563
[associated type]: items.associated.type
565
564
[block]: expr.block
565
+
[built-in attributes]: attributes.builtin
566
566
[const contexts]: const-eval.const-context
567
567
[const expression]: const-eval.const-expr
568
568
[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
0 commit comments