Skip to content

Commit

Permalink
Don't double-annotate the same Span
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Apr 14, 2020
1 parent aed7c30 commit e340375
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Expand Up @@ -1389,7 +1389,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"await occurs here".to_string(),
);

push_target_span(&mut span);
if target_span != await_span {
push_target_span(&mut span);
}

err.span_note(
span,
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/async-await/issue-68112.rs
Expand Up @@ -35,6 +35,15 @@ fn test1() {
//~^ ERROR future cannot be sent between threads
}

fn test1_no_let() {
let send_fut = async {
let _ = make_non_send_future1().await;
ready(0).await;
};
require_send(send_fut);
//~^ ERROR future cannot be sent between threads
}

async fn ready2<T>(t: T) -> T { t }
fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
ready2(Arc::new(RefCell::new(0)))
Expand Down
28 changes: 22 additions & 6 deletions src/test/ui/async-await/issue-68112.stderr
Expand Up @@ -16,8 +16,24 @@ LL | let non_send_fut = make_non_send_future1();
LL | let _ = non_send_fut.await;
| ^^^^^^^^^^^^ await occurs here

error: future cannot be sent between threads safely
--> $DIR/issue-68112.rs:43:5
|
LL | fn require_send(_: impl Send) {}
| ------------ ---- required by this bound in `require_send`
...
LL | require_send(send_fut);
| ^^^^^^^^^^^^ future created by async block is not `Send`
|
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
note: future is not `Send` as this value is used in an await
--> $DIR/issue-68112.rs:40:17
|
LL | let _ = make_non_send_future1().await;
| ^^^^^^^^^^^^^^^^^^^^^^^ await occurs here

error[E0277]: `std::cell::RefCell<i32>` cannot be shared between threads safely
--> $DIR/issue-68112.rs:49:5
--> $DIR/issue-68112.rs:58:5
|
LL | fn require_send(_: impl Send) {}
| ------------ ---- required by this bound in `require_send`
Expand All @@ -27,16 +43,16 @@ LL | require_send(send_fut);
|
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::cell::RefCell<i32>>`
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:38:31: 38:36 t:std::sync::Arc<std::cell::RefCell<i32>> {}]`
= note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:38:31: 38:36 t:std::sync::Arc<std::cell::RefCell<i32>> {}]>`
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:47:31: 47:36 t:std::sync::Arc<std::cell::RefCell<i32>> {}]`
= note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:47:31: 47:36 t:std::sync::Arc<std::cell::RefCell<i32>> {}]>`
= note: required because it appears within the type `impl std::future::Future`
= note: required because it appears within the type `impl std::future::Future`
= note: required because it appears within the type `impl std::future::Future`
= note: required because it appears within the type `{std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}`
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:44:26: 48:6 {std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}]`
= note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:44:26: 48:6 {std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}]>`
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:53:26: 57:6 {std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}]`
= note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:53:26: 57:6 {std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}]>`
= note: required because it appears within the type `impl std::future::Future`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.

0 comments on commit e340375

Please sign in to comment.