1
Fork 0

Rollup merge of #133218 - compiler-errors:const-opaque, r=fee1-dead

Implement `~const` item bounds in RPIT

an RPIT in a `const fn` is allowed to be conditionally const itself :)

r? fee1-dead or reroll
This commit is contained in:
Matthias Krüger 2024-11-21 07:56:13 +01:00 committed by GitHub
commit 920092531f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 144 additions and 31 deletions

View file

@ -697,7 +697,7 @@ rustc_queries! {
separate_provide_extern
}
query implied_const_bounds(
query explicit_implied_const_bounds(
key: DefId
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
desc { |tcx| "computing the implied `~const` bounds for `{}`",

View file

@ -393,12 +393,12 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
)
}
fn implied_const_bounds(
fn explicit_implied_const_bounds(
self,
def_id: DefId,
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
ty::EarlyBinder::bind(
self.implied_const_bounds(def_id).iter_identity_copied().map(|(c, _)| c),
self.explicit_implied_const_bounds(def_id).iter_identity_copied().map(|(c, _)| c),
)
}

View file

@ -2110,7 +2110,13 @@ impl<'tcx> TyCtxt<'tcx> {
_ => bug!("unexpected parent item of associated item: {parent_def_id:?}"),
}
}
DefKind::Closure | DefKind::OpaqueTy => {
DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) {
hir::OpaqueTyOrigin::FnReturn { parent, .. } => self.is_conditionally_const(parent),
hir::OpaqueTyOrigin::AsyncFn { .. } => false,
// FIXME(const_trait_impl): ATPITs could be conditionally const?
hir::OpaqueTyOrigin::TyAlias { .. } => false,
},
DefKind::Closure => {
// Closures and RPITs will eventually have const conditions
// for `~const` bounds.
false