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

Mismatched signature in trait implementation with lifetimes not caught #27083

Closed
Ms2ger opened this Issue Jul 17, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 17, 2015

I think this shouldn't compile, but it does (in rustc 1.3.0-dev (fddfd08 2015-07-10)):

struct Foo;

trait Bar {
    fn get_style<'a>(&'a self, r: &'a Foo) -> &'a Foo;
}

impl Bar for Foo {
    fn get_style<'a>(&self, r: &'a Foo) -> &'a Foo {
        r
    }
}

fn main() {}
@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 17, 2015

@Ms2ger

Could you extend it into a real unsoundness? I don't think this is a real problem: the trait type is for<'a> fn(&'a Foo, &'a Foo) -> &'a Foo, which is a subtype of the impl type for<'a,'s> fn(&'s Foo, &'a Foo) -> &'a Foo - it requires both of the argument lifetimes to be the same as the output lifetime, not just the second argument's lifetime, and we allow impl-types to be subtypes of the trait-type (e.g. you can even replace the return type with &'static Foo - of course only if you also adjust get_style's body - and it would still work).

@Ms2ger

This comment has been minimized.

Copy link
Contributor Author

Ms2ger commented Jul 17, 2015

I'm not sure anything's unsound here; I found this pattern in Servo and was surprised that it built at all, given the different signatures.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 18, 2015

I'll close this then.

@arielb1 arielb1 closed this Jul 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.