-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Lifetime bounds in auto trait impls prevent trait from being implemented on generators #64552
Comments
Minimized: fn needs_send<T: Send>(_val: T) {}
async fn use_async<T>(_val: T) {}
struct MyStruct<'a, T: 'a> {
val: &'a T
}
unsafe impl<'a, T: 'a> Send for MyStruct<'a, T> {}
async fn use_my_struct(val: MyStruct<'static, &'static u8>) {
use_async(val).await;
}
fn main() {
let first_struct: MyStruct<'static, &'static u8> = MyStruct { val: &&26 };
let second_struct: MyStruct<'static, &'static u8> = MyStruct { val: &&27 };
needs_send(first_struct);
needs_send(use_my_struct(second_struct)); // ERROR
} It seems as though the manual |
I think the bug occurs here: rust/src/librustc_typeck/check/generator_interior.rs Lines 124 to 144 in 9b9d2af
I believe that 'knowledge of the exact relationships between them isn't particularly important' is incorrect. If an auto trait impl imposes region constraints (as with For this particular issue, leaving In the general case, I think a full solution would require some notion of 'higher-ranked' region constraints. For example, consider the function: async fn use_my_struct<'a, 'b: 'a>(val: MyStruct<'a, &'b u8>) {
use_async(val).await;
} The returned generator should implement |
Concretely, I think we could implement this as follows:
This should only affect auto-trait resolution for generators. Users cannot implement any traits on the underlying generator type (in fact, they cannot even name it). This should ensure that these |
I haven't seen a "me too" yet so I thought I'd mention that I hit this as well, to help assess how frequent this bug is. use futures::future;
use futures::stream::{self, StreamExt};
struct Thing;
async fn genfoo(t: &[Thing]) {
let _ = stream::iter(t)
.map(future::ready)
.buffer_unordered(10)
.collect::<Vec<_>>()
.await;
}
fn foo<'a>(t: &'a [Thing]) -> impl Send + 'a {
genfoo(t)
} error: implementation of `std::iter::Iterator` is not general enough
--> src/main.rs:14:31
|
14 | fn foo<'a>(t: &'a [Thing]) -> impl Send + 'a {
| ^^^^^^^^^^^^^^ implementation of `std::iter::Iterator` is not general enough
|
= note: `std::iter::Iterator` would have to be implemented for the type `std::slice::Iter<'0, Thing>`, for any lifetime `'0`...
= note: ...but `std::iter::Iterator` is actually implemented for the type `std::slice::Iter<'1, Thing>`, for some specific lifetime `'1` |
This comment was marked as off-topic.
This comment was marked as off-topic.
- Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser
…in hosts - Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser - implements for parser Plugin hosts now awaits on the async call from the plugin instead of using `futures::executer::block_on()`. However, this change didn't improve the performance of the plugins
…in hosts - Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser - implements for parser Plugin hosts now awaits on the async call from the plugin instead of using `futures::executer::block_on()`. However, this change didn't improve the performance of the plugins
(playground)
The text was updated successfully, but these errors were encountered: