Skip to content

Commit bf38111

Browse files
tighten span slightly for synthetic item
1 parent 0ae0643 commit bf38111

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler/rustc_ty_utils/src/assoc.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,16 @@ fn associated_type_for_impl_trait_in_impl(
346346
) -> LocalDefId {
347347
let impl_local_def_id = tcx.local_parent(impl_fn_def_id);
348348

349-
// FIXME fix the span, we probably want the def_id of the return type of the function
350-
let span = tcx.def_span(impl_fn_def_id);
349+
let decl = tcx
350+
.hir()
351+
.find_by_def_id(impl_fn_def_id)
352+
.expect("expected item")
353+
.fn_decl()
354+
.expect("expected decl");
355+
let span = match decl.output {
356+
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
357+
hir::FnRetTy::Return(ty) => ty.span,
358+
};
351359
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy);
352360

353361
let local_def_id = impl_assoc_ty.def_id();

tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ LL | where Self: 'b;
1313
| ~~~~~~~~~~~~~~
1414

1515
error[E0477]: the type `&'a I` does not fulfill the required lifetime
16-
--> $DIR/bad-item-bound-within-rpitit.rs:19:5
16+
--> $DIR/bad-item-bound-within-rpitit.rs:19:23
1717
|
1818
LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
2121
note: type must outlive the anonymous lifetime as defined here
2222
--> $DIR/bad-item-bound-within-rpitit.rs:10:28

0 commit comments

Comments
 (0)