define_extension_trait: allow impls on generic types
What changed, and why it matters
This is a small Rust macro change that makes an internal helper macro able to define extension traits for generic types, not just plain types. It adds optional generic type parameters to the macro pattern. There is no security-relevant change visible in the diff.
No security action needed. Review as normal code-quality/macros change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies define_extension_trait! in bitcoin/src/internal_macros.rs to accept optional generic parameters on the trait, impl block, and target type. This is a macro grammar expansion (e.g., trait Foo<T> impl<U> for Bar<V>). No runtime behavior, boundary checks, cryptographic operations, or unsafe code is changed.
Changed components
bitcoin/src/internal_macros.rsInspect captured patch +3 / −3
diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs
index 0f7774e5..82b10e72 100644
--- a/bitcoin/src/internal_macros.rs
+++ b/bitcoin/src/internal_macros.rs
@@ -246,14 +246,14 @@ pub(crate) use only_non_doc_attrs;
/// Defines a trait `$trait_name` and implements it for `ty`, used to define extension traits.
macro_rules! define_extension_trait {
- ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident {
+ ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident$(<$traitgen:ident $(= $traitdefault:ty)?>)? impl$(<$implgen:ident $(= $impldefault:ty)?>)? for $ty:ident$(<$tygen:ident $(= $tydefault:ty)?>)? {
$(
$(#[$($fn_attrs:tt)*])*
fn $fn:ident$(<$($gen:ident: $gent:path),*>)?($($params:tt)*) $( -> $ret:ty )? $(where $wherety:ident $(= $whereeq:ident)? $(: $wherebound:ident)?)? $body:block
)*
}) => {
#[cfg_attr(docsrs, doc(notable_trait))]
- $(#[$($trait_attrs)*])* $trait_vis trait $trait_name: sealed::Sealed {
+ $(#[$($trait_attrs)*])* $trait_vis trait $trait_name$(<$traitgen $(= $traitdefault)?>)?: sealed::Sealed {
$(
$crate::internal_macros::only_doc_attrs! {
{ $(#[$($fn_attrs)*])* },
@@ -264,7 +264,7 @@ macro_rules! define_extension_trait {
)*
}
- impl $trait_name for $ty {
+ impl$(<$implgen $(= $impldefault)?>)? $trait_name$(<$traitgen $(= $traitdefault)?>)? for $ty$(<$tygen $(= $tydefault)?>)? {
$(
$crate::internal_macros::only_non_doc_attrs! {
{ $(#[$($fn_attrs)*])* },
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.