Skip to content

Commit 7f36283

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 7f36283

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ 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+
/// recursively copying everything when the result is unchanged.
239242
fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> {
240243
match self {
241244
Self::ConstIsZero(c) => {

0 commit comments

Comments
 (0)