@@ -1349,53 +1349,54 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
1349
1349
1350
1350
debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
1351
1351
1352
- let maybe_error_reported = infcx
1352
+ let err = infcx
1353
1353
. at ( & cause, param_env)
1354
1354
. sup ( trait_ty, impl_ty)
1355
- . map ( |ok| ocx. register_infer_ok_obligations ( ok) )
1356
- . map_err ( |terr| {
1357
- debug ! (
1358
- "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
1359
- impl_ty, trait_ty
1360
- ) ;
1355
+ . map ( |ok| ocx. register_infer_ok_obligations ( ok) ) ;
1361
1356
1362
- // Locate the Span containing just the type of the offending impl
1363
- match tcx . hir ( ) . expect_impl_item ( impl_const_item_def ) . kind {
1364
- ImplItemKind :: Const ( ref ty , _ ) => cause . span = ty . span ,
1365
- _ => bug ! ( "{:?} is not a impl const" , impl_const_item ) ,
1366
- }
1357
+ if let Err ( terr ) = err {
1358
+ debug ! (
1359
+ "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
1360
+ impl_ty , trait_ty
1361
+ ) ;
1367
1362
1368
- let mut diag = struct_span_err ! (
1369
- tcx. sess,
1370
- cause. span,
1371
- E0326 ,
1372
- "implemented const `{}` has an incompatible type for trait" ,
1373
- trait_const_item. name
1374
- ) ;
1363
+ // Locate the Span containing just the type of the offending impl
1364
+ match tcx. hir ( ) . expect_impl_item ( impl_const_item_def) . kind {
1365
+ ImplItemKind :: Const ( ref ty, _) => cause. span = ty. span ,
1366
+ _ => bug ! ( "{:?} is not a impl const" , impl_const_item) ,
1367
+ }
1375
1368
1376
- let trait_c_span = trait_const_item_def . as_local ( ) . map ( |trait_c_def_id| {
1377
- // Add a label to the Span containing just the type of the const
1378
- match tcx . hir ( ) . expect_trait_item ( trait_c_def_id ) . kind {
1379
- TraitItemKind :: Const ( ref ty , _ ) => ty . span ,
1380
- _ => bug ! ( "{:?} is not a trait const" , trait_const_item ) ,
1381
- }
1382
- } ) ;
1369
+ let mut diag = struct_span_err ! (
1370
+ tcx . sess ,
1371
+ cause . span ,
1372
+ E0326 ,
1373
+ "implemented const `{}` has an incompatible type for trait" ,
1374
+ trait_const_item . name
1375
+ ) ;
1383
1376
1384
- infcx. note_type_err (
1385
- & mut diag,
1386
- & cause,
1387
- trait_c_span. map ( |span| ( span, "type in trait" . to_owned ( ) ) ) ,
1388
- Some ( infer:: ValuePairs :: Terms ( ExpectedFound {
1389
- expected : trait_ty. into ( ) ,
1390
- found : impl_ty. into ( ) ,
1391
- } ) ) ,
1392
- terr,
1393
- false ,
1394
- false ,
1395
- ) ;
1396
- diag. emit ( )
1377
+ let trait_c_span = trait_const_item_def. as_local ( ) . map ( |trait_c_def_id| {
1378
+ // Add a label to the Span containing just the type of the const
1379
+ match tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind {
1380
+ TraitItemKind :: Const ( ref ty, _) => ty. span ,
1381
+ _ => bug ! ( "{:?} is not a trait const" , trait_const_item) ,
1382
+ }
1397
1383
} ) ;
1398
1384
1385
+ infcx. note_type_err (
1386
+ & mut diag,
1387
+ & cause,
1388
+ trait_c_span. map ( |span| ( span, "type in trait" . to_owned ( ) ) ) ,
1389
+ Some ( infer:: ValuePairs :: Terms ( ExpectedFound {
1390
+ expected : trait_ty. into ( ) ,
1391
+ found : impl_ty. into ( ) ,
1392
+ } ) ) ,
1393
+ terr,
1394
+ false ,
1395
+ false ,
1396
+ ) ;
1397
+ return Err ( diag. emit ( ) ) ;
1398
+ } ;
1399
+
1399
1400
// Check that all obligations are satisfied by the implementation's
1400
1401
// version.
1401
1402
let errors = ocx. select_all_or_error ( ) ;
@@ -1407,7 +1408,7 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
1407
1408
let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
1408
1409
infcx
1409
1410
. check_region_obligations_and_report_errors ( impl_const_item_def, & outlives_environment) ;
1410
- maybe_error_reported
1411
+ Ok ( ( ) )
1411
1412
} )
1412
1413
}
1413
1414
0 commit comments