Always make the "upvar types" a tuple of the actual upvar types (Parent issue#53488) #4
Description
Updated by nikomatsakis with current status:
In rust-lang/rust#69968, @eddyb landed the "first step" here of introducing a tuple into the upvar types. However, in current rustc, we create that tuple "eagerly", as soon as we create the closure type:
The next step is to move that tuple creation "late", so that it occurs during the "upvar analysis" code, so somewhere around here:
The problem with this is that the current accessor, ClosureSubsts::upvar_tys
, assumes that the upvar types are a tuple with known arity. Thus any calls to upvar_tys
that occur before the upvar analysis code runs will ICE.
Last time, we added an accessor upvar_tuple_ty
that returned the tuple itself (or an unbound type variable), since it turned out that many of the calls to upvar_tys
could be replaced by a call that operated on the tuple. Most notably, in the trait system, for example here:
We changed this to yield the tuple always. The problem with that was that it was effecting the error messages, because the tuple was being introduced into the "backtrace" and we somehow never got things quiite right to remove it.
I still think that is perhaps the right approach, but there is an alternative we could try: we could get the tuple ty and check whether it's been "resolved" yet (via a call to self.infcx.shallow_resolve
). If so, we can put each of its components as we do today, but if not, we can return Ambiguous
, as we do here.