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

new lint: variable scope that can be reduced #3429

Open
matthiaskrgr opened this issue Nov 15, 2018 · 1 comment
Open

new lint: variable scope that can be reduced #3429

matthiaskrgr opened this issue Nov 15, 2018 · 1 comment

Comments

@matthiaskrgr
Copy link
Member

inspired by cppcheck

It could warn about code like this:

fn do_something(is_true: bool, word: String) -> String {
    let mut s = String::from("hello world");
    if is_true {
        s.push_str(&word);
        s
    } else {
        word
    }
}

where the scope of s can be savely reduced to span across the true branch of the if:

fn do_something(is_true: bool, word: String) -> String {
    if is_true {
      let mut s = String::from("hello world");  
      s.push_str(&word);
      s
    } else {
        word
    }
} 
@killercup
Copy link
Member

Either assumes or needs to assert that construction or destruction of s doesn't have side effects.

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