@@ -1300,15 +1300,15 @@ fn compare_generic_param_kinds<'tcx>(
13001300 Ok ( ( ) )
13011301}
13021302
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 > (
13041305 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 > {
13101308 debug ! ( "compare_const_impl(impl_trait_ref={:?})" , impl_trait_ref) ;
13111309
1310+ let impl_c_span = tcx. def_span ( impl_c. def_id ) ;
1311+
13121312 tcx. infer_ctxt ( ) . enter ( |infcx| {
13131313 let param_env = tcx. param_env ( impl_c. def_id ) ;
13141314 let ocx = ObligationCtxt :: new ( & infcx) ;
@@ -1346,68 +1346,68 @@ pub(crate) fn compare_const_impl<'tcx>(
13461346
13471347 debug ! ( "compare_const_impl: trait_ty={:?}" , trait_ty) ;
13481348
1349- let err = infcx
1349+ let maybe_error_reported = infcx
13501350 . at ( & cause, param_env)
13511351 . 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+ ) ;
13531358
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+ }
13591364
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+ ) ;
13651372
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+ } ) ;
13731380
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 ( )
13801394 } ) ;
13811395
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-
13971396 // Check that all obligations are satisfied by the implementation's
13981397 // version.
13991398 let errors = ocx. select_all_or_error ( ) ;
14001399 if !errors. is_empty ( ) {
1401- infcx. report_fulfillment_errors ( & errors, None , false ) ;
1402- return ;
1400+ return Err ( infcx. report_fulfillment_errors ( & errors, None , false ) ) ;
14031401 }
14041402
1403+ // FIXME return `ErrorReported` if region obligations error?
14051404 let outlives_environment = OutlivesEnvironment :: new ( param_env) ;
14061405 infcx. check_region_obligations_and_report_errors (
14071406 impl_c. def_id . expect_local ( ) ,
14081407 & outlives_environment,
14091408 ) ;
1410- } ) ;
1409+ maybe_error_reported
1410+ } )
14111411}
14121412
14131413pub ( crate ) fn compare_ty_impl < ' tcx > (
0 commit comments