Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE: tuple_fields called on non-tuple: async fn with unknown macro #26

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
for required_region in required_region_bounds {
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
infcx: self,
});
}
if let GenerateMemberConstraints::IfNoStaticBound = mode {
Expand Down Expand Up @@ -510,6 +511,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
op: |r| self.sub_regions(infer::CallReturn(span), least_region, r),
infcx: self,
});
}

Expand Down Expand Up @@ -552,6 +554,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
&choice_regions,
)
},
infcx: self,
});
}

Expand Down Expand Up @@ -683,11 +686,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
//
// We ignore any type parameters because impl trait values are assumed to
// capture all the in-scope type parameters.
struct ConstrainOpaqueTypeRegionVisitor<OP> {
struct ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP> {
infcx: &'cx InferCtxt<'cx, 'tcx>,
op: OP,
}

impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<OP>
impl<'cx, 'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'cx, 'tcx, OP>
where
OP: FnMut(ty::Region<'tcx>),
{
Expand Down Expand Up @@ -730,15 +734,22 @@ where
// Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions.

substs.as_generator().tupled_upvars_ty().visit_with(self);
// We need to shallow resolve to ensure tuple_upvars_ty is of kind Tuple
// At this point, the kind should not be of type Infer but could potentially
// be of kind Error
let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());

for upvar_ty in substs.as_generator().upvar_tys() {
upvar_ty.visit_with(self);
}
if let ty::Tuple(_) = ty.kind() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to write the code more robustly, I think, so that it permits Error or Tuple but not other cases. I suspect the right fix is going to be to modify upvar_tys -- wouldn't we expect ICEs from other callers?

substs.as_generator().tupled_upvars_ty().visit_with(self);

substs.as_generator().return_ty().visit_with(self);
substs.as_generator().yield_ty().visit_with(self);
substs.as_generator().resume_ty().visit_with(self);
for upvar_ty in substs.as_generator().upvar_tys() {
upvar_ty.visit_with(self);
}

substs.as_generator().return_ty().visit_with(self);
substs.as_generator().yield_ty().visit_with(self);
substs.as_generator().resume_ty().visit_with(self);
}
}
_ => {
ty.super_visit_with(self);
Expand Down