17
17
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
18
18
//! contain revealed `impl Trait` values).
19
19
20
- use borrow_check:: nll:: renumber;
21
- use borrow_check:: nll:: type_check:: free_region_relations:: UniversalRegionRelations ;
22
20
use borrow_check:: nll:: universal_regions:: UniversalRegions ;
23
- use rustc:: hir:: def_id:: DefId ;
24
- use rustc:: infer:: InferOk ;
25
21
use rustc:: mir:: * ;
26
- use rustc:: traits:: query:: type_op:: custom:: CustomTypeOp ;
27
- use rustc:: traits:: { ObligationCause , PredicateObligations } ;
28
- use rustc:: ty:: subst:: Subst ;
29
22
use rustc:: ty:: Ty ;
30
23
31
24
use rustc_data_structures:: indexed_vec:: Idx ;
@@ -37,16 +30,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
37
30
pub ( super ) fn equate_inputs_and_outputs (
38
31
& mut self ,
39
32
mir : & Mir < ' tcx > ,
40
- mir_def_id : DefId ,
41
33
universal_regions : & UniversalRegions < ' tcx > ,
42
- universal_region_relations : & UniversalRegionRelations < ' tcx > ,
43
34
normalized_inputs_and_output : & [ Ty < ' tcx > ] ,
44
35
) {
45
- let tcx = self . infcx . tcx ;
46
-
47
36
let ( & normalized_output_ty, normalized_input_tys) =
48
37
normalized_inputs_and_output. split_last ( ) . unwrap ( ) ;
49
- let infcx = self . infcx ;
50
38
51
39
// Equate expected input tys with those in the MIR.
52
40
let argument_locals = ( 1 ..) . map ( Local :: new) ;
@@ -77,111 +65,23 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
77
65
78
66
// Return types are a bit more complex. They may contain existential `impl Trait`
79
67
// types.
80
- let param_env = self . param_env ;
81
68
let mir_output_ty = mir. local_decls [ RETURN_PLACE ] . ty ;
82
69
let output_span = mir. local_decls [ RETURN_PLACE ] . source_info . span ;
83
- let opaque_type_map =
84
- self . fully_perform_op (
85
- Locations :: All ( output_span) ,
86
- ConstraintCategory :: BoringNoLocation ,
87
- CustomTypeOp :: new (
88
- |infcx| {
89
- let mut obligations = ObligationAccumulator :: default ( ) ;
90
-
91
- let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
92
- let ( output_ty, opaque_type_map) =
93
- obligations. add ( infcx. instantiate_opaque_types (
94
- mir_def_id,
95
- dummy_body_id,
96
- param_env,
97
- & normalized_output_ty,
98
- ) ) ;
99
- debug ! (
100
- "equate_inputs_and_outputs: instantiated output_ty={:?}" ,
101
- output_ty
102
- ) ;
103
- debug ! (
104
- "equate_inputs_and_outputs: opaque_type_map={:#?}" ,
105
- opaque_type_map
106
- ) ;
107
-
108
- debug ! (
109
- "equate_inputs_and_outputs: mir_output_ty={:?}" ,
110
- mir_output_ty
111
- ) ;
112
- obligations. add (
113
- infcx
114
- . at ( & ObligationCause :: dummy ( ) , param_env)
115
- . eq ( output_ty, mir_output_ty) ?,
116
- ) ;
117
-
118
- for ( & opaque_def_id, opaque_decl) in & opaque_type_map {
119
- let opaque_defn_ty = tcx. type_of ( opaque_def_id) ;
120
- let opaque_defn_ty = opaque_defn_ty. subst ( tcx, opaque_decl. substs ) ;
121
- let opaque_defn_ty = renumber:: renumber_regions (
122
- infcx,
123
- & opaque_defn_ty,
124
- ) ;
125
- debug ! (
126
- "equate_inputs_and_outputs: concrete_ty={:?}" ,
127
- opaque_decl. concrete_ty
128
- ) ;
129
- debug ! ( "equate_inputs_and_outputs: opaque_defn_ty={:?}" ,
130
- opaque_defn_ty) ;
131
- obligations. add (
132
- infcx
133
- . at ( & ObligationCause :: dummy ( ) , param_env)
134
- . eq ( opaque_decl. concrete_ty , opaque_defn_ty) ?,
135
- ) ;
136
- }
137
-
138
- debug ! ( "equate_inputs_and_outputs: equated" ) ;
139
-
140
- Ok ( InferOk {
141
- value : Some ( opaque_type_map) ,
142
- obligations : obligations. into_vec ( ) ,
143
- } )
144
- } ,
145
- || "input_output" . to_string ( ) ,
146
- ) ,
147
- ) . unwrap_or_else ( |terr| {
148
- span_mirbug ! (
149
- self ,
150
- Location :: START ,
151
- "equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`" ,
152
- normalized_output_ty,
153
- mir_output_ty,
154
- terr
155
- ) ;
156
- None
157
- } ) ;
158
-
159
- // Finally, if we instantiated the opaque types successfully, we
160
- // have to solve any bounds (e.g., `-> impl Iterator` needs to
161
- // prove that `T: Iterator` where `T` is the type we
162
- // instantiated it with).
163
- if let Some ( opaque_type_map) = opaque_type_map {
164
- for ( opaque_def_id, opaque_decl) in opaque_type_map {
165
- self . fully_perform_op (
166
- Locations :: All ( infcx. tcx . def_span ( opaque_def_id) ) ,
167
- ConstraintCategory :: OpaqueType ,
168
- CustomTypeOp :: new (
169
- |_cx| {
170
- infcx. constrain_opaque_type (
171
- opaque_def_id,
172
- & opaque_decl,
173
- universal_region_relations
174
- ) ;
175
- Ok ( InferOk {
176
- value : ( ) ,
177
- obligations : vec ! [ ] ,
178
- } )
179
- } ,
180
- || "opaque_type_map" . to_string ( ) ,
181
- ) ,
182
- ) . unwrap ( ) ;
183
- }
184
- }
70
+ if let Err ( terr) = self . eq_opaque_type_and_type (
71
+ mir_output_ty,
72
+ normalized_output_ty,
73
+ Locations :: All ( output_span) ,
74
+ ConstraintCategory :: BoringNoLocation ,
75
+ ) {
76
+ span_mirbug ! (
77
+ self ,
78
+ Location :: START ,
79
+ "equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`" ,
80
+ normalized_output_ty,
81
+ mir_output_ty,
82
+ terr
83
+ ) ;
84
+ } ;
185
85
}
186
86
187
87
fn equate_normalized_input_or_output ( & mut self , a : Ty < ' tcx > , b : Ty < ' tcx > , span : Span ) {
@@ -204,20 +104,3 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
204
104
}
205
105
}
206
106
}
207
-
208
- #[ derive( Debug , Default ) ]
209
- struct ObligationAccumulator < ' tcx > {
210
- obligations : PredicateObligations < ' tcx > ,
211
- }
212
-
213
- impl < ' tcx > ObligationAccumulator < ' tcx > {
214
- fn add < T > ( & mut self , value : InferOk < ' tcx , T > ) -> T {
215
- let InferOk { value, obligations } = value;
216
- self . obligations . extend ( obligations) ;
217
- value
218
- }
219
-
220
- fn into_vec ( self ) -> PredicateObligations < ' tcx > {
221
- self . obligations
222
- }
223
- }
0 commit comments