You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
format_args!() can currently only be stored (and used later) if it has no arguments:
let a = format_args!("1 + 1 = 2");// oklet b = format_args!("1 + 1 = {}",2);// errorprintln!("{a} {b}");
However, format_args!("1 + 1 = {}", 2) is optimized to (effectively) format_args!("1 + 1 = 2") as part of ast lowering.
To avoid allowing more code because of this optimization, the lowering results in a slightly different expansion that would still result in the same error. (By using &none() rather than &[].)
However, I had failed to consider the effect in a const:
format_args!()can currently only be stored (and used later) if it has no arguments:However,
format_args!("1 + 1 = {}", 2)is optimized to (effectively)format_args!("1 + 1 = 2")as part of ast lowering.To avoid allowing more code because of this optimization, the lowering results in a slightly different expansion that would still result in the same error. (By using
&none()rather than&[].)However, I had failed to consider the effect in aconst:However, because of #135139, we now have:
(The expression for Y is subject to format_args inlining/flattening. The one for Z is not.)
It means there can be code out there that relies on format_args inlining/flattening working the way it does today.
Two solutions:
Yexample fail to compile as well. This would be a (small?) breaking change. Don't allow flattened format_args in const. #139624