diff --git a/compiler/rustc_ast_lowering/src/contract.rs b/compiler/rustc_ast_lowering/src/contract.rs index 8c58155c083e..ed32ac5c287d 100644 --- a/compiler/rustc_ast_lowering/src/contract.rs +++ b/compiler/rustc_ast_lowering/src/contract.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use thin_vec::thin_vec; use crate::LoweringContext; @@ -118,9 +120,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let req_span = self.mark_span_with_reason( rustc_span::DesugaringKind::Contract, lowered_req.span, - None, + Some(Arc::clone(&self.allow_contracts)), ); - let precond = self.expr_call_lang_item_qpath_fn_mut( + let precond = self.expr_call_lang_item_fn_mut( req_span, rustc_hir::LangItem::ContractCheckRequires, &*arena_vec![self; lowered_req], @@ -133,10 +135,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ens: &Box, ) -> &'hir rustc_hir::Expr<'hir> { let ens_span = self.lower_span(ens.span); - let ens_span = - self.mark_span_with_reason(rustc_span::DesugaringKind::Contract, ens_span, None); + let ens_span = self.mark_span_with_reason( + rustc_span::DesugaringKind::Contract, + ens_span, + Some(Arc::clone(&self.allow_contracts)), + ); let lowered_ens = self.lower_expr_mut(&ens); - self.expr_call_lang_item_qpath_fn( + self.expr_call_lang_item_fn( ens_span, rustc_hir::LangItem::ContractBuildCheckEnsures, &*arena_vec![self; lowered_ens], @@ -291,7 +296,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let ret = self.expr_ident(span, ret_ident, ret_hir_id); let cond_fn = self.expr_ident(span, cond_ident, cond_hir_id); - let contract_check = self.expr_call_lang_item_qpath_fn_mut( + let contract_check = self.expr_call_lang_item_fn_mut( span, rustc_hir::LangItem::ContractCheckEnsures, arena_vec![self; *cond_fn, *ret], diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index be9db9257356..a32144a266f8 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -138,6 +138,7 @@ struct LoweringContext<'a, 'hir> { #[cfg(debug_assertions)] node_id_to_local_id: NodeMap, + allow_contracts: Arc<[Symbol]>, allow_try_trait: Arc<[Symbol]>, allow_gen_future: Arc<[Symbol]>, allow_pattern_type: Arc<[Symbol]>, @@ -183,6 +184,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { current_item: None, impl_trait_defs: Vec::new(), impl_trait_bounds: Vec::new(), + allow_contracts: [sym::contracts_internals].into(), allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(), allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(), allow_gen_future: if tcx.features().async_fn_track_caller() {