From bf38111ac1ad499d592b9f9ef9ae28e947c1c587 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 27 Jul 2023 22:20:32 +0000 Subject: [PATCH] tighten span slightly for synthetic item --- compiler/rustc_ty_utils/src/assoc.rs | 12 ++++++++++-- .../in-trait/bad-item-bound-within-rpitit.stderr | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 4a544232174..780f7ea426f 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -346,8 +346,16 @@ fn associated_type_for_impl_trait_in_impl( ) -> LocalDefId { let impl_local_def_id = tcx.local_parent(impl_fn_def_id); - // FIXME fix the span, we probably want the def_id of the return type of the function - let span = tcx.def_span(impl_fn_def_id); + let decl = tcx + .hir() + .find_by_def_id(impl_fn_def_id) + .expect("expected item") + .fn_decl() + .expect("expected decl"); + let span = match decl.output { + hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id), + hir::FnRetTy::Return(ty) => ty.span, + }; let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy); let local_def_id = impl_assoc_ty.def_id(); diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr index 1e3363268f0..54a08c5b516 100644 --- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr +++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr @@ -13,10 +13,10 @@ LL | where Self: 'b; | ~~~~~~~~~~~~~~ error[E0477]: the type `&'a I` does not fulfill the required lifetime - --> $DIR/bad-item-bound-within-rpitit.rs:19:5 + --> $DIR/bad-item-bound-within-rpitit.rs:19:23 | LL | fn iter(&self) -> impl 'a + Iterator> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: type must outlive the anonymous lifetime as defined here --> $DIR/bad-item-bound-within-rpitit.rs:10:28