From f948ad77615635be14cbf687a2bfe5a8e5c3a2b5 Mon Sep 17 00:00:00 2001 From: Seigo Tanimura Date: Mon, 31 Aug 2026 14:32:07 +0900 Subject: [PATCH] Clarify that Generics::to_token() covers Generic::params only. Document the rationale for that design in Generics. Signed-off-by: Seigo Tanimura --- src/generics.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/generics.rs b/src/generics.rs index 37094a89af..efd9ec0647 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -20,11 +20,14 @@ ast_struct! { /// enum, trait, etc. /// /// This struct represents two distinct optional syntactic elements, - /// [generic parameters] and [where clause]. In some locations of the - /// grammar, there may be other tokens in between these two things. + /// [generic parameters] and [where clause]. These elements are + /// separated because [all functions] and [some traits] have other tokens + /// in between these two elements. /// /// [generic parameters]: https://doc.rust-lang.org/stable/reference/items/generics.html#generic-parameters /// [where clause]: https://doc.rust-lang.org/stable/reference/items/generics.html#where-clauses + /// [all functions]: https://doc.rust-lang.org/stable/reference/items/functions.html#r-items.fn.syntax + /// [some traits]: https://doc.rust-lang.org/stable/reference/items/traits.html#r-items.traits.syntax #[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct Generics { pub lt_token: Option, @@ -1179,6 +1182,11 @@ pub(crate) mod printing { #[cfg_attr(docsrs, doc(cfg(feature = "printing")))] impl ToTokens for Generics { + /// N.B. This method tokenises the contents of `self.params` only. + /// `self.where_clause` should be covered separately by the caller + /// as per the kind of the item to which `self` belongs. + /// + /// Please refer to [`Generics`] for the rationale of this design. fn to_tokens(&self, tokens: &mut TokenStream) { if self.params.is_empty() { return;