Skip to content

unimplemented_default_member #12727

@mladedav

Description

@mladedav

What it does

Forces useers to implement all methods in a trait, including all methods with default implementations.

This would be allow-by-default restriction lint. This makes sense to turn on only in specific scenarios.

Advantage

  • Users will not be surprised by an addition of new default members in traits if they wish to always implement all of them.

Drawbacks

  • There is no way to turn it on or off on a method-by-method basis so the user would sometimes be forced to copy the default implementation if that's the implementation they want to use. They would lose on any potential updates to its implementation.

Example

trait Record {
  fn record_debug(field: &dyn Debug);

  fn record_u64(field: u64) {
    record_debug(field);
  }

  fn record_i64(field: i64) {
    record_debug(field);
  }
}
trait HasRecord {
    type MyRecord: Record;
    fn my_record() -> Self::MyRecord;
}

impl Record for T where T: HasRecord {
  fn record_debug(field: &dyn Debug) {
     Self::my_record().record_debug();
  }

  fn record_u64(field: u64) {
     Self::my_record().record_u64()
  }

  fn record_i64(field: i64) {
     Self::my_record().record_i64()
  }
}

Now if the Record trait is extended with a new method with default implementation such as record_str(str: &str) the default implementation would be bad for implementations leveraging the HasRecord type. As I user, I'd like a way to tell clippy that I want to be notified, if any method is not explicitly defined in a given impl block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions