diff options
| author | Michael Goulet <michael@errs.io> | 2022-02-21 21:26:37 -0800 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-03-22 18:15:29 -0700 |
| commit | c8cbd3d03c92ec903a964b67dd90aa2cc6d78f2c (patch) | |
| tree | 651552508c4eb94f773426650383f5af3c55f45c /src/test | |
| parent | a4a5e79814fb4d1568fb0ea5ca50f810b071ae12 (diff) | |
| download | rust-c8cbd3d03c92ec903a964b67dd90aa2cc6d78f2c.tar.gz rust-c8cbd3d03c92ec903a964b67dd90aa2cc6d78f2c.zip | |
better errors when a Copy impl is not coherent
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/coherence/deep-bad-copy-reason.rs | 40 | ||||
| -rw-r--r-- | src/test/ui/coherence/deep-bad-copy-reason.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/union/union-copy.stderr | 6 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/test/ui/coherence/deep-bad-copy-reason.rs b/src/test/ui/coherence/deep-bad-copy-reason.rs new file mode 100644 index 00000000000..80bbe387ac7 --- /dev/null +++ b/src/test/ui/coherence/deep-bad-copy-reason.rs @@ -0,0 +1,40 @@ +#![feature(extern_types)] + +extern "Rust" { + type OpaqueListContents; +} + +pub struct ListS<T> { + len: usize, + data: [T; 0], + opaque: OpaqueListContents, +} + +pub struct Interned<'a, T>(&'a T); + +impl<'a, T> Clone for Interned<'a, T> { + fn clone(&self) -> Self { + *self + } +} + +impl<'a, T> Copy for Interned<'a, T> {} + +pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); +//~^ NOTE this field does not implement `Copy` +//~| NOTE the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized` + +impl<'tcx, T> Clone for List<'tcx, T> { + fn clone(&self) -> Self { + *self + } +} + +impl<'tcx, T> Copy for List<'tcx, T> {} +//~^ ERROR the trait `Copy` may not be implemented for this type + +fn assert_is_copy<T: Copy>() {} + +fn main() { + assert_is_copy::<List<'static, ()>>(); +} diff --git a/src/test/ui/coherence/deep-bad-copy-reason.stderr b/src/test/ui/coherence/deep-bad-copy-reason.stderr new file mode 100644 index 00000000000..295538cee60 --- /dev/null +++ b/src/test/ui/coherence/deep-bad-copy-reason.stderr @@ -0,0 +1,18 @@ +error[E0204]: the trait `Copy` may not be implemented for this type + --> $DIR/deep-bad-copy-reason.rs:33:15 + | +LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); + | ------------------------ this field does not implement `Copy` +... +LL | impl<'tcx, T> Copy for List<'tcx, T> {} + | ^^^^ + | +note: the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized` + --> $DIR/deep-bad-copy-reason.rs:23:26 + | +LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/src/test/ui/union/union-copy.stderr b/src/test/ui/union/union-copy.stderr index 0f47bae7f0f..279808dd55b 100644 --- a/src/test/ui/union/union-copy.stderr +++ b/src/test/ui/union/union-copy.stderr @@ -6,6 +6,12 @@ LL | a: std::mem::ManuallyDrop<String> ... LL | impl Copy for W {} | ^^^^ + | +note: the `Copy` impl for `ManuallyDrop<String>` requires that `String: Copy` + --> $DIR/union-copy.rs:8:5 + | +LL | a: std::mem::ManuallyDrop<String> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error |
