@@ -9,6 +9,7 @@ use std::iter;
99use rustc_data_structures:: fx:: FxIndexSet ;
1010use rustc_errors:: { Applicability , E0806 , struct_span_code_err} ;
1111use rustc_hir:: attrs:: EiiImplResolution ;
12+ use rustc_hir:: def:: DefKind ;
1213use rustc_hir:: def_id:: { DefId , LocalDefId } ;
1314use rustc_hir:: { self as hir, FnSig , HirId , ItemKind , find_attr} ;
1415use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
@@ -37,6 +38,14 @@ pub(crate) fn compare_eii_function_types<'tcx>(
3738 eii_name : Symbol ,
3839 eii_attr_span : Span ,
3940) -> Result < ( ) , ErrorGuaranteed > {
41+ // Error recovery can resolve the EII target to another value item with the same name,
42+ // such as a tuple-struct constructor. Skip the comparison in that case and rely on the
43+ // earlier name-resolution error instead of ICEing while building EII diagnostics.
44+ // See <https://github.com/rust-lang/rust/issues/153502>.
45+ if !is_foreign_function ( tcx, foreign_item) {
46+ return Ok ( ( ) ) ;
47+ }
48+
4049 check_is_structurally_compatible ( tcx, external_impl, foreign_item, eii_name, eii_attr_span) ?;
4150
4251 let external_impl_span = tcx. def_span ( external_impl) ;
@@ -442,3 +451,7 @@ fn get_declaration_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Option<&'
442451 let hir_id: HirId = tcx. local_def_id_to_hir_id ( def_id) ;
443452 tcx. hir_fn_sig_by_hir_id ( hir_id)
444453}
454+
455+ fn is_foreign_function ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
456+ tcx. is_foreign_item ( def_id) && matches ! ( tcx. def_kind( def_id) , DefKind :: Fn )
457+ }
0 commit comments