Skip to content

Commit 9a21f8d

Browse files
committed
constify const Fn*: Destruct
1 parent a47ae68 commit 9a21f8d

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,12 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
797797
| ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_))
798798
| ty::Error(_) => Ok(vec![]),
799799

800-
// Coroutines and closures could implement `[const] Drop`,
800+
// Closures are [const] Destruct when all of their upvars (captures) are [const] Destruct.
801+
ty::Closure(def, args) if cx.closure_is_const(def) => {
802+
let closure_args = args.as_closure();
803+
Ok(vec![ty::TraitRef::new(cx, destruct_def_id, [closure_args.tupled_upvars_ty()])])
804+
}
805+
// Coroutines could implement `[const] Drop`,
801806
// but they don't really need to right now.
802807
ty::Closure(_, _)
803808
| ty::CoroutineClosure(_, _)

compiler/rustc_trait_selection/src/traits/effects.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,17 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
472472
| ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_))
473473
| ty::Error(_) => thin_vec![],
474474

475-
// Coroutines and closures could implement `[const] Drop`,
475+
// Closures are [const] Destruct when all of their upvars (captures) are [const] Destruct.
476+
ty::Closure(_, args) => {
477+
let closure_args = args.as_closure();
478+
thin_vec![ty::TraitRef::new(tcx, destruct_def_id, [closure_args.tupled_upvars_ty()])]
479+
}
480+
481+
// Coroutines could implement `[const] Drop`,
476482
// but they don't really need to right now.
477-
ty::Closure(_, _)
478-
| ty::CoroutineClosure(_, _)
479-
| ty::Coroutine(_, _)
480-
| ty::CoroutineWitness(_, _) => return Err(EvaluationFailure::NoSolution),
483+
ty::CoroutineClosure(_, _) | ty::Coroutine(_, _) | ty::CoroutineWitness(_, _) => {
484+
return Err(EvaluationFailure::NoSolution);
485+
}
481486

482487
// FIXME(unsafe_binders): Unsafe binders could implement `[const] Drop`
483488
// if their inner type implements it.

0 commit comments

Comments
 (0)