]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/must_use-array.rs
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
[rust.git] / src / test / ui / lint / must_use-array.rs
1 #![deny(unused_must_use)]
2
3 #[must_use]
4 struct S;
5
6 struct A;
7
8 #[must_use]
9 trait T {}
10
11 impl T for A {}
12
13 fn empty() -> [S; 0] {
14     []
15 }
16
17 fn singleton() -> [S; 1] {
18     [S]
19 }
20
21 fn many() -> [S; 4] {
22     [S, S, S, S]
23 }
24
25 fn array_of_impl_trait() -> [impl T; 2] {
26     [A, A]
27 }
28
29 fn impl_array() -> [(u8, Box<dyn T>); 2] {
30     [(0, Box::new(A)), (0, Box::new(A))]
31 }
32
33 fn array_of_arrays_of_arrays() -> [[[S; 1]; 2]; 1] {
34     [[[S], [S]]]
35 }
36
37 fn main() {
38     empty(); // ok
39     singleton(); //~ ERROR unused array of `S` that must be used
40     many(); //~ ERROR unused array of `S` that must be used
41     ([S], 0, ()); //~ ERROR unused array of `S` in tuple element 0 that must be used
42     array_of_impl_trait(); //~ ERROR unused array of implementers of `T` that must be used
43     impl_array();
44     //~^ ERROR unused array of boxed `T` trait objects in tuple element 1 that must be used
45     array_of_arrays_of_arrays();
46     //~^ ERROR unused array of arrays of arrays of `S` that must be used
47 }