Skip to content

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

+2-2
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

+9-1
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

+2-2
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

+1-1
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

+3-3
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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 { }

tests/ui/exclusive-drop-and-copy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// issue #20126
22

3-
#[derive(Copy, Clone)] //~ ERROR the trait `Copy` may not be implemented
3+
#[derive(Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented
44
struct Foo;
55

66
impl Drop for Foo {
77
fn drop(&mut self) {}
88
}
99

10-
#[derive(Copy, Clone)] //~ ERROR the trait `Copy` may not be implemented
10+
#[derive(Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented
1111
struct Bar<T>(::std::marker::PhantomData<T>);
1212

1313
impl<T> Drop for Bar<T> {

tests/ui/exclusive-drop-and-copy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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/exclusive-drop-and-copy.rs:3:10
33
|
44
LL | #[derive(Copy, Clone)]
55
| ^^^^ `Copy` not allowed on types with destructors
66
|
77
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
88

9-
error[E0184]: the trait `Copy` may not be implemented for this type; the type has a destructor
9+
error[E0184]: the trait `Copy` cannot be implemented for this type; the type has a destructor
1010
--> $DIR/exclusive-drop-and-copy.rs:10:10
1111
|
1212
LL | #[derive(Copy, Clone)]

tests/ui/issues/issue-27340.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Foo;
22
#[derive(Copy, Clone)]
3-
//~^ ERROR the trait `Copy` may not be implemented for this type
3+
//~^ ERROR the trait `Copy` cannot be implemented for this type
44
struct Bar(Foo);
55

66
fn main() {}

tests/ui/issues/issue-27340.stderr

+1-1
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/issue-27340.rs:2:10
33
|
44
LL | #[derive(Copy, Clone)]

tests/ui/opt-in-copy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct IWantToCopyThis {
55
}
66

77
impl Copy for IWantToCopyThis {}
8-
//~^ ERROR the trait `Copy` may not be implemented for this type
8+
//~^ ERROR the trait `Copy` cannot be implemented for this type
99

1010
enum CantCopyThisEither {
1111
A,
@@ -17,6 +17,6 @@ enum IWantToCopyThisToo {
1717
}
1818

1919
impl Copy for IWantToCopyThisToo {}
20-
//~^ ERROR the trait `Copy` may not be implemented for this type
20+
//~^ ERROR the trait `Copy` cannot be implemented for this type
2121

2222
fn main() {}

tests/ui/opt-in-copy.stderr

+2-2
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/opt-in-copy.rs:7:15
33
|
44
LL | but_i_cant: CantCopyThis,
@@ -7,7 +7,7 @@ LL | but_i_cant: CantCopyThis,
77
LL | impl Copy for IWantToCopyThis {}
88
| ^^^^^^^^^^^^^^^
99

10-
error[E0204]: the trait `Copy` may not be implemented for this type
10+
error[E0204]: the trait `Copy` cannot be implemented for this type
1111
--> $DIR/opt-in-copy.rs:19:15
1212
|
1313
LL | ButICant(CantCopyThisEither),

tests/ui/range/range_traits-2.stderr

+1-1
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/range_traits-2.rs:3:10
33
|
44
LL | #[derive(Copy, Clone)]

tests/ui/range/range_traits-3.stderr

+1-1
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/range_traits-3.rs:3:10
33
|
44
LL | #[derive(Copy, Clone)]

tests/ui/range/range_traits-6.stderr

+1-1
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/range_traits-6.rs:3:10
33
|
44
LL | #[derive(Copy, Clone)]

tests/ui/span/E0204.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ struct Foo {
22
foo: Vec<u32>,
33
}
44

5-
impl Copy for Foo { } //~ ERROR may not be implemented for this type
5+
impl Copy for Foo { } //~ ERROR cannot be implemented for this type
66

7-
#[derive(Copy)] //~ ERROR may not be implemented for this type
7+
#[derive(Copy)] //~ ERROR cannot be implemented for this type
88
struct Foo2<'a> {
99
ty: &'a mut bool,
1010
}
@@ -14,9 +14,9 @@ enum EFoo {
1414
Baz,
1515
}
1616

17-
impl Copy for EFoo { } //~ ERROR may not be implemented for this type
17+
impl Copy for EFoo { } //~ ERROR cannot be implemented for this type
1818

19-
#[derive(Copy)] //~ ERROR may not be implemented for this type
19+
#[derive(Copy)] //~ ERROR cannot be implemented for this type
2020
enum EFoo2<'a> {
2121
Bar(&'a mut bool),
2222
Baz,

tests/ui/span/E0204.stderr

+4-4
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/E0204.rs:5:15
33
|
44
LL | foo: Vec<u32>,
@@ -7,7 +7,7 @@ LL | foo: Vec<u32>,
77
LL | impl Copy for Foo { }
88
| ^^^
99

10-
error[E0204]: the trait `Copy` may not be implemented for this type
10+
error[E0204]: the trait `Copy` cannot be implemented for this type
1111
--> $DIR/E0204.rs:7:10
1212
|
1313
LL | #[derive(Copy)]
@@ -18,7 +18,7 @@ LL | ty: &'a mut bool,
1818
|
1919
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
2020

21-
error[E0204]: the trait `Copy` may not be implemented for this type
21+
error[E0204]: the trait `Copy` cannot be implemented for this type
2222
--> $DIR/E0204.rs:17:15
2323
|
2424
LL | Bar { x: Vec<u32> },
@@ -27,7 +27,7 @@ LL | Bar { x: Vec<u32> },
2727
LL | impl Copy for EFoo { }
2828
| ^^^^
2929

30-
error[E0204]: the trait `Copy` may not be implemented for this type
30+
error[E0204]: the trait `Copy` cannot be implemented for this type
3131
--> $DIR/E0204.rs:19:10
3232
|
3333
LL | #[derive(Copy)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Vector2<T: Debug + Copy + Clone>{
77
pub y: T
88
}
99

10-
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` may not be implemented for this type
10+
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type
1111
pub struct AABB<K: Copy + Debug>{
1212
pub loc: Vector2<K>,
1313
pub size: Vector2<K>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Vector2<T: Debug + Copy + Clone>{
77
pub y: T
88
}
99

10-
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` may not be implemented for this type
10+
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type
1111
pub struct AABB<K: Copy>{
1212
pub loc: Vector2<K>,
1313
pub size: Vector2<K>

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
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/missing-bound-in-derive-copy-impl-3.rs:10:17
33
|
44
LL | #[derive(Debug, Copy, Clone)]
55
| ^^^^
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.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct Vector2<T: Debug + Copy + Clone>{
66
pub y: T
77
}
88

9-
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` may not be implemented for this type
9+
#[derive(Debug, Copy, Clone)] //~ ERROR the trait `Copy` cannot be implemented for this type
1010
pub struct AABB<K>{
1111
pub loc: Vector2<K>,
1212
pub size: Vector2<K>

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
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/missing-bound-in-derive-copy-impl.rs:9:17
33
|
44
LL | #[derive(Debug, Copy, Clone)]
55
| ^^^^
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
|

tests/ui/suggestions/missing-bound-in-manual-copy-impl-2.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ impl<T: std::fmt::Display> Clone for OnlyCopyIfDisplay<T> {
1414
impl<T: std::fmt::Display> Copy for OnlyCopyIfDisplay<T> {}
1515

1616
impl<S: std::fmt::Display> Copy for Wrapper<OnlyCopyIfDisplay<S>> {}
17-
//~^ ERROR the trait `Copy` may not be implemented for this type
17+
//~^ ERROR the trait `Copy` cannot be implemented for this type
1818

1919
fn main() {}

tests/ui/suggestions/missing-bound-in-manual-copy-impl-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ impl<T: std::fmt::Display> Clone for OnlyCopyIfDisplay<T> {
1414
impl<T: std::fmt::Display> Copy for OnlyCopyIfDisplay<T> {}
1515

1616
impl<S> Copy for Wrapper<OnlyCopyIfDisplay<S>> {}
17-
//~^ ERROR the trait `Copy` may not be implemented for this type
17+
//~^ ERROR the trait `Copy` cannot be implemented for this type
1818

1919
fn main() {}

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

+1-1
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/missing-bound-in-manual-copy-impl-2.rs:16:18
33
|
44
LL | struct Wrapper<T>(T);

tests/ui/suggestions/missing-bound-in-manual-copy-impl.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
struct Wrapper<T>(T);
55

66
impl<S: Copy> Copy for Wrapper<S> {}
7-
//~^ ERROR the trait `Copy` may not be implemented for this type
7+
//~^ ERROR the trait `Copy` cannot be implemented for this type
88

99
fn main() {}

tests/ui/suggestions/missing-bound-in-manual-copy-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
struct Wrapper<T>(T);
55

66
impl<S> Copy for Wrapper<S> {}
7-
//~^ ERROR the trait `Copy` may not be implemented for this type
7+
//~^ ERROR the trait `Copy` cannot be implemented for this type
88

99
fn main() {}

0 commit comments

Comments
 (0)