-
Couldn't load subscription status.
- Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lints
Description
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
}
}Skglandnyurik
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints