@@ -60,106 +60,106 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
6060 // with `collect()` because of the need to sometimes skip subtrees
6161 // in the `subtys` iterator (e.g., when encountering a
6262 // projection).
63- match ty. kind {
64- ty:: view:: Closure ( def_id, ref substs) => {
65- for upvar_ty in substs. as_closure ( ) . upvar_tys ( def_id, tcx) {
66- compute_components ( tcx, upvar_ty, out) ;
67- }
63+ match ty. into ( ) {
64+ ty:: view:: Closure ( def_id, ref substs) => {
65+ for upvar_ty in substs. as_closure ( ) . upvar_tys ( def_id, tcx) {
66+ compute_components ( tcx, upvar_ty, out) ;
6867 }
68+ }
6969
70- ty:: view:: Generator ( def_id, ref substs, _) => {
71- // Same as the closure case
72- for upvar_ty in substs. as_generator ( ) . upvar_tys ( def_id, tcx) {
73- compute_components ( tcx, upvar_ty, out) ;
74- }
75-
76- // We ignore regions in the generator interior as we don't
77- // want these to affect region inference
70+ ty:: view:: Generator ( def_id, ref substs, _) => {
71+ // Same as the closure case
72+ for upvar_ty in substs. as_generator ( ) . upvar_tys ( def_id, tcx) {
73+ compute_components ( tcx, upvar_ty, out) ;
7874 }
7975
80- // All regions are bound inside a witness
81- ty:: view:: GeneratorWitness ( ..) => ( ) ,
76+ // We ignore regions in the generator interior as we don't
77+ // want these to affect region inference
78+ }
8279
83- // OutlivesTypeParameterEnv -- the actual checking that `X:'a`
84- // is implied by the environment is done in regionck.
85- ty:: view:: Param ( p) => {
86- out. push ( Component :: Param ( p) ) ;
87- }
80+ // All regions are bound inside a witness
81+ ty:: view:: GeneratorWitness ( ..) => ( ) ,
82+
83+ // OutlivesTypeParameterEnv -- the actual checking that `X:'a`
84+ // is implied by the environment is done in regionck.
85+ ty:: view:: Param ( p) => {
86+ out. push ( Component :: Param ( p) ) ;
87+ }
8888
89- // For projections, we prefer to generate an obligation like
90- // `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
91- // regionck more ways to prove that it holds. However,
92- // regionck is not (at least currently) prepared to deal with
93- // higher-ranked regions that may appear in the
94- // trait-ref. Therefore, if we see any higher-ranke regions,
95- // we simply fallback to the most restrictive rule, which
96- // requires that `Pi: 'a` for all `i`.
97- ty:: view:: Projection ( data) => {
98- if !data. has_escaping_bound_vars ( ) {
99- // best case: no escaping regions, so push the
100- // projection and skip the subtree (thus generating no
101- // constraints for Pi). This defers the choice between
102- // the rules OutlivesProjectionEnv,
103- // OutlivesProjectionTraitDef, and
104- // OutlivesProjectionComponents to regionck.
105- out. push ( Component :: Projection ( data) ) ;
106- } else {
107- // fallback case: hard code
108- // OutlivesProjectionComponents. Continue walking
109- // through and constrain Pi.
110- let subcomponents = capture_components ( tcx, ty) ;
111- out. push ( Component :: EscapingProjection ( subcomponents) ) ;
112- }
89+ // For projections, we prefer to generate an obligation like
90+ // `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
91+ // regionck more ways to prove that it holds. However,
92+ // regionck is not (at least currently) prepared to deal with
93+ // higher-ranked regions that may appear in the
94+ // trait-ref. Therefore, if we see any higher-ranke regions,
95+ // we simply fallback to the most restrictive rule, which
96+ // requires that `Pi: 'a` for all `i`.
97+ ty:: view:: Projection ( data) => {
98+ if !data. has_escaping_bound_vars ( ) {
99+ // best case: no escaping regions, so push the
100+ // projection and skip the subtree (thus generating no
101+ // constraints for Pi). This defers the choice between
102+ // the rules OutlivesProjectionEnv,
103+ // OutlivesProjectionTraitDef, and
104+ // OutlivesProjectionComponents to regionck.
105+ out. push ( Component :: Projection ( data) ) ;
106+ } else {
107+ // fallback case: hard code
108+ // OutlivesProjectionComponents. Continue walking
109+ // through and constrain Pi.
110+ let subcomponents = capture_components ( tcx, ty) ;
111+ out. push ( Component :: EscapingProjection ( subcomponents) ) ;
113112 }
113+ }
114114
115- ty:: view:: UnnormalizedProjection ( ..) => bug ! ( "only used with chalk-engine" ) ,
115+ ty:: view:: UnnormalizedProjection ( ..) => bug ! ( "only used with chalk-engine" ) ,
116116
117- // We assume that inference variables are fully resolved.
118- // So, if we encounter an inference variable, just record
119- // the unresolved variable as a component.
120- ty:: view:: Infer ( infer_ty) => {
121- out. push ( Component :: UnresolvedInferenceVariable ( infer_ty) ) ;
122- }
117+ // We assume that inference variables are fully resolved.
118+ // So, if we encounter an inference variable, just record
119+ // the unresolved variable as a component.
120+ ty:: view:: Infer ( infer_ty) => {
121+ out. push ( Component :: UnresolvedInferenceVariable ( infer_ty) ) ;
122+ }
123123
124- // Most types do not introduce any region binders, nor
125- // involve any other subtle cases, and so the WF relation
126- // simply constraints any regions referenced directly by
127- // the type and then visits the types that are lexically
128- // contained within. (The comments refer to relevant rules
129- // from RFC1214.)
130- ty:: view:: Bool | // OutlivesScalar
131- ty:: view:: Char | // OutlivesScalar
132- ty:: view:: Int ( ..) | // OutlivesScalar
133- ty:: view:: Uint ( ..) | // OutlivesScalar
134- ty:: view:: Float ( ..) | // OutlivesScalar
135- ty:: view:: Never | // ...
136- ty:: view:: Adt ( ..) | // OutlivesNominalType
137- ty:: view:: Opaque ( ..) | // OutlivesNominalType (ish)
138- ty:: view:: Foreign ( ..) | // OutlivesNominalType
139- ty:: view:: Str | // OutlivesScalar (ish)
140- ty:: view:: Array ( ..) | // ...
141- ty:: view:: Slice ( ..) | // ...
142- ty:: view:: RawPtr ( ..) | // ...
143- ty:: view:: Ref ( ..) | // OutlivesReference
144- ty:: view:: Tuple ( ..) | // ...
145- ty:: view:: FnDef ( ..) | // OutlivesFunction (*)
146- ty:: view:: FnPtr ( _) | // OutlivesFunction (*)
147- ty:: view:: Dynamic ( ..) | // OutlivesObject, OutlivesFragment (*)
148- ty:: view:: Placeholder ( ..) |
149- ty:: view:: Bound ( ..) |
150- ty:: view:: Error => {
151- // (*) Bare functions and traits are both binders. In the
152- // RFC, this means we would add the bound regions to the
153- // "bound regions list". In our representation, no such
154- // list is maintained explicitly, because bound regions
155- // themselves can be readily identified.
156-
157- push_region_constraints ( ty, out) ;
158- for subty in ty. walk_shallow ( ) {
159- compute_components ( tcx, subty, out) ;
160- }
124+ // Most types do not introduce any region binders, nor
125+ // involve any other subtle cases, and so the WF relation
126+ // simply constraints any regions referenced directly by
127+ // the type and then visits the types that are lexically
128+ // contained within. (The comments refer to relevant rules
129+ // from RFC1214.)
130+ ty:: view:: Bool | // OutlivesScalar
131+ ty:: view:: Char | // OutlivesScalar
132+ ty:: view:: Int ( ..) | // OutlivesScalar
133+ ty:: view:: Uint ( ..) | // OutlivesScalar
134+ ty:: view:: Float ( ..) | // OutlivesScalar
135+ ty:: view:: Never | // ...
136+ ty:: view:: Adt ( ..) | // OutlivesNominalType
137+ ty:: view:: Opaque ( ..) | // OutlivesNominalType (ish)
138+ ty:: view:: Foreign ( ..) | // OutlivesNominalType
139+ ty:: view:: Str | // OutlivesScalar (ish)
140+ ty:: view:: Array ( ..) | // ...
141+ ty:: view:: Slice ( ..) | // ...
142+ ty:: view:: RawPtr ( ..) | // ...
143+ ty:: view:: Ref ( ..) | // OutlivesReference
144+ ty:: view:: Tuple ( ..) | // ...
145+ ty:: view:: FnDef ( ..) | // OutlivesFunction (*)
146+ ty:: view:: FnPtr ( _) | // OutlivesFunction (*)
147+ ty:: view:: Dynamic ( ..) | // OutlivesObject, OutlivesFragment (*)
148+ ty:: view:: Placeholder ( ..) |
149+ ty:: view:: Bound ( ..) |
150+ ty:: view:: Error => {
151+ // (*) Bare functions and traits are both binders. In the
152+ // RFC, this means we would add the bound regions to the
153+ // "bound regions list". In our representation, no such
154+ // list is maintained explicitly, because bound regions
155+ // themselves can be readily identified.
156+
157+ push_region_constraints ( ty, out) ;
158+ for subty in ty. walk_shallow ( ) {
159+ compute_components ( tcx, subty, out) ;
161160 }
162161 }
162+ }
163163}
164164
165165fn capture_components ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Vec < Component < ' tcx > > {
0 commit comments