Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dtolnay/prettyplease
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.2.21
Choose a base ref
...
head repository: dtolnay/prettyplease
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.2.22
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 25, 2024

  1. Upload CI Cargo.lock for reproducing failures

    dtolnay committed Aug 25, 2024
    Copy the full SHA
    61bd508 View commit details
  2. Pretty-print precise capture syntax (use<>)

    dtolnay committed Aug 25, 2024
    Copy the full SHA
    b54cd12 View commit details
  3. Merge pull request #80 from dtolnay/precisecapture

    Pretty-print precise capture syntax (`use<>`)
    dtolnay authored Aug 25, 2024
    Copy the full SHA
    dd76fd6 View commit details
  4. Release 0.2.22

    dtolnay committed Aug 25, 2024
    Copy the full SHA
    c28d8ea View commit details
Showing with 54 additions and 4 deletions.
  1. +5 −0 .github/workflows/ci.yml
  2. +1 −1 Cargo.toml
  3. +47 −2 src/generics.rs
  4. +1 −1 src/lib.rs
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -36,6 +36,11 @@ jobs:
- run: cargo test
env:
RUSTFLAGS: ${{env.RUSTFLAGS}} ${{matrix.rust == 'nightly' && '--cfg exhaustive' || ''}}
- uses: actions/upload-artifact@v4
if: matrix.rust == 'nightly' && always()
with:
name: Cargo.lock
path: Cargo.lock

examples:
name: Examples
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prettyplease"
version = "0.2.21"
version = "0.2.22"
authors = ["David Tolnay <dtolnay@gmail.com>"]
autoexamples = false
categories = ["development-tools"]
49 changes: 47 additions & 2 deletions src/generics.rs
Original file line number Diff line number Diff line change
@@ -151,13 +151,19 @@ impl Printer {
#[cfg(feature = "verbatim")]
fn type_param_bound_verbatim(&mut self, tokens: &TokenStream) {
use syn::parse::{Parse, ParseStream, Result};
use syn::{parenthesized, token, Token};
use syn::{parenthesized, token, Ident, Lifetime, Token};

enum TypeParamBoundVerbatim {
Ellipsis,
PreciseCapture(Vec<Capture>),
TildeConst(TraitBound),
}

enum Capture {
Lifetime(Lifetime),
Type(Ident),
}

impl Parse for TypeParamBoundVerbatim {
fn parse(input: ParseStream) -> Result<Self> {
let content;
@@ -167,7 +173,33 @@ impl Printer {
(None, input)
};
let lookahead = content.lookahead1();
if lookahead.peek(Token![~]) {
if lookahead.peek(Token![use]) {
input.parse::<Token![use]>()?;
input.parse::<Token![<]>()?;
let mut captures = Vec::new();
loop {
let lookahead = input.lookahead1();
captures.push(if lookahead.peek(Lifetime) {
input.parse().map(Capture::Lifetime)?
} else if lookahead.peek(Ident) {
input.parse().map(Capture::Type)?
} else if lookahead.peek(Token![>]) {
break;
} else {
return Err(lookahead.error());
});
let lookahead = input.lookahead1();
if lookahead.peek(Token![,]) {
input.parse::<Token![,]>()?;
} else if lookahead.peek(Token![>]) {
break;
} else {
return Err(lookahead.error());
}
}
input.parse::<Token![>]>()?;
Ok(TypeParamBoundVerbatim::PreciseCapture(captures))
} else if lookahead.peek(Token![~]) {
content.parse::<Token![~]>()?;
content.parse::<Token![const]>()?;
let mut bound: TraitBound = content.parse()?;
@@ -191,6 +223,19 @@ impl Printer {
TypeParamBoundVerbatim::Ellipsis => {
self.word("...");
}
TypeParamBoundVerbatim::PreciseCapture(captures) => {
self.word("use<");
for capture in captures.iter().delimited() {
match *capture {
Capture::Lifetime(lifetime) => self.lifetime(lifetime),
Capture::Type(ident) => self.ident(ident),
}
if !capture.is_last {
self.word(", ");
}
}
self.word(">");
}
TypeParamBoundVerbatim::TildeConst(trait_bound) => {
let tilde_const = true;
self.trait_bound(&trait_bound, tilde_const);
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -320,7 +320,7 @@
//! these situations with conditional punctuation tokens whose selection can be
//! deferred and populated after it's known that the group is or is not broken.
#![doc(html_root_url = "https://docs.rs/prettyplease/0.2.21")]
#![doc(html_root_url = "https://docs.rs/prettyplease/0.2.22")]
#![allow(
clippy::cast_possible_wrap,
clippy::cast_sign_loss,