Rust

Rust

Made by DeepSource

Audit required: Function call in default() that returns Self RS-A1008

Bug risk
Major

The default() function in the Default trait is used to create a default instance of the type. While implementing this, if a function call returns the same type, it could possibly create an infinite loop by calling default() itself.

Consider revisiting this implementation.

Bad practice

struct A(i32);

impl A {
    fn new() -> Self {
        Self::default()
    }
}

impl Default for A {
    fn default() -> Self {
        // This call will create an infinite loop
        Self::new()
    }
}