Fix rustfmt silently skipping symlinked sources#4002
Open
tamasvajk wants to merge 4 commits intobazelbuild:mainfrom
Open
Fix rustfmt silently skipping symlinked sources#4002tamasvajk wants to merge 4 commits intobazelbuild:mainfrom
rustfmt silently skipping symlinked sources#4002tamasvajk wants to merge 4 commits intobazelbuild:mainfrom
Conversation
added 4 commits
April 28, 2026 13:59
When transform_sources() symlinks hand-written .rs files into bazel-out (which happens when any compile_data entry is generated), the symlinked files are no longer is_source=True. This causes _find_rustfmtable_srcs to filter them all out, silently skipping formatting for the entire crate. Fix by recovering original source files from the aspect context's rule attributes when available. Also use crate_info.srcs directly in rustfmt_test to include all sources.
Add a test case with an intentionally unformatted source file and generated compile_data. This triggers transform_sources to symlink sources into bazel-out, exercising the fix in _find_rustfmtable_srcs. Without the fix, rustfmt silently passes (sources are skipped). With the fix, rustfmt correctly detects the formatting issue.
The test uses an intentionally unformatted source and is expected to fail. Including it in the test_suite causes CI to run it via //... and report failures. The test is already exercised by the rustfmt_failure_tester.sh script which expects exit code 3.
The unformatted source caused CI failures: - --config=rustfmt aspect caught the formatting issue during build - rustfmt_failure_tester.sh couldn't format it due to norustfmt tag Use a properly formatted source instead. The test still exercises the code path where compile_data has a generated file (triggering transform_sources), verifying that rustfmt correctly finds and checks the sources rather than silently skipping them.
7390345 to
34b71b4
Compare
Collaborator
|
@tamasvajk Does #3983 solve for your needs? This seems to be solving a similar issue to #3850 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
rustfmt_testandrustfmt_aspectsilently skipping hand-written sources that were symlinked bytransform_sources().Problem
When any
compile_dataentry is a generated file,transform_sources()symlinks all source files intobazel-out. After symlinking,is_sourcereturnsFalsefor these files, so_find_rustfmtable_srcsfilters them all out. The result is that rustfmt silently does nothing — no error, no formatting check.Fix
When the aspect context is available, recover original source
Fileobjects from the rule'ssrcsattribute (which still references the pre-symlink originals). This preserves correctexec_pathandshort_pathfor manifests and runfiles.Also use
crate_info.srcsdirectly in_rustfmt_test_implto include all sources.