diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-05-23 14:37:52 -0400 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2025-07-11 00:59:19 -0400 |
| commit | ed1088eec4235e7bb86ff9ea4c231c5b5472f7b7 (patch) | |
| tree | 51a777066f5a7c844791c5098d0adb420a5fce46 | |
| parent | 46ff0a85657fcc08f36fec0a06455536c3296121 (diff) | |
| download | rust-ed1088eec4235e7bb86ff9ea4c231c5b5472f7b7.tar.gz rust-ed1088eec4235e7bb86ff9ea4c231c5b5472f7b7.zip | |
Use `track_caller` more for better error spans in `clippy_dev`
| -rw-r--r-- | clippy_dev/src/utils.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clippy_dev/src/utils.rs b/clippy_dev/src/utils.rs index 4b77a49a9f6..0c5020c6982 100644 --- a/clippy_dev/src/utils.rs +++ b/clippy_dev/src/utils.rs @@ -338,6 +338,7 @@ pub struct FileUpdater { dst_buf: String, } impl FileUpdater { + #[track_caller] fn update_file_checked_inner( &mut self, tool: &str, @@ -361,6 +362,7 @@ impl FileUpdater { } } + #[track_caller] fn update_file_inner(&mut self, path: &Path, update: &mut dyn FnMut(&Path, &str, &mut String) -> UpdateStatus) { let mut file = File::open(path, OpenOptions::new().read(true).write(true)); file.read_to_cleared_string(&mut self.src_buf); @@ -370,6 +372,7 @@ impl FileUpdater { } } + #[track_caller] pub fn update_file_checked( &mut self, tool: &str, @@ -380,6 +383,7 @@ impl FileUpdater { self.update_file_checked_inner(tool, mode, path.as_ref(), update); } + #[track_caller] pub fn update_file( &mut self, path: impl AsRef<Path>, @@ -598,6 +602,7 @@ impl<'txt> RustSearcher<'txt> { } } +#[track_caller] #[expect(clippy::must_use_candidate)] pub fn try_rename_file(old_name: &Path, new_name: &Path) -> bool { match OpenOptions::new().create_new(true).write(true).open(new_name) { @@ -620,6 +625,7 @@ pub fn try_rename_file(old_name: &Path, new_name: &Path) -> bool { } } +#[track_caller] #[expect(clippy::must_use_candidate)] pub fn try_rename_dir(old_name: &Path, new_name: &Path) -> bool { match fs::create_dir(new_name) { @@ -646,10 +652,12 @@ pub fn try_rename_dir(old_name: &Path, new_name: &Path) -> bool { } } +#[track_caller] pub fn write_file(path: &Path, contents: &str) { expect_action(fs::write(path, contents), ErrAction::Write, path); } +#[track_caller] pub fn run_exit_on_err(path: &(impl AsRef<Path> + ?Sized), cmd: &mut Command) { match expect_action(cmd.status(), ErrAction::Run, path.as_ref()).code() { Some(0) => {}, @@ -661,6 +669,7 @@ pub fn run_exit_on_err(path: &(impl AsRef<Path> + ?Sized), cmd: &mut Command) { } } +#[track_caller] #[must_use] pub fn run_with_output(path: &(impl AsRef<Path> + ?Sized), cmd: &mut Command) -> Vec<u8> { fn f(path: &Path, cmd: &mut Command) -> Vec<u8> { @@ -746,6 +755,7 @@ pub fn split_args_for_threads( } } +#[track_caller] #[expect(clippy::must_use_candidate)] pub fn delete_file_if_exists(path: &Path) -> bool { match fs::remove_file(path) { @@ -755,6 +765,7 @@ pub fn delete_file_if_exists(path: &Path) -> bool { } } +#[track_caller] pub fn delete_dir_if_exists(path: &Path) { match fs::remove_dir_all(path) { Ok(()) => {}, |
