Auto merge of #60669 - c410-f3r:attrs-fn, r=petrochenkov

Allow attributes in formal function parameters

Implements https://github.com/rust-lang/rust/issues/60406.

This is my first contribution to the compiler and since this is a large and complex project, I am not fully aware of the consequences of the changes I have made.

**TODO**

- [x] Forbid some built-in attributes.
- [x] Expand cfg/cfg_attr
This commit is contained in:
bors 2019-06-12 07:38:01 +00:00
commit 3f511ade5b
28 changed files with 1115 additions and 74 deletions

View file

@ -1,20 +1,20 @@
pub fn f(
/// Comment
//~^ ERROR documentation comments cannot be applied to method arguments
//~^ ERROR documentation comments cannot be applied to function parameters
//~| NOTE doc comments are not allowed here
//~| ERROR attributes on function parameters are unstable
//~| NOTE https://github.com/rust-lang/rust/issues/60406
id: u8,
/// Other
//~^ ERROR documentation comments cannot be applied to method arguments
//~^ ERROR documentation comments cannot be applied to function parameters
//~| NOTE doc comments are not allowed here
//~| ERROR attributes on function parameters are unstable
//~| NOTE https://github.com/rust-lang/rust/issues/60406
a: u8,
) {}
fn foo(#[allow(dead_code)] id: i32) {}
//~^ ERROR attributes cannot be applied to method arguments
//~| NOTE attributes are not allowed here
fn bar(id: #[allow(dead_code)] i32) {}
//~^ ERROR attributes cannot be applied to a method argument's type
//~^ ERROR attributes cannot be applied to a function parameter's type
//~| NOTE attributes are not allowed here
fn main() {
@ -26,10 +26,6 @@ fn main() {
//~| ERROR mismatched types
//~| NOTE expected u8, found reference
//~| NOTE expected
foo("");
//~^ ERROR mismatched types
//~| NOTE expected i32, found reference
//~| NOTE expected
bar("");
//~^ ERROR mismatched types
//~| NOTE expected i32, found reference

View file

@ -1,26 +1,38 @@
error: documentation comments cannot be applied to method arguments
error: attributes cannot be applied to a function parameter's type
--> $DIR/fn-arg-doc-comment.rs:16:12
|
LL | fn bar(id: #[allow(dead_code)] i32) {}
| ^^^^^^^^^^^^^^^^^^^ attributes are not allowed here
error: documentation comments cannot be applied to function parameters
--> $DIR/fn-arg-doc-comment.rs:2:5
|
LL | /// Comment
| ^^^^^^^^^^^ doc comments are not allowed here
error: documentation comments cannot be applied to method arguments
--> $DIR/fn-arg-doc-comment.rs:6:5
error: documentation comments cannot be applied to function parameters
--> $DIR/fn-arg-doc-comment.rs:8:5
|
LL | /// Other
| ^^^^^^^^^ doc comments are not allowed here
error: attributes cannot be applied to method arguments
--> $DIR/fn-arg-doc-comment.rs:12:8
error[E0658]: attributes on function parameters are unstable
--> $DIR/fn-arg-doc-comment.rs:2:5
|
LL | fn foo(#[allow(dead_code)] id: i32) {}
| ^^^^^^^^^^^^^^^^^^^ attributes are not allowed here
LL | /// Comment
| ^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/60406
= help: add #![feature(param_attrs)] to the crate attributes to enable
error: attributes cannot be applied to a method argument's type
--> $DIR/fn-arg-doc-comment.rs:16:12
error[E0658]: attributes on function parameters are unstable
--> $DIR/fn-arg-doc-comment.rs:8:5
|
LL | fn bar(id: #[allow(dead_code)] i32) {}
| ^^^^^^^^^^^^^^^^^^^ attributes are not allowed here
LL | /// Other
| ^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/60406
= help: add #![feature(param_attrs)] to the crate attributes to enable
error[E0308]: mismatched types
--> $DIR/fn-arg-doc-comment.rs:22:7
@ -43,15 +55,6 @@ LL | f("", "");
error[E0308]: mismatched types
--> $DIR/fn-arg-doc-comment.rs:29:9
|
LL | foo("");
| ^^ expected i32, found reference
|
= note: expected type `i32`
found type `&'static str`
error[E0308]: mismatched types
--> $DIR/fn-arg-doc-comment.rs:33:9
|
LL | bar("");
| ^^ expected i32, found reference
|
@ -60,4 +63,5 @@ LL | bar("");
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0658.
For more information about an error, try `rustc --explain E0308`.