]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/unused/must_use-array.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / lint / unused / must_use-array.rs
1 #![deny(unused_must_use)]
2
3 #[must_use]
4 #[derive(Clone, Copy)]
5 struct S;
6
7 struct A;
8
9 #[must_use]
10 trait T {}
11
12 impl T for A {}
13
14 fn empty() -> [S; 0] {
15     []
16 }
17
18 fn singleton() -> [S; 1] {
19     [S]
20 }
21
22 fn many() -> [S; 4] {
23     [S, S, S, S]
24 }
25
26 fn array_of_impl_trait() -> [impl T; 2] {
27     [A, A]
28 }
29
30 fn impl_array() -> [(u8, Box<dyn T>); 2] {
31     [(0, Box::new(A)), (0, Box::new(A))]
32 }
33
34 fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] {
35     [[[S], [S]]]
36 }
37
38 fn usize_max() -> [S; usize::MAX] {
39     [S; usize::MAX]
40 }
41
42 fn main() {
43     empty(); // ok
44     singleton(); //~ ERROR unused array of `S` that must be used
45     many(); //~ ERROR unused array of `S` that must be used
46     ([S], 0, ()); //~ ERROR unused array of `S` in tuple element 0 that must be used
47     array_of_impl_trait(); //~ ERROR unused array of implementers of `T` that must be used
48     impl_array();
49     //~^ ERROR unused array of boxed `T` trait objects in tuple element 1 that must be used
50     array_of_arrays_of_arrays();
51     //~^ ERROR unused array of arrays of arrays of `S` that must be used
52     usize_max();
53     //~^ ERROR unused array of `S` that must be used
54 }