Skip to content

Allow attributes in logical parameter position #55033

Closed
@Robbepop

Description

@Robbepop

Allow attributes in logical parameter position like here

fn foonction(#[my_attribute] bar: u32) -> bool;

Current Situation

The compiler currently simply does not allow for attributes in this position:

error: expected pattern, found `#`
  --> file.rs:15:13
   |
15 |     pub fn foo(#![bar] capacity: usize) -> Self {
   |                ^ expected pattern

Rational

This could be very useful for some procedural macros which was effectively my use case yesterday.
Also I can imagine use cases for something like an #[ignore] attribute to say that a parameter is not in use which is currently implied by prefixing its name with an underscore. However, at least to me such an #[ignore] attribute (or come up with a better name for it) would be much more explicit which sticks better to the explicit nature of the language itself.

Other Sources

On march this year (2018) @petrochenkov was already talking about the usefulness of attributes for formal function parameters in this thread.


If there is anybody who is free of time and wants to give it a try I would be very grateful. Otherwise I would try implementing it in my spare time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamneeds-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions