Skip to content

Commit

Permalink
Fix precedence of attrs on assignment expr in stmt position
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 3, 2021
1 parent a2701a0 commit c09a2e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,13 @@ pub mod parsing {
let mut e = expr::parsing::expr_early(input)?;

let mut attr_target = &mut e;
while let Expr::Binary(e) = attr_target {
attr_target = &mut e.left;
loop {
attr_target = match attr_target {
Expr::Assign(e) => &mut e.left,
Expr::AssignOp(e) => &mut e.left,
Expr::Binary(e) => &mut e.left,
_ => break,
};
}
attrs.extend(attr_target.replace_attrs(Vec::new()));
attr_target.replace_attrs(attrs);
Expand Down
4 changes: 0 additions & 4 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ static EXCLUDE: &[&str] = &[
"src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs",
"src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs",

// TODO: precedence of attribute on assignment stmt
"src/tools/rustfmt/tests/source/attrib.rs",
"src/tools/rustfmt/tests/target/attrib.rs",

// TODO: doc comment on match arm
"src/tools/rustfmt/tests/source/match.rs",
"src/tools/rustfmt/tests/target/match.rs",
Expand Down

0 comments on commit c09a2e5

Please sign in to comment.