This CL applies the `#[deprecated]` attribute of an `impl` block to all of the function definitions within that `impl` block.

PiperOrigin-RevId: 644170637
Change-Id: I3319099e2d885f21ea8df7eb3ab7d1ddaac5dd2e
diff --git a/cc_bindings_from_rs/bindings.rs b/cc_bindings_from_rs/bindings.rs
index 9d43c39..9690c2e 100644
--- a/cc_bindings_from_rs/bindings.rs
+++ b/cc_bindings_from_rs/bindings.rs
@@ -1200,6 +1200,14 @@
         if let Some(cc_deprecated_tag) = format_deprecated_tag(tcx, def_id) {
             attributes.push(cc_deprecated_tag);
         }
+        // Also check the impl block to which this function belongs (if there is one).
+        // Note: parent_def_id can be Some(...) even if the function is not inside an
+        // impl block.
+        if let Some(parent_def_id) = tcx.opt_parent(def_id) {
+            if let Some(cc_deprecated_tag) = format_deprecated_tag(tcx, parent_def_id) {
+                attributes.push(cc_deprecated_tag);
+            }
+        }
 
         CcSnippet {
             prereqs,
@@ -7627,6 +7635,44 @@
     }
 
     #[test]
+    fn test_deprecated_attr_for_impl_block() {
+        let test_src = r#"
+        pub struct SomeStruct {
+            pub x: u32,
+            pub y: u32,
+        }
+
+        #[deprecated = "Use AnotherStruct instead"]
+        impl SomeStruct {
+            pub fn sum(&self) -> u32 {
+                self.x + self.y
+            }
+
+            pub fn product(&self) -> u32 {
+                self.x * self.y
+            }
+        }"#;
+
+        test_format_item(test_src, "SomeStruct", |result| {
+            let result = result.unwrap().unwrap();
+            let main_api = &result.main_api;
+            assert!(!main_api.prereqs.is_empty());
+            assert_cc_matches!(
+                main_api.tokens,
+                quote! {
+                    struct ... SomeStruct final {
+                        ...
+                        ... [[deprecated("Use AnotherStruct instead")]] std::uint32_t sum() const ...
+                        ...
+                        ... [[deprecated("Use AnotherStruct instead")]] std::uint32_t product() const ...
+                        ...
+                    };
+                }
+            )
+        })
+    }
+
+    #[test]
     fn test_multiple_attributes() {
         let test_src = r#"
         #[must_use = "Must use"]