Skip to content

Implementing traits for lambdas with static lifetimes stopped working #13434

@carllerche

Description

@carllerche

After I updating to rust master, the following stopped working:

struct MyStruct;

trait Repro {
  fn repro(self, s: MyStruct) -> ~str;
}

// Work arounds:
// a) impl<'a> Repro for |MyStruct|:'a
// b) bind the closure to a local variable first, such that the type can be specified
impl Repro for |MyStruct|:'static -> ~str {
  fn repro(self, s: MyStruct) -> ~str {
    self(s)
  }
}

fn do_stuff<R: Repro>(r: R) -> ~str {
  r.repro(MyStruct)
}

pub fn main() {
  println!("{}", do_stuff(|s: MyStruct| format!("{:?}", s)));
}
$rustc repro.rs
repro.rs:18:18: 18:26 error: failed to find an implementation of trait Repro for |MyStruct| -> ~str
repro.rs:18   println!("{}", do_stuff(|s: MyStruct| format!("{:?}", s)));
                             ^~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
repro.rs:18:3: 18:62 note: expansion site

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions