about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAman Arora <me@aman-arora.com>2020-10-08 00:28:53 -0400
committerAman Arora <me@aman-arora.com>2020-10-11 03:33:27 -0400
commit3c46fd67f8b4831da9f2e8a536d34f498cf70241 (patch)
tree31a907436ecdfdf681ac2d3d57872680dcb5041b
parent08d1ab0bf1c01948135548f5404eb625e454160e (diff)
downloadrust-3c46fd67f8b4831da9f2e8a536d34f498cf70241.tar.gz
rust-3c46fd67f8b4831da9f2e8a536d34f498cf70241.zip
traits diagnostics: Don't print closure/generator upvar_tys tuple
Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs24
-rw-r--r--src/test/ui/async-await/issue-68112.stderr1
-rw-r--r--src/test/ui/closures/closure-move-sync.stderr2
-rw-r--r--src/test/ui/generator/issue-68112.stderr1
-rw-r--r--src/test/ui/generator/not-send-sync.stderr1
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-1.stderr1
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-2.stderr1
-rw-r--r--src/test/ui/impl-trait/auto-trait-leak2.stderr2
-rw-r--r--src/test/ui/interior-mutability/interior-mutability.stderr1
-rw-r--r--src/test/ui/kindck/kindck-nonsendable-1.stderr1
-rw-r--r--src/test/ui/no-send-res-ports.stderr1
11 files changed, 23 insertions, 13 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 5908e73d483..7e86548f6ab 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -1922,7 +1922,29 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                     return;
                 }
 
-                err.note(&format!("required because it appears within the type `{}`", ty));
+                // If the obligation for a tuple is set directly by a Generator or Closure,
+                // then the tuple must be the one containing capture types.
+                let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) {
+                    false
+                } else {
+                    if let ObligationCauseCode::BuiltinDerivedObligation(ref data) =
+                        *data.parent_code
+                    {
+                        let parent_trait_ref =
+                            self.resolve_vars_if_possible(&data.parent_trait_ref);
+                        let ty = parent_trait_ref.skip_binder().self_ty();
+                        matches!(ty.kind(), ty::Generator(..))
+                            || matches!(ty.kind(), ty::Closure(..))
+                    } else {
+                        false
+                    }
+                };
+
+                // Don't print the tuple of capture types
+                if !is_upvar_tys_infer_tuple {
+                    err.note(&format!("required because it appears within the type `{}`", ty));
+                }
+
                 obligated_types.push(ty);
 
                 let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx);
diff --git a/src/test/ui/async-await/issue-68112.stderr b/src/test/ui/async-await/issue-68112.stderr
index a6c93e91a9e..e97d088cf3e 100644
--- a/src/test/ui/async-await/issue-68112.stderr
+++ b/src/test/ui/async-await/issue-68112.stderr
@@ -41,7 +41,6 @@ LL |     require_send(send_fut);
    |
    = help: the trait `Sync` is not implemented for `RefCell<i32>`
    = note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
-   = note: required because it appears within the type `(Arc<RefCell<i32>>,)`
    = note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]`
    = note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]>`
    = note: required because it appears within the type `impl Future`
diff --git a/src/test/ui/closures/closure-move-sync.stderr b/src/test/ui/closures/closure-move-sync.stderr
index 285b6543833..da5e25c0d18 100644
--- a/src/test/ui/closures/closure-move-sync.stderr
+++ b/src/test/ui/closures/closure-move-sync.stderr
@@ -11,7 +11,6 @@ LL |     F: Send + 'static,
    |
    = help: the trait `Sync` is not implemented for `std::sync::mpsc::Receiver<()>`
    = note: required because of the requirements on the impl of `Send` for `&std::sync::mpsc::Receiver<()>`
-   = note: required because it appears within the type `(&std::sync::mpsc::Receiver<()>,)`
    = note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:6:27: 9:6]`
 
 error[E0277]: `Sender<()>` cannot be shared between threads safely
@@ -27,7 +26,6 @@ LL |     F: Send + 'static,
    |
    = help: the trait `Sync` is not implemented for `Sender<()>`
    = note: required because of the requirements on the impl of `Send` for `&Sender<()>`
-   = note: required because it appears within the type `(&Sender<()>,)`
    = note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:18:19: 18:42]`
 
 error: aborting due to 2 previous errors
diff --git a/src/test/ui/generator/issue-68112.stderr b/src/test/ui/generator/issue-68112.stderr
index 5793bbd950e..96a8d6d70e0 100644
--- a/src/test/ui/generator/issue-68112.stderr
+++ b/src/test/ui/generator/issue-68112.stderr
@@ -29,7 +29,6 @@ LL |     require_send(send_gen);
    |
    = help: the trait `Sync` is not implemented for `RefCell<i32>`
    = note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
-   = note: required because it appears within the type `(Arc<RefCell<i32>>,)`
    = note: required because it appears within the type `[generator@$DIR/issue-68112.rs:38:5: 41:6 {()}]`
    = note: required because it appears within the type `impl Generator`
    = note: required because it appears within the type `impl Generator`
diff --git a/src/test/ui/generator/not-send-sync.stderr b/src/test/ui/generator/not-send-sync.stderr
index f5cfa83f500..2384ed3d249 100644
--- a/src/test/ui/generator/not-send-sync.stderr
+++ b/src/test/ui/generator/not-send-sync.stderr
@@ -9,7 +9,6 @@ LL |     assert_send(|| {
    |
    = help: the trait `Sync` is not implemented for `Cell<i32>`
    = note: required because of the requirements on the impl of `Send` for `&Cell<i32>`
-   = note: required because it appears within the type `(&Cell<i32>,)`
    = note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:16:17: 20:6 _]`
 
 error: generator cannot be shared between threads safely
diff --git a/src/test/ui/generator/print/generator-print-verbose-1.stderr b/src/test/ui/generator/print/generator-print-verbose-1.stderr
index 9669f4d96b9..b5c63584c6c 100644
--- a/src/test/ui/generator/print/generator-print-verbose-1.stderr
+++ b/src/test/ui/generator/print/generator-print-verbose-1.stderr
@@ -29,7 +29,6 @@ LL |     require_send(send_gen);
    |
    = help: the trait `Sync` is not implemented for `RefCell<i32>`
    = note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
-   = note: required because it appears within the type `(Arc<RefCell<i32>>,)`
    = note: required because it appears within the type `[make_gen2<Arc<RefCell<i32>>>::{closure#0} upvar_tys=(Arc<RefCell<i32>>) {()}]`
    = note: required because it appears within the type `Opaque(DefId(0:29 ~ generator_print_verbose_1[317d]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
    = note: required because it appears within the type `Opaque(DefId(0:32 ~ generator_print_verbose_1[317d]::make_non_send_generator2::{opaque#0}), [])`
diff --git a/src/test/ui/generator/print/generator-print-verbose-2.stderr b/src/test/ui/generator/print/generator-print-verbose-2.stderr
index f363ed6a3b9..f23949091d9 100644
--- a/src/test/ui/generator/print/generator-print-verbose-2.stderr
+++ b/src/test/ui/generator/print/generator-print-verbose-2.stderr
@@ -9,7 +9,6 @@ LL |     assert_send(|| {
    |
    = help: the trait `Sync` is not implemented for `Cell<i32>`
    = note: required because of the requirements on the impl of `Send` for `&'_#3r Cell<i32>`
-   = note: required because it appears within the type `(&'_#3r Cell<i32>,)`
    = note: required because it appears within the type `[main::{closure#1} upvar_tys=(&'_#3r Cell<i32>) _#17t]`
 
 error: generator cannot be shared between threads safely
diff --git a/src/test/ui/impl-trait/auto-trait-leak2.stderr b/src/test/ui/impl-trait/auto-trait-leak2.stderr
index fc2bc62f3a7..6b2b8248a4f 100644
--- a/src/test/ui/impl-trait/auto-trait-leak2.stderr
+++ b/src/test/ui/impl-trait/auto-trait-leak2.stderr
@@ -11,7 +11,6 @@ LL |     send(before());
    |     ^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
    |
    = help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
-   = note: required because it appears within the type `(Rc<Cell<i32>>,)`
    = note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:7:5: 7:22]`
    = note: required because it appears within the type `impl Fn<(i32,)>`
 
@@ -28,7 +27,6 @@ LL | fn after() -> impl Fn(i32) {
    |               ------------ within this `impl Fn<(i32,)>`
    |
    = help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
-   = note: required because it appears within the type `(Rc<Cell<i32>>,)`
    = note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:24:5: 24:22]`
    = note: required because it appears within the type `impl Fn<(i32,)>`
 
diff --git a/src/test/ui/interior-mutability/interior-mutability.stderr b/src/test/ui/interior-mutability/interior-mutability.stderr
index cddfe6c6946..dd43da11664 100644
--- a/src/test/ui/interior-mutability/interior-mutability.stderr
+++ b/src/test/ui/interior-mutability/interior-mutability.stderr
@@ -12,7 +12,6 @@ LL | pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
    = help: within `Cell<i32>`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<i32>`
    = note: required because it appears within the type `Cell<i32>`
    = note: required because of the requirements on the impl of `UnwindSafe` for `&Cell<i32>`
-   = note: required because it appears within the type `(&Cell<i32>,)`
    = note: required because it appears within the type `[closure@$DIR/interior-mutability.rs:5:18: 5:35]`
 
 error: aborting due to previous error
diff --git a/src/test/ui/kindck/kindck-nonsendable-1.stderr b/src/test/ui/kindck/kindck-nonsendable-1.stderr
index f942088eb7e..c7d67a991bf 100644
--- a/src/test/ui/kindck/kindck-nonsendable-1.stderr
+++ b/src/test/ui/kindck/kindck-nonsendable-1.stderr
@@ -10,7 +10,6 @@ LL |     bar(move|| foo(x));
    |     `Rc<usize>` cannot be sent between threads safely
    |
    = help: within `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:22]`, the trait `Send` is not implemented for `Rc<usize>`
-   = note: required because it appears within the type `(Rc<usize>,)`
    = note: required because it appears within the type `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:22]`
 
 error: aborting due to previous error
diff --git a/src/test/ui/no-send-res-ports.stderr b/src/test/ui/no-send-res-ports.stderr
index 8842b181586..ef7fb4ad7b2 100644
--- a/src/test/ui/no-send-res-ports.stderr
+++ b/src/test/ui/no-send-res-ports.stderr
@@ -19,7 +19,6 @@ LL |       F: Send + 'static,
    = help: within `[closure@$DIR/no-send-res-ports.rs:25:19: 29:6]`, the trait `Send` is not implemented for `Rc<()>`
    = note: required because it appears within the type `Port<()>`
    = note: required because it appears within the type `Foo`
-   = note: required because it appears within the type `(Foo,)`
    = note: required because it appears within the type `[closure@$DIR/no-send-res-ports.rs:25:19: 29:6]`
 
 error: aborting due to previous error