Skip to content

Commit da3e736

Browse files
committed
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.
1 parent 60493b8 commit da3e736

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs

+5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ impl<'tcx> InhabitedPredicate<'tcx> {
236236
self.instantiate_opt(tcx, args).unwrap_or(self)
237237
}
238238

239+
/// Same as [`Self::instantiate`], but if there is no generics to
240+
/// instantiate, returns `None`. This is useful because it lets us avoid
241+
/// allocating a recursive copy of everything when the result is unchanged.
242+
///
243+
/// Only used to implement `instantiate` itself.
239244
fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> {
240245
match self {
241246
Self::ConstIsZero(c) => {

0 commit comments

Comments
 (0)