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

derive(Serialize) regression with lifetimes #443

Closed
arcnmx opened this issue Jul 15, 2016 · 2 comments · Fixed by #456
Closed

derive(Serialize) regression with lifetimes #443

arcnmx opened this issue Jul 15, 2016 · 2 comments · Fixed by #456
Assignees
Milestone

Comments

@arcnmx
Copy link

arcnmx commented Jul 15, 2016

This used to work around version 0.7.10 of serde_codegen...

#[derive(Serialize)]
struct S<'a> {
    a: Option<&'static str>,
    b: Option<&'a str>,
}
error: mismatched types [E0308]
#[derive(Serialize)]
help: run `rustc --explain E0308` to see a detailed explanation
note: expected type `serde::Serialize`
note:    found type `serde::Serialize`
note: the lifetime 'a as defined on the impl at 31:9...
#[derive(Serialize)]
note: ...does not necessarily outlive the static lifetime
@dtolnay dtolnay self-assigned this Jul 15, 2016
@dtolnay
Copy link
Member

dtolnay commented Jul 15, 2016

I started looking into this. We generate code like the following:

impl<'a> Serialize for S<'a>
    where Option<&'static str>: Serialize,
          Option<&'a str>: Serialize,
{
    fn serialize<SER>(&self, _ser: &mut SER) -> Result<(), SER::Error>
        where SER: Serializer,
    {
        unimplemented!()
    }
}

The error message is coming from Option<&'static str>: Serialize. I need to figure out why, because that seems like a reasonable bound.

@dtolnay
Copy link
Member

dtolnay commented Jul 15, 2016

The option impl looks like this:

impl<T> Serialize for Option<T> where T: Serialize { /* ... */ }

The ref impl looks like this:

impl<'a, T: ?Sized> Serialize for &'a T where T: Serialize { /* ... */ }

And the str impl looks like this:

impl Serialize for str { /* ... */ }

So it seems like Option<&'static str>: Serialize should be fine. Possibly a compiler issue? I will continue debugging after work.

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

Successfully merging a pull request may close this issue.

2 participants