about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_typeck/src/coherence/builtin.rs22
-rw-r--r--src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr3
-rw-r--r--src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr3
3 files changed, 14 insertions, 14 deletions
diff --git a/compiler/rustc_typeck/src/coherence/builtin.rs b/compiler/rustc_typeck/src/coherence/builtin.rs
index 5953a13506d..c809b8bdd73 100644
--- a/compiler/rustc_typeck/src/coherence/builtin.rs
+++ b/compiler/rustc_typeck/src/coherence/builtin.rs
@@ -2,7 +2,7 @@
 //! up data structures required by type-checking/codegen.
 
 use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
-use rustc_errors::struct_span_err;
+use rustc_errors::{struct_span_err, MultiSpan};
 use rustc_hir as hir;
 use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::lang_items::LangItem;
@@ -16,6 +16,7 @@ use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
 use rustc_trait_selection::traits::misc::{can_type_implement_copy, CopyImplementationError};
 use rustc_trait_selection::traits::predicate_for_trait_def;
 use rustc_trait_selection::traits::{self, ObligationCause, TraitEngine, TraitEngineExt};
+use std::collections::BTreeMap;
 
 pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) {
     let lang_items = tcx.lang_items();
@@ -101,6 +102,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
                     generics = self_item.kind.generics();
                 }
             }
+            let mut errors: BTreeMap<_, Vec<_>> = Default::default();
             let mut bounds = vec![];
 
             for (field, ty) in fields {
@@ -127,13 +129,10 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
                         // FIXME: This error could be more descriptive, especially if the error_predicate
                         // contains a foreign type or if it's a deeply nested type...
                         if error_predicate != error.root_obligation.predicate {
-                            err.span_note(
-                                error.obligation.cause.span,
-                                &format!(
-                                    "the `Copy` impl for `{}` requires that `{}`",
-                                    ty, error_predicate
-                                ),
-                            );
+                            errors
+                                .entry((ty.to_string(), error_predicate.to_string()))
+                                .or_default()
+                                .push(error.obligation.cause.span);
                         }
                         if let ty::PredicateKind::Trait(ty::TraitPredicate {
                             trait_ref,
@@ -153,6 +152,13 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
                     }
                 });
             }
+            for ((ty, error_predicate), spans) in errors {
+                let span: MultiSpan = spans.into();
+                err.span_note(
+                    span,
+                    &format!("the `Copy` impl for `{}` requires that `{}`", ty, error_predicate),
+                );
+            }
             if let Some(generics) = generics {
                 suggest_constraining_type_params(
                     tcx,
diff --git a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr
index 2dc41709fdc..4eb1e318d97 100644
--- a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr
+++ b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr
@@ -14,9 +14,6 @@ note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
    |
 LL |     pub loc: Vector2<K>,
    |     ^^^^^^^^^^^^^^^^^^^
-note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
-  --> $DIR/missing-bound-in-derive-copy-impl-3.rs:13:5
-   |
 LL |     pub size: Vector2<K>
    |     ^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr
index 1f6932b1fa6..1cf2ab95bc3 100644
--- a/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr
+++ b/src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr
@@ -14,9 +14,6 @@ note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
    |
 LL |     pub loc: Vector2<K>,
    |     ^^^^^^^^^^^^^^^^^^^
-note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
-  --> $DIR/missing-bound-in-derive-copy-impl.rs:12:5
-   |
 LL |     pub size: Vector2<K>
    |     ^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)