Skip to content

Commit

Permalink
Reorder precise captured params to print lifetimes before idents
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 20, 2024
1 parent b387249 commit 9e125ce
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,26 @@ pub(crate) mod printing {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.use_token.to_tokens(tokens);
self.lt_token.to_tokens(tokens);
self.params.to_tokens(tokens);

// Print lifetimes before types and consts, regardless of their
// order in self.params.
let mut trailing_or_empty = true;
for param in self.params.pairs() {
if let CapturedParam::Lifetime(_) = **param.value() {
param.to_tokens(tokens);
trailing_or_empty = param.punct().is_some();
}
}
for param in self.params.pairs() {
if let CapturedParam::Ident(_) = **param.value() {
if !trailing_or_empty {
<Token![,]>::default().to_tokens(tokens);
trailing_or_empty = true;
}
param.to_tokens(tokens);
}
}

self.gt_token.to_tokens(tokens);
}
}
Expand Down

0 comments on commit 9e125ce

Please sign in to comment.