Commit graph

176 commits

Author SHA1 Message Date
bors
da0538eaca Auto merge of #7330 - xFrednet:0000-refactor-map-identity, r=flip1995
Refactoring identity function lints

I've noticed that we have several lints that all check for identity functions and each used their own check implementation. I moved the `is_expr_identity_function` function to `clippy_utils` and adapted all lints to reuse that one function. This should make the addition of new lints like this also easier in the future.

I've also moved the `map_identity` lint into the `methods` module. It's probably the best to review this PR by checking each commit individually. And that's it, have a great day 🙃

changelog: none
2021-06-09 08:27:05 +00:00
bors
07217e3370 Auto merge of #7262 - Jarcho:while_let_on_iter_closure, r=xFrednet,flip1995
fix `while_let_on_iterator` suggestion in a closure

fixes: #7249

A future improvement would be to check if the closure is being used as `FnOnce`, in which case the original suggestion would be correct.

changelog: Suggest `&mut iter` inside a closure for `while_let_on_iterator`
2021-06-08 15:52:40 +00:00
xFrednet
967d815a42 Extracting is_expr_identity_function into clippy_utils for reusability 2021-06-07 22:42:11 +02:00
Mara Bos
25639101dd Don't treat cfg!() as a constant. 2021-06-04 10:47:03 +02:00
Jason Newcomb
cfddf0927b
Fix type checks for manual_str_repeat 2021-05-31 09:37:13 -04:00
Jason Newcomb
97311f0906
Add lint manual_str_repeat 2021-05-30 23:26:48 -04:00
Cameron Steffen
f3e77a454a Fix allow on some statement lints 2021-05-26 22:07:53 -05:00
mbartlett21
0c017ea058 Remove semicolons in clippy_utils 2021-05-25 02:12:27 +00:00
Cameron Steffen
7f340578cc Hash Symbol directly 2021-05-24 10:51:40 -05:00
Cameron Steffen
9d61b4e081 Fix SpanlessEq for GenericArg::Const 2021-05-24 10:51:40 -05:00
Cameron Steffen
0ebd5018bf Add a short-circuiting case 2021-05-24 09:48:05 -05:00
Cameron Steffen
24743b3968 Use UnhashMap 2021-05-24 09:48:05 -05:00
Cameron Steffen
f21d909e62 Use FxHasher 2021-05-24 09:31:11 -05:00
Cameron Steffen
27ac647649 Use discriminant instead of stable_hash 2021-05-24 09:31:09 -05:00
Cameron Steffen
e027b6bc49 Minor SpanlessHash improvements 2021-05-24 09:30:52 -05:00
Jason Newcomb
7db0e4f791
Suggest &mut iter inside a closure for while_let_on_iterator 2021-05-21 12:27:40 -04:00
Jason Newcomb
f355aebf10
Move needless_borrow to style 2021-05-21 11:24:52 -04:00
Jason Newcomb
6d4dc35882
Improve needless_borrow lint
Suggest changing usages of ref bindings to match the new type
Split out some cases into new lint `ref_binding_to_reference`
2021-05-20 09:03:47 -04:00
flip1995
451ff5668b
Merge remote-tracking branch 'upstream/master' into rustup 2021-05-20 12:05:02 +02:00
flip1995
9586ddb046
Fix fallout from not ignoring warnings anymore 2021-05-18 11:08:19 +02:00
flip1995
ff452d5ba6
Deny warning in every main sub-crate
This enables the same warnings that are enabled in `clippy_lints` also
in `clippy_utils` and `clippy_dev`. Then it makes sure, that the
`deny-warnings` feature is passed down to `clippy_lints` and
`clippy_utils` when compiling Clippy.
2021-05-18 11:05:48 +02:00
bors
1aad7541db Auto merge of #7223 - ThibsG:FpUselessConversion7205, r=camsteffen
Fix FPs about generic args

Fix 2 false positives in [`use_self`] and [`useless_conversion`] lints, by taking into account generic args and comparing them.

Fixes: #7205
Fixes: #7206

changelog: Fix FPs about generic args in [`use_self`] and [`useless_conversion`] lints
2021-05-17 17:40:48 +00:00
ThibsG
2fb35ce4f0 Add generic args for comparison in use_self and useless_conversion lints 2021-05-17 17:27:16 +02:00
Jason Newcomb
4713e25ab0
Cleanup of while_let_on_iterator 2021-05-12 21:51:19 -04:00
Jason Newcomb
daca50a515
Improvements to while_let_on_iterator
* Suggest `&mut iter` when the iterator is used after the loop.
* Suggest `&mut iter` when the iterator is a field in a struct.
* Don't lint when the iterator is a field in a struct, and the struct is
used in the loop.
* Lint when the loop is nested in another loop, but suggest `&mut iter`
unless the iterator is from a local declared inside the loop.
2021-05-12 21:49:22 -04:00
Camille GILLOT
b03b74734b Use () for entry_fn. 2021-05-12 13:58:42 +02:00
Aaron Hill
ab73020d40 Implement span quoting for proc-macros
This PR implements span quoting, allowing proc-macros to produce spans
pointing *into their own crate*. This is used by the unstable
`proc_macro::quote!` macro, allowing us to get error messages like this:

```
error[E0412]: cannot find type `MissingType` in this scope
  --> $DIR/auxiliary/span-from-proc-macro.rs:37:20
   |
LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream {
   | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]`
...
LL |             field: MissingType
   |                    ^^^^^^^^^^^ not found in this scope
   |
  ::: $DIR/span-from-proc-macro.rs:8:1
   |
LL | #[error_from_attribute]
   | ----------------------- in this macro invocation
```

Here, `MissingType` occurs inside the implementation of the proc-macro
`#[error_from_attribute]`. Previosuly, this would always result in a
span pointing at `#[error_from_attribute]`

This will make many proc-macro-related error message much more useful -
when a proc-macro generates code containing an error, users will get an
error message pointing directly at that code (within the macro
definition), instead of always getting a span pointing at the macro
invocation site.

This is implemented as follows:
* When a proc-macro crate is being *compiled*, it causes the `quote!`
  macro to get run. This saves all of the sapns in the input to `quote!`
  into the metadata of *the proc-macro-crate* (which we are currently
  compiling). The `quote!` macro then expands to a call to
  `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an
opaque identifier for the span in the crate metadata.
* When the same proc-macro crate is *run* (e.g. it is loaded from disk
  and invoked by some consumer crate), the call to
`proc_macro::Span::recover_proc_macro_span` causes us to load the span
from the proc-macro crate's metadata. The proc-macro then produces a
`TokenStream` containing a `Span` pointing into the proc-macro crate
itself.

The recursive nature of 'quote!' can be difficult to understand at
first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows
the output of the `quote!` macro, which should make this eaier to
understand.

This PR also supports custom quoting spans in custom quote macros (e.g.
the `quote` crate). All span quoting goes through the
`proc_macro::quote_span` method, which can be called by a custom quote
macro to perform span quoting. An example of this usage is provided in
`src/test/ui/proc-macro/auxiliary/custom-quote.rs`

Custom quoting currently has a few limitations:

In order to quote a span, we need to generate a call to
`proc_macro::Span::recover_proc_macro_span`. However, proc-macros
support renaming the `proc_macro` crate, so we can't simply hardcode
this path. Previously, the `quote_span` method used the path
`crate::Span` - however, this only works when it is called by the
builtin `quote!` macro in the same crate. To support being called from
arbitrary crates, we need access to the name of the `proc_macro` crate
to generate a path. This PR adds an additional argument to `quote_span`
to specify the name of the `proc_macro` crate. Howver, this feels kind
of hacky, and we may want to change this before stabilizing anything
quote-related.

Additionally, using `quote_span` currently requires enabling the
`proc_macro_internals` feature. The builtin `quote!` macro
has an `#[allow_internal_unstable]` attribute, but this won't work for
custom quote implementations. This will likely require some additional
tricks to apply `allow_internal_unstable` to the span of
`proc_macro::Span::recover_proc_macro_span`.
2021-05-12 00:51:31 -04:00
flip1995
d605882023 Merge commit 'b71f3405606d49b9735606b479c3415a0ca9810f' into clippyup 2021-05-06 12:20:44 +02:00
flip1995
d481b38634
Bump Clippy version -> 0.1.54 2021-05-06 11:32:34 +02:00
flip1995
767cc7cd89
Merge remote-tracking branch 'upstream/master' into rustup 2021-05-06 11:32:03 +02:00
xFrednet
e0eb29c936 Applying PR suggestions (mostly typos)
Co-authored-by: flip1995 <hello@philkrones.com>
Co-authored-by: phansch <dev@phansch.net>
2021-05-05 18:58:57 +02:00
xFrednet
4fc960301b Metadata collection: Rounding up the implementation 2021-05-05 18:38:26 +02:00
xFrednet
35844d0a48 Metadata collection: Resolve lint from locals 2021-05-05 18:35:33 +02:00
xFrednet
6658db1044 Metadata collection: processing emission closures (417/455) 2021-05-05 18:35:33 +02:00
xFrednet
ee8a99a114 Metadata collection: Collecting Applicability assign values 2021-05-05 18:35:33 +02:00
xFrednet
8dca1b8f61 Metadata collection: Collecting Applicability assign values 2021-05-05 18:35:33 +02:00
xFrednet
060e0e9f93 Metadata collection lint: Basic applicability collection 2021-05-05 18:35:33 +02:00
Cameron Steffen
1c3c54a6ef SpanlessHash Pat 2021-05-04 08:43:20 -05:00
Christiaan Dirkx
ee6d1a35ba Change std::sys::unix::ext::fs::PermissionsExt::from_mode to std::os:👿:unix::fs::PermissionsExt::from_mode in Clippy 2021-05-03 16:56:22 +02:00
bors
5e49c4bd67 Auto merge of #6951 - Jarcho:implicit_return_fp, r=flip1995
`implicit_return` improvements

fixes: #6940

changelog: Fix `implicit_return` suggestion for async functions
changelog: Improve `implicit_return` suggestions when returning the result of a macro
changelog: Check for `break` expressions inside a loop which are then implicitly returned
changelog: Allow all diverging functions in `implicit_return`, not just panic functions
2021-04-30 14:55:56 +00:00
Charles Lew
2f494557ba Implement RFC 1260 with feature_name imported_main. 2021-04-29 08:35:08 +08:00
flip1995
ae72f1adb9 Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup 2021-04-27 16:55:11 +02:00
bors
7c7683c8ef Auto merge of #7128 - Jarcho:const_fn_ice, r=flip1995
Fix ICE checking for feature gated const fn

fixes: #7126
changelog: Fix ICE in `missing_const_for_fn` when using a feature-gated `const fn`
2021-04-27 14:21:11 +00:00
Cameron Steffen
340b570ea0 Refactor MSRV aliases 2021-04-26 16:07:48 -05:00
Jason Newcomb
db7ad648e7
Fix ICE checking for feature gated const fn 2021-04-25 10:18:15 -04:00
Jason Newcomb
ef9ad80617
Add examples to better explain walk_span_to_context 2021-04-22 09:36:46 -04:00
Jason Newcomb
74cf5f2fc6
Fix implicit_return suggestion for async functions 2021-04-22 09:36:32 -04:00
Jason Newcomb
22f8c13cf5
Improve implicit_return
Better suggestions when returning macro calls.
Suggest changeing all the break expressions in a loop, not just the final statement.
Don't lint divergent functions.
Don't suggest returning the result of any divergent fuction.
2021-04-22 09:13:06 -04:00
flip1995
02bf692169 Merge commit '98e2b9f25b6db4b2680a3d388456d9f95cb28344' into clippyup 2021-04-22 11:31:13 +02:00
bors
bbc22e2ef3 Auto merge of #7083 - GuillaumeGomez:bool-assert-eq, r=camsteffen
Add lint to check for boolean comparison in assert macro calls

This PR adds a lint to check if an assert macro is using a boolean as "comparison value". For example:

```rust
assert_eq!("a".is_empty(), false);
```

Could be rewritten as:

```rust
assert!(!"a".is_empty());
```

PS: The dev guidelines are amazing. Thanks a lot for writing them!

changelog: Add `bool_assert_comparison` lint
2021-04-21 13:58:53 +00:00