Why is there a plus sign inside of the macro implementing Add for numbers in Rust?
Hello!
While looking into Rust's implementation of the Add trait, I noticed that the add method has the expression self + other. I find that intriguing because isn't + the same operator that this implementation is defining behavior for? What implementation of + is add calling here, if say u8 doesn't have that behavior defined yet? Like in fn add(self, other: u8) -> u8 { self + other } for example.
Here is the source code of the macro:
macro_rules! add_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Add for $t {
type Output = $t;
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
fn add(self, other: $t) -> $t { self + other }
}
forward_ref_binop! { impl Add, add for $t, $t }
)*)
}