1
1
use super :: potentially_plural_count;
2
2
use crate :: errors:: LifetimesOrBoundsMismatchOnTrait ;
3
- use hir:: def_id:: DefId ;
3
+ use hir:: def_id:: { DefId , LocalDefId } ;
4
4
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5
5
use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticId , ErrorGuaranteed } ;
6
6
use rustc_hir as hir;
@@ -1303,14 +1303,17 @@ fn compare_generic_param_kinds<'tcx>(
1303
1303
/// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
1304
1304
pub ( crate ) fn raw_compare_const_impl < ' tcx > (
1305
1305
tcx : TyCtxt < ' tcx > ,
1306
- ( impl_c , trait_c , impl_trait_ref ) : ( & ty :: AssocItem , & ty :: AssocItem , ty :: TraitRef < ' tcx > ) ,
1306
+ ( impl_const_item_def , trait_const_item_def ) : ( LocalDefId , DefId ) ,
1307
1307
) -> Result < ( ) , ErrorGuaranteed > {
1308
+ let impl_const_item = tcx. associated_item ( impl_const_item_def) ;
1309
+ let trait_const_item = tcx. associated_item ( trait_const_item_def) ;
1310
+ let impl_trait_ref = tcx. impl_trait_ref ( impl_const_item. container_id ( tcx) ) . unwrap ( ) ;
1308
1311
debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
1309
1312
1310
- let impl_c_span = tcx. def_span ( impl_c . def_id ) ;
1313
+ let impl_c_span = tcx. def_span ( impl_const_item_def . to_def_id ( ) ) ;
1311
1314
1312
1315
tcx. infer_ctxt ( ) . enter ( |infcx| {
1313
- let param_env = tcx. param_env ( impl_c . def_id ) ;
1316
+ let param_env = tcx. param_env ( impl_const_item_def . to_def_id ( ) ) ;
1314
1317
let ocx = ObligationCtxt :: new ( & infcx) ;
1315
1318
1316
1319
// The below is for the most part highly similar to the procedure
@@ -1322,18 +1325,18 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
1322
1325
1323
1326
// Create a parameter environment that represents the implementation's
1324
1327
// method.
1325
- let impl_c_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_c . def_id . expect_local ( ) ) ;
1328
+ let impl_c_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_const_item_def ) ;
1326
1329
1327
1330
// Compute placeholder form of impl and trait const tys.
1328
- let impl_ty = tcx. type_of ( impl_c . def_id ) ;
1329
- let trait_ty = tcx. bound_type_of ( trait_c . def_id ) . subst ( tcx, trait_to_impl_substs) ;
1331
+ let impl_ty = tcx. type_of ( impl_const_item_def . to_def_id ( ) ) ;
1332
+ let trait_ty = tcx. bound_type_of ( trait_const_item_def ) . subst ( tcx, trait_to_impl_substs) ;
1330
1333
let mut cause = ObligationCause :: new (
1331
1334
impl_c_span,
1332
1335
impl_c_hir_id,
1333
1336
ObligationCauseCode :: CompareImplItemObligation {
1334
- impl_item_def_id : impl_c . def_id . expect_local ( ) ,
1335
- trait_item_def_id : trait_c . def_id ,
1336
- kind : impl_c . kind ,
1337
+ impl_item_def_id : impl_const_item_def ,
1338
+ trait_item_def_id : trait_const_item_def ,
1339
+ kind : impl_const_item . kind ,
1337
1340
} ,
1338
1341
) ;
1339
1342
@@ -1357,24 +1360,24 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
1357
1360
) ;
1358
1361
1359
1362
// Locate the Span containing just the type of the offending impl
1360
- match tcx. hir ( ) . expect_impl_item ( impl_c . def_id . expect_local ( ) ) . kind {
1363
+ match tcx. hir ( ) . expect_impl_item ( impl_const_item_def ) . kind {
1361
1364
ImplItemKind :: Const ( ref ty, _) => cause. span = ty. span ,
1362
- _ => bug ! ( "{:?} is not a impl const" , impl_c ) ,
1365
+ _ => bug ! ( "{:?} is not a impl const" , impl_const_item ) ,
1363
1366
}
1364
1367
1365
1368
let mut diag = struct_span_err ! (
1366
1369
tcx. sess,
1367
1370
cause. span,
1368
1371
E0326 ,
1369
1372
"implemented const `{}` has an incompatible type for trait" ,
1370
- trait_c . name
1373
+ trait_const_item . name
1371
1374
) ;
1372
1375
1373
- let trait_c_span = trait_c . def_id . as_local ( ) . map ( |trait_c_def_id| {
1376
+ let trait_c_span = trait_const_item_def . as_local ( ) . map ( |trait_c_def_id| {
1374
1377
// Add a label to the Span containing just the type of the const
1375
1378
match tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind {
1376
1379
TraitItemKind :: Const ( ref ty, _) => ty. span ,
1377
- _ => bug ! ( "{:?} is not a trait const" , trait_c ) ,
1380
+ _ => bug ! ( "{:?} is not a trait const" , trait_const_item ) ,
1378
1381
}
1379
1382
} ) ;
1380
1383
@@ -1402,10 +1405,8 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
1402
1405
1403
1406
// FIXME return `ErrorReported` if region obligations error?
1404
1407
let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
1405
- infcx. check_region_obligations_and_report_errors (
1406
- impl_c. def_id . expect_local ( ) ,
1407
- & outlives_environment,
1408
- ) ;
1408
+ infcx
1409
+ . check_region_obligations_and_report_errors ( impl_const_item_def, & outlives_environment) ;
1409
1410
maybe_error_reported
1410
1411
} )
1411
1412
}
0 commit comments