Skip to content

Unclear block attribute positions #1155

Open
@pushkine

Description

@pushkine

The Attributes on block expressions section specifies when inner attributes are allowed in blocks, it's unclear whether that applies to outer attributes too? Even more confusing is that the example showcases outer attributes instead

## Attributes on block expressions
[Inner attributes] are allowed directly after the opening brace of a block expression in the following situations:
* [Function] and [method] bodies.
* Loop bodies ([`loop`], [`while`], [`while let`], and [`for`]).
* Block expressions used as a [statement].
* Block expressions as elements of [array expressions], [tuple expressions],
[call expressions], and tuple-style [struct] expressions.
* A block expression as the tail expression of another block expression.
<!-- Keep list in sync with expressions.md -->
The attributes that have meaning on a block expression are [`cfg`] and [the lint check attributes].
For example, this function returns `true` on unix platforms and `false` on other platforms.
```rust
fn is_unix_platform() -> bool {
#[cfg(unix)] { true }
#[cfg(not(unix))] { false }
}
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions