Skip to content

Commit 9247286

Browse files
committed
Remove implicit Sized bound from PhantomData's impls
Since PhantomData doesn't contain any data it doesn't matter if T is Sized or not. There's an implicit Sized bound here that we have to override to remove it. This tweaks the (public) `impl_borrow_decode!(...)` and `impl_borrow_decode_with_context!(...)` macros to support type bounds, not just comma-separated token trees. I think this change should be backwards-compatible.
1 parent 7195538 commit 9247286

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/de/impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,12 @@ impl<Context> Decode<Context> for () {
540540
}
541541
impl_borrow_decode!(());
542542

543-
impl<Context, T> Decode<Context> for core::marker::PhantomData<T> {
543+
impl<Context, T: ?Sized> Decode<Context> for core::marker::PhantomData<T> {
544544
fn decode<D: Decoder<Context = Context>>(_: &mut D) -> Result<Self, DecodeError> {
545545
Ok(core::marker::PhantomData)
546546
}
547547
}
548-
impl_borrow_decode!(core::marker::PhantomData<T>, T);
548+
impl_borrow_decode!(core::marker::PhantomData<T>, T: ?Sized);
549549

550550
impl<Context, T> Decode<Context> for Option<T>
551551
where

src/de/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pub trait BorrowDecode<'de, Context>: Sized {
120120
/// Helper macro to implement `BorrowDecode` for any type that implements `Decode`.
121121
#[macro_export]
122122
macro_rules! impl_borrow_decode {
123-
($ty:ty $(, $param:tt)*) => {
124-
impl<'de $(, $param)*, __Context> $crate::BorrowDecode<'de, __Context> for $ty {
123+
($ty:ty $(, $($params:tt)*)?) => {
124+
impl<'de $(, $($params)*)?, __Context> $crate::BorrowDecode<'de, __Context> for $ty {
125125
fn borrow_decode<D: $crate::de::BorrowDecoder<'de, Context = __Context>>(
126126
decoder: &mut D,
127127
) -> core::result::Result<Self, $crate::error::DecodeError> {
@@ -134,8 +134,8 @@ macro_rules! impl_borrow_decode {
134134
/// Helper macro to implement `BorrowDecode` for any type that implements `Decode`.
135135
#[macro_export]
136136
macro_rules! impl_borrow_decode_with_context {
137-
($ty:ty, $context:ty $(, $param:tt)*) => {
138-
impl<'de $(, $param)*> $crate::BorrowDecode<'de, $context> for $ty {
137+
($ty:ty, $context:ty $(, $($params:tt)*)?) => {
138+
impl<'de $(, $($params)*)?> $crate::BorrowDecode<'de, $context> for $ty {
139139
fn borrow_decode<D: $crate::de::BorrowDecoder<'de, Context = $context>>(
140140
decoder: &mut D,
141141
) -> core::result::Result<Self, $crate::error::DecodeError> {

src/enc/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Encode for () {
2121
}
2222
}
2323

24-
impl<T> Encode for PhantomData<T> {
24+
impl<T: ?Sized> Encode for PhantomData<T> {
2525
fn encode<E: Encoder>(&self, _: &mut E) -> Result<(), EncodeError> {
2626
Ok(())
2727
}

0 commit comments

Comments
 (0)