Skip to content

RUSTC_BLESS=1 cargo test modifies source files instead of targets #6056

@Nemo157

Description

@Nemo157

Reproduction:

# make a target file wrong
> echo > tests/target/5131_module.rs

# run tests with blessing enabled
> RUSTC_BLESS=1 cargo test

# check what it changed
> git diff
diff --git tests/source/5131_module.rs tests/source/5131_module.rs
index 3e913917..763024d6 100644
--- tests/source/5131_module.rs
+++ tests/source/5131_module.rs
@@ -9,8 +9,7 @@ mod a {
         }
     }
 
-    use crate::a::b::Data;
-    use crate::a::b::Data as Data2;
+    use crate::a::b::{Data, Data as Data2};
 
     pub fn data(a: i32) -> Data {
         Data { a }
diff --git tests/target/5131_module.rs tests/target/5131_module.rs
index 763024d6..8b137891 100644
--- tests/target/5131_module.rs
+++ tests/target/5131_module.rs
@@ -1,32 +1 @@
-// rustfmt-imports_granularity: Module
 
-#![allow(dead_code)]
-
-mod a {
-    pub mod b {
-        pub struct Data {
-            pub a: i32,
-        }
-    }
-
-    use crate::a::b::{Data, Data as Data2};
-
-    pub fn data(a: i32) -> Data {
-        Data { a }
-    }
-
-    pub fn data2(a: i32) -> Data2 {
-        Data2 { a }
-    }
-
-    #[cfg(test)]
-    mod tests {
-        use super::*;
-
-        #[test]
-        pub fn test() {
-            data(1);
-            data2(1);
-        }
-    }
-}

My expectation is that this should be writing to target, but it was originally implemented for ./x support in the main tree, so I'm not sure if that expects it to modify source files instead for some reason.

std::fs::write(file_name, fmt_text).unwrap();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions