-
Notifications
You must be signed in to change notification settings - Fork 533
Add reference for attributes in function parameters #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,7 +17,7 @@ | |||||
> _FunctionParam_ (`,` _FunctionParam_)<sup>\*</sup> `,`<sup>?</sup> | ||||||
> | ||||||
> _FunctionParam_ :\ | ||||||
> [_Pattern_] `:` [_Type_] | ||||||
> [_OuterAttribute_]<sup>\*</sup> [_Pattern_] `:` [_Type_] | ||||||
> | ||||||
> _FunctionReturnType_ :\ | ||||||
> `->` [_Type_] | ||||||
|
@@ -244,12 +244,36 @@ fn test_only() { | |||||
> Note: Except for lints, it is idiomatic to only use outer attributes on | ||||||
> function items. | ||||||
|
||||||
The attributes that have meaning on a function are [`cfg`], [`deprecated`], | ||||||
The attributes that have meaning on a function are [`cfg`], [`cfg_attr`], [`deprecated`], | ||||||
[`doc`], [`export_name`], [`link_section`], [`no_mangle`], [the lint check | ||||||
attributes], [`must_use`], [the procedural macro attributes], [the testing | ||||||
attributes], and [the optimization hint attributes]. Functions also accept | ||||||
attributes macros. | ||||||
|
||||||
## Attributes on function parameters | ||||||
|
||||||
[Outer attributes][attributes] are allowed on function parameters and the | ||||||
permitted [built-in attributes] are restricted to `cfg`, `cfg_attr`, `allow`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to be clearer about exactly which attributes are allowed, since this doesn't mention that (active) proc macros are forbidden. As Centril pointed out in the release notes (and which took me a while to grok until I read rust-lang/rust#63210), that inert helper attributes are allowed. I'm not sure how to word that clearly. |
||||||
`warn`, `deny`, and `forbid`. | ||||||
|
||||||
```rust | ||||||
fn len( | ||||||
#[cfg(windows)] slice: &[u16], | ||||||
#[cfg(not(windows))] slice: &[u8], | ||||||
) -> usize { | ||||||
slice.len() | ||||||
} | ||||||
``` | ||||||
|
||||||
Inert helper attributes used by procedural macro attributes applied to items are also | ||||||
allowed but be careful to not include these inert attributes in your final `TokenStream`. | ||||||
|
||||||
```rust | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This doesn't pass the tests because the attribute isn't defined. |
||||||
#[hi_i_am_a_proc_macro_attribute] | ||||||
fn foo_oof(#[hello_i_am_an_inert_attribute] arg: u8) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment explaining what this is trying to illustrate? Maybe something like this: // This inert attribute is not formally defined anywhere. The
// `hi_i_am_a_proc_macro_attribute` proc macro is responsible for detecting
// its presence and removing it from the output token stream. |
||||||
} | ||||||
``` | ||||||
|
||||||
[IDENTIFIER]: ../identifiers.md | ||||||
[RAW_STRING_LITERAL]: ../tokens.md#raw-string-literals | ||||||
[STRING_LITERAL]: ../tokens.md#string-literals | ||||||
|
@@ -258,6 +282,7 @@ attributes macros. | |||||
[_Pattern_]: ../patterns.md | ||||||
[_Type_]: ../types.md#type-expressions | ||||||
[_WhereClause_]: generics.md#where-clauses | ||||||
[_OuterAttribute_]: ../attributes.md | ||||||
[const context]: ../const_eval.md#const-context | ||||||
[external blocks]: external-blocks.md | ||||||
[path]: ../paths.md | ||||||
|
@@ -267,7 +292,8 @@ attributes macros. | |||||
[*function item type*]: ../types/function-item.md | ||||||
[Trait]: traits.md | ||||||
[attributes]: ../attributes.md | ||||||
[`cfg`]: ../conditional-compilation.md | ||||||
[`cfg`]: ../conditional-compilation.md#the-cfg-attribute | ||||||
[`cfg_attr`]: ../conditional-compilation.md#the-cfg_attr-attribute | ||||||
[the lint check attributes]: ../attributes/diagnostics.md#lint-check-attributes | ||||||
[the procedural macro attributes]: ../procedural-macros.md | ||||||
[the testing attributes]: ../attributes/testing.md | ||||||
|
@@ -282,3 +308,4 @@ attributes macros. | |||||
[`link_section`]: ../abi.md#the-link_section-attribute | ||||||
[`no_mangle`]: ../abi.md#the-no_mangle-attribute | ||||||
[external_block_abi]: external-blocks.md#abi | ||||||
[built-in attributes]: ../attributes.html#built-in-attributes-index |
Uh oh!
There was an error while loading. Please reload this page.