about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaja Kądziołka <maya@compilercrim.es>2025-02-28 20:54:10 +0100
committerMaja Kądziołka <maya@compilercrim.es>2025-03-04 13:33:16 +0100
commitda3e73654f311869c052f218e37871a2f4381c85 (patch)
tree11933132861b5e0f553a24dd22d4be2e7df6f65f
parent60493b8973ac5ba632952eaa2f212b56bb97ccfe (diff)
downloadrust-da3e73654f311869c052f218e37871a2f4381c85.tar.gz
rust-da3e73654f311869c052f218e37871a2f4381c85.zip
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.
-rw-r--r--compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
index 505c7278176..86ef07dff5f 100644
--- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
+++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
@@ -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) => {