File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -551,6 +551,22 @@ fn derive_try_from_bytes_enum(
551551/// Attempts to generate a `TryFromBytes::is_bit_valid` instance that
552552/// unconditionally returns true.
553553///
554+ /// This is possible when the `top_level` trait is `FromBytes` and there are no
555+ /// generic type parameters. In this case, we know that compilation will succeed
556+ /// only if the type is unconditionally `FromBytes`. Type parameters are not
557+ /// supported because a type with type parameters could be `TryFromBytes` but
558+ /// not `FromBytes` depending on its type parameters, and so deriving a trivial
559+ /// `is_bit_valid` would be either unsound or, assuming we add a defensive
560+ /// `Self: FromBytes` bound (as we currently do), overly restrictive. Consider,
561+ /// for example, that `Foo<bool>` ought to be `TryFromBytes` but not `FromBytes`
562+ /// in this example:
563+ ///
564+ /// ```rust,ignore
565+ /// #[derive(FromBytes)]
566+ /// #[repr(transparent)]
567+ /// struct Foo<T>(T);
568+ /// ```
569+ ///
554570/// This should be used where possible. Using this impl is faster to codegen,
555571/// faster to compile, and is friendlier on the optimizer.
556572fn try_gen_trivial_is_bit_valid (
You can’t perform that action at this time.
0 commit comments