@@ -7,59 +7,42 @@ use crate::traits::{NormalizeExt, Obligation};
7
7
8
8
#[ extension( pub trait StructurallyNormalizeExt <' tcx>) ]
9
9
impl < ' tcx > At < ' _ , ' tcx > {
10
- fn structurally_normalize < E : ' tcx > (
10
+ fn structurally_normalize_ty < E : ' tcx > (
11
11
& self ,
12
12
ty : Ty < ' tcx > ,
13
13
fulfill_cx : & mut dyn TraitEngine < ' tcx , E > ,
14
14
) -> 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 ( ) )
48
16
}
49
17
50
18
fn structurally_normalize_const < E : ' tcx > (
51
19
& self ,
52
20
ct : ty:: Const < ' tcx > ,
53
21
fulfill_cx : & mut dyn TraitEngine < ' tcx , E > ,
54
22
) -> 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" ) ;
56
36
57
37
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
+ }
61
41
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
+ } ;
63
46
64
47
// We simply emit an `alias-eq` goal here, since that will take care of
65
48
// normalizing the LHS of the projection until it is a rigid projection
@@ -68,11 +51,7 @@ impl<'tcx> At<'_, 'tcx> {
68
51
self . infcx . tcx ,
69
52
self . cause . clone ( ) ,
70
53
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 ) ,
76
55
) ;
77
56
78
57
fulfill_cx. register_predicate_obligation ( self . infcx , obligation) ;
@@ -81,11 +60,9 @@ impl<'tcx> At<'_, 'tcx> {
81
60
return Err ( errors) ;
82
61
}
83
62
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) )
87
64
} 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) )
89
66
}
90
67
}
91
68
}
0 commit comments