0

I haven't quite understood how unsafe assignments works. The following code gives me some error:

fn num() -> u64 {
    1;
}

fn test() -> u64 {
    let x = unsafe {
        num();
    };
    return x;
}

The error is:

src/main.rs:37:9: 37:10 note: expected type `u64`
src/main.rs:37:9: 37:10 note:    found type `()`

My real example is similar to this one. Strange that I have the exact same code, though I cannot compile.

malbarbo
  • 10,717
  • 1
  • 42
  • 57
einstein
  • 13,389
  • 27
  • 80
  • 110

1 Answers1

2

Semicolons.

fn num() -> u64 {
    1
}

fn test() -> u64 {
    let x = unsafe {
        num()
    };
    return x;
}

See also this answer about semicolons.

Community
  • 1
  • 1
DK.
  • 55,277
  • 5
  • 189
  • 162