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

Duplicate Deserialize impls found when deriving Deserialize for a generic type #2899

Open
fjarri opened this issue Feb 23, 2025 · 0 comments

Comments

@fjarri
Copy link

fjarri commented Feb 23, 2025

MRE (playground link):

use serde::{Deserialize, Deserializer};

pub trait MyTrait: for<'x> Deserialize<'x> {}

#[derive(Debug, Clone)]
struct Inner<T: MyTrait>(core::marker::PhantomData<T>);

impl<'de, T: MyTrait> Deserialize<'de> for Inner<T>
{
    fn deserialize<D: Deserializer<'de>>(_deserializer: D) -> Result<Self, D::Error> {
        unimplemented!()
    }
}

#[derive(Debug, Clone, Deserialize)]
pub struct Outer<T: MyTrait> {
    e: Inner<T>,
}

fn main() {}

This results in (on Rust 1.85):

error[E0283]: type annotations needed: cannot satisfy `T: Deserialize<'_>`
  --> src/main.rs:16:12
   |
16 | pub struct Outer<T: MyTrait> {
   |            ^^^^^^^^^^^^^^^^^
   |
note: multiple `impl`s or `where` clauses satisfying `T: Deserialize<'_>` found
  --> src/main.rs:15:24
   |
15 | #[derive(Debug, Clone, Deserialize)]
   |                        ^^^^^^^^^^^
16 | pub struct Outer<T: MyTrait> {
   |                     ^^^^^^^
note: required for `Outer<T>` to implement `Deserialize<'de>`
  --> src/main.rs:15:24
   |
15 | #[derive(Debug, Clone, Deserialize)]
   |                        ^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
16 | pub struct Outer<T: MyTrait> {
   |            ^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

<... long error output, see the playground link>

This may be related to #2463.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant