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

Type error when specifying types #43753

Closed
d653 opened this issue Aug 9, 2017 · 1 comment
Closed

Type error when specifying types #43753

d653 opened this issue Aug 9, 2017 · 1 comment
Labels
A-closures Area: Closures (`|…| { … }`) A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug.

Comments

@d653
Copy link

d653 commented Aug 9, 2017


fn test1<F>(_: F)
where
    F: Fn(i32, i32),
{
}

fn test2<F>(_: F)
where
    F: Fn(i32, &i32),
{
}

fn test3<F>(_: F)
where
    F: Fn(&mut i32, &i32),
{
}

fn main() {
    test1(|_, _| {});
    test2(|_, _| {});
    test3(|_, _| {});

    test1(|_: i32, _: i32| {});
    test2(|_: i32, _: &i32| {});
    test3(|_: &mut i32, _: &i32| {});


    test1(|_, _: i32| {});
    test2(|_, _: &i32| {});
    //this gives an error
    test3(|_, _: &i32| {});

}
   Compiling playground v0.0.1 (file:///playground)
error[E0281]: type mismatch: `[closure@src/main.rs:33:11: 33:26]` implements the trait `for<'r> std::ops::Fn<(&'r mut i32, &'r i32)>`, but the trait `for<'r, 'r> std::ops::Fn<(&'r mut i32, &'r i32)>` is required
  --> src/main.rs:33:5
   |
33 |     test3(|_, _: &i32| {});
   |     ^^^^^ --------------- implements `for<'r> std::ops::Fn<(&'r mut i32, &'r i32)>`
   |     |
   |     expected concrete lifetime, found bound lifetime parameter
   |     requires `for<'r, 'r> std::ops::Fn<(&'r mut i32, &'r i32)>`
   |
   = note: required by `test3`

error[E0271]: type mismatch resolving `for<'r, 'r> <[closure@src/main.rs:33:11: 33:26] as std::ops::FnOnce<(&'r mut i32, &'r i32)>>::Output == ()`
  --> src/main.rs:33:5
   |
33 |     test3(|_, _: &i32| {});
   |     ^^^^^ expected bound lifetime parameter, found concrete lifetime
   |
   = note: concrete lifetime that was found is lifetime ReSkolemized(1, BrAnon(1))
   = note: required by `test3`

error: aborting due to 2 previous errors

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Also, it could be related to #13998

@Mark-Simulacrum Mark-Simulacrum added A-closures Area: Closures (`|…| { … }`) A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. labels Aug 10, 2017
@estebank
Copy link
Contributor

This compiles successfully in both current Beta and Nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants