Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk
Use `upvar_tys` in more places, make it return a list Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
This commit is contained in:
commit
46f6b05eb7
17 changed files with 66 additions and 78 deletions
|
@ -886,6 +886,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
.universal_regions()
|
||||
.defining_ty
|
||||
.upvar_tys()
|
||||
.iter()
|
||||
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
|
||||
{
|
||||
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
fr: RegionVid,
|
||||
) -> Option<usize> {
|
||||
let upvar_index =
|
||||
self.universal_regions().defining_ty.upvar_tys().position(|upvar_ty| {
|
||||
self.universal_regions().defining_ty.upvar_tys().iter().position(|upvar_ty| {
|
||||
debug!("get_upvar_index_for_region: upvar_ty={upvar_ty:?}");
|
||||
tcx.any_free_region_meets(&upvar_ty, |r| {
|
||||
let r = r.as_var();
|
||||
|
@ -52,7 +52,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
})
|
||||
})?;
|
||||
|
||||
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().nth(upvar_index);
|
||||
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().get(upvar_index);
|
||||
|
||||
debug!(
|
||||
"get_upvar_index_for_region: found {fr:?} in upvar {upvar_index} which has type {upvar_ty:?}",
|
||||
|
|
|
@ -791,25 +791,20 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
(adt_def.variant(FIRST_VARIANT), args)
|
||||
}
|
||||
ty::Closure(_, args) => {
|
||||
return match args
|
||||
.as_closure()
|
||||
.tupled_upvars_ty()
|
||||
.tuple_fields()
|
||||
.get(field.index())
|
||||
{
|
||||
return match args.as_closure().upvar_tys().get(field.index()) {
|
||||
Some(&ty) => Ok(ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: args.as_closure().upvar_tys().count(),
|
||||
field_count: args.as_closure().upvar_tys().len(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
ty::Generator(_, args, _) => {
|
||||
// Only prefix fields (upvars and current state) are
|
||||
// accessible without a variant index.
|
||||
return match args.as_generator().prefix_tys().nth(field.index()) {
|
||||
Some(ty) => Ok(ty),
|
||||
return match args.as_generator().prefix_tys().get(field.index()) {
|
||||
Some(ty) => Ok(*ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: args.as_generator().prefix_tys().count(),
|
||||
field_count: args.as_generator().prefix_tys().len(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
@ -1772,10 +1767,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
AggregateKind::Closure(_, args) => {
|
||||
match args.as_closure().upvar_tys().nth(field_index.as_usize()) {
|
||||
Some(ty) => Ok(ty),
|
||||
match args.as_closure().upvar_tys().get(field_index.as_usize()) {
|
||||
Some(ty) => Ok(*ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: args.as_closure().upvar_tys().count(),
|
||||
field_count: args.as_closure().upvar_tys().len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -1783,10 +1778,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
// It doesn't make sense to look at a field beyond the prefix;
|
||||
// these require a variant index, and are not initialized in
|
||||
// aggregate rvalues.
|
||||
match args.as_generator().prefix_tys().nth(field_index.as_usize()) {
|
||||
Some(ty) => Ok(ty),
|
||||
match args.as_generator().prefix_tys().get(field_index.as_usize()) {
|
||||
Some(ty) => Ok(*ty),
|
||||
None => Err(FieldAccessError::OutOfRange {
|
||||
field_count: args.as_generator().prefix_tys().count(),
|
||||
field_count: args.as_generator().prefix_tys().len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
//! The code in this file doesn't *do anything* with those results; it
|
||||
//! just returns them for other code to use.
|
||||
|
||||
use either::Either;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_hir as hir;
|
||||
|
@ -115,14 +114,12 @@ impl<'tcx> DefiningTy<'tcx> {
|
|||
/// not a closure or generator, there are no upvars, and hence it
|
||||
/// will be an empty list. The order of types in this list will
|
||||
/// match up with the upvar order in the HIR, typesystem, and MIR.
|
||||
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
|
||||
pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> {
|
||||
match self {
|
||||
DefiningTy::Closure(_, args) => Either::Left(args.as_closure().upvar_tys()),
|
||||
DefiningTy::Generator(_, args, _) => {
|
||||
Either::Right(Either::Left(args.as_generator().upvar_tys()))
|
||||
}
|
||||
DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(),
|
||||
DefiningTy::Generator(_, args, _) => args.as_generator().upvar_tys(),
|
||||
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
|
||||
Either::Right(Either::Right(iter::empty()))
|
||||
ty::List::empty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue