@@ -57,28 +57,10 @@ impl<'tcx> UniverseInfo<'tcx> {
57
57
error_element : RegionElement ,
58
58
cause : ObligationCause < ' tcx > ,
59
59
) {
60
- match * self {
61
- UniverseInfo :: RelateTys { expected, found } => {
62
- let err = mbcx. infcx . err_ctxt ( ) . report_mismatched_types (
63
- & cause,
64
- mbcx. infcx . param_env ,
65
- expected,
66
- found,
67
- TypeError :: RegionsPlaceholderMismatch ,
68
- ) ;
69
- mbcx. buffer_error ( err) ;
70
- }
71
- UniverseInfo :: TypeOp ( ref type_op_info) => {
72
- type_op_info. report_erroneous_element ( mbcx, placeholder, error_element, cause) ;
73
- }
74
- UniverseInfo :: Other => {
75
- // FIXME: This error message isn't great, but it doesn't show
76
- // up in the existing UI tests. Consider investigating this
77
- // some more.
78
- mbcx. buffer_error (
79
- mbcx. dcx ( ) . create_err ( HigherRankedSubtypeError { span : cause. span } ) ,
80
- ) ;
81
- }
60
+ if let UniverseInfo :: TypeOp ( ref type_op_info) = * self {
61
+ type_op_info. report_erroneous_element ( mbcx, placeholder, error_element, cause) ;
62
+ } else {
63
+ self . report_generic_error ( mbcx, cause) ;
82
64
}
83
65
}
84
66
@@ -90,7 +72,18 @@ impl<'tcx> UniverseInfo<'tcx> {
90
72
cause : ObligationCause < ' tcx > ,
91
73
placeholder_b : ty:: PlaceholderRegion ,
92
74
) {
93
- // FIXME(amandasystems) this function is now a direct copy of the one above and that's not great.
75
+ if let UniverseInfo :: TypeOp ( ref type_op_info) = * self {
76
+ type_op_info. report_placeholder_mismatch ( mbcx, placeholder_a, cause, placeholder_b) ;
77
+ } else {
78
+ self . report_generic_error ( mbcx, cause) ;
79
+ }
80
+ }
81
+
82
+ fn report_generic_error (
83
+ & self ,
84
+ mbcx : & mut MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
85
+ cause : ObligationCause < ' tcx > ,
86
+ ) {
94
87
match * self {
95
88
UniverseInfo :: RelateTys { expected, found } => {
96
89
let err = mbcx. infcx . err_ctxt ( ) . report_mismatched_types (
@@ -102,9 +95,8 @@ impl<'tcx> UniverseInfo<'tcx> {
102
95
) ;
103
96
mbcx. buffer_error ( err) ;
104
97
}
105
- UniverseInfo :: TypeOp ( ref type_op_info) => {
106
- // FIXME(amandasystems) maybe...I can just use the type error above?!?!?!?!
107
- type_op_info. report_placeholder_mismatch ( mbcx, placeholder_a, cause, placeholder_b) ;
98
+ UniverseInfo :: TypeOp ( _) => {
99
+ unreachable ! ( "This case should already have been handled!" ) ;
108
100
}
109
101
UniverseInfo :: Other => {
110
102
// FIXME: This error message isn't great, but it doesn't show
@@ -189,46 +181,42 @@ pub(crate) trait TypeOpInfo<'tcx> {
189
181
cause : ObligationCause < ' tcx > ,
190
182
placeholder_b : ty:: PlaceholderRegion ,
191
183
) {
192
- // FIXME(amandasystems) -- this fn is a duplicate of the one below and it shouldn't be.
193
- // This really is the dumbest version of this function.
194
184
let tcx = mbcx. infcx . tcx ;
195
- let base_universe = self . base_universe ( ) ;
196
- debug ! ( ?base_universe) ;
197
185
198
- let Some ( adjusted_universe_a) =
199
- placeholder_a. universe . as_u32 ( ) . checked_sub ( base_universe. as_u32 ( ) )
200
- else {
201
- mbcx. buffer_error ( self . fallback_error ( tcx, cause. span ) ) ;
202
- return ;
203
- } ;
204
-
205
- let Some ( adjusted_universe_b) =
206
- placeholder_b. universe . as_u32 ( ) . checked_sub ( base_universe. as_u32 ( ) )
207
- else {
208
- mbcx. buffer_error ( self . fallback_error ( tcx, cause. span ) ) ;
209
- return ;
210
- } ;
211
-
212
- let placeholder_a = ty:: Region :: new_placeholder (
213
- tcx,
214
- ty:: Placeholder { universe : adjusted_universe_a. into ( ) , bound : placeholder_a. bound } ,
215
- ) ;
216
-
217
- let placeholder_b = ty:: Region :: new_placeholder (
218
- tcx,
219
- ty:: Placeholder { universe : adjusted_universe_b. into ( ) , bound : placeholder_b. bound } ,
220
- ) ;
186
+ let placeholder_a = self . region_with_adjusted_universe ( placeholder_a, tcx) ;
187
+ let placeholder_b = self . region_with_adjusted_universe ( placeholder_b, tcx) ;
221
188
222
189
debug ! ( ?placeholder_a, ?placeholder_b) ;
223
190
224
191
let span = cause. span ;
225
- // FIXME(amandasystems) -- propagate or flatten the changes and remove error_region here.
192
+ // FIXME: see note in `report_erroneous_element()` below!
226
193
let nice_error = self . nice_error ( mbcx, cause, placeholder_a, Some ( placeholder_b) ) ;
227
- // I think this should never fail?!
228
194
debug ! ( ?nice_error) ;
229
195
mbcx. buffer_error ( nice_error. unwrap_or_else ( || self . fallback_error ( tcx, span) ) ) ;
230
196
}
231
197
198
+ /// Turn a placeholder region into a Region with its universe adjusted by
199
+ /// the base universe.
200
+ fn region_with_adjusted_universe (
201
+ & self ,
202
+ placeholder : ty:: PlaceholderRegion ,
203
+ tcx : TyCtxt < ' tcx > ,
204
+ ) -> ty:: Region < ' tcx > {
205
+ let Some ( adjusted_universe) =
206
+ placeholder. universe . as_u32 ( ) . checked_sub ( self . base_universe ( ) . as_u32 ( ) )
207
+ else {
208
+ unreachable ! (
209
+ "Could not adjust universe {:?} of {placeholder:?} by base universe {:?}" ,
210
+ placeholder. universe,
211
+ self . base_universe( )
212
+ ) ;
213
+ } ;
214
+ ty:: Region :: new_placeholder (
215
+ tcx,
216
+ ty:: Placeholder { universe : adjusted_universe. into ( ) , bound : placeholder. bound } ,
217
+ )
218
+ }
219
+
232
220
#[ instrument( level = "debug" , skip( self , mbcx) ) ]
233
221
fn report_erroneous_element (
234
222
& self ,
@@ -238,28 +226,22 @@ pub(crate) trait TypeOpInfo<'tcx> {
238
226
cause : ObligationCause < ' tcx > ,
239
227
) {
240
228
let tcx = mbcx. infcx . tcx ;
241
- let base_universe = self . base_universe ( ) ;
242
- debug ! ( ?base_universe) ;
243
229
244
- let Some ( adjusted_universe) =
245
- placeholder. universe . as_u32 ( ) . checked_sub ( base_universe. as_u32 ( ) )
246
- else {
247
- mbcx. buffer_error ( self . fallback_error ( tcx, cause. span ) ) ;
248
- return ;
249
- } ;
250
-
251
- // FIXME(amandasystems) -- construct this earlier when we have
252
- // adjusted universes and pass it in rather than placeholder
253
- let placeholder_region = ty:: Region :: new_placeholder (
254
- tcx,
255
- ty:: Placeholder { universe : adjusted_universe. into ( ) , bound : placeholder. bound } ,
256
- ) ;
230
+ // FIXME: these adjusted universes are not (always) the same ones as we compute
231
+ // earlier. They probably should be, but the logic downstream is complicated,
232
+ // and assumes they use whatever this is.
233
+ //
234
+ // In fact, this function throws away a lot of interesting information that would
235
+ // probably allow bypassing lots of logic downstream for a much simpler flow.
236
+ let placeholder_region = self . region_with_adjusted_universe ( placeholder, tcx) ;
257
237
258
238
debug ! ( ?placeholder_region) ;
259
239
260
240
let span = cause. span ;
261
- // FIXME(amandasystems) -- propagate or flatten the changes and remove error_region here.
262
- // --- I think we always fall back!!!
241
+ // FIXME: it's not good that we have one variant that always sends None,
242
+ // and one variant with always sends Some. We should break out these code
243
+ // paths -- but the downstream code is complicated and that's not straight-
244
+ // forward.
263
245
let nice_error = self . nice_error ( mbcx, cause, placeholder_region, None ) ;
264
246
265
247
debug ! ( ?nice_error) ;
@@ -286,7 +268,6 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
286
268
self . base_universe
287
269
}
288
270
289
- // NOTE(amandasystems) this is the method being executed!
290
271
fn nice_error < ' infcx > (
291
272
& self ,
292
273
mbcx : & mut MirBorrowckCtxt < ' _ , ' infcx , ' tcx > ,
0 commit comments