diff options
| author | Celina G. Val <celinval@amazon.com> | 2025-02-25 13:24:07 -0800 |
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2025-04-07 11:17:33 -0700 |
| commit | b9754f9e7bfe2d8eed780962b550a25a87118ce4 (patch) | |
| tree | 1d8ef4bffc26b6918e8698db3bcfbebfb9f03d7f /compiler/rustc_ast_lowering/src | |
| parent | 5337252b9952fdd9482ed6a4add17254e5bd2c40 (diff) | |
| download | rust-b9754f9e7bfe2d8eed780962b550a25a87118ce4.tar.gz rust-b9754f9e7bfe2d8eed780962b550a25a87118ce4.zip | |
Enable contracts for const functions
Use `const_eval_select!()` macro to enable contract checking only at runtime. The existing contract logic relies on closures, which are not supported in constant functions. This commit also removes one level of indirection for ensures clauses, however, it currently has a spurious warning message when the bottom of the function is unreachable.
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 80bb1e8fc41..0b7a7630431 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -397,12 +397,17 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, expr: &'hir hir::Expr<'hir>, span: Span, - check_ident: Ident, - check_hir_id: HirId, + cond_ident: Ident, + cond_hir_id: HirId, ) -> &'hir hir::Expr<'hir> { - let checker_fn = self.expr_ident(span, check_ident, check_hir_id); + let cond_fn = self.expr_ident(span, cond_ident, cond_hir_id); let span = self.mark_span_with_reason(DesugaringKind::Contract, span, None); - self.expr_call(span, checker_fn, std::slice::from_ref(expr)) + let call_expr = self.expr_call_lang_item_fn_mut( + span, + hir::LangItem::ContractCheckEnsures, + arena_vec![self; *expr, *cond_fn], + ); + self.arena.alloc(call_expr) } pub(crate) fn lower_const_block(&mut self, c: &AnonConst) -> hir::ConstBlock { |
