You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, this is probably a pretty silly feature request, but this tripped me up way more than it should have.
Normally, if you try to implement Default and use ..Default::default(), it'll give you the following warning: recursive call site [unconditional_recursion].
However, if you add any function call, this will no longer happen.
pubstructTest{puba:String,pubb:i32,}implDefaultforTest{fndefault() -> Self{let test = "test".to_string();Self{a: test,
..Default::default()// No compiler warning!}}}
In retrospect, this is exceptionally obvious. But my intuitive thought when I was writing that line was that the remaining fields would be implemented with Default, not that it would refer to the struct itself. Rust Analyzer even suggests using it... not that that's any excuse either, but I lost a lot of time to this particular footgun 😞
Like @mikatpt I also think it seems like a perfectly reasonable thing to try, but obvious why it cant work. Hopefully there is like a ..super_default() or a ..partial_default() in the future :)
Description
Hey, this is probably a pretty silly feature request, but this tripped me up way more than it should have.
Normally, if you try to implement
Default
and use..Default::default()
, it'll give you the following warning:recursive call site [unconditional_recursion]
.However, if you add any function call, this will no longer happen.
In retrospect, this is exceptionally obvious. But my intuitive thought when I was writing that line was that the remaining fields would be implemented with
Default
, not that it would refer to the struct itself. Rust Analyzer even suggests using it... not that that's any excuse either, but I lost a lot of time to this particular footgun 😞Related issue: #103
Version
No response
Additional Labels
No response
The text was updated successfully, but these errors were encountered: