@@ -155,7 +155,7 @@ struct NamedRegionMap {
155
155
156
156
crate enum MissingLifetimeSpot<'tcx> {
157
157
Generics(&'tcx hir::Generics<'tcx>),
158
- HRLT { span: Span, span_type: ForLifetimeSpanType },
158
+ HigherRanked { span: Span, span_type: ForLifetimeSpanType },
159
159
}
160
160
161
161
crate enum ForLifetimeSpanType {
@@ -165,6 +165,22 @@ crate enum ForLifetimeSpanType {
165
165
TypeTail,
166
166
}
167
167
168
+ impl ForLifetimeSpanType {
169
+ crate fn descr(&self) -> &'static str {
170
+ match self {
171
+ Self::BoundEmpty | Self::BoundTail => "bound",
172
+ Self::TypeEmpty | Self::TypeTail => "type",
173
+ }
174
+ }
175
+
176
+ crate fn suggestion(&self, sugg: &str) -> String {
177
+ match self {
178
+ Self::BoundEmpty | Self::TypeEmpty => format!("for<{}> ", sugg),
179
+ Self::BoundTail | Self::TypeTail => format!(", {}", sugg),
180
+ }
181
+ }
182
+ }
183
+
168
184
impl<'tcx> Into<MissingLifetimeSpot<'tcx>> for &'tcx hir::Generics<'tcx> {
169
185
fn into(self) -> MissingLifetimeSpot<'tcx> {
170
186
MissingLifetimeSpot::Generics(self)
@@ -525,7 +541,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
525
541
(ty.span.shrink_to_lo(), ForLifetimeSpanType::TypeEmpty)
526
542
};
527
543
self.missing_named_lifetime_spots
528
- .push(MissingLifetimeSpot::HRLT { span, span_type });
544
+ .push(MissingLifetimeSpot::HigherRanked { span, span_type });
529
545
let scope = Scope::Binder {
530
546
lifetimes: c
531
547
.generic_params
@@ -1887,29 +1903,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1887
1903
Applicability::MaybeIncorrect,
1888
1904
);
1889
1905
}
1890
- MissingLifetimeSpot::HRLT { span, span_type } => {
1906
+ MissingLifetimeSpot::HigherRanked { span, span_type } => {
1891
1907
err.span_suggestion(
1892
1908
*span,
1893
1909
&format!(
1894
1910
"consider making the {} lifetime-generic with a new `{}` lifetime",
1895
- match span_type {
1896
- ForLifetimeSpanType::BoundEmpty
1897
- | ForLifetimeSpanType::BoundTail => "bound",
1898
- ForLifetimeSpanType::TypeEmpty
1899
- | ForLifetimeSpanType::TypeTail => "type",
1900
- },
1911
+ span_type.descr(),
1901
1912
lifetime_ref
1902
1913
),
1903
- match span_type {
1904
- ForLifetimeSpanType::TypeEmpty
1905
- | ForLifetimeSpanType::BoundEmpty => {
1906
- format!("for<{}> ", lifetime_ref)
1907
- }
1908
- ForLifetimeSpanType::TypeTail | ForLifetimeSpanType::BoundTail => {
1909
- format!(", {}", lifetime_ref)
1910
- }
1911
- }
1912
- .to_string(),
1914
+ span_type.suggestion(&lifetime_ref.to_string()),
1913
1915
Applicability::MaybeIncorrect,
1914
1916
);
1915
1917
err.note(
@@ -2840,7 +2842,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2840
2842
[.., bound] => (bound.span.shrink_to_hi(), ForLifetimeSpanType::BoundTail),
2841
2843
};
2842
2844
self.missing_named_lifetime_spots
2843
- .push(MissingLifetimeSpot::HRLT { span, span_type });
2845
+ .push(MissingLifetimeSpot::HigherRanked { span, span_type });
2844
2846
return true;
2845
2847
}
2846
2848
};
0 commit comments