pub static MACRO_EXTENDED_TEMPORARY_SCOPES: &LintExpand description
The macro_extended_temporary_scopes lint detects borrowed temporary
values in arguments to pin! and formatting macros which have longer
lifetimes than intended due to a bug in the compiler. For more
information on temporary scopes and lifetime extension, see the
Rust Reference.
§Example
fn main() {
println!("{:?}{}", (), if cond() { &build_string() } else { "" });
}{{produces}}
§Recommended fix
To extend the lifetimes of temporaries borrowed in macro arguments,
create separate definitions for them with let statements.
fn main() {
let string = if cond() { &build_string() } else { "" };
println!("{:?}{}", (), string);
}§Explanation
Due to a compiler bug, pin! and formatting macros were able to extend
the lifetimes of temporaries borrowed in their arguments past their
usual scopes. The bug is fixed in future Rust versions, so we issue this
future-incompatibility warning for code that may stop compiling or may
change in behavior thereafter.