Closed
Description
It's unintuitive that this doesn't compile:
struct Foo;
const fn bar() -> Foo { Foo }
// doesn't compile
fn foo() -> &'static Foo {
&bar()
}
// this compiles
fn foo2() -> &'static Foo {
const FOO: &'static Foo = &bar();
FOO
}
// this compiles
fn foo3() -> &'static Foo {
const FOO: Foo = bar();
&FOO
}
rustc should just generate a const
(or static
) behind the scenes and typecheck the code as if the user had written that.
Activity
jonas-schievink commentedon Jul 17, 2020
This is intended behavior according to rust-lang/const-eval#19