Why doesn't Rust give a "unconditional recursion" warning for using x.into()
method when it gives warning for Self::from(x)
?
Consider below example, in rust playground:
struct Foo;
struct Bar;
impl From<Foo> for Bar {
fn from(x: Foo) -> Self {
x.into() // No recursion warning
}
}
fn main() {}
Consider another example that shows recursive warning in rust playground
struct Foo;
struct Bar;
impl From<Foo> for Bar {
fn from(x: Foo) -> Self {
Self::from(x) // Shows recursion warning
}
}
fn main() {}
warning: function cannot return without recursing
--> src/main.rs:5:5
|
5 | fn from(x: Foo) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
6 | Self::from(x)
| ------------- recursive call site
|
= note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose