Commit graph

2685 commits

Author SHA1 Message Date
Geoffrey Copin
71ac0c0be8 Keep separators in cast_size_32bits stderr 2020-10-24 14:08:53 +02:00
Geoffrey Copin
d46edd9966 Keep sign in int-to-float casts 2020-10-24 00:04:37 +02:00
Geoffrey Copin
30f80c3b8c Fix test file 2020-10-23 00:33:15 +02:00
Geoffrey Copin
02f01104bf Add test case for negative literals 2020-10-23 00:04:27 +02:00
Geoffrey Copin
e8f12d2f02 Address review comments 2020-10-22 23:56:49 +02:00
Geoffrey Copin
bb0ce32423 Lint unnecessary int-to-int and float-to-float casts 2020-10-17 16:12:51 +02:00
bors
18ffea01ee Auto merge of #6158 - giraffate:improve_updating_references, r=phansch
Remove the generated files by `update-references.sh` if they are empty

An empty file may be generated by `update-references.sh` and committed as is when creating a patch like https://github.com/rust-lang/rust-clippy/pull/6101#issuecomment-702076508 and https://github.com/rust-lang/rust-clippy/pull/6079#pullrequestreview-496502721. So, I think it would be helpful to add documentation, and automatically remove the generated file if it's empty.

changelog: none
2020-10-12 13:49:19 +00:00
Eduardo Broto
74ae116131 Use lowercase in error messages 2020-10-11 22:28:55 +02:00
Andre Bogus
6021c23159 New lint: result-unit-err 2020-10-11 22:04:59 +02:00
Takayuki Nakata
377d1fab1f Remove the generated files by update-references.sh if they are empty 2020-10-11 22:57:22 +09:00
flip1995
52e650ae88
Add test for ICE #6153 2020-10-10 15:12:20 +02:00
bors
dbc02854fc 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
2020-10-10 06:32:32 +00:00
bors
2bdadd8e7d Auto merge of #6151 - bofh69:master, r=ebroto
Preserve raw strs for: format!(s) to s.to_string() lint

fixes #6142

clippy::useless_format will keep the source's string (after converting {{ and }} to { and }) when suggesting a change from format!() to .to_string() usage. Ie:
|     let s = format!(r#""hello {{}}""#);
|             ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `r#""hello {}""#.to_string()`

changelog: [`useless_format`]: preserve raw string literals when no arguments to `format!()` are provided.
2020-10-09 23:14:58 +00:00
bors
0b86340999 Auto merge of #6144 - rust-lang:float-cmp-ref, r=ebroto
allow refs in our constant folder

This helps with #3804 (but won't completely fix it).

---

changelog: none
2020-10-09 22:28:00 +00:00
bors
08bd3f0b0d Auto merge of #6152 - flip1995:ice_6139, r=ebroto
Fixes ICE 6139

Fixes #6139

Kind of hacky, but this should be fine.

changelog: none
2020-10-09 20:39:26 +00:00
flip1995
6d88803a1c
Add regression test for ICE 6139 2020-10-09 22:21:47 +02:00
Andre Bogus
26e4de9557 allow refs in our constant handling 2020-10-09 21:37:50 +02:00
Sebastian Andersson
7b7ddfa55d Preserve raw strs for: format!(s) to s.to_string() lint
Ie:
|     let s = format!(r#""hello""#);
|             ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `r#""hello""#.to_string()`
2020-10-09 20:23:03 +02:00
bors
947516f018 Auto merge of #6130 - Ambroisie:lint-ptr-eq, r=Manishearth
New lint: Recommend using `ptr::eq` when possible

This is based almost entirely on the code available in the previous PR #4596. I merely updated the code to make it compile.

Fixes #3661.

- [ ] I'm not sure about the lint name, but it was the one used in the original PR.
- [X] Added passing UI tests (including committed `.stderr` file)
- [X] `cargo test` passes locally
- [X] Executed `cargo dev update_lints`
- [X] Added lint documentation
- [X] Run `cargo dev fmt`

---

changelog: none
2020-10-09 16:46:09 +00:00
bors
e651a04fab Auto merge of #6133 - JPTIZ:no-box-for-c-ffi, r=ebroto
clippy_lints: Do not warn against Box parameter in C FFI

changelog: [`boxed_local`]: don't lint in `extern fn` arguments

Fixes #5542.

When using C FFI, to handle pointers in parameters it is needed to
declare them as `Box` in its Rust-side signature. However, the current
linter warns against the usage of Box stating that "local variable
doesn't need to be boxed here".

This commit fixes it by ignoring functions whose Abi is C.
2020-10-08 22:50:29 +00:00
João Paulo Taylor Ienczak Zanette
b709b87363 tests: Add test function that does not specify ABI 2020-10-08 18:50:52 -03:00
João Paulo Taylor Ienczak Zanette
5ae0f2644d clippy_lint: extern definition is in Rust, not C 2020-10-08 09:07:24 -03:00
João Paulo Taylor Ienczak Zanette
418cde0389 clippy_lint: Fix typo (now -> not) 2020-10-08 09:06:19 -03:00
João Paulo Taylor Ienczak Zanette
15150c07ea clippy_lint: Test for BoxedLocal false-positive in C-FFI and fix C-FFI Abi comparison. 2020-10-07 22:49:50 -03:00
Andre Bogus
11672577de Fix unicode regexen with bytes::Regex
fixes #6005
2020-10-08 01:07:00 +02:00
Bruno BELANYI
5bad9175fb New lint: Recommend using ptr::eq when possible
This is based almost entirely on the code available in the previous PR #4596.
2020-10-07 11:48:06 +02:00
Eduardo Broto
6c3611bdef Reinstate test for forbid blanket restriction 2020-10-07 00:02:28 +02:00
bors
1a4175bcec Auto merge of #6126 - flip1995:rustup, r=flip1995
Rustup

Supersedes #6121. There was another breakage.

r? `@ghost`

changelog: none
2020-10-06 21:34:50 +00:00
bors
c9fdeef643 Auto merge of #6078 - ebroto:unnecessary_sort_by_take_2, r=phansch
unnecessary sort by: avoid dereferencing the suggested closure parameter

This change tries to simplify the solution for problematic cases but is less restrictive than  #6006.

* We can't dereference shared references to non-Copy types, so the new suggestion does not do that. Note that this implies that the suggested closure parameter will be a reference.
* We can't take a reference to the closure parameter in the returned key, so we don't lint in those cases. This can happen either because the key borrows from the parameter (e.g. `|a| a.borrows()`), or because we suggest `|a| Reverse(a)`. If we did we would hit this error:
```
error: lifetime may not live long enough
  --> /home/ebroto/src/ebroto-clippy/tests/ui/unnecessary_sort_by.fixed:19:25
   |
19 |     vec.sort_by_key(|b| Reverse(b));
   |                      -- ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
   |                      ||
   |                      |return type of closure is Reverse<&'2 isize>
   |                      has type `&'1 isize`

error: aborting due to previous error
```

Note that Clippy does not currently have the (MIR-based) machinery necessary to check that what is borrowed is actually the closure parameter.

changelog: [`unnecessary_sort_by`]: avoid dereferencing the suggested closure parameter

Fixes #6001
2020-10-06 06:59:33 +00:00
FliegendeWurst
428ef362d6 Fix test formatting 2020-10-05 12:23:01 +02:00
FliegendeWurst
78695bd496
Do not lint float fractions in mistyped_literal_suffixes (fixes #4706) 2020-10-05 12:09:21 +02:00
Felix S. Klock II
5747c15961 Prevent forbid from being ignored if overriden at the same level.
That is, this changes `#[forbid(foo)] #[allow(foo)]` from allowing foo to
forbidding foo.
2020-10-04 13:14:01 -04:00
bors
2ed5143c0e Auto merge of #6111 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: Deprecate [`drop_bounds`] lint. This lint was uplifted to rustc with the same name.
2020-10-04 12:04:31 +00:00
Dániel Buga
572e4c4837 Add WJ 2020-10-03 00:07:56 +02:00
Dániel Buga
998bd3b6b4 Rename lint to invisible_characters 2020-10-03 00:03:33 +02:00
Michael Howell
840f7daaad Deprecate clippy lint 2020-10-02 11:34:14 -07:00
rail
7820cb1442 Add tests for
* `dst.len()` as the end of the range with loop counters
* the increment of the loop counter at the top of the loop
2020-10-02 23:21:24 +13:00
Dániel Buga
515ca93123 Look for soft hyphens as well 2020-10-02 11:56:21 +02:00
rail
1402d8ae4f fix a FN where incr exprs with no semicolon at ends 2020-10-02 21:18:37 +13:00
Michael Wright
e91202cf68 Allow exponent separator
Fixes #6096
2020-10-02 07:02:58 +02:00
bors
8c9800a3a9 Auto merge of #6102 - giraffate:no_lint_when_invalid_suggestion_in_needless_range_loop, r=flip1995
Don't emit a lint for the suggestion leading to errors in `needless_range_loop`

Fix #5945

changelog: Don't emit a lint for the suggestion leading to errors in `needless_range_loop`
2020-10-01 16:29:08 +00:00
Takayuki Nakata
0a91fe7016 Don't emit a lint for the suggestion leading to errors in needless_range_loop 2020-10-02 00:49:05 +09:00
bors
d4313737d8 Auto merge of #5978 - montrivo:needless-lifetime, r=ebroto
needless-lifetime - nested elision sites

Closes #2944

changelog: fix needless-lifetime nested elision site FPs
2020-10-01 13:43:24 +00:00
bors
abce9e7c9f Auto merge of #6092 - jethrogb:jb/inline-asm-syntax-lint, r=ebroto
Add lint for inline assembly syntax style preference

changelog: Add lint for inline assembly syntax style preference
2020-09-30 21:44:29 +00:00
Eduardo Broto
507561ecfc
Update tests/ui/asm_syntax.rs
Use a single `only` header command in asm_syntax test
2020-09-30 23:30:49 +02:00
Jethro Beekman
0690f9c5d5 Add lint for inline assembly syntax style preference 2020-09-30 09:43:46 +02:00
Tim Nielens
cb2be6f9db needless-lifetime / pr remarks 2020-09-30 00:33:46 +02:00
Tim Nielens
124420f920 needless-lifetime / fix master merge 2020-09-29 23:06:08 +02:00
Tim Nielens
7cfe3dc2eb Merge branch 'master' into needless-lifetime 2020-09-29 22:51:59 +02:00
Eduardo Broto
101e76f117 needless arbitrary self: handle macros 2020-09-28 19:17:22 +02:00