Skip to content

Commit 9ac18a2

Browse files
committed
Try reading both rust-toolchain and rust-toolchain.toml
1 parent f113fde commit 9ac18a2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

internal/src/clippy_utils.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Context, Result, anyhow};
1+
use anyhow::{Context, Result, anyhow, bail};
22
use semver::Version;
33
use std::{
44
fs::{read_to_string, write},
@@ -68,12 +68,21 @@ pub fn set_clippy_utils_dependency_revision(path: &Path, rev: &str) -> Result<()
6868

6969
pub fn toolchain_channel(path: &Path) -> Result<String> {
7070
let rust_toolchain = path.join("rust-toolchain");
71-
let contents = read_to_string(&rust_toolchain).with_context(|| {
72-
format!(
73-
"`read_to_string` failed for `{}`",
74-
rust_toolchain.to_string_lossy(),
75-
)
76-
})?;
71+
let rust_toolchain_toml = path.join("rust-toolchain.toml");
72+
let contents = match read_to_string(&rust_toolchain) {
73+
Ok(contents) => contents,
74+
Err(error) => match read_to_string(&rust_toolchain_toml) {
75+
Ok(contents) => contents,
76+
Err(error_toml) => {
77+
bail!(
78+
"`read_to_string` failed for both `{}` and `{}`: {:#?}",
79+
rust_toolchain.to_string_lossy(),
80+
rust_toolchain_toml.to_string_lossy(),
81+
[error, error_toml]
82+
);
83+
}
84+
},
85+
};
7786
let document = contents.parse::<DocumentMut>()?;
7887
document
7988
.as_table()

0 commit comments

Comments
 (0)