Skip to content

Commit 097f9c6

Browse files
Stop using prefix_tys
This function hints at an early commitment to coroutine memory layout. We should not give promises on how upvars are allocated. Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
1 parent be326a9 commit 097f9c6

10 files changed

Lines changed: 335 additions & 180 deletions

File tree

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use rustc_middle::traits::query::NoSolution;
2626
use rustc_middle::ty::adjustment::PointerCoercion;
2727
use rustc_middle::ty::cast::CastTy;
2828
use rustc_middle::ty::{
29-
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
30-
GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
29+
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, GenericArgsRef, Ty, TyCtxt,
30+
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
3131
};
3232
use rustc_mir_dataflow::move_paths::MoveData;
3333
use rustc_mir_dataflow::points::DenseLocationMap;
@@ -2222,14 +2222,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22222222
}
22232223
}
22242224
AggregateKind::Coroutine(_, args) => {
2225-
// It doesn't make sense to look at a field beyond the prefix;
2226-
// these require a variant index, and are not initialized in
2227-
// aggregate rvalues.
2228-
match args.as_coroutine().prefix_tys().get(field_index.as_usize()) {
2229-
Some(ty) => Ok(*ty),
2230-
None => Err(FieldAccessError::OutOfRange {
2231-
field_count: args.as_coroutine().prefix_tys().len(),
2232-
}),
2225+
// It doesn't make sense to look at a field beyond the captured
2226+
// upvars.
2227+
// Otherwise it require a variant index, and are not initialized
2228+
// in aggregate rvalues.
2229+
let upvar_tys = &args.as_coroutine().upvar_tys();
2230+
if let Some(ty) = upvar_tys.get(field_index.as_usize()) {
2231+
Ok(*ty)
2232+
} else {
2233+
Err(FieldAccessError::OutOfRange { field_count: upvar_tys.len() })
22332234
}
22342235
}
22352236
AggregateKind::CoroutineClosure(_, args) => {

0 commit comments

Comments
 (0)