Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 031b528

Browse files
authored
Rollup merge of rust-lang#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
2 parents f6b8a9f + 0f4255e commit 031b528

38 files changed

+62
-62
lines changed

compiler/rustc_hir_analysis/locales/en-US.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ hir_analysis_missing_type_params =
8989
.note = because of the default `Self` reference, type parameters must be specified on object types
9090
9191
hir_analysis_copy_impl_on_type_with_dtor =
92-
the trait `Copy` may not be implemented for this type; the type has a destructor
92+
the trait `Copy` cannot be implemented for this type; the type has a destructor
9393
.label = `Copy` not allowed on types with destructors
9494
9595
hir_analysis_multiple_relaxed_default_bounds =
9696
type parameter has more than one relaxed default bound, only one is supported
9797
9898
hir_analysis_copy_impl_on_non_adt =
99-
the trait `Copy` may not be implemented for this type
99+
the trait `Copy` cannot be implemented for this type
100100
.label = type is not a structure or enumeration
101101
102102
hir_analysis_const_impl_for_non_const_trait =

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 9 additions & 1 deletion
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};
@@ -86,15 +87,22 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
8687
tcx.sess,
8788
span,
8889
E0204,
89-
"the trait `Copy` may not be implemented for this type"
90+
"the trait `Copy` cannot be implemented for this type"
9091
);
9192

9293
// We'll try to suggest constraining type parameters to fulfill the requirements of
9394
// their `Copy` implementation.
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

compiler/rustc_hir_typeck/locales/en-US.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ hir_typeck_field_multiply_specified_in_initializer =
44
.previous_use_label = first use of `{$ident}`
55
66
hir_typeck_copy_impl_on_type_with_dtor =
7-
the trait `Copy` may not be implemented for this type; the type has a destructor
7+
the trait `Copy` cannot be implemented for this type; the type has a destructor
88
.label = `Copy` not allowed on types with destructors
99
1010
hir_typeck_multiple_relaxed_default_bounds =
1111
type parameter has more than one relaxed default bound, only one is supported
1212
1313
hir_typeck_copy_impl_on_non_adt =
14-
the trait `Copy` may not be implemented for this type
14+
the trait `Copy` cannot be implemented for this type
1515
.label = type is not a structure or enumeration
1616
1717
hir_typeck_trait_object_declared_with_no_traits =

library/core/src/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub trait StructuralEq {
324324
/// attempt to derive a `Copy` implementation, we'll get an error:
325325
///
326326
/// ```text
327-
/// the trait `Copy` may not be implemented for this type; field `points` does not implement `Copy`
327+
/// the trait `Copy` cannot be implemented for this type; field `points` does not implement `Copy`
328328
/// ```
329329
///
330330
/// Shared references (`&T`) are also `Copy`, so a type can be `Copy`, even when it holds

tests/ui/coherence/coherence-impls-copy.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ LL | impl Copy for [MyType] {}
5252
|
5353
= note: define and implement a trait or new type instead
5454

55-
error[E0206]: the trait `Copy` may not be implemented for this type
55+
error[E0206]: the trait `Copy` cannot be implemented for this type
5656
--> $DIR/coherence-impls-copy.rs:21:15
5757
|
5858
LL | impl Copy for &'static mut MyType {}
5959
| ^^^^^^^^^^^^^^^^^^^ type is not a structure or enumeration
6060

61-
error[E0206]: the trait `Copy` may not be implemented for this type
61+
error[E0206]: the trait `Copy` cannot be implemented for this type
6262
--> $DIR/coherence-impls-copy.rs:25:15
6363
|
6464
LL | impl Copy for (MyType, MyType) {}
6565
| ^^^^^^^^^^^^^^^^ type is not a structure or enumeration
6666

67-
error[E0206]: the trait `Copy` may not be implemented for this type
67+
error[E0206]: the trait `Copy` cannot be implemented for this type
6868
--> $DIR/coherence-impls-copy.rs:30:15
6969
|
7070
LL | impl Copy for [MyType] {}

tests/ui/coherence/deep-bad-copy-reason.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'tcx, T> Clone for List<'tcx, T> {
3131
}
3232

3333
impl<'tcx, T> Copy for List<'tcx, T> {}
34-
//~^ ERROR the trait `Copy` may not be implemented for this type
34+
//~^ ERROR the trait `Copy` cannot be implemented for this type
3535

3636
fn assert_is_copy<T: Copy>() {}
3737

tests/ui/coherence/deep-bad-copy-reason.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0204]: the trait `Copy` may not be implemented for this type
1+
error[E0204]: the trait `Copy` cannot be implemented for this type
22
--> $DIR/deep-bad-copy-reason.rs:33:24
33
|
44
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);

tests/ui/error-codes/E0184.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0184]: the trait `Copy` may not be implemented for this type; the type has a destructor
1+
error[E0184]: the trait `Copy` cannot be implemented for this type; the type has a destructor
22
--> $DIR/E0184.rs:1:10
33
|
44
LL | #[derive(Copy)]

tests/ui/error-codes/E0206.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
struct Bar;
33

44
impl Copy for &'static mut Bar { }
5-
//~^ ERROR the trait `Copy` may not be implemented for this type
5+
//~^ ERROR the trait `Copy` cannot be implemented for this type
66

77
fn main() {
88
}

tests/ui/error-codes/E0206.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0206]: the trait `Copy` may not be implemented for this type
1+
error[E0206]: the trait `Copy` cannot be implemented for this type
22
--> $DIR/E0206.rs:4:15
33
|
44
LL | impl Copy for &'static mut Bar { }

0 commit comments

Comments
 (0)