rust-clippy/tests
bors e3b8c41d0d Auto merge of #5536 - rail-rain:fix_manual_memcpy, r=phansch
Fix the bugs of `manual_memcpy`, simplify the suggestion and refactor it

While I’m working on the long procrastinated work to expand `manual_memcpy`(#1670), I found a few minor bugs and probably unidiomatic or old coding style. There is a brief explanation of changes to the behaviour this PR will make below. And, I have a questoin: do I need to add tests for the first and second fixed bugs? I thought it might be too rare cases to include the tests for those. I added for the last one though.

* Bug fix
  * It negates resulted offsets (`src/dst_offset`) when `offset` is subtraction by 0. This PR will remove any subtraction by 0 as a part of minification.

    ```rust
    for i in 0..5 {
        dst[i - 0] = src[i];
    }
    ```

    ```diff
     warning: it looks like you're manually copying between slices
       --> src/main.rs:2:14
        |
    LL  |     for i in 0..5 {
    -   |              ^^^^ help: try replacing the loop by: `dst[..-5].clone_from_slice(&src[..5])`
    +   |              ^^^^ help: try replacing the loop by: `dst[..5].clone_from_slice(&src[..5])`
        |
    ```
  * It prints `RangeTo` or `RangeFull` when both of `end` and `offset` are 0, which have different meaning. This PR will print 0. I could reject the cases `end` is 0, but I thought I won’t catch other cases `reverse_range_loop` will trigger, and it’s over to catch every such cases.

    ```rust
    for i in 0..0 {
        dst[i] = src[i];
    }
    ```

    ```diff
     warning: it looks like you're manually copying between slices
       --> src/main.rs:2:14
        |
     LL |     for i in 0..0 {
    -   |              ^^^^ help: try replacing the loop by: `dst.clone_from_slice(&src[..])`
    +   |              ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
        |
    ```
  * it prints four dots when `end` is `None`. This PR will ignore any `for` loops without `end` because a `for` loop that takes `RangeFrom` as its argument and contains indexing without the statements or the expressions that end loops such as `break` will definitely panic, and `manual_memcpy` should ignore the loops with such control flow.

    ```rust
    fn manual_copy(src: &[u32], dst: &mut [u32]) {
        for i in 0.. {
            dst[i] = src[i];
        }
    }
    ```

    ```diff
    -warning: it looks like you're manually copying between slices
    -  --> src/main.rs:2:14
    -   |
    -LL |     for i in 0.. {
    -   |              ^^^ help: try replacing the loop by: `dst[....].clone_from_slice(&src[....])`
    -   |
    ```
* Simplification of the suggestion

  * It prints 0 when `start` or `end` and `offset` are same (from #3323). This PR will use `RangeTo`

changelog: fixed the bugs of `manual_memcpy` and also simplify the suggestion.
2020-05-02 08:11:48 +00:00
..
auxiliary Remove all copyright license headers 2019-01-08 21:46:39 +01:00
cargo Use current_dir instead of cargo_metadata 2020-02-10 16:42:50 +01:00
ui Auto merge of #5536 - rail-rain:fix_manual_memcpy, r=phansch 2020-05-02 08:11:48 +00:00
ui-toml Add test for zero single char names 2020-04-15 13:35:44 +02:00
compile-test.rs Fix error E0460 when compiled on Rustc repo 2020-02-09 19:02:27 +07:00
dogfood.rs Fix error E0460 when compiled on Rustc repo 2020-02-09 19:02:27 +07:00
fmt.rs Apply review comments 2020-02-12 09:34:28 +01:00
integration.rs Explain panic on E0463 in integration tests 2020-04-13 22:12:57 +02:00
missing-test-files.rs cargo fmt 2019-06-21 16:47:34 +02:00
versioncheck.rs test(versioncheck): Use .no_deps() 2019-01-25 21:53:44 +01:00