Skip to content

Commit

Permalink
traits diagnostics: Don't print closure/generator upvar_tys tuple
Browse files Browse the repository at this point in the history
Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
  • Loading branch information
arora-aman and roxelo committed Oct 11, 2020
1 parent 08d1ab0 commit 3c46fd6
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/async-await/issue-68112.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/closures/closure-move-sync.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/generator/issue-68112.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/generator/not-send-sync.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}), [])`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/impl-trait/auto-trait-leak2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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,)>`

Expand All @@ -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,)>`

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/interior-mutability/interior-mutability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/kindck/kindck-nonsendable-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/no-send-res-ports.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c46fd6

Please sign in to comment.