diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index 8af6e7a5897..6c25b82e98b 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -165,7 +165,14 @@ fn write_no_inner_attr(output: &str, filter: &[&str]) { } fn riddle(output: &str, filter: &[&str], config: &[&str]) { - _ = std::fs::remove_file(output); + // Rust-analyzer may re-run build scripts whenever a source file is deleted + // which causes an endless loop if the file is deleted from a build script. + // To workaroud this, we truncate the file instead of deleting it. + // See #2777. + _ = std::fs::File::options() + .truncate(true) + .write(true) + .open(output); let mut command = std::process::Command::new("cargo");