Conversation
|
This change seems logical, and I like it, but I'm not very happy about adding one more Also I found one more error message that is not very helpful: fn main() -> ! {
while true {
}
} |
Me neither. I wish the diagnostics for forgetting the feature gate were better. We can always wait until the feature gets stabilized.
That seems unrelated to the termination trait. You get the same error with any other function: fn foo() -> ! {
while true {}
//^ error: expected !, found ()
}I think the compiler doesn't check the |
|
@japaric sorry, I didn't mean to say that When you write this code: fn main() {
while true {
}
}You get a nice warning that suggests using But when you have a diverging function, you don't see such message. |
|
Oh, OK. That sounds like it might be worth to report in rust-lang/rust? |
|
This has been done. The |
Now that the
Terminationtrait has been implemented (cf. rust-lang/rust#46479) we can narrow downthe return type of
mainto be one of the types that implements theTerminationtrait.This RFC proposes only implementing
Terminationfor the never type (!) -- currentlyTerminationis only implemented for the unit type (()). With this change all programs that linkto
cortex-m-rtare forced to set the signature ofmainto befn() -> !. The rationale here isthat a divergent (never ending) function better matches the logic of microcontroller programs.
When the change is implemented the user will be forced to make
maininto a divergent function.This won't work:
Whereas this would works:
Drawbacks
Diagnostics for the
Terminationfeature are rather bad at the moment. If this change isimplemented and you write a program where
main: fn()but forget to add the#![feature(termination_trait)]feature gate you get an unhelpful linker error:cc @pftbest