Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e3a40dd

Browse files
authoredJun 4, 2022
Rollup merge of rust-lang#97715 - xFrednet:97650-expect-in-fuction-arg, r=wesleywiser
Support the `#[expect]` attribute on fn parameters (RFC-2383) A small PR to allow the `#[expect]` attribute on function parameters. Nothing more to say, I hope everyone reading this has a lovely day. --- r? `@wesleywiser` closes: rust-lang#97650 cc: rust-lang#85549
2 parents a354a8f + b5eee17 commit e3a40dd

File tree

8 files changed

+78
-45
lines changed

8 files changed

+78
-45
lines changed
 

‎compiler/rustc_ast_passes/src/ast_validation.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,15 @@ impl<'a> AstValidator<'a> {
420420
.iter()
421421
.flat_map(|i| i.attrs.as_ref())
422422
.filter(|attr| {
423-
let arr = [sym::allow, sym::cfg, sym::cfg_attr, sym::deny, sym::forbid, sym::warn];
423+
let arr = [
424+
sym::allow,
425+
sym::cfg,
426+
sym::cfg_attr,
427+
sym::deny,
428+
sym::expect,
429+
sym::forbid,
430+
sym::warn,
431+
];
424432
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(attr)
425433
})
426434
.for_each(|attr| {
@@ -435,7 +443,7 @@ impl<'a> AstValidator<'a> {
435443
} else {
436444
self.err_handler().span_err(
437445
attr.span,
438-
"allow, cfg, cfg_attr, deny, \
446+
"allow, cfg, cfg_attr, deny, expect, \
439447
forbid, and warn are the only allowed built-in attributes in function parameters",
440448
);
441449
}

‎src/test/ui/attributes/attrs-on-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fn function(#[inline] param: u32) {
44
//~^ ERROR attribute should be applied to function or closure
5-
//~| ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes
5+
//~| ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes
66
}
77

88
fn main() {}

‎src/test/ui/attributes/attrs-on-params.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
1+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
22
--> $DIR/attrs-on-params.rs:3:13
33
|
44
LL | fn function(#[inline] param: u32) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
#![feature(lint_reasons)]
3+
4+
#[warn(unused_variables)]
5+
6+
/// This should catch the unused_variables lint and not emit anything
7+
fn check_fulfilled_expectation(#[expect(unused_variables)] unused_value: u32) {}
8+
9+
fn check_unfulfilled_expectation(#[expect(unused_variables)] used_value: u32) {
10+
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
11+
//~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default
12+
println!("I use the value {used_value}");
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: this lint expectation is unfulfilled
2+
--> $DIR/expect_on_fn_params.rs:9:43
3+
|
4+
LL | fn check_unfulfilled_expectation(#[expect(unused_variables)] used_value: u32) {
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
8+
9+
warning: 1 warning emitted
10+

‎src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ extern "C" {
77
/// Bar
88
//~^ ERROR documentation comments cannot be applied to function
99
#[must_use]
10-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
10+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
1111
/// Baz
1212
//~^ ERROR documentation comments cannot be applied to function
1313
#[no_mangle] b: i32,
14-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
14+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
1515
);
1616
}
1717

@@ -23,11 +23,11 @@ type FnType = fn(
2323
/// Bar
2424
//~^ ERROR documentation comments cannot be applied to function
2525
#[must_use]
26-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
26+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
2727
/// Baz
2828
//~^ ERROR documentation comments cannot be applied to function
2929
#[no_mangle] b: i32,
30-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
30+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
3131
);
3232

3333
pub fn foo(
@@ -38,11 +38,11 @@ pub fn foo(
3838
/// Bar
3939
//~^ ERROR documentation comments cannot be applied to function
4040
#[must_use]
41-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
41+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
4242
/// Baz
4343
//~^ ERROR documentation comments cannot be applied to function
4444
#[no_mangle] b: i32,
45-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
45+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
4646
) {}
4747

4848
struct SelfStruct {}
@@ -58,11 +58,11 @@ impl SelfStruct {
5858
/// Baz
5959
//~^ ERROR documentation comments cannot be applied to function
6060
#[must_use]
61-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
61+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
6262
/// Qux
6363
//~^ ERROR documentation comments cannot be applied to function
6464
#[no_mangle] b: i32,
65-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
65+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
6666
) {}
6767

6868
fn issue_64682_associated_fn(
@@ -73,11 +73,11 @@ impl SelfStruct {
7373
/// Baz
7474
//~^ ERROR documentation comments cannot be applied to function
7575
#[must_use]
76-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
76+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
7777
/// Qux
7878
//~^ ERROR documentation comments cannot be applied to function
7979
#[no_mangle] b: i32,
80-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
80+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
8181
) {}
8282
}
8383

@@ -94,11 +94,11 @@ impl RefStruct {
9494
/// Baz
9595
//~^ ERROR documentation comments cannot be applied to function
9696
#[must_use]
97-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
97+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
9898
/// Qux
9999
//~^ ERROR documentation comments cannot be applied to function
100100
#[no_mangle] b: i32,
101-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
101+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
102102
) {}
103103
}
104104
trait RefTrait {
@@ -113,11 +113,11 @@ trait RefTrait {
113113
/// Baz
114114
//~^ ERROR documentation comments cannot be applied to function
115115
#[must_use]
116-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
116+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
117117
/// Qux
118118
//~^ ERROR documentation comments cannot be applied to function
119119
#[no_mangle] b: i32,
120-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
120+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
121121
) {}
122122

123123
fn issue_64682_associated_fn(
@@ -128,11 +128,11 @@ trait RefTrait {
128128
/// Baz
129129
//~^ ERROR documentation comments cannot be applied to function
130130
#[must_use]
131-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
131+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
132132
/// Qux
133133
//~^ ERROR documentation comments cannot be applied to function
134134
#[no_mangle] b: i32,
135-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
135+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
136136
) {}
137137
}
138138

@@ -148,11 +148,11 @@ impl RefTrait for RefStruct {
148148
/// Baz
149149
//~^ ERROR documentation comments cannot be applied to function
150150
#[must_use]
151-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
151+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
152152
/// Qux
153153
//~^ ERROR documentation comments cannot be applied to function
154154
#[no_mangle] b: i32,
155-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
155+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
156156
) {}
157157
}
158158

@@ -165,10 +165,10 @@ fn main() {
165165
/// Bar
166166
//~^ ERROR documentation comments cannot be applied to function
167167
#[must_use]
168-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
168+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
169169
/// Baz
170170
//~^ ERROR documentation comments cannot be applied to function
171171
#[no_mangle] b: i32
172-
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
172+
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
173173
| {};
174174
}

‎src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ error: documentation comments cannot be applied to function parameters
7070
LL | /// Bar
7171
| ^^^^^^^ doc comments are not allowed here
7272

73-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
73+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
7474
--> $DIR/param-attrs-builtin-attrs.rs:9:9
7575
|
7676
LL | #[must_use]
@@ -82,7 +82,7 @@ error: documentation comments cannot be applied to function parameters
8282
LL | /// Baz
8383
| ^^^^^^^ doc comments are not allowed here
8484

85-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
85+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
8686
--> $DIR/param-attrs-builtin-attrs.rs:13:9
8787
|
8888
LL | #[no_mangle] b: i32,
@@ -100,7 +100,7 @@ error: documentation comments cannot be applied to function parameters
100100
LL | /// Bar
101101
| ^^^^^^^ doc comments are not allowed here
102102

103-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
103+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
104104
--> $DIR/param-attrs-builtin-attrs.rs:25:5
105105
|
106106
LL | #[must_use]
@@ -112,7 +112,7 @@ error: documentation comments cannot be applied to function parameters
112112
LL | /// Baz
113113
| ^^^^^^^ doc comments are not allowed here
114114

115-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
115+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
116116
--> $DIR/param-attrs-builtin-attrs.rs:29:5
117117
|
118118
LL | #[no_mangle] b: i32,
@@ -130,7 +130,7 @@ error: documentation comments cannot be applied to function parameters
130130
LL | /// Bar
131131
| ^^^^^^^ doc comments are not allowed here
132132

133-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
133+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
134134
--> $DIR/param-attrs-builtin-attrs.rs:40:5
135135
|
136136
LL | #[must_use]
@@ -142,7 +142,7 @@ error: documentation comments cannot be applied to function parameters
142142
LL | /// Baz
143143
| ^^^^^^^ doc comments are not allowed here
144144

145-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
145+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
146146
--> $DIR/param-attrs-builtin-attrs.rs:44:5
147147
|
148148
LL | #[no_mangle] b: i32,
@@ -166,7 +166,7 @@ error: documentation comments cannot be applied to function parameters
166166
LL | /// Baz
167167
| ^^^^^^^ doc comments are not allowed here
168168

169-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
169+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
170170
--> $DIR/param-attrs-builtin-attrs.rs:60:9
171171
|
172172
LL | #[must_use]
@@ -178,7 +178,7 @@ error: documentation comments cannot be applied to function parameters
178178
LL | /// Qux
179179
| ^^^^^^^ doc comments are not allowed here
180180

181-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
181+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
182182
--> $DIR/param-attrs-builtin-attrs.rs:64:9
183183
|
184184
LL | #[no_mangle] b: i32,
@@ -196,7 +196,7 @@ error: documentation comments cannot be applied to function parameters
196196
LL | /// Baz
197197
| ^^^^^^^ doc comments are not allowed here
198198

199-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
199+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
200200
--> $DIR/param-attrs-builtin-attrs.rs:75:9
201201
|
202202
LL | #[must_use]
@@ -208,7 +208,7 @@ error: documentation comments cannot be applied to function parameters
208208
LL | /// Qux
209209
| ^^^^^^^ doc comments are not allowed here
210210

211-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
211+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
212212
--> $DIR/param-attrs-builtin-attrs.rs:79:9
213213
|
214214
LL | #[no_mangle] b: i32,
@@ -232,7 +232,7 @@ error: documentation comments cannot be applied to function parameters
232232
LL | /// Baz
233233
| ^^^^^^^ doc comments are not allowed here
234234

235-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
235+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
236236
--> $DIR/param-attrs-builtin-attrs.rs:96:9
237237
|
238238
LL | #[must_use]
@@ -244,7 +244,7 @@ error: documentation comments cannot be applied to function parameters
244244
LL | /// Qux
245245
| ^^^^^^^ doc comments are not allowed here
246246

247-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
247+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
248248
--> $DIR/param-attrs-builtin-attrs.rs:100:9
249249
|
250250
LL | #[no_mangle] b: i32,
@@ -268,7 +268,7 @@ error: documentation comments cannot be applied to function parameters
268268
LL | /// Baz
269269
| ^^^^^^^ doc comments are not allowed here
270270

271-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
271+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
272272
--> $DIR/param-attrs-builtin-attrs.rs:115:9
273273
|
274274
LL | #[must_use]
@@ -280,7 +280,7 @@ error: documentation comments cannot be applied to function parameters
280280
LL | /// Qux
281281
| ^^^^^^^ doc comments are not allowed here
282282

283-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
283+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
284284
--> $DIR/param-attrs-builtin-attrs.rs:119:9
285285
|
286286
LL | #[no_mangle] b: i32,
@@ -298,7 +298,7 @@ error: documentation comments cannot be applied to function parameters
298298
LL | /// Baz
299299
| ^^^^^^^ doc comments are not allowed here
300300

301-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
301+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
302302
--> $DIR/param-attrs-builtin-attrs.rs:130:9
303303
|
304304
LL | #[must_use]
@@ -310,7 +310,7 @@ error: documentation comments cannot be applied to function parameters
310310
LL | /// Qux
311311
| ^^^^^^^ doc comments are not allowed here
312312

313-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
313+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
314314
--> $DIR/param-attrs-builtin-attrs.rs:134:9
315315
|
316316
LL | #[no_mangle] b: i32,
@@ -334,7 +334,7 @@ error: documentation comments cannot be applied to function parameters
334334
LL | /// Baz
335335
| ^^^^^^^ doc comments are not allowed here
336336

337-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
337+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
338338
--> $DIR/param-attrs-builtin-attrs.rs:150:9
339339
|
340340
LL | #[must_use]
@@ -346,7 +346,7 @@ error: documentation comments cannot be applied to function parameters
346346
LL | /// Qux
347347
| ^^^^^^^ doc comments are not allowed here
348348

349-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
349+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
350350
--> $DIR/param-attrs-builtin-attrs.rs:154:9
351351
|
352352
LL | #[no_mangle] b: i32,
@@ -364,7 +364,7 @@ error: documentation comments cannot be applied to function parameters
364364
LL | /// Bar
365365
| ^^^^^^^ doc comments are not allowed here
366366

367-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
367+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
368368
--> $DIR/param-attrs-builtin-attrs.rs:167:9
369369
|
370370
LL | #[must_use]
@@ -376,7 +376,7 @@ error: documentation comments cannot be applied to function parameters
376376
LL | /// Baz
377377
| ^^^^^^^ doc comments are not allowed here
378378

379-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
379+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
380380
--> $DIR/param-attrs-builtin-attrs.rs:171:9
381381
|
382382
LL | #[no_mangle] b: i32

‎src/test/ui/rustdoc/check-doc-alias-attr-location.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
1+
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
22
--> $DIR/check-doc-alias-attr-location.rs:22:12
33
|
44
LL | fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {

0 commit comments

Comments
 (0)
Please sign in to comment.