diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 0520c9ac60cf0..21db7d0eebcc0 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -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", ); } diff --git a/src/test/ui/attributes/attrs-on-params.rs b/src/test/ui/attributes/attrs-on-params.rs index 0e606eac1e8b6..158a4500bde77 100644 --- a/src/test/ui/attributes/attrs-on-params.rs +++ b/src/test/ui/attributes/attrs-on-params.rs @@ -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() {} diff --git a/src/test/ui/attributes/attrs-on-params.stderr b/src/test/ui/attributes/attrs-on-params.stderr index 003f43d371a35..306e862cb58d4 100644 --- a/src/test/ui/attributes/attrs-on-params.stderr +++ b/src/test/ui/attributes/attrs-on-params.stderr @@ -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) { diff --git a/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.rs b/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.rs new file mode 100644 index 0000000000000..5fdb710416f04 --- /dev/null +++ b/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.rs @@ -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() {} diff --git a/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.stderr b/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.stderr new file mode 100644 index 0000000000000..69f7cda08ef0b --- /dev/null +++ b/src/test/ui/lint/rfc-2383-lint-reason/expect_on_fn_params.stderr @@ -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 + diff --git a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs index 6403b3f55c40c..151659e35c0d6 100644 --- a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs +++ b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.rs @@ -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 | {}; } diff --git a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr index edca8cea68d72..7573e39d8eb0c 100644 --- a/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr +++ b/src/test/ui/rfc-2565-param-attrs/param-attrs-builtin-attrs.stderr @@ -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 diff --git a/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr b/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr index 2b25882be21f1..650a82a23a981 100644 --- a/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr +++ b/src/test/ui/rustdoc/check-doc-alias-attr-location.stderr @@ -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 {