Trying to suggest additional lifetime parameter
This commit is contained in:
parent
e1d7dec558
commit
887515af33
1 changed files with 32 additions and 8 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use rustc_ast::walk_list;
|
use rustc_ast::walk_list;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
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 as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
|
@ -24,6 +24,7 @@ use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
||||||
trait RegionExt {
|
trait RegionExt {
|
||||||
fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region);
|
fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region);
|
||||||
|
|
||||||
|
@ -1318,6 +1319,26 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
|
&& let hir::IsAsync::NotAsync = self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id)
|
||||||
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
||||||
{
|
{
|
||||||
|
|
||||||
|
match self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.to_def_id().as_local().unwrap()) {
|
||||||
|
Some(generics) => {
|
||||||
|
for i in 0..generics.params.len() {
|
||||||
|
|
||||||
|
if !generics.span.contains(generics.params[i].span) {
|
||||||
|
struct_span_err!(
|
||||||
|
self.tcx.sess,
|
||||||
|
lifetime_ref.span,
|
||||||
|
E0106,
|
||||||
|
"missing lifetime specifier"
|
||||||
|
)
|
||||||
|
.span_label(lifetime_ref.span, "expected named lifetime parameter")
|
||||||
|
.span_help(generics.span, "consider introducing a named lifetime parameter")
|
||||||
|
.emit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
rustc_session::parse::feature_err(
|
rustc_session::parse::feature_err(
|
||||||
&self.tcx.sess.parse_sess,
|
&self.tcx.sess.parse_sess,
|
||||||
sym::anonymous_lifetime_in_impl_trait,
|
sym::anonymous_lifetime_in_impl_trait,
|
||||||
|
@ -1326,6 +1347,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
).emit();
|
).emit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue