Clarify why InhabitedPredicate::instantiate_opt exists

At first glance, the extra casework seems pointless and needlessly
error-prone. Clarify that there is a reason for it being there.
This commit is contained in:
Maja Kądziołka 2025-02-28 20:54:10 +01:00
parent 60493b8973
commit da3e73654f
No known key found for this signature in database

View file

@ -236,6 +236,11 @@ impl<'tcx> InhabitedPredicate<'tcx> {
self.instantiate_opt(tcx, args).unwrap_or(self)
}
/// Same as [`Self::instantiate`], but if there is no generics to
/// instantiate, returns `None`. This is useful because it lets us avoid
/// allocating a recursive copy of everything when the result is unchanged.
///
/// Only used to implement `instantiate` itself.
fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> {
match self {
Self::ConstIsZero(c) => {