@@ -822,7 +822,7 @@ impl<'a, 'gcx, 'tcx> Struct {
822
822
}
823
823
824
824
( _, & ty:: TyProjection ( _) ) | ( _, & ty:: TyAnon ( ..) ) => {
825
- let normalized = normalize_associated_type ( infcx, ty) ;
825
+ let normalized = infcx. normalize_projections ( ty) ;
826
826
if ty == normalized {
827
827
return Ok ( None ) ;
828
828
}
@@ -1067,28 +1067,6 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
1067
1067
}
1068
1068
}
1069
1069
1070
- /// Helper function for normalizing associated types in an inference context.
1071
- fn normalize_associated_type < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
1072
- ty : Ty < ' gcx > )
1073
- -> Ty < ' gcx > {
1074
- if !ty. has_projection_types ( ) {
1075
- return ty;
1076
- }
1077
-
1078
- let mut selcx = traits:: SelectionContext :: new ( infcx) ;
1079
- let cause = traits:: ObligationCause :: dummy ( ) ;
1080
- let traits:: Normalized { value : result, obligations } =
1081
- traits:: normalize ( & mut selcx, cause, & ty) ;
1082
-
1083
- let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1084
-
1085
- for obligation in obligations {
1086
- fulfill_cx. register_predicate_obligation ( infcx, obligation) ;
1087
- }
1088
-
1089
- infcx. drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & result)
1090
- }
1091
-
1092
1070
impl < ' a , ' gcx , ' tcx > Layout {
1093
1071
pub fn compute_uncached ( ty : Ty < ' gcx > ,
1094
1072
infcx : & InferCtxt < ' a , ' gcx , ' tcx > )
@@ -1100,7 +1078,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1100
1078
1101
1079
let ptr_layout = |pointee : Ty < ' gcx > | {
1102
1080
let non_zero = !ty. is_unsafe_ptr ( ) ;
1103
- let pointee = normalize_associated_type ( infcx, pointee) ;
1081
+ let pointee = infcx. normalize_projections ( pointee) ;
1104
1082
if pointee. is_sized ( tcx, & infcx. parameter_environment , DUMMY_SP ) {
1105
1083
Ok ( Scalar { value : Pointer , non_zero : non_zero } )
1106
1084
} else {
@@ -1494,7 +1472,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1494
1472
1495
1473
// Types with no meaningful known layout.
1496
1474
ty:: TyProjection ( _) | ty:: TyAnon ( ..) => {
1497
- let normalized = normalize_associated_type ( infcx, ty) ;
1475
+ let normalized = infcx. normalize_projections ( ty) ;
1498
1476
if ty == normalized {
1499
1477
return Err ( LayoutError :: Unknown ( ty) ) ;
1500
1478
}
@@ -1812,7 +1790,7 @@ impl<'a, 'gcx, 'tcx> SizeSkeleton<'gcx> {
1812
1790
}
1813
1791
1814
1792
ty:: TyProjection ( _) | ty:: TyAnon ( ..) => {
1815
- let normalized = normalize_associated_type ( infcx, ty) ;
1793
+ let normalized = infcx. normalize_projections ( ty) ;
1816
1794
if ty == normalized {
1817
1795
Err ( err)
1818
1796
} else {
@@ -1882,20 +1860,40 @@ pub trait LayoutTyper<'tcx>: HasTyCtxt<'tcx> {
1882
1860
type TyLayout ;
1883
1861
1884
1862
fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout ;
1863
+ fn normalize_projections ( self , ty : Ty < ' tcx > ) -> Ty < ' tcx > ;
1885
1864
}
1886
1865
1887
1866
impl < ' a , ' gcx , ' tcx > LayoutTyper < ' gcx > for & ' a InferCtxt < ' a , ' gcx , ' tcx > {
1888
1867
type TyLayout = Result < TyLayout < ' gcx > , LayoutError < ' gcx > > ;
1889
1868
1890
1869
fn layout_of ( self , ty : Ty < ' gcx > ) -> Self :: TyLayout {
1891
- let ty = normalize_associated_type ( self , ty) ;
1870
+ let ty = self . normalize_projections ( ty) ;
1892
1871
1893
1872
Ok ( TyLayout {
1894
1873
ty : ty,
1895
1874
layout : ty. layout ( self ) ?,
1896
1875
variant_index : None
1897
1876
} )
1898
1877
}
1878
+
1879
+ fn normalize_projections ( self , ty : Ty < ' gcx > ) -> Ty < ' gcx > {
1880
+ if !ty. has_projection_types ( ) {
1881
+ return ty;
1882
+ }
1883
+
1884
+ let mut selcx = traits:: SelectionContext :: new ( self ) ;
1885
+ let cause = traits:: ObligationCause :: dummy ( ) ;
1886
+ let traits:: Normalized { value : result, obligations } =
1887
+ traits:: normalize ( & mut selcx, cause, & ty) ;
1888
+
1889
+ let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
1890
+
1891
+ for obligation in obligations {
1892
+ fulfill_cx. register_predicate_obligation ( self , obligation) ;
1893
+ }
1894
+
1895
+ self . drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & result)
1896
+ }
1899
1897
}
1900
1898
1901
1899
impl < ' a , ' tcx > TyLayout < ' tcx > {
@@ -2019,6 +2017,6 @@ impl<'a, 'tcx> TyLayout<'tcx> {
2019
2017
}
2020
2018
2021
2019
pub fn field < C : LayoutTyper < ' tcx > > ( & self , cx : C , i : usize ) -> C :: TyLayout {
2022
- cx. layout_of ( self . field_type ( cx, i) )
2020
+ cx. layout_of ( cx . normalize_projections ( self . field_type ( cx, i) ) )
2023
2021
}
2024
2022
}
0 commit comments