Don't ICE when computing a layout of a generator tainted by errors

This commit is contained in:
Tomasz Miąsko
2021-01-14 00:00:00 +00:00
parent a4f022e109
commit 5ea1d0e865
6 changed files with 50 additions and 8 deletions

View File

@@ -3068,8 +3068,10 @@ impl<'tcx> TyCtxt<'tcx> {
self.trait_def(trait_def_id).has_auto_impl
}
pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> {
self.optimized_mir(def_id).generator_layout.as_ref().unwrap()
/// Returns layout of a generator. Layout might be unavailable if the
/// generator is tainted by errors.
pub fn generator_layout(self, def_id: DefId) -> Option<&'tcx GeneratorLayout<'tcx>> {
self.optimized_mir(def_id).generator_layout.as_ref()
}
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.