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
  • 9,909
  • 1
  • 35
  • 53
einstein
  • 12,479
  • 27
  • 79
  • 104

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.
  • 49,288
  • 3
  • 161
  • 146