File: must_use-in-stdlib-traits.rs

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,517,036 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (47 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (24)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![deny(unused_must_use)]
#![feature(arbitrary_self_types)]

use std::iter::Iterator;
use std::future::Future;

use std::task::{Context, Poll};
use std::pin::Pin;
use std::unimplemented;

struct MyFuture;

impl Future for MyFuture {
   type Output = u32;

   fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> 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 `Iterator` that must be used
   future(); //~ ERROR unused implementer of `Future` that must be used
   square_fn_once(); //~ ERROR unused implementer of `FnOnce` that must be used
   square_fn_mut(); //~ ERROR unused implementer of `FnMut` that must be used
   square_fn(); //~ ERROR unused implementer of `Fn` that must be used
}