Support the #[expect] attribute on fn parameters (RFC-2383)

This commit is contained in:
xFrednet 2022-06-04 00:04:19 +02:00
parent 7e9b92cb43
commit b5eee17088
No known key found for this signature in database
GPG Key ID: F5C59D0E669E5302
8 changed files with 78 additions and 45 deletions

View File

@ -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| {
@ -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",
);
}

View File

@ -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() {}

View File

@ -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) {

View File

@ -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() {}

View File

@ -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

View File

@ -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
);
}
@ -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(
@ -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 {}
@ -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(
@ -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
) {}
}
@ -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 {
@ -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(
@ -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
) {}
}
@ -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
) {}
}
@ -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
| {};
}

View File

@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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,
@ -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]
@ -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

View File

@ -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 {