Skip to content

Commit bcacdc8

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 b35cf93 commit bcacdc8

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,13 @@ fn check_region_bounds_on_impl_item<'tcx>(
11151115
.expect("expected impl item to have generics or else we can't compare them")
11161116
.span;
11171117

1118-
let mut generics_span = None;
1118+
let mut generics_span = tcx.def_span(trait_m.def_id);
11191119
let mut bounds_span = vec![];
11201120
let mut where_span = None;
11211121
if let Some(trait_node) = tcx.hir().get_if_local(trait_m.def_id)
11221122
&& let Some(trait_generics) = trait_node.generics()
11231123
{
1124-
generics_span = Some(trait_generics.span);
1124+
generics_span = trait_generics.span;
11251125
// FIXME: we could potentially look at the impl's bounds to not point at bounds that
11261126
// *are* present in the impl.
11271127
for p in trait_generics.predicates {

compiler/rustc_hir_analysis/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub(crate) struct LifetimesOrBoundsMismatchOnTrait {
196196
#[label]
197197
pub span: Span,
198198
#[label(hir_analysis_generics_label)]
199-
pub generics_span: Option<Span>,
199+
pub generics_span: Span,
200200
#[label(hir_analysis_where_label)]
201201
pub where_span: Option<Span>,
202202
#[label(hir_analysis_bounds_label)]

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

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

1518
error: aborting due to 2 previous errors
1619

0 commit comments

Comments
 (0)