Skip to content

Commit

Permalink
Merge pull request #1754 from dtolnay/precisecapture
Browse files Browse the repository at this point in the history
Reorder precise captured params to print lifetimes before idents
  • Loading branch information
dtolnay authored Oct 20, 2024
2 parents b387249 + 9e125ce commit 2525a10
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 2525a10

Please sign in to comment.