Open nandesu-utils opened 1 year ago
If we put explicit lifetimes, the diagnostic will become clearer:
pub trait FooExt: Foo {
fn run_via<'a, 'b: 'a, T: Sync>(&'a self, t: &'b T) -> impl Future<Output = ()> + 'a + Send {
async move {
self.run::<'a, 'b, T>(t).await;
}
}
}
With diagnostic:
error: lifetime bound not satisfied
--> src/lib.rs:10:9
|
10 | / async move {
11 | | self.run::<'a, 'b, T>(t).await;
12 | | }
| |_________^
|
note: the lifetime `'a` defined here...
--> src/lib.rs:9:16
|
9 | fn run_via<'a, 'b: 'a, T: Sync>(&'a self, t: &'b T) -> impl Future<Output = ()> + 'a + Send {
| ^^
note: ...must outlive the lifetime `'a` defined here
--> src/lib.rs:9:16
|
9 | fn run_via<'a, 'b: 'a, T: Sync>(&'a self, t: &'b T) -> impl Future<Output = ()> + 'a + Send {
| ^^
= note: this is a known limitation that will be removed in the future ([see issue #100013 <https://github.com/rust-lang/rust/issues/100013>](https://github.com/rust-lang/rust/issues/100013) for more information)
@rustbot label +A-borrow-checker +F-return_position_impl_trait_in_trait
If it helps in debugging, this might be another example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bdfcc8a7ba16afef1ba7c86636a23fce
Deleting the Send
bound on async_method
makes it compile
I tried this code:
I expected to see this happen: successful compilation
Instead, this happened: an outlives lifetime error with very bad diagnostics
Then I tried this code:
And the code compiled! Seems like
Send
bound on the return impl trait type inrun
function breaks borrow checker in some way, or possibly breaks inner definition of the anonymous impl type since the following code with a trait object works.-Ztrait-solver=next
and poloniusFirst code snippet leads to an ICE when using
-Ztrait-solver=next
, I am not sure whether it's worth filing an ICE report right now because this is a bug in the default solver. As for polonius, it doesn't change anything.Meta
rustc --version --verbose
: