Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems around unexpected_cfgs #744

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ unused_import_braces = "warn"
variant_size_differences = "warn"
# Unsafe code is needed for array initialization using MaybeUninit.
# unsafe_code = "forbid"
# FIXME: For tarpaulin some code is excluded, since tarpaulin does not detect the line coverage well
# Statements like: #![cfg(not(tarpaulin_include))]
# but the lint doesn't like them and it is probably better to not have a build.rs just for that.
unexpected_cfgs = "allow"

[workspace.lints.clippy]
# These lints have false positives and are disabled until they are fixed.
Expand Down
12 changes: 6 additions & 6 deletions serde_with/src/guide/serde_as.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Our goal is to serialize this `Data` struct.
Currently, we do not have anything we can use to replace `???` with, since `_` only works if `RemoteType` would implement `Serialize`, which it does not.

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
#[serde_as]
#[derive(serde::Serialize)]
struct Data {
Expand All @@ -159,7 +159,7 @@ The `SerializeAs` implementation is **always** written for a local type.
This allows it to seamlessly work with types from dependencies without running into orphan rule problems.

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
struct LocalType;

impl SerializeAs<RemoteType> for LocalType {
Expand Down Expand Up @@ -188,7 +188,7 @@ As can be seen, this is mostly boilerplate, since the most part is encapsulated
The final `Data` struct will now look like:

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
#[serde_as]
#[derive(serde::Serialize)]
struct Data {
Expand All @@ -205,7 +205,7 @@ This is a special functionality of serde, where it derives the de/serialization
You can find all the details in the [official serde documentation](https://serde.rs/remote-derive.html).

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
// Pretend that this is somebody else's crate, not a module.
mod other_crate {
// Neither Serde nor the other crate provides Serialize and Deserialize
Expand Down Expand Up @@ -238,7 +238,7 @@ We can write this implementation.
The implementation for `DeserializeAs` works analogue.

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
impl SerializeAs<Duration> for DurationDef {
fn serialize_as<S>(value: &Duration, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -253,7 +253,7 @@ impl SerializeAs<Duration> for DurationDef {
This now allows us to use `Duration` for serialization.

```rust
# #[cfg(FALSE)] {
# #[cfg(any())] {
use other_crate::Duration;

#[serde_as]
Expand Down
8 changes: 4 additions & 4 deletions serde_with/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ pub struct PickFirst<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// struct S {
/// #[serde_as(as = "FromInto<T>")]
/// value: O,
Expand Down Expand Up @@ -1849,7 +1849,7 @@ pub struct FromInto<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// struct S {
/// #[serde_as(as = "FromIntoRef<T>")]
/// value: O,
Expand Down Expand Up @@ -1930,7 +1930,7 @@ pub struct FromIntoRef<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// struct S {
/// #[serde_as(as = "TryFromInto<T>")]
/// value: O,
Expand Down Expand Up @@ -2019,7 +2019,7 @@ pub struct TryFromInto<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// struct S {
/// #[serde_as(as = "TryFromIntoRef<T>")]
/// value: O,
Expand Down
10 changes: 5 additions & 5 deletions serde_with/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::prelude::*;
/// This cannot work, since there is no way to tell the `Vec` to skip the inner `DoubleOption` if it is `None`.
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// # struct Foobar {
/// #[serde_as(as = "Vec<DoubleOption<_>>")]
/// data: Vec<Option<Option<i32>>>,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub mod unwrap_or_skip {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -300,7 +300,7 @@ pub mod sets_duplicate_value_is_error {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -420,7 +420,7 @@ pub mod maps_duplicate_key_is_error {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -508,7 +508,7 @@ pub mod sets_last_value_wins {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(FALSE)] {
/// # #[cfg(any())] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down
Loading