@@ -24,7 +24,6 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_
24
24
use tracing:: { debug, instrument} ;
25
25
26
26
use crate :: MirBorrowckCtxt ;
27
- use crate :: region_infer:: values:: RegionElement ;
28
27
use crate :: session_diagnostics:: {
29
28
HigherRankedErrorCause , HigherRankedLifetimeError , HigherRankedSubtypeError ,
30
29
} ;
@@ -49,11 +48,12 @@ impl<'tcx> UniverseInfo<'tcx> {
49
48
UniverseInfo :: RelateTys { expected, found }
50
49
}
51
50
51
+ /// Report an error where an element erroneously made its way into `placeholder`.
52
52
pub ( crate ) fn report_erroneous_element (
53
53
& self ,
54
54
mbcx : & mut MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
55
55
placeholder : ty:: PlaceholderRegion ,
56
- error_element : RegionElement ,
56
+ error_element : Option < ty :: PlaceholderRegion > ,
57
57
cause : ObligationCause < ' tcx > ,
58
58
) {
59
59
match * self {
@@ -145,52 +145,54 @@ pub(crate) trait TypeOpInfo<'tcx> {
145
145
error_region : Option < ty:: Region < ' tcx > > ,
146
146
) -> Option < Diag < ' infcx > > ;
147
147
148
- /// Constraints require that `error_element` appear in the
149
- /// values of `placeholder`, but this cannot be proven to
150
- /// hold. Report an error.
148
+ /// Turn a placeholder region into a Region with its universe adjusted by
149
+ /// the base universe.
150
+ fn region_with_adjusted_universe (
151
+ & self ,
152
+ placeholder : ty:: PlaceholderRegion ,
153
+ tcx : TyCtxt < ' tcx > ,
154
+ ) -> ty:: Region < ' tcx > {
155
+ let Some ( adjusted_universe) =
156
+ placeholder. universe . as_u32 ( ) . checked_sub ( self . base_universe ( ) . as_u32 ( ) )
157
+ else {
158
+ unreachable ! (
159
+ "Could not adjust universe {:?} of {placeholder:?} by base universe {:?}" ,
160
+ placeholder. universe,
161
+ self . base_universe( )
162
+ ) ;
163
+ } ;
164
+ ty:: Region :: new_placeholder (
165
+ tcx,
166
+ ty:: Placeholder { universe : adjusted_universe. into ( ) , bound : placeholder. bound } ,
167
+ )
168
+ }
169
+
170
+ /// Report an error where an erroneous element reaches `placeholder`.
171
+ /// The erroneous element is either another placeholder that we provide,
172
+ /// or we reverse engineer what happened later anyway.
151
173
#[ instrument( level = "debug" , skip( self , mbcx) ) ]
152
174
fn report_erroneous_element (
153
175
& self ,
154
176
mbcx : & mut MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
155
177
placeholder : ty:: PlaceholderRegion ,
156
- error_element : RegionElement ,
178
+ error_element : Option < ty :: PlaceholderRegion > ,
157
179
cause : ObligationCause < ' tcx > ,
158
180
) {
159
181
let tcx = mbcx. infcx . tcx ;
160
- let base_universe = self . base_universe ( ) ;
161
- debug ! ( ?base_universe) ;
162
-
163
- let Some ( adjusted_universe) =
164
- placeholder. universe . as_u32 ( ) . checked_sub ( base_universe. as_u32 ( ) )
165
- else {
166
- mbcx. buffer_error ( self . fallback_error ( tcx, cause. span ) ) ;
167
- return ;
168
- } ;
169
182
170
- let placeholder_region = ty:: Region :: new_placeholder (
171
- tcx,
172
- ty:: Placeholder { universe : adjusted_universe. into ( ) , bound : placeholder. bound } ,
173
- ) ;
174
-
175
- let error_region = if let RegionElement :: PlaceholderRegion ( error_placeholder) =
176
- error_element
177
- {
178
- let adjusted_universe =
179
- error_placeholder. universe . as_u32 ( ) . checked_sub ( base_universe. as_u32 ( ) ) ;
180
- adjusted_universe. map ( |adjusted| {
181
- ty:: Region :: new_placeholder (
182
- tcx,
183
- ty:: Placeholder { universe : adjusted. into ( ) , bound : error_placeholder. bound } ,
184
- )
185
- } )
186
- } else {
187
- None
188
- } ;
183
+ // FIXME: these adjusted universes are not (always) the same ones as we compute
184
+ // earlier. They probably should be, but the logic downstream is complicated,
185
+ // and assumes they use whatever this is.
186
+ //
187
+ // In fact, this function throws away a lot of interesting information that would
188
+ // probably allow bypassing lots of logic downstream for a much simpler flow.
189
+ let placeholder_region = self . region_with_adjusted_universe ( placeholder, tcx) ;
190
+ let error_element = error_element. map ( |e| self . region_with_adjusted_universe ( e, tcx) ) ;
189
191
190
192
debug ! ( ?placeholder_region) ;
191
193
192
194
let span = cause. span ;
193
- let nice_error = self . nice_error ( mbcx, cause, placeholder_region, error_region ) ;
195
+ let nice_error = self . nice_error ( mbcx, cause, placeholder_region, error_element ) ;
194
196
195
197
debug ! ( ?nice_error) ;
196
198
mbcx. buffer_error ( nice_error. unwrap_or_else ( || self . fallback_error ( tcx, span) ) ) ;
0 commit comments