What it does
Detects cases where a parameterless new simply calls Default::default, and indicates that default should call new, rather than the opposite.
Advantage
new functions can potentially be const, while default cannot, and calling them in the opposite order can prohibit this.
Drawbacks
The lint is completely irrelevant if the new function is never intended to be const.
Example
pub struct Config;
impl Default for Config {
fn default() -> Self { Self }
}
impl Config {
pub fn new() -> Self {
Self::default()
}
}
Could be written as:
pub struct Config;
impl Default for Config {
fn default() -> Self { Self::new() }
}
impl Config {
pub fn new() -> Self {
Self
}
}
What it does
Detects cases where a parameterless
newsimply callsDefault::default, and indicates thatdefaultshould call new, rather than the opposite.Advantage
newfunctions can potentially beconst, whiledefaultcannot, and calling them in the opposite order can prohibit this.Drawbacks
The lint is completely irrelevant if the
newfunction is never intended to beconst.Example
Could be written as: