-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
I'm not sure whether this is a compiler or language docs issue, so I'll report it here and cc @rust-lang/lang-docs
The Reference and FLS specify that the operands of extending array expressions are extending. Clicking through to see the definition of array expressions, both specifications include [expr; N]
repetition expressions. Thus from these specifications I would expect
let x = [&temp(); 1];
to extend temp()
to live in the same scope as x
. This is not the case (playground):
fn temp() {}
fn main() {
let extended = [&temp()];
extended; // this is okay
let not_extended = [&temp(); 1];
not_extended;
//~^ ERROR: temporary value dropped while borrowed
}
On the compiler side, the implementation of extending expressions only includes normal array expressions, not repetition expressions, which are represented as hir::ExprKind::Repeat
rather than hir:ExprKind::Array
.
@rustbot label +T-compiler +T-lang +T-lang-docs +A-docs +A-temporary-lifetime-extension +A-array