Change:
} } <ins> fn report_trait_method_mismatch<'tcx>( tcx: TyCtxt<'tcx>, cause: &mut ObligationCause<'tcx>, infcx: &InferCtxt<'tcx>, terr: TypeError<'tcx>, (trait_m, trait_fty): (&AssocItem, Ty<'tcx>), (impl_m, impl_fty): (&AssocItem, Ty<'tcx>), trait_sig: &FnSig<'tcx>, impl_trait_ref: &TraitRef<'tcx>, ) -> ErrorGuaranteed { let (impl_err_span, trait_err_span) = extract_spans_for_error_reporting(&infcx, terr, &cause, impl_m, trait_m); cause.span = impl_err_span; let mut diag = struct_span_err!( tcx.sess, cause.span(), E0053, "method `{}` has an incompatible type for trait", trait_m.name ); match &terr { TypeError::ArgumentMutability(0) | TypeError::ArgumentSorts(_, 0) if trait_m.fn_has_self_parameter => { let ty = trait_sig.inputs()[0]; let sugg = match ExplicitSelf::determine(ty, |_| ty == impl_trait_ref.self_ty()) { ExplicitSelf::ByValue => "self".to_owned(), ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(), ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(), _ => format!("self: {ty}"), }; // When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the // span points only at the type `Box<Self`>, but we want to cover the whole // argument pattern and type. let span = match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind { ImplItemKind::Fn(ref sig, body) => tcx .hir() .body_param_names(body) .zip(sig.decl.inputs.iter()) .map(|(param, ty)| param.span.to(ty.span)) .next() .unwrap_or(impl_err_span), _ => bug!("{:?} is not a method", impl_m), }; diag.span_suggestion( span, "change the self-receiver type to match the trait", sugg, Applicability::MachineApplicable, ); } TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(_, i) => { if trait_sig.inputs().len() == *i { // Suggestion to change output type. We do not suggest in `async` functions // to avoid complex logic or incorrect output. match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind { ImplItemKind::Fn(ref sig, _) if sig.header.asyncness == hir::IsAsync::NotAsync => { let msg = "change the output type to match the trait"; let ap = Applicability::MachineApplicable; match sig.decl.output { hir::FnRetTy::DefaultReturn(sp) => { let sugg = format!("-> {} ", trait_sig.output()); diag.span_suggestion_verbose(sp, msg, sugg, ap); } hir::FnRetTy::Return(hir_ty) => { let sugg = trait_sig.output(); diag.span_suggestion(hir_ty.span, msg, sugg, ap); } }; } _ => {} }; } else if let Some(trait_ty) = trait_sig.inputs().get(*i) { diag.span_suggestion( impl_err_span, "change the parameter type to match the trait", trait_ty, Applicability::MachineApplicable, ); } } _ => {} } infcx.err_ctxt().note_type_err( &mut diag, &cause, trait_err_span.map(|sp| (sp, "type in trait".to_owned())), Some(infer::ValuePairs::Terms(ExpectedFound { expected: trait_fty.into(), found: impl_fty.into(), })), terr, false, false, ); return diag.emit(); } </ins> fn check_region_bounds_on_impl_item<'tcx>( tcx: TyCtxt<'tcx>, impl_m: &ty::AssocItem,

Discussion:
Essentially, if my trait has and my impl has the compiler panics. Note that the code is invalid and compilation should fail. <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: Note that I'm using which is experimental. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
This happens for all type mismatches in the arguments (but not the arity!) A : <details<summaryWith the following backtrace: </summary</details
When not using a normal , the proper error is emitted here inside : But something gets messed up with the return position impl trait in trait desugaring that doesn't make this work (the arity check above does work). claim