@@ -13,7 +13,6 @@ use rustc_hir::intravisit::{self, Visitor};
13
13
use rustc_hir:: { Body , Closure , Expr , ExprKind , FnRetTy , HirId , LetStmt , LocalSource } ;
14
14
use rustc_middle:: bug;
15
15
use rustc_middle:: hir:: nested_filter;
16
- use rustc_middle:: infer:: unify_key:: ConstVariableValue ;
17
16
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow } ;
18
17
use rustc_middle:: ty:: print:: { FmtPrinter , PrettyPrinter , Print , Printer } ;
19
18
use rustc_middle:: ty:: {
@@ -183,9 +182,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
183
182
warn ! ( "resolved ty var in error message" ) ;
184
183
}
185
184
186
- let mut infcx_inner = infcx. inner . borrow_mut ( ) ;
187
- let ty_vars = infcx_inner. type_variables ( ) ;
188
- let var_origin = ty_vars. var_origin ( ty_vid) ;
185
+ let var_origin = infcx. type_var_origin ( ty_vid) ;
189
186
if let Some ( def_id) = var_origin. param_def_id
190
187
// The `Self` param of a trait has the def-id of the trait,
191
188
// since it's a synthetic parameter.
@@ -206,24 +203,8 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
206
203
}
207
204
} ;
208
205
printer. ty_infer_name_resolver = Some ( Box :: new ( ty_getter) ) ;
209
- let const_getter = move |ct_vid| match infcx
210
- . inner
211
- . borrow_mut ( )
212
- . const_unification_table ( )
213
- . probe_value ( ct_vid)
214
- {
215
- ConstVariableValue :: Known { value : _ } => {
216
- warn ! ( "resolved const var in error message" ) ;
217
- None
218
- }
219
- ConstVariableValue :: Unknown { origin, universe : _ } => {
220
- if let Some ( def_id) = origin. param_def_id {
221
- Some ( infcx. tcx . item_name ( def_id) )
222
- } else {
223
- None
224
- }
225
- }
226
- } ;
206
+ let const_getter =
207
+ move |ct_vid| Some ( infcx. tcx . item_name ( infcx. const_var_origin ( ct_vid) ?. param_def_id ?) ) ;
227
208
printer. const_infer_name_resolver = Some ( Box :: new ( const_getter) ) ;
228
209
printer
229
210
}
@@ -300,9 +281,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
300
281
match arg. unpack ( ) {
301
282
GenericArgKind :: Type ( ty) => {
302
283
if let ty:: Infer ( ty:: TyVar ( ty_vid) ) = * ty. kind ( ) {
303
- let mut inner = self . inner . borrow_mut ( ) ;
304
- let ty_vars = & inner. type_variables ( ) ;
305
- let var_origin = ty_vars. var_origin ( ty_vid) ;
284
+ let var_origin = self . infcx . type_var_origin ( ty_vid) ;
306
285
if let Some ( def_id) = var_origin. param_def_id
307
286
// The `Self` param of a trait has the def-id of the trait,
308
287
// since it's a synthetic parameter.
@@ -332,13 +311,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
332
311
}
333
312
GenericArgKind :: Const ( ct) => {
334
313
if let ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) = ct. kind ( ) {
335
- let origin =
336
- match self . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( vid) {
337
- ConstVariableValue :: Known { value } => {
338
- bug ! ( "resolved infer var: {vid:?} {value}" )
339
- }
340
- ConstVariableValue :: Unknown { origin, universe : _ } => origin,
341
- } ;
314
+ let origin = self . const_var_origin ( vid) . expect ( "expected unresolved const var" ) ;
342
315
if let Some ( def_id) = origin. param_def_id {
343
316
return InferenceDiagnosticsData {
344
317
name : self . tcx . item_name ( def_id) . to_string ( ) ,
@@ -885,7 +858,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
885
858
use ty:: InferConst :: * ;
886
859
match ( inner_ct. kind ( ) , target_ct. kind ( ) ) {
887
860
( ty:: ConstKind :: Infer ( Var ( a_vid) ) , ty:: ConstKind :: Infer ( Var ( b_vid) ) ) => {
888
- self . tecx . inner . borrow_mut ( ) . const_unification_table ( ) . unioned ( a_vid , b_vid)
861
+ self . tecx . root_const_var ( a_vid ) == self . tecx . root_const_var ( b_vid)
889
862
}
890
863
_ => false ,
891
864
}
0 commit comments