Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:1:12
|
1 | fn main()->! {
| ---- ^ expected `!`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected type `!`
found unit type `()`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
Don’t believe all code you see in a YouTube video is correct and/or tested.[1]
One doesn’t even need to scroll down through all that many other comments (some of which are also pointing out other code examples that don’t actually compile, or explanations that aren’t completely accurate) to find someone already pointing out this exact mistake…
Put simply, the type signature fn main()->! means that “the main function will never terminate”. Either because of an infinite loop, or because of a panic, or because a different non-terminating function is called. The ->! means that the main function will (be required to) unconditionally/definitely do any of these things, instead of terminating/returning.
On the other hand, the body of the main function here does (well… at least can) terminate/return. So the way to fix it is
either change the implementation, e.g. by inserting some infinite loop or panic at the end
or perhaps fn main()->! isn’t what you wanted in the first place, so fix the signature and remove that “->!”!