]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/unused/unused_attributes-must_use.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / lint / unused / unused_attributes-must_use.rs
1 #![allow(dead_code, path_statements)]
2 #![deny(unused_attributes, unused_must_use)]
3 #![feature(asm_experimental_arch, stmt_expr_attributes, trait_alias)]
4
5 #[must_use] //~ ERROR `#[must_use]` has no effect
6 extern crate std as std2;
7
8 #[must_use] //~ ERROR `#[must_use]` has no effect
9 mod test_mod {}
10
11 #[must_use] //~ ERROR `#[must_use]` has no effect
12 use std::arch::global_asm;
13
14 #[must_use] //~ ERROR `#[must_use]` has no effect
15 const CONST: usize = 4;
16 #[must_use] //~ ERROR `#[must_use]` has no effect
17 #[no_mangle]
18 static STATIC: usize = 4;
19
20 #[must_use]
21 struct X;
22
23 #[must_use]
24 enum Y {
25     Z,
26 }
27
28 #[must_use]
29 union U {
30     unit: (),
31 }
32
33 #[must_use] //~ ERROR `#[must_use]` has no effect
34 impl U {
35     #[must_use]
36     fn method() -> i32 {
37         4
38     }
39 }
40
41 #[must_use]
42 #[no_mangle]
43 fn foo() -> i64 {
44     4
45 }
46
47 #[must_use] //~ ERROR `#[must_use]` has no effect
48 extern "Rust" {
49     #[link_name = "STATIC"]
50     #[must_use] //~ ERROR `#[must_use]` has no effect
51     static FOREIGN_STATIC: usize;
52
53     #[link_name = "foo"]
54     #[must_use]
55     fn foreign_foo() -> i64;
56 }
57
58 #[must_use] //~ ERROR unused attribute
59 global_asm!("");
60
61 #[must_use] //~ ERROR `#[must_use]` has no effect
62 type UseMe = ();
63
64 fn qux<#[must_use] T>(_: T) {} //~ ERROR `#[must_use]` has no effect
65
66 #[must_use]
67 trait Use {
68     #[must_use] //~ ERROR `#[must_use]` has no effect
69     const ASSOC_CONST: usize = 4;
70     #[must_use] //~ ERROR `#[must_use]` has no effect
71     type AssocTy;
72
73     #[must_use]
74     fn get_four(&self) -> usize {
75         4
76     }
77 }
78
79 #[must_use] //~ ERROR `#[must_use]` has no effect
80 impl Use for () {
81     type AssocTy = ();
82 }
83
84 #[must_use] //~ ERROR `#[must_use]` has no effect
85 trait Alias = Use;
86
87 #[must_use] //~ ERROR `#[must_use]` has no effect
88 macro_rules! cool_macro {
89     () => {
90         4
91     };
92 }
93
94 fn main() {
95     #[must_use] //~ ERROR `#[must_use]` has no effect
96     let x = || {};
97     x();
98
99     let x = #[must_use] //~ ERROR `#[must_use]` has no effect
100     || {};
101     x();
102
103     X; //~ ERROR that must be used
104     Y::Z; //~ ERROR that must be used
105     U { unit: () }; //~ ERROR that must be used
106     U::method(); //~ ERROR that must be used
107     foo(); //~ ERROR that must be used
108
109     unsafe {
110         foreign_foo(); //~ ERROR that must be used
111     };
112
113     CONST;
114     STATIC;
115     unsafe { FOREIGN_STATIC };
116     cool_macro!();
117     qux(4);
118     ().get_four(); //~ ERROR that must be used
119
120     match Some(4) {
121         #[must_use] //~ ERROR `#[must_use]` has no effect
122         Some(res) => res,
123         None => 0,
124     };
125
126     struct PatternField {
127         foo: i32,
128     }
129     let s = PatternField { #[must_use]  foo: 123 }; //~ ERROR `#[must_use]` has no effect
130     let PatternField { #[must_use] foo } = s; //~ ERROR `#[must_use]` has no effect
131 }