Do not suggest introducing lifetime in impl assoc type

```
error[E0261]: use of undeclared lifetime name `'a`
  --> $DIR/missing-lifetime-in-assoc-type-2.rs:7:57
   |
LL | impl IntoIterator for &S {
   |     - help: consider introducing lifetime `'a` here: `<'a>`
...
LL |     type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
   |                                                         ^^ undeclared lifetime
```

```
error[E0106]: missing lifetime specifier
  --> $DIR/issue-74918-missing-lifetime.rs:9:30
   |
LL |     type Item = IteratorChunk<T, S>;
   |                              ^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
LL ~ impl<'a, T, S: Iterator<Item = T>> Iterator for ChunkingIterator<T, S> {
LL ~     type Item = IteratorChunk<'a, T, S>;
   |
```
This commit is contained in:
Esteban Küber 2025-01-16 22:12:35 +00:00
parent 1e9e1f2f9a
commit 75bb675f96
7 changed files with 17 additions and 15 deletions

View file

@ -378,6 +378,7 @@ enum LifetimeBinderKind {
Function,
Closure,
ImplBlock,
ImplAssocType,
}
impl LifetimeBinderKind {
@ -388,6 +389,7 @@ impl LifetimeBinderKind {
PolyTrait => "bound",
WhereBound => "bound",
Item | ConstItem => "item",
ImplAssocType => "associated type",
ImplBlock => "impl block",
Function => "function",
Closure => "closure",
@ -3398,7 +3400,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
&generics.params,
RibKind::AssocItem,
item.id,
LifetimeBinderKind::Item,
LifetimeBinderKind::ImplAssocType,
generics.span,
|this| {
this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {

View file

@ -3178,6 +3178,9 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
{
continue;
}
if let LifetimeBinderKind::ImplAssocType = kind {
continue;
}
if !span.can_be_used_for_suggestions()
&& suggest_note

View file

@ -14,10 +14,6 @@ LL | type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
|
help: consider introducing lifetime `'a` here
|
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | impl<'a> IntoIterator for &S {
| ++++

View file

@ -14,8 +14,11 @@ LL | type IntoIter = std::collections::btree_map::Values<i32, T>;
|
help: consider introducing a named lifetime parameter
|
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
| ++++ +++
LL ~ impl<'a> IntoIterator for &S {
LL | type Item = &T;
LL |
LL ~ type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
|
error: aborting due to 2 previous errors

View file

@ -20,8 +20,9 @@ LL | impl<'a> IntoIterator for &'_ S {
|
help: consider using the named lifetime here instead of an implict lifetime
|
LL | impl<'a> IntoIterator for &'a S {
| ~~
LL - impl<'a> IntoIterator for &'_ S {
LL + impl<'a> IntoIterator for &'a S {
|
error: aborting due to 2 previous errors

View file

@ -6,8 +6,9 @@ LL | type Item = IteratorChunk<T, S>;
|
help: consider introducing a named lifetime parameter
|
LL | type Item<'a> = IteratorChunk<'a, T, S>;
| ++++ +++
LL ~ impl<'a, T, S: Iterator<Item = T>> Iterator for ChunkingIterator<T, S> {
LL ~ type Item = IteratorChunk<'a, T, S>;
|
error: aborting due to 1 previous error

View file

@ -17,10 +17,6 @@ LL | type T = &'missing ();
|
help: consider introducing lifetime `'missing` here
|
LL | type T<'missing> = &'missing ();
| ++++++++++
help: consider introducing lifetime `'missing` here
|
LL | impl<'missing> Lt<'missing> for () {
| ++++++++++