Remove QPath::LangItem from contracts

This commit is contained in:
Cameron Steffen
2025-09-01 14:19:55 -05:00
parent eac2c2523e
commit 9c98533491
2 changed files with 13 additions and 6 deletions

View File

@@ -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<rustc_ast::Expr>,
) -> &'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],

View File

@@ -138,6 +138,7 @@ struct LoweringContext<'a, 'hir> {
#[cfg(debug_assertions)]
node_id_to_local_id: NodeMap<hir::ItemLocalId>,
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() {