Skip to content

Commit f9aa2e0

Browse files
committed
Tweak output
1 parent 8567b68 commit f9aa2e0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

compiler/rustc_typeck/src/coherence/builtin.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! up data structures required by type-checking/codegen.
33
44
use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
5-
use rustc_errors::struct_span_err;
5+
use rustc_errors::{struct_span_err, MultiSpan};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::{DefId, LocalDefId};
88
use rustc_hir::lang_items::LangItem;
@@ -16,6 +16,7 @@ use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
1616
use rustc_trait_selection::traits::misc::{can_type_implement_copy, CopyImplementationError};
1717
use rustc_trait_selection::traits::predicate_for_trait_def;
1818
use rustc_trait_selection::traits::{self, ObligationCause, TraitEngine, TraitEngineExt};
19+
use std::collections::BTreeMap;
1920

2021
pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) {
2122
let lang_items = tcx.lang_items();
@@ -101,6 +102,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
101102
generics = self_item.kind.generics();
102103
}
103104
}
105+
let mut errors: BTreeMap<_, Vec<_>> = Default::default();
104106
let mut bounds = vec![];
105107

106108
for (field, ty) in fields {
@@ -127,13 +129,10 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
127129
// FIXME: This error could be more descriptive, especially if the error_predicate
128130
// contains a foreign type or if it's a deeply nested type...
129131
if error_predicate != error.root_obligation.predicate {
130-
err.span_note(
131-
error.obligation.cause.span,
132-
&format!(
133-
"the `Copy` impl for `{}` requires that `{}`",
134-
ty, error_predicate
135-
),
136-
);
132+
errors
133+
.entry((ty.to_string(), error_predicate.to_string()))
134+
.or_default()
135+
.push(error.obligation.cause.span);
137136
}
138137
if let ty::PredicateKind::Trait(ty::TraitPredicate {
139138
trait_ref,
@@ -153,6 +152,13 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
153152
}
154153
});
155154
}
155+
for ((ty, error_predicate), spans) in errors {
156+
let span: MultiSpan = spans.into();
157+
err.span_note(
158+
span,
159+
&format!("the `Copy` impl for `{}` requires that `{}`", ty, error_predicate),
160+
);
161+
}
156162
if let Some(generics) = generics {
157163
suggest_constraining_type_params(
158164
tcx,

src/test/ui/suggestions/missing-bound-in-derive-copy-impl-3.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
1414
|
1515
LL | pub loc: Vector2<K>,
1616
| ^^^^^^^^^^^^^^^^^^^
17-
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
18-
--> $DIR/missing-bound-in-derive-copy-impl-3.rs:13:5
19-
|
2017
LL | pub size: Vector2<K>
2118
| ^^^^^^^^^^^^^^^^^^^^
2219
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

src/test/ui/suggestions/missing-bound-in-derive-copy-impl.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
1414
|
1515
LL | pub loc: Vector2<K>,
1616
| ^^^^^^^^^^^^^^^^^^^
17-
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
18-
--> $DIR/missing-bound-in-derive-copy-impl.rs:12:5
19-
|
2017
LL | pub size: Vector2<K>
2118
| ^^^^^^^^^^^^^^^^^^^^
2219
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)