about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-10 06:32:32 +0000
committerbors <bors@rust-lang.org>2020-10-10 06:32:32 +0000
commitdbc02854fce1f783599e3f98b6ee6b9a136d9e96 (patch)
tree79cea5dd04adaef96de5fdba80c4c4f0b93850a4 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent2bdadd8e7dc54651df06e0adff1c1b1e7dcf6480 (diff)
parentb54188429409a6da5f931fa4be5df1f40b377015 (diff)
downloadrust-dbc02854fce1f783599e3f98b6ee6b9a136d9e96.tar.gz
rust-dbc02854fce1f783599e3f98b6ee6b9a136d9e96.zip
Auto merge of #5727 - rail-rain:manual_memcpy_with_counter, r=flip1995
Expands `manual_memcpy` to lint ones with loop counters

Closes #1670

This PR expands `manual_memcpy` to lint ones with loop counters as described in https://github.com/rust-lang/rust-clippy/issues/1670#issuecomment-293280204

Although the current code is working, I have a couple of questions and concerns.

~~Firstly, I manually implemented `Clone` for `Sugg` because `AssocOp` lacks `Clone`. As `AssocOp` only holds an enum, which is `Copy`, as a value, it seems `AssocOp` can be `Clone`; but, I was not sure where to ask it. Should I make a PR to `rustc`?~~ The [PR]( https://github.com/rust-lang/rust/pull/73629) was made.

Secondly, manual copying with loop counters are likely to trigger `needless_range_loop` and `explicit_counter_loop` along with `manual_memcpy`; in fact, I explicitly allowed them in the tests. Is there any way to disable these two lints when a code triggers `manual_memcpy`?

And, another thing I'd like to note is that `Sugg` adds unnecessary parentheses when expressions with parentheses passed to its `hir` function, as seen here:

```
error: it looks like you're manually copying between slices
  --> $DIR/manual_memcpy.rs:145:14
   |
LL |     for i in 3..(3 + src.len()) {
   |              ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)])
```

However, using the `hir` function is needed to prevent the suggestion causing  errors when users use bitwise operations; and also this have already existed, for example: `verbose_bit_mask`. Thus, I think this is fine.

changelog: Expands `manual_memcpy` to lint ones with loop counters
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions