Decide on path forward for attributes on expressions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Long ago, we adopted rust-lang/rfcs#16 ("attributes on statements and blocks"). However, it's long been blocked despite the known and compelling use cases for this.
Over in the tracking issue, #15701, @WaffleLapkin explains the nature of what is blocking this and proposes a path forward:
From what I understand the issue blocking this is ambiguity -- even if the RFC specifies what
#[meow] 1 + 1means, it's still not very readable. I think the path forward is to cut this feature to only allow attributes on things that are unambiguous, such as:
- All kinds of braces:
#[meow] (1 + 1),#[uwu] [1, 2, 3],#[purr] {}(parethesis/grouping expr, tuples, arrays, blocks)- Closures:
#[kwncjhn] || 2- Expressions starting with a keyword:
#[meow] if x {},#[attr] loop { break 'rust; },#[kva] while false {}, ...- etc
Then we can provide a suggestion to add parenthesis around the expression, if it is not supported:
error: meow meow meow ambiguous attribute --> src/main.rs:LL:CC | LL | let x = #[meow] 1 + 1; | help: wrap the expression in parenthesis | LL | let x = #[meow] (1 + 1); | + + help: wrap the expression in parenthesis (alternative | LL | let x = (#[meow] 1) + 1; | + +
Let's nominate this for discussion so we can decide whether we can unblock this by adopting that proposal.
This may have relevance for whether libs-api would feel the need to stabilize this:
@rustbot labels +I-lang-nominated +T-lang +C-discussion
cc @rust-lang/lang @WaffleLapkin
Tracking:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tracking issue #15701, RFC 16, and the linked proposal about restricting attributes to unambiguous expressions. Review the language-team discussion and related issue #94745. Done means reaching and documenting a decision on whether the proposed path can unblock attributes on expressions; the payload names no implementation files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100