From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/kindck/kindck-copy.rs | 71 ++++++++++ src/test/ui/kindck/kindck-copy.stderr | 155 +++++++++++++++++++++ src/test/ui/kindck/kindck-impl-type-params-2.rs | 15 ++ .../ui/kindck/kindck-impl-type-params-2.stderr | 22 +++ src/test/ui/kindck/kindck-impl-type-params.rs | 47 +++++++ src/test/ui/kindck/kindck-impl-type-params.stderr | 103 ++++++++++++++ .../kindck/kindck-inherited-copy-bound.curr.stderr | 53 +++++++ ...ited-copy-bound.object_safe_for_dispatch.stderr | 39 ++++++ src/test/ui/kindck/kindck-inherited-copy-bound.rs | 34 +++++ src/test/ui/kindck/kindck-nonsendable-1.rs | 11 ++ src/test/ui/kindck/kindck-nonsendable-1.stderr | 23 +++ src/test/ui/kindck/kindck-send-object.rs | 26 ++++ src/test/ui/kindck/kindck-send-object.stderr | 32 +++++ src/test/ui/kindck/kindck-send-object1.rs | 32 +++++ src/test/ui/kindck/kindck-send-object1.stderr | 32 +++++ src/test/ui/kindck/kindck-send-object2.rs | 24 ++++ src/test/ui/kindck/kindck-send-object2.stderr | 32 +++++ src/test/ui/kindck/kindck-send-owned.rs | 16 +++ src/test/ui/kindck/kindck-send-owned.stderr | 18 +++ src/test/ui/kindck/kindck-send-unsafe.rs | 11 ++ .../kindck/kindck-send-unsafe.rs~rust-lang_master | 12 ++ src/test/ui/kindck/kindck-send-unsafe.stderr | 16 +++ 22 files changed, 824 insertions(+) create mode 100644 src/test/ui/kindck/kindck-copy.rs create mode 100644 src/test/ui/kindck/kindck-copy.stderr create mode 100644 src/test/ui/kindck/kindck-impl-type-params-2.rs create mode 100644 src/test/ui/kindck/kindck-impl-type-params-2.stderr create mode 100644 src/test/ui/kindck/kindck-impl-type-params.rs create mode 100644 src/test/ui/kindck/kindck-impl-type-params.stderr create mode 100644 src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr create mode 100644 src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr create mode 100644 src/test/ui/kindck/kindck-inherited-copy-bound.rs create mode 100644 src/test/ui/kindck/kindck-nonsendable-1.rs create mode 100644 src/test/ui/kindck/kindck-nonsendable-1.stderr create mode 100644 src/test/ui/kindck/kindck-send-object.rs create mode 100644 src/test/ui/kindck/kindck-send-object.stderr create mode 100644 src/test/ui/kindck/kindck-send-object1.rs create mode 100644 src/test/ui/kindck/kindck-send-object1.stderr create mode 100644 src/test/ui/kindck/kindck-send-object2.rs create mode 100644 src/test/ui/kindck/kindck-send-object2.stderr create mode 100644 src/test/ui/kindck/kindck-send-owned.rs create mode 100644 src/test/ui/kindck/kindck-send-owned.stderr create mode 100644 src/test/ui/kindck/kindck-send-unsafe.rs create mode 100644 src/test/ui/kindck/kindck-send-unsafe.rs~rust-lang_master create mode 100644 src/test/ui/kindck/kindck-send-unsafe.stderr (limited to 'src/test/ui/kindck') 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() { } + +trait Dummy { } + +#[derive(Copy, Clone)] +struct MyStruct { + x: isize, + y: isize, +} + +struct MyNoncopyStruct { + x: Box, +} + +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::>(); //~ ERROR : Copy` is not satisfied + assert_copy::(); //~ ERROR : Copy` is not satisfied + assert_copy:: >(); //~ ERROR : Copy` is not satisfied + assert_copy::>(); //~ 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::>(); //~ ERROR : Copy` is not satisfied + assert_copy::>(); //~ 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::(); + assert_copy::(); + assert_copy::<()>(); + + // tuples are ok + assert_copy::<(isize,isize)>(); + + // structs of POD are ok + assert_copy::(); + + // structs containing non-POD are not ok + assert_copy::(); //~ ERROR : Copy` is not satisfied + + // ref counted types are not ok + assert_copy::>(); //~ 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() { } + | ^^^^ 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() { } + | ^^^^ required by this bound in `assert_copy` + +error[E0277]: the trait bound `Box: Copy` is not satisfied + --> $DIR/kindck-copy.rs:31:19 + | +LL | assert_copy::>(); + | ^^^^^^^^^^ the trait `Copy` is not implemented for `Box` + | +note: required by a bound in `assert_copy` + --> $DIR/kindck-copy.rs:5:18 + | +LL | fn assert_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::(); + | ^^^^^^ 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() { } + | ^^^^ required by this bound in `assert_copy` + +error[E0277]: the trait bound `Vec: Copy` is not satisfied + --> $DIR/kindck-copy.rs:33:19 + | +LL | assert_copy:: >(); + | ^^^^^^^^^^ the trait `Copy` is not implemented for `Vec` + | +note: required by a bound in `assert_copy` + --> $DIR/kindck-copy.rs:5:18 + | +LL | fn assert_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::>(); + | ^^^^^^^^^^^^^^^^^^ 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() { } + | ^^^^ required by this bound in `assert_copy` + +error[E0277]: the trait bound `Box: Copy` is not satisfied + --> $DIR/kindck-copy.rs:42:19 + | +LL | assert_copy::>(); + | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box` + | +note: required by a bound in `assert_copy` + --> $DIR/kindck-copy.rs:5:18 + | +LL | fn assert_copy() { } + | ^^^^ required by this bound in `assert_copy` + +error[E0277]: the trait bound `Box: Copy` is not satisfied + --> $DIR/kindck-copy.rs:43:19 + | +LL | assert_copy::>(); + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box` + | +note: required by a bound in `assert_copy` + --> $DIR/kindck-copy.rs:5:18 + | +LL | fn assert_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() { } + | ^^^^ 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::(); + | ^^^^^^^^^^^^^^^ 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() { } + | ^^^^ required by this bound in `assert_copy` + +error[E0277]: the trait bound `Rc: Copy` is not satisfied + --> $DIR/kindck-copy.rs:67:19 + | +LL | assert_copy::>(); + | ^^^^^^^^^ the trait `Copy` is not implemented for `Rc` + | +note: required by a bound in `assert_copy` + --> $DIR/kindck-copy.rs:5:18 + | +LL | fn assert_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 Foo for T { +} + +fn take_param(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 Foo for T { + | ^^^ ^ +note: required by a bound in `take_param` + --> $DIR/kindck-impl-type-params-2.rs:9:17 + | +LL | fn take_param(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(marker::PhantomData); + +trait Gettable { + fn get(&self) -> T { panic!() } +} + +impl Gettable for S {} + +fn f(val: T) { + let t: S = S(marker::PhantomData); + let a = &t as &dyn Gettable; + //~^ ERROR `T` cannot be sent between threads safely + //~| ERROR : Copy` is not satisfied +} + +fn g(val: T) { + let t: S = S(marker::PhantomData); + let a: &dyn Gettable = &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> = Box::new(S(marker::PhantomData)); + let a = t as Box>; + //~^ ERROR : Copy` is not satisfied +} + +fn foo3<'a>() { + struct Foo; // does not impl Copy + + let t: Box> = Box::new(S(marker::PhantomData)); + let a: Box> = 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` cannot be sent between threads safely + | +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` +help: consider restricting type parameter `T` + | +LL | fn f(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; + | ^^ the trait `Copy` is not implemented for `T` + | +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` +help: consider restricting type parameter `T` + | +LL | fn f(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` cannot be sent between threads safely + | +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` +help: consider restricting type parameter `T` + | +LL | fn g(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; + | ^^ the trait `Copy` is not implemented for `T` + | +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` +help: consider restricting type parameter `T` + | +LL | fn g(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>; + | ^ the trait `Copy` is not implemented for `String` + | + = help: the trait `Gettable` is implemented for `S` +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` + +error[E0277]: the trait bound `Foo: Copy` is not satisfied + --> $DIR/kindck-impl-type-params.rs:43:37 + | +LL | let a: Box> = t; + | ^ the trait `Copy` is not implemented for `Foo` + | + = help: the trait `Gettable` is implemented for `S` +note: required because of the requirements on the impl of `Gettable` for `S` + --> $DIR/kindck-impl-type-params.rs:12:32 + | +LL | impl Gettable for S {} + | ^^^^^^^^^^^ ^^^^ + = note: required for the cast from `S` to the object type `dyn Gettable` +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 Foo for T { + | ^^^ ^ +note: required by a bound in `take_param` + --> $DIR/kindck-inherited-copy-bound.rs:17:17 + | +LL | fn take_param(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 + --> $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 + --> $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 Foo for T { + | ^^^ ^ +note: required by a bound in `take_param` + --> $DIR/kindck-inherited-copy-bound.rs:17:17 + | +LL | fn take_param(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 + --> $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` + = 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 Foo for T { +} + +fn take_param(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) {} + +fn bar(_: F) { } + +fn main() { + let x = Rc::new(3); + bar(move|| foo(x)); + //~^ ERROR `Rc` 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` 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` 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` +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) { } + | ^^^^ 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() { } +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::>(); + //~^ ERROR `dyn Dummy` cannot be sent between threads safely +} + +fn object_with_send_bound_ok() { + assert_send::<&'static (dyn Dummy + Sync)>(); + assert_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() { } + | ^^^^ 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::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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` + = note: required because it appears within the type `Box` +note: required by a bound in `assert_send` + --> $DIR/kindck-send-object.rs:5:18 + | +LL | fn assert_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() { } +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::>(); +} + +// closure and object types can have lifetime bounds which make +// them not ok +fn test_71<'a>() { + assert_send::>(); + //~^ 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() { } + | ^^^^ 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::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(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() { } + | ^^^^ 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() { } +trait Dummy { } + +fn test50() { + assert_send::<&'static dyn Dummy>(); + //~^ ERROR `(dyn Dummy + 'static)` cannot be shared between threads safely [E0277] +} + +fn test53() { + assert_send::>(); + //~^ 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::>(); +} + +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() { } + | ^^^^ 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::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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` + = note: required because it appears within the type `Box` +note: required by a bound in `assert_send` + --> $DIR/kindck-send-object2.rs:3:18 + | +LL | fn assert_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() { } + +// owned content are ok +fn test30() { assert_send::>(); } +fn test31() { assert_send::(); } +fn test32() { assert_send:: >(); } + +// but not if they own a bad thing +fn test40() { + assert_send::>(); + //~^ 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::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*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() { } + | ^^^^ 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() { } + +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() { } + +// 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() { } + | ^^^^ required by this bound in `assert_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. -- cgit v1.2.3