Skip to content

New lint: trait_not_impl #11570

Closed
Closed
@PyroTechniac

Description

@PyroTechniac

What it does

Lints for warnings where traits are only imported for their methods, not to be implemented on a type

Suggestion: rename traits to _.

Advantage

Remove potential name conflicts when importing multiple traits, such as io::Write and fmt::Write

Drawbacks

Would need to be named if multiple traits have the same named methods and one needs selected

Example

use std::fmt::{Display, Formatter, Result, Write};

struct Foo(char);

impl Display for Foo {
	fn fmt(&self, f: &mut Formatter<'_>) -> Result {
		f.write_char(self.0)
	}
}

Could be written as:

use std::fmt::{Display, Formatter, Result, Write as _};

struct Foo(char);

impl Display for Foo {
	fn fmt(&self, f: &mut Formatter<'_>) -> Result {
		f.write_char(self.0)
	}
}

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