Navigation Menu

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

No warning on duplicate function outside trait implementation #81120

Closed
arnabanimesh opened this issue Jan 17, 2021 · 1 comment
Closed

No warning on duplicate function outside trait implementation #81120

arnabanimesh opened this issue Jan 17, 2021 · 1 comment

Comments

@arnabanimesh
Copy link

struct Person {
    name: String,
    age: u8,
}

trait HasVoiceBox {
    fn speak(&self);
    fn can_speak(&self) -> bool;
}

impl HasVoiceBox for Person {
    fn speak(&self) {
        println!("Hello, my name is {}.", self.name);
    }
    // This does not run
    fn can_speak(&self) -> bool {
        !matches!(self.age, 0..=2)
    }
}

impl Person {
    // This runs
    fn can_speak(&self) -> bool {
        matches!(self.age, 0..=2)
    }
}

fn main() {
    let person = Person {
        name: String::from("Bob"),
        age: 3,
    };
    /* Returns false, there should be an error or warning of some sort
    on the functions that won't run and unused traits*/
    println!("Can {} speak? {}", person.name, person.can_speak());
}
@jonas-schievink
Copy link
Contributor

New lints generally have to go through the RFC process, so closing in favor of that (or alternatively discussion on https://internals.rust-lang.org/).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants