Skip to content

Commit d6fcafe

Browse files
committed
Improve docs of traversable derivation macros
1 parent e26386f commit d6fcafe

File tree

1 file changed

+40
-9
lines changed
  • compiler/rustc_macros/src

1 file changed

+40
-9
lines changed

compiler/rustc_macros/src/lib.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,52 @@ decl_derive!(
7878
[TypeFoldable, attributes(type_foldable)] =>
7979
/// Derives `TypeFoldable` for the annotated `struct` or `enum` (`union` is not supported).
8080
///
81-
/// The fold will produce a value of the same struct or enum variant as the input, with
82-
/// each field respectively folded using the `TypeFoldable` implementation for its type.
83-
/// However, if a field of a struct or an enum variant is annotated with
84-
/// `#[type_foldable(identity)]` then that field will retain its incumbent value (and its
85-
/// type is not required to implement `TypeFoldable`).
81+
/// Folds will produce a value of the same struct or enum variant as the input, with each field
82+
/// respectively folded (in definition order) using the `TypeFoldable` implementation for its
83+
/// type. However, if a field of a struct or of an enum variant is annotated with
84+
/// `#[type_foldable(identity)]` then that field will retain its incumbent value (and its type
85+
/// is not required to implement `TypeFoldable`). However use of this attribute is dangerous
86+
/// and should be used with extreme caution: should the type of the annotated field contain
87+
/// (now or in the future) a type that is of interest to a folder, it will not get folded (which
88+
/// may result in unexpected, hard-to-track bugs that could result in unsoundness).
89+
///
90+
/// If the annotated item has a `'tcx` lifetime parameter, then that will be used as the
91+
/// lifetime for the type context/interner; otherwise the lifetime of the type context/interner
92+
/// will be unrelated to the annotated type. It therefore matters how any lifetime parameters of
93+
/// the annotated type are named. For example, deriving `TypeFoldable` for both `Foo<'a>` and
94+
/// `Bar<'tcx>` will respectively produce:
95+
///
96+
/// `impl<'a, 'tcx> TypeFoldable<TyCtxt<'tcx>> for Foo<'a>`
97+
///
98+
/// and
99+
///
100+
/// `impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Bar<'tcx>`
86101
type_foldable::type_foldable_derive
87102
);
88103
decl_derive!(
89104
[TypeVisitable, attributes(type_visitable)] =>
90105
/// Derives `TypeVisitable` for the annotated `struct` or `enum` (`union` is not supported).
91106
///
92-
/// Each field of the struct or enum variant will be visited in definition order, using the
93-
/// `TypeVisitable` implementation for its type. However, if a field of a struct or an enum
94-
/// variant is annotated with `#[type_visitable(ignore)]` then that field will not be
95-
/// visited (and its type is not required to implement `TypeVisitable`).
107+
/// Each field of the struct or enum variant will be visited (in definition order) using the
108+
/// `TypeVisitable` implementation for its type. However, if a field of a struct or of an enum
109+
/// variant is annotated with `#[type_visitable(ignore)]` then that field will not be visited
110+
/// (and its type is not required to implement `TypeVisitable`). However use of this attribute
111+
/// is dangerous and should be used with extreme caution: should the type of the annotated
112+
/// field (now or in the future) a type that is of interest to a visitor, it will not get
113+
/// visited (which may result in unexpected, hard-to-track bugs that could result in
114+
/// unsoundness).
115+
///
116+
/// If the annotated item has a `'tcx` lifetime parameter, then that will be used as the
117+
/// lifetime for the type context/interner; otherwise the lifetime of the type context/interner
118+
/// will be unrelated to the annotated type. It therefore matters how any lifetime parameters of
119+
/// the annotated type are named. For example, deriving `TypeVisitable` for both `Foo<'a>` and
120+
/// `Bar<'tcx>` will respectively produce:
121+
///
122+
/// `impl<'a, 'tcx> TypeVisitable<TyCtxt<'tcx>> for Foo<'a>`
123+
///
124+
/// and
125+
///
126+
/// `impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Bar<'tcx>`
96127
type_visitable::type_visitable_derive
97128
);
98129
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);

0 commit comments

Comments
 (0)