Skip to content

Commit 78d6c1b

Browse files
fix: incorrect rustfmt edition query (#1582)
* fix: incorrect rustfmt edition query This change fixes incorrect query gathering rust targets with an explicitly specified edition. The comment above the query states the following intention: > Get all targets with the specified `edition` attribute. > Except for targets tagged with `norustfmt`. > And except for targets with a populated `crate` attribute since > `crate` defines edition for this target However, the actual query is: ``` let scope = set({scope}) in filter("^//.*\.rs$", kind("source file", deps(attr(edition, "{edition}", $scope) except attr(tags, "...", $scope) + attr(crate, ".*", $scope), 1))) ``` According to the query grammar[1], `X except Y + Z` parses as `(X except Y) + Z)`, while the author's intention was clearly `X except (Y + Z)`. The fix changes the expression to `X except Y except Z` that implements the original intention correctly. Fixes #1579. [1]: https://bazel.build/query/language#algebraic-set-operations * Update tools/rustfmt/src/main.rs
1 parent 4892712 commit 78d6c1b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/rustfmt/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ fn edition_query(bazel_bin: &Path, edition: &str, scope: &str, current_dir: &Pat
7575
// Get all source files.
7676
// Get direct dependencies.
7777
// Get all targets with the specified `edition` attribute.
78-
// Except for targets tagged with `norustfmt`.
78+
// Except for targets tagged with `norustfmt`, `no-rustfmt`, or `no-format`.
7979
// And except for targets with a populated `crate` attribute since `crate` defines edition for this target
8080
format!(
81-
r#"let scope = set({scope}) in filter("^//.*\.rs$", kind("source file", deps(attr(edition, "{edition}", $scope) except attr(tags, "(^\[|, )(no-format|no-rustfmt|norustfmt)(, |\]$)", $scope) + attr(crate, ".*", $scope), 1)))"#,
81+
r#"let scope = set({scope}) in filter("^//.*\.rs$", kind("source file", deps(attr(edition, "{edition}", $scope) except attr(tags, "(^\[|, )(no-format|no-rustfmt|norustfmt)(, |\]$)", $scope) except attr(crate, ".*", $scope), 1)))"#,
8282
edition = edition,
8383
scope = scope,
8484
),

0 commit comments

Comments
 (0)