summaryrefslogtreecommitdiffstats
path: root/src/test/ui/kindck
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/kindck
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/kindck')
-rw-r--r--src/test/ui/kindck/kindck-copy.rs71
-rw-r--r--src/test/ui/kindck/kindck-copy.stderr155
-rw-r--r--src/test/ui/kindck/kindck-impl-type-params-2.rs15
-rw-r--r--src/test/ui/kindck/kindck-impl-type-params-2.stderr22
-rw-r--r--src/test/ui/kindck/kindck-impl-type-params.rs47
-rw-r--r--src/test/ui/kindck/kindck-impl-type-params.stderr103
-rw-r--r--src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr53
-rw-r--r--src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr39
-rw-r--r--src/test/ui/kindck/kindck-inherited-copy-bound.rs34
-rw-r--r--src/test/ui/kindck/kindck-nonsendable-1.rs11
-rw-r--r--src/test/ui/kindck/kindck-nonsendable-1.stderr23
-rw-r--r--src/test/ui/kindck/kindck-send-object.rs26
-rw-r--r--src/test/ui/kindck/kindck-send-object.stderr32
-rw-r--r--src/test/ui/kindck/kindck-send-object1.rs32
-rw-r--r--src/test/ui/kindck/kindck-send-object1.stderr32
-rw-r--r--src/test/ui/kindck/kindck-send-object2.rs24
-rw-r--r--src/test/ui/kindck/kindck-send-object2.stderr32
-rw-r--r--src/test/ui/kindck/kindck-send-owned.rs16
-rw-r--r--src/test/ui/kindck/kindck-send-owned.stderr18
-rw-r--r--src/test/ui/kindck/kindck-send-unsafe.rs11
-rw-r--r--src/test/ui/kindck/kindck-send-unsafe.rs~rust-lang_master12
-rw-r--r--src/test/ui/kindck/kindck-send-unsafe.stderr16
22 files changed, 824 insertions, 0 deletions
diff --git a/src/test/ui/kindck/kindck-copy.rs b/src/test/ui/kindck/kindck-copy.rs
new file mode 100644
index 000000000..6df98c230
--- /dev/null
+++ b/src/test/ui/kindck/kindck-copy.rs
@@ -0,0 +1,71 @@
+// Test which of the builtin types are considered POD.
+
+use std::rc::Rc;
+
+fn assert_copy<T:Copy>() { }
+
+trait Dummy { }
+
+#[derive(Copy, Clone)]
+struct MyStruct {
+ x: isize,
+ y: isize,
+}
+
+struct MyNoncopyStruct {
+ x: Box<char>,
+}
+
+fn test<'a,T,U:Copy>(_: &'a isize) {
+ // lifetime pointers are ok...
+ assert_copy::<&'static isize>();
+ assert_copy::<&'a isize>();
+ assert_copy::<&'a str>();
+ assert_copy::<&'a [isize]>();
+
+ // ...unless they are mutable
+ assert_copy::<&'static mut isize>(); //~ ERROR : Copy` is not satisfied
+ assert_copy::<&'a mut isize>(); //~ ERROR : Copy` is not satisfied
+
+ // boxes are not ok
+ assert_copy::<Box<isize>>(); //~ ERROR : Copy` is not satisfied
+ assert_copy::<String>(); //~ ERROR : Copy` is not satisfied
+ assert_copy::<Vec<isize> >(); //~ ERROR : Copy` is not satisfied
+ assert_copy::<Box<&'a mut isize>>(); //~ ERROR : Copy` is not satisfied
+
+ // borrowed object types are generally ok
+ assert_copy::<&'a dyn Dummy>();
+ assert_copy::<&'a (dyn Dummy + Send)>();
+ assert_copy::<&'static (dyn Dummy + Send)>();
+
+ // owned object types are not ok
+ assert_copy::<Box<dyn Dummy>>(); //~ ERROR : Copy` is not satisfied
+ assert_copy::<Box<dyn Dummy + Send>>(); //~ ERROR : Copy` is not satisfied
+
+ // mutable object types are not ok
+ assert_copy::<&'a mut (dyn Dummy + Send)>(); //~ ERROR : Copy` is not satisfied
+
+ // unsafe ptrs are ok
+ assert_copy::<*const isize>();
+ assert_copy::<*const &'a mut isize>();
+
+ // regular old ints and such are ok
+ assert_copy::<isize>();
+ assert_copy::<bool>();
+ assert_copy::<()>();
+
+ // tuples are ok
+ assert_copy::<(isize,isize)>();
+
+ // structs of POD are ok
+ assert_copy::<MyStruct>();
+
+ // structs containing non-POD are not ok
+ assert_copy::<MyNoncopyStruct>(); //~ ERROR : Copy` is not satisfied
+
+ // ref counted types are not ok
+ assert_copy::<Rc<isize>>(); //~ ERROR : Copy` is not satisfied
+}
+
+pub fn main() {
+}
diff --git a/src/test/ui/kindck/kindck-copy.stderr b/src/test/ui/kindck/kindck-copy.stderr
new file mode 100644
index 000000000..025a5008d
--- /dev/null
+++ b/src/test/ui/kindck/kindck-copy.stderr
@@ -0,0 +1,155 @@
+error[E0277]: the trait bound `&'static mut isize: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:27:19
+ |
+LL | assert_copy::<&'static mut isize>();
+ | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&'static mut isize`
+ |
+ = help: the following other types implement trait `Copy`:
+ f32
+ f64
+ i128
+ i16
+ i32
+ i64
+ i8
+ isize
+ and 6 others
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `&'a mut isize: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:28:19
+ |
+LL | assert_copy::<&'a mut isize>();
+ | ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&'a mut isize`
+ |
+ = help: the following other types implement trait `Copy`:
+ f32
+ f64
+ i128
+ i16
+ i32
+ i64
+ i8
+ isize
+ and 6 others
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Box<isize>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:31:19
+ |
+LL | assert_copy::<Box<isize>>();
+ | ^^^^^^^^^^ the trait `Copy` is not implemented for `Box<isize>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `String: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:32:19
+ |
+LL | assert_copy::<String>();
+ | ^^^^^^ the trait `Copy` is not implemented for `String`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Vec<isize>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:33:19
+ |
+LL | assert_copy::<Vec<isize> >();
+ | ^^^^^^^^^^ the trait `Copy` is not implemented for `Vec<isize>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Box<&'a mut isize>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:34:19
+ |
+LL | assert_copy::<Box<&'a mut isize>>();
+ | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<&'a mut isize>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Box<dyn Dummy>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:42:19
+ |
+LL | assert_copy::<Box<dyn Dummy>>();
+ | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Box<dyn Dummy + Send>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:43:19
+ |
+LL | assert_copy::<Box<dyn Dummy + Send>>();
+ | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `&'a mut (dyn Dummy + Send + 'a): Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:46:19
+ |
+LL | assert_copy::<&'a mut (dyn Dummy + Send)>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&'a mut (dyn Dummy + Send + 'a)`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `MyNoncopyStruct: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:64:19
+ |
+LL | assert_copy::<MyNoncopyStruct>();
+ | ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `MyNoncopyStruct`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error[E0277]: the trait bound `Rc<isize>: Copy` is not satisfied
+ --> $DIR/kindck-copy.rs:67:19
+ |
+LL | assert_copy::<Rc<isize>>();
+ | ^^^^^^^^^ the trait `Copy` is not implemented for `Rc<isize>`
+ |
+note: required by a bound in `assert_copy`
+ --> $DIR/kindck-copy.rs:5:18
+ |
+LL | fn assert_copy<T:Copy>() { }
+ | ^^^^ required by this bound in `assert_copy`
+
+error: aborting due to 11 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-impl-type-params-2.rs b/src/test/ui/kindck/kindck-impl-type-params-2.rs
new file mode 100644
index 000000000..8b0771985
--- /dev/null
+++ b/src/test/ui/kindck/kindck-impl-type-params-2.rs
@@ -0,0 +1,15 @@
+trait Foo {
+}
+
+
+
+impl<T:Copy> Foo for T {
+}
+
+fn take_param<T:Foo>(foo: &T) { }
+
+fn main() {
+ let x: Box<_> = Box::new(3);
+ take_param(&x);
+ //~^ ERROR the trait bound `Box<{integer}>: Foo` is not satisfied
+}
diff --git a/src/test/ui/kindck/kindck-impl-type-params-2.stderr b/src/test/ui/kindck/kindck-impl-type-params-2.stderr
new file mode 100644
index 000000000..89975e968
--- /dev/null
+++ b/src/test/ui/kindck/kindck-impl-type-params-2.stderr
@@ -0,0 +1,22 @@
+error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
+ --> $DIR/kindck-impl-type-params-2.rs:13:16
+ |
+LL | take_param(&x);
+ | ---------- ^^ the trait `Copy` is not implemented for `Box<{integer}>`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required because of the requirements on the impl of `Foo` for `Box<{integer}>`
+ --> $DIR/kindck-impl-type-params-2.rs:6:14
+ |
+LL | impl<T:Copy> Foo for T {
+ | ^^^ ^
+note: required by a bound in `take_param`
+ --> $DIR/kindck-impl-type-params-2.rs:9:17
+ |
+LL | fn take_param<T:Foo>(foo: &T) { }
+ | ^^^ required by this bound in `take_param`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-impl-type-params.rs b/src/test/ui/kindck/kindck-impl-type-params.rs
new file mode 100644
index 000000000..72a6599c3
--- /dev/null
+++ b/src/test/ui/kindck/kindck-impl-type-params.rs
@@ -0,0 +1,47 @@
+// Issue #14061: tests the interaction between generic implementation
+// parameter bounds and trait objects.
+
+use std::marker;
+
+struct S<T>(marker::PhantomData<T>);
+
+trait Gettable<T> {
+ fn get(&self) -> T { panic!() }
+}
+
+impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+
+fn f<T>(val: T) {
+ let t: S<T> = S(marker::PhantomData);
+ let a = &t as &dyn Gettable<T>;
+ //~^ ERROR `T` cannot be sent between threads safely
+ //~| ERROR : Copy` is not satisfied
+}
+
+fn g<T>(val: T) {
+ let t: S<T> = S(marker::PhantomData);
+ let a: &dyn Gettable<T> = &t;
+ //~^ ERROR `T` cannot be sent between threads safely
+ //~| ERROR : Copy` is not satisfied
+}
+
+fn foo<'a>() {
+ let t: S<&'a isize> = S(marker::PhantomData);
+ let a = &t as &dyn Gettable<&'a isize>;
+}
+
+fn foo2<'a>() {
+ let t: Box<S<String>> = Box::new(S(marker::PhantomData));
+ let a = t as Box<dyn Gettable<String>>;
+ //~^ ERROR : Copy` is not satisfied
+}
+
+fn foo3<'a>() {
+ struct Foo; // does not impl Copy
+
+ let t: Box<S<Foo>> = Box::new(S(marker::PhantomData));
+ let a: Box<dyn Gettable<Foo>> = t;
+ //~^ ERROR : Copy` is not satisfied
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-impl-type-params.stderr b/src/test/ui/kindck/kindck-impl-type-params.stderr
new file mode 100644
index 000000000..902349135
--- /dev/null
+++ b/src/test/ui/kindck/kindck-impl-type-params.stderr
@@ -0,0 +1,103 @@
+error[E0277]: `T` cannot be sent between threads safely
+ --> $DIR/kindck-impl-type-params.rs:16:13
+ |
+LL | let a = &t as &dyn Gettable<T>;
+ | ^^ `T` cannot be sent between threads safely
+ |
+note: required because of the requirements on the impl of `Gettable<T>` for `S<T>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
+help: consider restricting type parameter `T`
+ |
+LL | fn f<T: std::marker::Send>(val: T) {
+ | +++++++++++++++++++
+
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/kindck-impl-type-params.rs:16:13
+ |
+LL | let a = &t as &dyn Gettable<T>;
+ | ^^ the trait `Copy` is not implemented for `T`
+ |
+note: required because of the requirements on the impl of `Gettable<T>` for `S<T>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
+help: consider restricting type parameter `T`
+ |
+LL | fn f<T: std::marker::Copy>(val: T) {
+ | +++++++++++++++++++
+
+error[E0277]: `T` cannot be sent between threads safely
+ --> $DIR/kindck-impl-type-params.rs:23:31
+ |
+LL | let a: &dyn Gettable<T> = &t;
+ | ^^ `T` cannot be sent between threads safely
+ |
+note: required because of the requirements on the impl of `Gettable<T>` for `S<T>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
+help: consider restricting type parameter `T`
+ |
+LL | fn g<T: std::marker::Send>(val: T) {
+ | +++++++++++++++++++
+
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/kindck-impl-type-params.rs:23:31
+ |
+LL | let a: &dyn Gettable<T> = &t;
+ | ^^ the trait `Copy` is not implemented for `T`
+ |
+note: required because of the requirements on the impl of `Gettable<T>` for `S<T>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<T>` to the object type `dyn Gettable<T>`
+help: consider restricting type parameter `T`
+ |
+LL | fn g<T: std::marker::Copy>(val: T) {
+ | +++++++++++++++++++
+
+error[E0277]: the trait bound `String: Copy` is not satisfied
+ --> $DIR/kindck-impl-type-params.rs:35:13
+ |
+LL | let a = t as Box<dyn Gettable<String>>;
+ | ^ the trait `Copy` is not implemented for `String`
+ |
+ = help: the trait `Gettable<T>` is implemented for `S<T>`
+note: required because of the requirements on the impl of `Gettable<String>` for `S<String>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<String>` to the object type `dyn Gettable<String>`
+
+error[E0277]: the trait bound `Foo: Copy` is not satisfied
+ --> $DIR/kindck-impl-type-params.rs:43:37
+ |
+LL | let a: Box<dyn Gettable<Foo>> = t;
+ | ^ the trait `Copy` is not implemented for `Foo`
+ |
+ = help: the trait `Gettable<T>` is implemented for `S<T>`
+note: required because of the requirements on the impl of `Gettable<Foo>` for `S<Foo>`
+ --> $DIR/kindck-impl-type-params.rs:12:32
+ |
+LL | impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
+ | ^^^^^^^^^^^ ^^^^
+ = note: required for the cast from `S<Foo>` to the object type `dyn Gettable<Foo>`
+help: consider annotating `Foo` with `#[derive(Copy)]`
+ |
+LL | #[derive(Copy)]
+ |
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr
new file mode 100644
index 000000000..016cd393c
--- /dev/null
+++ b/src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr
@@ -0,0 +1,53 @@
+error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
+ --> $DIR/kindck-inherited-copy-bound.rs:21:16
+ |
+LL | take_param(&x);
+ | ---------- ^^ the trait `Copy` is not implemented for `Box<{integer}>`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required because of the requirements on the impl of `Foo` for `Box<{integer}>`
+ --> $DIR/kindck-inherited-copy-bound.rs:14:14
+ |
+LL | impl<T:Copy> Foo for T {
+ | ^^^ ^
+note: required by a bound in `take_param`
+ --> $DIR/kindck-inherited-copy-bound.rs:17:17
+ |
+LL | fn take_param<T:Foo>(foo: &T) { }
+ | ^^^ required by this bound in `take_param`
+
+error[E0038]: the trait `Foo` cannot be made into an object
+ --> $DIR/kindck-inherited-copy-bound.rs:28:19
+ |
+LL | let z = &x as &dyn Foo;
+ | ^^^^^^^^ `Foo` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/kindck-inherited-copy-bound.rs:10:13
+ |
+LL | trait Foo : Copy {
+ | --- ^^^^ ...because it requires `Self: Sized`
+ | |
+ | this trait cannot be made into an object...
+
+error[E0038]: the trait `Foo` cannot be made into an object
+ --> $DIR/kindck-inherited-copy-bound.rs:28:13
+ |
+LL | let z = &x as &dyn Foo;
+ | ^^ `Foo` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/kindck-inherited-copy-bound.rs:10:13
+ |
+LL | trait Foo : Copy {
+ | --- ^^^^ ...because it requires `Self: Sized`
+ | |
+ | this trait cannot be made into an object...
+ = note: required because of the requirements on the impl of `CoerceUnsized<&dyn Foo>` for `&Box<{integer}>`
+ = note: required by cast to type `&dyn Foo`
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0038, E0277.
+For more information about an error, try `rustc --explain E0038`.
diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr
new file mode 100644
index 000000000..eaf34dff4
--- /dev/null
+++ b/src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr
@@ -0,0 +1,39 @@
+error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
+ --> $DIR/kindck-inherited-copy-bound.rs:21:16
+ |
+LL | take_param(&x);
+ | ---------- ^^ the trait `Copy` is not implemented for `Box<{integer}>`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required because of the requirements on the impl of `Foo` for `Box<{integer}>`
+ --> $DIR/kindck-inherited-copy-bound.rs:14:14
+ |
+LL | impl<T:Copy> Foo for T {
+ | ^^^ ^
+note: required by a bound in `take_param`
+ --> $DIR/kindck-inherited-copy-bound.rs:17:17
+ |
+LL | fn take_param<T:Foo>(foo: &T) { }
+ | ^^^ required by this bound in `take_param`
+
+error[E0038]: the trait `Foo` cannot be made into an object
+ --> $DIR/kindck-inherited-copy-bound.rs:28:13
+ |
+LL | let z = &x as &dyn Foo;
+ | ^^ `Foo` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/kindck-inherited-copy-bound.rs:10:13
+ |
+LL | trait Foo : Copy {
+ | --- ^^^^ ...because it requires `Self: Sized`
+ | |
+ | this trait cannot be made into an object...
+ = note: required because of the requirements on the impl of `CoerceUnsized<&dyn Foo>` for `&Box<i32>`
+ = note: required by cast to type `&dyn Foo`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0038, E0277.
+For more information about an error, try `rustc --explain E0038`.
diff --git a/src/test/ui/kindck/kindck-inherited-copy-bound.rs b/src/test/ui/kindck/kindck-inherited-copy-bound.rs
new file mode 100644
index 000000000..87d47556b
--- /dev/null
+++ b/src/test/ui/kindck/kindck-inherited-copy-bound.rs
@@ -0,0 +1,34 @@
+// Test that Copy bounds inherited by trait are checked.
+//
+// revisions: curr object_safe_for_dispatch
+
+#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
+
+
+use std::any::Any;
+
+trait Foo : Copy {
+ fn foo(&self) {}
+}
+
+impl<T:Copy> Foo for T {
+}
+
+fn take_param<T:Foo>(foo: &T) { }
+
+fn a() {
+ let x: Box<_> = Box::new(3);
+ take_param(&x); //[curr]~ ERROR E0277
+ //[object_safe_for_dispatch]~^ ERROR E0277
+}
+
+fn b() {
+ let x: Box<_> = Box::new(3);
+ let y = &x;
+ let z = &x as &dyn Foo;
+ //[curr]~^ ERROR E0038
+ //[curr]~| ERROR E0038
+ //[object_safe_for_dispatch]~^^^ ERROR E0038
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-nonsendable-1.rs b/src/test/ui/kindck/kindck-nonsendable-1.rs
new file mode 100644
index 000000000..b32fd7862
--- /dev/null
+++ b/src/test/ui/kindck/kindck-nonsendable-1.rs
@@ -0,0 +1,11 @@
+use std::rc::Rc;
+
+fn foo(_x: Rc<usize>) {}
+
+fn bar<F:FnOnce() + Send>(_: F) { }
+
+fn main() {
+ let x = Rc::new(3);
+ bar(move|| foo(x));
+ //~^ ERROR `Rc<usize>` cannot be sent between threads safely
+}
diff --git a/src/test/ui/kindck/kindck-nonsendable-1.stderr b/src/test/ui/kindck/kindck-nonsendable-1.stderr
new file mode 100644
index 000000000..eab003a11
--- /dev/null
+++ b/src/test/ui/kindck/kindck-nonsendable-1.stderr
@@ -0,0 +1,23 @@
+error[E0277]: `Rc<usize>` cannot be sent between threads safely
+ --> $DIR/kindck-nonsendable-1.rs:9:5
+ |
+LL | bar(move|| foo(x));
+ | ^^^ ------ within this `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:15]`
+ | |
+ | `Rc<usize>` cannot be sent between threads safely
+ |
+ = help: within `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:15]`, the trait `Send` is not implemented for `Rc<usize>`
+note: required because it's used within this closure
+ --> $DIR/kindck-nonsendable-1.rs:9:9
+ |
+LL | bar(move|| foo(x));
+ | ^^^^^^
+note: required by a bound in `bar`
+ --> $DIR/kindck-nonsendable-1.rs:5:21
+ |
+LL | fn bar<F:FnOnce() + Send>(_: F) { }
+ | ^^^^ required by this bound in `bar`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-send-object.rs b/src/test/ui/kindck/kindck-send-object.rs
new file mode 100644
index 000000000..6411e688b
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object.rs
@@ -0,0 +1,26 @@
+// Test which of the builtin types are considered sendable. The tests
+// in this file all test the "kind" violates detected during kindck.
+// See all `regions-bounded-by-send.rs`
+
+fn assert_send<T:Send>() { }
+trait Dummy { }
+trait Message : Send { }
+
+// careful with object types, who knows what they close over...
+
+fn object_ref_with_static_bound_not_ok() {
+ assert_send::<&'static (dyn Dummy + 'static)>();
+ //~^ ERROR `(dyn Dummy + 'static)` cannot be shared between threads safely [E0277]
+}
+
+fn box_object_with_no_bound_not_ok<'a>() {
+ assert_send::<Box<dyn Dummy>>();
+ //~^ ERROR `dyn Dummy` cannot be sent between threads safely
+}
+
+fn object_with_send_bound_ok() {
+ assert_send::<&'static (dyn Dummy + Sync)>();
+ assert_send::<Box<dyn Dummy + Send>>();
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-send-object.stderr b/src/test/ui/kindck/kindck-send-object.stderr
new file mode 100644
index 000000000..f14983a51
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object.stderr
@@ -0,0 +1,32 @@
+error[E0277]: `(dyn Dummy + 'static)` cannot be shared between threads safely
+ --> $DIR/kindck-send-object.rs:12:5
+ |
+LL | assert_send::<&'static (dyn Dummy + 'static)>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Dummy + 'static)` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `(dyn Dummy + 'static)`
+ = note: required because of the requirements on the impl of `Send` for `&'static (dyn Dummy + 'static)`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object.rs:5:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error[E0277]: `dyn Dummy` cannot be sent between threads safely
+ --> $DIR/kindck-send-object.rs:17:5
+ |
+LL | assert_send::<Box<dyn Dummy>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Dummy` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `dyn Dummy`
+ = note: required because of the requirements on the impl of `Send` for `Unique<dyn Dummy>`
+ = note: required because it appears within the type `Box<dyn Dummy>`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object.rs:5:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-send-object1.rs b/src/test/ui/kindck/kindck-send-object1.rs
new file mode 100644
index 000000000..787d0f8f6
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object1.rs
@@ -0,0 +1,32 @@
+// Test which object types are considered sendable. This test
+// is broken into two parts because some errors occur in distinct
+// phases in the compiler. See kindck-send-object2.rs as well!
+
+fn assert_send<T:Send+'static>() { }
+trait Dummy { }
+
+// careful with object types, who knows what they close over...
+fn test51<'a>() {
+ assert_send::<&'a dyn Dummy>();
+ //~^ ERROR `(dyn Dummy + 'a)` cannot be shared between threads safely [E0277]
+}
+fn test52<'a>() {
+ assert_send::<&'a (dyn Dummy + Sync)>();
+}
+
+// ...unless they are properly bounded
+fn test60() {
+ assert_send::<&'static (dyn Dummy + Sync)>();
+}
+fn test61() {
+ assert_send::<Box<dyn Dummy + Send>>();
+}
+
+// closure and object types can have lifetime bounds which make
+// them not ok
+fn test_71<'a>() {
+ assert_send::<Box<dyn Dummy + 'a>>();
+ //~^ ERROR `(dyn Dummy + 'a)` cannot be sent between threads safely
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-send-object1.stderr b/src/test/ui/kindck/kindck-send-object1.stderr
new file mode 100644
index 000000000..1f5e21cbf
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object1.stderr
@@ -0,0 +1,32 @@
+error[E0277]: `(dyn Dummy + 'a)` cannot be shared between threads safely
+ --> $DIR/kindck-send-object1.rs:10:5
+ |
+LL | assert_send::<&'a dyn Dummy>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Dummy + 'a)` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `(dyn Dummy + 'a)`
+ = note: required because of the requirements on the impl of `Send` for `&'a (dyn Dummy + 'a)`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object1.rs:5:18
+ |
+LL | fn assert_send<T:Send+'static>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error[E0277]: `(dyn Dummy + 'a)` cannot be sent between threads safely
+ --> $DIR/kindck-send-object1.rs:28:5
+ |
+LL | assert_send::<Box<dyn Dummy + 'a>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Dummy + 'a)` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `(dyn Dummy + 'a)`
+ = note: required because of the requirements on the impl of `Send` for `Unique<(dyn Dummy + 'a)>`
+ = note: required because it appears within the type `Box<(dyn Dummy + 'a)>`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object1.rs:5:18
+ |
+LL | fn assert_send<T:Send+'static>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-send-object2.rs b/src/test/ui/kindck/kindck-send-object2.rs
new file mode 100644
index 000000000..b797588e4
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object2.rs
@@ -0,0 +1,24 @@
+// Continue kindck-send-object1.rs.
+
+fn assert_send<T:Send>() { }
+trait Dummy { }
+
+fn test50() {
+ assert_send::<&'static dyn Dummy>();
+ //~^ ERROR `(dyn Dummy + 'static)` cannot be shared between threads safely [E0277]
+}
+
+fn test53() {
+ assert_send::<Box<dyn Dummy>>();
+ //~^ ERROR `dyn Dummy` cannot be sent between threads safely
+}
+
+// ...unless they are properly bounded
+fn test60() {
+ assert_send::<&'static (dyn Dummy + Sync)>();
+}
+fn test61() {
+ assert_send::<Box<dyn Dummy + Send>>();
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-send-object2.stderr b/src/test/ui/kindck/kindck-send-object2.stderr
new file mode 100644
index 000000000..527127e95
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-object2.stderr
@@ -0,0 +1,32 @@
+error[E0277]: `(dyn Dummy + 'static)` cannot be shared between threads safely
+ --> $DIR/kindck-send-object2.rs:7:5
+ |
+LL | assert_send::<&'static dyn Dummy>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Dummy + 'static)` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `(dyn Dummy + 'static)`
+ = note: required because of the requirements on the impl of `Send` for `&'static (dyn Dummy + 'static)`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object2.rs:3:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error[E0277]: `dyn Dummy` cannot be sent between threads safely
+ --> $DIR/kindck-send-object2.rs:12:5
+ |
+LL | assert_send::<Box<dyn Dummy>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Dummy` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `dyn Dummy`
+ = note: required because of the requirements on the impl of `Send` for `Unique<dyn Dummy>`
+ = note: required because it appears within the type `Box<dyn Dummy>`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-object2.rs:3:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-send-owned.rs b/src/test/ui/kindck/kindck-send-owned.rs
new file mode 100644
index 000000000..65efb6904
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-owned.rs
@@ -0,0 +1,16 @@
+// Test which of the builtin types are considered sendable.
+
+fn assert_send<T:Send>() { }
+
+// owned content are ok
+fn test30() { assert_send::<Box<isize>>(); }
+fn test31() { assert_send::<String>(); }
+fn test32() { assert_send::<Vec<isize> >(); }
+
+// but not if they own a bad thing
+fn test40() {
+ assert_send::<Box<*mut u8>>();
+ //~^ ERROR `*mut u8` cannot be sent between threads safely
+}
+
+fn main() { }
diff --git a/src/test/ui/kindck/kindck-send-owned.stderr b/src/test/ui/kindck/kindck-send-owned.stderr
new file mode 100644
index 000000000..454291aa9
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-owned.stderr
@@ -0,0 +1,18 @@
+error[E0277]: `*mut u8` cannot be sent between threads safely
+ --> $DIR/kindck-send-owned.rs:12:5
+ |
+LL | assert_send::<Box<*mut u8>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut u8` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `*mut u8`
+ = note: required because of the requirements on the impl of `Send` for `Unique<*mut u8>`
+ = note: required because it appears within the type `Box<*mut u8>`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-owned.rs:3:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/kindck/kindck-send-unsafe.rs b/src/test/ui/kindck/kindck-send-unsafe.rs
new file mode 100644
index 000000000..4ef30a71f
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-unsafe.rs
@@ -0,0 +1,11 @@
+extern crate core;
+
+fn assert_send<T:Send>() { }
+
+fn test71<'a>() {
+ assert_send::<*mut &'a isize>();
+ //~^ ERROR `*mut &'a isize` cannot be sent between threads safely
+}
+
+fn main() {
+}
diff --git a/src/test/ui/kindck/kindck-send-unsafe.rs~rust-lang_master b/src/test/ui/kindck/kindck-send-unsafe.rs~rust-lang_master
new file mode 100644
index 000000000..3f0444ec9
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-unsafe.rs~rust-lang_master
@@ -0,0 +1,12 @@
+fn assert_send<T:Send>() { }
+
+// unsafe ptrs are ok unless they point at unsendable things
+fn test70() {
+ assert_send::<*mut int>();
+}
+fn test71<'a>() {
+ assert_send::<*mut &'a int>(); //~ ERROR does not fulfill the required lifetime
+}
+
+fn main() {
+}
diff --git a/src/test/ui/kindck/kindck-send-unsafe.stderr b/src/test/ui/kindck/kindck-send-unsafe.stderr
new file mode 100644
index 000000000..ceed0053c
--- /dev/null
+++ b/src/test/ui/kindck/kindck-send-unsafe.stderr
@@ -0,0 +1,16 @@
+error[E0277]: `*mut &'a isize` cannot be sent between threads safely
+ --> $DIR/kindck-send-unsafe.rs:6:19
+ |
+LL | assert_send::<*mut &'a isize>();
+ | ^^^^^^^^^^^^^^ `*mut &'a isize` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `*mut &'a isize`
+note: required by a bound in `assert_send`
+ --> $DIR/kindck-send-unsafe.rs:3:18
+ |
+LL | fn assert_send<T:Send>() { }
+ | ^^^^ required by this bound in `assert_send`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.