Im losing it please help

Heres the code :

    fn enable_raw_mode() -> R<()> {
    let mut o_ts_guard = O_TS.lock()?;
    let o_ts = &mut *o_ts_guard;

    let ret = unsafe { ioctl(0, TCGETS, o_ts) };
    if ret == -1 {
        return Err("syscall failed".into());
    }
// stuck now..
    Ok(())
}

i get the following error message:

 cannot return value referencing temporary value
   returns a value referencing data owned by the current function [E0515]

i have been banging my head cause i really do not know the issue please help me thank you

Hi. Many people here will be glad to help you, but we can't do much with the information you provided us. Please try providing a minimal reproducible example (sharing it on Rust playground would be best). Without knowing what the types are - what is R<()> for example? - it is impossible to determine what is the root cause of your problem. Also error message should point faulty expression (and provide a hint to where this temporary is created), but you removed it. Reading your example now I don't see any return paths, that return borrowed data.

2 Likes

ok the solution is so dumb that its pretty Embarrassing.the problem was i called the global var as const ... instead of static..
and also fyi
R<()> is

type R<T> = Result<T, Box<dyn Error>>;
1 Like