Skip to content

Commit db9f925

Browse files
committed
Allow #[serde(...)] attributes without De/Serialize
1 parent 04c7056 commit db9f925

File tree

5 files changed

+10
-33
lines changed

5 files changed

+10
-33
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
<!-- ## [Unreleased] -->
8+
## [Unreleased]
9+
10+
### Changed
11+
- `#[serde(...)]` attributes are now allowed even when not deriving
12+
`De/Serialize` with `#[derive_where(...)]`.
13+
914
## [1.5.0] - 2025-06-08
1015

1116
### Added

src/attr/item.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,6 @@ impl ItemAttr {
9696
return Err(Error::none(span));
9797
}
9898

99-
// Check for `#[serde(...)]` attributes without `De/Serialize`.
100-
#[cfg(feature = "serde")]
101-
if !self_.derive_wheres.iter().any(|derive_where| {
102-
derive_where.contains(Trait::Deserialize) | derive_where.contains(Trait::Serialize)
103-
}) {
104-
for attr in attrs {
105-
if attr.path().is_ident("serde") {
106-
return Err(Error::serde_without_serde(attr.span()));
107-
}
108-
}
109-
}
110-
11199
// Merge `DeriveWhere`s with the same bounds.
112100
self_
113101
.derive_wheres

src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,6 @@ impl Error {
301301
syn::Error::new(skip_clone, "Cannot skip `Clone` while deriving `Copy`")
302302
}
303303

304-
/// Unsupported `serde(...)` without deriving `De/Serialize`.
305-
#[cfg(feature = "serde")]
306-
pub fn serde_without_serde(serde: Span) -> syn::Error {
307-
syn::Error::new(serde, "Found unused `#[serde(...)]`")
308-
}
309-
310304
/// Conflicting `serde(bound ...)` when deriving `De/Serialize`.
311305
#[cfg(feature = "serde")]
312306
pub fn serde_bound(serde: Span) -> syn::Error {

tests/ui/serde/serde.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ use std::marker::PhantomData;
22

33
use derive_where::derive_where;
44

5-
#[derive_where(Clone)]
6-
#[serde(crate = "serde_")]
7-
struct InvalidSerde<T>(PhantomData<T>);
8-
95
#[derive_where(Deserialize)]
106
#[serde(bound = "")]
117
struct ConflictingBound<T>(PhantomData<T>);

tests/ui/serde/serde.stderr

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
error: Found unused `#[serde(...)]`
2-
--> tests/ui/serde/serde.rs:6:1
3-
|
4-
6 | #[serde(crate = "serde_")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
71
error: Found conflicting `#[serde(bound ...)]`
8-
--> tests/ui/serde/serde.rs:10:9
9-
|
10-
10 | #[serde(bound = "")]
11-
| ^^^^^^^^^^
2+
--> tests/ui/serde/serde.rs:6:9
3+
|
4+
6 | #[serde(bound = "")]
5+
| ^^^^^^^^^^

0 commit comments

Comments
 (0)