Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint tuple structs that could be named-field structs #1926

Open
clarfonthey opened this issue Aug 5, 2017 · 1 comment
Open

Lint tuple structs that could be named-field structs #1926

clarfonthey opened this issue Aug 5, 2017 · 1 comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types

Comments

@clarfonthey
Copy link
Contributor

As pointed out in rust-lang/rust#42998 it's an anti-pattern in Rust to create a tuple struct and then used named accessors, as in:

/// Type for Unicode Version.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct UnicodeVersion(
    pub u16, // Major version
    pub u16, // Minor version
    pub u16 // Micro (or Update) version
);

impl UnicodeVersion {
    /// Major version
    pub fn major(&self) -> u16 {
        self.0
    }

    /// Minor version
    pub fn minor(&self) -> u16 {
        self.1
    }

    /// Micro (or Update) version
    pub fn micro(&self) -> u16 {
        self.2
    }
}

We should lint cases like this and suggest replacing the tuple struct with a named-field struct, and adding a new method instead.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 5, 2017

This could be part of the getter/setter lint

@oli-obk oli-obk added L-style Lint: Belongs in the style lint group E-medium Call for participation: Medium difficulty level problem and requires some initial experience. A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

2 participants