递归的 `--config-path` 不会递归
作者: lnicola创建于 2021年1月21日更新于 2026年9月11日
标签C-bug
描述错误
--config-path 的帮助说明如下:
--config-path [Path for the configuration file]
Recursively searches the given path for the
rustfmt.toml config file. If not found reverts to the
input file path然而,它似乎没有递归搜索:
$ rustfmt --config-path ~/Downloads/test_issue/my_crate/src/main.rs --edition 2018 < ~/Downloads/test_issue/my_crate/src/main.rs
Could not parse TOML: expected an equals, found an identifier at line 1 column 4
$ rustfmt --config-path ~/Downloads/test_issue/my_crate/src/ --edition 2018 < ~/Downloads/test_issue/my_crate/src/main.rs
Error: unable to find a config file for the given path: `~/Downloads/test_issue/my_crate/src/`
$ rustfmt --config-path ~/Downloads/test_issue/my_crate/src --edition 2018 < ~/Downloads/test_issue/my_crate/src/main.rs
Error: unable to find a config file for the given path: `~/Downloads/test_issue/my_crate/src`
$ rustfmt --config-path ~/Downloads/test_issue/my_crate --edition 2018 < ~/Downloads/test_issue/my_crate/src/main.rs
fn fjsdlkfjklsdajflksdjlfdasdsadsadsaadkjdskljflkasj_jflksjdklfjsdlkjflkdjslkfjas(a: i32, b: i32, c: i32) {
println!("TEST");
}
fn main() {
fjsdlkfjklsdajflksdjlfdasdsadsadsaadkjdskljflkasj_jflksjdklfjsdlkjflkdjslkfjas(1, 2, 3);
println!("Hello, world!");
}
$ rustfmt --config-path ~/Downloads/test_issue/ --edition 2018 < ~/Downloads/test_issue/my_crate/src/main.rs
Error: unable to find a config file for the given path: `~/Downloads/test_issue/`
**重现**
测试项目来自 https://GitHub.com/Rust-analyzer/Rust-analyzer/issues/6973#issuecomment-762881775内容来源: rust-lang/rustfmt