- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-offset_of`#![feature(offset_of)]``#![feature(offset_of)]`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.
Description
I tried this code:
struct Foo {
    a: u32,
}
impl Foo {
    fn bar() -> &'static [usize] {
        &[std::mem::offset_of!(Self, a)]
    }
}I expected to see this happen: no error
Instead, this happened:
error[E0515]: cannot return reference to temporary value
 --> src/lib.rs:7:9
  |
7 |         &[std::mem::offset_of!(Self, a)]
  |         ^-------------------------------
  |         ||
  |         |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
C-bugCategory: This is a bug.Category: This is a bug.F-offset_of`#![feature(offset_of)]``#![feature(offset_of)]`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.