Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakis

Ergonomic ref counting

This is an experimental first version of ergonomic ref counting.

This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? ```@nikomatsakis```
This commit is contained in:
Matthias Krüger 2025-03-07 19:15:33 +01:00 committed by GitHub
commit f5a143f796
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
119 changed files with 1401 additions and 79 deletions

View file

@ -14,6 +14,8 @@ ty_utils_borrow_not_supported = borrowing is not supported in generic constants
ty_utils_box_not_supported = allocations are not allowed in generic constants
ty_utils_by_use_not_supported = .use is not allowed in generic constants
ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants
ty_utils_const_block_not_supported = const blocks are not supported in generic constants

View file

@ -10,6 +10,13 @@ fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty
is_item_raw(tcx, query, LangItem::Copy)
}
fn is_use_cloned_raw<'tcx>(
tcx: TyCtxt<'tcx>,
query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
) -> bool {
is_item_raw(tcx, query, LangItem::UseCloned)
}
fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
is_item_raw(tcx, query, LangItem::Sized)
}
@ -33,5 +40,12 @@ fn is_item_raw<'tcx>(
}
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { is_copy_raw, is_sized_raw, is_freeze_raw, is_unpin_raw, ..*providers };
*providers = Providers {
is_copy_raw,
is_use_cloned_raw,
is_sized_raw,
is_freeze_raw,
is_unpin_raw,
..*providers
};
}

View file

@ -230,7 +230,9 @@ fn recurse_build<'tcx>(
error(GenericConstantTooComplexSub::LoopNotSupported(node.span))?
}
ExprKind::Box { .. } => error(GenericConstantTooComplexSub::BoxNotSupported(node.span))?,
ExprKind::ByUse { .. } => {
error(GenericConstantTooComplexSub::ByUseNotSupported(node.span))?
}
ExprKind::Unary { .. } => unreachable!(),
// we handle valid unary/binary ops above
ExprKind::Binary { .. } => {
@ -317,6 +319,7 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> {
| thir::ExprKind::Box { .. }
| thir::ExprKind::If { .. }
| thir::ExprKind::Call { .. }
| thir::ExprKind::ByUse { .. }
| thir::ExprKind::Deref { .. }
| thir::ExprKind::Binary { .. }
| thir::ExprKind::LogicalOp { .. }

View file

@ -55,6 +55,8 @@ pub(crate) enum GenericConstantTooComplexSub {
BoxNotSupported(#[primary_span] Span),
#[label(ty_utils_binary_not_supported)]
BinaryNotSupported(#[primary_span] Span),
#[label(ty_utils_by_use_not_supported)]
ByUseNotSupported(#[primary_span] Span),
#[label(ty_utils_logical_op_not_supported)]
LogicalOpNotSupported(#[primary_span] Span),
#[label(ty_utils_assign_not_supported)]