Dedup copy field errors for identical types

This commit is contained in:
Michael Goulet 2023-03-08 00:00:02 +00:00
parent a439c0293c
commit 0f4255ece2
3 changed files with 8 additions and 8 deletions

View File

@ -2,6 +2,7 @@
//! up data structures required by type-checking/codegen. //! up data structures required by type-checking/codegen.
use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem}; use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{struct_span_err, MultiSpan}; use rustc_errors::{struct_span_err, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
@ -94,7 +95,14 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
let mut errors: BTreeMap<_, Vec<_>> = Default::default(); let mut errors: BTreeMap<_, Vec<_>> = Default::default();
let mut bounds = vec![]; let mut bounds = vec![];
let mut seen_tys = FxHashSet::default();
for (field, ty, reason) in fields { for (field, ty, reason) in fields {
// Only report an error once per type.
if !seen_tys.insert(ty) {
continue;
}
let field_span = tcx.def_span(field.did); let field_span = tcx.def_span(field.did);
err.span_label(field_span, "this field does not implement `Copy`"); err.span_label(field_span, "this field does not implement `Copy`");

View File

@ -6,16 +6,12 @@ LL | #[derive(Debug, Copy, Clone)]
LL | pub struct AABB<K: Copy>{ LL | pub struct AABB<K: Copy>{
LL | pub loc: Vector2<K>, LL | pub loc: Vector2<K>,
| ------------------- this field does not implement `Copy` | ------------------- this field does not implement `Copy`
LL | pub size: Vector2<K>
| -------------------- this field does not implement `Copy`
| |
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug` note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
--> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:14 --> $DIR/missing-bound-in-derive-copy-impl-3.rs:12:14
| |
LL | pub loc: Vector2<K>, LL | pub loc: Vector2<K>,
| ^^^^^^^^^^ | ^^^^^^^^^^
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) = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound help: consider further restricting this bound
| |

View File

@ -6,16 +6,12 @@ LL | #[derive(Debug, Copy, Clone)]
LL | pub struct AABB<K>{ LL | pub struct AABB<K>{
LL | pub loc: Vector2<K>, LL | pub loc: Vector2<K>,
| ------------------- this field does not implement `Copy` | ------------------- this field does not implement `Copy`
LL | pub size: Vector2<K>
| -------------------- this field does not implement `Copy`
| |
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug` note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
--> $DIR/missing-bound-in-derive-copy-impl.rs:11:14 --> $DIR/missing-bound-in-derive-copy-impl.rs:11:14
| |
LL | pub loc: Vector2<K>, LL | pub loc: Vector2<K>,
| ^^^^^^^^^^ | ^^^^^^^^^^
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) = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `K` help: consider restricting type parameter `K`
| |