Skip to content

Commit 9dacfbb

Browse files
committed
Fill in more doc(cfg) attributes
1 parent 05c2509 commit 9dacfbb

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

serde/src/de/impls.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<'de> Deserialize<'de> for () {
3939
}
4040

4141
#[cfg(feature = "unstable")]
42+
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
4243
impl<'de> Deserialize<'de> for ! {
4344
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
4445
where
@@ -596,6 +597,7 @@ impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
596597
}
597598

598599
#[cfg(any(feature = "std", feature = "alloc"))]
600+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
599601
impl<'de> Deserialize<'de> for String {
600602
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
601603
where
@@ -739,6 +741,7 @@ impl<'de> Visitor<'de> for CStringVisitor {
739741
}
740742

741743
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
744+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
742745
impl<'de> Deserialize<'de> for CString {
743746
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
744747
where
@@ -767,6 +770,7 @@ macro_rules! forwarded_impl {
767770

768771
forwarded_impl! {
769772
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
773+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
770774
(), Box<CStr>, CString::into_boxed_c_str
771775
}
772776

@@ -978,6 +982,7 @@ fn nop_reserve<T>(_seq: T, _n: usize) {}
978982

979983
seq_impl!(
980984
#[cfg(any(feature = "std", feature = "alloc"))]
985+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
981986
BinaryHeap<T: Ord>,
982987
seq,
983988
BinaryHeap::clear,
@@ -988,6 +993,7 @@ seq_impl!(
988993

989994
seq_impl!(
990995
#[cfg(any(feature = "std", feature = "alloc"))]
996+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
991997
BTreeSet<T: Eq + Ord>,
992998
seq,
993999
BTreeSet::clear,
@@ -998,6 +1004,7 @@ seq_impl!(
9981004

9991005
seq_impl!(
10001006
#[cfg(any(feature = "std", feature = "alloc"))]
1007+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
10011008
LinkedList<T>,
10021009
seq,
10031010
LinkedList::clear,
@@ -1008,6 +1015,7 @@ seq_impl!(
10081015

10091016
seq_impl!(
10101017
#[cfg(feature = "std")]
1018+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
10111019
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
10121020
seq,
10131021
HashSet::clear,
@@ -1018,6 +1026,7 @@ seq_impl!(
10181026

10191027
seq_impl!(
10201028
#[cfg(any(feature = "std", feature = "alloc"))]
1029+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
10211030
VecDeque<T>,
10221031
seq,
10231032
VecDeque::clear,
@@ -1029,6 +1038,7 @@ seq_impl!(
10291038
////////////////////////////////////////////////////////////////////////////////
10301039

10311040
#[cfg(any(feature = "std", feature = "alloc"))]
1041+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
10321042
impl<'de, T> Deserialize<'de> for Vec<T>
10331043
where
10341044
T: Deserialize<'de>,
@@ -1432,13 +1442,15 @@ macro_rules! map_impl {
14321442

14331443
map_impl! {
14341444
#[cfg(any(feature = "std", feature = "alloc"))]
1445+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
14351446
BTreeMap<K: Ord, V>,
14361447
map,
14371448
BTreeMap::new(),
14381449
}
14391450

14401451
map_impl! {
14411452
#[cfg(feature = "std")]
1453+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
14421454
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
14431455
map,
14441456
HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default()),
@@ -1580,6 +1592,7 @@ macro_rules! deserialize_enum {
15801592
}
15811593

15821594
#[cfg(feature = "std")]
1595+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
15831596
impl<'de> Deserialize<'de> for net::IpAddr {
15841597
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
15851598
where
@@ -1600,11 +1613,13 @@ impl<'de> Deserialize<'de> for net::IpAddr {
16001613

16011614
parse_ip_impl! {
16021615
#[cfg(feature = "std")]
1616+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16031617
net::Ipv4Addr, "IPv4 address", 4
16041618
}
16051619

16061620
parse_ip_impl! {
16071621
#[cfg(feature = "std")]
1622+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16081623
net::Ipv6Addr, "IPv6 address", 16
16091624
}
16101625

@@ -1631,6 +1646,7 @@ macro_rules! parse_socket_impl {
16311646
}
16321647

16331648
#[cfg(feature = "std")]
1649+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16341650
impl<'de> Deserialize<'de> for net::SocketAddr {
16351651
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
16361652
where
@@ -1651,12 +1667,14 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
16511667

16521668
parse_socket_impl! {
16531669
#[cfg(feature = "std")]
1670+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16541671
net::SocketAddrV4, "IPv4 socket address",
16551672
|(ip, port)| net::SocketAddrV4::new(ip, port),
16561673
}
16571674

16581675
parse_socket_impl! {
16591676
#[cfg(feature = "std")]
1677+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16601678
net::SocketAddrV6, "IPv6 socket address",
16611679
|(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0),
16621680
}
@@ -1692,6 +1710,7 @@ impl<'a> Visitor<'a> for PathVisitor {
16921710
}
16931711

16941712
#[cfg(feature = "std")]
1713+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
16951714
impl<'de: 'a, 'a> Deserialize<'de> for &'a Path {
16961715
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
16971716
where
@@ -1746,6 +1765,7 @@ impl<'de> Visitor<'de> for PathBufVisitor {
17461765
}
17471766

17481767
#[cfg(feature = "std")]
1768+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
17491769
impl<'de> Deserialize<'de> for PathBuf {
17501770
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
17511771
where
@@ -1757,6 +1777,7 @@ impl<'de> Deserialize<'de> for PathBuf {
17571777

17581778
forwarded_impl! {
17591779
#[cfg(feature = "std")]
1780+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
17601781
(), Box<Path>, PathBuf::into_boxed_path
17611782
}
17621783

@@ -1818,6 +1839,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
18181839
}
18191840

18201841
#[cfg(all(feature = "std", any(unix, windows)))]
1842+
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
18211843
impl<'de> Deserialize<'de> for OsString {
18221844
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
18231845
where
@@ -1831,25 +1853,30 @@ impl<'de> Deserialize<'de> for OsString {
18311853

18321854
forwarded_impl! {
18331855
#[cfg(any(feature = "std", feature = "alloc"))]
1856+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
18341857
(T), Box<T>, Box::new
18351858
}
18361859

18371860
forwarded_impl! {
18381861
#[cfg(any(feature = "std", feature = "alloc"))]
1862+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
18391863
(T), Box<[T]>, Vec::into_boxed_slice
18401864
}
18411865

18421866
forwarded_impl! {
18431867
#[cfg(any(feature = "std", feature = "alloc"))]
1868+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
18441869
(), Box<str>, String::into_boxed_str
18451870
}
18461871

18471872
forwarded_impl! {
18481873
#[cfg(all(feature = "std", any(unix, windows)))]
1874+
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
18491875
(), Box<OsStr>, OsString::into_boxed_os_str
18501876
}
18511877

18521878
#[cfg(any(feature = "std", feature = "alloc"))]
1879+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
18531880
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
18541881
where
18551882
T: ToOwned,
@@ -1871,6 +1898,10 @@ where
18711898
///
18721899
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
18731900
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
1901+
#[cfg_attr(
1902+
doc_cfg,
1903+
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
1904+
)]
18741905
impl<'de, T: ?Sized> Deserialize<'de> for RcWeak<T>
18751906
where
18761907
T: Deserialize<'de>,
@@ -1889,6 +1920,10 @@ where
18891920
///
18901921
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
18911922
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
1923+
#[cfg_attr(
1924+
doc_cfg,
1925+
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
1926+
)]
18921927
impl<'de, T: ?Sized> Deserialize<'de> for ArcWeak<T>
18931928
where
18941929
T: Deserialize<'de>,
@@ -1933,6 +1968,7 @@ box_forwarded_impl! {
19331968
///
19341969
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
19351970
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
1971+
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
19361972
Rc
19371973
}
19381974

@@ -1945,6 +1981,7 @@ box_forwarded_impl! {
19451981
///
19461982
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
19471983
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
1984+
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
19481985
Arc
19491986
}
19501987

@@ -1968,11 +2005,13 @@ forwarded_impl! {
19682005

19692006
forwarded_impl! {
19702007
#[cfg(feature = "std")]
2008+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
19712009
(T), Mutex<T>, Mutex::new
19722010
}
19732011

19742012
forwarded_impl! {
19752013
#[cfg(feature = "std")]
2014+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
19762015
(T), RwLock<T>, RwLock::new
19772016
}
19782017

@@ -2127,6 +2166,7 @@ impl<'de> Deserialize<'de> for Duration {
21272166
////////////////////////////////////////////////////////////////////////////////
21282167

21292168
#[cfg(feature = "std")]
2169+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
21302170
impl<'de> Deserialize<'de> for SystemTime {
21312171
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
21322172
where
@@ -2962,6 +3002,7 @@ macro_rules! atomic_impl {
29623002
($($ty:ident $size:expr)*) => {
29633003
$(
29643004
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
3005+
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
29653006
impl<'de> Deserialize<'de> for $ty {
29663007
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
29673008
where

serde/src/de/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ pub trait Visitor<'de>: Sized {
15251525
/// `String`.
15261526
#[inline]
15271527
#[cfg(any(feature = "std", feature = "alloc"))]
1528+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
15281529
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
15291530
where
15301531
E: Error,
@@ -1583,6 +1584,7 @@ pub trait Visitor<'de>: Sized {
15831584
/// The default implementation forwards to `visit_bytes` and then drops the
15841585
/// `Vec<u8>`.
15851586
#[cfg(any(feature = "std", feature = "alloc"))]
1587+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
15861588
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
15871589
where
15881590
E: Error,

serde/src/de/value.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl Debug for Error {
112112
}
113113

114114
#[cfg(feature = "std")]
115+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
115116
impl error::Error for Error {
116117
fn description(&self) -> &str {
117118
&self.err
@@ -184,12 +185,14 @@ impl<E> Debug for UnitDeserializer<E> {
184185

185186
/// A deserializer that cannot be instantiated.
186187
#[cfg(feature = "unstable")]
188+
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
187189
pub struct NeverDeserializer<E> {
188190
never: !,
189191
marker: PhantomData<E>,
190192
}
191193

192194
#[cfg(feature = "unstable")]
195+
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
193196
impl<'de, E> IntoDeserializer<'de, E> for !
194197
where
195198
E: de::Error,
@@ -562,6 +565,7 @@ impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
562565

563566
/// A deserializer holding a `String`.
564567
#[cfg(any(feature = "std", feature = "alloc"))]
568+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
565569
pub struct StringDeserializer<E> {
566570
value: String,
567571
marker: PhantomData<E>,
@@ -578,6 +582,7 @@ impl<E> Clone for StringDeserializer<E> {
578582
}
579583

580584
#[cfg(any(feature = "std", feature = "alloc"))]
585+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
581586
impl<'de, E> IntoDeserializer<'de, E> for String
582587
where
583588
E: de::Error,
@@ -665,6 +670,7 @@ impl<E> Debug for StringDeserializer<E> {
665670

666671
/// A deserializer holding a `Cow<str>`.
667672
#[cfg(any(feature = "std", feature = "alloc"))]
673+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
668674
pub struct CowStrDeserializer<'a, E> {
669675
value: Cow<'a, str>,
670676
marker: PhantomData<E>,
@@ -681,6 +687,7 @@ impl<'a, E> Clone for CowStrDeserializer<'a, E> {
681687
}
682688

683689
#[cfg(any(feature = "std", feature = "alloc"))]
690+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
684691
impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
685692
where
686693
E: de::Error,
@@ -999,6 +1006,7 @@ where
9991006
////////////////////////////////////////////////////////////////////////////////
10001007

10011008
#[cfg(any(feature = "std", feature = "alloc"))]
1009+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
10021010
impl<'de, T, E> IntoDeserializer<'de, E> for Vec<T>
10031011
where
10041012
T: IntoDeserializer<'de, E>,
@@ -1012,6 +1020,7 @@ where
10121020
}
10131021

10141022
#[cfg(any(feature = "std", feature = "alloc"))]
1023+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
10151024
impl<'de, T, E> IntoDeserializer<'de, E> for BTreeSet<T>
10161025
where
10171026
T: IntoDeserializer<'de, E> + Eq + Ord,
@@ -1025,6 +1034,7 @@ where
10251034
}
10261035

10271036
#[cfg(feature = "std")]
1037+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
10281038
impl<'de, T, S, E> IntoDeserializer<'de, E> for HashSet<T, S>
10291039
where
10301040
T: IntoDeserializer<'de, E> + Eq + Hash,
@@ -1411,6 +1421,7 @@ impl Expected for ExpectedInMap {
14111421
////////////////////////////////////////////////////////////////////////////////
14121422

14131423
#[cfg(any(feature = "std", feature = "alloc"))]
1424+
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
14141425
impl<'de, K, V, E> IntoDeserializer<'de, E> for BTreeMap<K, V>
14151426
where
14161427
K: IntoDeserializer<'de, E> + Eq + Ord,
@@ -1425,6 +1436,7 @@ where
14251436
}
14261437

14271438
#[cfg(feature = "std")]
1439+
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
14281440
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>
14291441
where
14301442
K: IntoDeserializer<'de, E> + Eq + Hash,

0 commit comments

Comments
 (0)