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;
@@ -1300,17 +1300,20 @@ fn compare_generic_param_kinds<'tcx>(
1300
1300
Ok ( ( ) )
1301
1301
}
1302
1302
1303
- pub ( crate ) fn compare_const_impl < ' tcx > (
1303
+ /// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
1304
+ pub ( crate ) fn raw_compare_const_impl < ' tcx > (
1304
1305
tcx : TyCtxt < ' tcx > ,
1305
- impl_c : & ty :: AssocItem ,
1306
- impl_c_span : Span ,
1307
- trait_c : & ty :: AssocItem ,
1308
- impl_trait_ref : ty :: TraitRef < ' tcx > ,
1309
- ) {
1306
+ ( impl_const_item_def , trait_const_item_def ) : ( LocalDefId , DefId ) ,
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 ( ) ;
1310
1311
debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
1311
1312
1313
+ let impl_c_span = tcx. def_span ( impl_const_item_def. to_def_id ( ) ) ;
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 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
@@ -1358,24 +1361,24 @@ pub(crate) fn compare_const_impl<'tcx>(
1358
1361
) ;
1359
1362
1360
1363
// Locate the Span containing just the type of the offending impl
1361
- match tcx. hir ( ) . expect_impl_item ( impl_c . def_id . expect_local ( ) ) . kind {
1364
+ match tcx. hir ( ) . expect_impl_item ( impl_const_item_def ) . kind {
1362
1365
ImplItemKind :: Const ( ref ty, _) => cause. span = ty. span ,
1363
- _ => bug ! ( "{:?} is not a impl const" , impl_c ) ,
1366
+ _ => bug ! ( "{:?} is not a impl const" , impl_const_item ) ,
1364
1367
}
1365
1368
1366
1369
let mut diag = struct_span_err ! (
1367
1370
tcx. sess,
1368
1371
cause. span,
1369
1372
E0326 ,
1370
1373
"implemented const `{}` has an incompatible type for trait" ,
1371
- trait_c . name
1374
+ trait_const_item . name
1372
1375
) ;
1373
1376
1374
- let trait_c_span = trait_c . def_id . as_local ( ) . map ( |trait_c_def_id| {
1377
+ let trait_c_span = trait_const_item_def . as_local ( ) . map ( |trait_c_def_id| {
1375
1378
// Add a label to the Span containing just the type of the const
1376
1379
match tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind {
1377
1380
TraitItemKind :: Const ( ref ty, _) => ty. span ,
1378
- _ => bug ! ( "{:?} is not a trait const" , trait_c ) ,
1381
+ _ => bug ! ( "{:?} is not a trait const" , trait_const_item ) ,
1379
1382
}
1380
1383
} ) ;
1381
1384
@@ -1391,23 +1394,22 @@ pub(crate) fn compare_const_impl<'tcx>(
1391
1394
false ,
1392
1395
false ,
1393
1396
) ;
1394
- diag. emit ( ) ;
1395
- }
1397
+ return Err ( diag. emit ( ) ) ;
1398
+ } ;
1396
1399
1397
1400
// Check that all obligations are satisfied by the implementation's
1398
1401
// version.
1399
1402
let errors = ocx. select_all_or_error ( ) ;
1400
1403
if !errors. is_empty ( ) {
1401
- infcx. report_fulfillment_errors ( & errors, None , false ) ;
1402
- return ;
1404
+ return Err ( infcx. report_fulfillment_errors ( & errors, None , false ) ) ;
1403
1405
}
1404
1406
1407
+ // FIXME return `ErrorReported` if region obligations error?
1405
1408
let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
1406
- infcx. check_region_obligations_and_report_errors (
1407
- impl_c. def_id . expect_local ( ) ,
1408
- & outlives_environment,
1409
- ) ;
1410
- } ) ;
1409
+ infcx
1410
+ . check_region_obligations_and_report_errors ( impl_const_item_def, & outlives_environment) ;
1411
+ Ok ( ( ) )
1412
+ } )
1411
1413
}
1412
1414
1413
1415
pub ( crate ) fn compare_ty_impl < ' tcx > (
0 commit comments