Commit Graph

4711 Commits

Author SHA1 Message Date
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
bors
7118d37bf8 Auto merge of #6154 - flip1995:ice_fixes, r=ebroto
Fix two ICEs caused by ty.is_{sized,freeze}

Fixes #6153
Properly fixes #6139

The test case in #6153 is kind of weird. Even removing one of the arguments of the `foo` function prevented the ICE. I think this test case is actually minimal.

changelog: none
2020-10-10 13:29:05 +00:00
flip1995
cf81975d77
Fix two ICEs caused by ty.is_{sized,freeze} 2020-10-10 14:04:14 +02:00
bors
8b70b84639 Auto merge of #6107 - nahuakang:ref_style_link_false_positive, r=flip1995
Ref style link false positive

This PR does not fix #5834, but it records the problematic link text as a **known problem** inside `doc_markdown` lint.

r? `@flip1995`

- [ ] Followed [lint naming conventions][lint_naming]
- [ ] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [ ] Added lint documentation
- [x] Run `cargo dev fmt`

---

*Please keep the line below*
changelog: Document problematic link text style as known problem for `doc_markdown`
2020-10-10 09:25:46 +00: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
a98f9d21fc
(Hacky) Fix for ICE #6139 2020-10-09 22:22:21 +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
Jean SIMARD
732d370404
clippy_lint: Fix doc on 'option_if_let_else'
- a typo in `expresion`
- a useless double space
- Some back-tick quotes for 'if let'
2020-10-09 09:47:53 +02: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
bors
265e4841b7 Auto merge of #6117 - dtolnay:string_lit_as_bytes, r=ebroto
Downgrade string_lit_as_bytes to nursery

Between #1402 (regarding `to_owned`) and #4494 (regarding `impl Read`), as well as other confusion I've seen hit in my work codebase involving string_lit_as_bytes (`"...".as_bytes().into()`), I don't think this lint is at a quality to be enabled by default.

I would consider re-enabling this lint after it is updated to understand when the surrounding type information is sufficient to unsize `b"..."` to &\[u8\] without causing a type error.

As currently implemented, this lint is pushing people to write `&b"_"[..]` which is not an improvement over `"_".as_bytes()` as far as I am concerned.

---

changelog: Remove string_lit_as_bytes from default set of enabled lints
2020-10-08 21:33:32 +00:00
João Paulo Taylor Ienczak Zanette
cc26924cce clippy_lint: Extend BoxedLocal ignored ABI to all non-rust ABIs. 2020-10-08 09:03:11 -03:00
David Tolnay
c81bea45f4
Make clippy_lints's doc tests succeed 2020-10-08 04:54:17 -07:00
David Tolnay
3a6f59ecae
Document string_lit_as_bytes known problems 2020-10-08 04:50:24 -07:00
bors
171ab9bf9f Auto merge of #6132 - rust-lang:regex-unicode, r=ebroto
Fix unicode regexen with bytes::Regex

fixes #6005

The rationale for this is that since we wrote that lint, `bytes::Regex` was extended to be able to use unicode character classes.

---

changelog: [`invalid_regex`]: allow unicode character classes in bytes regex.
2020-10-08 08:48:12 +00: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
João Paulo Taylor Ienczak Zanette
738ed38306 clippy_lints: Do not warn against Box parameter in C FFI
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 Cdecl.
2020-10-07 21:41:54 -03:00
bors
13a80b34ba Auto merge of #6128 - dtolnay:rc_buffer, r=yaahc
Downgrade rc_buffer to restriction

I think Arc\<Vec\<T\>\> and Arc\<String\> and similar are a totally reasonable data structure, as observed by others in the comments on [#6044](https://github.com/rust-lang/rust-clippy/pull/6044#event-3799579830) as well. Doing `Arc::make_mut(&mut self.vec).push(...)` or `Arc::make_mut(&mut self.string).push_str("...")` is a terrific and well performing copy-on-write pattern. Linting this with an enabled-by-default <kbd>performance</kbd> lint strikes me as an unacceptable false positive balance.

As of #6090 the documentation of this lint now contains:

> **Known problems:** This pattern can be desirable ...

which should indicate that we shouldn't be linting against correct, reasonable, well-performing patterns with an enabled-by-default lint.

Mentioning #6044, #6090.
r? `@yaahc,` who reviewed the lint.

---

changelog: Remove rc_buffer from default set of enabled lints
2020-10-07 23:10:34 +00:00
Andre Bogus
11672577de Fix unicode regexen with bytes::Regex
fixes #6005
2020-10-08 01:07:00 +02:00
Bruno BELANYI
6edde811b5
fixup! New lint: Recommend using ptr::eq when possible
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2020-10-07 17:11:11 +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
bors
277191890b Auto merge of #6120 - phansch:replace-lazy-static, r=Manishearth
Replace some lazy_static usage with once_cell feature

This replaces some `lazy_static` usage with [`SyncLazy`](https://doc.rust-lang.org/nightly/std/lazy/struct.SyncLazy.html) of the unstable `once_cell` feature.

changelog: none
2020-10-07 04:58:13 +00:00
David Tolnay
0e159a55d6
Downgrade rc_buffer to restriction 2020-10-06 19:46:03 -07:00
David Tolnay
a5ef305cb5
Downgrade string_lit_as_bytes to nursery 2020-10-06 19:41:22 -07:00
bors
14e72696a6 Auto merge of #6124 - pickfire:patch-1, r=flip1995
Use more concrete explanation for methods

*Please keep the line below*
changelog: none
2020-10-06 23:22:28 +00: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
flip1995
b05aeaa9bc
Run fmt 2020-10-06 23:32:38 +02:00
Ivan Tham
7021d70d2e
Use more concrete explanation for methods
Show some code rather than "a single method call".
2020-10-06 23:58:32 +08:00
Philipp Hansch
da57a16872
clippy_lints: Replace lazy_static with SyncLazy 2020-10-06 14:39:04 +02:00
Matthew Jasper
adb7fc6283 Fix tools 2020-10-06 11:19:30 +01:00
Yuki Okushi
22c5e0c347 Rollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr
Fix LitKind's byte buffer to use refcounted slice

While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type.

This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
2020-10-06 16:26:11 +09: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
bors
3239b46e92 Auto merge of #6114 - FliegendeWurst:no-mistyped-fraction, r=Manishearth
Do not lint float fractions in `mistyped_literal_suffixes`

As suggested in https://github.com/rust-lang/rust-clippy/issues/4706#issuecomment-544797928, the fractional part is now ignored (the integer part is checked instead).

Fixes: #4706

changelog: `mistyped_literal_suffixes` no longer warns on the fractional part of a float (e.g. 713.23_64)
2020-10-05 21:17:37 +00:00
Eduardo Broto
5554641fce Fix rustup fallout 2020-10-05 22:32:04 +02:00
Eduardo Broto
5f492490a3 Merge remote-tracking branch 'upstream/master' into rustup 2020-10-05 22:13:44 +02:00
FliegendeWurst
78695bd496
Do not lint float fractions in mistyped_literal_suffixes (fixes #4706) 2020-10-05 12:09:21 +02:00
Dylan MacKenzie
29d43f63bd clippy: (Body, DefId) -> Body 2020-10-04 16:07:03 -07:00
Robin Schoonover
f34f4a7327 Change clippy's Constant back to refcount clone byte strings 2020-10-04 15:53:37 -06: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
bors
9408c68c1d Auto merge of #6105 - bugadani:sus-char, r=ebroto
Lint for invisible Unicode characters other than ZWSP

This PR extends the existing `zero_width_space` lint to look for other invisible characters as well (in this case, `\\u{ad}` soft hyphen.

I feel like this lint is the logical place to add the check, but I also realize the lint name is not particularly flexible, but I also understand that it shouldn't be renamed for compatibility reasons.

Open questions:
 - What other characters should trigger the lint?
 - What should be done with the lint name?
 - How to indicate the change in functionality?

Motivation behind this PR: https://github.com/rust-lang/rust/issues/77417 - I managed to shoot myself in the foot by an invisible character pasted into my test case.

changelog: rename [`zero_width_space`] to [`invisible_characters`] and add SHY and WJ to the list.
2020-10-02 22:22:37 +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
Long Louis Bui
8b8c63f568 changed non_copy_const lints to warn by default 2020-10-02 23:12:40 +02:00
nahuakang
f302af33bc Add doc comment issue of #5834 to known problems of lint doc_markdown 2020-10-02 22:05:40 +02:00
Michael Howell
840f7daaad Deprecate clippy lint 2020-10-02 11:34:14 -07:00