]> git.lizzy.rs Git - rust.git/commitdiff
Use "generator" instead of "future" when appropriate
authorTyler Mandry <tmandry@gmail.com>
Wed, 25 Mar 2020 04:13:05 +0000 (21:13 -0700)
committerTyler Mandry <tmandry@gmail.com>
Tue, 14 Apr 2020 01:48:55 +0000 (18:48 -0700)
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
src/test/ui/generator/issue-68112.rs
src/test/ui/generator/issue-68112.stderr
src/test/ui/generator/not-send-sync.rs
src/test/ui/generator/not-send-sync.stderr

index 7c29315352349c6733db8465884e668a0a15162b..0f4fbc41d161108fb39009b55eaab97df545e670 100644 (file)
@@ -1281,13 +1281,7 @@ fn note_obligation_cause_for_async_await(
     ) {
         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 @@ fn note_obligation_cause_for_async_await(
                 _ => 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 @@ fn note_obligation_cause_for_async_await(
 
             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 @@ fn note_obligation_cause_for_async_await(
                             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 @@ fn note_obligation_cause_for_async_await(
 
         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 {
index ee62cbff08f3210fb346d7b0b4a9c7d7407eb428..9ab2abf740572049a22c93b11c18fb4b091b56bf 100644 (file)
@@ -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> {
index 273fec082cf8d0dfbb415a7974d92ab12c93b58c..f40771d2826d65f540f3ec1462bcfc398a3c258e 100644 (file)
@@ -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();
index 0db01c6f756aca80e8fc910a64b289b55b3b63f0..8ca5565fb2ab551982a5143b50682bedee8f3919 100644 (file)
@@ -7,7 +7,7 @@ fn assert_sync<T: Sync>(_: T) {}
     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;
     });
index 0ce9770f7aa6a736a61cad6d3402a0f688d23a7f..fb59ef5f433a1b91a3df6c21f9dd9f4ba89cbb82 100644 (file)
@@ -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);