Skip to content

Commit ea04862

Browse files
committed
Add attrs on function/closure params
1 parent 33eb2d7 commit ea04862

File tree

5 files changed

+137
-35
lines changed

5 files changed

+137
-35
lines changed

tests/ui/attributes/positions/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ pub mod module {
152152
fn main() {
153153
let _closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental
154154
//~^ WARN
155-
| _arg: u32| {};
156-
155+
| #[ATTRIBUTE] _arg: u32| {}; //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
156+
//~^ ERROR
157157
let _move_closure = #[ATTRIBUTE] //~ ERROR attributes on expressions are experimental
158158
//~^ WARN
159-
move | _arg: u32| {};
160-
159+
move | #[ATTRIBUTE] _arg: u32| {}; //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
160+
//~^ ERROR
161161
#[ATTRIBUTE] //~ WARN
162162
{
163163
#![ATTRIBUTE] //~ WARN
@@ -236,8 +236,8 @@ unsafe extern "C" {
236236

237237
#[ATTRIBUTE] //~ WARN
238238
pub fn external_function(
239-
arg: *mut u8,
240-
...
239+
#[ATTRIBUTE] arg: *mut u8, //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
240+
#[ATTRIBUTE] ... //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
241241
);
242242

243243
#[ATTRIBUTE] //~ WARN
@@ -248,8 +248,8 @@ unsafe extern "C" {
248248
}
249249

250250
#[ATTRIBUTE] //~ WARN
251-
pub unsafe extern "C" fn abi_function(_: u32) {}
252-
251+
pub unsafe extern "C" fn abi_function(#[ATTRIBUTE] _: u32) {} //~ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
252+
//~^ ERROR
253253
#[ATTRIBUTE] //~ WARN
254254
#[macro_export]
255255
macro_rules! my_macro {

tests/ui/attributes/positions/must_use.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ pub mod module {
118118
fn main() {
119119
let _closure = #[must_use] //~ ERROR attributes on expressions are experimental
120120
//~^ WARN
121-
| _arg: u32| {};
122-
121+
| #[must_use] _arg: u32| {}; //~ ERROR
122+
//~^ WARN
123123
let _move_closure = #[must_use] //~ ERROR attributes on expressions are experimental
124124
//~^ WARN
125-
move | _arg: u32| {};
126-
125+
move | #[must_use] _arg: u32| {}; //~ ERROR
126+
//~^ WARN
127127
#[must_use] //~ WARN
128128
{
129129
#![must_use] //~ WARN
@@ -202,8 +202,8 @@ unsafe extern "C" {
202202

203203
#[must_use] // OK
204204
pub fn external_function(
205-
arg: *mut u8,
206-
...
205+
#[must_use] arg: *mut u8, //~ ERROR
206+
#[must_use] ... //~ ERROR
207207
);
208208

209209
#[must_use] //~ WARN
@@ -214,8 +214,8 @@ unsafe extern "C" {
214214
}
215215

216216
#[must_use] // OK
217-
pub unsafe extern "C" fn abi_function(_: u32) {}
218-
217+
pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {} //~ ERROR
218+
//~^ WARN
219219
#[must_use] //~ WARN
220220
#[macro_export]
221221
macro_rules! my_macro {

tests/ui/attributes/positions/must_use.stderr

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed
6060
LL | ... pub fn static_method(#[must_use] _arg: u32) {}
6161
| ^^^^^^^^^^^
6262

63+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
64+
--> $DIR/must_use.rs:121:7
65+
|
66+
LL | | #[must_use] _arg: u32| {};
67+
| ^^^^^^^^^^^
68+
69+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
70+
--> $DIR/must_use.rs:125:12
71+
|
72+
LL | move | #[must_use] _arg: u32| {};
73+
| ^^^^^^^^^^^
74+
75+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
76+
--> $DIR/must_use.rs:205:9
77+
|
78+
LL | #[must_use] arg: *mut u8,
79+
| ^^^^^^^^^^^
80+
81+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
82+
--> $DIR/must_use.rs:206:9
83+
|
84+
LL | #[must_use] ...
85+
| ^^^^^^^^^^^
86+
87+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
88+
--> $DIR/must_use.rs:217:39
89+
|
90+
LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {}
91+
| ^^^^^^^^^^^
92+
6393
error[E0658]: trait aliases are experimental
6494
--> $DIR/must_use.rs:35:5
6595
|
@@ -119,12 +149,24 @@ warning: `#[must_use]` has no effect when applied to a closure
119149
LL | let _closure = #[must_use]
120150
| ^^^^^^^^^^^
121151

152+
warning: `#[must_use]` has no effect when applied to a function param
153+
--> $DIR/must_use.rs:121:7
154+
|
155+
LL | | #[must_use] _arg: u32| {};
156+
| ^^^^^^^^^^^
157+
122158
warning: `#[must_use]` has no effect when applied to a closure
123159
--> $DIR/must_use.rs:123:25
124160
|
125161
LL | let _move_closure = #[must_use]
126162
| ^^^^^^^^^^^
127163

164+
warning: `#[must_use]` has no effect when applied to a function param
165+
--> $DIR/must_use.rs:125:12
166+
|
167+
LL | move | #[must_use] _arg: u32| {};
168+
| ^^^^^^^^^^^
169+
128170
warning: `#[must_use]` has no effect when applied to an expression
129171
--> $DIR/must_use.rs:127:5
130172
|
@@ -259,6 +301,12 @@ LL | #[must_use]
259301
| ^^^^^^^^^^^
260302
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
261303

304+
warning: `#[must_use]` has no effect when applied to a function param
305+
--> $DIR/must_use.rs:217:39
306+
|
307+
LL | pub unsafe extern "C" fn abi_function(#[must_use] _: u32) {}
308+
| ^^^^^^^^^^^
309+
262310
warning: `#[must_use]` has no effect when applied to a macro def
263311
--> $DIR/must_use.rs:219:1
264312
|
@@ -465,6 +513,6 @@ warning: `#[must_use]` has no effect when applied to a provided trait method
465513
LL | #[must_use]
466514
| ^^^^^^^^^^^
467515

468-
error: aborting due to 8 previous errors; 59 warnings emitted
516+
error: aborting due to 13 previous errors; 62 warnings emitted
469517

470518
For more information about this error, try `rustc --explain E0658`.

tests/ui/attributes/positions/no_link.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ pub mod module {
118118
fn main() {
119119
let _closure = #[no_link] //~ ERROR attributes on expressions are experimental
120120
//~^ ERROR
121-
| _arg: u32| {};
122-
121+
| #[no_link] _arg: u32| {}; //~ ERROR
122+
//~^ ERROR
123123
let _move_closure = #[no_link] //~ ERROR attributes on expressions are experimental
124124
//~^ ERROR
125-
move | _arg: u32| {};
126-
125+
move | #[no_link] _arg: u32| {}; //~ ERROR
126+
//~^ ERROR
127127
#[no_link] //~ ERROR
128128
{
129129
#![no_link] //~ ERROR
@@ -202,8 +202,8 @@ unsafe extern "C" {
202202

203203
#[no_link] //~ ERROR
204204
pub fn external_function(
205-
arg: *mut u8,
206-
...
205+
#[no_link] arg: *mut u8, //~ ERROR
206+
#[no_link] ... //~ ERROR
207207
);
208208

209209
#[no_link] //~ ERROR
@@ -214,8 +214,8 @@ unsafe extern "C" {
214214
}
215215

216216
#[no_link] //~ ERROR
217-
pub unsafe extern "C" fn abi_function(_: u32) {}
218-
217+
pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {} //~ ERROR
218+
//~^ ERROR
219219
#[no_link] //~ WARN
220220
#[macro_export]
221221
macro_rules! my_macro {

tests/ui/attributes/positions/no_link.stderr

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed
6060
LL | ... pub fn static_method(#[no_link] _arg: u32) {}
6161
| ^^^^^^^^^^
6262

63+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
64+
--> $DIR/no_link.rs:121:7
65+
|
66+
LL | | #[no_link] _arg: u32| {};
67+
| ^^^^^^^^^^
68+
69+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
70+
--> $DIR/no_link.rs:125:12
71+
|
72+
LL | move | #[no_link] _arg: u32| {};
73+
| ^^^^^^^^^^
74+
75+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
76+
--> $DIR/no_link.rs:205:9
77+
|
78+
LL | #[no_link] arg: *mut u8,
79+
| ^^^^^^^^^^
80+
81+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
82+
--> $DIR/no_link.rs:206:9
83+
|
84+
LL | #[no_link] ...
85+
| ^^^^^^^^^^
86+
87+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
88+
--> $DIR/no_link.rs:217:39
89+
|
90+
LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {}
91+
| ^^^^^^^^^^
92+
6393
error[E0658]: trait aliases are experimental
6494
--> $DIR/no_link.rs:35:5
6595
|
@@ -124,7 +154,7 @@ LL | #[no_link]
124154
LL | / fn main() {
125155
LL | | let _closure = #[no_link]
126156
LL | |
127-
LL | | | _arg: u32| {};
157+
LL | | | #[no_link] _arg: u32| {};
128158
... |
129159
LL | | }
130160
| |_- not an `extern crate` item
@@ -135,17 +165,33 @@ error: attribute should be applied to an `extern crate` item
135165
LL | let _closure = #[no_link]
136166
| ^^^^^^^^^^
137167
LL |
138-
LL | | _arg: u32| {};
139-
| --------------- not an `extern crate` item
168+
LL | | #[no_link] _arg: u32| {};
169+
| -------------------------- not an `extern crate` item
170+
171+
error: attribute should be applied to an `extern crate` item
172+
--> $DIR/no_link.rs:121:7
173+
|
174+
LL | | #[no_link] _arg: u32| {};
175+
| ^^^^^^^^^^----------
176+
| |
177+
| not an `extern crate` item
140178

141179
error: attribute should be applied to an `extern crate` item
142180
--> $DIR/no_link.rs:123:25
143181
|
144182
LL | let _move_closure = #[no_link]
145183
| ^^^^^^^^^^
146184
LL |
147-
LL | move | _arg: u32| {};
148-
| -------------------- not an `extern crate` item
185+
LL | move | #[no_link] _arg: u32| {};
186+
| ------------------------------- not an `extern crate` item
187+
188+
error: attribute should be applied to an `extern crate` item
189+
--> $DIR/no_link.rs:125:12
190+
|
191+
LL | move | #[no_link] _arg: u32| {};
192+
| ^^^^^^^^^^----------
193+
| |
194+
| not an `extern crate` item
149195

150196
error: attribute should be applied to an `extern crate` item
151197
--> $DIR/no_link.rs:127:5
@@ -347,8 +393,16 @@ error: attribute should be applied to an `extern crate` item
347393
|
348394
LL | #[no_link]
349395
| ^^^^^^^^^^
350-
LL | pub unsafe extern "C" fn abi_function(_: u32) {}
351-
| ------------------------------------------------ not an `extern crate` item
396+
LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {}
397+
| ----------------------------------------------------------- not an `extern crate` item
398+
399+
error: attribute should be applied to an `extern crate` item
400+
--> $DIR/no_link.rs:217:39
401+
|
402+
LL | pub unsafe extern "C" fn abi_function(#[no_link] _: u32) {}
403+
| ^^^^^^^^^^-------
404+
| |
405+
| not an `extern crate` item
352406

353407
warning: `#[no_link]` is ignored on struct fields, match arms and macro defs
354408
--> $DIR/no_link.rs:219:1
@@ -362,8 +416,8 @@ error: attribute should be applied to an `extern crate` item
362416
LL | #[no_link]
363417
| ^^^^^^^^^^
364418
LL | / pub fn external_function(
365-
LL | | arg: *mut u8,
366-
LL | | ...
419+
LL | | #[no_link] arg: *mut u8,
420+
LL | | #[no_link] ...
367421
LL | | );
368422
| |______- not an `extern crate` item
369423

@@ -725,6 +779,6 @@ LL | | // ..
725779
LL | | }
726780
| |_________- not an `extern crate` item
727781

728-
error: aborting due to 66 previous errors; 13 warnings emitted
782+
error: aborting due to 74 previous errors; 13 warnings emitted
729783

730784
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)