Skip to content

Commit ce8331f

Browse files
committed
Improve span label
1 parent 0c97636 commit ce8331f

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir as hir;
1010
use rustc_hir::def::DefKind;
1111
use rustc_hir::def_id::DefId;
1212
use rustc_hir::intravisit::Visitor;
13-
use rustc_hir::Node;
13+
use rustc_hir::{GeneratorKind, AsyncGeneratorKind, Node};
1414
use rustc_middle::ty::TypeckTables;
1515
use rustc_middle::ty::{
1616
self, AdtKind, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
@@ -1204,15 +1204,23 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12041204
let original_span = err.span.primary_span().unwrap();
12051205
let mut span = MultiSpan::from_span(original_span);
12061206

1207-
let message = if let Some(name) = outer_generator
1208-
.and_then(|generator_did| self.tcx.parent(generator_did))
1209-
.and_then(|parent_did| hir.as_local_hir_id(parent_did))
1210-
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
1211-
{
1212-
format!("future returned by `{}` is not {}", name, trait_name)
1213-
} else {
1214-
format!("future is not {}", trait_name)
1215-
};
1207+
let message = outer_generator
1208+
.and_then(|generator_did| Some(
1209+
match self.tcx.generator_kind(generator_did).unwrap() {
1210+
GeneratorKind::Gen => format!("generator is not {}", trait_name),
1211+
GeneratorKind::Async(AsyncGeneratorKind::Fn) =>
1212+
self.tcx.parent(generator_did)
1213+
.and_then(|parent_did| hir.as_local_hir_id(parent_did))
1214+
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
1215+
.map(|name| format!("future returned by `{}` is not {}",
1216+
name, trait_name))?,
1217+
GeneratorKind::Async(AsyncGeneratorKind::Block) =>
1218+
format!("future created by async block is not {}", trait_name),
1219+
GeneratorKind::Async(AsyncGeneratorKind::Closure) =>
1220+
format!("future created by async closure is not {}", trait_name),
1221+
}
1222+
))
1223+
.unwrap_or_else(|| format!("future is not {}", trait_name));
12161224

12171225
span.push_span_label(original_span, message);
12181226
err.set_span(span);

src/test/ui/async-await/issue-64130-4-async-move.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
22
--> $DIR/issue-64130-4-async-move.rs:15:17
33
|
44
LL | pub fn foo() -> impl Future + Send {
5-
| ^^^^^^^^^^^^^^^^^^ future returned by `foo` is not `Send`
5+
| ^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
66
...
77
LL | / async move {
88
LL | | match client.status() {

src/test/ui/async-await/issue-67252-unnamed-future.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn spawn<T: Send>(_: T) {}
55
| ----- ---- required by this bound in `spawn`
66
...
77
LL | spawn(async {
8-
| ^^^^^ future is not `Send`
8+
| ^^^^^ future created by async block is not `Send`
99
|
1010
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `*mut ()`
1111
note: future is not `Send` as this value is used across an await

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn require_send(_: impl Send) {}
55
| ------------ ---- required by this bound in `require_send`
66
...
77
LL | require_send(send_fut);
8-
| ^^^^^^^^^^^^ future returned by `test1` is not `Send`
8+
| ^^^^^^^^^^^^ future created by async block is not `Send`
99
|
1010
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
1111
note: future is not `Send` as this value is used across an await

src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn assert_send<T: Send>(_: T) {}
55
| ----------- ---- required by this bound in `assert_send`
66
...
77
LL | assert_send(async {
8-
| ^^^^^^^^^^^ future returned by `main` is not `Send`
8+
| ^^^^^^^^^^^ future created by async block is not `Send`
99
|
1010
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `*const u8`
1111
note: future is not `Send` as this value is used across an await

src/test/ui/generator/issue-68112.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn require_send(_: impl Send) {}
55
| ------------ ---- required by this bound in `require_send`
66
...
77
LL | require_send(send_gen);
8-
| ^^^^^^^^^^^^ future returned by `test1` is not `Send`
8+
| ^^^^^^^^^^^^ generator is not `Send`
99
|
1010
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
1111
note: future is not `Send` as this value is used across an yield

src/test/ui/generator/not-send-sync.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | fn assert_sync<T: Sync>(_: T) {}
1818
| ----------- ---- required by this bound in `main::assert_sync`
1919
...
2020
LL | assert_sync(|| {
21-
| ^^^^^^^^^^^ future returned by `main` is not `Sync`
21+
| ^^^^^^^^^^^ generator is not `Sync`
2222
|
2323
= help: within `[generator@$DIR/not-send-sync.rs:9:17: 13:6 {std::cell::Cell<i32>, ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
2424
note: future is not `Sync` as this value is used across an yield

0 commit comments

Comments
 (0)