LINUX.ORG.RU

История изменений

Исправление unDEFER, (текущая версия) :

//все норм

А.. поспешил, не доглядел пример.. Сейчас подумаю.

Исходная версия unDEFER, :

//все норм

Врёте вы всё:

$ cat src/lib.rs 
fn bad(b: &i32) -> &i32
{
    &b
}

fn very_bad(_a: &i32) -> &i32 {
    let b = 1i32;
    bad(&b)
}
$ cargo build
   Compiling test1 v0.1.0 (/home/undefer/MyFiles/Projects/TEST/Rust/test1)
error[E0515]: cannot return value referencing local variable `b`
 --> src/lib.rs:8:5
  |
8 |     bad(&b)
  |     ^^^^--^
  |     |   |
  |     |   `b` is borrowed here
  |     returns a value referencing data owned by the current function

For more information about this error, try `rustc --explain E0515`.
error: could not compile `test1` due to previous error
$ rustc --version
rustc 1.65.0 (gentoo)