The following code triggers the lint:
#![no_std]
trait Abs {
fn abs(self) -> Self;
}
impl Abs for f64 {
fn abs(self) -> f64 {
core::primitive::f64::abs(self)
}
}
The warning is
warning: function cannot return without recursing
--> src/lib.rs:8:5
|
8 | fn abs(self) -> f64 {
| ^^^^^^^^^^^^^^^^^^^ cannot return without recursing
9 | core::primitive::f64::abs(self)
| ------------------------------- recursive call site
|
= note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
This recurses on no_std
because f64
does not have a dedicated .abs()
method.
How can I unambiguously refer to the dedicated method, such that the above implementation will fail to compile on no_std
?