-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't promote temporary to static when a const fn
is involved
#85181
Comments
const fn
is involvedconst fn
is involved
const fn
is involvedconst fn
is involved
const fn
is involvedconst fn
is involved
Arbitrary |
To be clear, I think the behavior is intended to stay this way. cc @RalfJung |
Yes, this is intended. Promoting However, your observation that static _STATIC2: &Foo = {
let x = &Foo::new();
x
}; This is for backwards compatibility and because the concerns around promoting So, the summary is that |
Closing as intended behavior per this RFC. |
See this playground code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c21ca661aa56e4594e46510acd21c630
In the case of
_bar
, the code gives no errors. The compiler is able to promote the temporary into astatic
. But for_baz
, which calls aconst fn
, the compiler fails to do this, and complains of a temporary being dropped. It is, however, able to do so for_STATIC
, which is explicitly declared as astatic
variable.Of course, it shouldn't be dropping the temporary here, but promote it to
static
just like the first line.The text was updated successfully, but these errors were encountered: