Skip to content

Commit 6fcc9f5

Browse files
committed
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>; | ```
1 parent 02b8028 commit 6fcc9f5

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ enum LifetimeBinderKind {
378378
Function,
379379
Closure,
380380
ImplBlock,
381+
ImplAssocType,
381382
}
382383

383384
impl LifetimeBinderKind {
@@ -388,6 +389,7 @@ impl LifetimeBinderKind {
388389
PolyTrait => "bound",
389390
WhereBound => "bound",
390391
Item | ConstItem => "item",
392+
ImplAssocType => "associated type",
391393
ImplBlock => "impl block",
392394
Function => "function",
393395
Closure => "closure",
@@ -3406,7 +3408,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34063408
&generics.params,
34073409
RibKind::AssocItem,
34083410
item.id,
3409-
LifetimeBinderKind::Item,
3411+
LifetimeBinderKind::ImplAssocType,
34103412
generics.span,
34113413
|this| {
34123414
this.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,9 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
31543154
{
31553155
continue;
31563156
}
3157+
if let LifetimeBinderKind::ImplAssocType = kind {
3158+
continue;
3159+
}
31573160

31583161
if !span.can_be_used_for_suggestions()
31593162
&& suggest_note

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ LL | type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
1414
|
1515
help: consider introducing lifetime `'a` here
1616
|
17-
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
18-
| ++++
19-
help: consider introducing lifetime `'a` here
20-
|
2117
LL | impl<'a> IntoIterator for &S {
2218
| ++++
2319

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ LL | type IntoIter = std::collections::btree_map::Values<i32, T>;
1414
|
1515
help: consider introducing a named lifetime parameter
1616
|
17-
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
18-
| ++++ +++
17+
LL ~ impl<'a> IntoIterator for &S {
18+
LL | type Item = &T;
19+
LL |
20+
LL ~ type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
21+
|
1922

2023
error: aborting due to 2 previous errors
2124

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ LL | impl<'a> IntoIterator for &'_ S {
2020
|
2121
help: consider using the named lifetime here instead of an implict lifetime
2222
|
23-
LL | impl<'a> IntoIterator for &'a S {
24-
| ~~
23+
LL - impl<'a> IntoIterator for &'_ S {
24+
LL + impl<'a> IntoIterator for &'a S {
25+
|
2526

2627
error: aborting due to 2 previous errors
2728

tests/ui/mismatched_types/issue-74918-missing-lifetime.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | type Item = IteratorChunk<T, S>;
66
|
77
help: consider introducing a named lifetime parameter
88
|
9-
LL | type Item<'a> = IteratorChunk<'a, T, S>;
10-
| ++++ +++
9+
LL ~ impl<'a, T, S: Iterator<Item = T>> Iterator for ChunkingIterator<T, S> {
10+
LL ~ type Item = IteratorChunk<'a, T, S>;
11+
|
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/nll/user-annotations/region-error-ice-109072.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ LL | type T = &'missing ();
1717
|
1818
help: consider introducing lifetime `'missing` here
1919
|
20-
LL | type T<'missing> = &'missing ();
21-
| ++++++++++
22-
help: consider introducing lifetime `'missing` here
23-
|
2420
LL | impl<'missing> Lt<'missing> for () {
2521
| ++++++++++
2622

0 commit comments

Comments
 (0)