Change:
} if let Err(terr) = result { <del> debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty); </del> <ins> debug!(?terr, "sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty); </ins> <del> 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(), })), </del> <ins> let emitted = report_trait_method_mismatch( tcx, &mut cause, &infcx, </ins> terr, <del> false, false, </del> <ins> (trait_m, trait_fty), (impl_m, impl_fty), &trait_sig, &impl_trait_ref, </ins> ); <del> return Err(diag.emit()); </del> <ins> return Err(emitted); </ins> } // Check that all obligations are satisfied by the implementation's

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