-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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` |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
…922) The proxy currently has its own implementation of a `tower` `Service` that makes an inner service `Clone`able by driving it in a spawned task and buffering requests on a channel. This also exists upstream, as `tower::buffer`. We implemented our own version for a couple of reasons: to avoid an upstream issue where memory was leaked when a buffered request was cancelled, and to implement an idle timeout when the buffered service has been unready for too long. However, it's no longer necessary to reimplement our own buffer service for these reasons: the upstream bug was fixed in `tower` 0.4 (see tower-rs/tower#476, tower-rs/tower#480, and tower-rs/tower#556); and we no longer actually use the buffer idle timeout (instead, we idle out unresponsive services with the separate `Failfast` middleware, note that `push_spawn_buffer_with_idle_timeout` is never actually used). Therefore, we can remove our _sui generis_ implementation in favour of `tower::buffer` from upstream. This eliminates dead code for the idle timeout, which we never actually use, and reduces duplication (since `tonic` uses `tower::buffer` internally, its code is already compiled into the proxy). It also reduces the amount of code I'm personally responsible for maintaining in two separate places ;) Since the `linkerd-buffer` crate erases the type of the buffered service, while `tower::buffer` does not, I've changed the `push_spawn_buffer`/`spawn_buffer` helpers to also include a `BoxService` layer. This required adding a `BoxServiceLayer` type, since `BoxService::layer` returns a `LayerFn` with an unnameable type. Also, this change ran into issues due to a compiler bug where generators (async blocks) sometimes forget concrete lifetimes, rust-lang/rust#64552. In order to resolve this, I had to remove the outermost `async` blocks from the OpenCensus and identity daemon tasks. These async blocks were used only for emitting a tracing event when the task is started, so it wasn't a big deal to remove them; I moved the trace events into the actual daemon task functions, and used a `tracing` span to propagate the remote addresses which aren't known inside the daemon task functions. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
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: