@@ -1300,15 +1300,15 @@ 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_c, trait_c, impl_trait_ref) : ( & ty:: AssocItem , & ty:: AssocItem , ty:: TraitRef < ' tcx > ) ,
1307
+ ) -> Result < ( ) , ErrorGuaranteed > {
1310
1308
debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
1311
1309
1310
+ let impl_c_span = tcx. def_span ( impl_c. def_id ) ;
1311
+
1312
1312
tcx. infer_ctxt ( ) . enter ( |infcx| {
1313
1313
let param_env = tcx. param_env ( impl_c. def_id ) ;
1314
1314
let ocx = ObligationCtxt :: new ( & infcx) ;
@@ -1346,68 +1346,68 @@ pub(crate) fn compare_const_impl<'tcx>(
1346
1346
1347
1347
debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
1348
1348
1349
- let err = infcx
1349
+ let maybe_error_reported = infcx
1350
1350
. at ( & cause, param_env)
1351
1351
. sup ( trait_ty, impl_ty)
1352
- . map ( |ok| ocx. register_infer_ok_obligations ( ok) ) ;
1352
+ . map ( |ok| ocx. register_infer_ok_obligations ( ok) )
1353
+ . map_err ( |terr| {
1354
+ debug ! (
1355
+ "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
1356
+ impl_ty, trait_ty
1357
+ ) ;
1353
1358
1354
- if let Err ( terr ) = err {
1355
- debug ! (
1356
- "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
1357
- impl_ty , trait_ty
1358
- ) ;
1359
+ // 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 {
1361
+ ImplItemKind :: Const ( ref ty , _ ) => cause . span = ty . span ,
1362
+ _ => bug ! ( "{:?} is not a impl const" , impl_c ) ,
1363
+ }
1359
1364
1360
- // 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 {
1362
- ImplItemKind :: Const ( ref ty, _) => cause. span = ty. span ,
1363
- _ => bug ! ( "{:?} is not a impl const" , impl_c) ,
1364
- }
1365
+ let mut diag = struct_span_err ! (
1366
+ tcx. sess,
1367
+ cause. span,
1368
+ E0326 ,
1369
+ "implemented const `{}` has an incompatible type for trait" ,
1370
+ trait_c. name
1371
+ ) ;
1365
1372
1366
- let mut diag = struct_span_err ! (
1367
- tcx . sess ,
1368
- cause . span ,
1369
- E0326 ,
1370
- "implemented const `{}` has an incompatible type for trait" ,
1371
- trait_c . name
1372
- ) ;
1373
+ let trait_c_span = trait_c . def_id . as_local ( ) . map ( |trait_c_def_id| {
1374
+ // Add a label to the Span containing just the type of the const
1375
+ match tcx . hir ( ) . expect_trait_item ( trait_c_def_id ) . kind {
1376
+ TraitItemKind :: Const ( ref ty , _ ) => ty . span ,
1377
+ _ => bug ! ( "{:?} is not a trait const" , trait_c ) ,
1378
+ }
1379
+ } ) ;
1373
1380
1374
- let trait_c_span = trait_c. def_id . as_local ( ) . map ( |trait_c_def_id| {
1375
- // Add a label to the Span containing just the type of the const
1376
- match tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind {
1377
- TraitItemKind :: Const ( ref ty, _) => ty. span ,
1378
- _ => bug ! ( "{:?} is not a trait const" , trait_c) ,
1379
- }
1381
+ infcx. note_type_err (
1382
+ & mut diag,
1383
+ & cause,
1384
+ trait_c_span. map ( |span| ( span, "type in trait" . to_owned ( ) ) ) ,
1385
+ Some ( infer:: ValuePairs :: Terms ( ExpectedFound {
1386
+ expected : trait_ty. into ( ) ,
1387
+ found : impl_ty. into ( ) ,
1388
+ } ) ) ,
1389
+ terr,
1390
+ false ,
1391
+ false ,
1392
+ ) ;
1393
+ diag. emit ( )
1380
1394
} ) ;
1381
1395
1382
- infcx. note_type_err (
1383
- & mut diag,
1384
- & cause,
1385
- trait_c_span. map ( |span| ( span, "type in trait" . to_owned ( ) ) ) ,
1386
- Some ( infer:: ValuePairs :: Terms ( ExpectedFound {
1387
- expected : trait_ty. into ( ) ,
1388
- found : impl_ty. into ( ) ,
1389
- } ) ) ,
1390
- terr,
1391
- false ,
1392
- false ,
1393
- ) ;
1394
- diag. emit ( ) ;
1395
- }
1396
-
1397
1396
// Check that all obligations are satisfied by the implementation's
1398
1397
// version.
1399
1398
let errors = ocx. select_all_or_error ( ) ;
1400
1399
if !errors. is_empty ( ) {
1401
- infcx. report_fulfillment_errors ( & errors, None , false ) ;
1402
- return ;
1400
+ return Err ( infcx. report_fulfillment_errors ( & errors, None , false ) ) ;
1403
1401
}
1404
1402
1403
+ // FIXME return `ErrorReported` if region obligations error?
1405
1404
let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
1406
1405
infcx. check_region_obligations_and_report_errors (
1407
1406
impl_c. def_id . expect_local ( ) ,
1408
1407
& outlives_environment,
1409
1408
) ;
1410
- } ) ;
1409
+ maybe_error_reported
1410
+ } )
1411
1411
}
1412
1412
1413
1413
pub ( crate ) fn compare_ty_impl < ' tcx > (
0 commit comments