Skip to content

Commit 116bd92

Browse files
committed
Always point at trait assoc item when generics don't match
Previously we only showed the trait's assoc item if the trait was local, because we were looking for a small span only for the generics, which we don't have for foreign traits. We now use `def_span` for the item, so we at least provide some context, even if its span is too wide. ``` error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration --> tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs:7:18 | 7 | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>; | ^^^^ lifetimes do not match type in trait | ::: /home/gh-estebank/rust/library/core/src/iter/traits/collect.rs:292:5 | 292 | type IntoIter: Iterator<Item = Self::Item>; | ------------------------------------------ lifetimes in impl do not match this type in trait ```
1 parent b15a874 commit 116bd92

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,14 +1097,14 @@ fn check_region_bounds_on_impl_item<'tcx>(
10971097
.expect("expected impl item to have generics or else we can't compare them")
10981098
.span;
10991099

1100-
let mut generics_span = None;
1100+
let mut generics_span = tcx.def_span(trait_m.def_id);
11011101
let mut bounds_span = vec![];
11021102
let mut where_span = None;
11031103

11041104
if let Some(trait_node) = tcx.hir_get_if_local(trait_m.def_id)
11051105
&& let Some(trait_generics) = trait_node.generics()
11061106
{
1107-
generics_span = Some(trait_generics.span);
1107+
generics_span = trait_generics.span;
11081108
// FIXME: we could potentially look at the impl's bounds to not point at bounds that
11091109
// *are* present in the impl.
11101110
for p in trait_generics.predicates {

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub(crate) struct LifetimesOrBoundsMismatchOnTrait {
191191
#[label]
192192
pub span: Span,
193193
#[label(hir_analysis_generics_label)]
194-
pub generics_span: Option<Span>,
194+
pub generics_span: Span,
195195
#[label(hir_analysis_where_label)]
196196
pub where_span: Option<Span>,
197197
#[label(hir_analysis_bounds_label)]

tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ error[E0195]: lifetime parameters or bounds on associated type `IntoIter` do not
1111
|
1212
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
1313
| ^^^^ lifetimes do not match associated type in trait
14+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
15+
|
16+
= note: lifetimes in impl do not match this associated type in trait
1417

1518
error: aborting due to 2 previous errors
1619

0 commit comments

Comments
 (0)