Rollup merge of #81008 - tmiasko:generator-layout-err, r=tmandry
Don't ICE when computing a layout of a generator tainted by errors Fixes #80998.
This commit is contained in:
commit
ce06df2e4a
@ -1832,8 +1832,9 @@ fn field_name(&self, i: usize) -> String {
|
|||||||
fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option<SourceInfo<'ll>> {
|
fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option<SourceInfo<'ll>> {
|
||||||
match self {
|
match self {
|
||||||
VariantInfo::Generator { def_id, variant_index, .. } => {
|
VariantInfo::Generator { def_id, variant_index, .. } => {
|
||||||
let span =
|
let span = cx.tcx.generator_layout(*def_id).unwrap().variant_source_info
|
||||||
cx.tcx.generator_layout(*def_id).variant_source_info[*variant_index].span;
|
[*variant_index]
|
||||||
|
.span;
|
||||||
if !span.is_dummy() {
|
if !span.is_dummy() {
|
||||||
let loc = cx.lookup_debug_loc(span.lo());
|
let loc = cx.lookup_debug_loc(span.lo());
|
||||||
return Some(SourceInfo {
|
return Some(SourceInfo {
|
||||||
|
@ -1466,10 +1466,12 @@ fn generator_layout(
|
|||||||
) -> Result<&'tcx Layout, LayoutError<'tcx>> {
|
) -> Result<&'tcx Layout, LayoutError<'tcx>> {
|
||||||
use SavedLocalEligibility::*;
|
use SavedLocalEligibility::*;
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
let subst_field = |ty: Ty<'tcx>| ty.subst(tcx, substs);
|
let subst_field = |ty: Ty<'tcx>| ty.subst(tcx, substs);
|
||||||
|
|
||||||
let info = tcx.generator_layout(def_id);
|
let info = match tcx.generator_layout(def_id) {
|
||||||
|
None => return Err(LayoutError::Unknown(ty)),
|
||||||
|
Some(info) => info,
|
||||||
|
};
|
||||||
let (ineligible_locals, assignments) = self.generator_saved_local_eligibility(&info);
|
let (ineligible_locals, assignments) = self.generator_saved_local_eligibility(&info);
|
||||||
|
|
||||||
// Build a prefix layout, including "promoting" all ineligible
|
// Build a prefix layout, including "promoting" all ineligible
|
||||||
|
@ -3068,8 +3068,10 @@ pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
|
|||||||
self.trait_def(trait_def_id).has_auto_impl
|
self.trait_def(trait_def_id).has_auto_impl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> {
|
/// Returns layout of a generator. Layout might be unavailable if the
|
||||||
self.optimized_mir(def_id).generator_layout.as_ref().unwrap()
|
/// 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.
|
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
|
||||||
|
@ -605,7 +605,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
|
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
|
||||||
// FIXME requires optimized MIR
|
// FIXME requires optimized MIR
|
||||||
let num_variants = tcx.generator_layout(def_id).variant_fields.len();
|
let num_variants = tcx.generator_layout(def_id).unwrap().variant_fields.len();
|
||||||
VariantIdx::new(0)..VariantIdx::new(num_variants)
|
VariantIdx::new(0)..VariantIdx::new(num_variants)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,7 +666,7 @@ pub fn state_tys(
|
|||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
|
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
|
||||||
let layout = tcx.generator_layout(def_id);
|
let layout = tcx.generator_layout(def_id).unwrap();
|
||||||
layout.variant_fields.iter().map(move |variant| {
|
layout.variant_fields.iter().map(move |variant| {
|
||||||
variant.iter().map(move |field| layout.field_tys[*field].subst(tcx, self.substs))
|
variant.iter().map(move |field| layout.field_tys[*field].subst(tcx, self.substs))
|
||||||
})
|
})
|
||||||
|
28
src/test/ui/generator/layout-error.rs
Normal file
28
src/test/ui/generator/layout-error.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Verifies that computing a layout of a generator tainted by type errors
|
||||||
|
// doesn't ICE. Regression test for #80998.
|
||||||
|
//
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
pub struct Task<F: Future>(F);
|
||||||
|
impl<F: Future> Task<F> {
|
||||||
|
fn new() -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn spawn(&self, _: impl FnOnce() -> F) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
async fn cb() {
|
||||||
|
let a = Foo; //~ ERROR cannot find value `Foo` in this scope
|
||||||
|
}
|
||||||
|
|
||||||
|
type F = impl Future;
|
||||||
|
// Check that statics are inhabited computes they layout.
|
||||||
|
static POOL: Task<F> = Task::new();
|
||||||
|
Task::spawn(&POOL, || cb());
|
||||||
|
}
|
9
src/test/ui/generator/layout-error.stderr
Normal file
9
src/test/ui/generator/layout-error.stderr
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
error[E0425]: cannot find value `Foo` in this scope
|
||||||
|
--> $DIR/layout-error.rs:21:17
|
||||||
|
|
|
||||||
|
LL | let a = Foo;
|
||||||
|
| ^^^ not found in this scope
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0425`.
|
Loading…
Reference in New Issue
Block a user