1
Fork 0

Auto merge of #118689 - compiler-errors:const-drop, r=fee1-dead

Fix const drop checking

Fixes confirmation of `~const Destruct` and const drops.

r? fee1-dead
This commit is contained in:
bors 2023-12-08 13:43:12 +00:00
commit ae612bedcb
10 changed files with 57 additions and 67 deletions

View file

@ -872,9 +872,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) {
// If the predicate is `~const Destruct` in a non-const environment, we don't actually need
// to check anything. We'll short-circuit checking any obligations in confirmation, too.
// FIXME(effects)
if true {
candidates.vec.push(ConstDestructCandidate(None));
let Some(host_effect_index) =
self.tcx().generics_of(obligation.predicate.def_id()).host_effect_index
else {
candidates.vec.push(BuiltinCandidate { has_nested: false });
return;
};
// If the obligation has `host = true`, then the obligation is non-const and it's always
// trivially implemented.
if obligation.predicate.skip_binder().trait_ref.args.const_at(host_effect_index)
== self.tcx().consts.true_
{
candidates.vec.push(BuiltinCandidate { has_nested: false });
return;
}

View file

@ -1172,11 +1172,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &PolyTraitObligation<'tcx>,
impl_def_id: Option<DefId>,
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
// `~const Destruct` in a non-const environment is always trivially true, since our type is `Drop`
// FIXME(effects)
if true {
return Ok(vec![]);
}
let Some(host_effect_index) =
self.tcx().generics_of(obligation.predicate.def_id()).host_effect_index
else {
bug!()
};
let host_effect_param: ty::GenericArg<'tcx> =
obligation.predicate.skip_binder().trait_ref.args.const_at(host_effect_index).into();
let drop_trait = self.tcx().require_lang_item(LangItem::Drop, None);
@ -1284,7 +1286,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.tcx(),
LangItem::Destruct,
cause.span,
[nested_ty],
[nested_ty.into(), host_effect_param],
),
polarity: ty::ImplPolarity::Positive,
}),
@ -1310,7 +1312,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
self.tcx(),
LangItem::Destruct,
cause.span,
[nested_ty],
[nested_ty.into(), host_effect_param],
),
polarity: ty::ImplPolarity::Positive,
});