1
Fork 0

Fix unreachable expression warning

Invert the order that we pass the arguments to the
`contract_check_ensures` function to avoid the warning when the tail
of the function is unreachable.

Note that the call itself is also unreachable, but we have already
handled that case by ignoring unreachable call for contract calls.
This commit is contained in:
Celina G. Val 2025-04-07 17:42:08 -07:00
parent b9754f9e7b
commit 3feac59b79
16 changed files with 39 additions and 66 deletions

View file

@ -401,11 +401,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
cond_hir_id: HirId,
) -> &'hir hir::Expr<'hir> {
let cond_fn = self.expr_ident(span, cond_ident, cond_hir_id);
let span = self.mark_span_with_reason(DesugaringKind::Contract, span, None);
let call_expr = self.expr_call_lang_item_fn_mut(
span,
hir::LangItem::ContractCheckEnsures,
arena_vec![self; *expr, *cond_fn],
arena_vec![self; *cond_fn, *expr],
);
self.arena.alloc(call_expr)
}

View file

@ -1209,8 +1209,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let precond = if let Some(req) = &contract.requires {
// Lower the precondition check intrinsic.
let lowered_req = this.lower_expr_mut(&req);
let req_span = this.mark_span_with_reason(
DesugaringKind::Contract,
lowered_req.span,
None,
);
let precond = this.expr_call_lang_item_fn_mut(
req.span,
req_span,
hir::LangItem::ContractCheckRequires,
&*arena_vec![this; lowered_req],
);
@ -1220,6 +1225,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
};
let (postcond, body) = if let Some(ens) = &contract.ensures {
let ens_span = this.lower_span(ens.span);
let ens_span =
this.mark_span_with_reason(DesugaringKind::Contract, ens_span, None);
// Set up the postcondition `let` statement.
let check_ident: Ident =
Ident::from_str_and_span("__ensures_checker", ens_span);

View file

@ -236,7 +236,7 @@ pub fn check_intrinsic_type(
// where C: for<'a> Fn(&'a Ret) -> bool,
//
// so: two type params, 0 lifetime param, 0 const params, two inputs, no return
(2, 0, 0, vec![param(0), param(1)], param(0), hir::Safety::Safe)
(2, 0, 0, vec![param(0), param(1)], param(1), hir::Safety::Safe)
} else {
let safety = intrinsic_operation_unsafety(tcx, intrinsic_id);
let (n_tps, n_cts, inputs, output) = match intrinsic_name {