about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2020-04-25 21:06:26 +0200
committerGitHub <noreply@github.com>2020-04-25 21:06:26 +0200
commite1d13c34b0beaea9a5fbf13687672ef85e779d9f (patch)
tree24391aab51b3616204063ade85db12cadb35c475 /src/test/codegen/src-hash-algorithm
parent6ffe725bbcbcbad4caf4b10e546687c13c1d2ac7 (diff)
parentef28361293b39b63f313aa756fce1b9c74f9eb28 (diff)
downloadrust-e1d13c34b0beaea9a5fbf13687672ef85e779d9f.tar.gz
rust-e1d13c34b0beaea9a5fbf13687672ef85e779d9f.zip
Rollup merge of #5408 - dtolnay:matchbool, r=flip1995
Downgrade match_bool to pedantic

I don't quite buy the justification in https://rust-lang.github.io/rust-clippy/. The justification is:

> It makes the code less readable.

In the Rust codebases I've worked in, I have found people were comfortable using `match bool` (selectively) to make code more readable. For example, initializing struct fields is a place where the indentation of `match` can work better than the indentation of `if`:

```rust
let _ = Struct {
    v: {
        ...
    },
    w: match doing_w {
        true => ...,
        false => ...,
    },
    x: Nested {
        c: ...,
        b: ...,
        a: ...,
    },
    y: if doing_y {
        ...
    } else { // :(
        ...
    },
    z: ...,
};
```

Or sometimes people prefer something a bit less pithy than `if` when the meaning of the bool doesn't read off clearly from the condition:

```rust
if set.insert(...) {
    ... // ???
} else {
    ...
}

match set.insert(...) {
    // set.insert returns false if already present
    false => ...,
    true => ...,
}
```

Or `match` can be a better fit when the bool is playing the role more of a value than a branch condition:

```rust
impl ErrorCodes {
    pub fn from(b: bool) -> Self {
        match b {
            true => ErrorCodes::Yes,
            false => ErrorCodes::No,
        }
    }
}
```

And then there's plain old it's-1-line-shorter, which means we get 25% more content on a screen when stacking a sequence of conditions:

```rust
let old_noun = match old_binding.is_import() {
    true => "import",
    false => "definition",
};
let new_participle = match new_binding.is_import() {
    true => "imported",
    false => "defined",
};
```

Bottom line is I think this lint fits the bill better as a pedantic lint; I don't think linting on this by default is justified.

changelog: Remove match_bool from default set of enabled lints
Diffstat (limited to 'src/test/codegen/src-hash-algorithm')
0 files changed, 0 insertions, 0 deletions