IssueRaiser

HRTBs: "implementation is not general enough", but it is

[Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dd8b42df59f46cea2ed646339ad1d024) ```rust trait MyFn<'a> {} impl<'a, F> MyFn<'a> for F where F: FnOnce(&'a i32) -> &'a i32 {} fn foo<F>(f: F) where F: for<'a> MyFn<'a> {} // This works: // fn foo<F>(f: F) where F: for<'a> FnOnce(&'a i32) -> &'a i32 {} fn main() { foo(|x: &i32| -> &i32 { x }); } ``` produces: ``` error: implementation of `MyFn` is not general enough --> src/main.rs:10:5 | 1 | trait MyFn<'a> {} | ----------------- trait `MyFn` defined here ... 10 | foo(|x: &i32| -> &i32 { x }); | ^^^ implementation of `MyFn` is not general enough | = note: `MyFn<'1>` would have to be implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for any lifetime `'1`... = note: ...but `MyFn<'_>` is actually implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for some specific lifetime `'2` ``` But clearly it actually is implemented for any lifetime.

Posted by comex on Mar 22, 2020, 8:35 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Other)

HRTBs: "implementation is not general enough", but it is

comexMar 22, 2020, 8:35 AM

[Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dd8b42df59f46cea2ed646339ad1d024) ```rust trait MyFn<'a> {} impl<'a, F> MyFn<'a> for F where F: FnOnce(&'a i32) -> &'a i32 {} fn foo<F>(f: F) where F: for<'a> MyFn<'a> {} // This works: // fn foo<F>(f: F) where F: for<'a> FnOnce(&'a i32) -> &'a i32 {} fn main() { foo(|x: &i32| -> &i32 { x }); } ``` produces: ``` error: implementation of `MyFn` is not general enough --> src/main.rs:10:5 | 1 | trait MyFn<'a> {} | ----------------- trait `MyFn` defined here ... 10 | foo(|x: &i32| -> &i32 { x }); | ^^^ implementation of `MyFn` is not general enough | = note: `MyFn<'1>` would have to be implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for any lifetime `'1`... = note: ...but `MyFn<'_>` is actually implemented for the type `[closure@src/main.rs:10:9: 10:32]`, for some specific lifetime `'2` ``` But clearly it actually is implemented for any lifetime.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue