about summary refs log tree commit diff
diff options
context:
space:
mode:
authorstoozy <stoozy@proton.me>2022-09-26 13:10:24 -0400
committerstoozy <stoozy@proton.me>2022-09-26 13:10:24 -0400
commit887515af33f80d85b76b41ef175ea1ec0e208776 (patch)
treeca2e590203c88c9461edb55f0212fb1d1dd9b6a7
parente1d7dec558d863fb76f98453088b36cb1a926d48 (diff)
downloadrust-887515af33f80d85b76b41ef175ea1ec0e208776.tar.gz
rust-887515af33f80d85b76b41ef175ea1ec0e208776.zip
Trying to suggest additional lifetime parameter
-rw-r--r--compiler/rustc_resolve/src/late/lifetimes.rs40
1 files changed, 32 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs
index 9fb1af20ac9..c69242f5d33 100644
--- a/compiler/rustc_resolve/src/late/lifetimes.rs
+++ b/compiler/rustc_resolve/src/late/lifetimes.rs
@@ -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()) {
+                            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(
+                                    &self.tcx.sess.parse_sess,
+                                    sym::anonymous_lifetime_in_impl_trait,
+                                    lifetime_ref.span,
+                                    "anonymous lifetimes in `impl Trait` are unstable",
+                                ).emit();
+                                return;
+                            }
+                        }
+
                     }
                     scope = s;
                 }