summaryrefslogtreecommitdiffstats
path: root/tests/ui/dropck
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/dropck')
-rw-r--r--tests/ui/dropck/explicit-drop-bounds.bad1.stderr35
-rw-r--r--tests/ui/dropck/explicit-drop-bounds.bad2.stderr35
-rw-r--r--tests/ui/dropck/explicit-drop-bounds.rs44
-rw-r--r--tests/ui/dropck/explicit-implied-outlives.bad1.stderr15
-rw-r--r--tests/ui/dropck/explicit-implied-outlives.bad2.stderr15
-rw-r--r--tests/ui/dropck/explicit-implied-outlives.rs43
-rw-r--r--tests/ui/dropck/negative.rs7
-rw-r--r--tests/ui/dropck/negative.stderr8
-rw-r--r--tests/ui/dropck/reservation.rs10
-rw-r--r--tests/ui/dropck/reservation.stderr8
-rw-r--r--tests/ui/dropck/transitive-outlives-2.rs18
-rw-r--r--tests/ui/dropck/transitive-outlives.bad.stderr15
-rw-r--r--tests/ui/dropck/transitive-outlives.rs26
-rw-r--r--tests/ui/dropck/trivial-impl-bounds.rs34
14 files changed, 313 insertions, 0 deletions
diff --git a/tests/ui/dropck/explicit-drop-bounds.bad1.stderr b/tests/ui/dropck/explicit-drop-bounds.bad1.stderr
new file mode 100644
index 000000000..3b506c7e7
--- /dev/null
+++ b/tests/ui/dropck/explicit-drop-bounds.bad1.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/explicit-drop-bounds.rs:27:18
+ |
+LL | impl<T> Drop for DropMe<T>
+ | ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+ |
+note: required by a bound in `DropMe`
+ --> $DIR/explicit-drop-bounds.rs:7:18
+ |
+LL | struct DropMe<T: Copy>(T);
+ | ^^^^ required by this bound in `DropMe`
+help: consider further restricting type parameter `T`
+ |
+LL | [T; 1]: Copy, T: std::marker::Copy // But `[T; 1]: Copy` does not imply `T: Copy`
+ | ~~~~~~~~~~~~~~~~~~~~~~
+
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/explicit-drop-bounds.rs:32:13
+ |
+LL | fn drop(&mut self) {}
+ | ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+ |
+note: required by a bound in `DropMe`
+ --> $DIR/explicit-drop-bounds.rs:7:18
+ |
+LL | struct DropMe<T: Copy>(T);
+ | ^^^^ required by this bound in `DropMe`
+help: consider further restricting type parameter `T`
+ |
+LL | [T; 1]: Copy, T: std::marker::Copy // But `[T; 1]: Copy` does not imply `T: Copy`
+ | ~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dropck/explicit-drop-bounds.bad2.stderr b/tests/ui/dropck/explicit-drop-bounds.bad2.stderr
new file mode 100644
index 000000000..832af3e52
--- /dev/null
+++ b/tests/ui/dropck/explicit-drop-bounds.bad2.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/explicit-drop-bounds.rs:37:18
+ |
+LL | impl<T> Drop for DropMe<T>
+ | ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+ |
+note: required by a bound in `DropMe`
+ --> $DIR/explicit-drop-bounds.rs:7:18
+ |
+LL | struct DropMe<T: Copy>(T);
+ | ^^^^ required by this bound in `DropMe`
+help: consider restricting type parameter `T`
+ |
+LL | impl<T: std::marker::Copy> Drop for DropMe<T>
+ | +++++++++++++++++++
+
+error[E0277]: the trait bound `T: Copy` is not satisfied
+ --> $DIR/explicit-drop-bounds.rs:40:13
+ |
+LL | fn drop(&mut self) {}
+ | ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+ |
+note: required by a bound in `DropMe`
+ --> $DIR/explicit-drop-bounds.rs:7:18
+ |
+LL | struct DropMe<T: Copy>(T);
+ | ^^^^ required by this bound in `DropMe`
+help: consider restricting type parameter `T`
+ |
+LL | impl<T: std::marker::Copy> Drop for DropMe<T>
+ | +++++++++++++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/dropck/explicit-drop-bounds.rs b/tests/ui/dropck/explicit-drop-bounds.rs
new file mode 100644
index 000000000..ab6f33c09
--- /dev/null
+++ b/tests/ui/dropck/explicit-drop-bounds.rs
@@ -0,0 +1,44 @@
+// revisions: good1 good2 bad1 bad2
+//[good1] check-pass
+//[good2] check-pass
+
+use std::ops::Drop;
+
+struct DropMe<T: Copy>(T);
+
+#[cfg(good1)]
+impl<T> Drop for DropMe<T>
+where
+ T: Copy + Clone,
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(good2)]
+impl<T> Drop for DropMe<T>
+where
+ T: Copy,
+ [T; 1]: Copy, // Trivial bound implied by `T: Copy`
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(bad1)]
+impl<T> Drop for DropMe<T>
+//[bad1]~^ ERROR the trait bound `T: Copy` is not satisfied
+where
+ [T; 1]: Copy, // But `[T; 1]: Copy` does not imply `T: Copy`
+{
+ fn drop(&mut self) {}
+ //[bad1]~^ ERROR the trait bound `T: Copy` is not satisfied
+}
+
+#[cfg(bad2)]
+impl<T> Drop for DropMe<T>
+//[bad2]~^ ERROR the trait bound `T: Copy` is not satisfied
+{
+ fn drop(&mut self) {}
+ //[bad2]~^ ERROR the trait bound `T: Copy` is not satisfied
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/explicit-implied-outlives.bad1.stderr b/tests/ui/dropck/explicit-implied-outlives.bad1.stderr
new file mode 100644
index 000000000..bf6d70e7d
--- /dev/null
+++ b/tests/ui/dropck/explicit-implied-outlives.bad1.stderr
@@ -0,0 +1,15 @@
+error[E0367]: `Drop` impl requires `T: 'static` but the struct it is implemented for does not
+ --> $DIR/explicit-implied-outlives.rs:28:8
+ |
+LL | T: 'static,
+ | ^^^^^^^
+ |
+note: the implementor must specify the same requirement
+ --> $DIR/explicit-implied-outlives.rs:7:1
+ |
+LL | struct DropMe<'a, T>(&'a T);
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0367`.
diff --git a/tests/ui/dropck/explicit-implied-outlives.bad2.stderr b/tests/ui/dropck/explicit-implied-outlives.bad2.stderr
new file mode 100644
index 000000000..27a15170b
--- /dev/null
+++ b/tests/ui/dropck/explicit-implied-outlives.bad2.stderr
@@ -0,0 +1,15 @@
+error[E0367]: `Drop` impl requires `'a: 'static` but the struct it is implemented for does not
+ --> $DIR/explicit-implied-outlives.rs:37:9
+ |
+LL | 'a: 'static,
+ | ^^^^^^^
+ |
+note: the implementor must specify the same requirement
+ --> $DIR/explicit-implied-outlives.rs:7:1
+ |
+LL | struct DropMe<'a, T>(&'a T);
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0367`.
diff --git a/tests/ui/dropck/explicit-implied-outlives.rs b/tests/ui/dropck/explicit-implied-outlives.rs
new file mode 100644
index 000000000..fa446591f
--- /dev/null
+++ b/tests/ui/dropck/explicit-implied-outlives.rs
@@ -0,0 +1,43 @@
+// revisions: good1 good2 bad1 bad2
+//[good1] check-pass
+//[good2] check-pass
+
+use std::ops::Drop;
+
+struct DropMe<'a, T>(&'a T);
+
+#[cfg(good1)]
+impl<'a, T> Drop for DropMe<'a, T>
+where
+ T: 'a, // Implied by struct, explicit on impl
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(good2)]
+impl<'a, T> Drop for DropMe<'a, T>
+where
+ 'static: 'a, // Trivial bound
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(bad1)]
+impl<'a, T> Drop for DropMe<'a, T>
+where
+ T: 'static,
+ //[bad1]~^ ERROR `Drop` impl requires `T: 'static`
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(bad2)]
+impl<'a, T> Drop for DropMe<'a, T>
+where
+ 'a: 'static,
+ //[bad2]~^ ERROR `Drop` impl requires `'a: 'static`
+{
+ fn drop(&mut self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/negative.rs b/tests/ui/dropck/negative.rs
new file mode 100644
index 000000000..ae63632b5
--- /dev/null
+++ b/tests/ui/dropck/negative.rs
@@ -0,0 +1,7 @@
+#![feature(negative_impls)]
+
+struct NonDrop;
+impl !Drop for NonDrop {}
+//~^ ERROR negative `Drop` impls are not supported
+
+fn main() {}
diff --git a/tests/ui/dropck/negative.stderr b/tests/ui/dropck/negative.stderr
new file mode 100644
index 000000000..d613e30b5
--- /dev/null
+++ b/tests/ui/dropck/negative.stderr
@@ -0,0 +1,8 @@
+error: negative `Drop` impls are not supported
+ --> $DIR/negative.rs:4:1
+ |
+LL | impl !Drop for NonDrop {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/dropck/reservation.rs b/tests/ui/dropck/reservation.rs
new file mode 100644
index 000000000..f7199d4ec
--- /dev/null
+++ b/tests/ui/dropck/reservation.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+struct ReservedDrop;
+#[rustc_reservation_impl = "message"]
+impl Drop for ReservedDrop {
+//~^ ERROR reservation `Drop` impls are not supported
+ fn drop(&mut self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/reservation.stderr b/tests/ui/dropck/reservation.stderr
new file mode 100644
index 000000000..19325d6ed
--- /dev/null
+++ b/tests/ui/dropck/reservation.stderr
@@ -0,0 +1,8 @@
+error: reservation `Drop` impls are not supported
+ --> $DIR/reservation.rs:5:1
+ |
+LL | impl Drop for ReservedDrop {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/dropck/transitive-outlives-2.rs b/tests/ui/dropck/transitive-outlives-2.rs
new file mode 100644
index 000000000..87154e25d
--- /dev/null
+++ b/tests/ui/dropck/transitive-outlives-2.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+use std::marker::PhantomData;
+use std::ops::Drop;
+
+// a >= b >= c >= a implies a = b = c
+struct DropMe<'a: 'b, 'b: 'c, 'c: 'a>(
+ PhantomData<&'a ()>,
+ PhantomData<&'b ()>,
+ PhantomData<&'c ()>,
+);
+
+// a >= b, a >= c, b >= a, c >= a implies a = b = c
+impl<'a: 'b + 'c, 'b: 'a, 'c: 'a> Drop for DropMe<'a, 'b, 'c> {
+ fn drop(&mut self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/transitive-outlives.bad.stderr b/tests/ui/dropck/transitive-outlives.bad.stderr
new file mode 100644
index 000000000..da5088b27
--- /dev/null
+++ b/tests/ui/dropck/transitive-outlives.bad.stderr
@@ -0,0 +1,15 @@
+error[E0367]: `Drop` impl requires `'a: 'c` but the struct it is implemented for does not
+ --> $DIR/transitive-outlives.rs:20:9
+ |
+LL | 'a: 'c,
+ | ^^
+ |
+note: the implementor must specify the same requirement
+ --> $DIR/transitive-outlives.rs:7:1
+ |
+LL | struct DropMe<'a, 'b: 'a, 'c: 'b>(PhantomData<&'a ()>, PhantomData<&'b ()>, PhantomData<&'c ()>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0367`.
diff --git a/tests/ui/dropck/transitive-outlives.rs b/tests/ui/dropck/transitive-outlives.rs
new file mode 100644
index 000000000..d071664ab
--- /dev/null
+++ b/tests/ui/dropck/transitive-outlives.rs
@@ -0,0 +1,26 @@
+// revisions: good bad
+//[good] check-pass
+
+use std::marker::PhantomData;
+use std::ops::Drop;
+
+struct DropMe<'a, 'b: 'a, 'c: 'b>(PhantomData<&'a ()>, PhantomData<&'b ()>, PhantomData<&'c ()>);
+
+#[cfg(good)]
+impl<'a, 'b, 'c> Drop for DropMe<'a, 'b, 'c>
+where
+ 'c: 'a,
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(bad)]
+impl<'a, 'b, 'c> Drop for DropMe<'a, 'b, 'c>
+where
+ 'a: 'c,
+ //[bad]~^ ERROR `Drop` impl requires `'a: 'c`
+{
+ fn drop(&mut self) {}
+}
+
+fn main() {}
diff --git a/tests/ui/dropck/trivial-impl-bounds.rs b/tests/ui/dropck/trivial-impl-bounds.rs
new file mode 100644
index 000000000..a8f5d2c35
--- /dev/null
+++ b/tests/ui/dropck/trivial-impl-bounds.rs
@@ -0,0 +1,34 @@
+// revisions: good1 good2 good3
+// check-pass
+
+use std::ops::Drop;
+
+struct Foo;
+
+const X: usize = 1;
+
+#[cfg(good1)]
+impl Drop for Foo
+where
+ [(); X]:, // Trivial WF bound
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(good2)]
+impl Drop for Foo
+where
+ for<'a> &'a (): Copy, // Trivial trait bound
+{
+ fn drop(&mut self) {}
+}
+
+#[cfg(good3)]
+impl Drop for Foo
+where
+ for<'a> &'a (): 'a, // Trivial outlives bound
+{
+ fn drop(&mut self) {}
+}
+
+fn main() {}