mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Use "generator" instead of "future" when appropriate
This commit is contained in:
parent
7127ff3d94
commit
6edfd66c5d
@ -1281,13 +1281,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
) {
|
||||
let source_map = self.tcx.sess.source_map();
|
||||
|
||||
let is_async_fn = self
|
||||
.tcx
|
||||
.parent(inner_generator)
|
||||
.map(|parent_did| self.tcx.asyncness(parent_did))
|
||||
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
|
||||
.unwrap_or(false);
|
||||
let is_async_move = self
|
||||
let is_async = self
|
||||
.tcx
|
||||
.hir()
|
||||
.as_local_hir_id(inner_generator)
|
||||
@ -1299,7 +1293,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
_ => false,
|
||||
})
|
||||
.unwrap_or(false);
|
||||
let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
|
||||
let await_or_yield = if is_async { "await" } else { "yield" };
|
||||
let future_or_generator = if is_async { "future" } else { "generator" };
|
||||
|
||||
// Special case the primary error message when send or sync is the trait that was
|
||||
// not implemented.
|
||||
@ -1312,7 +1307,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
err.clear_code();
|
||||
err.set_primary_message(format!(
|
||||
"future cannot be {} between threads safely",
|
||||
"{} cannot be {} between threads safely",
|
||||
future_or_generator,
|
||||
trait_verb
|
||||
));
|
||||
|
||||
@ -1335,14 +1331,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
format!("future created by async closure is not {}", trait_name),
|
||||
}
|
||||
))
|
||||
.unwrap_or_else(|| format!("future is not {}", trait_name));
|
||||
.unwrap_or_else(|| format!("{} is not {}", future_or_generator, trait_name));
|
||||
|
||||
span.push_span_label(original_span, message);
|
||||
err.set_span(span);
|
||||
|
||||
format!("is not {}", trait_name)
|
||||
format!("{} is not {}", future_or_generator, trait_name)
|
||||
} else {
|
||||
format!("does not implement `{}`", trait_ref.print_only_trait_path())
|
||||
format!(
|
||||
"{} does not implement `{}`",
|
||||
future_or_generator,
|
||||
trait_ref.print_only_trait_path()
|
||||
)
|
||||
};
|
||||
|
||||
// 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> {
|
||||
|
||||
err.span_note(
|
||||
span,
|
||||
&format!(
|
||||
"future {} as this value is used across an {}",
|
||||
trait_explanation, await_or_yield,
|
||||
),
|
||||
&format!("{} as this value is used across an {}", trait_explanation, await_or_yield),
|
||||
);
|
||||
|
||||
if let Some(expr_id) = expr {
|
||||
|
@ -31,7 +31,7 @@ fn test1() {
|
||||
yield;
|
||||
};
|
||||
require_send(send_gen);
|
||||
//~^ ERROR future cannot be sent between threads
|
||||
//~^ ERROR generator cannot be sent between threads
|
||||
}
|
||||
|
||||
pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: future cannot be sent between threads safely
|
||||
error: generator cannot be sent between threads safely
|
||||
--> $DIR/issue-68112.rs:33:5
|
||||
|
|
||||
LL | fn require_send(_: impl Send) {}
|
||||
@ -8,7 +8,7 @@ LL | require_send(send_gen);
|
||||
| ^^^^^^^^^^^^ generator 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 across an yield
|
||||
note: generator is not `Send` as this value is used across an yield
|
||||
--> $DIR/issue-68112.rs:31:9
|
||||
|
|
||||
LL | let _non_send_gen = make_non_send_generator();
|
||||
|
@ -7,7 +7,7 @@ fn main() {
|
||||
fn assert_send<T: Send>(_: T) {}
|
||||
|
||||
assert_sync(|| {
|
||||
//~^ ERROR: future cannot be shared between threads safely
|
||||
//~^ ERROR: generator cannot be shared between threads safely
|
||||
let a = Cell::new(2);
|
||||
yield;
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ LL | assert_send(|| {
|
||||
= note: required because of the requirements on the impl of `std::marker::Send` for `&std::cell::Cell<i32>`
|
||||
= note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:16:17: 20:6 a:&std::cell::Cell<i32> _]`
|
||||
|
||||
error: future cannot be shared between threads safely
|
||||
error: generator cannot be shared between threads safely
|
||||
--> $DIR/not-send-sync.rs:9:5
|
||||
|
|
||||
LL | fn assert_sync<T: Sync>(_: T) {}
|
||||
@ -21,7 +21,7 @@ LL | assert_sync(|| {
|
||||
| ^^^^^^^^^^^ generator is not `Sync`
|
||||
|
|
||||
= 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>`
|
||||
note: future is not `Sync` as this value is used across an yield
|
||||
note: generator is not `Sync` as this value is used across an yield
|
||||
--> $DIR/not-send-sync.rs:12:9
|
||||
|
|
||||
LL | let a = Cell::new(2);
|
||||
|
Loading…
Reference in New Issue
Block a user