Commit graph

6585 commits

Author SHA1 Message Date
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 fe1a7f71fb
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
Michael Wright
265b8ec622 Reorder approx_consts constant to match rust docs 2021-09-03 06:41:30 +02:00
Jake Goulding
b4775435e8 Adjust the output of unnecessary_unwrap and provide a suggestion 2021-09-02 20:52:16 -04:00
Jake Goulding
03d3131cb4 Extend unnecessary_unwrap to look for expect in addition to unwrap
Closes #7581
2021-09-02 20:44:39 -04:00
bors
a0152da5ae Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebank
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix.

This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting).

The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output.

In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix.

This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642.

Fixes https://github.com/rust-lang/rust/issues/87745.

cc `@cbeuw`
r? `@ghost`
2021-09-03 00:23:10 +00:00
flip1995
01b17af108
Fix fallout from re-applying patches 2021-09-02 13:04:47 +01:00
xFrednet
8bf2940abb
Fix matadata collection configuration formatting 2021-09-02 12:42:00 +01:00
Cameron Steffen
c2bb313e7a
Add higher docs and remove some unneeded fields 2021-09-02 12:41:30 +01:00
Cameron Steffen
588367b62e
Fix dogfood 2021-09-02 12:39:54 +01:00
Cameron Steffen
5722a7dacd
Fix manual_match with let-expressions 2021-09-02 12:38:59 +01:00
flip1995
61bb96738c
Merge remote-tracking branch 'upstream/master' into rustup2 2021-09-02 12:38:17 +01:00
Eduard-Mihai Burtescu
8f7c249980 rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
xordi
83f1454ade Fix function and variable names 2021-08-31 09:06:14 +02:00
xordi
aee4f1fc0c Fix CI errors 2021-08-31 08:56:53 +02:00
xordi
f75d1b2bc5 Check for Not trait implementation 2021-08-31 08:56:53 +02:00
Cameron Steffen
78bf4acc3a Fix clippy for let-else 2021-08-30 20:18:41 -05:00
bors
fd30241281 Auto merge of #7573 - Jarcho:option_if_let_else, r=giraffate
Fix `option_if_let_else`

fixes: #5822
fixes: #6737
fixes: #7567

The inference from #6137 still exists so I'm not sure if this should be moved from the nursery. Before doing that though I'd almost want to see this split into two lints. One suggesting `map_or` and the other suggesting `map_or_else`.

`map_or_else` tends to have longer expressions for both branches so it doesn't end up much shorter than a match expression in practice. It also seems most people find it harder to read. `map_or` at least has the terseness benefit of being on one line most of the time, especially when the `None` branch is just a literal or path expression.

changelog: `break` and `continue` statments local to the would-be closure are allowed in `option_if_let_else`
changelog: don't lint in const contexts  in `option_if_let_else`
changelog: don't lint when yield expressions are used  in `option_if_let_else`
changelog: don't lint when the captures made by the would-be closure conflict with the other branch  in `option_if_let_else`
changelog: don't lint when a field of a local is used when the type could be pontentially moved from  in `option_if_let_else`
changelog: in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure  in `option_if_let_else`
2021-08-30 13:57:21 +00:00
inquisitivecrystal
c8262ade90 Teach tools that macros are now HIR items 2021-08-28 00:24:39 -07:00
inquisitivecrystal
8c4056fd4a Treat macros as HIR items 2021-08-28 00:16:34 -07:00
Michael Woerister
c6c1f328eb Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. 2021-08-27 11:50:44 +02:00
Jason Newcomb
3e5dcba2ee
Small cleanup of option_if_let_else and additional tests. 2021-08-26 11:44:36 -04:00
flip1995
c6e420266a
Set applicability of needless_collect to MaybeIncorrect 2021-08-26 10:01:11 +01:00
lcnr
afd892a549 update TypeFlags to deal with missing ct substs 2021-08-26 11:00:30 +02:00
lcnr
b1786f62ed add tcx to fn walk 2021-08-26 11:00:30 +02:00
lcnr
19d1fe21c7 make unevaluated const substs optional 2021-08-26 11:00:30 +02:00
lcnr
4d627fc41b require a tcx for TypeVisitor 2021-08-26 10:54:01 +02:00
bors
de80188c64 Auto merge of #7543 - DevinR528:disallowed-mod, r=Manishearth
Add module_style lint to style

changelog: Add new [`module_style`] style lint

This is a configurable (no mod file/mod file) lint that determines if `mod.rs` is used consistently or if `mod.rs` is never used (using the new mod layout).
2021-08-25 15:20:28 +00:00
bors
305177342f Auto merge of #7453 - F3real:assume_function_calls_have_side_effect, r=flip1995
Don't report function calls as unnecessary operation if used in array index

Attempts to fix: #7412

changelog: Don't report function calls used in indexing as unnecessary operation. [`unnecessary_operation`]
2021-08-25 08:31:20 +00:00
Devin Ragotzy
31738b1da3 Add module_style lint to restriction
Add tests for disallowed_mod in ui-cargo test section

Use correct algorithm to determine if mod.rs is missing

Move to two lints and remove config option

Switch lint names so they read "warn on ..."

Emit the same help info for self_named_mod_file warnings

Bail when both lints are Allow

Reword help message for both module_style lints
2021-08-24 15:53:58 -04:00
bors
87c6f32756 Auto merge of #7592 - lengyijun:redundant_allocation, r=camsteffen
redundant_allocation: fix 7487

Fixes #7487

changelog: [`redundant_allocation`] - allow `Box<Box<dyn T>>` which replaces wide pointers with thin pointers
2021-08-24 12:32:01 +00:00
lengyijun
641be558fc redundant_allocation: fix 7487 2021-08-24 13:03:48 +08:00
Mara Bos
4c847c0dbd Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00
Cameron Steffen
2f73776525 Move branches_sharing_code to nursery 2021-08-23 13:40:04 -05:00
bors
22606e7358 Auto merge of #7539 - Labelray:master, r=camsteffen
Add new lint `negative_feature_names` and `redundant_feature_names`

Add new lint [`negative_feature_names`] to detect feature names with prefixes `no-` or `not-` and new lint [`redundant_feature_names`] to detect feature names with prefixes `use-`, `with-` or suffix `-support`
changelog: Add new lint [`negative_feature_names`] and [`redundant_feature_names`]
2021-08-23 13:56:18 +00:00
Labelray
0a021d5900 Add new lints negative_feature_names and redundant_feature_names 2021-08-23 21:05:44 +08:00
Guillaume Gomez
5868e28537 Rollup merge of #88211 - petrochenkov:withhilo, r=jyn514
cleanup: `Span::new` -> `Span::with_lo`

Extracted from https://github.com/rust-lang/rust/pull/84373 as suggested in https://github.com/rust-lang/rust/pull/84373#issuecomment-857773867.
It turned out less useful then I expected, but anyway.
r? `@cjgillot`
`@bors` rollup
2021-08-22 20:52:54 +02:00
Frank Steffahn
8b6529e048 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Frank Steffahn
21da42ce29 Fix more “a”/“an” typos 2021-08-22 17:27:18 +02:00
Frank Steffahn
c86071898f Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
Vadim Petrochenkov
cd4bf7fb8e cleanup: Span::new -> Span::with_lo 2021-08-21 18:07:21 +03:00
Cameron Steffen
ae02282ad0 Fix clippy let expressions fallout 2021-08-19 14:17:05 -05:00
Marcel Hellwig
4123fedac5 remove box_syntax uses from cranelift and tools 2021-08-18 09:31:51 +02:00
bors
1fc1aee7be Auto merge of #7565 - Jarcho:manual_split_once, r=llogiq
New lint `manual_split_once`

This is a WIP because it still needs to recognize more patterns. Currently handles:

```rust
s.splitn(2, ' ').next();
s.splitn(2, ' ').nth(0)
s.splitn(2, ' ').nth(1);
s.splitn(2, ' ').skip(0).next();
s.splitn(2, ' ').skip(1).next();
s.splitn(2, ' ').next_tuple(); // from itertools

// as well as `unwrap()` and `?` forms
```

Still to do:

```rust
let mut iter = s.splitn(2, ' ');
(iter.next().unwrap(), iter.next()?)

let mut iter = s.splitn(2, ' ');
let key = iter.next().unwrap();
let value = iter.next()?;
```

Suggestions on other patterns to check for would be useful. I've done a search on github for uses of `splitn`. Still have yet to actually look through the results.

There's also the question of whether the lint shouold trigger on all uses of `splitn` with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be.

changelog: Add lint `manual_split_once`
2021-08-17 21:15:48 +00:00
xFrednet
c01aa64591 Small documentation update for the new metadata_collector 2021-08-17 14:51:56 +02:00
Jason Newcomb
3c6c7d5de9
Update docs for expl_impl_clone_on_copy. Bug was fixed in 879fa5c9721c89c27be6a9db5f51d935a51f549b1~ 2021-08-16 19:57:14 -04:00
Jason Newcomb
8b3ca9a315
Fix option_if_let_else
* `break` and `continue` statments local to the would-be closure are allowed
* don't lint in const contexts
* don't lint when yield expressions are used
* don't lint when the captures made by the would-be closure conflict with the other branch
* don't lint when a field of a local is used when the type could be pontentially moved from
* in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure
2021-08-16 16:12:00 -04:00
Jason Newcomb
aab3267412
Update docs for manual_split_once 2021-08-16 09:35:03 -04:00
Jason Newcomb
a7f376fbd3
Add lint manual_split_once 2021-08-16 09:34:58 -04:00
Jason Newcomb
8cf6dae0ca
Add for_each_local_usage. Switch LocalUsedVisitor to a function. 2021-08-16 09:34:42 -04:00
dswij
a09bc1b6fe Check if let expr usage in manual_flatten
`manual_flatten` should not trigger when match expression in `if let` is
going to be used.
2021-08-16 16:25:10 +08:00
bors
d9c3f0d690 Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiser
Uplift the invalid_atomic_ordering lint from clippy to rustc

This is mostly just a rebase of https://github.com/rust-lang/rust/pull/79654; I've copy/pasted the text from that PR below.

r? `@lcnr` since you reviewed the last one, but feel free to reassign.

---

This is an implementation of https://github.com/rust-lang/compiler-team/issues/390.

As mentioned, in general this turns an unconditional runtime panic into a (compile time) lint failure. It has no false positives, and the only false negatives I'm aware of are if `Ordering` isn't specified directly and is comes from an argument/constant/whatever.

As a result of it having no false positives, and the alternative always being strictly wrong, it's on as deny by default. This seems right.

In the [zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Uplift.20the.20.60invalid_atomic_ordering.60.20lint.20from.20clippy/near/218483957) `@joshtriplett` suggested that lang team should FCP this before landing it. Perhaps libs team cares too?

---

Some notes on the code for reviewers / others below

## Changes from clippy

The code is changed from [the implementation in clippy](68cf94f6a6/clippy_lints/src/atomic_ordering.rs) in the following ways:

1. Uses `Symbols` and `rustc_diagnostic_item`s instead of string literals.
    - It's possible I should have just invoked Symbol::intern for some of these instead? Seems better to use symbol, but it did require adding several.
2. The functions are moved to static methods inside the lint struct, as a way to namespace them.
    - There's a lot of other code in that file — which I picked as the location for this lint because `@jyn514` told me that seemed reasonable.
3. Supports unstable AtomicU128/AtomicI128.
    - I did this because it was almost easier to support them than not — not supporting them would have (ideally) required finding a way not to give them a `rustc_diagnostic_item`, which would have complicated an already big macro.
    - These don't have tests since I wasn't sure if/how I should make tests conditional on whether or not the target has the atomic... This is to a certain extent an issue of 64bit atomics too, but 128-bit atomics are much less common. Regardless, the existing tests should be *more* than thorough enough here.
4. Minor changes like:
    - grammar tweaks ("loads cannot have `Release` **and** `AcqRel` ordering" => "loads cannot have `Release` **or** `AcqRel` ordering")
    - function renames (`match_ordering_def_path` => `matches_ordering_def_path`),
    - avoiding clippy-specific helper methods that don't exist in rustc_lint and didn't seem worth adding for this case (for example `cx.struct_span_lint` vs clippy's `span_lint_and_help` helper).

## Potential issues

(This is just about the code in this PR, not conceptual issues with the lint or anything)

1. I'm not sure if I should have used a diagnostic item for `Ordering` and its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated).
    - It seems possible that failing to do this might possibly mean there are more cases this lint would miss, but I don't really know how `match_def_path` works and if it has any pitfalls like that, so maybe not.

2. I *think* I deprecated the lint in clippy (CC `@flip1995` who asked to be notified about clippy changes in the future in [this comment](https://github.com/rust-lang/rust/pull/75671#issuecomment-718731659)) but I'm not sure if I need to do anything else there.
    - I'm kind of hoping CI will catch if I missed anything, since `x.py test src/tools/clippy` fails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Running `cargo test` from src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue.

3. I wasn't sure if the description/example I gave good. Hopefully it is. The example is less thorough than the one from clippy here: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering. Let me know if/how I should change it if it needs changing.

4. It pulls in the `if_chain` crate. This crate was already used in clippy, and seems like it's used elsewhere in rustc, but I'm willing to rewrite it to not use this if needed (I'd prefer not to, all things being equal).
2021-08-16 06:36:13 +00:00
Thom Chiovoloni
295225b660 Uplift the invalid_atomic_ordering lint from clippy to rustc
- Deprecate clippy::invalid_atomic_ordering
- Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint
- Reduce code duplication
- Give up on making enum variants diagnostic items and just look for
`Ordering` instead

  I ran into tons of trouble with this because apparently the change to
  store HIR attrs in a side table also gave the DefIds of the
  constructor instead of the variant itself. So I had to change
  `matches_ordering` to also check the grandparent of the defid as well.

- Rename `atomic_ordering_x` symbols to just the name of the variant
- Fix typos in checks - there were a few places that said "may not be
  Release" in the diagnostic but actually checked for SeqCst in the lint.
- Make constant items const
- Use fewer diagnostic items
- Only look at arguments after making sure the method matches

  This prevents an ICE when there aren't enough arguments.

- Ignore trait methods
- Only check Ctors instead of going through `qpath_res`

  The functions take values, so this couldn't ever be anything else.

- Add if_chain to allowed dependencies
- Fix grammar
- Remove unnecessary allow
2021-08-16 03:55:27 +00:00
bors
3f0c97740f Auto merge of #7531 - Jarcho:manual_map_7413, r=camsteffen
Manual map 7413

fixes: #7413

This only fixes the specific problem from #7413, not the general case. The full fix requires interacting with the borrow checker to determine the lifetime of all the borrows made in the function. I'll open an issue about it later.

changelog: Don't suggest using `map` when the option is borrowed in the match, and also consumed in the arm.
changelog: Locals declared within the would-be closure will not prevent the closure from being suggested in `manual_map` and `map_entry`
2021-08-16 01:48:01 +00:00
Caio
b97d4c062b Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Jason Newcomb
251dd30d77
Improve manual_map
In some cases check if a borrow made in the scrutinee expression would prevent creating the closure used by `map`
2021-08-14 19:49:54 -04:00
Jason Newcomb
4838c78ba4
Improve manual_map and map_entry
Locals which can be partially moved created within the to-be-created closure shouldn't block the use of a closure
2021-08-14 19:49:45 -04:00
David Tolnay
3c8eaa8b2c
Downgrade option_if_let_else to nursery 2021-08-14 05:47:01 -07:00
Deadbeef
80bff87c6f move Constness into TraitPredicate 2021-08-13 09:26:33 +00:00
dswij
91b598a8e4 Fix false positive on filter_next 2021-08-13 14:56:37 +08:00
xFrednet
206741bf57 Use avoid_breaking_exported_api for types module lints
Addressed PR reviews regarding code style
2021-08-12 22:18:42 +02:00
xFrednet
09b7745f34 Updated lint message for rc_mutex 2021-08-12 13:53:23 +02:00
flip1995
1ad5464200 Merge commit '7bfc26ec8e7a454786668e7e52ffe527fc649735' into clippyup 2021-08-12 11:16:25 +02:00
flip1995
d02016d686
Merge remote-tracking branch 'upstream/master' into rustup 2021-08-12 10:58:44 +02:00
bors
62f4187ed0 Auto merge of #7546 - mgeier:patch-1, r=giraffate
similar_names: allow "iter" and "item"

changelog: [`similar_names`] no longer complains about `iter` and `item` being too similar
2021-08-12 08:16:50 +00:00
bors
e62a6cad1e Auto merge of #7516 - lf-:unwrap-or-default, r=xFrednet
Add `unwrap_or_else_default` lint

---

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

changelog: Add a new [`unwrap_or_else_default`] style lint. This will catch `unwrap_or_else(Default::default)` on Result and Option and suggest `unwrap_or_default()` instead.
2021-08-12 08:02:44 +00:00
F3real
979ce29086 Correctly report inclusive range in no_effect lint 2021-08-12 01:05:41 +02:00
bors
b1b38604f2 Auto merge of #7541 - LeSeulArtichaut:for-never-loop, r=camsteffen
`never_loop`: suggest using an `if let` instead of a `for` loop

changelog: suggest using an `if let` statement instead of a `for` loop that [`never_loop`]s

Fixes #7537, r? `@camsteffen.`
2021-08-11 14:49:37 +00:00
LeSeulArtichaut
fc0af8e4d8 never_loop: suggest using an if let instead of a for loop 2021-08-11 16:35:33 +02:00
Jade
23d398b184 tree-wide: Fix all the rustdoc warnings 2021-08-10 14:40:26 -07:00
Jade
c78cc7ac1f Add is_trait_item, refactor or_fun_call and unwrap_or_else_default 2021-08-10 14:40:26 -07:00
Jade
11ef04728c Add unwrap_or_else_default lint
This will catch `unwrap_or_else(Default::default)` on Result and Option
and suggest `unwrap_or_default()` instead.
2021-08-10 14:40:26 -07:00
bors
76c4a337d1 Auto merge of #7535 - LeSeulArtichaut:7518-self-ty-arg, r=xFrednet
Properly handle `Self` type for `trivially_copy_pass_by_ref`

changelog: properly handle `Self` type for [`trivially_copy_pass_by_ref`].

Fixes #7518
2021-08-10 10:25:26 +00:00
F3real
ede977cf31 Update suggestion in case of index for unnecessary_operation lint 2021-08-10 12:08:09 +02:00
bors
f998e89e43 Auto merge of #7478 - DevinR528:preemtive, r=llogiq
Fix nonstandard_macro_braces FP and docs of disallowed_types

changelog: Fix FP in [`nonstandard_macro_braces`] lint
2021-08-10 00:52:04 +00:00
bors
14d2aa1582 Auto merge of #7542 - LeSeulArtichaut:cleanups, r=flip1995
Cleanup usage of `span_to_snippet` and `LintContext::sess`

- avoid using `SourceMap::span_to_snippet` directly and use `clippy_utils::source::snippet_opt` instead
- don't use `LintContext::sess()` on `EarlyContext`s which have a `sess` field directly available, saving the import of `LintContext`

changelog: none
2021-08-09 13:48:47 +00:00
bors
0084195dee Auto merge of #7506 - HKalbasi:add-xor-swap, r=camsteffen
Add xor case to `manual swap` lint

Continue of #7153
closes #6598

changelog: Add "xor swap" case to [`manual_swap`]
2021-08-09 13:34:42 +00:00
hamidreza kalbasi
6d36d1a835 merge XOR_SWAP with MANUAL_SWAP 2021-08-09 02:15:10 +04:30
Matthias Geier
bc9459f9d4
similar_names: allow "iter" and "item" 2021-08-07 18:11:49 +02:00
bors
176df7ca9a Auto merge of #7536 - LeSeulArtichaut:redundant-allocation-doc, r=giraffate
Add missing backtick in docs for `redundant_allocation`

changelog: none
2021-08-07 13:19:06 +00:00
bors
6cb30ad581 Auto merge of #7534 - LeSeulArtichaut:7517-closure-too-many-lines, r=flip1995
Don't emit `too_many_lines` for closures

changelog: don't emit the [`too_many_lines`] lint inside closures to avoir duplicated diagnostics.

Fixes #7517.
2021-08-07 13:05:53 +00:00
LeSeulArtichaut
ae700b42ed Use EarlyContext::sess instead of LintContext::sess() 2021-08-07 01:59:08 +02:00
LeSeulArtichaut
64ff2b05b9 Replace span_to_snippet calls with snippet_opt from clippy_utils 2021-08-07 01:59:05 +02:00
LeSeulArtichaut
15b87088be Add missing backtick in docs for redundant_allocation 2021-08-05 19:06:35 +02:00
LeSeulArtichaut
ccb5d73dec Properly handle Self type for trivially_copy_pass_by_ref 2021-08-05 18:11:08 +02:00
valentine-mario
8a4ffb881d fixed bug that had to deal with mut and non mut suggestion 2021-08-05 16:15:44 +01:00
LeSeulArtichaut
4743ec1948 Don't emit too_many_lines for closures 2021-08-05 15:38:57 +02:00
bors
afe6b12b33 Auto merge of #87568 - petrochenkov:localevel, r=cjgillot
rustc: Replace `HirId`s with `LocalDefId`s in `AccessLevels` tables

and passes using those tables - primarily privacy checking, stability checking and dead code checking.

All these passes work with definitions rather than with arbitrary HIR nodes.
r? `@cjgillot`
cc `@lambinoo` (#87487)
2021-08-04 02:04:04 +00:00
Matthias Krüger
54c41c049c needless_borrow: try to make lint example a bit more illustrating 2021-08-04 00:21:25 +02:00
Devin Ragotzy
bc7fac9526 fixup! Lint inside macro when owned by current crate 2021-08-03 08:19:13 -04:00
xFrednet
b7d80e7d65 Updated define_Conf! to support multi-line doc comments 2021-08-02 17:56:09 +02:00
bors
10bb28ce73 Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Pietro Albini
2f315b82af bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04:00
Dharma Saputra Wijaya
69d439065e Handle Result on map_flatten lint
Adds a check on `.map(..).flatten()` on `Result` type that follows the
behaviour on `Option` type.
2021-08-01 17:47:54 +08:00
Vadim Petrochenkov
a1f790c8a9 Fix clippy 2021-07-31 19:31:30 +03:00
Jason Newcomb
205aa88921
Fix while_let_on_iterator
When the iterator is one field within a local correctly check for usages of the field
2021-07-31 09:32:54 -04:00
Jason Newcomb
fe75faa6ee
Fix while_let_on_iterator
Reborrow mutable references rather then take a reference to them.
2021-07-31 00:11:46 -04:00
Jade
6c2199ea9f rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Léo Lanteri Thauvin
e9004b063f
Remove or_patterns feature gate in example 2021-07-29 14:23:12 +02:00
Hrishi Dharam
dbb10b87f8 add xor-swap lint 2021-07-29 15:25:08 +04:30
flip1995
2b20f49841 Merge commit '0cce3f643bfcbb92d5a1bb71858c9cbaff749d6b' into clippyup 2021-07-29 12:16:06 +02:00
flip1995
54e539121d
Rename two lints to comply with our lint naming convention
self_named_constructor -> self_named_constructors
append_instead_of_extend -> extend_with_drain
2021-07-29 12:10:18 +02:00
flip1995
80116f9009
Bump Clippy Version -> 0.1.56 2021-07-29 11:15:11 +02:00
flip1995
490beda6be
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-29 11:14:25 +02:00
Philipp Krones
464c85c8c1
Rollup merge of #7420 - xFrednet:7172-update-lint-documentation, r=flip1995
Update lint documentation to use markdown headlines

This PR updates all lint documentation to use markdown headlines. It additionally removed the *Known problems* section for lints without any problems. I've double-checked all automatic replacements, but a second pair of eyes is definitely appreciated!

I wasn't sure when you wanted to switch to the new metadata collection tomorrow, I therefore prepared this PR today. And that's it this is a standalone PR to keep the other related PRs reviewable.

changelog:  none

r? `@flip1995`

cc: #7172

Note: This should be merged with the other metadata collection related PRs.
2021-07-28 15:06:27 +02:00
Philipp Krones
bcdf147aaf
Rollup merge of #7298 - flip1995:ci-switch-to-monster, r=xFrednet,flip1995
Switch CI to new metadata collection

r? `@xFrednet`

Things we have to keep in mind:

- This removes the template files and the scripts used for deployment from the checkout. This was added in #5517. I don't think we ever needed those there. Not sure though.
- ~~As a result, we can't remove the python scripts yet. We have to wait until this hits a stable Clippy release.~~ I'll just break the next stable deploy and do it by hand once.
- This should be merged together with #7279. Me and `@xFrednet` will coordinate the switch
- ...?

I still have to try out some things:

- [x] Is it worth caching? Yes
- [x] ~~Is it worth to do a release build?~~ Nope
- [x] Does it actually work? With a few changes, yes
- [ ] ...?

changelog: Clippy now uses a lint to generate its documentation 🎉
2021-07-28 15:06:26 +02:00
xFrednet
322a768c77
Adapting the lint list to Clippy's new metadata format
Changes included:
    - Minimum adaption to the new `lints.json` format
    - Fixing filtering for the new `lints.json` format; hardcoding the
      lint groups in the index
    - Recreating the original doc styling for the new format
    - Fixed sytax highlighting for rust,ignore code blocks
    - Fixed markdown table extraction in the metadata collector and
      fixed lint level output
    - Adding the additional information row for lints
    - Changed the website title to Clippy's lint list
    - Flexing the website for mobile users
    - Added (?) references for lint levels and groups
    - Making deprecated lints look dead
    - Removed JS code block language extraction in favor of a rust
      implementation `rust-clippy#7352`
    - Added the suspicious lint group to the lint list
    - Remove trailing whitespaces from index.html
    - Fix code highlighting
    - Use default value if the docVersion is empty

Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-07-28 15:03:55 +02:00
flip1995
9bc5803195
Fix last occurence of **What it does:** 2021-07-28 14:32:02 +02:00
xFrednet
12c61612f7
Update lint documentation to use markdown headlines 2021-07-28 14:31:59 +02:00
flip1995
6c5d199d57
Update deploy CI
This updates all the deploy scripts and the deploy workflow.

The deploy workflow now runs the metadata collector to collect the lint
documentation. It also changes the files that are checked out in the
deploy workflow from master and adds an explanation why we have to do
this.
2021-07-28 14:16:31 +02:00
bors
ea988afcda Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer

In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-27 16:24:45 +00:00
Devin Ragotzy
a1bab3bc63 Add primitive type support to disallowed_type lint
Fix docs of disallowed_type

Add ability to name primitive types without import path

Move primitive resolution to clippy_utils path_to_res fn

Refactor Res matching, fix naming and docs from review

Use tcx.def_path_str when emitting the lint
2021-07-27 10:01:38 -04:00
bors
ceb7a868d3 Auto merge of #7466 - xFrednet:5393-use-more-diagnostic-items, r=flip1995
Use diagnostic items where possible

Clippy still uses a bunch of paths in places that could easily use already defined diagnostic items. This PR updates all references to such paths and also removes a bunch of them that are no longer needed after this cleanup.

Some paths are also used to construct new paths and can therefore not be removed that easily. I've added a doc comment to those instances that recommends the use of the diagnostic item where possible.

And that's it, cleaning crew signing off 🧹 🗑️

---

changelog: none

(only internal improvements)

cc: #5393
2021-07-27 08:19:23 +00:00
kadmin
74379d4d85 Actually infer args in visitors 2021-07-26 21:15:18 +00:00
bors
3214de3fe6 Auto merge of #7493 - xFrednet:7220-fix-new-without-default-impl-type, r=camsteffen
Prefer a code snipped over formatting the self type (`new_without_default`)

Fixes: rust-lang/rust-clippy#7220

changelog: [`new_without_default`]: The `Default` impl block type doesn't use the full type path qualification

Have a nice day to everyone reading this 🙃
2021-07-26 12:20:54 +00:00
bors
02d70f3604 Auto merge of #7477 - F3real:needless_continue, r=flip1995
Enhance needless continue to detect loop {continue;}

Fixes #7417

changelog: Report [`needless_continue`] in `loop { continue; }` case
2021-07-26 11:52:55 +00:00
bors
6d9036bc5f Auto merge of #7484 - camsteffen:author, r=flip1995
Some `clippy::author` improvements

changelog: none

* Use `Debug` instead of re-implementing it for some things
* Fix block trailing expression handing
* Don't double print on stmt/expr with `#[clippy::author]` attribute
2021-07-26 11:41:46 +00:00
xFrednet
89c8c3f4cd Prefer a code snipped over formatting the self type (new_without_default) 2021-07-26 09:35:38 +02:00
Cameron Steffen
d3492a0894 author: check block.expr: None 2021-07-25 18:10:59 -05:00
Camille GILLOT
5b914f6e33 Introduce OwnerNode::Crate. 2021-07-25 12:22:47 +02:00
kadmin
8286824ab2 Add inferred args to typeck 2021-07-25 07:28:51 +00:00
Devin Ragotzy
44d37a44bc Lint inside macro when owned by current crate 2021-07-24 07:30:22 -04:00
Devin Ragotzy
f5c3ed4463 Only trigger for one level of macros 2021-07-24 07:30:22 -04:00
Devin Ragotzy
fb9b13a69f Fix FP for nonstandard_macro_braces lint 2021-07-24 07:30:22 -04:00
Cameron Steffen
afe5962d38 clippy::author improvements 2021-07-23 17:03:12 -05:00
F3real
045dbb52d5 Clean up unnecessary unwraps 2021-07-23 17:34:27 +02:00
xFrednet
544c462d25 Documented constant expression evaluation for repeat_once 2021-07-23 17:07:43 +02:00
F3real
c3452f3bd2 Lint on continue expression without semi-colon 2021-07-22 22:23:59 +02:00
F3real
9d6127cdb0 Emit needless_continue warning if loop ends on continue 2021-07-21 23:32:16 +02:00
F3real
24ec35a904 Enhance needless continue to detect loop {continue;} 2021-07-20 19:26:45 +02:00
bors
610381455c Auto merge of #7221 - th1000s:keyword_, r=giraffate
similar_names: No longer suggest inserting or appending an underscore

changelog: [`similar_names`] lint no longer suggests to insert or add an underscore to "fix" too similar names
2021-07-19 14:18:59 +00:00
flip1995
884ef4c287 Merge commit '4c41a222ca5d1325fb4b6709395bd06e766cc042' into clippyup 2021-07-19 11:52:05 +02:00
flip1995
26321b35c8
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-19 11:48:49 +02:00
bors
f467750680 Auto merge of #7470 - DevinR528:fix-ice7447, r=flip1995
Add check if ty has_escaping_bound_vars in zero_sized_map_values lint

Fixes: #7447

changelog: fix ICE in [`zero_sized_map_values`]
2021-07-19 09:22:34 +00:00
bors
f70a07454b Auto merge of #7403 - Anthuang:redundant-method-names, r=Manishearth
New lint: [`self_named_constructor`]

Adds the `self_named_constructor` lint for detecting when an implemented method has the same name as the type it is implemented for.

changelog: [`self_named_constructor`]

closes: #7142
2021-07-19 06:49:51 +00:00
Cameron Steffen
98c500cf83 Factor BinOp utils 2021-07-17 20:49:19 -05:00
Cameron Steffen
efbf7ca61e Use From to convert BinOpKind 2021-07-17 20:25:26 -05:00
bors
1b0e57800c Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
Remove refs from Pat slices

Changes `PatKind::Or(&'hir [&'hir Pat<'hir>])` to `PatKind::Or(&'hir [Pat<'hir>])` and others. This is more consistent with `ExprKind`, saves a little memory, and is a little easier to use.
2021-07-16 13:35:48 +00:00
Guillaume Gomez
5c54d04ef6 Rollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis
ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow

r? ```@nikomatsakis```
2021-07-16 10:08:05 +02:00
Devin Ragotzy
7312611207 Add check if ty has_escaping_bound_vars in zero_sized_map_values lint 2021-07-15 18:37:02 -04:00
Cameron Steffen
81904a413e Remove refs from pat slices 2021-07-15 16:09:57 -05:00
flip1995
1d084b13a5 Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup 2021-07-15 10:44:10 +02:00
flip1995
69fbd64e2a
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-15 10:32:06 +02:00
lyj
e575610fb3 redundant_allocation: add Arc; some refractoring. 2021-07-15 07:10:55 +08:00
xFrednet
ecf85f4bdc Use diagnostic items for Vec, VecDeque and connected refactorings 2021-07-15 00:02:46 +02:00
xFrednet
6ce6b29527 Use diagnostic items for intrinsics::transmute, TryInto 2021-07-14 23:34:19 +02:00
xFrednet
6030428fd2 Use diagnostic items for Into, IntoIterator, LinkedList, ptr::null, prt::null_mut 2021-07-14 22:50:59 +02:00
bors
2b193e247f Auto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-fp, r=camsteffen
FP fix and documentation for `branches_sharing_code` lint

Closes rust-lang/rust-clippy#7369

Related rust-lang/rust-clippy#7452 I'm still thinking about the best way to fix this. I could simply add another visitor to ensure that the moved expressions don't modify values being used in the condition, but I'm not totally happy with this due to the complexity. I therefore only documented it for now

changelog: [`branches_sharing_code`] fixed false positive where block expressions would sometimes be ignored.
2021-07-14 20:29:56 +00:00
xFrednet
2ac21889bc Use diagnostic items for BinaryHeap, BTreeMap, BTreeSet, HashMap, HashSet, Borrow, Default 2021-07-14 22:02:59 +02:00
xFrednet
61e280863f Fixed branches_sharing_code FP with block expressions in else
And added `branches_sharing_code` PF note to lint doc for `rust-clippy#7452`
2021-07-14 21:37:17 +02:00
bors
4acbff9eb0 Auto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995
suggest `&mut` for redundant FnMut closures

fixes #6903

changelog: suggest `&mut` for redundant FnMut closures
2021-07-14 15:15:28 +00:00
Elliot Bobrow
4c398e07e0 suggest &mut for redundant FnMut closures 2021-07-14 07:56:27 -07:00
Aman Arora
a9e9b7f9b2 ExprUseVisitor::Delegate consume only when moving 2021-07-14 02:21:08 -04:00
lyj
10910020ec rename possible_borrowed to possible_origin; pass dogfood 2021-07-14 13:46:33 +08:00
lyj
251c3b64da fix 5707 2021-07-14 10:57:47 +08:00
Thomas Otto
e8f57c3ac4 No longer suggest inserting or appending an underscore
changelog: [`similar_names`] lint no longer suggests to insert or add an underscore
to "fix" too similar names
2021-07-13 23:21:24 +02:00
bors
2fd8dbc8af Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk
Fix internal `default_hash_types` lint to use resolved path

I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
2021-07-13 15:06:10 +00:00
bors
8131445e53 Auto merge of #7446 - Y-Nak:fix-7445, r=xFrednet,flip1995
`default_numeric_fallback`: Fix FP with floating literal

Fix #7445

changelog: `default_numeric_fallback`: Fix FP with floating literal
2021-07-13 14:31:02 +00:00
Yoshitomo Nakanishi
25e4c7d73f default_numeric_fallback: Add rustfix tests 2021-07-13 23:18:31 +09:00
Cameron Steffen
306f9e843d Split a lint message into help 2021-07-13 08:57:16 -05:00
Cameron Steffen
73ffae6ea1 Reduce redundant code 2021-07-13 08:57:16 -05:00
Cameron Steffen
e6ab222b81 Refactor format macro parsing 2021-07-13 08:57:16 -05:00
Cameron Steffen
20dbb277cf Fix useless_format false positive 2021-07-13 08:57:16 -05:00
Cameron Steffen
3fc8dae46c Allow needless_bool in macro 2021-07-13 08:57:16 -05:00
flip1995
f05949f9ce
Add fixed example to unused_unit documentation 2021-07-13 10:54:29 +02:00
Vadim Petrochenkov
075a28996c rustc_span: Revert addition of proc_macro field to ExpnKind::Macro
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-10 23:03:35 +03:00
Cameron Steffen
dce274024e clippy: allow default_hash_types on bootstrap 2021-07-09 09:10:45 -05:00
flip1995
d2c8f50bbe
Rename is_allowed -> is_lint_allowed 2021-07-09 15:06:12 +02:00
flip1995
5add651223
Remove lints_enabled function
This function was redundant with the is_allowed function. Now is_allowed
is used everywhere lints_enabled was used before.
2021-07-09 15:00:24 +02:00
Guillaume Gomez
3fc34455f4 Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
flip1995
795868dd88
Rename run_lints -> lints_enabled 2021-07-08 15:45:19 +02:00
Yoshitomo Nakanishi
3bc5abef62 default_numeric_fallback: Fix FP with floating literal 2021-07-08 11:37:12 +09:00
Ryan Levick
30c5c2ff03 Add s to non_fmt_panic 2021-07-06 20:12:56 +02:00
iobtl
eeefbb7617 fix false positive (panic message) with assert macro using message parameter 2021-07-06 15:14:53 +08:00
Anthony Huang
357a8f0344 Add redundant_method_names lint 2021-07-05 14:15:20 -04:00
Mateusz Gacek
59a164e86c Add new lint: strlen_on_c_strings 2021-07-05 11:10:45 +02:00
bors
3cc6778512 Auto merge of #7431 - DevinR528:fix-macro-brace, r=llogiq
Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint

fixes #7422

changelog: fixes false positives in [`nonstandard_macro_braces`]
2021-07-04 16:47:11 +00:00
Devin Ragotzy
1d110f8c2e Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint 2021-07-04 07:06:23 -04:00
Cameron Steffen
cb4670deb3 Fix use_self ICE 2021-07-03 12:40:50 -05:00
bors
c195db7fee Auto merge of #7426 - ebobrow:doc-markdown-fp, r=llogiq
fix doc_markdown false positive

fixes #7421

changelog: don't lint unbalanced tick marks in code blocks
2021-07-03 16:53:21 +00:00
Elliot Bobrow
e9a5694597 fix doc_markdown false positive 2021-07-03 09:34:10 -07:00
bors
84209994ad Auto merge of #7316 - lengyijun:rc_mutex, r=llogiq
Add new lint: `rc_mutex`

changelog: Add new lint `rc_mutex`.

It lints on `Rc<Mutex<T>>`.

`Rc<Mutex<T>>` should be corrected to `Rc<RefCell<T>>`
2021-07-03 10:26:03 +00:00
David Tolnay
0f662e5833
Downgrade nonstandard_macro_braces to nursery 2021-07-02 22:16:04 -07:00
lyj
b9cc2feaaa rc_mutex: known problems 2021-07-02 22:10:13 +08:00
flip1995
ebe52869a3 Merge commit '61eb38aeda6cb54b93b872bf503d70084c4d621c' into clippyup 2021-07-01 18:17:38 +02:00
flip1995
a82a744155
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-01 17:41:24 +02:00
bors
753bce30f0 Auto merge of #7407 - m-ou-se:doc-hidden-variants, r=flip1995
Don't suggest doc(hidden) or unstable variants in wildcard lint

Clippy's wildcard lint would suggest doc(hidden) and unstable variants for non_exhaustive enums, even though those aren't part of the public interface (yet) and should only be matched on using a `_`, just like potential future additions to the enum. There was already some logic to exclude a *single* doc(hidden) variant. This extends that to all hidden variants, and also hides `#[unstable]` variants.

See https://github.com/rust-lang/rust/pull/85746#issuecomment-868886893

This PR includes https://github.com/rust-lang/rust-clippy/pull/7406 as the first commit.

Here's the diff that this PR adds on top of that PR: https://github.com/m-ou-se/rust-clippy/compare/std-errorkind...m-ou-se:doc-hidden-variants

---

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

changelog: No longer suggest unstable and doc(hidden) variants in wildcard lint. wildcard_enum_match_arm, match_wildcard_for_single_variants
2021-07-01 15:02:21 +00:00
flip1995
fae7a09eea
match_wildcard_for_single_variants: don't produce bad suggestion
This fixes a bug where match_wildcard_for_single_variants produced a
bad suggestion where besides the missing variant, one or more hidden
variants were left.

This also adds tests to the ui-tests match_wildcard_for_single_variants
and wildcard_enum_match_arm to make sure that the correct suggestion is
produced.
2021-07-01 12:38:30 +02:00
bors
cadb93b6de Auto merge of #7400 - popzxc:restrict-locales, r=Manishearth
New lint: `disallowed_script_idents`

This PR implements a new lint to restrict locales that can be used in the code,
as proposed in #7376.

Current concerns / unresolved questions:

- ~~Mixed usage of `script` (as a Unicode term) and `locale` (as something that is easier to understand for the broad audience). I'm not sure whether these terms are fully interchangeable and whether in the current form it is more confusing than helpful.~~ `script` is now used everywhere.
- ~~Having to mostly copy-paste `AllowedScript`. Probably it's not a big problem, as the list of scripts is standardized and is unlikely to change, and even if we'd stick to the `unicode_script::Script`, we'll still have to implement custom deserialization, and I don't think that it will be shorter in terms of the amount of LoC.~~ `unicode::Script` is used together with a filtering deserialize function.
- Should we stick to the list of "recommended scripts" from [UAX #31](http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts) in the configuration?

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

changelog: ``[`disallowed_script_idents`]``

r? `@Manishearth`
2021-06-30 18:14:16 +00:00
Igor Aleksanov
018be41dee Implement 'disallowed_script_idents' lint 2021-06-30 19:06:33 +03:00
bors
3525a6b61a Auto merge of #7390 - popzxc:issue-7331, r=flip1995
Improve lint message for match-same-arms lint

fixes #7331

Follow-up to #7377

This PR improves the lint message for `match-same-arms` lint and adds `todo!(..)`  example to the lint docs.

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

changelog: None
2021-06-30 15:12:55 +00:00
Cameron Steffen
bae76f9c17 Remove a visitor from use_self 2021-06-29 08:17:23 -05:00
Cameron Steffen
6e801e251f Use type_of for impl self type 2021-06-29 08:15:45 -05:00
Cameron Steffen
4913d82175 Simplify in impl check 2021-06-29 08:14:21 -05:00