Skip to content

Commit 0f4255e

Browse files
Dedup copy field errors for identical types
1 parent a439c02 commit 0f4255e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! up data structures required by type-checking/codegen.
33
44
use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
5+
use rustc_data_structures::fx::FxHashSet;
56
use rustc_errors::{struct_span_err, MultiSpan};
67
use rustc_hir as hir;
78
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -94,7 +95,14 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
9495
let mut errors: BTreeMap<_, Vec<_>> = Default::default();
9596
let mut bounds = vec![];
9697

98+
let mut seen_tys = FxHashSet::default();
99+
97100
for (field, ty, reason) in fields {
101+
// Only report an error once per type.
102+
if !seen_tys.insert(ty) {
103+
continue;
104+
}
105+
98106
let field_span = tcx.def_span(field.did);
99107
err.span_label(field_span, "this field does not implement `Copy`");
100108

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

-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ LL | #[derive(Debug, Copy, Clone)]
66
LL | pub struct AABB<K: Copy>{
77
LL | pub loc: Vector2<K>,
88
| ------------------- this field does not implement `Copy`
9-
LL | pub size: Vector2<K>
10-
| -------------------- this field does not implement `Copy`
119
|
1210
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
1311
--> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:14
1412
|
1513
LL | pub loc: Vector2<K>,
1614
| ^^^^^^^^^^
17-
LL | pub size: Vector2<K>
18-
| ^^^^^^^^^^
1915
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
2016
help: consider further restricting this bound
2117
|

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

-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ LL | #[derive(Debug, Copy, Clone)]
66
LL | pub struct AABB<K>{
77
LL | pub loc: Vector2<K>,
88
| ------------------- this field does not implement `Copy`
9-
LL | pub size: Vector2<K>
10-
| -------------------- this field does not implement `Copy`
119
|
1210
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
1311
--> $DIR/missing-bound-in-derive-copy-impl.rs:11:14
1412
|
1513
LL | pub loc: Vector2<K>,
1614
| ^^^^^^^^^^
17-
LL | pub size: Vector2<K>
18-
| ^^^^^^^^^^
1915
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
2016
help: consider restricting type parameter `K`
2117
|

0 commit comments

Comments
 (0)