diff options
| author | Maja Kądziołka <maya@compilercrim.es> | 2025-02-28 20:54:10 +0100 |
|---|---|---|
| committer | Maja Kądziołka <maya@compilercrim.es> | 2025-03-04 13:33:16 +0100 |
| commit | da3e73654f311869c052f218e37871a2f4381c85 (patch) | |
| tree | 11933132861b5e0f553a24dd22d4be2e7df6f65f | |
| parent | 60493b8973ac5ba632952eaa2f212b56bb97ccfe (diff) | |
| download | rust-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.rs | 5 |
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) => { |
