File tree 4 files changed +52
-0
lines changed
4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ use task::{Poll, LocalWaker};
33
33
///
34
34
/// When using a future, you generally won't call `poll` directly, but instead
35
35
/// `await!` the value.
36
+ #[ must_use]
36
37
pub trait Future {
37
38
/// The result of the `Future`.
38
39
type Output ;
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
98
98
message="`{Self}` is not an iterator"
99
99
) ]
100
100
#[ doc( spotlight) ]
101
+ #[ must_use]
101
102
pub trait Iterator {
102
103
/// The type of the elements being iterated over.
103
104
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change 72
72
label="expected an `Fn<{Args}>` closure, found `{Self}`" ,
73
73
) ]
74
74
#[ fundamental] // so that regex can rely that `&str: !FnMut`
75
+ #[ must_use]
75
76
pub trait Fn < Args > : FnMut < Args > {
76
77
/// Performs the call operation.
77
78
#[ unstable( feature = "fn_traits" , issue = "29625" ) ]
@@ -150,6 +151,7 @@ pub trait Fn<Args> : FnMut<Args> {
150
151
label="expected an `FnMut<{Args}>` closure, found `{Self}`" ,
151
152
) ]
152
153
#[ fundamental] // so that regex can rely that `&str: !FnMut`
154
+ #[ must_use]
153
155
pub trait FnMut < Args > : FnOnce < Args > {
154
156
/// Performs the call operation.
155
157
#[ unstable( feature = "fn_traits" , issue = "29625" ) ]
@@ -228,6 +230,7 @@ pub trait FnMut<Args> : FnOnce<Args> {
228
230
label="expected an `FnOnce<{Args}>` closure, found `{Self}`" ,
229
231
) ]
230
232
#[ fundamental] // so that regex can rely that `&str: !FnMut`
233
+ #[ must_use]
231
234
pub trait FnOnce < Args > {
232
235
/// The returned type after the call operator is used.
233
236
#[ stable( feature = "fn_once_output" , since = "1.12.0" ) ]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments