Skip to content

rustc cannot see impls for other lifetimes in presence of specific where clause #38308

@djzin

Description

@djzin

The following code fails to compile:

trait Foo {
    fn foo(&self) {}
}

fn fail<'a>() where &'a (): Foo {
    (&()).foo()
}

impl<'a> Foo for &'a () {}

fn main() {}

The temporary &() is deduced to have type &'a () because of the where clause. If this where clause is removed, the code compiles. For some reason the compiler cannot see that &() still implements Foo for other lifetimes because of this where clause.

n.b. this came from reducing this reddit post
https://www.reddit.com/r/rust/comments/5hm2b6/my_lifetime_snafu/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions