Skip to content

Commit

Permalink
Merge pull request #54 from dtolnay/bracket
Browse files Browse the repository at this point in the history
Fix parsing of angle brackets in writedoc expr argument
  • Loading branch information
dtolnay committed Jan 29, 2023
2 parents a8f5edf + f9e455e commit bdfa483
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/expr.rs
Expand Up @@ -10,6 +10,7 @@ pub fn parse(input: &mut TokenIter) -> Result<Expr> {
enum Lookbehind {
JointColon,
DoubleColon,
JointHyphen,
Other,
}

Expand All @@ -31,10 +32,11 @@ pub fn parse(input: &mut TokenIter) -> Result<Expr> {
angle_bracket_depth += 1;
Lookbehind::Other
}
'>' if angle_bracket_depth > 0 => {
'>' if angle_bracket_depth > 0 && lookbehind != Lookbehind::JointHyphen => {
angle_bracket_depth -= 1;
Lookbehind::Other
}
'-' if spacing == Spacing::Joint => Lookbehind::JointHyphen,
_ => Lookbehind::Other,
};
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_writedoc.rs
Expand Up @@ -42,13 +42,13 @@ fn test_angle_bracket_parsing() {
const ZERO: usize = 0;

struct Pair<A, B>(A, B);
impl Pair<(), ()> {
impl<A, B> Pair<A, B> {
const ONE: usize = 1;
}

let mut s = String::new();
let _ = writedoc! {
if ZERO < Pair::<(), ()>::ONE { &mut s } else { &mut s },
if ZERO < Pair::<fn() -> (), ()>::ONE { &mut s } else { &mut s },
"writedoc",
};

Expand Down

0 comments on commit bdfa483

Please sign in to comment.