Skip to content

block-expr: add new rule expr.block.result-value#2174

Open
DanielEScherzer wants to merge 1 commit intorust-lang:masterfrom
DanielEScherzer:patch-2
Open

block-expr: add new rule expr.block.result-value#2174
DanielEScherzer wants to merge 1 commit intorust-lang:masterfrom
DanielEScherzer:patch-2

Conversation

@DanielEScherzer
Copy link
Contributor

Document that the value of a block expression is based on the final operand (if present), just like the type.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Feb 15, 2026
Document that the value of a block expression is based on the final operand (if
present), just like the type.
@DanielEScherzer DanielEScherzer changed the title block-expr: add new rule expr.block.value block-expr: add new rule expr.block.result-value Feb 15, 2026
@DanielEScherzer
Copy link
Contributor Author

Discovered while working on a conference talk about rust, I couldn't find any rule saying that a block expression had a value equal to the final operand, so I added such a rule
Not quite sure how to phrase the part about diverging blocks - on the playground the following compiles with just some warnings about unreachable code:

fn main () {
    let result: String = { panic!("test") };
    let result: bool = { panic!("test") };
    let result: Vec<String> = { panic!("test") };
}

also, rule name could be improved, I originally was going to use expr.block.value but that is an existing rule

Blocks are always value expressions and evaluate the last operand in value expression context.

@rustbot label A-expressions

@rustbot rustbot added the A-expressions Area: Expressions label Feb 15, 2026
@DanielEScherzer
Copy link
Contributor Author

From the review policy

If this would make a new guarantee about the language, this needs to go through the lang team to be accepted (unless the lang team has clearly accepted this guarantee elsewhere). Ask @traviscross if at all unsure about any of these.

Not sure if this is a new guarantee or just documenting a long-standing reality, @traviscross does this need to go through the lang team?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-expressions Area: Expressions S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants