about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-08 21:24:52 +0100
committerGitHub <noreply@github.com>2023-03-08 21:24:52 +0100
commit031b528052d97ef217748e4d0f0a6503426de229 (patch)
tree2539f068e38a3617bc833ad39d97c9e5a5069153 /compiler/rustc_hir_analysis/src
parentf6b8a9f6dbfad6dc0e7651cbb5372ac8f5b593c6 (diff)
parent0f4255ece2e2ff5e0ab7467513cd45d3cdecb27d (diff)
downloadrust-031b528052d97ef217748e4d0f0a6503426de229.tar.gz
rust-031b528052d97ef217748e4d0f0a6503426de229.zip
Rollup merge of #108884 - compiler-errors:tweak-illegal-copy-impl-message, r=WaffleLapkin
Tweak illegal `Copy` impl message

The phrase "may not" can both mean "is not able to" and "possibly does not". Disambiguate this by just using "cannot".
``@Lokathor`` expressed being annoyed by this [here](https://twitter.com/Lokathor/status/1633200313544089602?s=20).

Also drive-by fix for this extremely noisy message: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6a37275bc810f7846bfe191845b7d11d.

r? diagnostics
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/coherence/builtin.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
index ffb68abf978..8294d92c936 100644
--- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs
+++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
@@ -2,6 +2,7 @@
 //! up data structures required by type-checking/codegen.
 
 use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
+use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{struct_span_err, MultiSpan};
 use rustc_hir as hir;
 use rustc_hir::def_id::{DefId, LocalDefId};
@@ -86,7 +87,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
                 tcx.sess,
                 span,
                 E0204,
-                "the trait `Copy` may not be implemented for this type"
+                "the trait `Copy` cannot be implemented for this type"
             );
 
             // We'll try to suggest constraining type parameters to fulfill the requirements of
@@ -94,7 +95,14 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
             let mut errors: BTreeMap<_, Vec<_>> = Default::default();
             let mut bounds = vec![];
 
+            let mut seen_tys = FxHashSet::default();
+
             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);
                 err.span_label(field_span, "this field does not implement `Copy`");