Commit graph

7077 commits

Author SHA1 Message Date
Alex Macleod
3957244120 Add needless_late_init lint 2021-11-23 15:08:49 +00:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
dswij
ec3d1c8ca3 Fix FP on if_then_some_else_none when there is early return 2021-11-23 10:11:30 +08:00
bors
57a8804ef9 Auto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet
Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

Fixes #7981

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Add new lint [`octal_escapes`], which checks for literals like `"\033[0m"`.
2021-11-22 20:29:53 +00:00
Georg Brandl
1210bb40d3 octal_escapes: note on print!() format strings 2021-11-22 21:02:03 +01:00
Georg Brandl
0bc25d04c6 octal_escapes: emit only one lint for all cases found each literal 2021-11-22 21:00:19 +01:00
Georg Brandl
850e7f533e octal_escapes: updates from review, fix byte string prefix 2021-11-22 18:02:17 +01:00
bors
5fbfdfa319 Auto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate
Allow `suboptimal_flops` in const functions

This PR allows `clippy::suboptimal_flops` in constant functions. The check also effects the `clippy::imprecise_flops` lint logic. However, this doesn't have any effects as all functions checked for are not const and can therefore not be found in such functions.

---

changelog: [`suboptimal_flops`]: No longer triggers in constant functions

Closes: rust-lang/rust-clippy#8004
2021-11-22 00:01:49 +00:00
bors
de2208a351 Auto merge of #7997 - surechen:Fixes_7915, r=giraffate
Fixes shadow_same's false positive for #7915

Fix shadow_same's false positive for async function's params(Fixes #7915):

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's false positive for async function's params
2021-11-21 23:48:24 +00:00
Cameron Steffen
8c1c763c2d clippy: Fix pattern_type_mismatch for loop 2021-11-21 08:16:20 -06:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
surechen
846c0bef07 Fixes #7915
Fix shadow_same's positive false for async function's params:

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's positive false for async function's params
2021-11-21 14:28:44 +08:00
Georg Brandl
0c4055c283 Avoid inline hints with double backticks for doc-markdown 2021-11-20 18:13:24 +01:00
ThibsG
092fe209a6 Move deref closure builder to clippy_utils::sugg module 2021-11-20 15:48:21 +01:00
xFrednet
1c8085d705
Allow suboptimal_flops in const functions 2021-11-20 15:39:29 +01:00
Georg Brandl
982124acfa Add new lint octal_escapes
This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.
2021-11-20 11:57:25 +01:00
ThibsG
5ebede0c14 Fix full projection identifier + move applicability to MaybeIncorrect 2021-11-20 09:40:11 +01:00
ThibsG
1176b8e5e9 Handle closures with type annotations on args 2021-11-20 09:40:11 +01:00
ThibsG
2ff702cbb5 Rephrase the fn checking for a double ref, not only one 2021-11-20 09:40:11 +01:00
ThibsG
abaaf744fd Add some notes about MethodCall cases 2021-11-20 09:40:11 +01:00
ThibsG
90a72f506c Handle args taken by ref also for MethodCall 2021-11-20 09:40:11 +01:00
ThibsG
7a55407cc3 Fix suggestions when call functions involved taking by ref 2021-11-20 09:40:11 +01:00
ThibsG
6d1ccbf466 Correct suggestion when dereferencing enough, calling a function 2021-11-20 09:40:11 +01:00
ThibsG
ac45a83ad5 Handle multiple reference levels into binding type and add more tests 2021-11-20 09:40:11 +01:00
ThibsG
788c9ccc93 Applying refactoring for simplified code 2021-11-20 09:40:11 +01:00
ThibsG
91dd9c46de Handle other projection kinds 2021-11-20 09:40:11 +01:00
ThibsG
97783a8cb9 Return a struct and add applicability 2021-11-20 09:40:11 +01:00
ThibsG
d0dd797709 Build end of suggestion only once at the end of the process 2021-11-20 09:40:11 +01:00
ThibsG
9ab4b673eb Simplifying next_pos init 2021-11-20 09:40:11 +01:00
ThibsG
e24aba2c1a Use applicability for snippets 2021-11-20 09:40:11 +01:00
ThibsG
6dca4f261d Add some doc for search_is_some lint 2021-11-20 09:40:11 +01:00
ThibsG
b38f173aa3 Build suggestion within visitor + add more tests 2021-11-20 09:40:10 +01:00
ThibsG
5ed93af9c4 Use ExprUseVisitor and multipart suggestion to avoid iffy String replacement 2021-11-20 09:40:10 +01:00
ThibsG
f4c75cde5e Fix any() not taking reference in search_is_some lint 2021-11-20 09:40:10 +01:00
Jason Newcomb
0d1f1cec44 Remove surrounding unsafe block in strlen_on_c_strings when possible 2021-11-19 21:14:51 -05:00
Jason Newcomb
c443f8fb95 Fix strlen_on_c_strings when not used with a full path 2021-11-19 20:02:49 -05:00
bors
38bd2514ad Auto merge of #7984 - phansch:disallowed-type-rename, r=xFrednet
Pluralize `disallowed_type` lint

This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types

changelog: Rename nursery lint [`disallowed_type`] to [`disallowed_types`].
2021-11-19 13:39:08 +00:00
bors
2776076efa Auto merge of #7977 - Jarcho:multi_needless_borrow, r=xFrednet
Improve `needless_borrow` lint

fixes: #5327
fixes: #1726
fixes: #1212

This is merging `needless_borrow` into the `dereference` pass in preparation for `explicit_auto_deref`. `explicit_auto_deref` needs to implement most of what `needless_borrow` implements in order to work.

There is a minor regression here where `let x: &str = &x.deref()` will trigger `needless_borrow` without triggering `explicit_deref_methods`. Removing the redundant borrow will cause `explicit_deref_methods` to trigger. This will be fixed when `explicit_auto_deref` is implemented.

changelog: Lint `needless_borrow` when a borrow is auto-derefed more than once
changelog: Lint `needless_borrow` in the trailing expression of a block for a match arm
2021-11-18 23:35:03 +00:00
flip1995
9b38fb7b71
Also pluralize disallowed_method(s) lint
To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.
2021-11-18 17:37:06 +01:00
Philipp Hansch
a0d81d1327
Pluralize disallowed_type lint filenames
This way they match up with the pluralized lint name as well.
2021-11-18 17:37:06 +01:00
Philipp Hansch
b7f18916fa
Pluralize disallowed_type lint
This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types
2021-11-18 17:37:02 +01:00
flip1995
731dfde267
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-18 12:22:00 +01:00
Vadim Petrochenkov
cb62680262 rustc: Remove #[rustc_synthetic]
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
2021-11-18 14:32:29 +08:00
bors
bb58dc84c1 Auto merge of #7968 - Jarcho:manual_map_unsafe, r=xFrednet
Fix `manual_map` with unsafe functions

fixes: #7820
changelog: Fix `manual_map` suggestion when used with unsafe functions and unsafe blocks
2021-11-17 16:20:04 +00:00
bors
6ac42fe6fa Auto merge of #7971 - togami2864:fix/option-map-or-none, r=llogiq
fix suggestion in option_map_or_none

fix: #7960
changelog: change suggestion in the lint rule `option_map_or_none`
2021-11-17 16:01:55 +00:00
Jason Newcomb
8506f66294 Minor simplification to manual_map 2021-11-17 10:36:13 -05:00
togami2864
006c442657 check whether stmts is empty or not in block 2021-11-18 00:36:11 +09:00
bors
d550e5f5e6 Auto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995
Fix ICE on `undocumented_unsafe_blocks`

fix https://github.com/rust-lang/rust-clippy/issues/7979

changelog: Fix ICE on `undocumented_unsafe_blocks`
2021-11-17 15:24:07 +00:00
bors
94ca94fa5f Auto merge of #7898 - F3real:unit_struct, r=camsteffen
Don't show no_effect warning on unit structs implementing fn_once

Fixes #7792

changelog: Don't show [`no_effect`] or [`unecessary_operation`] warning for unit struct implementing FnOnce
2021-11-17 14:09:51 +00:00
Takayuki Nakata
3f3d7c2005 Fix ICE on undocumented_unsafe_blocks 2021-11-17 22:35:01 +09:00
bors
46687f1313 Auto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen
Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 01:46:58 +00:00
surechen
c051656c83 fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 08:38:45 +08:00
F3real
e9bf5ec659 Don't show no_effect warning on unit structs implementing fn* traits 2021-11-17 00:50:07 +01:00
bors
83ad51108b Auto merge of #7982 - Blckbrry-Pi:master, r=llogiq
Fix `needless_collect`'s tendency to suggest code requiring multiple mutable borrows of the same value.

Fixes error specified in #7975.

changelog: [`needless_collect`] no longer suggests removal of `collect` when removal would create code requiring mutably borrowing a value multiple times.
2021-11-16 23:01:02 +00:00
Skyler Calaman
c52b389b16 Fix readability suggestions.
1. Make the lifetime contained in LateContext `'tcx`.
2. Fix `'txc` to `'tcx` because it was a typo.
3. Refactor `IterFunctionVisitor`'s `visit_block` method to be more readable.
4. Replace uses of `rustc_middle::ty::TyKind` with `rustc::middle::ty`, and remove the `#[allow(...)]`.

(Thank you llogiq for all these suggestions!)
2021-11-16 11:29:26 -05:00
Skyler Calaman
5b3c00f012 Successfully generalize prevention of suggestions causing multiple mutable borrows.
Also add some more tests to check that it's working.
2021-11-16 09:18:49 -05:00
togami2864
7605bac2cb resolve CI 2021-11-16 23:07:19 +09:00
Jason Newcomb
2938ffd0d9 Improve heuristics for determining whether eager of lazy evaluation is preferred 2021-11-15 20:54:13 -05:00
Jason Newcomb
8ded385ddc Improve needless_borrow lint.
* Lint when a borrow is auto dereferenced more than once
* Lint when the expression is used as the expression of a block for a match arm

Moves `needless_borrow` and `ref_binding_to_reference` to `dereference`
lint pass in preperation for `explicit_auto_deref` lint.
2021-11-15 13:17:59 -05:00
togami2864
0a30fdcd3c move the let statement out of the macro 2021-11-16 03:02:08 +09:00
togami2864
300282c09a fix fmt 2021-11-16 02:53:35 +09:00
togami2864
cd5781648a add comment 2021-11-16 02:30:54 +09:00
togami2864
02e0726149 fix a bug that the closure arguments are not displayed 2021-11-16 02:29:02 +09:00
togami2864
bbffe825ed add reduce_unit_expression 2021-11-16 02:06:31 +09:00
bors
0def42fd7b Auto merge of #7974 - matthiaskrgr:7973_opt_map_or_else_dont_expand_sugg_macro, r=flip1995
option_if_let_else: don't expand macros in suggestion

Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else
2021-11-15 10:27:29 +00:00
bors
f82bf470d0 Auto merge of #7957 - surechen:fix_for_7854, r=giraffate
Support suggestion for #7854

I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.(Fixes #7854)

changelog: Make let_underscore_lock support parking_lot
2021-11-15 00:50:28 +00:00
surechen
634e79c655 Support suggestion for #7854
I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.

changelog: Make let_underscore_lock support parking_lot
2021-11-15 08:36:36 +08:00
Skyler Calaman
3e20e300f6 Fix specific code outlined in issue #7975.
Still needs to generalize to other mixes of let bindings, `map` method calls, etc.
2021-11-14 18:18:43 -05:00
Matthias Krüger
3fe11e776c option_if_let_else: don't expand macros in suggestion
Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else
2021-11-13 23:17:21 +01:00
togami2864
2ed4a8a3e6 fix suggestion in option_map_or_none 2021-11-13 22:38:28 +09:00
Jason Newcomb
80a263d469 Fix manual_map suggestion when used with unsafe functions and unsafe blocks. 2021-11-12 19:12:17 -05:00
bors
4f82dd83df Auto merge of #7948 - 5225225:castlosslessbool, r=llogiq
Lint for bool to integer casts in `cast_lossless`

The lint description says

> Checks for casts between *numerical* types that may be replaced by safe conversion functions.

Which is strictly speaking being violated here, but it seems within the spirit of the lint. I think it is still a useful lint to have, and having a different lint for just this feels excessive. Thoughts?

Fixes #7947

changelog: Lint for bool to integer casts in [`cast_lossless`]
2021-11-12 18:17:18 +00:00
5225225
d4c8cb63a4 Change cast_lossless message for bools only 2021-11-12 17:01:35 +00:00
bors
8b84a760ca Auto merge of #7956 - camsteffen:author, r=llogiq
Author improvements

changelog: none

Various aspects of the author implementation are re-imagined to be much less repetitive. Also fixes some bugs. I hope this makes author more fun to work on for future contributors.

The last commit is pretty heavy but I tried to at least separate some changes so that the test file diffs per commit are simple.
2021-11-11 19:33:06 +00:00
xFrednet
e444cbe5d6
New index_refutable_slice lint
* Finding pattern slices for `avoidable_slice_indexing`
* `avoidable_slice_indexing` analysing slice usage
* Add configuration to `avoidable_slice_indexing`
* Emitting `avoidable_slice_indexing` with suggestions
* Dogfooding and fixing bugs
* Add ui-toml test for `avoidable_slice_indexing`
* Correctly suggest `ref` keywords for `avoidable_slice_indexing`
* Test and document `mut` for `avoid_slice_indexing`
* Handle macros with `avoidable_slice_indexing` lint
* Ignore slices with sub patterns in `avoidable_slice_indexing`
* Update lint description for `avoidable_slice_indexing`
* Move `avoidable_slice_indexing` to nursery
* Added more tests for `avoidable_slice_indexing`
* Update documentation and message for `avoidable_slice_indexing`
* Teach `avoidable_slice_indexing` about `HirId`s and `Visitors`
* Rename lint to `index_refutable_slice` and connected config
2021-11-11 17:34:02 +01:00
Cameron Steffen
27a1763eac Make author DRYer 2021-11-11 09:38:00 -06:00
bors
3bfe98d372 Auto merge of #7813 - xFrednet:6492-lint-version, r=flip1995
Add Clippy version to Clippy's lint list

Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate.

I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding #6623 🙃

This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted 🙃

![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png)

Also, mobile approved xD

![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png)

---

r? `@flip1995`

cc: #7172

closes: #6492

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. 🎉

---

Example lint declaration after this update:

```rs
declare_clippy_lint! {
    /// [...]
    ///
    /// ### Example
    /// ```rust
    /// // Bad
    /// let x = 3.14;
    /// // Good
    /// let x = std::f32::consts::PI;
    /// ```
    #[clippy::version = "pre 1.29.0"]
    pub APPROX_CONSTANT,
    correctness,
    "the approximate of a known float constant (in `std::fXX::consts`)"
}
```
2021-11-11 12:38:04 +00:00
xFrednet
8c45fd88d0
New internal lint to make clippy::version attribute mandatory 2021-11-11 13:03:30 +01:00
dswij
2d037aa4a6 Check for no_std and no_core attribute in swap lint
This commit adds a `no_std` and `no_core` check on `swap` lint and additionally suggest `core::mem::swap` whenever possible.
Remove warning if both `std` and `core` is not present.
2021-11-11 12:30:07 +08:00
Cameron Steffen
72d7b9c097 author: Remove needless refs 2021-11-10 16:37:55 -06:00
Cameron Steffen
a806ce79b6 author: reorder match arm 2021-11-10 16:36:54 -06:00
Cameron Steffen
d0cc201204 author: fix some bugs 2021-11-10 16:36:51 -06:00
Cameron Steffen
ce01346ac1 author: name qpath consistently 2021-11-10 15:40:50 -06:00
xFrednet
94bc0a1c78
Address review feedback 2021-11-10 20:14:02 +01:00
xFrednet
9d9d06d557
Add lint to check for invalid clippy:version attributes 2021-11-10 19:48:31 +01:00
xFrednet
d647696c1f
Added clippy::version attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...

And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...

Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.

```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;

let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
    ls | where name =~ "rust-" | select name | format {name}/lints.json |
    each { open $it | select id | insert version $it | str substring "5,11" version} |
    group-by id | rotate counter-clockwise id version |
    update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
    let version = ($versions | where id == ($row.id) | format {version})
    let idu = ($row.id | str upcase)
    $"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n    pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```

And this still has some problems, but at this point I just want to be done -.-
2021-11-10 19:48:31 +01:00
xFrednet
63cb41098b
Manually add clippy::version attribute to deprecated lints 2021-11-10 19:48:30 +01:00
xFrednet
8565fc468e
Add clippy version to Clippy's lint list 2021-11-10 19:48:30 +01:00
xFrednet
7c1e62d962
Added clippy::version attribute as lint metadata 2021-11-10 19:48:29 +01:00
dswij
a003ca6853 semicolon_if_nothing_returned now checks if the stmt ends with semicolon 2021-11-10 14:46:00 +08:00
bors
93f13d532f Auto merge of #7951 - mikerite:matches-20211109, r=llogiq
`match_overlapping_arm` refactoring

The main purpose of this pull request is to remove the unneeded and scary `unimplented!()` in the `match_arm_overlapping` code.

The rest is gratuitous refactoring.

changelog: none
2021-11-09 19:28:48 +00:00
bors
f69721f37c Auto merge of #7950 - Serial-ATA:issue-7920, r=llogiq
Fix `explicit_counter_loop` suggestion for non-usize types

changelog: Add a new suggestion for non-usize types in [`explicit_counter_loop`]

closes: #7920
2021-11-09 19:14:24 +00:00
Matthias Krüger
3b6b1ab0ec Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts

Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-09 19:00:40 +01:00
5225225
6e84f00045 Check MSRV for bool to int from impl 2021-11-09 17:35:35 +00:00
5225225
33822012ec Lint for bool to integer casts in cast_lossless 2021-11-09 17:30:15 +00:00
bors
c94d62b153 Auto merge of #7949 - Serial-ATA:issue-7921, r=flip1995
Fix suggestion for deref expressions in redundant_pattern_matching

changelog: Fix suggestion for deref expressions in [`redundant_pattern_matching`]

closes: #7921
2021-11-09 12:37:49 +00:00
Serial
e54c341d05 Fix suggestion for deref expressions in redundant_pattern_matching 2021-11-09 07:25:09 -05:00
Michael Wright
8b7691551a matches: remove pub from some items
There is no reason for these to be `pub`. They aren't used anywhere
else.
2021-11-09 05:44:02 +02:00
Michael Wright
81fa758356 Improve variable naming 2 2021-11-09 05:44:02 +02:00
Michael Wright
c8f909ee54 Improve variable naming 2021-11-09 05:44:02 +02:00
Michael Wright
f829523340 Simplify range comparison code
Reword the `Kind` type so that the `cmp` function is simpler.
2021-11-09 05:44:02 +02:00
Michael Wright
949b25981c Change Bound to EndBound
Only the end bounds of ranges can actually be included or excluded. This
commit changes the SpannedRange type to reflect that. Update `Kind::value`
to and `Kind::cmp` for this change. `Kind::cmp` gets flipped to check value
first and then the bound details and is much shorter.
2021-11-09 05:44:02 +02:00
Michael Wright
98416d7f6c Remove unimplemented!() case in matches code
This unbounded case never actually happens because `all_ranges(..)` uses
the scrutinee type bounds for open ranges. Switch to our own `Bound`
enum so that we don't have this case.
2021-11-09 05:44:02 +02:00
Serial
680923491a Fix explicit_counter_loop suggestion for non-usize types 2021-11-08 22:21:05 -05:00
bors
830f2205d4 Auto merge of #7944 - Serial-ATA:deprecated-cfg-attr-msrv, r=giraffate
Add MSRV to deprecated_cfg_attr

changelog: Add MSRV to [`deprecated_cfg_attr`]

closes: #7922
2021-11-09 00:58:37 +00:00
Serial
413d255916 Add MSRV to deprecated_cfg_attr 2021-11-08 17:53:50 -05:00
Deadbeef
6d23824ef4 Make select_* methods return Vec for TraitEngine 2021-11-08 23:35:23 +08:00
bors
94517d397c Auto merge of #7938 - camsteffen:visitors, r=xFrednet
Introduce `expr_visitor` and `expr_visitor_no_bodies`

changelog: none

A couple utils that satisfy a *lot* of visitor use cases. Factoring in every possible usage would be really big so I just focused on cleaning clippy_utils.
2021-11-08 13:39:58 +00:00
Serial
2c6f03d48b Fix ICE in undocumented_unsafe_blocks 2021-11-07 14:28:30 -05:00
Vadim Petrochenkov
c063203c2b ast: Fix naming conventions in AST structures
TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
2021-11-07 21:38:17 +08:00
Gary Guo
0cb9ac2d96 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Serial
c96cd359f5 Extend author lint 2021-11-06 03:08:14 -04:00
Cameron Steffen
2c7b7e8c56 Remove if let check for match_ref_pats 2021-11-05 14:50:23 -05:00
Cameron Steffen
5239a90f70 Factor in some expr_visitor usages 2021-11-05 14:39:39 -05:00
Cameron Steffen
1c4dd8d3eb Remove trim_semicolon 2021-11-05 11:39:50 -05:00
bors
445c83f8f3 Auto merge of #7937 - flip1995:rustfmt-skip-artefact, r=Manishearth
Remove rustfmt::skip attribute from register_plugins function

r? `@Manishearth` since you added this in #540 😄

changelog: none
2021-11-05 15:34:46 +00:00
bors
9a60a93cac Auto merge of #7897 - camsteffen:in-macro, r=flip1995
Replace `in_macro` usage with `from_expansion`

changelog: none

Generally replace `in_macro(span)` with `span.from_expansion()`. If we're just trying to avoid expanded code, this seems more appropriate because any kind of expanded code is prone to false positives. One place I did not touch is `macro_use.rs`. I think this lint could use a rewrite so I moved `in_macro` there, the only place it is still used.
2021-11-05 14:42:32 +00:00
bors
85e25923e1 Auto merge of #7909 - mikerite:fix-7816, r=camsteffen
Fix false negative in [`match_overlapping_arms`]

changelog: Fix false negative in [`match_overlapping_arms`]
2021-11-05 14:16:38 +00:00
Cameron Steffen
14d54f0f6e Use Span::from_expansion instead of in_macro 2021-11-05 08:50:17 -05:00
flip1995
93ffc9d233
Remove rustfmt::skip attribute from register_plugins function 2021-11-05 10:54:37 +00:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
flip1995
1cc21db8c6
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-04 12:03:28 +00:00
Serial
0db8c52291 Add suggestion to missing backticks error 2021-11-02 16:50:47 -04:00
Samuel Tardieu
7f8198acad Advise to put a :: prefix inside the ticks 2021-11-02 17:57:50 +01:00
xFrednet
db9e012927 Update clippy dependencies
* semver = "0.11" -> "1.0"
* cargo_metadata = "0.12" -> "0.14"
2021-11-02 14:19:31 +01:00
bors
18cc4e74f8 Auto merge of #7907 - Alexendoo:non-ascii-restriction, r=flip1995
Move non_ascii_literal to restriction

It feels like the more apt category, since cases where you'd want it enabled would be pretty specific

changelog: Move [`non_ascii_literal`] to `restriction`
2021-11-02 10:36:26 +00:00
bors
9720619432 Auto merge of #7901 - samueltardieu:fix-7893, r=xFrednet,flip1995
Prevent clippy::needless_lifetimes false positive in async function definition

Scan `OpaqueDef` bounds for lifetimes as well. Those `OpaqueDef` instances are generated while desugaring an `async` function definition.

This fixes #7893

changelog: Prevent [`clippy::needless_lifetimes`] false positive in `async` function definition
2021-11-02 10:23:15 +00:00
bors
276e8951f1 Auto merge of #7851 - nbdd0121:master, r=flip1995
Fix manual_assert and match_wild_err_arm for `#![no_std]` and Rust 2021

Rust 2015 `std::panic!` has a wrapping block while `core::panic!` and Rust 2021 `std::panic!` does not. See rust-lang/rust#88919 for details.

Note that the test won't pass until clippy changes in rust-lang/rust#88860 is synced.

---

changelog: Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust 2021.

Fixes #7723
2021-11-02 10:09:47 +00:00
bors
38d80257d0 Auto merge of #7726 - dswij:unseparated-literal-suffix, r=flip1995
Unseparated literal suffix

Closes #7658

Since `literal_suffix` style is opinionated, we should disable by default and only enforce if it's stated as so.

changelog: [`unseparated_literal_suffix`] is renamed to `literal_suffix`, adds a new configuration `literal-suffix-style` to enforce a certain style writing literal_suffix. Possible values for `literal-suffix-style`: `"separated"`, `"unseparated"`
2021-11-02 09:57:12 +00:00
Samuel Tardieu
3f84010688 Examine lifetimes in OpaqueDef bounds as well
Fix #7893.
2021-11-02 10:54:58 +01:00
bors
4e355ebb6e Auto merge of #7819 - rust-lang:avoid-linting-impossible-truncation, r=flip1995
avoid linting `possible_truncation` on bit-reducing operations

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: avoid linting `possible_truncation` on bit-reducing operations
2021-11-02 09:44:27 +00:00
Takayuki Nakata
ec456de2a3 Small fixes for missing backticks in doc 2021-11-02 09:09:22 +09:00
Gary Guo
7e5f99ab58 Fix manual_assert for #![no_std] and Rust 2021 2021-11-01 15:47:33 +00:00
Dharma Saputra Wijaya
1085df58ac Add separated_literal_suffix as an alternative for
`unseparated_literal_suffix`

This commit adds a configuration `literal-suffix-style` to enforce a
specific style for unseparated_literal_suffix. The configuration accepts
two values:
- "separated"
    enforce all literals to be written separately (e.g. `123_i32`)
- "unseparated"
    enforce all literals to be written as unseparated (e.g. `123i32`)

Not specifying a value means that there is no preference on style and
any style should not be warned.
2021-11-01 22:26:13 +08:00
Michael Wright
693df63c7d Ensure match_overlapping_arms warns on first 2021-11-01 06:12:43 +02:00
Michael Wright
c3d45775c4 Fix match_overlapping_arm false negative
Fixes #7816
2021-11-01 06:12:43 +02:00
Alex Macleod
28c225f775 Move non_ascii_literal to restriction 2021-10-31 12:59:53 +00:00
bors
4c70c182c0 Auto merge of #7895 - ahmedkrmn:master, r=Manishearth
Disable "if_not_else" lints from firing on else-ifs

Fixes #7892

1. Convert `['if_not_else']` to `LateLintPass` and use `clippy_utils::is_else_clause` for checking.
2. Update tests.

changelog: [`if_not_else`] now ignores else if statements.
2021-10-29 20:31:51 +00:00
Ahmed Karaman
2f327aaba5
Disable "if_not_else" lints firing on else-ifs
1. Convert IfNotElse to LateLintPass and use clippy_utils::is_else_clause for checking.
2. Handle the case where the span comes from desugaring.
3. Update tests.
2021-10-29 22:07:05 +02:00
Andre Bogus
00ea73e162 avoid linting possible_truncation on bit-reducing operations 2021-10-29 21:59:24 +02:00
bors
dbe167daaa Auto merge of #7890 - Alexendoo:ptr-arg-alias, r=camsteffen
Ignore references to type aliases in ptr_arg

Works using the fact that the hir path will point to a TyAlias, rather than being resolved to the underlying type

Fixes #7699

changelog: [`ptr_arg`] No longer lints references to type aliases
2021-10-29 19:45:26 +00:00
Cameron Steffen
022146d2c3 Rename if_then_panic to manual_assert 2021-10-28 09:41:53 -05:00
Cameron Steffen
d8fcfd7d64 Move if_then_panic to pedantic 2021-10-28 09:38:01 -05:00
bors
7788af9c47 Auto merge of #7891 - giraffate:fix_ice_for_undocumented_unsafe_blocks, r=flip1995
Fix ice in `undocumented_unsafe_blocks`

Fix https://github.com/rust-lang/rust-clippy/issues/7868

changelog: Fix ice in [`undocumented_unsafe_blocks`]
2021-10-28 13:37:40 +00:00
Takayuki Nakata
35bf041c21 Fix ICE in undocumented_unsafe_blocks 2021-10-28 22:10:59 +09:00
bors
89a11564cc Auto merge of #7847 - mikerite:fix-7829, r=flip1995
Fix false positive in `match_overlapping_arm`

Fixes #7829

changelog: Fix false positive in [`match_overlapping_arm`].
2021-10-28 08:59:21 +00:00
bors
ed71addee7 Auto merge of #7885 - devonhollowood:deprecated-cleanup, r=llogiq
Clean up `tests/ui/deprecated.rs`

Clean up `tests/ui/deprecated.rs`

Along with #7884, this fixes #7057

changelog: none
2021-10-27 18:38:38 +00:00
Alex Macleod
e2c30f05c1 Ignore references to type aliases in ptr_arg
Works using the fact that the hir path will point to a TyAlias, rather
than being resolved to the underlying type
2021-10-27 19:08:42 +01:00
bors
962e21cf15 Auto merge of #7875 - mbStavola:unit-hash, r=xFrednet
Add unit-hash lint

changelog: [`unit_hash`] Add lint for hashing unit values

This will lint for situations where the end user is attempting to hash a unit value (`()`), as the implementation in `std` simply [does nothing][impl]. Closes #7159 .

Example:

```rust
().hash(&mut state);

// Should (probably) be replaced with:
0_u8.hash(&mut state);
```

[impl]: a5f164faad/library/core/src/hash/mod.rs (L656)
2021-10-27 14:37:54 +00:00
Matt Stavola
36d4a4ea82
Add unit-hash lint 2021-10-27 06:32:37 -07:00
bors
444ef3e4d5 Auto merge of #7880 - Alexendoo:newlint-add-pass, r=flip1995
Register the generated lints from `cargo dev new_lint`

How to register a lint was something that took me a couple reads to figure out, this will hopefully make that easier. It appends the created lint to the end of the list when running `cargo dev new_lint`

changelog: none
2021-10-27 07:33:00 +00:00
bors
ba2ac3e263 Auto merge of #7860 - dswij:question-mark-fp, r=giraffate
Fix `question_mark` FP on custom error type

Closes #7859

#7840 aims to ignore `question_mark` when the return type is custom, which is [covered here](df65291edd/tests/ui/question_mark.rs (L144-L149)). But this fails when there is a call in conditional predicate

changelog: [`question_mark`] Fix false positive when there is call in conditional predicate
2021-10-26 23:46:21 +00:00
bors
a48367e21c Auto merge of #7884 - devonhollowood:rename-cleanup, r=xFrednet
Clean up tests/ui/rename.rs

Part one of #7057, cleaning up `tests/ui/rename.rs`. `tests/ui/deprecated.rs` will be updated in a subsequent PR.

changelog: none
2021-10-26 21:16:44 +00:00
xFrednet
dea940259e Remove hidden code lines in Clippy's lint list 2021-10-26 22:33:46 +02:00
Alex Macleod
bd778e216d Register the generated lints from cargo dev new_lint 2021-10-26 19:05:29 +01:00
Devon Hollowood
e48ab448f9 Clean up tests/ui/deprecated.rs
This also removes the uplifted lints from this test suite -- these are now
tested in `tests/ui/rename.rs`
2021-10-26 10:52:35 -07:00
Dharma Saputra Wijaya
fb0fbad5ca Rename variable name in question_mark 2021-10-26 21:22:22 +08:00
dswij
a1a399d168 Fix question_mark FP on calls 2021-10-26 21:21:46 +08:00
bors
075996efd7 Auto merge of #7878 - rust-lang:string-slice, r=giraffate
new lint: string-slice

This is a restriction lint to highlight code that should have tests containing non-ascii characters. See #6623.

changelog: new lint: [`string-slice`]
2021-10-26 08:11:49 +00:00
Devon Hollowood
d0c04b4d78 Clean up tests/ui/rename.rs 2021-10-26 00:53:53 -07:00
Andre Bogus
999b3004c4 new lint: string-slice 2021-10-26 09:05:28 +02:00
bors
cb0132d209 Auto merge of #7865 - Herschel:fix-match-str-case-mismatch, r=xFrednet
Fix `match_str_case_mismatch` on uncased chars

False positives would result because `char::is_lowercase` and friends will return `false` for non-alphabetic chars and alphabetic chars lacking case (such as CJK scripts). Care also has to be taken for handling titlecase characters (`Dz`) and lowercased chars with no uppercase equivalent (`ʁ`).

For example, when verifying lowercase:
 * Check `!any(char::is_ascii_uppercase)` instead of `all(char::is_ascii_lowercase)` for ASCII.
 * Check that `all(|c| c.to_lowercase() == c)` instead of `all(char::is_lowercase)` for non-ASCII

Fixes #7863.

changelog: Fix false positives in [`match_str_case_mismatch`] on uncased characters
2021-10-25 21:34:11 +00:00
bors
3ef1f19d60 Auto merge of #7873 - xFrednet:7869-string-index-ice, r=Manishearth
Update `str` utils to prevent ICEs and FNs

This PR reworks some string handling for lints regarding enum naming. I hope the refactoring will prevent future ICEs and help with new bug free implementations.

It might be better to review this PR by going through the commits, as `clippy_utils::camel_case` was renamed to `clippy_utils::str_utils` and then changed further. GH sadly doesn't really make the changes that obvious 🙃

Not too much more to say. Have a nice day 🌞

---

Fixes: rust-lang/rust-clippy#7869

changelog: ICE Fix: [`enum_variant_names`] #7869
2021-10-25 19:20:05 +00:00
xFrednet
1ad04f4054 Move non_send_fields_in_send_ty to suspicious
Also updated one configuration for nicer formatting
2021-10-25 19:32:17 +02:00
xFrednet
7517ae2fb3 Refactored some string handling to prevent ICEs and FNs 2021-10-24 22:47:39 +02:00
xFrednet
d38fddd899 Refactor camel_case util functions for new StrIndex 2021-10-24 21:13:43 +02:00
Cameron Steffen
20fb7f2916 Update rustfmt 2021-10-24 12:52:38 -05:00
xFrednet
1b91d986ea Rename clippy_utils::camal_case to clippy_utils::str_utils 2021-10-24 17:42:13 +02:00
Mike Welsh
e953dff536 Fix match_str_case_mismatch false positives
Properly consider uncased and titlecased characters.
Fixes #7863.
2021-10-23 02:03:15 -07:00
Yuki Okushi
efef16f6ed Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco
Don't mark for loop iter expression as desugared

We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at https://github.com/rust-lang/rust-clippy/pull/7789#issuecomment-939289501.
2021-10-22 19:42:45 +09:00
bors
df65291edd Auto merge of #7856 - Manishearth:impl-safety, r=xFrednet
missing_safety_doc: Handle 'implementation safety' headers as well

We hit some FPs on this in `yoke`, it's somewhat normal to mark trait impl safety with "implementation safety". We could also broaden the check for headers which contain the word "safety" somehow, or split out impl safety stuff to only apply to traits.

changelog: handle 'implementation safety' headers in `missing_safety_doc`
2021-10-21 21:51:24 +00:00
Manish Goregaokar
9def82d382 use a variable 2021-10-21 14:40:33 -07:00
bors
2ba1a6a331 Auto merge of #7801 - aDotInTheVoid:empty-format, r=camsteffen
Make useless_format recognize format!("")

Closes #7796

changelog: [`useless_format`] Fix for false negitive for `format!("")`
2021-10-21 18:15:23 +00:00
bors
c97a06d9af Auto merge of #7850 - ThibsG:PossibleCastTruncation5395, r=camsteffen
Fix FP: no lint when cast is coming from `signum` method call for `cast_possible_truncation` lint

Fixes a FP when cast is coming from `signum` method call

fixes: #5395

changelog: [`cast_possible_truncation`] Fix FP when cast is coming from `signum` method call
2021-10-21 18:01:39 +00:00
Nixon Enraght-Moony
081d0f82f4 Make useless_format recognize format!("")
Closes #7796
2021-10-21 19:01:28 +01:00
ThibsG
566244a8bc Do not lint when cast is coming from signum method call 2021-10-21 19:15:26 +02:00
Manish Goregaokar
1e8d9fb18c Handle 'implementation safety' headers as well 2021-10-21 08:50:50 -07:00
flip1995
7631fc5d82 Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup 2021-10-21 13:11:36 +02:00
flip1995
122233091a
Bump Clippy Version -> 0.1.58 2021-10-21 12:19:32 +02:00
flip1995
085181e29d
Merge remote-tracking branch 'upstream/master' into rustup 2021-10-21 12:18:12 +02:00
surechen
abb7ae9a79 Fix typo for INVALID_NULL_PTR_USAGE and MISSING_INLINE_IN_PUBLIC_ITEMS. 2021-10-21 14:33:43 +08:00
bors
300b821d51 Auto merge of #7838 - nhamovitz:trailing_zs_arr_wo_repr, r=Manishearth
Warn on structs with a trailing zero-sized array but no `repr` attribute

Closes #2868

changelog: Implement ``[`trailing_empty_array`]``, which warns if a struct is defined where the last field is a zero-sized array but there are no `repr` attributes. Zero-sized arrays aren't very useful in Rust itself, so such a struct is likely being created to pass to C code or in some other situation where control over memory layout matters. Either way, a `repr` attribute is needed.
2021-10-20 20:35:58 +00:00
bors
f11905af15 Auto merge of #7849 - ThibsG:SafetyDoc, r=llogiq
FIx FP in `missing_safety_doc` lint

Fix FP where lint souldn't fire if any parent has `#[doc(hidden)]` attribute

fixes: #7347

changelog: [`missing_safety_doc`] Fix FP if any parent has `#[doc(hidden)]` attribute
2021-10-20 16:46:38 +00:00
ThibsG
3630afb57f Do not lint if any parent has hidden attribute 2021-10-20 17:53:05 +02:00
Lukas Wirth
9cf68e40fe
Fix doc heading of TRANSMUTE_NUM_TO_BYTES 2021-10-20 13:46:12 +02:00
bors
06722c0c15 Auto merge of #7775 - F3real:no_effect, r=xFrednet
Detect underscored variables with no side effects

Fixes #7545

changelog: Lint on underscored variables with no side effects in [`no_effect`]
2021-10-20 09:33:45 +00:00
bors
ee8c155527 Auto merge of #7840 - dswij:question-mark-result, r=llogiq
Cover `Result` for `question_mark`

closes #7135

changelog: [`question_mark`] now covers `Result`
2021-10-20 07:27:13 +00:00
dswij
083a4546f6 Small refactor on question_mark condition checks 2021-10-20 13:41:44 +08:00
Michael Wright
1ede540b21 Fix false positive in match_overlapping_arm
The bug was dues to the constant bytes being compared instead of their
values. This meant that negative values were being treated as larger
than some positive values.

Fixes #7829
2021-10-20 06:13:42 +02:00
Michael Wright
4679eb3a0d Move const int value code to utils 2021-10-20 06:13:42 +02:00
F3real
6b22bba902 Lint on underscore variable assignment
Fix tests after no_effect update

Add a drop testcase

Don't lint _ variables in macro expansion

Address review comments and update tests

Don't shadow unnecessary operation lint if no_effect is allowed

Revert shadowing change and remove no_effect allows

Update clippy_lints/src/no_effect.rs

Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Update clippy_lints/src/no_effect.rs

Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Address review comments
2021-10-20 00:39:28 +02:00
Nathaniel Hamovitz
0f9f591e30 Rename lint 2021-10-19 14:33:43 -07:00
bors
c1e7a07c9c Auto merge of #7811 - rust-lang:eq-op-testless, r=xFrednet
avoid `eq_op` in test code

Add a check to `eq_op` that will avoid linting in functions annotated with `#[test]`

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: avoid `eq_op` in test functions
2021-10-19 19:54:40 +00:00
Andre Bogus
e88c956e1e avoid eq_op in test code 2021-10-19 21:02:30 +02:00
dswij
687f3925da Cover Result for question_mark 2021-10-19 18:50:49 +08:00
Nathaniel Hamovitz
5283d24b38 formatting 🙃 2021-10-18 18:42:01 -07:00
Nathaniel Hamovitz
4c8e816972 Use real type in doc examples 2021-10-18 18:32:00 -07:00
Nathaniel Hamovitz
02b1f266d6 Remove explicit lifetime 2021-10-18 18:20:35 -07:00
Nathaniel Hamovitz
bc32be0fec Remove comment 2021-10-18 18:03:00 -07:00
Nathaniel Hamovitz
c654cc56da One more test + final tidying 2021-10-18 17:41:27 -07:00
Nathaniel Hamovitz
6303d2d075 Revert "!: this is the commit that demonstrates the ICE"
This reverts commit d85f903c91.
2021-10-18 17:18:07 -07:00
Nathaniel Hamovitz
d85f903c91 !: this is the commit that demonstrates the ICE 2021-10-18 17:07:51 -07:00
Nathaniel Hamovitz
48cf9c284a Don't need rustc_attr anymore 2021-10-18 16:53:17 -07:00
Nathaniel Hamovitz
18c863dd0e Improve help message 2021-10-18 16:53:05 -07:00
Nathaniel Hamovitz
d8bacf078a All five has_repr_attr agree + are correct 2021-10-18 15:33:11 -07:00
Nathaniel Hamovitz
3a41f226c5 Exploring emitting other sorts of spans 2021-10-18 07:02:00 -07:00
Nathaniel Hamovitz
a54dbf6445 Improve doc and span messages 2021-10-18 03:52:57 -07:00
Nathaniel Hamovitz
7f84e3d791 Rename lint 2021-10-18 03:45:08 -07:00
Nathaniel Hamovitz
149b372873 run rustfmt 2021-10-18 03:16:10 -07:00
Nathaniel Hamovitz
6377fb2fe7 Tidy import + update expected stderr 2021-10-18 03:13:48 -07:00
Nathaniel Hamovitz
cd6862283e Tidy imports 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
9f402b370c Check for tuple structs 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
2a5a4f07cf Refactor ZS array detection again and this one seems great 👍 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
c5d3167a23 update testsuite and expand if_chain 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
a3420f7004 Tidy comments + tests; revert 'size-is-zero' detection 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
9b3f55ee61 tried to simplify but it doesn't work :/ 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
5fdf93415b intermediate step 2021-10-18 03:05:19 -07:00
Nathaniel Hamovitz
003972f428 add multiple get_attrs and includes_repr and they all work! 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
b9948c4be6 Ran dev bless! 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
4b4db59772 output looks fantastic 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
e53a4da4a1 it works i think (incl some dbgs) 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
523b013161 Implement getting an array of attributes! 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
7ee8e7a9b8 Implement detecting trailing zero-sized array 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
92d3b775bd ayy it compiles! ship it, right? 😎 /s
why was `rustc_lint_defs` not already externed in `lib.rs`?
and how was r-a able to find it but cargo wasn't? 🤔
2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
c69387a0d5 Well it builds 2021-10-18 03:05:18 -07:00
Nathaniel Hamovitz
797507c583 Add boilerplate and basic tests 2021-10-18 03:05:18 -07:00
Michael Wright
63d715209e Remove unneeded allow 2021-10-18 08:46:11 +02:00
Matthias Krüger
79b73ac98d Rollup merge of #89963 - r00ster91:parenthesisparentheses, r=nagisa
Some "parenthesis" and "parentheses" fixes

"Parenthesis" is the singular (e.g. one `(` or one `)`) and "parentheses" is the plural (multiple `(` or `)`s) and this is not hard to mix up so here are some fixes for that.

Inspired by #89958
2021-10-17 18:18:59 +02:00
Paul Gey
a550133b8f Fix false positive of implicit_saturating_sub with else clause
Fixes #7831
2021-10-17 15:56:59 +02:00
r00ster91
599d9126a2 Some "parenthesis" and "parentheses" fixes 2021-10-17 12:04:01 +02:00
Matthias Kaak
25ff7ce128 Fixed naive doc formatting for #[must_use] lints 2021-10-16 15:26:47 +00:00
bors
e1871ba0da Auto merge of #7743 - smoelius:master, r=camsteffen
Add `format_in_format_args` and `to_string_in_format_args` lints

Fixes #7667 and #7729

I put these in `perf` since that was one of `@jplatte's` suggestions, and `redundant_clone` (which I consider to be similar) lives there as well.

However, I am open to changing the category or anything else.

r? `@camsteffen`

changelog: Add `format_in_format_args` and `to_string_in_format_args` lints
2021-10-15 17:05:13 +00:00
Samuel E. Moelius III
75e9f8cbd6 Remove redundant to_strings 2021-10-15 12:44:49 -04:00
Samuel E. Moelius III
c9599d79a3 Add format_in_format_args and to_string_in_format_args lints
Fixes #7667 and #7729
2021-10-15 12:44:38 -04:00
Cameron Steffen
449d68d47c Fix clippy with for loop span change 2021-10-15 08:04:51 -05:00
dswij
ec5071931e unnecessary_sort_by only warns if argument impl Ord trait 2021-10-15 18:10:55 +08:00
Cameron Steffen
0a23fff82d Fix clippy with changed macro statement spans 2021-10-15 02:36:58 -05:00
bors
4996e17b14 Auto merge of #7815 - nhamovitz:patch-1, r=giraffate
Fix typo in example for `match_result_ok`

changelog: Fix typo in example for ``[`match_result_ok`]``
2021-10-13 23:44:42 +00:00
bors
b9b11a96d2 Auto merge of #7805 - aDotInTheVoid:transmute-num-bits, r=camsteffen
Add lint transmute_num_to_bytes

Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
2021-10-13 19:40:33 +00:00
nhamovitz
09aa4ad6dc
Fix typo in example for match_result_ok 2021-10-13 12:12:46 -07:00
Nixon Enraght-Moony
58969807ab Add lint transmute_num_to_bytes
Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
2021-10-13 20:05:05 +01:00
bors
57dc0343bd Auto merge of #7788 - flip1995:eq_if_let_sugg, r=giraffate
Do not expand macros in equatable_if_let suggestion

Fixes #7781

Let's use Hacktoberfest as a motivation to start contributing PRs myself again :)

changelog: [`equatable_if_let`]: No longer expands macros in the suggestion
2021-10-13 12:04:57 +00:00
bors
3d9c4a655b Auto merge of #7682 - Qwaz:uninit_vec, r=xFrednet
Implement uninit_vec lint

changelog: add the new lint [`uninit_vec`]

Fix #7681
2021-10-12 21:04:13 +00:00
Yechan Bae
4ed3a4fe2f Update lint description for new() and default() 2021-10-12 16:02:13 -04:00
bors
d3905af454 Auto merge of #7806 - Serial-ATA:lint-match-case-mismatch, r=llogiq
Add match_str_case_mismatch lint

changelog: Added a new lint [`match_str_case_mismatch`]

Fixes #7440
2021-10-12 18:39:09 +00:00
Serial
0c99de0ab2 Add a suggestion 2021-10-12 07:13:19 -04:00
Lukas Wirth
5adf17cb43
Bring manual_split_once docs in line with other lint docs 2021-10-12 09:42:42 +02:00
Serial
99bfee7201 Don't run examples 2021-10-11 20:40:13 -04:00
Serial
9e0ce14700 Add match_str_case_mismatch lint 2021-10-11 20:19:34 -04:00
bors
77dda9c6b1 Auto merge of #7791 - JamesHinshelwood:reason-in-disallowed-type, r=giraffate
Allow giving reasons for `disallowed_types`

Similar to #7609 but for the `disallowed_type` lint. The permitted form of configuration is the same as for `disallowed_methods`.

changelog: Allow giving reasons for [`disallowed_type`]
2021-10-12 00:17:37 +00:00
flip1995
f44a904a56 Deprecate mem_discriminant_non_enum
This lint has been uplifted and is now included in
enum_intrinsics_non_enums.
2021-10-11 10:10:16 +02:00
James Hinshelwood
886cbb1882
Rename disallowed to conf_disallowed
Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
2021-10-11 08:29:56 +01:00
James Hinshelwood
857a4073b8
Add reason config example for disallowed_type
Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
2021-10-11 08:29:41 +01:00
bors
bc9ad848eb Auto merge of #7795 - ThibsG:MutMut6922, r=giraffate
Fix FP in external macros for `mut_mut` lint

Fix FP in `mut_mut` lint when type is defined in external macros.

fixes: #6922

changelog: [`mut_mut`] Fix FP when type is defined in external macros
2021-10-11 01:14:53 +00:00
bors
9205e3d800 Auto merge of #7800 - 1nF0rmed:no-lint-in-match-single-amp, r=llogiq
Refactor `clippy::match_ref_pats` to check for multiple reference patterns

fixes #7740

When there is only one pattern, to begin with, i.e. a single deref(`&`), then in such cases we suppress `clippy::match_ref_pats`.
This is done by checking the count of the reference pattern and emitting `clippy::match_ref_pats` when more than one pattern is present.

Removed certain errors in the `stderr` tests as they would not be triggered.

changelog: Refactor `clippy::match_ref_pats` to check for multiple reference patterns
2021-10-10 11:13:05 +00:00
1nF0rmed
fc32425521 Refactor to check for multiple reference patterns 2021-10-09 22:30:12 +05:30
ThibsG
1e18b8a269 Fix FP in external macros for mut_mut lint 2021-10-09 15:54:16 +02:00
ThibsG
7aaed02b8c Fix false positive when Drop and Copy involved 2021-10-09 14:56:33 +02:00
Yechan Bae
03fed75c89 Address internal lints 2021-10-09 05:59:53 -04:00
Yechan Bae
2181387c3a Improved error message for set_len() on empty Vec 2021-10-09 05:47:07 -04:00
Yechan Bae
b1aa3064b6 Address PR comments 2021-10-09 05:47:06 -04:00
Yechan Bae
dd9c8d32f2 Extract get_vec_init_kind and share it 2021-10-09 05:43:58 -04:00
Yechan Bae
fec20bf617 Add #allow attribute to suppress FP #7698 2021-10-09 05:38:19 -04:00
Yechan Bae
fdc06d9b2b Improve error messages 2021-10-09 05:38:19 -04:00
Yechan Bae
759200b699 Handle PR feedbacks first round 2021-10-09 05:38:19 -04:00
Yechan Bae
b8ba7269cd Fix clippy lints 2021-10-09 05:38:19 -04:00
Yechan Bae
452181c69d Implement uninit_vec lint 2021-10-09 05:38:19 -04:00
James Hinshelwood
72078faf91
Allow giving reasons for disallowed_types
Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
2021-10-08 20:47:52 +01:00
flip1995
b423b85ca9
Don't trigger semicolon_if_nothing_returned in expanded code
Before this lint didn't trigger on macros. With rust-lang/rust#88175
this isn't enough anymore. In this PR a `WhileLoop` desugaring kind was
introduced. This overrides the span of expanded expressions when
lowering the while loop. So if a while loop is in a macro, the
expressions that it expands to are no longer marked with
`ExpnKind::Macro`, but with `ExpnKind::Desugaring`. In general, this is
the correct behavior and the same that is done for `ForLoop`s. It just
tripped up this lint.
2021-10-08 16:16:56 +02:00
flip1995
28fb591b6e
Do not expand macros in equatable_if_let suggestion 2021-10-08 15:26:10 +02:00
Serial
412b862fba Add undocumented_unsafe_blocks lint 2021-10-07 17:06:21 -04:00
bors
8aff5dd570 Auto merge of #7705 - michaelsproul:fn_to_numeric_cast_any, r=camsteffen
Restriction lint for function pointer casts

The existing lints for function pointer casts cover the cases where a cast is non-portable or would result in truncation, however there's currently no way to forbid numeric function pointer casts entirely.

I've added a new lint `fn_to_numeric_cast_any`, which allows one to ban _all_ numeric function pointer casts, including to `usize`. This is useful if you're writing high-level Rust and want to opt-out of potentially surprising behaviour, avoiding silent bugs from forgotten parentheses, e.g.

```rust
fn foo() -> u32 {
    10
}

fn main() {
    let _ = foo as usize; // oops, forgot to call foo and got a random address instead!
}
```

~~I'm open to suggestions for the naming of the lint, because `fn_to_numeric_cast_any` is a bit clunky. Ideally I'd call this lint `fn_to_numeric_cast`, but that name is already taken for the more specific lint~~. We've stuck with `fn_to_numeric_cast_any` to avoid renaming the existing lint, or choosing a different name that's too generic (like `fn_cast`).

I'm also open to changing the suggestion behaviour, as adding parentheses is only one of many possible ways to fix the lint.

changelog: add ``[`fn_to_numeric_cast_any`]`` restriction lint
2021-10-07 14:14:19 +00:00
Michael Sproul
fbd0fb9aed Restriction lint for function pointer casts 2021-10-07 09:11:47 -05:00
bors
872f3213f2 Auto merge of #7782 - dswij:shadow-unrelated-block, r=flip1995
Make `shadow_reuse` suggestion less verbose

Closes #7764

Make `shadow_reuse` suggestion less verbose.

changelog: [`shadow_reuse`] does not warn shadowing statement
2021-10-07 09:49:19 +00:00
flip1995
5cf4984872 Merge commit 'b7f3f7f6082679da2da9a0b3faf1b5adef3afd3b' into clippyup 2021-10-07 11:21:30 +02:00
flip1995
1f955158dd
Merge remote-tracking branch 'upstream/master' into rustup 2021-10-07 11:11:23 +02:00
dswij
64f8b9d0ea Make shadow_reuse suggestion less verbose 2021-10-07 16:50:13 +08:00
Michael Wright
8f075ec961 Revert update_lints module list generating code
This commit reverts the module list generation code to what it was
before the change to `include!` it and generates better output.
2021-10-07 06:42:21 +02:00
Manish Goregaokar
2a8d7bd0dd Handle intra-doc links in doc_markdown 2021-10-06 08:38:35 -07:00
Manish Goregaokar
d9488c50ce Regen update_lints 2021-10-06 00:12:58 -07:00
Matthias Kaak
320ecb1f0b Mentioned inspect in lint description of suspicious_map 2021-10-05 19:40:15 +00:00
Matthias Kaak
7c82e78f30 improved help message for suspicious_map 2021-10-05 19:09:08 +00:00
hkalbasi
388a3d0983 Implement equatable if let lint 2021-10-04 22:16:42 +03:30
Takayuki Nakata
72f0180f7b Fix ICE in implicit_hasher 2021-10-04 23:31:40 +09:00
dswij
e6e6e7d211 Change unseparated_literal_suffix type to restriction 2021-10-04 11:02:17 +08:00
bors
63b04f7d7f Auto merge of #7755 - HKalbasi:master, r=xFrednet
exclude enum from derivable impls

fix #7753

changelog: Exclude enum from ``[`derivable_impls`]``
2021-10-03 10:30:16 +00:00
HKalbasi
0ebc656a9a
Change not enum to is struct 2021-10-03 13:01:57 +03:30
hkalbasi
ea8e65f0da exclude enum from derivable impls 2021-10-03 11:58:27 +03:30
Cameron Steffen
e165c12932 Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Yechan Bae
fb0353b28d Update documentation and name for non_send_fields_in_send_ty lint 2021-10-02 19:22:37 -04:00
Yechan Bae
dfed2e31d5 Do not use full type path in help message 2021-10-01 14:04:20 -04:00
Yechan Bae
4f01656a7d Add ui-test for enable-raw-pointer-heuristic-for-send config 2021-10-01 14:04:20 -04:00
Yechan Bae
08f0aecffd Minor changes from PR feedback 2021-10-01 14:04:20 -04:00
Yechan Bae
427a09ba7b Add configuration for raw pointer heuristic 2021-10-01 14:04:20 -04:00
Yechan Bae
d413e157a5 Look into tuple, array, ADT args in raw pointer heuristic 2021-10-01 14:04:20 -04:00
Yechan Bae
ee74574876 Emit one report for all fields in the same ADT 2021-10-01 14:04:20 -04:00
Yechan Bae
a81a5ad1a8 Update documentation 2021-10-01 14:04:20 -04:00
Yechan Bae
6458630e1a typo 2021-10-01 14:04:20 -04:00
Yechan Bae
d7a9ec2c50 Fix attribute handling 2021-10-01 14:04:20 -04:00
Yechan Bae
e4c3000e5b Initial implementation 2021-10-01 14:04:20 -04:00
bors
fe999e88ed Auto merge of #7741 - surechen:fix_if_then_panic, r=flip1995
Make if_then_panic handle situation of BinOpKind::And || BinOpKind::Or

fixes #7731

Make if_then_panic handle situation of cond.kind = ExprKind::DropTemps(ExprKind::Binary(BinOpKind::And || BinOpKind::Or, left, right), ..) =

changelog: [`if_then_panic`] Fix suggestion for more complex conditions
2021-10-01 10:04:19 +00:00
surechen
41e2c68a6e use sugg::Sugg::maybe_par 2021-10-01 13:13:09 +08:00
Cameron Steffen
8c0e4d5ccf Rewrite shadow lint 2021-09-30 14:07:58 -05:00
Cameron Steffen
99861c0e88 Remove initialization note from shadow lint 2021-09-30 13:54:30 -05:00
Cameron Steffen
89f77f3512 Move shadow_unrelated to restriction 2021-09-30 13:54:28 -05:00
Camille GILLOT
ea60b69ee1 Do not pass hir::Crate to lints. 2021-09-30 17:39:54 +02:00
bors
a893eb993b Auto merge of #7677 - surechen:edit_large_enum_variant, r=camsteffen
fix bug for large_enum_variants

Fix the discussion problem in the issue of https://github.com/rust-lang/rust-clippy/issues/7666#issuecomment-919654291

About the false positive problem of case:
```rust
enum LargeEnum6 {
    A,
    B([u8;255]),
    C([u8;200]),
}
```

changelog: Fix largest_enum_variant wrongly identifying the second largest variant.
2021-09-30 12:45:17 +00:00
surechen
4babfae9cb fix issue #7731
Make if_then_else handle situation of cond.kind = ExprKind::DropTemps(ExprKind::Binary(BinOpKind::And || BinOpKind::Or, left, right), ..) =
2021-09-30 19:06:42 +08:00
surechen
56f0c9afdd fix bug for large_enum_variants 2021-09-30 10:07:57 +08:00
Camille GILLOT
3037c40e9a Avoid more invocations of hir_crate query. 2021-09-29 23:16:47 +02:00
Michael Wright
e6747df5cd Fix lint register code format
Also change the generation functions to return `String` instead of
`Vec<String>`. This makes sense now as the updates aren't line oriented
anymore.
2021-09-29 05:46:39 +02:00
Michael Wright
50ea370619 Move code generated by update_lints to includes 2021-09-29 05:43:25 +02:00
vxpm
30ea0a5ebb
Fix typo ("asynx" corrected to "async") 2021-09-28 17:53:12 -03:00
bors
fb17671eb0 Auto merge of #7734 - Manishearth:doc-unsafe-trait, r=camsteffen
Make `doc_unsafe` warn on unsafe traits as well

Fixes #7732

changelog: Make [`doc_unsafe`] warn on unsafe traits as well
2021-09-28 17:09:34 +00:00
flip1995
23d5457e6d Merge commit 'cb7915b00c235e9b5861564f3be78dba330980ee' into clippyup 2021-09-28 18:03:12 +01:00
bors
cb7915b00c Auto merge of #7733 - flip1995:rustup, r=flip1995
Rustup

This needs a review this time. Especially 521bf8f0fa cc `@camsteffen` I think this is necessary now, because `itertools` is no longer a dependency of `clippy_utils` and therefore this path can't be found 🤔

( I forgot about the sync last week. I should get to document this process better, so other people can do it when I'm not around )

changelog: none
2021-09-28 16:42:31 +00:00
flip1995
c2b8882cef
Cleanup of rustup changes 2021-09-28 17:40:06 +01:00
flip1995
d8f453d021
Bump nightly version -> 2021-09-28 2021-09-28 17:39:16 +01:00
Manish Goregaokar
53c534d11b Update clippy_lints/src/doc.rs
Co-authored-by: Cameron Steffen <cam.steffen94@gmail.com>
2021-09-28 09:37:58 -07:00
flip1995
ec38746b4a
Allow internal lint INVALID_PATHS for itertools path
Since clippy_utils doesn't depend on the itertools crate anymore, the
lint can't find the path.
2021-09-28 17:07:51 +01:00
Manish Goregaokar
25850fc264 Make doc_unsafe lint on unsafe traits as well 2021-09-28 08:40:59 -07:00
flip1995
707494eca9
Merge remote-tracking branch 'upstream/master' into rustup 2021-09-28 10:52:31 +01:00
Manish Goregaokar
13834e6ad2 fmt 2021-09-27 22:33:45 -07:00
Manish Goregaokar
17155c8dca Add renamed lint 2021-09-27 22:26:14 -07:00
Manish Goregaokar
baec67e9de Use a single if_chain 2021-09-27 22:23:17 -07:00
Andrew Pollack
b7d40bc103 Adding new linting 2021-09-27 22:23:17 -07:00
bors
0c8799da5a Auto merge of #7664 - matthiaskrgr:bump_to_2021, r=flip1995
bump clippy crates to edition 2021

Also helps with dogfooding edition 2021 a bit. :)
Tests passed locally.

---

changelog: bump edition from 2018 to 2021
2021-09-27 09:14:10 +00:00
bors
f100159f8c Auto merge of #7692 - workingjubilee:float-cmp-not-wrong, r=giraffate
Demote float_cmp to pedantic

See this issue: https://github.com/rust-lang/rust-clippy/issues/7666

This is one of the most frequently suppressed lints. It is deny-by-default. It is not actually clearly wrong, as there are many instances where direct float comparison is actually desirable. It is only after operating on floats that they may lose precision, and that depends greatly on the operation. As most correctness lints have a much higher standard of error, being based on hard and fast binary logic, this should not be amongst them.

A linter is not a substitute for observing the math carefully and running tests, and doing the desirable thing is even more likely to lead one to want exact comparisons.

changelog: Demote [`float_cmp`] from correctness to pedantic lints
2021-09-27 09:00:31 +00:00
David Tolnay
e63d69244e
Stop suggesting a float truncation that is not shorter 2021-09-25 22:55:23 -07:00
Manish Goregaokar
067bfe3618 Rollup merge of #89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation

This makes the big O time complexity notation in places with markdown support more consistent.
Inspired by #89210
2021-09-25 18:22:20 -07:00
Matthias Krüger
d888b4b98c clippy lints: update doctest ranges to inclusive ones 2021-09-25 22:40:58 +02:00
Matthias Krüger
c3515c301d bump clippy crates to edition 2021 2021-09-25 22:40:58 +02:00
Jubilee
e0b68ae6c0 Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy

This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders.

Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet.

r? ``@nikomatsakis``
2021-09-24 11:40:11 -07:00
bors
fb61d04896 Auto merge of #7669 - Labelray:if_then_panic, r=giraffate
New lint `if_then_panic`

changelog: add the new lint [`if_then_panic`]
fix #7645
2021-09-24 14:43:51 +00:00
Labelray
543b638dbe Add new lint if_then_panic 2021-09-24 22:14:20 +08:00
r00ster91
7355376d5b consistent big O notation 2021-09-24 12:44:28 +02:00
F3real
7a4a556100 Avoid needless heap allocation in box_collection 2021-09-24 11:02:22 +02:00
bors
cd3f3cf8a8 Auto merge of #7707 - Jarcho:suspicious_else_proc_mac, r=Manishearth
Don't lint `suspicious_else_formatting` inside proc-macros

fixes: #7650

I'll add a test for this one soon.

changelog: Don't lint `suspicious_else_formatting` inside proc-macros
2021-09-23 16:14:29 +00:00
Jason Newcomb
5efd6bc6c3
Don't lint suspicious_else_formatting inside proc-macros 2021-09-23 01:13:21 -04:00
bors
ef2e2f0a0c Auto merge of #7693 - F3real:vec2, r=Manishearth
Expand box_vec lint to box_collection

fixed #7451

changelog: Expand `box_vec` into [`box_collection`], and have it error on all sorts of boxed collections
2021-09-22 22:13:13 +00:00
bors
a4a8ec2d52 Auto merge of #7679 - lengyijun:issue4546, r=xFrednet
add #4546 test

changelog: none
fixed #4546

I notice #4546 was fixed some time, I just add the tests.
2021-09-22 09:00:30 +00:00
lengyijun
b68325ecf6 add #4546 test 2021-09-22 16:04:04 +08:00
bors
8a75002930 Auto merge of #7685 - camsteffen:let-else-needless-ret, r=giraffate
Fix needless_return with let-else

changelog: Fix needless_return FP with `let...else`

Fixes #7637
2021-09-22 00:23:23 +00:00
Jubilee Young
3ad3c51cee Demote float_cmp to pedantic 2021-09-21 12:25:47 -07:00
F3real
7f96b358b0 Register lint rename 2021-09-20 23:07:17 +02:00
F3real
63ed2f9eb4 Expand BOX_VEC to BOX_COLLECTION 2021-09-20 10:23:55 +02:00
Camille GILLOT
44b8301c08 Do not store visibility in *ItemRef. 2021-09-20 00:29:53 +02:00
bors
871ad80bb0 Auto merge of #7690 - Jarcho:while_loop_by_ref, r=xFrednet
Change `while_let_on_iterator` suggestion to use `by_ref()`

It came up in the discussion #7659 that suggesting `iter.by_ref()` is a clearer suggestion than `&mut iter`. I personally think they're equivalent, but if `by_ref()` is clearer to people then that should be the suggestion.

changelog: Change `while_let_on_iterator` suggestion when using `&mut` to use `by_ref()`
2021-09-19 17:37:04 +00:00
Cameron Steffen
b36591217d Fix needless_return with let-else 2021-09-18 09:42:51 -05:00
Jason Newcomb
ee6a6b55c4
Change the suggestion for while_let_on_iterator when the iterator cannot be consumed to iter.by_ref() 2021-09-17 21:44:21 -04:00
bors
59cd77710d Auto merge of #7657 - dswij:needless-borrow-mut, r=llogiq
`needless_borrow` checks for mutable borrow

closes #7635

changelog: [`needless_borrow`] now checks for needless mutable borrow
2021-09-17 22:25:07 +00:00
bors
ed7a82ef05 Auto merge of #7653 - lengyijun:same_name_method_crate, r=llogiq
New lint: `same_name_method`

changelog: ``[`same_name_method`]``
fix: https://github.com/rust-lang/rust-clippy/issues/7632

It only compares a method in `impl` with another in `impl trait for`
It doesn't lint two methods in two traits.

I'm not sure my approach is the best way. I meet difficulty in other approaches.
2021-09-17 22:02:04 +00:00
jackh726
2a9a9ca829 Fix clippy 2021-09-16 00:12:56 -04:00
David Tolnay
c2783c1dcb
Downgrade many_single_char_names to pedantic 2021-09-14 09:59:06 -07:00
Kneasle
b2ffb28da5 Fix FN for collections/smart ptrs in std 2021-09-14 16:51:09 +01:00
lengyijun
e2cdaec984 same_name_method 2021-09-14 09:20:27 +08:00
Kneasle
e0090735f1 Fix FP when using raw pointers as hashed keys 2021-09-13 11:08:50 +01:00
dswij
46c3076784 Fix needless_borrow not linting mutable reference 2021-09-13 12:29:24 +08:00
bors
1add837c91 Auto merge of #88517 - smoelius:without-patch-versions, r=flip1995
Update Clippy dependencies without patch versions

Trial run for https://github.com/rust-lang/rust-clippy/pull/7606
2021-09-13 02:45:18 +00:00
bors
a64b7698a4 Auto merge of #7661 - camsteffen:eta, r=giraffate
Fix various redundant_closure bugs

changelog: Fix various false negatives and false positives for [`redundant_closure`]

Closes #3071
Closes #4002

This lint is full of weird nuances and this is basically a re-write to tighten up the logic.
2021-09-13 00:39:34 +00:00
bors
e6455ea72c Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
Encode spans relative to the enclosing item

The aim of this PR is to avoid recomputing queries when code is moved without modification.

MCP at https://github.com/rust-lang/compiler-team/issues/443

This is achieved by :
1. storing the HIR owner LocalDefId information inside the span;
2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache;
3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation.

Since all client code uses `Span`, step 3 ensures that all manipulations
of span byte positions actually create the dependency edge between
the caller and the `source_span(LocalDefId)`.
This query return the actual absolute span of the parent item.
As a consequence, any source code motion that changes the absolute byte position of a node will either:
- modify the distance to the parent's beginning, so change the relative span's hash;
- dirty `source_span`, and trigger the incremental recomputation of all code that
  depends on the span's absolute byte position.

With this scheme, I believe the dependency tracking to be accurate.

For the moment, the spans are marked during lowering.
I'd rather do this during def-collection,
but the AST MutVisitor is not practical enough just yet.
The only difference is that we attach macro-expanded spans
to their expansion point instead of the macro itself.
2021-09-11 23:35:28 +00:00
Camille GILLOT
ce1da849b0 Rebase fallout. 2021-09-11 17:52:39 +02:00
bors
2636a1b7b5 Auto merge of #7663 - Jarcho:rsplit_once_order, r=llogiq
Fix result order for `manual_split_once` when `rsplitn` is used

fixes: #7656

changelog: Fix result order for `manual_split_once` when `rsplitn` is used
2021-09-11 08:29:52 +00:00
bors
eac0b26015 Auto merge of #88214 - notriddle:notriddle/for-loop-span-drop-temps-mut, r=nagisa
rustc: use more correct span data in for loop desugaring

Fixes #82462

Before:

      help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
         |
      LL |     for x in DroppingSlice(&*v).iter(); {
         |                                       +

After:

      help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
         |
      LL |     };
         |      +

This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
2021-09-11 07:11:01 +00:00
Camille GILLOT
11e2966f3f Keep a parent LocalDefId in SpanData. 2021-09-10 20:17:33 +02:00
Jason Newcomb
4c1b6a28e4
Fix result order for manual_split_once when rsplitn is used 2021-09-10 13:05:09 -04:00
hamidreza kalbasi
5aff720e1a fix derivable impl false positives 2021-09-10 19:49:02 +04:30
Cameron Steffen
ae2a95fadc Eat dogfood 2021-09-09 17:10:59 -05:00
Cameron Steffen
5782dc0eb9 Fix redundant closure bugs 2021-09-09 17:10:59 -05:00
Fabian Wolff
81ce2fb167 Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
Samuel E. Moelius III
43ed2065cc Update dependencies 2021-09-09 07:47:16 -04:00
Samuel E. Moelius III
ccc087ed62 Prep for upgrade to cargo_metadata 0.14.0 2021-09-09 04:59:06 -04:00
bors
1a524783b1 Auto merge of #7610 - Labelray:master, r=camsteffen
Add new lint `iter_not_returning_iterator`

Add new lint [`iter_not_returning_iterator`] to detect method `iter()` or `iter_mut()` returning a type not implementing `Iterator`
changelog: Add new lint [`iter_not_returning_iterator`]
2021-09-09 01:47:08 +00:00
Labelray
8f88acdbfa add new lint iter_not_returning_iterator 2021-09-09 09:21:38 +08:00
Ariel Davis
293db0d33c Allow giving reasons for disallowed_methods 2021-09-08 21:12:02 -04:00
bors
261e34d534 Auto merge of #88615 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`
2021-09-08 23:52:31 +00:00
flip1995
091ed44b50 Merge commit '27afd6ade4bb1123a8bf82001629b69d23d62aff' into clippyup 2021-09-08 16:31:47 +02:00
bors
5458358461 Auto merge of #7644 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2021-09-08 09:00:54 +00:00
flip1995
563a00b2a0
Bump Clippy Version -> 0.1.57 2021-09-08 10:59:04 +02:00
flip1995
4962608ca6
Merge remote-tracking branch 'upstream/master' into rustup 2021-09-08 10:51:27 +02:00
dswij
dc6f7dc6bf Add known problems to mut_range_bound docs 2021-09-08 11:00:27 +08:00
dswij
8fbf75e0f9 mut_range_bound to check for immediate break from loop 2021-09-08 10:41:37 +08:00
Camille GILLOT
06ae9e43d0 Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
bors
b7c25e1679 Auto merge of #7642 - mikerite:fix-7641, r=flip1995
Add `TAU` to `approx_constant`

changelog: [`approx_constant`]: Add `TAU`
2021-09-07 08:16:36 +00:00
Michael Howell
48268f5237 fix(clippy): update loop lints to use arg.span
Adapts clippy for fe1a7f71fbf3cf845a09a9b333a6adcf7e839607
2021-09-06 23:30:04 -07:00
Michael Wright
a7a5a5d9b0 Add TAU to approx_constant 2021-09-07 05:50:04 +02:00
bors
17294b8161 Auto merge of #7634 - chansuke:update-eval-order-depends-docs, r=Manishearth
Fix documentation of eval_order_dependence

Fixes #7624.

changelog: fix documentation of eval_order_dependence
2021-09-06 07:51:55 +00:00
bors
7a0d7d8283 Auto merge of #7596 - lengyijun:option_needless_deref, r=llogiq
New lint: option_needless_deref

changelog: [`option_needless_deref`]
fix #7571
2021-09-05 18:11:56 +00:00
bors
051286d7ec Auto merge of #7638 - xFrednet:7569-avoid-indexing-in-clippy, r=Manishearth
Avoid slice indexing in Clippy (down with the ICEs)

While working on #7569 I got about 23 lint reports where we can avoid slice indexing by destructing the slice early. This is a preparation PR to avoid fixing them in the lint PR. (The implementation already takes about 300 lines without tests 😅). Either way, this should hopefully be easy to review 🙃

---

changelog: none
2021-09-05 17:01:50 +00:00
bors
ad8610d11c Auto merge of #88499 - eddyb:layout-off, r=nagisa
Provide `layout_of` automatically (given tcx + param_env + error handling).

After #88337, there's no longer any uses of `LayoutOf` within `rustc_target` itself, so I realized I could move the trait to `rustc_middle::ty::layout` and redesign it a bit.

This is similar to #88338 (and supersedes it), but at no ergonomic loss, since there's no funky `C: LayoutOf<Ty = Ty>` -> `Ty: TyAbiInterface<C>` generic `impl` chain, and each `LayoutOf` still corresponds to one `impl` (of `LayoutOfHelpers`) for the specific context.

After this PR, this is what's needed to get `trait LayoutOf` (with the `layout_of` method) implemented on some context type:
* `TyCtxt`, via `HasTyCtxt`
* `ParamEnv`, via `HasParamEnv`
* a way to transform `LayoutError`s into the desired error type
  * an error type of `!` can be paired with having `cx.layout_of(...)` return `TyAndLayout` *without* `Result<...>` around it, such as used by codegen
  * this is done through a new `LayoutOfHelpers` trait (and so is specifying the type of `cx.layout_of(...)`)

When going through this path (and not bypassing it with a manual `impl` of `LayoutOf`), the end result is that only the error case can be customized, the query itself and the success paths are guaranteed to be uniform.

(**EDIT**: just noticed that because of the supertrait relationship, you cannot actually implement `LayoutOf` yourself, the blanket `impl` fully covers all possible context types that could ever implement it)

Part of the motivation for this shape of API is that I've been working on querifying `FnAbi::of_*`, and what I want/need to introduce for that looks a lot like the setup in this PR - in particular, it's harder to express the `FnAbi` methods in `rustc_target`, since they're much more tied to `rustc` concepts.

r? `@nagisa` cc `@oli-obk` `@bjorn3`
2021-09-05 16:14:41 +00:00
bors
e5ae3f5491 Auto merge of #7629 - mikerite:fix-7623-2, r=xFrednet
Make `approx_const` MSRV aware

changelog: [`approx_const`]: Add MRSV checks for LOG10_2 and LOG2_10.

Fixes #7623
2021-09-05 13:17:02 +00:00
xFrednet
62b46125cb Avoid slice indexing in Clippy (down with the ICEs) 2021-09-05 14:50:13 +02:00
Michael Wright
19d8a3e53c Improve approx_constant output 2021-09-05 08:47:45 +02:00
Michael Wright
4ee9ec960e Add MSRV to approx_constant documentation 2021-09-05 08:44:37 +02:00
lyj
37af742bbb
Update clippy_lints/src/needless_option_as_deref.rs
Co-authored-by: llogiq <bogusandre@gmail.com>
2021-09-05 08:33:04 +08:00
bors
a8c269ad50 Auto merge of #7570 - HKalbasi:derivable-impls, r=camsteffen
Add the `derivable_impls` lint

Fix #7550

changelog: Add new derivable_impls lint. mem_replace_with_default now covers non constructor cases.
2021-09-04 21:40:04 +00:00
hamidreza kalbasi
8221f9e795 add derivable impls lint 2021-09-05 01:25:59 +04:30
lengyijun
4184cc369a needless_option_as_deref 2021-09-04 22:18:23 +08:00
chansuke
b2f01ef6f6 Fix documentation of eval_order_dependence 2021-09-04 21:07:25 +09:00
Michael Wright
a23af89447 Make approx_const MSRV aware
Fixes #7623.
2021-09-03 08:34:34 +02:00