Skip to content

Commit cd501a6

Browse files
committed
Don't double-annotate the same Span
1 parent 9862bbe commit cd501a6

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12741274
"await occurs here".to_string(),
12751275
);
12761276

1277-
push_target_span(&mut span);
1277+
if target_span != await_span {
1278+
push_target_span(&mut span);
1279+
}
12781280

12791281
err.span_note(
12801282
span,

src/test/ui/async-await/issue-68112.rs

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ fn test1() {
3535
//~^ ERROR future cannot be sent between threads
3636
}
3737

38+
fn test1_no_let() {
39+
let send_fut = async {
40+
let _ = make_non_send_future1().await;
41+
ready(0).await;
42+
};
43+
require_send(send_fut);
44+
//~^ ERROR future cannot be sent between threads
45+
}
46+
3847
async fn ready2<T>(t: T) -> T { t }
3948
fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
4049
ready2(Arc::new(RefCell::new(0)))

src/test/ui/async-await/issue-68112.stderr

+22-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,24 @@ LL | let non_send_fut = make_non_send_future1();
1616
LL | let _ = non_send_fut.await;
1717
| ^^^^^^^^^^^^ await occurs here
1818

19+
error: future cannot be sent between threads safely
20+
--> $DIR/issue-68112.rs:43:5
21+
|
22+
LL | fn require_send(_: impl Send) {}
23+
| ------------ ---- required by this bound in `require_send`
24+
...
25+
LL | require_send(send_fut);
26+
| ^^^^^^^^^^^^ future created by async block is not `Send`
27+
|
28+
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
29+
note: future is not `Send` as this value is used in an await
30+
--> $DIR/issue-68112.rs:40:17
31+
|
32+
LL | let _ = make_non_send_future1().await;
33+
| ^^^^^^^^^^^^^^^^^^^^^^^ await occurs here
34+
1935
error[E0277]: `std::cell::RefCell<i32>` cannot be shared between threads safely
20-
--> $DIR/issue-68112.rs:49:5
36+
--> $DIR/issue-68112.rs:58:5
2137
|
2238
LL | fn require_send(_: impl Send) {}
2339
| ------------ ---- required by this bound in `require_send`
@@ -27,16 +43,16 @@ LL | require_send(send_fut);
2743
|
2844
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
2945
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::cell::RefCell<i32>>`
30-
= 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>> {}]`
31-
= 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>> {}]>`
46+
= 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>> {}]`
47+
= 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>> {}]>`
3248
= note: required because it appears within the type `impl std::future::Future`
3349
= note: required because it appears within the type `impl std::future::Future`
3450
= note: required because it appears within the type `impl std::future::Future`
3551
= note: required because it appears within the type `{std::future::ResumeTy, impl std::future::Future, (), i32, Ready<i32>}`
36-
= 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>}]`
37-
= 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>}]>`
52+
= 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>}]`
53+
= 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>}]>`
3854
= note: required because it appears within the type `impl std::future::Future`
3955

40-
error: aborting due to 2 previous errors
56+
error: aborting due to 3 previous errors
4157

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

0 commit comments

Comments
 (0)