-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Spawned off of #54528 (specificially this card in the project).
Consider the following code:
const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
fn main() { }
With AST-borrowck, you get (play):
error: trait bounds other than `Sized` on const fn parameters are unstable
--> src/main.rs:1:32
|
1 | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
With NLL (here using migration a la 2018 edition), you get (play):
error: trait bounds other than `Sized` on const fn parameters are unstable
--> src/main.rs:1:32
|
1 | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning[E0515]: cannot return reference to temporary value
--> src/main.rs:1:63
|
1 | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^--
| ||
| |temporary value created here
| returns a reference to data owned by the current function
|
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.
error: aborting due to previous error
I have not managed to replicate the above borrow-check error on code that does not exhibit some other const fn
error.
And the problem goes away if you opt into #![feature(const_fn)]
(play).
So, this is really a very minor diagnostic issue.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.