Fill in angle brackets with appropriate span if elided from impl key
diff --git a/macro/src/generics.rs b/macro/src/generics.rs
index 6c391fc..3de0330 100644
--- a/macro/src/generics.rs
+++ b/macro/src/generics.rs
@@ -3,6 +3,7 @@
use crate::syntax::Impl;
use proc_macro2::TokenStream;
use quote::ToTokens;
+use syn::Token;
pub struct ImplGenerics<'a> {
explicit_impl: Option<&'a Impl>,
@@ -46,10 +47,17 @@
fn to_tokens(&self, tokens: &mut TokenStream) {
if let Some(imp) = self.explicit_impl {
imp.ty_generics.to_tokens(tokens);
- } else {
- self.key.lt_token.to_tokens(tokens);
+ } else if !self.resolve.generics.lifetimes.is_empty() {
+ let span = self.key.rust.span();
+ self.key
+ .lt_token
+ .unwrap_or_else(|| Token)
+ .to_tokens(tokens);
self.resolve.generics.lifetimes.to_tokens(tokens);
- self.key.gt_token.to_tokens(tokens);
+ self.key
+ .gt_token
+ .unwrap_or_else(|| Token)
+ .to_tokens(tokens);
}
}
}
diff --git a/tests/ui/expected_named.stderr b/tests/ui/expected_named.stderr
index bb06cdf..4676401 100644
--- a/tests/ui/expected_named.stderr
+++ b/tests/ui/expected_named.stderr
@@ -1,7 +1,11 @@
-error: expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found `'a`
- --> $DIR/expected_named.rs:4:23
+error[E0106]: missing lifetime specifier
+ --> $DIR/expected_named.rs:5:36
|
-4 | type Borrowed<'a>;
- | ^^ unexpected token
5 | fn borrowed() -> UniquePtr<Borrowed>;
- | - expected one of 7 possible tokens
+ | ^^^^^^^^ expected named lifetime parameter
+ |
+ = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
+help: consider using the `'static` lifetime
+ |
+5 | fn borrowed() -> UniquePtr<Borrowed<'static>>;
+ | ^^^^^^^^^^^^^^^^^