about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix Chapman <aelred717@gmail.com>2018-12-10 14:44:16 +0000
committerFelix Chapman <aelred717@gmail.com>2018-12-10 14:45:18 +0000
commita336228760389b5ef01390f1c90a029dc44a0dc1 (patch)
treeff0ac1944167496b5aa16c8f6f6e63e87e925b3d
parentb755501043d5b27b39f94bcadd57c8d5dedfd6ba (diff)
downloadrust-a336228760389b5ef01390f1c90a029dc44a0dc1.tar.gz
rust-a336228760389b5ef01390f1c90a029dc44a0dc1.zip
Add test to check library traits have #[must_use] attribute
-rw-r--r--src/test/compile-fail/must_use-in-stdlib-traits.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/compile-fail/must_use-in-stdlib-traits.rs b/src/test/compile-fail/must_use-in-stdlib-traits.rs
new file mode 100644
index 00000000000..ddbe8071e4c
--- /dev/null
+++ b/src/test/compile-fail/must_use-in-stdlib-traits.rs
@@ -0,0 +1,47 @@
+#![deny(unused_must_use)]
+#![feature(futures_api, pin, arbitrary_self_types)]
+
+use std::iter::Iterator;
+use std::future::Future;
+
+use std::task::{Poll, LocalWaker};
+use std::pin::Pin;
+use std::unimplemented;
+
+struct MyFuture;
+
+impl Future for MyFuture {
+   type Output = u32;
+
+   fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<u32> {
+      Poll::Pending
+   }
+}
+
+fn iterator() -> impl Iterator {
+   std::iter::empty::<u32>()
+}
+
+fn future() -> impl Future {
+   MyFuture
+}
+
+fn square_fn_once() -> impl FnOnce(u32) -> u32 {
+   |x| x * x
+}
+
+fn square_fn_mut() -> impl FnMut(u32) -> u32 {
+   |x| x * x
+}
+
+fn square_fn() -> impl Fn(u32) -> u32 {
+   |x| x * x
+}
+
+fn main() {
+   iterator(); //~ ERROR unused implementer of `std::iter::Iterator` that must be used
+   future(); //~ ERROR unused implementer of `std::future::Future` that must be used
+   square_fn_once(); //~ ERROR unused implementer of `std::ops::FnOnce` that must be used
+   square_fn_mut(); //~ ERROR unused implementer of `std::ops::FnMut` that must be used
+   square_fn(); //~ ERROR unused implementer of `std::ops::Fn` that must be used
+}
\ No newline at end of file