@@ -37,7 +37,7 @@ pub struct ConstraintContext<'a, 'tcx: 'a> {
3737 invariant : VarianceTermPtr < ' a > ,
3838 bivariant : VarianceTermPtr < ' a > ,
3939
40- pub constraints : Vec < Constraint < ' a > > ,
40+ pub constraints : Vec < Constraint < ' a > > ,
4141}
4242
4343/// Declares that the variable `decl_id` appears in a location with
@@ -49,8 +49,7 @@ pub struct Constraint<'a> {
4949}
5050
5151pub fn add_constraints_from_crate < ' a , ' tcx > ( terms_cx : TermsContext < ' a , ' tcx > )
52- -> ConstraintContext < ' a , ' tcx >
53- {
52+ -> ConstraintContext < ' a , ' tcx > {
5453 let tcx = terms_cx. tcx ;
5554 let covariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Covariant ) ) ;
5655 let contravariant = terms_cx. arena . alloc ( ConstantTerm ( ty:: Contravariant ) ) ;
@@ -80,7 +79,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
8079 debug ! ( "visit_item item={}" , tcx. map. node_to_string( item. id) ) ;
8180
8281 match item. node {
83- hir:: ItemEnum ( ..) | hir:: ItemStruct ( ..) | hir:: ItemUnion ( ..) => {
82+ hir:: ItemEnum ( ..) |
83+ hir:: ItemStruct ( ..) |
84+ hir:: ItemUnion ( ..) => {
8485 let scheme = tcx. lookup_item_type ( did) ;
8586
8687 // Not entirely obvious: constraints on structs/enums do not
@@ -111,16 +112,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ConstraintContext<'a, 'tcx> {
111112 hir:: ItemForeignMod ( ..) |
112113 hir:: ItemTy ( ..) |
113114 hir:: ItemImpl ( ..) |
114- hir:: ItemDefaultImpl ( ..) => {
115- }
115+ hir:: ItemDefaultImpl ( ..) => { }
116116 }
117117 }
118118}
119119
120120/// Is `param_id` a lifetime according to `map`?
121121fn is_lifetime ( map : & hir_map:: Map , param_id : ast:: NodeId ) -> bool {
122122 match map. find ( param_id) {
123- Some ( hir_map:: NodeLifetime ( ..) ) => true , _ => false
123+ Some ( hir_map:: NodeLifetime ( ..) ) => true ,
124+ _ => false ,
124125 }
125126}
126127
@@ -143,13 +144,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
143144 let tcx = self . terms_cx . tcx ;
144145 assert ! ( is_lifetime( & tcx. map, param_id) ) ;
145146 match tcx. named_region_map . defs . get ( & param_id) {
146- Some ( & rl:: DefEarlyBoundRegion ( _, lifetime_decl_id) )
147- => lifetime_decl_id,
147+ Some ( & rl:: DefEarlyBoundRegion ( _, lifetime_decl_id) ) => lifetime_decl_id,
148148 Some ( _) => bug ! ( "should not encounter non early-bound cases" ) ,
149149
150150 // The lookup should only fail when `param_id` is
151151 // itself a lifetime binding: use it as the decl_id.
152- None => param_id,
152+ None => param_id,
153153 }
154154
155155 }
@@ -163,14 +163,15 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
163163 // parameter (by inspecting parent of its binding declaration
164164 // to see if it is introduced by a type or by a fn/impl).
165165
166- let check_result = |this : & ConstraintContext | -> bool {
166+ let check_result = |this : & ConstraintContext | -> bool {
167167 let tcx = this. terms_cx . tcx ;
168168 let decl_id = this. find_binding_for_lifetime ( param_id) ;
169169 // Currently only called on lifetimes; double-checking that.
170170 assert ! ( is_lifetime( & tcx. map, param_id) ) ;
171171 let parent_id = tcx. map . get_parent ( decl_id) ;
172- let parent = tcx. map . find ( parent_id) . unwrap_or_else (
173- || bug ! ( "tcx.map missing entry for id: {}" , parent_id) ) ;
172+ let parent = tcx. map
173+ . find ( parent_id)
174+ . unwrap_or_else ( || bug ! ( "tcx.map missing entry for id: {}" , parent_id) ) ;
174175
175176 let is_inferred;
176177 macro_rules! cannot_happen { ( ) => { {
@@ -186,14 +187,14 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
186187 hir:: ItemEnum ( ..) |
187188 hir:: ItemStruct ( ..) |
188189 hir:: ItemUnion ( ..) |
189- hir:: ItemTrait ( ..) => is_inferred = true ,
190- hir:: ItemFn ( ..) => is_inferred = false ,
191- _ => cannot_happen ! ( ) ,
190+ hir:: ItemTrait ( ..) => is_inferred = true ,
191+ hir:: ItemFn ( ..) => is_inferred = false ,
192+ _ => cannot_happen ! ( ) ,
192193 }
193194 }
194- hir_map:: NodeTraitItem ( ..) => is_inferred = false ,
195- hir_map:: NodeImplItem ( ..) => is_inferred = false ,
196- _ => cannot_happen ! ( ) ,
195+ hir_map:: NodeTraitItem ( ..) => is_inferred = false ,
196+ hir_map:: NodeImplItem ( ..) => is_inferred = false ,
197+ _ => cannot_happen ! ( ) ,
197198 }
198199
199200 return is_inferred;
@@ -230,21 +231,18 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
230231 fn add_constraint ( & mut self ,
231232 InferredIndex ( index) : InferredIndex ,
232233 variance : VarianceTermPtr < ' a > ) {
233- debug ! ( "add_constraint(index={}, variance={:?})" ,
234- index, variance) ;
235- self . constraints . push ( Constraint { inferred : InferredIndex ( index) ,
236- variance : variance } ) ;
234+ debug ! ( "add_constraint(index={}, variance={:?})" , index, variance) ;
235+ self . constraints . push ( Constraint {
236+ inferred : InferredIndex ( index) ,
237+ variance : variance,
238+ } ) ;
237239 }
238240
239- fn contravariant ( & mut self ,
240- variance : VarianceTermPtr < ' a > )
241- -> VarianceTermPtr < ' a > {
241+ fn contravariant ( & mut self , variance : VarianceTermPtr < ' a > ) -> VarianceTermPtr < ' a > {
242242 self . xform ( variance, self . contravariant )
243243 }
244244
245- fn invariant ( & mut self ,
246- variance : VarianceTermPtr < ' a > )
247- -> VarianceTermPtr < ' a > {
245+ fn invariant ( & mut self , variance : VarianceTermPtr < ' a > ) -> VarianceTermPtr < ' a > {
248246 self . xform ( variance, self . invariant )
249247 }
250248
@@ -257,23 +255,16 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
257255 }
258256 }
259257
260- fn xform ( & mut self ,
261- v1 : VarianceTermPtr < ' a > ,
262- v2 : VarianceTermPtr < ' a > )
263- -> VarianceTermPtr < ' a > {
258+ fn xform ( & mut self , v1 : VarianceTermPtr < ' a > , v2 : VarianceTermPtr < ' a > ) -> VarianceTermPtr < ' a > {
264259 match ( * v1, * v2) {
265260 ( _, ConstantTerm ( ty:: Covariant ) ) => {
266261 // Applying a "covariant" transform is always a no-op
267262 v1
268263 }
269264
270- ( ConstantTerm ( c1) , ConstantTerm ( c2) ) => {
271- self . constant_term ( c1. xform ( c2) )
272- }
265+ ( ConstantTerm ( c1) , ConstantTerm ( c2) ) => self . constant_term ( c1. xform ( c2) ) ,
273266
274- _ => {
275- & * self . terms_cx . arena . alloc ( TransformTerm ( v1, v2) )
276- }
267+ _ => & * self . terms_cx . arena . alloc ( TransformTerm ( v1, v2) ) ,
277268 }
278269 }
279270
@@ -292,13 +283,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
292283 // README.md for a discussion on dep-graph management.
293284 self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & trait_ref. def_id ) ) ;
294285
295- self . add_constraints_from_substs (
296- generics,
297- trait_ref. def_id ,
298- & trait_def. generics . types ,
299- & trait_def. generics . regions ,
300- trait_ref. substs ,
301- variance) ;
286+ self . add_constraints_from_substs ( generics,
287+ trait_ref. def_id ,
288+ & trait_def. generics . types ,
289+ & trait_def. generics . regions ,
290+ trait_ref. substs ,
291+ variance) ;
302292 }
303293
304294 /// Adds constraints appropriate for an instance of `ty` appearing
@@ -313,13 +303,13 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
313303 variance) ;
314304
315305 match ty. sty {
316- ty:: TyBool |
317- ty:: TyChar | ty:: TyInt ( _) | ty:: TyUint ( _) |
318- ty:: TyFloat ( _) | ty:: TyStr | ty:: TyNever => {
319- /* leaf type -- noop */
306+ ty:: TyBool | ty:: TyChar | ty:: TyInt ( _) | ty:: TyUint ( _) | ty:: TyFloat ( _) |
307+ ty:: TyStr | ty:: TyNever => {
308+ // leaf type -- noop
320309 }
321310
322- ty:: TyClosure ( ..) | ty:: TyAnon ( ..) => {
311+ ty:: TyClosure ( ..) |
312+ ty:: TyAnon ( ..) => {
323313 bug ! ( "Unexpected closure type in variance computation" ) ;
324314 }
325315
@@ -329,11 +319,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
329319 self . add_constraints_from_mt ( generics, mt, variance) ;
330320 }
331321
332- ty:: TyBox ( typ) | ty:: TyArray ( typ, _) | ty:: TySlice ( typ) => {
322+ ty:: TyBox ( typ) |
323+ ty:: TyArray ( typ, _) |
324+ ty:: TySlice ( typ) => {
333325 self . add_constraints_from_ty ( generics, typ, variance) ;
334326 }
335327
336-
337328 ty:: TyRawPtr ( ref mt) => {
338329 self . add_constraints_from_mt ( generics, mt, variance) ;
339330 }
@@ -352,13 +343,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
352343 // README.md for a discussion on dep-graph management.
353344 self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & def. did ) ) ;
354345
355- self . add_constraints_from_substs (
356- generics,
357- def. did ,
358- & item_type. generics . types ,
359- & item_type. generics . regions ,
360- substs,
361- variance) ;
346+ self . add_constraints_from_substs ( generics,
347+ def. did ,
348+ & item_type. generics . types ,
349+ & item_type. generics . regions ,
350+ substs,
351+ variance) ;
362352 }
363353
364354 ty:: TyProjection ( ref data) => {
@@ -370,22 +360,20 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
370360 // README.md for a discussion on dep-graph management.
371361 self . tcx ( ) . dep_graph . read ( ItemVariances :: to_dep_node ( & trait_ref. def_id ) ) ;
372362
373- self . add_constraints_from_substs (
374- generics,
375- trait_ref. def_id ,
376- & trait_def. generics . types ,
377- & trait_def. generics . regions ,
378- trait_ref. substs ,
379- variance) ;
363+ self . add_constraints_from_substs ( generics,
364+ trait_ref. def_id ,
365+ & trait_def. generics . types ,
366+ & trait_def. generics . regions ,
367+ trait_ref. substs ,
368+ variance) ;
380369 }
381370
382371 ty:: TyTrait ( ref data) => {
383372 // The type `Foo<T+'a>` is contravariant w/r/t `'a`:
384373 let contra = self . contravariant ( variance) ;
385374 self . add_constraints_from_region ( generics, data. region_bound , contra) ;
386375
387- let poly_trait_ref =
388- data. principal . with_self_ty ( self . tcx ( ) , self . tcx ( ) . types . err ) ;
376+ let poly_trait_ref = data. principal . with_self_ty ( self . tcx ( ) , self . tcx ( ) . types . err ) ;
389377 self . add_constraints_from_trait_ref ( generics, poly_trait_ref. 0 , variance) ;
390378
391379 for projection in & data. projection_bounds {
@@ -425,7 +413,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
425413
426414 ty:: TyInfer ( ..) => {
427415 bug ! ( "unexpected type encountered in \
428- variance inference: {}", ty) ;
416+ variance inference: {}",
417+ ty) ;
429418 }
430419 }
431420 }
@@ -445,18 +434,17 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
445434 variance) ;
446435
447436 for p in type_param_defs {
448- let variance_decl =
449- self . declared_variance ( p. def_id , def_id, p. index as usize ) ;
437+ let variance_decl = self . declared_variance ( p. def_id , def_id, p. index as usize ) ;
450438 let variance_i = self . xform ( variance, variance_decl) ;
451439 let substs_ty = substs. type_for_def ( p) ;
452440 debug ! ( "add_constraints_from_substs: variance_decl={:?} variance_i={:?}" ,
453- variance_decl, variance_i) ;
441+ variance_decl,
442+ variance_i) ;
454443 self . add_constraints_from_ty ( generics, substs_ty, variance_i) ;
455444 }
456445
457446 for p in region_param_defs {
458- let variance_decl =
459- self . declared_variance ( p. def_id , def_id, p. index as usize ) ;
447+ let variance_decl = self . declared_variance ( p. def_id , def_id, p. index as usize ) ;
460448 let variance_i = self . xform ( variance, variance_decl) ;
461449 let substs_r = substs. region_for_def ( p) ;
462450 self . add_constraints_from_region ( generics, substs_r, variance_i) ;
@@ -494,15 +482,19 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
494482 }
495483 }
496484
497- ty:: ReStatic => { }
485+ ty:: ReStatic => { }
498486
499487 ty:: ReLateBound ( ..) => {
500488 // We do not infer variance for region parameters on
501489 // methods or in fn types.
502490 }
503491
504- ty:: ReFree ( ..) | ty:: ReScope ( ..) | ty:: ReVar ( ..) |
505- ty:: ReSkolemized ( ..) | ty:: ReEmpty | ty:: ReErased => {
492+ ty:: ReFree ( ..) |
493+ ty:: ReScope ( ..) |
494+ ty:: ReVar ( ..) |
495+ ty:: ReSkolemized ( ..) |
496+ ty:: ReEmpty |
497+ ty:: ReErased => {
506498 // We don't expect to see anything but 'static or bound
507499 // regions when visiting member types or method types.
508500 bug ! ( "unexpected region encountered in variance \
0 commit comments