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

Implementing traits for lambdas with static lifetimes stopped working #13434

Closed
carllerche opened this issue Apr 9, 2014 · 1 comment · Fixed by #17721
Closed

Implementing traits for lambdas with static lifetimes stopped working #13434

carllerche opened this issue Apr 9, 2014 · 1 comment · Fixed by #17721
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@carllerche
Copy link
Member

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
@ghost
Copy link

ghost commented Oct 1, 2014

Works as intended now but needs a test.

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 1, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 7, 2024
New lint `needless_as_bytes`

changelog: [`needless_as_bytes`]: new lint

Fix rust-lang#13434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants