Closed
Description
Code
fn main() {
#[derive(Debug)]
struct Number(f32);
impl From<f32> for Number {
fn from(value: f32) -> Self {
value.into()
}
}
let value: Number = (10.0).into();
println!("{value:?}");
}
Current output
Compiling number v0.1.0 (/home/number)
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
Running `target/debug/number`
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1] 25988 IOT instruction (core dumped) cargo run
Desired output
The compiler should detect that we are calling Into for f32 trait which is automatically implemented by From for Number trait in our implementation of the From for Number trait.
Rationale and extra context
No response
Other cases
No response
Anything else?
No response
Activity
riking commentedon Jul 12, 2023
Implementation would be a deny-by-default lint. Not sure whether to recommend Clippy first or straight into rustc.
Noratrieb commentedon Jul 13, 2023
I agree that this should live in clippy instead of rustc, @matthiaskrgr do you want to move the issue :)?
y21 commentedon Sep 6, 2023
I think a more general version of this is #11032. The blanket
Into
impl just hasU::from(self)
in its implementation, so this is basically the same idea:from
->into
->from
-> ...Into
impl from aFrom
impl #12459Auto merge of #12459 - y21:unconditional_recursion_from_into, r=Jarcho