summaryrefslogtreecommitdiffstats
path: root/src/test/ui/builtin-superkinds
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/builtin-superkinds')
-rw-r--r--src/test/ui/builtin-superkinds/auxiliary/trait_superkinds_in_metadata.rs8
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-transitive.rs25
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-xc.rs27
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-capabilities.rs21
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.rs14
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.stderr37
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.rs16
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr24
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata2.rs23
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-phantom-typaram.rs18
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-self-type.rs17
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr19
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-simple.rs9
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-simple.stderr16
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-simple2.rs10
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.rs8
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.stderr19
-rw-r--r--src/test/ui/builtin-superkinds/builtin-superkinds-typaram.rs11
18 files changed, 322 insertions, 0 deletions
diff --git a/src/test/ui/builtin-superkinds/auxiliary/trait_superkinds_in_metadata.rs b/src/test/ui/builtin-superkinds/auxiliary/trait_superkinds_in_metadata.rs
new file mode 100644
index 000000000..acfd1e13e
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/auxiliary/trait_superkinds_in_metadata.rs
@@ -0,0 +1,8 @@
+// Test library crate for cross-crate usages of traits inheriting
+// from the builtin kinds. Mostly tests metadata correctness.
+
+#![crate_type="lib"]
+
+pub trait RequiresShare : Sync { }
+pub trait RequiresRequiresShareAndSend : RequiresShare + Send { }
+pub trait RequiresCopy : Copy { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-transitive.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-transitive.rs
new file mode 100644
index 000000000..1f997d371
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-transitive.rs
@@ -0,0 +1,25 @@
+// run-pass
+// Tests "transitivity" of super-builtin-kinds on traits. Here, if
+// we have a Foo, we know we have a Bar, and if we have a Bar, we
+// know we have a Send. So if we have a Foo we should know we have
+// a Send. Basically this just makes sure rustc is using
+// each_bound_trait_and_supertraits in type_contents correctly.
+
+
+use std::sync::mpsc::{channel, Sender};
+
+trait Bar : Send { }
+trait Foo : Bar { }
+
+impl <T: Send> Foo for T { }
+impl <T: Send> Bar for T { }
+
+fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
+ chan.send(val).unwrap();
+}
+
+pub fn main() {
+ let (tx, rx) = channel();
+ foo(31337, tx);
+ assert_eq!(rx.recv().unwrap(), 31337);
+}
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-xc.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-xc.rs
new file mode 100644
index 000000000..8416bb3a3
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities-xc.rs
@@ -0,0 +1,27 @@
+// run-pass
+// aux-build:trait_superkinds_in_metadata.rs
+
+// Tests "capabilities" granted by traits with super-builtin-kinds,
+// even when using them cross-crate.
+
+
+extern crate trait_superkinds_in_metadata;
+
+use std::sync::mpsc::{channel, Sender, Receiver};
+use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
+
+#[derive(PartialEq, Debug)]
+struct X<T>(T);
+
+impl <T: Sync> RequiresShare for X<T> { }
+impl <T: Sync+Send> RequiresRequiresShareAndSend for X<T> { }
+
+fn foo<T: RequiresRequiresShareAndSend + 'static>(val: T, chan: Sender<T>) {
+ chan.send(val).unwrap();
+}
+
+pub fn main() {
+ let (tx, rx): (Sender<X<isize>>, Receiver<X<isize>>) = channel();
+ foo(X(31337), tx);
+ assert_eq!(rx.recv().unwrap(), X(31337));
+}
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities.rs
new file mode 100644
index 000000000..e936f921a
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-capabilities.rs
@@ -0,0 +1,21 @@
+// run-pass
+// Tests "capabilities" granted by traits that inherit from super-
+// builtin-kinds, e.g., if a trait requires Send to implement, then
+// at usage site of that trait, we know we have the Send capability.
+
+
+use std::sync::mpsc::{channel, Sender, Receiver};
+
+trait Foo : Send { }
+
+impl <T: Send> Foo for T { }
+
+fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
+ chan.send(val).unwrap();
+}
+
+pub fn main() {
+ let (tx, rx): (Sender<isize>, Receiver<isize>) = channel();
+ foo(31337, tx);
+ assert_eq!(rx.recv().unwrap(), 31337);
+}
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.rs
new file mode 100644
index 000000000..e716489c2
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.rs
@@ -0,0 +1,14 @@
+// Test for traits that inherit from multiple builtin kinds at once,
+// testing that all such kinds must be present on implementing types.
+
+trait Foo : Send+Sync { }
+
+impl <T: Sync+'static> Foo for (T,) { }
+//~^ ERROR `T` cannot be sent between threads safely [E0277]
+
+impl <T: Send> Foo for (T,T) { }
+//~^ ERROR `T` cannot be shared between threads safely [E0277]
+
+impl <T: Send+Sync> Foo for (T,T,T) { } // (ok)
+
+fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.stderr
new file mode 100644
index 000000000..492316f00
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-double-superkind.stderr
@@ -0,0 +1,37 @@
+error[E0277]: `T` cannot be sent between threads safely
+ --> $DIR/builtin-superkinds-double-superkind.rs:6:24
+ |
+LL | impl <T: Sync+'static> Foo for (T,) { }
+ | ^^^ `T` cannot be sent between threads safely
+ |
+ = note: required because it appears within the type `(T,)`
+note: required by a bound in `Foo`
+ --> $DIR/builtin-superkinds-double-superkind.rs:4:13
+ |
+LL | trait Foo : Send+Sync { }
+ | ^^^^ required by this bound in `Foo`
+help: consider further restricting this bound
+ |
+LL | impl <T: Sync+'static + std::marker::Send> Foo for (T,) { }
+ | +++++++++++++++++++
+
+error[E0277]: `T` cannot be shared between threads safely
+ --> $DIR/builtin-superkinds-double-superkind.rs:9:16
+ |
+LL | impl <T: Send> Foo for (T,T) { }
+ | ^^^ `T` cannot be shared between threads safely
+ |
+ = note: required because it appears within the type `(T, T)`
+note: required by a bound in `Foo`
+ --> $DIR/builtin-superkinds-double-superkind.rs:4:18
+ |
+LL | trait Foo : Send+Sync { }
+ | ^^^^ required by this bound in `Foo`
+help: consider further restricting this bound
+ |
+LL | impl <T: Send + std::marker::Sync> Foo for (T,T) { }
+ | +++++++++++++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.rs
new file mode 100644
index 000000000..b4555a180
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.rs
@@ -0,0 +1,16 @@
+// aux-build:trait_superkinds_in_metadata.rs
+
+// Test for traits inheriting from the builtin kinds cross-crate.
+// Mostly tests correctness of metadata.
+
+extern crate trait_superkinds_in_metadata;
+use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
+
+struct X<T>(T);
+
+impl <T:Sync> RequiresShare for X<T> { }
+
+impl <T:Sync+'static> RequiresRequiresShareAndSend for X<T> { }
+//~^ ERROR `T` cannot be sent between threads safely [E0277]
+
+fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr
new file mode 100644
index 000000000..a46e4b233
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr
@@ -0,0 +1,24 @@
+error[E0277]: `T` cannot be sent between threads safely
+ --> $DIR/builtin-superkinds-in-metadata.rs:13:23
+ |
+LL | impl <T:Sync+'static> RequiresRequiresShareAndSend for X<T> { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be sent between threads safely
+ |
+note: required because it appears within the type `X<T>`
+ --> $DIR/builtin-superkinds-in-metadata.rs:9:8
+ |
+LL | struct X<T>(T);
+ | ^
+note: required by a bound in `RequiresRequiresShareAndSend`
+ --> $DIR/auxiliary/trait_superkinds_in_metadata.rs:7:58
+ |
+LL | pub trait RequiresRequiresShareAndSend : RequiresShare + Send { }
+ | ^^^^ required by this bound in `RequiresRequiresShareAndSend`
+help: consider further restricting this bound
+ |
+LL | impl <T:Sync+'static + std::marker::Send> RequiresRequiresShareAndSend for X<T> { }
+ | +++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata2.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata2.rs
new file mode 100644
index 000000000..cdde48871
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-in-metadata2.rs
@@ -0,0 +1,23 @@
+// run-pass
+
+#![allow(unused_imports)]
+
+// aux-build:trait_superkinds_in_metadata.rs
+
+// Tests (correct) usage of trait super-builtin-kinds cross-crate.
+
+extern crate trait_superkinds_in_metadata;
+use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
+use trait_superkinds_in_metadata::RequiresCopy;
+use std::marker;
+
+#[derive(Copy, Clone)]
+struct X<T>(#[allow(unused_tuple_struct_fields)] T);
+
+impl<T:Sync> RequiresShare for X<T> { }
+
+impl<T:Sync+Send> RequiresRequiresShareAndSend for X<T> { }
+
+impl<T:Copy> RequiresCopy for X<T> { }
+
+pub fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-phantom-typaram.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-phantom-typaram.rs
new file mode 100644
index 000000000..9b80664b0
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-phantom-typaram.rs
@@ -0,0 +1,18 @@
+// run-pass
+
+#![allow(dead_code)]
+// Tests that even when a type parameter doesn't implement a required
+// super-builtin-kind of a trait, if the type parameter is never used,
+// the type can implement the trait anyway.
+
+// pretty-expanded FIXME #23616
+
+use std::marker;
+
+trait Foo : Send { }
+
+struct X<T> { marker: marker::PhantomData<T> }
+
+impl<T:Send> Foo for X<T> { }
+
+pub fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.rs
new file mode 100644
index 000000000..6fba87b31
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.rs
@@ -0,0 +1,17 @@
+// Tests (negatively) the ability for the Self type in default methods
+// to use capabilities granted by builtin kinds as supertraits.
+
+use std::sync::mpsc::{channel, Sender};
+
+trait Foo : Sized+Sync+'static {
+ fn foo(self, mut chan: Sender<Self>) { }
+}
+
+impl <T: Sync> Foo for T { }
+//~^ ERROR the parameter type `T` may not live long enough
+
+fn main() {
+ let (tx, rx) = channel();
+ 1193182.foo(tx);
+ assert_eq!(rx.recv(), 1193182);
+}
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr
new file mode 100644
index 000000000..e2b177b95
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr
@@ -0,0 +1,19 @@
+error[E0310]: the parameter type `T` may not live long enough
+ --> $DIR/builtin-superkinds-self-type.rs:10:16
+ |
+LL | impl <T: Sync> Foo for T { }
+ | ^^^ ...so that the type `T` will meet its required lifetime bounds...
+ |
+note: ...that is required by this bound
+ --> $DIR/builtin-superkinds-self-type.rs:6:24
+ |
+LL | trait Foo : Sized+Sync+'static {
+ | ^^^^^^^
+help: consider adding an explicit lifetime bound...
+ |
+LL | impl <T: Sync + 'static> Foo for T { }
+ | +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0310`.
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-simple.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-simple.rs
new file mode 100644
index 000000000..1620f8d5c
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-simple.rs
@@ -0,0 +1,9 @@
+// Basic test for traits inheriting from the builtin kinds, checking
+// the type contents of the implementing type (that's not a typaram).
+
+trait Foo : Send { }
+
+impl Foo for std::rc::Rc<i8> { }
+//~^ ERROR `Rc<i8>` cannot be sent between threads safely
+
+fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-simple.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-simple.stderr
new file mode 100644
index 000000000..9db9cbfdb
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-simple.stderr
@@ -0,0 +1,16 @@
+error[E0277]: `Rc<i8>` cannot be sent between threads safely
+ --> $DIR/builtin-superkinds-simple.rs:6:6
+ |
+LL | impl Foo for std::rc::Rc<i8> { }
+ | ^^^ `Rc<i8>` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `Rc<i8>`
+note: required by a bound in `Foo`
+ --> $DIR/builtin-superkinds-simple.rs:4:13
+ |
+LL | trait Foo : Send { }
+ | ^^^^ required by this bound in `Foo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-simple2.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-simple2.rs
new file mode 100644
index 000000000..8d2477157
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-simple2.rs
@@ -0,0 +1,10 @@
+// run-pass
+// Simple test case of implementing a trait with super-builtin-kinds.
+
+// pretty-expanded FIXME #23616
+
+trait Foo : Send { }
+
+impl Foo for isize { }
+
+pub fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.rs
new file mode 100644
index 000000000..74ae62711
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.rs
@@ -0,0 +1,8 @@
+// Basic test for traits inheriting from the builtin kinds.
+
+trait Foo : Send { }
+
+impl <T: Sync+'static> Foo for T { }
+//~^ ERROR `T` cannot be sent between threads safely
+
+fn main() { }
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.stderr
new file mode 100644
index 000000000..3ec0b907d
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram-not-send.stderr
@@ -0,0 +1,19 @@
+error[E0277]: `T` cannot be sent between threads safely
+ --> $DIR/builtin-superkinds-typaram-not-send.rs:5:24
+ |
+LL | impl <T: Sync+'static> Foo for T { }
+ | ^^^ `T` cannot be sent between threads safely
+ |
+note: required by a bound in `Foo`
+ --> $DIR/builtin-superkinds-typaram-not-send.rs:3:13
+ |
+LL | trait Foo : Send { }
+ | ^^^^ required by this bound in `Foo`
+help: consider further restricting this bound
+ |
+LL | impl <T: Sync+'static + std::marker::Send> Foo for T { }
+ | +++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-typaram.rs b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram.rs
new file mode 100644
index 000000000..f999dfff7
--- /dev/null
+++ b/src/test/ui/builtin-superkinds/builtin-superkinds-typaram.rs
@@ -0,0 +1,11 @@
+// run-pass
+// Tests correct implementation of traits with super-builtin-kinds
+// using a bounded type parameter.
+
+// pretty-expanded FIXME #23616
+
+trait Foo : Send { }
+
+impl <T: Send> Foo for T { }
+
+pub fn main() { }