]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/must_use-trait.rs
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
[rust.git] / src / test / ui / lint / must_use-trait.rs
1 #![deny(unused_must_use)]
2
3 #[must_use]
4 trait Critical {}
5
6 trait NotSoCritical {}
7
8 trait DecidedlyUnimportant {}
9
10 struct Anon;
11
12 impl Critical for Anon {}
13 impl NotSoCritical for Anon {}
14 impl DecidedlyUnimportant for Anon {}
15
16 fn get_critical() -> impl NotSoCritical + Critical + DecidedlyUnimportant {
17     Anon {}
18 }
19
20 fn get_boxed_critical() -> Box<dyn Critical> {
21     Box::new(Anon {})
22 }
23
24 fn get_nested_boxed_critical() -> Box<Box<dyn Critical>> {
25     Box::new(Box::new(Anon {}))
26 }
27
28 fn get_critical_tuple() -> (u32, Box<dyn Critical>, impl Critical, ()) {
29     (0, get_boxed_critical(), get_critical(), ())
30 }
31
32 fn main() {
33     get_critical(); //~ ERROR unused implementer of `Critical` that must be used
34     get_boxed_critical(); //~ ERROR unused boxed `Critical` trait object that must be used
35     get_nested_boxed_critical();
36     //~^ ERROR unused boxed boxed `Critical` trait object that must be used
37     get_critical_tuple(); //~ ERROR unused boxed `Critical` trait object in tuple element 1
38     //~^ ERROR unused implementer of `Critical` in tuple element 2
39 }