11use super :: potentially_plural_count;
22use crate :: errors:: LifetimesOrBoundsMismatchOnTrait ;
3- use hir:: def_id:: DefId ;
3+ use hir:: def_id:: { DefId , LocalDefId } ;
44use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
55use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticId , ErrorGuaranteed } ;
66use rustc_hir as hir;
@@ -1303,14 +1303,17 @@ fn compare_generic_param_kinds<'tcx>(
13031303/// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
13041304pub ( crate ) fn raw_compare_const_impl < ' tcx > (
13051305 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 ) ,
13071307) -> 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 ( ) ;
13081311 debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
13091312
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 ( ) ) ;
13111314
13121315 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 ( ) ) ;
13141317 let ocx = ObligationCtxt :: new ( & infcx) ;
13151318
13161319 // The below is for the most part highly similar to the procedure
@@ -1322,18 +1325,18 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
13221325
13231326 // Create a parameter environment that represents the implementation's
13241327 // 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 ) ;
13261329
13271330 // 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) ;
13301333 let mut cause = ObligationCause :: new (
13311334 impl_c_span,
13321335 impl_c_hir_id,
13331336 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 ,
13371340 } ,
13381341 ) ;
13391342
@@ -1357,24 +1360,24 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
13571360 ) ;
13581361
13591362 // 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 {
13611364 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 ) ,
13631366 }
13641367
13651368 let mut diag = struct_span_err ! (
13661369 tcx. sess,
13671370 cause. span,
13681371 E0326 ,
13691372 "implemented const `{}` has an incompatible type for trait" ,
1370- trait_c . name
1373+ trait_const_item . name
13711374 ) ;
13721375
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| {
13741377 // Add a label to the Span containing just the type of the const
13751378 match tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind {
13761379 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 ) ,
13781381 }
13791382 } ) ;
13801383
@@ -1402,10 +1405,8 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
14021405
14031406 // FIXME return `ErrorReported` if region obligations error?
14041407 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) ;
14091410 maybe_error_reported
14101411 } )
14111412}
0 commit comments