22
22
//! constituents)
23
23
24
24
use crate :: infer:: InferCtxt ;
25
+ use crate :: traits:: DomainGoal ;
26
+ use crate :: ty:: error:: TypeError ;
25
27
use crate :: ty:: fold:: { TypeFoldable , TypeVisitor } ;
26
28
use crate :: ty:: relate:: { self , Relate , RelateResult , TypeRelation } ;
27
29
use crate :: ty:: subst:: Kind ;
28
30
use crate :: ty:: { self , Ty , TyCtxt } ;
29
- use crate :: ty:: error:: TypeError ;
30
- use crate :: traits:: DomainGoal ;
31
31
use rustc_data_structures:: fx:: FxHashMap ;
32
32
33
33
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
@@ -266,15 +266,17 @@ where
266
266
fn relate_projection_ty (
267
267
& mut self ,
268
268
projection_ty : ty:: ProjectionTy < ' tcx > ,
269
- value_ty : ty:: Ty < ' tcx >
269
+ value_ty : ty:: Ty < ' tcx > ,
270
270
) -> Ty < ' tcx > {
271
271
use crate :: infer:: type_variable:: TypeVariableOrigin ;
272
272
use crate :: traits:: WhereClause ;
273
273
use syntax_pos:: DUMMY_SP ;
274
274
275
275
match value_ty. sty {
276
276
ty:: Projection ( other_projection_ty) => {
277
- let var = self . infcx . next_ty_var ( TypeVariableOrigin :: MiscVariable ( DUMMY_SP ) ) ;
277
+ let var = self
278
+ . infcx
279
+ . next_ty_var ( TypeVariableOrigin :: MiscVariable ( DUMMY_SP ) ) ;
278
280
self . relate_projection_ty ( projection_ty, var) ;
279
281
self . relate_projection_ty ( other_projection_ty, var) ;
280
282
var
@@ -285,9 +287,8 @@ where
285
287
projection_ty,
286
288
ty : value_ty,
287
289
} ;
288
- self . delegate . push_domain_goal (
289
- DomainGoal :: Holds ( WhereClause :: ProjectionEq ( projection) )
290
- ) ;
290
+ self . delegate
291
+ . push_domain_goal ( DomainGoal :: Holds ( WhereClause :: ProjectionEq ( projection) ) ) ;
291
292
value_ty
292
293
}
293
294
}
@@ -297,20 +298,21 @@ where
297
298
fn relate_ty_var (
298
299
& mut self ,
299
300
vid : ty:: TyVid ,
300
- value_ty : Ty < ' tcx >
301
+ value_ty : Ty < ' tcx > ,
301
302
) -> RelateResult < ' tcx , Ty < ' tcx > > {
302
303
debug ! ( "relate_ty_var(vid={:?}, value_ty={:?})" , vid, value_ty) ;
303
304
304
305
match value_ty. sty {
305
306
ty:: Infer ( ty:: TyVar ( value_vid) ) => {
306
307
// Two type variables: just equate them.
307
- self . infcx . type_variables . borrow_mut ( ) . equate ( vid, value_vid) ;
308
+ self . infcx
309
+ . type_variables
310
+ . borrow_mut ( )
311
+ . equate ( vid, value_vid) ;
308
312
return Ok ( value_ty) ;
309
313
}
310
314
311
- ty:: Projection ( projection_ty)
312
- if D :: normalization ( ) == NormalizationStrategy :: Lazy =>
313
- {
315
+ ty:: Projection ( projection_ty) if D :: normalization ( ) == NormalizationStrategy :: Lazy => {
314
316
return Ok ( self . relate_projection_ty ( projection_ty, self . infcx . tcx . mk_ty_var ( vid) ) ) ;
315
317
}
316
318
@@ -327,7 +329,10 @@ where
327
329
assert ! ( !generalized_ty. has_infer_types( ) ) ;
328
330
}
329
331
330
- self . infcx . type_variables . borrow_mut ( ) . instantiate ( vid, generalized_ty) ;
332
+ self . infcx
333
+ . type_variables
334
+ . borrow_mut ( )
335
+ . instantiate ( vid, generalized_ty) ;
331
336
332
337
// The generalized values we extract from `canonical_var_values` have
333
338
// been fully instantiated and hence the set of scopes we have
@@ -348,7 +353,7 @@ where
348
353
fn generalize_value < T : Relate < ' tcx > > (
349
354
& mut self ,
350
355
value : T ,
351
- for_vid : ty:: TyVid
356
+ for_vid : ty:: TyVid ,
352
357
) -> RelateResult < ' tcx , T > {
353
358
let universe = self . infcx . probe_ty_var ( for_vid) . unwrap_err ( ) ;
354
359
@@ -764,7 +769,9 @@ where
764
769
drop ( variables) ;
765
770
self . relate ( & u, & u)
766
771
}
767
- TypeVariableValue :: Unknown { universe : _universe } => {
772
+ TypeVariableValue :: Unknown {
773
+ universe : _universe,
774
+ } => {
768
775
if self . ambient_variance == ty:: Bivariant {
769
776
// FIXME: we may need a WF predicate (related to #54105).
770
777
}
@@ -779,17 +786,15 @@ where
779
786
let u = self . tcx ( ) . mk_ty_var ( new_var_id) ;
780
787
debug ! (
781
788
"generalize: replacing original vid={:?} with new={:?}" ,
782
- vid,
783
- u
789
+ vid, u
784
790
) ;
785
791
return Ok ( u) ;
786
792
}
787
793
}
788
794
}
789
795
}
790
796
791
- ty:: Infer ( ty:: IntVar ( _) ) |
792
- ty:: Infer ( ty:: FloatVar ( _) ) => {
797
+ ty:: Infer ( ty:: IntVar ( _) ) | ty:: Infer ( ty:: FloatVar ( _) ) => {
793
798
// No matter what mode we are in,
794
799
// integer/floating-point types must be equal to be
795
800
// relatable.
@@ -800,19 +805,16 @@ where
800
805
if self . universe . cannot_name ( placeholder. universe ) {
801
806
debug ! (
802
807
"TypeGeneralizer::tys: root universe {:?} cannot name\
803
- placeholder in universe {:?}",
804
- self . universe,
805
- placeholder. universe
808
+ placeholder in universe {:?}",
809
+ self . universe, placeholder. universe
806
810
) ;
807
811
Err ( TypeError :: Mismatch )
808
812
} else {
809
813
Ok ( a)
810
814
}
811
815
}
812
816
813
- _ => {
814
- relate:: super_relate_tys ( self , a, a)
815
- }
817
+ _ => relate:: super_relate_tys ( self , a, a) ,
816
818
}
817
819
}
818
820
0 commit comments