Auto merge of #78432 - sexxi-goose:fix-77993-take3, r=nikomatsakis
Handle type errors in closure/generator upvar_tys Fixes #77993
This commit is contained in:
commit
0d33ab7af4
5 changed files with 82 additions and 6 deletions
|
@ -388,9 +388,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
|
|||
self.split().parent_substs
|
||||
}
|
||||
|
||||
/// Returns an iterator over the list of types of captured paths by the closure.
|
||||
/// In case there was a type error in figuring out the types of the captured path, an
|
||||
/// empty iterator is returned.
|
||||
#[inline]
|
||||
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
||||
self.tupled_upvars_ty().tuple_fields()
|
||||
match self.tupled_upvars_ty().kind() {
|
||||
TyKind::Error(_) => None,
|
||||
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
|
||||
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
|
||||
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
|
||||
}
|
||||
.into_iter()
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// Returns the tuple type representing the upvars for this closure.
|
||||
|
@ -515,9 +525,19 @@ impl<'tcx> GeneratorSubsts<'tcx> {
|
|||
self.split().witness.expect_ty()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the list of types of captured paths by the generator.
|
||||
/// In case there was a type error in figuring out the types of the captured path, an
|
||||
/// empty iterator is returned.
|
||||
#[inline]
|
||||
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
||||
self.tupled_upvars_ty().tuple_fields()
|
||||
match self.tupled_upvars_ty().kind() {
|
||||
TyKind::Error(_) => None,
|
||||
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
|
||||
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
|
||||
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
|
||||
}
|
||||
.into_iter()
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// Returns the tuple type representing the upvars for this generator.
|
||||
|
@ -660,13 +680,24 @@ pub enum UpvarSubsts<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> UpvarSubsts<'tcx> {
|
||||
/// Returns an iterator over the list of types of captured paths by the closure/generator.
|
||||
/// In case there was a type error in figuring out the types of the captured path, an
|
||||
/// empty iterator is returned.
|
||||
#[inline]
|
||||
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
||||
let tupled_upvars_ty = match self {
|
||||
UpvarSubsts::Closure(substs) => substs.as_closure().split().tupled_upvars_ty,
|
||||
UpvarSubsts::Generator(substs) => substs.as_generator().split().tupled_upvars_ty,
|
||||
let tupled_tys = match self {
|
||||
UpvarSubsts::Closure(substs) => substs.as_closure().tupled_upvars_ty(),
|
||||
UpvarSubsts::Generator(substs) => substs.as_generator().tupled_upvars_ty(),
|
||||
};
|
||||
tupled_upvars_ty.expect_ty().tuple_fields()
|
||||
|
||||
match tupled_tys.kind() {
|
||||
TyKind::Error(_) => None,
|
||||
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
|
||||
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
|
||||
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
|
||||
}
|
||||
.into_iter()
|
||||
.flatten()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue