-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
Originally noticed in #124478 (comment), @GKFX identified it as a problem in must_use
in #124478 (comment)
I tried this code:
#![feature(hint_must_use)]
fn foo() -> &'static [usize] {
&[core::hint::must_use(42)]
}
I expected to see this happen: no error, the value is a constant
Instead, this happened:
error[E0515]: cannot return reference to temporary value
--> src/lib.rs:4:5
|
4 | &[core::hint::must_use(42)]
| ^--------------------------
| ||
| |temporary value created here
| returns a reference to data owned by the current function
For more information about this error, try `rustc --explain E0515`.
error: could not compile `playground` (lib) due to 1 previous error
Meta
rustc 1.79 nightly 2024-04-27
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.