Skip to content

Commit 455537e

Browse files
committed
Use "generator" instead of "future" when appropriate
1 parent b731478 commit 455537e

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
@@ -1166,13 +1166,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11661166
) {
11671167
let source_map = self.tcx.sess.source_map();
11681168

1169-
let is_async_fn = self
1170-
.tcx
1171-
.parent(inner_generator)
1172-
.map(|parent_did| self.tcx.asyncness(parent_did))
1173-
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
1174-
.unwrap_or(false);
1175-
let is_async_move = self
1169+
let is_async = self
11761170
.tcx
11771171
.hir()
11781172
.as_local_hir_id(inner_generator)
@@ -1184,7 +1178,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11841178
_ => false,
11851179
})
11861180
.unwrap_or(false);
1187-
let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
1181+
let await_or_yield = if is_async { "await" } else { "yield" };
1182+
let future_or_generator = if is_async { "future" } else { "generator" };
11881183

11891184
// Special case the primary error message when send or sync is the trait that was
11901185
// not implemented.
@@ -1197,7 +1192,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11971192

11981193
err.clear_code();
11991194
err.set_primary_message(format!(
1200-
"future cannot be {} between threads safely",
1195+
"{} cannot be {} between threads safely",
1196+
future_or_generator,
12011197
trait_verb
12021198
));
12031199

@@ -1220,14 +1216,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12201216
format!("future created by async closure is not {}", trait_name),
12211217
}
12221218
))
1223-
.unwrap_or_else(|| format!("future is not {}", trait_name));
1219+
.unwrap_or_else(|| format!("{} is not {}", future_or_generator, trait_name));
12241220

12251221
span.push_span_label(original_span, message);
12261222
err.set_span(span);
12271223

1228-
format!("is not {}", trait_name)
1224+
format!("{} is not {}", future_or_generator, trait_name)
12291225
} else {
1230-
format!("does not implement `{}`", trait_ref.print_only_trait_path())
1226+
format!(
1227+
"{} does not implement `{}`",
1228+
future_or_generator,
1229+
trait_ref.print_only_trait_path()
1230+
)
12311231
};
12321232

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

12561256
err.span_note(
12571257
span,
1258-
&format!(
1259-
"future {} as this value is used across an {}",
1260-
trait_explanation, await_or_yield,
1261-
),
1258+
&format!("{} as this value is used across an {}", trait_explanation, await_or_yield),
12621259
);
12631260

12641261
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)