Skip to content

Commit 6edfd66

Browse files
committed
Use "generator" instead of "future" when appropriate
1 parent 7127ff3 commit 6edfd66

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,13 +1281,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12811281
) {
12821282
let source_map = self.tcx.sess.source_map();
12831283

1284-
let is_async_fn = self
1285-
.tcx
1286-
.parent(inner_generator)
1287-
.map(|parent_did| self.tcx.asyncness(parent_did))
1288-
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
1289-
.unwrap_or(false);
1290-
let is_async_move = self
1284+
let is_async = self
12911285
.tcx
12921286
.hir()
12931287
.as_local_hir_id(inner_generator)
@@ -1299,7 +1293,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12991293
_ => false,
13001294
})
13011295
.unwrap_or(false);
1302-
let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
1296+
let await_or_yield = if is_async { "await" } else { "yield" };
1297+
let future_or_generator = if is_async { "future" } else { "generator" };
13031298

13041299
// Special case the primary error message when send or sync is the trait that was
13051300
// not implemented.
@@ -1312,7 +1307,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13121307

13131308
err.clear_code();
13141309
err.set_primary_message(format!(
1315-
"future cannot be {} between threads safely",
1310+
"{} cannot be {} between threads safely",
1311+
future_or_generator,
13161312
trait_verb
13171313
));
13181314

@@ -1335,14 +1331,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13351331
format!("future created by async closure is not {}", trait_name),
13361332
}
13371333
))
1338-
.unwrap_or_else(|| format!("future is not {}", trait_name));
1334+
.unwrap_or_else(|| format!("{} is not {}", future_or_generator, trait_name));
13391335

13401336
span.push_span_label(original_span, message);
13411337
err.set_span(span);
13421338

1343-
format!("is not {}", trait_name)
1339+
format!("{} is not {}", future_or_generator, trait_name)
13441340
} else {
1345-
format!("does not implement `{}`", trait_ref.print_only_trait_path())
1341+
format!(
1342+
"{} does not implement `{}`",
1343+
future_or_generator,
1344+
trait_ref.print_only_trait_path()
1345+
)
13461346
};
13471347

13481348
// Look at the last interior type to get a span for the `.await`.
@@ -1370,10 +1370,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13701370

13711371
err.span_note(
13721372
span,
1373-
&format!(
1374-
"future {} as this value is used across an {}",
1375-
trait_explanation, await_or_yield,
1376-
),
1373+
&format!("{} as this value is used across an {}", trait_explanation, await_or_yield),
13771374
);
13781375

13791376
if let Some(expr_id) = expr {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn test1() {
3131
yield;
3232
};
3333
require_send(send_gen);
34-
//~^ ERROR future cannot be sent between threads
34+
//~^ ERROR generator cannot be sent between threads
3535
}
3636

3737
pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: future cannot be sent between threads safely
1+
error: generator cannot be sent between threads safely
22
--> $DIR/issue-68112.rs:33:5
33
|
44
LL | fn require_send(_: impl Send) {}
@@ -8,7 +8,7 @@ LL | require_send(send_gen);
88
| ^^^^^^^^^^^^ generator is not `Send`
99
|
1010
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
11-
note: future is not `Send` as this value is used across an yield
11+
note: generator is not `Send` as this value is used across an yield
1212
--> $DIR/issue-68112.rs:31:9
1313
|
1414
LL | let _non_send_gen = make_non_send_generator();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
fn assert_send<T: Send>(_: T) {}
88

99
assert_sync(|| {
10-
//~^ ERROR: future cannot be shared between threads safely
10+
//~^ ERROR: generator cannot be shared between threads safely
1111
let a = Cell::new(2);
1212
yield;
1313
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | assert_send(|| {
1111
= note: required because of the requirements on the impl of `std::marker::Send` for `&std::cell::Cell<i32>`
1212
= note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:16:17: 20:6 a:&std::cell::Cell<i32> _]`
1313

14-
error: future cannot be shared between threads safely
14+
error: generator cannot be shared between threads safely
1515
--> $DIR/not-send-sync.rs:9:5
1616
|
1717
LL | fn assert_sync<T: Sync>(_: T) {}
@@ -21,7 +21,7 @@ LL | assert_sync(|| {
2121
| ^^^^^^^^^^^ 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>`
24-
note: future is not `Sync` as this value is used across an yield
24+
note: generator is not `Sync` as this value is used across an yield
2525
--> $DIR/not-send-sync.rs:12:9
2626
|
2727
LL | let a = Cell::new(2);

0 commit comments

Comments
 (0)