@@ -801,7 +801,7 @@ impl<'a, 'gcx, 'tcx> Struct {
801
801
}
802
802
803
803
( _, & ty:: TyProjection ( _) ) | ( _, & ty:: TyAnon ( ..) ) => {
804
- let normalized = normalize_associated_type ( infcx, ty) ;
804
+ let normalized = infcx. normalize_projections ( ty) ;
805
805
if ty == normalized {
806
806
return Ok ( None ) ;
807
807
}
@@ -1020,28 +1020,6 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
1020
1020
}
1021
1021
}
1022
1022
1023
- /// Helper function for normalizing associated types in an inference context.
1024
- fn normalize_associated_type < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
1025
- ty : Ty < ' gcx > )
1026
- -> Ty < ' gcx > {
1027
- if !ty. has_projection_types ( ) {
1028
- return ty;
1029
- }
1030
-
1031
- let mut selcx = traits:: SelectionContext :: new ( infcx) ;
1032
- let cause = traits:: ObligationCause :: dummy ( ) ;
1033
- let traits:: Normalized { value : result, obligations } =
1034
- traits:: normalize ( & mut selcx, cause, & ty) ;
1035
-
1036
- let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1037
-
1038
- for obligation in obligations {
1039
- fulfill_cx. register_predicate_obligation ( infcx, obligation) ;
1040
- }
1041
-
1042
- infcx. drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & result)
1043
- }
1044
-
1045
1023
impl < ' a , ' gcx , ' tcx > Layout {
1046
1024
pub fn compute_uncached ( ty : Ty < ' gcx > ,
1047
1025
infcx : & InferCtxt < ' a , ' gcx , ' tcx > )
@@ -1053,7 +1031,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1053
1031
1054
1032
let ptr_layout = |pointee : Ty < ' gcx > | {
1055
1033
let non_zero = !ty. is_unsafe_ptr ( ) ;
1056
- let pointee = normalize_associated_type ( infcx, pointee) ;
1034
+ let pointee = infcx. normalize_projections ( pointee) ;
1057
1035
if pointee. is_sized ( tcx, & infcx. parameter_environment , DUMMY_SP ) {
1058
1036
Ok ( Scalar { value : Pointer , non_zero : non_zero } )
1059
1037
} else {
@@ -1441,7 +1419,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1441
1419
1442
1420
// Types with no meaningful known layout.
1443
1421
ty:: TyProjection ( _) | ty:: TyAnon ( ..) => {
1444
- let normalized = normalize_associated_type ( infcx, ty) ;
1422
+ let normalized = infcx. normalize_projections ( ty) ;
1445
1423
if ty == normalized {
1446
1424
return Err ( LayoutError :: Unknown ( ty) ) ;
1447
1425
}
@@ -1735,7 +1713,7 @@ impl<'a, 'gcx, 'tcx> SizeSkeleton<'gcx> {
1735
1713
}
1736
1714
1737
1715
ty:: TyProjection ( _) | ty:: TyAnon ( ..) => {
1738
- let normalized = normalize_associated_type ( infcx, ty) ;
1716
+ let normalized = infcx. normalize_projections ( ty) ;
1739
1717
if ty == normalized {
1740
1718
Err ( err)
1741
1719
} else {
@@ -1805,20 +1783,40 @@ pub trait LayoutTyper<'tcx>: HasTyCtxt<'tcx> {
1805
1783
type TyLayout ;
1806
1784
1807
1785
fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout ;
1786
+ fn normalize_projections ( self , ty : Ty < ' tcx > ) -> Ty < ' tcx > ;
1808
1787
}
1809
1788
1810
1789
impl < ' a , ' gcx , ' tcx > LayoutTyper < ' gcx > for & ' a InferCtxt < ' a , ' gcx , ' tcx > {
1811
1790
type TyLayout = Result < TyLayout < ' gcx > , LayoutError < ' gcx > > ;
1812
1791
1813
1792
fn layout_of ( self , ty : Ty < ' gcx > ) -> Self :: TyLayout {
1814
- let ty = normalize_associated_type ( self , ty) ;
1793
+ let ty = self . normalize_projections ( ty) ;
1815
1794
1816
1795
Ok ( TyLayout {
1817
1796
ty : ty,
1818
1797
layout : ty. layout ( self ) ?,
1819
1798
variant_index : None
1820
1799
} )
1821
1800
}
1801
+
1802
+ fn normalize_projections ( self , ty : Ty < ' gcx > ) -> Ty < ' gcx > {
1803
+ if !ty. has_projection_types ( ) {
1804
+ return ty;
1805
+ }
1806
+
1807
+ let mut selcx = traits:: SelectionContext :: new ( self ) ;
1808
+ let cause = traits:: ObligationCause :: dummy ( ) ;
1809
+ let traits:: Normalized { value : result, obligations } =
1810
+ traits:: normalize ( & mut selcx, cause, & ty) ;
1811
+
1812
+ let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1813
+
1814
+ for obligation in obligations {
1815
+ fulfill_cx. register_predicate_obligation ( self , obligation) ;
1816
+ }
1817
+
1818
+ self . drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & result)
1819
+ }
1822
1820
}
1823
1821
1824
1822
impl < ' a , ' tcx > TyLayout < ' tcx > {
@@ -1942,6 +1940,6 @@ impl<'a, 'tcx> TyLayout<'tcx> {
1942
1940
}
1943
1941
1944
1942
pub fn field < C : LayoutTyper < ' tcx > > ( & self , cx : C , i : usize ) -> C :: TyLayout {
1945
- cx. layout_of ( self . field_type ( cx, i) )
1943
+ cx. layout_of ( cx . normalize_projections ( self . field_type ( cx, i) ) )
1946
1944
}
1947
1945
}
0 commit comments