Skip to content

Commit a336228

Browse files
committed
Add test to check library traits have #[must_use] attribute
1 parent b755501 commit a336228

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#![deny(unused_must_use)]
2+
#![feature(futures_api, pin, arbitrary_self_types)]
3+
4+
use std::iter::Iterator;
5+
use std::future::Future;
6+
7+
use std::task::{Poll, LocalWaker};
8+
use std::pin::Pin;
9+
use std::unimplemented;
10+
11+
struct MyFuture;
12+
13+
impl Future for MyFuture {
14+
type Output = u32;
15+
16+
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<u32> {
17+
Poll::Pending
18+
}
19+
}
20+
21+
fn iterator() -> impl Iterator {
22+
std::iter::empty::<u32>()
23+
}
24+
25+
fn future() -> impl Future {
26+
MyFuture
27+
}
28+
29+
fn square_fn_once() -> impl FnOnce(u32) -> u32 {
30+
|x| x * x
31+
}
32+
33+
fn square_fn_mut() -> impl FnMut(u32) -> u32 {
34+
|x| x * x
35+
}
36+
37+
fn square_fn() -> impl Fn(u32) -> u32 {
38+
|x| x * x
39+
}
40+
41+
fn main() {
42+
iterator(); //~ ERROR unused implementer of `std::iter::Iterator` that must be used
43+
future(); //~ ERROR unused implementer of `std::future::Future` that must be used
44+
square_fn_once(); //~ ERROR unused implementer of `std::ops::FnOnce` that must be used
45+
square_fn_mut(); //~ ERROR unused implementer of `std::ops::FnMut` that must be used
46+
square_fn(); //~ ERROR unused implementer of `std::ops::Fn` that must be used
47+
}

0 commit comments

Comments
 (0)