This rust code does different things in stable vs beta/nightly lol
This code prints "X10" on stable, but prints "X01" on beta or nightly. I found the code in this comment in the PR that caused this change in behavior.
The short explanation is: The print! macro got changed. Before this change, the argument would get dropped at the end of the statement. After this change, the argument would get dropped inside the macro. (Notably, this change makes print! behave the same way as println!. Yes, they used to drop things differently.)
Apparently this doesn't count as a break in the stability promise. It's probably fine since this is such a ridiculous edge case, but I find it amusing.
use std::fmt::{self, Display};
use std::ops::Add;
struct X(usize);
impl Display for X {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("X")
}
}
impl Add<X> for () {
type Output = ();
fn add(self, _: X) -> Self::Output {}
}
impl Drop for X {
fn drop(&mut self) {
print!("{}", self.0);
}
}
fn main() {
print!("{}", X(0)) + X(1);
}