Rollup merge of #87322 - chazkiker2:fix/suggestion-ref-sync-send, r=estebank
fix: clarify suggestion that `&T` must refer to `T: Sync` for `&T: Send` ### Description - [x] fix #86507 - [x] add UI test for relevant code from issue - [x] change `rustc_trait_selection/src/traits/error_reporting/suggestions.rs` to include a more clear suggestion when `&T` fails to satisfy `Send` bounds due to the fact that `T` fails to implement `Sync` - [x] update UI test in Clippy: `src/tools/tests/ui/future_not_send.stderr`
This commit is contained in:
commit
3fc79fde63
4 changed files with 80 additions and 7 deletions
25
src/test/ui/async-await/issue-86507.rs
Normal file
25
src/test/ui/async-await/issue-86507.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// edition:2018
|
||||
|
||||
use ::core::pin::Pin;
|
||||
use ::core::future::Future;
|
||||
use ::core::marker::Send;
|
||||
|
||||
trait Foo {
|
||||
fn bar<'me, 'async_trait, T: Send>(x: &'me T)
|
||||
-> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
|
||||
where 'me: 'async_trait;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
fn bar<'me, 'async_trait, T: Send>(x: &'me T)
|
||||
-> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
|
||||
where 'me:'async_trait {
|
||||
Box::pin( //~ ERROR future cannot be sent between threads safely
|
||||
async move {
|
||||
let x = x;
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
23
src/test/ui/async-await/issue-86507.stderr
Normal file
23
src/test/ui/async-await/issue-86507.stderr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
error: future cannot be sent between threads safely
|
||||
--> $DIR/issue-86507.rs:17:13
|
||||
|
|
||||
LL | / Box::pin(
|
||||
LL | | async move {
|
||||
LL | | let x = x;
|
||||
LL | | }
|
||||
LL | | )
|
||||
| |_____________^ future created by async block is not `Send`
|
||||
|
|
||||
note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
|
||||
--> $DIR/issue-86507.rs:19:29
|
||||
|
|
||||
LL | let x = x;
|
||||
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
|
||||
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
|
||||
help: consider further restricting type parameter `T`
|
||||
|
|
||||
LL | where 'me:'async_trait, T: std::marker::Sync {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue