mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #70827 - estebank:shorten-sugg-span-add-lt, r=ecstatic-morse
Use smaller span for suggestion restricting lifetime
This commit is contained in:
commit
3faec69865
@ -208,45 +208,34 @@ impl BorrowExplanation {
|
||||
);
|
||||
};
|
||||
|
||||
self.add_lifetime_bound_suggestion_to_diagnostic(
|
||||
tcx,
|
||||
err,
|
||||
&category,
|
||||
span,
|
||||
region_name,
|
||||
);
|
||||
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic<'tcx>(
|
||||
pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
category: &ConstraintCategory,
|
||||
span: Span,
|
||||
region_name: &RegionName,
|
||||
) {
|
||||
if let ConstraintCategory::OpaqueType = category {
|
||||
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) {
|
||||
let suggestable_name = if region_name.was_named() {
|
||||
region_name.to_string()
|
||||
} else {
|
||||
"'_".to_string()
|
||||
};
|
||||
let suggestable_name =
|
||||
if region_name.was_named() { region_name.to_string() } else { "'_".to_string() };
|
||||
|
||||
err.span_suggestion(
|
||||
span,
|
||||
&format!(
|
||||
"you can add a bound to the {}to make it last less than \
|
||||
`'static` and match `{}`",
|
||||
category.description(),
|
||||
region_name,
|
||||
),
|
||||
format!("{} + {}", snippet, suggestable_name),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
let msg = format!(
|
||||
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
|
||||
category.description(),
|
||||
region_name,
|
||||
);
|
||||
|
||||
err.span_suggestion_verbose(
|
||||
span.shrink_to_hi(),
|
||||
&msg,
|
||||
format!(" + {}", suggestable_name),
|
||||
Applicability::Unspecified,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ LL | }
|
||||
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
|
||||
|
|
||||
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> + 'a {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user