Skip to content

Commit

Permalink
Rollup merge of rust-lang#97715 - xFrednet:97650-expect-in-fuction-ar…
Browse files Browse the repository at this point in the history
…g, 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
  • Loading branch information
Dylan-DPC committed Jun 4, 2022
2 parents a354a8f + b5eee17 commit e3a40dd
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 45 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,15 @@ impl<'a> AstValidator<'a> {
.iter()
.flat_map(|i| i.attrs.as_ref())
.filter(|attr| {
let arr = [sym::allow, sym::cfg, sym::cfg_attr, sym::deny, sym::forbid, sym::warn];
let arr = [
sym::allow,
sym::cfg,
sym::cfg_attr,
sym::deny,
sym::expect,
sym::forbid,
sym::warn,
];
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(attr)
})
.for_each(|attr| {
Expand All @@ -435,7 +443,7 @@ impl<'a> AstValidator<'a> {
} else {
self.err_handler().span_err(
attr.span,
"allow, cfg, cfg_attr, deny, \
"allow, cfg, cfg_attr, deny, expect, \
forbid, and warn are the only allowed built-in attributes in function parameters",
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/attributes/attrs-on-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/attributes/attrs-on-params.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
--> $DIR/attrs-on-params.rs:3:13
|
LL | fn function(#[inline] param: u32) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// check-pass
#![feature(lint_reasons)]

#[warn(unused_variables)]

/// This should catch the unused_variables lint and not emit anything
fn check_fulfilled_expectation(#[expect(unused_variables)] unused_value: u32) {}

fn check_unfulfilled_expectation(#[expect(unused_variables)] used_value: u32) {
//~^ WARNING this lint expectation is unfulfilled [unfulfilled_lint_expectations]
//~| NOTE `#[warn(unfulfilled_lint_expectations)]` on by default
println!("I use the value {used_value}");
}

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: this lint expectation is unfulfilled
--> $DIR/expect_on_fn_params.rs:9:43
|
LL | fn check_unfulfilled_expectation(#[expect(unused_variables)] used_value: u32) {
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default

warning: 1 warning emitted

40 changes: 20 additions & 20 deletions src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ extern "C" {
/// Bar
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
);
}

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

pub fn foo(
Expand All @@ -38,11 +38,11 @@ pub fn foo(
/// Bar
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}

struct SelfStruct {}
Expand All @@ -58,11 +58,11 @@ impl SelfStruct {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}

fn issue_64682_associated_fn(
Expand All @@ -73,11 +73,11 @@ impl SelfStruct {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}
}

Expand All @@ -94,11 +94,11 @@ impl RefStruct {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}
}
trait RefTrait {
Expand All @@ -113,11 +113,11 @@ trait RefTrait {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}

fn issue_64682_associated_fn(
Expand All @@ -128,11 +128,11 @@ trait RefTrait {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}
}

Expand All @@ -148,11 +148,11 @@ impl RefTrait for RefStruct {
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Qux
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32,
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
) {}
}

Expand All @@ -165,10 +165,10 @@ fn main() {
/// Bar
//~^ ERROR documentation comments cannot be applied to function
#[must_use]
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
/// Baz
//~^ ERROR documentation comments cannot be applied to function
#[no_mangle] b: i32
//~^ ERROR allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in
//~^ ERROR allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
| {};
}
40 changes: 20 additions & 20 deletions src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ error: documentation comments cannot be applied to function parameters
LL | /// Bar
| ^^^^^^^ doc comments are not allowed here

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
--> $DIR/param-attrs-builtin-attrs.rs:171:9
|
LL | #[no_mangle] b: i32
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rustdoc/check-doc-alias-attr-location.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: allow, cfg, cfg_attr, deny, forbid, and warn are the only allowed built-in attributes in function parameters
error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
--> $DIR/check-doc-alias-attr-location.rs:22:12
|
LL | fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {
Expand Down

0 comments on commit e3a40dd

Please sign in to comment.