Repository: tokio-rs/prost (language: rust)

Issue:
Add @generated comment at the top of the generated file
If a file starts with `// @generated` then [rustfmt will ignore it](https://github.com/rust-lang/rustfmt/pull/4296).

This is useful if you're committing the generated files to git and you don't want to have CI fail because of the generated files


Discussion / hints:

Fix patch:
diff --git a/prost-build/src/fixtures/alphabet/_expected_include.rs b/prost-build/src/fixtures/alphabet/_expected_include.rs
index 8f42b561e..87de4feed 100644
--- a/prost-build/src/fixtures/alphabet/_expected_include.rs
+++ b/prost-build/src/fixtures/alphabet/_expected_include.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 pub mod a {
     include!("a.rs");
 }
diff --git a/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs b/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs
index 04860e63d..95fb05d86 100644
--- a/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs
+++ b/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
 pub struct Container {
diff --git a/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs b/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs
index 8c329f902..f1eaee751 100644
--- a/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs
+++ b/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
 pub struct Container {
diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs
index 2f05c46ed..401ee90cd 100644
--- a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs
+++ b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 #[derive(derive_builder::Builder)]
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs
index a64c4da3c..3f688c7e0 100644
--- a/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs
+++ b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 #[derive(derive_builder::Builder)]
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
diff --git a/prost-build/src/fixtures/imports_empty/_expected_include.rs b/prost-build/src/fixtures/imports_empty/_expected_include.rs
index 6deb45f07..a9dcc9386 100644
--- a/prost-build/src/fixtures/imports_empty/_expected_include.rs
+++ b/prost-build/src/fixtures/imports_empty/_expected_include.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 pub mod com {
     pub mod prost_test {
         pub mod test {
diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs
index f8aa05687..9b71094b3 100644
--- a/prost-build/src/lib.rs
+++ b/prost-build/src/lib.rs
@@ -1031,6 +1031,7 @@ impl Config {
         if let Some(ref include_file) = self.include_file {
             trace!("Writing include file: {:?}", target.join(include_file));
             let mut file = fs::File::create(target.join(include_file))?;
+            self.write_line(&mut file, 0, "// This file is @generated by prost-build.")?;
             self.write_includes(
                 modules.keys().collect(),
                 &mut file,
@@ -1266,9 +1267,18 @@ impl Config {
             self.fmt_modules(&mut modules);
         }
 
+        self.add_generated_modules(&mut modules);
+
         Ok(modules)
     }
 
+    fn add_generated_modules(&mut self, modules: &mut HashMap<Module, String>) {
+        for buf in modules.values_mut() {
+            let with_generated = "// This file is @generated by prost-build.\n".to_string() + buf;
+            *buf = with_generated;
+        }
+    }
+
     #[cfg(feature = "format")]
     fn fmt_modules(&mut self, modules: &mut HashMap<Module, String>) {
         for buf in modules.values_mut() {
diff --git a/prost-types/src/compiler.rs b/prost-types/src/compiler.rs
index 81cdcfa55..0a3b46804 100644
--- a/prost-types/src/compiler.rs
+++ b/prost-types/src/compiler.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 /// The version number of protocol compiler.
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs
index fcbe430df..edc1361be 100644
--- a/prost-types/src/protobuf.rs
+++ b/prost-types/src/protobuf.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 /// The protocol compiler can output a FileDescriptorSet containing the .proto
 /// files it parses.
 #[allow(clippy::derive_partial_eq_without_eq)]


Test patch:
diff --git a/tests/single-include/src/outdir/mod.rs b/tests/single-include/src/outdir/mod.rs
index 8cf70ccb6..400d90465 100644
--- a/tests/single-include/src/outdir/mod.rs
+++ b/tests/single-include/src/outdir/mod.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 pub mod outdir {
     include!("outdir.rs");
 }
diff --git a/tests/single-include/src/outdir/outdir.rs b/tests/single-include/src/outdir/outdir.rs
index eee461c1b..577245e5f 100644
--- a/tests/single-include/src/outdir/outdir.rs
+++ b/tests/single-include/src/outdir/outdir.rs
@@ -1,3 +1,4 @@
+// This file is @generated by prost-build.
 #[allow(clippy::derive_partial_eq_without_eq)]
 #[derive(Clone, PartialEq, ::prost::Message)]
 pub struct OutdirRequest {