-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Trying to suggest additional lifetime parameter #102323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
887515a
365457b
24c8e27
e7cb6ad
ef930a2
2657f9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||
|
|
||||||
| use rustc_ast::walk_list; | ||||||
| use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; | ||||||
| use rustc_errors::struct_span_err; | ||||||
| use rustc_errors::{struct_span_err}; | ||||||
| use rustc_hir as hir; | ||||||
| use rustc_hir::def::{DefKind, Res}; | ||||||
| use rustc_hir::def_id::LocalDefId; | ||||||
|
|
@@ -24,6 +24,7 @@ use rustc_span::symbol::{sym, Ident}; | |||||
| use rustc_span::Span; | ||||||
| use std::fmt; | ||||||
|
|
||||||
|
|
||||||
| trait RegionExt { | ||||||
| fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region); | ||||||
|
|
||||||
|
|
@@ -1318,13 +1319,36 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { | |||||
| && let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id) | ||||||
| && !self.tcx.features().anonymous_lifetime_in_impl_trait | ||||||
| { | ||||||
| rustc_session::parse::feature_err( | ||||||
| &self.tcx.sess.parse_sess, | ||||||
| sym::anonymous_lifetime_in_impl_trait, | ||||||
| lifetime_ref.span, | ||||||
| "anonymous lifetimes in `impl Trait` are unstable", | ||||||
| ).emit(); | ||||||
| return; | ||||||
|
|
||||||
| match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.to_def_id().as_local().unwrap()) { | ||||||
|
||||||
| match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.to_def_id().as_local().unwrap()) { | |
| match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you have generics you want 2 things to know where to suggest the lifetime parameter param_span, and in what form param_sugg.
Once you have that, you call
diag.multipart_suggestion(
"consider introducing a named lifetime parameter",
vec![
(lifetime_ref.span, "'a".to_owned()), // this is at the use site
(param_span, param_sugg), // this is in generics
],
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems if I put "'a" for the message, it replaces the ampersand symbol from the original posters input. Should I keep this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use lifetime_ref.span.shrink_to_hi() instead then.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only use a single parameter. Could you separate the choice of param from the suggestion / move the suggestion code out of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep this a feature error. You can keep this line, but instead of calling
emitimmediately, store it in a mut variablediag, decorate it usingspan_...methods, and callemitwhen you're done.