mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
traits diagnostics: Don't print closure/generator upvar_tys tuple
Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
This commit is contained in:
parent
08d1ab0bf1
commit
3c46fd67f8
@ -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);
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
@ -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}), [])`
|
||||
|
@ -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
|
||||
|
@ -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,)>`
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user