diff options
author | David Tolnay <dtolnay@gmail.com> | 2021-04-02 01:22:56 -0400 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2021-04-02 01:23:22 -0400 |
commit | e294a2b52cf1dac4199daeb769c77ff8fd9103e7 (patch) | |
tree | a3fc9a639c9b91c8cd8edc5cfec86d05b4b6b1e8 | |
parent | 11064ffba04cb65f8eec74777c9d5b82645ed187 (diff) | |
download | cxx-e294a2b52cf1dac4199daeb769c77ff8fd9103e7.tar.gz |
Fill in angle brackets with appropriate span if elided from impl key
-rw-r--r-- | macro/src/generics.rs | 14 | ||||
-rw-r--r-- | tests/ui/expected_named.stderr | 14 |
2 files changed, 20 insertions, 8 deletions
diff --git a/macro/src/generics.rs b/macro/src/generics.rs index 6c391fc7..3de0330b 100644 --- a/macro/src/generics.rs +++ b/macro/src/generics.rs @@ -3,6 +3,7 @@ use crate::syntax::resolve::Resolution; 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 @@ impl<'a> ToTokens for TyGenerics<'a> { 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![<](span)) + .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![>](span)) + .to_tokens(tokens); } } } diff --git a/tests/ui/expected_named.stderr b/tests/ui/expected_named.stderr index bb06cdf3..46764014 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>>; + | ^^^^^^^^^^^^^^^^^ |