Skip to content

Commit 5d30f8d

Browse files
Rollup merge of rust-lang#137820 - meithecatte:instantiate-opt, r=BoxyUwU
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.
2 parents e634d23 + a3d63fb commit 5d30f8d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

+9-1
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) => {
@@ -260,7 +265,10 @@ impl<'tcx> InhabitedPredicate<'tcx> {
260265
Some(InhabitedPredicate::True) => Some(InhabitedPredicate::True),
261266
Some(a) => Some(a.or(tcx, b.instantiate_opt(tcx, args).unwrap_or(b))),
262267
},
263-
_ => None,
268+
Self::True | Self::False | Self::NotInModule(_) => None,
269+
Self::OpaqueType(_) => {
270+
bug!("unexpected OpaqueType in InhabitedPredicate");
271+
}
264272
}
265273
}
266274
}

0 commit comments

Comments
 (0)