Skip to content

"a temporary value which is freed while still in use" in nightly but not on stable #105891

Open
@poliorcetics

Description

@poliorcetics

Code

I tried this code:

// Do: cargo add obfstr

fn main() {
    let product = "macos";
    let is_not = |s| !product.eq_ignore_ascii_case(s);

    let _res = is_not(obfstr::obfstr!("windows")) && is_not(obfstr::obfstr!("macos"));
}

I expected to see this happen: the code compiles without problems on stable and nightly

Instead, this happened: compilation failed but only on nightly

RUSTFLAGS="-Z macro-backtrace" cg +nightly build -q

error[E0716]: temporary value dropped while borrowed
   --> /Users/alexis/.local/share/cargo/registry/src/mygithub.libinneed.workers.dev-1ecc6299db9ec823/obfstr-0.4.1/src/bytes.rs:93:16
    |
54  |   macro_rules! obfstr {
    |   ------------------- in this expansion of `obfstr::obfstr!` (#1)
...
66  |           $crate::unsafe_as_str($crate::obfbytes!($s.as_bytes()))
    |                                 -------------------------------- in this macro invocation (#2)
...
72  |   macro_rules! obfbytes {
    |   --------------------- in this expansion of `$crate::obfbytes!` (#2)
...
86  |           &$crate::__obfbytes!($s)
    |            ----------------------- in this macro invocation (#3)
...
92  |   macro_rules! __obfbytes {
    |   ----------------------- in this expansion of `$crate::__obfbytes!` (#3)
93  |       ($s:expr) => {{
    |  ___________________^
94  | |         const _OBFBYTES_STRING: &[u8] = $s;
95  | |         const _OBFBYTES_LEN: usize = _OBFBYTES_STRING.len();
96  | |         const _OBFBYTES_KEYSTREAM: [u8; _OBFBYTES_LEN] = $crate::bytes::keystream::<_OBFBYTES_LEN>($crate::__entropy!("key", stringify!($...
...   |
103 | |             &_OBFBYTES_KEYSTREAM)
104 | |     }};
    | |_____^ creates a temporary value which is freed while still in use
    |
   ::: src/main.rs:5:49
    |
5   |       let _res = is_not(obfstr::obfstr!("windows")) && is_not(obfstr::obfstr!("macos"));
    |                         ---------------------------    ------ borrow later used here
    |                         |                         |
    |                         |                         temporary value is freed at the end of this statement
    |                         in this macro invocation (#1)
    |
    = note: consider using a `let` binding to create a longer lived value

For more information about this error, try `rustc --explain E0716`.
error: could not compile `pg2` due to previous error

Version it worked on

It most recently worked on: Rust 1.66

Version with regression

rustc --version --verbose:

rustc 1.68.0-nightly (d0dc9efff 2022-12-18)
binary: rustc
commit-hash: d0dc9efff14ac0a1eeceffd1e605e37eeb8362a0
commit-date: 2022-12-18
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6

Backtrace

Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions