@@ -79,35 +79,38 @@ slice_encode_impl!(
79
79
27 , 28 , 29 , 30 , 31 , 32
80
80
) ;
81
81
82
- /*
83
- External crates cannot implement Encode for pointers or Optionals, but they
84
- *can* implement it for references. rust-lang/rust#25126
85
-
86
- As a workaround, we provide implementations for these types that return the
87
- same encoding as references.
88
- */
89
- unsafe impl < T > Encode for * const T
82
+ // External crates cannot implement Encode for pointers or [`Option`], but
83
+ // they *can* implement it for references. See
84
+ // [rust-lang/rust#25126](https://github.com/rust-lang/rust/issues/25126)
85
+ //
86
+ // So, as a workaround, we provide implementations for these types that return
87
+ // the same encoding as references.
88
+ //
89
+ // Using `?Sized` is safe here because we delegate to other implementations
90
+ // (which will verify that the implementation is safe for the unsized type).
91
+
92
+ unsafe impl < T : ?Sized > Encode for * const T
90
93
where
91
94
for < ' b > & ' b T : Encode ,
92
95
{
93
96
const ENCODING : Encoding < ' static > = <& T >:: ENCODING ;
94
97
}
95
98
96
- unsafe impl < T > Encode for * mut T
99
+ unsafe impl < T : ? Sized > Encode for * mut T
97
100
where
98
101
for < ' b > & ' b mut T : Encode ,
99
102
{
100
103
const ENCODING : Encoding < ' static > = <& mut T >:: ENCODING ;
101
104
}
102
105
103
- unsafe impl < ' a , T > Encode for Option < & ' a T >
106
+ unsafe impl < ' a , T : ? Sized > Encode for Option < & ' a T >
104
107
where
105
108
for < ' b > & ' b T : Encode ,
106
109
{
107
110
const ENCODING : Encoding < ' static > = <& T >:: ENCODING ;
108
111
}
109
112
110
- unsafe impl < ' a , T > Encode for Option < & ' a mut T >
113
+ unsafe impl < ' a , T : ? Sized > Encode for Option < & ' a mut T >
111
114
where
112
115
for < ' b > & ' b mut T : Encode ,
113
116
{
0 commit comments