DEFAULT_OVERRIDES_DEFAULT_FIELDS in rustc_lint::default_could_be_derived - Rust
Description: The `default_overrides_default_fields` lint checks for manual `impl` blocks of the `Default` trait of types with default field values.

Skip to main content

## DEFAULT_OVERRIDES_DEFAULT_FIELDS

# Static DEFAULT_OVERRIDES_DEFAULT_FIELDS

Source

    pub static DEFAULT_OVERRIDES_DEFAULT_FIELDS: &Lint

Expand description

The `default_overrides_default_fields` lint checks for manual `impl` blocks of the `Default` trait of types with default field values.

#### §Example

ⓘ

    #![feature(default_field_values)]
    struct Foo {
        x: i32 = 101,
        y: NonDefault,
    }

    struct NonDefault;

    #[deny(default_overrides_default_fields)]
    impl Default for Foo {
        fn default() -> Foo {
            Foo { x: 100, y: NonDefault }
        }
    }

{{produces}}

#### §Explanation

Manually writing a `Default` implementation for a type that has default field values runs the risk of diverging behavior between `Type { .. }` and `<Type as Default>::default()`, which would be a foot-gun for users of that type that would expect these to be equivalent. If `Default` can’t be derived due to some fields not having a `Default` implementation, we encourage the use of `..` for the fields that do have a default field value.