Commit graph

580 commits

Author SHA1 Message Date
Samuel E. Moelius III
f1f780c942 Add let_underscore_drop 2020-11-08 07:00:35 -05:00
bors
92ba07582e Auto merge of #6134 - patrickelectric:as_utf8, r=llogiq
Check when `from_utf8` is called from sliced byte array from string

---

*Please keep the line below*
changelog: Fix #5487: Add linter to check when `from_utf8` is called from sliced byte array from string.
2020-11-07 17:06:27 +00:00
Patrick José Pereira
bc27d1492d Add string_from_utf8_as_bytes linter
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-11-04 21:17:46 -03:00
bors
5b52474ae6 Auto merge of #5911 - hegza:issue-568, r=ebroto
Add lint for 'field_reassign_with_default` #568

changelog: Add lint for field_reassign_with_default that checks if mutable object + field modification is used to edit a binding initialized with Default::default() instead of struct constructor.

Fixes #568

Notes:
- Checks for reassignment of one or more fields of a binding initialized with Default::default().
- Implemented using EarlyLintPass, might be future proofed better with LateLintPass.
- Does not trigger if Default::default() is used via another type implementing Default.
- This is a re-open of [PR#4761](https://github.com/rust-lang/rust-clippy/pull/4761), but I couldn't figure out how to re-open that one so here's a new one with the requested changes :S
2020-11-04 22:21:44 +00:00
bors
225ce5ff58 Auto merge of #6233 - montrivo:manual_ok_or, r=flip1995
add manual_ok_or lint

Implements partially #5923

changelog: add lint manual_ok_or
2020-11-03 16:42:59 +00:00
bors
2fe87a89c9 Auto merge of #6165 - dvermd:ref_option_ref, r=flip1995
Add lint 'ref_option_ref' #1377

This lint checks for usage of `&Option<&T>` which can be simplified as `Option<&T>` as suggested in #1377.

This WIP PR is here to get feedback on the lint as there's more cases to be handled:
* statics/consts,
* associated types,
* type alias,
* function/method parameter/return,
* ADT definitions (struct/tuple struct fields, enum variants)

changelog: Add 'ref_option_ref' lint
2020-11-03 16:21:51 +00:00
bors
a2bf404d34 Auto merge of #6101 - pitiK3U:from_iter_instead_of_collect, r=flip1995
Add lint: from_iter_instead_of_collect

Fixes #5679

This implements lint for `::from_iter()` from #5679 not the general issue (`std::ops::Add::add`, etc.).
This lint checks if expression is function call with `from_iter` name and if it's implementation of the `std::iter::FromIterator` trait.

changelog: Introduce  from_iter_instead_of_collect lint
2020-11-03 15:59:16 +00:00
Piti the little Light
9d6eedf5f2
Run cargo dev update_lints 2020-11-03 16:42:30 +01:00
Henri Lunnikivi
7b203f3da6 Implement field_reassign_with_default
- Implement `field_reassign_with_default` as a `LateLintPass`
- Avoid triggering `default_trait_access` on a span already linted by
`field_reassigned_with_default`
- Merge `default_trait_access` and `field_reassign_with_default` into
`Default`
- Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
- Fixes #568
2020-10-31 15:49:58 +02:00
Eduardo Broto
f8ac1f99ef Address suggestions in PR review 2020-10-30 23:47:22 +01:00
Eduardo Broto
d958269fe5 Rename single_char_push_str to single_char_add_str 2020-10-30 23:29:44 +01:00
bors
c57d8ae515 Auto merge of #6227 - HMPerson1:collect_map, r=phansch
Add lint for replacing `.map().collect()` with `.try_for_each()`

Fixes #6208

changelog: Add `map_collect_result_unit`
2020-10-29 15:34:15 +00:00
bors
e1a2845558 Auto merge of #6226 - Urcra:master, r=flip1995
Add lint for comparing to empty slices instead of using .is_empty()

Hey first time making a clippy lint

I added the implementation of the lint the `len_zero` since it shared a lot of the code, I would otherwise have to rewrite. Just tell me if the lint should use it's own file instead

changelog: Add lint for comparing to empty slices

Fixes #6217
2020-10-29 15:12:24 +00:00
Tim Nielens
111b9023da add manual_ok_or lint 2020-10-27 01:57:04 +01:00
dvermd
213dbf7aac clippy_lint: Add 'ref_option_ref' 2020-10-26 22:34:40 +01:00
HMPerson1
f0cf3bdca1
Add lint for replacing .map().collect() with .try_for_each() 2020-10-25 21:20:57 -04:00
Urcra
de5a6d3420 Initial implementation of comparison_to_empty 2020-10-26 00:31:25 +01:00
cgm616
312bbff696
Integrate suggestions from code review 2020-10-25 11:31:24 -04:00
Florian Hartwig
db8380c4a0 Add lint for unusually-grouped hex/binary literals 2020-10-25 09:18:38 -04:00
bors
90cb25d3f6 Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
New lint: manual-range-contains

This fixes #1110, at least for the contains-suggesting part.

- \[x] Followed [lint naming conventions][lint_naming]
- \[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: new lint: manual-range-contains
2020-10-25 10:35:46 +00:00
bors
399732bf79 Auto merge of #6103 - FrancisMurillo:mut_mutex_lock, r=flip1995
Add lint for `&mut Mutex::lock`

Fixes #1765

changelog: Add lint [`mut_mutex_lock`] for `&mut Mutex::lock` and suggests using `&mut Mutex::get_mut` instead.
2020-10-25 10:16:23 +00:00
bors
6b01c39e64 Auto merge of #6181 - cgm616:undropped-manually-drops, r=flip1995
Add new lint for undropped ManuallyDrop values

Adds a new lint for the following code:

```rust
struct S;

impl Drop for S {
    fn drop(&mut self) {
        println!("drip drop");
    }
}

fn main() {
    // This will not drop the `S`!!!
    drop(std::mem::ManuallyDrop::new(S));
    unsafe {
        // This will.
        std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
    }
}
```

The inner value of a `ManuallyDrop` will not be dropped unless the proper, unsafe drop function is called on it. This lint makes sure that a user does not accidently use the wrong function and forget to drop a `ManuallyDrop` value.

Fixes #5581.

---

*Please keep the line below*
changelog: none
2020-10-25 09:37:09 +00:00
Francis Murillo
f82f9c2c55 Add lint for &mut Mutex::lock 2020-10-25 17:18:52 +08:00
bors
e0e617adaa Auto merge of #6109 - patrickelectric:single_element_for_check, r=flip1995
Add linter for a single element for loop

changelog: Fixes #1540, check for vectors that contain a single element in a for loop
2020-10-25 09:15:55 +00:00
bors
a675778cfb Auto merge of #6029 - Daniel-B-Smith:refcell_ref_await, r=flip1995
Add lint for holding RefCell Ref across an await

Fixes #6008

This introduces the lint await_holding_refcell_ref. For async functions, we iterate
over all types in generator_interior_types and look for `core::cell::Ref` or `core::cell::RefMut`. If we find one then we emit a lint.

Heavily cribs from: https://github.com/rust-lang/rust-clippy/pull/5439

changelog: introduce the await_holding_refcell_ref lint
2020-10-25 08:54:27 +00:00
Cauê Baasch de Souza
e8731a926c Add large_types_passed_by_value lint
Refactor trivially_copy_pass_by_ref and the new lint into pass_by_ref_or_value module

Update stderr of conf_unknown_key test

Rename lint to large_types_passed_by_value

Increase `pass_by_value_size_limit` default value to 256

Improve rules for `large_types_passed_by_value`

Improve tests for `large_types_passed_by_value`

Improve documentation for `large_types_passed_by_value`

Make minor corrections to pass_by_ref_or_value.rs suggested by clippy itself

Fix `large_types_passed_by_value` example and improve docs

pass_by_ref_or_value: Tweak check for mut annotation in params

large_types_passed_by_value: add tests for pub trait, trait impl and inline attributes
2020-10-24 14:46:56 -03:00
Andre Bogus
c693de350a New lint: manual-range-contains 2020-10-22 08:45:21 +02:00
cgm616
4a4f998c39 Add new lint for undropped ManuallyDrop values 2020-10-21 21:21:11 -04:00
Daniel Smith
070a751d4c update_lints 2020-10-21 11:04:26 -04:00
Patrick José Pereira
ec23db9496 Add linter for a single element for loop
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-10-19 09:53:35 -03:00
Tim Nielens
6d4eeeabcd manual-unwrap-or / pr remarks 2020-10-14 22:16:48 +02:00
Tim Nielens
07b2da884c add lint less_concise_than_option_unwrap_or 2020-10-14 22:16:48 +02:00
Andre Bogus
6021c23159 New lint: result-unit-err 2020-10-11 22:04:59 +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
Bruno BELANYI
aa7c42f756 fixup! New lint: Recommend using ptr::eq when possible
Add missing modified files.
2020-10-07 11:54:09 +02:00
Eduardo Broto
13781ae2f8 Remove "thanks" section 2020-10-06 00:09:45 +02:00
Eduardo Broto
c5f17002e5 Add changelog for 1.48 beta 2020-10-05 17:03:24 +02:00
Dániel Buga
998bd3b6b4 Rename lint to invisible_characters 2020-10-03 00:03:33 +02:00
Jethro Beekman
0690f9c5d5 Add lint for inline assembly syntax style preference 2020-09-30 09:43:46 +02:00
Frank
1479c18396 add disallowed_method lint 2020-09-25 11:09:04 -05:00
bors
e636b88aa1 Auto merge of #6044 - rschoon:rc-buffer, r=yaahc
Add `rc_buffer` lint for checking Rc<String> and friends

Fixes #2623

This is a bit different from the original PR attempting to implement this type of lint.   Rather than linting against converting into the unwanted types, this PR lints against declaring the unwanted type in a struct or function definition.

I'm reasonably happy with what I have here, although I used the fully qualified type names for the Path and OsString suggestions, and I'm not sure if I should have just used the short versions instead, even if they might not have been declared via use.

Also, I don't know if "buffer type" is the best way to put it or not.  Alternatively I could call it a "growable type" or "growable buffer type", but I was thinking of PathBuf when I started making the lint.

changelog: Add `rc_buffer` lint
2020-09-23 18:35:08 +00:00
Michael Wright
8b04c2d6e8 Merge branch 'master' into lint-5734 2020-09-15 21:21:35 +02:00
Robin Schoonover
1b5317f68b Add rc_buffer lint for Rc<String> and other buffer types 2020-09-14 17:08:14 -06:00
bors
f82e84c894 Auto merge of #5998 - deg4uss3r:master, r=yaahc
Add map_err_ignore lint

In a large code base a lot of times errors are ignored by using something like:

```rust
foo.map_err(|_| Some::Enum)?;
```

This drops the original error in favor of a enum that will not have the original error's context. This lint helps catch throwing away the original error in favor of an enum without its context.

---

*Please keep the line below*
changelog: Added map_err_ignore lint
2020-09-14 19:56:47 +00:00
Michael Wright
d1f0f04a48 New lint: manual-strip
Add a new lint, `manual-strip`, that suggests using the `str::strip_prefix`
and `str::strip_suffix` methods introduced in Rust 1.45 when the same
functionality is performed 'manually'.

Closes #5734
2020-09-14 06:11:35 +02:00
bors
0ab75c37b6 Auto merge of #5977 - xvschneider:AddLintPanicInResult, r=matthiaskrgr
Add lint panic in result

### Change
Adding a new "restriction" lint that will emit a warning when using "panic", "unimplemented" or "unreachable" in a function of type option/result.

### Motivation
Some codebases must avoid crashes at all costs, and hence functions of type option/result must return an error instead of crashing.

### Test plan
Running:
TESTNAME=panic_in_result cargo uitest ---

changelog: none
2020-09-10 16:22:20 +00:00
bors
5034d47f72 Auto merge of #5980 - matsujika:create-dir, r=flip1995
Add a lint to prevent `create_dir` from being used

This closes #5950
changelog: none
2020-09-10 14:34:22 +00:00
Vali Schneider
f90b1fc063 cargo dev update-lints 2020-09-09 14:06:11 -07:00
Vali Schneider
3550568a54 removing if chain and renaming lint 2020-09-09 14:02:34 -07:00
Ricky
337729137b Ran cargo dev update_lints 2020-09-01 17:05:40 -04:00