Skip to content

Lint against declaring fn to_string(&self) -> String #4247

Closed
@kennytm

Description

@kennytm

Emit a lint when a type defines an inherent to_string() method. One should implement Display instead.

impl S {
    fn to_string(&self) -> String {  ...  }
//  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}

If a type both implements Display and defines an inherent to_string() method, turn up the warn level to error, since the inherent to_string() will shadow the Display impl and they may behave differently.

Do not emit the lint if to_string() is a trait method or free function.

Do not emit the lint if the method is not exactly fn(&self) -> String, or maybe still emit a lint but suggest renaming the method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint groupL-styleLint: Belongs in the style lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions