contracts: fix lowering final declaration without trailing semicolon

Lowering for contract delcarations incorrectly handled the final
declaration statement when it didn't end in a semicolon. This
change fixes the issue.
This commit is contained in:
Dawid Lachowicz
2025-12-06 19:16:00 +00:00
parent da2544bfbe
commit d54fee82f4
2 changed files with 35 additions and 1 deletions
+22
View File
@@ -0,0 +1,22 @@
//@ run-pass
//@ compile-flags: -Zcontract-checks=yes
#![expect(incomplete_features)]
#![feature(contracts)]
extern crate core;
use core::contracts::requires;
// Compound statements (those using [ExpressionWithBlock]
// (https://doc.rust-lang.org/beta/reference/expressions.html#railroad-ExpressionWithBlock))
// like blocks, if-expressions, and loops require no trailing semicolon. This
// regression test captures the case where the last statement in the contract
// declarations has no trailing semicolon.
#[requires(
{}
true
)]
fn foo() {}
fn main() {
foo()
}