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
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
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.
Comments (0)
No comments yet. Start the discussion.