1
Fork 0

Don't suggest adding 'static lifetime to arguments

Fixes #69350

This is almost always the wrong this to do
This commit is contained in:
Aaron Hill 2021-05-12 21:39:37 -04:00
parent 31bd868c39
commit bc6330d47a
No known key found for this signature in database
GPG key ID: B4087E510E98B164
11 changed files with 10 additions and 41 deletions

View file

@ -114,12 +114,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
);
diag.span_label(span, format!("lifetime `{}` required", named));
diag.span_suggestion(
new_ty_span,
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
new_ty.to_string(),
Applicability::Unspecified,
);
// Suggesting `'static` is nearly always incorrect, and can steer users
// down the wrong path.
if *named != ty::ReStatic {
diag.span_suggestion(
new_ty_span,
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
new_ty.to_string(),
Applicability::Unspecified,
);
}
Some(diag)
}