rustfmt: Use edition form Cargo.toml rather than always 2015 (DO NOT MERGE)
#5232
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.
This patch shows an example solution to #4074, where
rustfmtwill fetch theeditionfrom the source of truth:Cargo.toml. This is meant as a point of discussion rather than a serious fix.For example, this allows
rustfmtto be run against files in therust-lang/rustfmtrepository itself and automatically detect the correct edition of2018as configured inCargo.toml, rather than using the incorrect default of2015like it does today.From discussion in #4074, it sounds like the current preference is to not have
rustfmtbe the user-facing tool for formatting individual files and to instead have a different command for that? But in the meantime this provides a reference for one way that it could be done.Note that if this were a serious PR I would also have written tests for the change, including the missing tests for the current scan for
rustfmt.toml, but again this is just meant to be an example to show how the lookup logic could work and per discussion it isn't expected to be accepted.As of this patch, the
editionselection order is as follows:--editionprovided as an argumenteditionfrom anyrustfmt.tomlin the directory tree or on the host system (IMO this should be deprecated)package.editionfromCargo.tomlin the directory tree (NEW)2015