@@ -7,59 +7,42 @@ use crate::traits::{NormalizeExt, Obligation};
77
88#[ extension( pub  trait  StructurallyNormalizeExt <' tcx>) ]  
99impl < ' tcx >  At < ' _ ,  ' tcx >  { 
10-     fn  structurally_normalize < E :  ' tcx > ( 
10+     fn  structurally_normalize_ty < E :  ' tcx > ( 
1111        & self , 
1212        ty :  Ty < ' tcx > , 
1313        fulfill_cx :  & mut  dyn  TraitEngine < ' tcx ,  E > , 
1414    )  -> Result < Ty < ' tcx > ,  Vec < E > >  { 
15-         assert ! ( !ty. is_ty_var( ) ,  "should have resolved vars before calling" ) ; 
16- 
17-         if  self . infcx . next_trait_solver ( )  { 
18-             let  ty:: Alias ( ..)  = * ty. kind ( )  else  { 
19-                 return  Ok ( ty) ; 
20-             } ; 
21- 
22-             let  new_infer_ty = self . infcx . next_ty_var ( self . cause . span ) ; 
23- 
24-             // We simply emit an `alias-eq` goal here, since that will take care of 
25-             // normalizing the LHS of the projection until it is a rigid projection 
26-             // (or a not-yet-defined opaque in scope). 
27-             let  obligation = Obligation :: new ( 
28-                 self . infcx . tcx , 
29-                 self . cause . clone ( ) , 
30-                 self . param_env , 
31-                 ty:: PredicateKind :: AliasRelate ( 
32-                     ty. into ( ) , 
33-                     new_infer_ty. into ( ) , 
34-                     ty:: AliasRelationDirection :: Equate , 
35-                 ) , 
36-             ) ; 
37- 
38-             fulfill_cx. register_predicate_obligation ( self . infcx ,  obligation) ; 
39-             let  errors = fulfill_cx. select_where_possible ( self . infcx ) ; 
40-             if  !errors. is_empty ( )  { 
41-                 return  Err ( errors) ; 
42-             } 
43- 
44-             Ok ( self . infcx . resolve_vars_if_possible ( new_infer_ty) ) 
45-         }  else  { 
46-             Ok ( self . normalize ( ty) . into_value_registering_obligations ( self . infcx ,  fulfill_cx) ) 
47-         } 
15+         self . structurally_normalize_term ( ty. into ( ) ,  fulfill_cx) . map ( |term| term. expect_type ( ) ) 
4816    } 
4917
5018    fn  structurally_normalize_const < E :  ' tcx > ( 
5119        & self , 
5220        ct :  ty:: Const < ' tcx > , 
5321        fulfill_cx :  & mut  dyn  TraitEngine < ' tcx ,  E > , 
5422    )  -> Result < ty:: Const < ' tcx > ,  Vec < E > >  { 
55-         assert ! ( !ct. is_ct_infer( ) ,  "should have resolved vars before calling" ) ; 
23+         if  self . infcx . tcx . features ( ) . generic_const_exprs ( )  { 
24+             return  Ok ( super :: evaluate_const ( & self . infcx ,  ct,  self . param_env ) ) ; 
25+         } 
26+ 
27+         self . structurally_normalize_term ( ct. into ( ) ,  fulfill_cx) . map ( |term| term. expect_const ( ) ) 
28+     } 
29+ 
30+     fn  structurally_normalize_term < E :  ' tcx > ( 
31+         & self , 
32+         term :  ty:: Term < ' tcx > , 
33+         fulfill_cx :  & mut  dyn  TraitEngine < ' tcx ,  E > , 
34+     )  -> Result < ty:: Term < ' tcx > ,  Vec < E > >  { 
35+         assert ! ( !term. is_infer( ) ,  "should have resolved vars before calling" ) ; 
5636
5737        if  self . infcx . next_trait_solver ( )  { 
58-             let  ty :: ConstKind :: Unevaluated ( .. )  = ct . kind ( )   else  { 
59-                 return  Ok ( ct ) ; 
60-             } ; 
38+             if   let  None  = term . to_alias_term ( )  { 
39+                 return  Ok ( term ) ; 
40+             } 
6141
62-             let  new_infer_ct = self . infcx . next_const_var ( self . cause . span ) ; 
42+             let  new_infer = match  term. unpack ( )  { 
43+                 ty:: TermKind :: Ty ( _)  => self . infcx . next_ty_var ( self . cause . span ) . into ( ) , 
44+                 ty:: TermKind :: Const ( _)  => self . infcx . next_const_var ( self . cause . span ) . into ( ) , 
45+             } ; 
6346
6447            // We simply emit an `alias-eq` goal here, since that will take care of 
6548            // normalizing the LHS of the projection until it is a rigid projection 
@@ -68,11 +51,7 @@ impl<'tcx> At<'_, 'tcx> {
6851                self . infcx . tcx , 
6952                self . cause . clone ( ) , 
7053                self . param_env , 
71-                 ty:: PredicateKind :: AliasRelate ( 
72-                     ct. into ( ) , 
73-                     new_infer_ct. into ( ) , 
74-                     ty:: AliasRelationDirection :: Equate , 
75-                 ) , 
54+                 ty:: PredicateKind :: AliasRelate ( term,  new_infer,  ty:: AliasRelationDirection :: Equate ) , 
7655            ) ; 
7756
7857            fulfill_cx. register_predicate_obligation ( self . infcx ,  obligation) ; 
@@ -81,11 +60,9 @@ impl<'tcx> At<'_, 'tcx> {
8160                return  Err ( errors) ; 
8261            } 
8362
84-             Ok ( self . infcx . resolve_vars_if_possible ( new_infer_ct) ) 
85-         }  else  if  self . infcx . tcx . features ( ) . generic_const_exprs ( )  { 
86-             Ok ( super :: evaluate_const ( & self . infcx ,  ct,  self . param_env ) ) 
63+             Ok ( self . infcx . resolve_vars_if_possible ( new_infer) ) 
8764        }  else  { 
88-             Ok ( self . normalize ( ct ) . into_value_registering_obligations ( self . infcx ,  fulfill_cx) ) 
65+             Ok ( self . normalize ( term ) . into_value_registering_obligations ( self . infcx ,  fulfill_cx) ) 
8966        } 
9067    } 
9168} 
0 commit comments