Commit graph

9121 commits

Author SHA1 Message Date
bors
298f139798 Auto merge of #10317 - m-ou-se:suspicious-command-arg-space, r=Manishearth
Add `suspicious_command_arg_space` lint

Fixes #10316

---

changelog: New lint: [`suspicious_command_arg_space`]
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
<!-- changelog_checked -->
2023-02-12 21:57:49 +00:00
Mara Bos
1f77866991 Add SUSPICIOUS_COMMAND_ARG_SPACE to lint pass. 2023-02-12 22:00:13 +01:00
Caio
c43937316a [arithmetic_side_effects] Fix #10252 2023-02-12 17:34:07 -03:00
bors
6f353fdf0a Auto merge of #10310 - c410-f3r:arith-2, r=Alexendoo
[arithmetic_side_effects] Fix #10209

Fix #10209

---

changelog: Enhancement: [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
<!-- changelog_checked -->
2023-02-12 19:34:15 +00:00
Caio
1ed8ed3435 Address comment 2023-02-12 16:27:30 -03:00
Caio
e70a7a68bd [arithmetic_side_effects] Evaluate integers originated from constant declarations 2023-02-12 16:19:51 -03:00
Caio
1b286b128b Address comments 2023-02-12 16:17:37 -03:00
Samuel Tardieu
09d3097734 manual_let_else: do not suggest semantically different replacements 2023-02-12 20:07:23 +01:00
Samuel Tardieu
d9dc1679f5 cast_possible_truncation: issue proper help message 2023-02-12 08:56:21 +01:00
Michael Krasnitski
8789b37d06 Fix false positives for extra_unused_type_parameters 2023-02-11 12:22:25 -05:00
Caio
078f149aa4 [significant_drop_tightening] Add MVP 2023-02-10 15:07:34 -03:00
Mara Bos
8f56767c94 Update lints. 2023-02-10 19:03:20 +01:00
Mara Bos
984c47b9f4 Clarify description of suspicious_command_arg_space.
Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>
2023-02-10 19:02:39 +01:00
Mara Bos
145e6a94d6 Add suspicious_command_arg_space lint. 2023-02-10 19:02:39 +01:00
Philipp Krones
e7fe1f9c14 Merge commit '0f7558148c22e53cd4608773b56cdfa50dcdeac3' into clippyup 2023-02-10 14:01:19 +01:00
Philipp Krones
7c61b4ed89
Merge remote-tracking branch 'upstream/master' into rustup 2023-02-10 11:33:45 +01:00
DevAccentor
179c037643 improve almost swap to look for let statement 2023-02-10 18:00:46 +09:00
Christian Poveda
cc19fbe177
update metadata 2023-02-09 16:53:34 -05:00
Christian Poveda
e2e23c0045
Add docs and update tests 2023-02-09 16:41:45 -05:00
Esteban Küber
374c393a93 Introduce -Zterminal-urls to use OSC8 for error codes
Terminals supporting the OSC8 Hyperlink Extension can support inline
anchors where the text is user defineable but clicking on it opens a
browser to a specified URLs, just like `<a href="URL">` does in HTML.

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-02-09 14:52:54 +00:00
bors
5adeebf92f Auto merge of #10292 - xFrednet:0000-support-trait-item-in-dump, r=flip1995
Make `[clippy::dump]` support trait items

Roses are red,
violets are blue,
trait items are rare,
`[clippy::dump]` is too

---

Let's just ignore the horrible poem... anyways. While working on Marker I noticed, that `[clippy::dump]` doesn't work on trait item (See [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e2d9791ffa2872e7c09a9dfbd470350c)). This simply adds support for that. `[clippy::dump]` doesn't have UI tests, to make it more resistant to changes in the AST. I tested it locally and the dump works after these changes.

---

changelog: none
2023-02-09 13:22:00 +00:00
bors
fd2d8beaf8 Auto merge of #10293 - Alexendoo:bool-assert-comparison-negation, r=dswij
Negate suggestions when needed in `bool_assert_comparison`

changelog: none assuming this gets into the same release as #10218

Fixes #10291

r? `@dswij`

Thanks to `@black-puppydog` for spotting it early
2023-02-08 23:03:32 +00:00
Christian Poveda
c6692a8b42
Add configuration to lint missing docs of pub(crate) items 2023-02-06 14:21:37 -05:00
Kartavya Vashishtha
2fc1693cd5
split suggestions into two separate suggestions 2023-02-06 21:34:35 +05:30
Kartavya Vashishtha
63a57ee1c3
retain applicability 2023-02-05 01:50:44 +05:30
Kartavya Vashishtha
1fb42daf11
use span_suggestions to suggest both intents 2023-02-05 01:05:31 +05:30
Alex Macleod
5546c82051 Negate suggestions when needed in bool_assert_comparison 2023-02-04 19:28:11 +00:00
xFrednet
c642cfe3bf
Make [clippy::dump] support trait items 2023-02-04 19:34:31 +01:00
Michael Krasnitski
fba16e2e3a Add extra_unused_type_parameters lint 2023-02-02 19:37:34 -05:00
bors
006a4cc767 Auto merge of #10276 - m-ou-se:manual-assert, r=Alexendoo
Don't depend on FormatArgsExpn in ManualAssert.

Part of https://github.com/rust-lang/rust-clippy/issues/10233

changelog: none
2023-02-02 14:47:43 +00:00
Mara Bos
f7d59b2e57 Don't depend on FormatArgsExpn in ManualAssert. 2023-02-01 22:50:43 +01:00
bors
a2f85deba3 Auto merge of #10250 - tylerjw:issue_7419, r=xFrednet
wildcard_enum_match_arm lint takes the enum origin into account

fixes #7419

---

changelog: Enhancement: [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
[#10250](https://github.com/rust-lang/rust-clippy/pull/10250)
<!-- changelog_checked -->
2023-02-01 20:01:56 +00:00
bors
588c1ba3ff Auto merge of #10270 - kadiwa4:update_some_deps, r=flip1995
Update dependencies `cargo_metadata` and `clap`

changelog: none

Allows removing some duplicate dependencies in rust-lang/rust's `Cargo.lock`.
2023-02-01 16:34:05 +00:00
bors
75d76806c1 Auto merge of #10256 - SylvainDe:master, r=giraffate
Fix version declared for semicolon_inside_block and semicolon_outside…

As per Issue #10244, the lint were documentated
as being part of 1.66.0 but will actually be
released 1.68.0 .

changelog: [`semicolon_inside_block`]: Documentation fix
Fixes #10244
2023-02-01 00:24:04 +00:00
KaDiWa
ef2596155d
update some dependencies 2023-01-31 23:31:12 +01:00
bors
2880dccabb Auto merge of #10265 - Manishearth:uninlined-fmt-pedantic, r=Alexendoo
Mark uninlined_format_args as pedantic

Fixes https://github.com/rust-lang/rust-clippy/issues/10087

We should restore this when rust-analyzer support gets better. Worth filing an issue to track.

changelog: Mark [`uninlined_format_args`] as `pedantic`
2023-01-31 19:21:44 +00:00
Alex Macleod
6a8b20230b Add machine applicable suggestion for needless_lifetimes
Also adds a test for #5787
2023-01-31 14:12:03 +00:00
bors
607e3e893e Auto merge of #10114 - tgross35:option-let-else-wording, r=flip1995
option_if_let_else: update known problems wording

changelog: none
<!-- changelog_checked -->
2023-01-31 09:36:15 +00:00
bors
d227f18c2e Auto merge of #10225 - evantypanski:et/issue10132, r=flip1995
[`unused_io_amount`]: Lint with `is_ok` and `is_err`

Fixes #10132

changelog: Apply [`unused_io_amount`] lint to `is_ok` and `is_err` without checking read/write amount
2023-01-31 08:20:21 +00:00
Manish Goregaokar
b4e2b48270 Mark uninlined_format_args as pedantic 2023-01-30 19:28:27 -08:00
Tyler Weaver
df7cdf732d
Pull the is_external test out of the loop 2023-01-30 17:29:29 -07:00
Tyler Weaver
c531b09eb8
Check external before hidden 2023-01-30 17:29:29 -07:00
Tyler Weaver
2432e97d6a
wildcard_enum_match_arm lint takes the enum origin into account
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-30 17:29:29 -07:00
Tyler Weaver
4fde96c30e
Test needless_lifetimes within external macro
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-30 16:16:53 -07:00
bors
d020fd7fe6 Auto merge of #10260 - Niki4tap:external_macro_fp, r=xFrednet
`multiple_unsafe_ops_per_block`: Don't lint in external macros

Fixes #10259

changelog: FP: [`multiple_unsafe_ops_per_block`]: No longer lints in external macros
[#10260](https://github.com/rust-lang/rust-clippy/pull/10260)
<!-- changelog_none -->
2023-01-30 20:10:19 +00:00
bors
173fac0989 Auto merge of #10255 - khayyamsaleem:issue_9520, r=Jarcho
prevents `len_without_is_empty` from yielding positive when `len` takes arguments besides `&self`

Fixes #9520

---

changelog: FP [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
<!-- changelog_checked -->
2023-01-30 19:08:04 +00:00
Niki4tap
926c5e4cde multiple_unsafe_ops_per_block: don't lint in external macros 2023-01-30 20:42:40 +03:00
bors
d92070a7b9 Auto merge of #10254 - tylerjw:issue_6929, r=Manishearth
needless_range_loop: improve documentation

fixes #6929

changelog: [`needless_range_loop`]: improve documentation
2023-01-30 17:30:32 +00:00
Tyler Weaver
3b225e3a96
Update clippy_lints/src/loops/needless_range_loop.rs
Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>
2023-01-30 09:59:26 -07:00
bors
8fb0041f47 Auto merge of #10248 - koka831:missing-config, r=xFrednet
Missing config

This PR addresses https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Some.20lints.20miss.20its.20config/near/318460000.

changelog: Documentation: Made sure that lint configurations on Clippy's lint list are all up to date
[#10248](https://github.com/rust-lang/rust-clippy/pull/10248)
<!-- changelog_checked -->

r? `@xFrednet`

---

I have tried to create [a prototype](https://github.com/koka831/rust-clippy/pull/1), but have not yet found a good way to implement it.
So I would like to put it aside for now and try again after addressing other issues so that I can understand how clippy works better:)
2023-01-30 16:40:25 +00:00
koka
a9e6b12854
fix: use correct lint name
fix
2023-01-30 20:35:35 +09:00
Sylvain Desodt
ecde2019e9 Fix version declared for semicolon_inside_block and semicolon_outside_block
As per Issue #10244, the lint were documentated
as being part of 1.66.0 but will actually be
released 1.68.0 .
2023-01-30 10:01:38 +01:00
ksaleem
2fd94a4e01 prevents len_without_is_empty from yielding positive when len takes
more than just `&self` in non-standard implementations.

changelog: Fix [`len_without_is_empty`] false positive when len has a
non-standard method signature

Fixes #9520
2023-01-29 17:35:36 -05:00
Tyler Weaver
4d266d31de
needless_range_loop: improve documentation 2023-01-29 11:41:53 -07:00
bors
96c28d1f69 Auto merge of #10231 - Alexendoo:regex-spans, r=llogiq
`invalid_regex`: Show full error when string value doesn't match source

changelog: [`invalid_regex`]: Show full error when parsing non-literals or regular strings containing escape sequences

Fixes #4170, the escape sequence there causes the span to be incorrect which will have caused most of the confusion
2023-01-29 14:13:58 +00:00
koka
af62bf95a3
fix key name of MUTABLE_KEY_TYPE 2023-01-29 03:13:30 +09:00
koka
d87a6bc9b1
add MANUAL_RETAIN to msrv
MANUAL_RETAIN uses
- msrvs::STRING_RETAIN
- msrvs::BTREE_SET_RETAIN
- msrvs::BTREE_MAP_RETAIN
- msrvs::HASH_SET_RETAIN
- msrvs::HASH_MAP_RETAIN
2023-01-29 03:07:09 +09:00
koka
2f4b047b27
add MANUAL_REM_EUCLID to msrv
MANUAL_REM_EUCLID uses msrvs::REM_EUCLID
2023-01-29 03:04:56 +09:00
koka
1766532b20
add MANUAL_IS_ASCII_CHECK to msrv
MANUAL_IS_ASCII_CHECK uses msrvs::IS_ASCII_DIGIT and msrvs::IS_ASCII_DIGIT_CONST
2023-01-29 03:02:23 +09:00
koka
25d455bd17
fix: add missing dot to suppress_restriction_lint_in_const 2023-01-29 02:54:26 +09:00
koka
e791522d35
add DERIVABLE_IMPLS to msrv
DERIVABLE_IMPLS uses msrvs::DEFAULT_ENUM_ATTRIBUTE
2023-01-29 02:39:37 +09:00
koka
fb77b02789
add NEEDLESS_BORROW to msrv
NEEDLESS_BORROW uses msrvs::ARRAY_INTO_ITERATOR
2023-01-29 02:37:00 +09:00
koka
7716d69757
fix: add missing dot to AWAIT_HOLDING_INVALID_TYPE 2023-01-29 02:27:43 +09:00
koka
e65f9f9d32
add ALMOST_COMPLETE_RANGE to msrv
ALMOST_COMPLETE_RANGE uses msrvs::RANGE_INCLUSIVE
2023-01-29 02:22:10 +09:00
koka
07a8bf15ff
add TRANSMUTE_PTR_TO_REF to msrv
TRANSMUTE_PTR_TO_REF uses msrvs::POINTER_CAST
2023-01-29 02:14:38 +09:00
koka
532841fcae
add UNNECESSARY_LAZY_EVALUATIONS to msrv
UNNECESSARY_LAZY_EVALUATIONS uses msrvs::BOOL_THEN_SOME for `then` to
`then_some`
2023-01-29 02:02:46 +09:00
koka
a05e86f5dd
add SEEK_REWIND in msrv
SEEK_REWIND uses msrvs::SEEK_REWIND
2023-01-29 01:54:31 +09:00
koka
5a9c4a0090
add SEEK_FROM_CURRENT in msrv
SEEK_FROM_CURRENT uses msrvs::SEEK_FROM_CURRENT
2023-01-29 01:52:05 +09:00
koka
a0460cf37d
add COLLAPSIBLE_STR_REPLACE in msrv
COLLAPSIBLE_STR_REPLACE uses msrvs::PATTERN_TRAIT_CHAR_ARRAY
2023-01-29 01:49:10 +09:00
bors
79475f56ec Auto merge of #107206 - cjgillot:no-h2l-map, r=WaffleLapkin
Remove HirId -> LocalDefId map from HIR.

Having this map in HIR prevents the creating of new definitions after HIR has been built.
Thankfully, we do not need it.

Based on https://github.com/rust-lang/rust/pull/103902
2023-01-28 16:11:33 +00:00
bors
75c8179c25 Auto merge of #107408 - matthiaskrgr:rollup-b5vz2ow, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader)
 - #104252 (Stabilize the const_socketaddr feature)
 - #105524 (Replace libc::{type} with crate::ffi::{type})
 - #107096 (Detect references to non-existant messages in Fluent resources)
 - #107355 (Add regression test for #60755)
 - #107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`)
 - #107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`)
 - #107391 (rustdoc: remove inline javascript from copy-path button)
 - #107398 (Remove `ControlFlow::{BREAK, CONTINUE}`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-28 13:12:59 +00:00
Matthias Krüger
a493717718 Rollup merge of #107398 - scottmcm:its-their-funeral, r=dtolnay
Remove `ControlFlow::{BREAK, CONTINUE}`

Libs-API decided to remove these in #102697.

Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.

r? libs
2023-01-28 11:11:09 +01:00
bors
3a68217f49 Auto merge of #106916 - lukas-code:overlapping-substs, r=estebank
Remove overlapping parts of multipart suggestions

This PR adds a debug assertion that the parts of a single substitution cannot overlap, fixes a overlapping substitution from the testsuite, and fixes https://github.com/rust-lang/rust/issues/106870.

Note that a single suggestion can still have multiple overlapping substitutions / possible edits, we just don't suggest overlapping replacements in a single edit anymore.

I've also included a fix for an unrelated bug where rustfix for `explicit_outlives_requirements` would produce multiple trailing commas for a where clause.
2023-01-28 10:00:56 +00:00
Camille GILLOT
3e32533cc2 Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
Camille GILLOT
92c4f1e2d9 Take a LocalDefId in hir::Visitor::visit_fn. 2023-01-28 09:51:50 +00:00
Scott McMurray
e65a7ff0b3 Remove from librustdoc and clippy too 2023-01-27 20:44:19 -08:00
bors
06e785548b Auto merge of #101692 - cjgillot:generator-lazy-witness, r=oli-obk
Compute generator saved locals on MIR

Generators are currently type-checked by introducing a `witness` type variable, which is unified with a `GeneratorWitness(captured types)` whose purpose is to ensure that the auto traits correctly migrate from the captured types to the `witness` type.  This requires computing the captured types on HIR during type-checking, only to re-do it on MIR later.

This PR proposes to drop the HIR-based computation, and only keep the MIR one.  This is done in 3 steps.
1. During type-checking, the `witness` type variable is never unified.  This allows to stall all the obligations that depend on it until the end of type-checking.  Then, the stalled obligations are marked as successful, and saved into the typeck results for later verification.
2. At type-checking writeback, `witness` is replaced by `GeneratorWitnessMIR(def_id, substs)`.  From this point on, all trait selection involving `GeneratorWitnessMIR` will fetch the MIR-computed locals, similar to what opaque types do.  There is no lifetime to be preserved here: we consider all the lifetimes appearing in this witness type to be higher-ranked.
3. After borrowck, the stashed obligations are verified against the actually computed types, in the `check_generator_obligations` query.  If any obligation was wrongly marked as fulfilled in step 1, it should be reported here.

There are still many issues:
- ~I am not too happy having to filter out some locals from the checked bounds, I think this is MIR building that introduces raw pointers polluting the analysis;~ solved by a check specific to static variables.
- the diagnostics for captured types don't show where they are used/dropped;
- I do not attempt to support chalk.

cc `@eholk` `@jyn514` for the drop-tracking work
r? `@oli-obk` as you warned me of potential unsoundness
2023-01-28 01:05:29 +00:00
Philipp Krones
5c7a65251a Merge commit '1480cea393d0cee195e59949eabdfbcf1230f7f9' into clippyup 2023-01-27 21:09:08 +01:00
Philipp Krones
6f9c70a201
Bump Clippy version -> 0.1.69 2023-01-27 20:27:00 +01:00
Philipp Krones
2bc2431fd1
Merge remote-tracking branch 'upstream/master' into rustup 2023-01-27 20:26:35 +01:00
Camille GILLOT
ba6d3e7e9d Introduce GeneratorWitnessMIR. 2023-01-27 18:58:44 +00:00
Kyle Matsuda
afb586fa1f change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add EarlyBinder to fn_sig in metadata 2023-01-26 20:28:25 -07:00
Kyle Matsuda
38899d0c29 replace usages of fn_sig query with bound_fn_sig 2023-01-26 20:15:36 -07:00
Collin Styles
a1a01c19f1 Fix docs for suspicious_xor_used_as_pow lint
There was a tab after the three leading slashes which caused the
contents of the "Why is this bad?" section to be rendered as a code
block.
2023-01-26 16:52:39 -08:00
Alex Macleod
986f40fab0 invalid_regex: Show full error when string value doesn't match source 2023-01-26 15:33:40 +00:00
bors
a64940f948 Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering)

Implements https://github.com/rust-lang/compiler-team/issues/541

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-26 12:44:47 +00:00
Martin Fischer
20cc72e8a8 Improve span for module_name_repetitions 2023-01-25 07:07:10 +01:00
Evan Typanski
f9f75e0932 Lint unused_io_amount with is_ok and is_err 2023-01-24 18:22:35 -05:00
Vincenzo Palazzo
2d8ede2335 fix: use LocalDefId instead of HirId in trait res
use LocalDefId instead of HirId in trait resolution to simplify
the obligation clause resolution

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-01-23 11:42:18 +00:00
bors
a9c251f11d Auto merge of #10106 - koka831:fix/10084, r=Alexendoo
Fix FP in `unnecessary_safety_comment`

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

changelog: FP: [`unnecessary_safety_comment`]: No longer lints code inside macros
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
<!-- changelog_checked -->
2023-01-22 14:10:16 +00:00
Alex Macleod
5f49808bde Add machine applicable suggestion for bool_assert_comparison 2023-01-21 17:33:39 +00:00
bors
298a78277e Auto merge of #106977 - michaelwoerister:unord_id_collections, r=oli-obk
Use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc)

This PR changes the `rustc_data_structures::define_id_collections!` macro to use `UnordMap` and `UnordSet` instead of `FxHashMap` and `FxHashSet`. This should account for a large portion of hash-maps being used in places where they can cause trouble.

The changes required are moderate but non-zero:
- In some places the collections are extracted into sorted vecs.
- There are a few instances where for-loops have been changed to extends.

~~Let's see what the performance impact is. With a bit more refactoring, we might be able to get rid of some of the additional sorting -- but the change set is already big enough. Unless there's a performance impact, I'd like to do further changes in subsequent PRs.~~

Performance does not seem to be negatively affected ([perf-run here](https://github.com/rust-lang/rust/pull/106977#issuecomment-1396776699)).

Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).

r? `@ghost`
2023-01-21 14:18:17 +00:00
bors
ce460dcd14 Auto merge of #105102 - compiler-errors:copy-impl-considering-regions, r=lcnr
Check ADT fields for copy implementations considering regions

Fixes #88901
r? `@ghost`
2023-01-20 21:29:52 +00:00
Lukas Markeffsky
10c868686d fix overlapping spans for clippy::uninlined_format_args 2023-01-20 20:16:37 +01:00
xFrednet
e3a09eca6d
Update version attribute for 1.67 lints 2023-01-19 21:58:08 +01:00
bors
aa0eb7fb1c Auto merge of #10206 - Niki4tap:one_unsafe_op_per_block, r=Alexendoo
Add `multiple_unsafe_ops_per_block` lint

Adds a lint, which restricts an `unsafe` block to only one unsafe operation.

Closes #10064

---

changelog: New lint: [`multiple_unsafe_ops_per_block`]
[#10206](https://github.com/rust-lang/rust-clippy/pull/10206)
<!-- changelog_checked -->
2023-01-19 13:58:09 +00:00
Alex Macleod
11611b0440 Move unchecked_duration_subtraction to pedantic 2023-01-19 11:18:47 +01:00
Michael Woerister
c1b358945a Allow for more efficient sorting when exporting Unord collections. 2023-01-19 10:40:54 +01:00
Michael Woerister
465ed5bd46 Use UnordMap instead of FxHashMap in define_id_collections!(). 2023-01-19 10:40:47 +01:00
Michael Woerister
31a053059e Use UnordSet instead of FxHashSet in define_id_collections!(). 2023-01-19 10:19:07 +01:00
Niki4tap
875e36f7e4 Add multiple_unsafe_ops_per_block lint 2023-01-18 10:00:31 +03:00
bors
89d443a4c3 Auto merge of #10193 - Jarcho:issue_9894, r=Manishearth
Fix suggestion in `transmutes_expressible_as_ptr_casts` when the source type is a borrow.

fixes #9894

changelog: `transmutes_expressible_as_ptr_casts`: Fix suggestion when the source type is a borrow.
2023-01-17 14:58:39 +00:00
bors
07a7603994 Auto merge of #10187 - dswij:issue-10182-semicolon, r=Jarcho
[needless_return]: Remove all semicolons on suggestion

Closes #10182

Multiple semicolons currently breaks autofix for `needless_return` suggestions. Any semicolons left after removing return means that the return type will always be `()`, and thus fail to compile.

This PR allows `needless_return` to remove multiple semicolons.

The change won't cover the case where there is multiple line yet.

i.e.

```rust
fn needless_return() -> bool {
    return true;
;;
}
```

---

changelog: Sugg: [`needless_return`]: Now removes all semicolons on the same line
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
<!-- changelog_checked -->
2023-01-15 15:49:40 +00:00
bors
aceb4439d6 Auto merge of #10199 - tylerjw:document-extending-list-configs, r=xFrednet
Document lint configuration values in Clippy's book

changelog: document lint configuration values in Clippy's book

fixes #9991

r? `@xFrednet`
2023-01-14 18:14:31 +00:00
Tyler Weaver
c0da8acb72
Comment that lint_configuration.md is machine generated 2023-01-14 11:10:40 -07:00
bors
483b7ac918 Auto merge of #10038 - xFrednet:9231-sugg-try-from, r=Jarcho
`cast_possible_truncation` Suggest TryFrom when truncation possible

This fixes the last issues from https://github.com/rust-lang/rust-clippy/pull/9664 as the author seems to be inactive. The PR author was sadly kept during the rebase, due to the conflict resolution.

IDK if it's worth it do to a full review, I only added the last commit, everything else remained the same, besides a rebase.

---

changelog: Sugg: [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
<!-- changelog_checked -->

closes: https://github.com/rust-lang/rust-clippy/issues/9231
2023-01-14 16:04:51 +00:00
Kyle Matsuda
b92d90211e change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata 2023-01-14 00:29:56 -07:00
Kyle Matsuda
a160ce3a48 change usages of impl_trait_ref to bound_impl_trait_ref 2023-01-14 00:23:32 -07:00
Tyler Weaver
7d1609dce3
Document configurations in table and paragraphs
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-13 16:26:46 -07:00
Michael Goulet
93d0f47064 Check ADT fields for copy implementations considering regions 2023-01-13 23:06:29 +00:00
Tyler Weaver
2e2ae68d5a
Document lint configuration values in Clippy's book
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-13 11:48:51 -07:00
bors
efb631a09c Auto merge of #106776 - oli-obk:om_nom_nom_nom_nom, r=cjgillot
Feed a bunch of queries instead of tracking fields on TyCtxt

r? `@cjgillot`

pulled out of https://github.com/rust-lang/rust/pull/105462
2023-01-13 13:57:21 +00:00
Alex Macleod
295225e9cd Move unchecked_duration_subtraction to pedantic 2023-01-13 00:04:28 +00:00
Jason Newcomb
b38848d8f7 Fix suggestion in transmutes_expressible_as_ptr_casts when the source type is a borrow. 2023-01-12 16:01:24 -05:00
Philipp Krones
d21616737b Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup 2023-01-12 19:48:13 +01:00
bors
7f27e2e74e Auto merge of #10192 - Jarcho:revert_9701, r=flip1995
Partially revert #9701

This partially reverts #9701 due to #10134

r? `@flip1995`

changelog: None
2023-01-12 18:47:17 +00:00
Jason Newcomb
5eed9c69ca Revert 4dbd8ad34e, c7dc961558, ed519ad746 and c6477eb711 2023-01-12 13:28:22 -05:00
Philipp Krones
631481ffb3
Merge remote-tracking branch 'upstream/master' into rustup 2023-01-12 18:59:59 +01:00
Oli Scherer
0c48b5a223 Feed the features_query instead of grabbing it from the session lazily 2023-01-12 17:14:17 +00:00
bors
decaba97cc Auto merge of #10184 - robertbastian:master, r=xFrednet
Allow implementing `Hash` with derived `PartialEq` (`derive_hash_xor_eq`

This is a common pattern and is totally allowed by the `Hash` trait.

Fixes #2627

changelog: Move: Renamed `derive_hash_xor_eq` to [`derived_hash_with_manual_eq`]
[#10184](https://github.com/rust-lang/rust-clippy/pull/10184)
changelog: Enhancement: [`derived_hash_with_manual_eq`]: Now allows `#[derive(PartialEq)]` with custom `Hash` implementations
[#10184](https://github.com/rust-lang/rust-clippy/pull/10184)
<!-- changelog_checked -->
2023-01-12 14:59:41 +00:00
bors
7c01721434 Auto merge of #10179 - llogiq:trim-suspicious-to-owned-paths, r=xFrednet
trim paths in `suspicious_to_owned`

This continues my path trimming spree. I'm not going to add yet another changelog entry, we should have one "trim paths in some applicable lints" entry instead.

---

changelog: none
2023-01-12 12:10:56 +00:00
xFrednet
5cb6246c3e
Address PR reivew 2023-01-12 12:37:56 +01:00
xFrednet
e6948c4117
Last PR adjustments 2023-01-12 12:16:08 +01:00
navh
fcdd08badf
update cast_possible_truncation documentation 2023-01-12 12:16:07 +01:00
navh
51aaba6e8c
cast_possible_truncation Suggest TryFrom when truncation possible 2023-01-12 12:16:06 +01:00
Mara Bos
2bcd697e2d Update clippy for new format_args!() lang items. 2023-01-12 00:25:46 +01:00
Alex Macleod
34024adc88 expl_impl_clone_on_copy: ignore packed structs with type/const params 2023-01-11 17:37:19 +00:00
Andre Bogus
bd76d9133b trim paths in suspicious_to_owned 2023-01-11 16:39:34 +01:00
bors
15226f91bb Auto merge of #10166 - sulami:master, r=giraffate
unused_self: Don't trigger if the method body contains todo!()

If the author is using todo!(), presumably they intend to use self at some point later, so we don't have a good basis to recommend factoring out to an associated function.

Fixes #10117.

---

changelog: Enhancement: [`unused_self`]: No longer lints, if the method body contains a `todo!()` call
[#10166](https://github.com/rust-lang/rust-clippy/pull/10166)
<!-- changelog_checked -->
2023-01-11 00:30:19 +00:00
dswij
d73adea465 needless_return: remove multiple semis on suggestion 2023-01-11 07:09:57 +08:00
Robert Bastian
8ca900b01c rename 2023-01-10 11:12:54 +01:00
Robert Bastian
53c12e085a hash xor peq 2023-01-09 21:29:42 +01:00
koka
1a7ef02dcb
Fix fp in unnecessary_safety_comment 2023-01-09 18:49:46 +09:00
bors
cf1d3d0370 Auto merge of #10162 - tamaroning:fix10018, r=xFrednet
Fix FP of single-element-loop

closes #10018

---

changelog: [`single_element_loop`]: No longer lints, if the loop contains a `break` or `continue`
[#10162](https://github.com/rust-lang/rust-clippy/pull/10162)
<!-- changelog_checked -->
2023-01-07 11:53:45 +00:00
Raiki Tamura
ce56cf71d9 chore 2023-01-07 20:44:02 +09:00
bors
ef5a545f98 Auto merge of #10164 - khuey:default_enum_unit_variant_msrv, r=llogiq
Restrict suggestion of deriving Default for enums to MSRV 1.62.

See https://blog.rust-lang.org/2022/06/30/Rust-1.62.0.html#default-enum-variants

---

changelog: none
2023-01-07 00:28:00 +00:00
bors
19b79c485e Auto merge of #10168 - blyxyas:fix_reversed_empty_ranges, r=dswij
[#10167] Clarify that the lint only works if x eq. y in a `for` loop.

Reading the documentation for the lint, one could expect that the lint works in all cases that `X == Y`. This is false.

While the lint was updated, the documentation wasn't.

More information about the `N..N` problem in #5689 and #5628

---

Fixes #10167
changelog: [`reversed_empty_ranges`]: Update and clarify documentation
2023-01-06 18:55:20 +00:00
Caio
4262aebeaa [arithmetic-side-effects] Consider negative numbers and add more tests 2023-01-06 12:25:51 -03:00
blyxyas
1b9a25e28d
[#10167] Clarify that the lint only works if x eq. y in a for loop.
Reading the documentation for the lint, one could expect that the lint works in all cases that `X == Y`. This is false.

While the lint was updated, the documentation wasn't.

More information about the `N..N` problem in #5689 and #5628
2023-01-06 14:41:50 +01:00
bors
179a22f624 Auto merge of #10153 - llogiq:box-default-trim-paths, r=Jarcho
trim paths in `box_default`

This might help with #10089, though I have not tested that yet. In any event, it keeps the suggestion short and to the point.

---
changelog: Trim paths in [`box_default`] suggestion
2023-01-06 09:21:27 +00:00
bors
3f48ed523f Auto merge of #10160 - llogiq:default-trim-paths, r=dswij
trim paths in `default_trait_access`/`clone_on_copy` suggestions

This should help making the suggestions more palatable. Similar to #10153.

---

changelog: trim paths in [`default_trait_access`]/[`clone_on_copy`] suggestions
2023-01-06 09:07:58 +00:00
bors
3816f9a6f9 Auto merge of #10137 - euclio:dbg-macro, r=giraffate
reword dbg_macro labels

---

This change rewords the `dbg_macro` lint labels to be clearer.

changelog: none
<!-- changelog_checked -->
2023-01-06 05:25:34 +00:00
Robin Schroer
e443604a24
unused_self: Don't trigger if the method body contains todo!()
If the author is using todo!(), presumably they intend to use self at
some point later, so we don't have a good basis to recommend factoring
out to an associated function.

Fixes #10117.

changelog: Don't trigger [`unused_self`] if the method body contains a `todo!()` call
2023-01-06 12:58:51 +09:00
bors
4f4c96155a Auto merge of #10142 - EricWu2003:drop_ref-FP, r=llogiq
[`drop_ref`]: don't lint idiomatic in match arm

fixes #10122

As established in issue #9482, it is idiomatic to use a single `drop()` expression in a match arm to achieve a side-effect of a function while discarding its output. This should also apply to cases where the function returns a reference.

The change to the lint's code was less than 1 line, because all the heavy lifting was done in PR #9491.

---

changelog: FP: [`drop_ref`]: No longer lints idiomatic expression in `match` arms
[#10142](https://github.com/rust-lang/rust-clippy/pull/10142)
<!-- changelog_checked -->
2023-01-05 23:36:49 +00:00
Kyle Huey
6433d796a1 Restrict suggestion of deriving Default for enums to MSRV 1.62.
See https://blog.rust-lang.org/2022/06/30/Rust-1.62.0.html#default-enum-variants
2023-01-05 13:06:43 -08:00
Raiki Tamura
79ed23ff81 fix 2023-01-05 18:30:13 +09:00
Kyle Huey
1c42dbba60 Expand derivable-impls to cover enums with a default unit variant. 2023-01-04 19:08:37 -08:00
bors
d5d8ef13d7 Auto merge of #10159 - khuey:iter_kv_map_ref_mut, r=llogiq
Make the iter_kv_map lint handle ref/mut annotations.

For the degenerate (`map(|(k, _)| k)`/`map(|(_, v)| v)`) cases a mut annotation is superfluous and a ref annotation won't compile, so no additional handling is required. For cases where the `map` call must be preserved ref/mut annotations should also be presereved so that the map body continues to work as expected.

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

changelog: [`iter_kv_map`]: handle ref/mut annotations
2023-01-04 23:13:39 +00:00
Kyle Huey
755ae3fa29 Fix spelling while we're in the neighborhood. 2023-01-04 14:58:07 -08:00
Andre Bogus
05ba519a3a trim paths in default_trait_access/clone_on_copy suggestions 2023-01-04 23:39:46 +01:00
Kyle Huey
d0c1605d51 Make the iter_kv_map lint handle ref/mut annotations.
For the degenerate (`map(|(k, _)| k)`/`map(|(_, v)| v)`) cases a mut annotation is superfluous and a ref annotation won't compile, so no additional handling is required. For cases where the `map` call must be preserved ref/mut annotations should also be presereved so that the map body continues to work as expected.
2023-01-04 13:32:34 -08:00
bors
a385d34fc2 Auto merge of #10107 - tylerjw:suggest_path, r=Alexendoo
Suggest using Path for comparing extensions

fixes #10042

changelog: Sugg: [`case_sensitive_file_extension_comparisons`]: Now displays a suggestion with `Path`
[#10107](https://github.com/rust-lang/rust-clippy/pull/10107)
<!-- changelog_checked -->
2023-01-04 19:27:11 +00:00
Tyler Weaver
ea6ff7ed04
Apply changes suggested in review 2023-01-04 07:06:07 -07:00
Michael Goulet
70f6c478f6 get_parent and find_parent 2023-01-04 00:43:13 +00:00
Michael Goulet
bd1d8971cf rename find_parent_node to opt_parent_id 2023-01-04 00:43:13 +00:00
Michael Goulet
73d293fb6d rename get_parent_node to parent_id 2023-01-04 00:43:13 +00:00
Andre Bogus
d3a50d2fda trim paths in box_default 2023-01-04 00:44:20 +01:00
bors
8b1ac4539d Auto merge of #10141 - FoseFx:fosefx/9887, r=Jarcho
fix empty_structs_with_brackets suggestion errors

fixes #9887

I refer to [my comment](https://github.com/rust-lang/rust-clippy/issues/9887#issuecomment-1368495395) to explain this PR.

---

changelog: Sugg: [`empty_structs_with_brackets`]: The suggestion is no longer machine applicable, to avoid errors when accessing struct fields
[#10141](https://github.com/rust-lang/rust-clippy/pull/10141)
<!-- changelog_checked -->
2023-01-03 03:57:19 +00:00
bors
43349195f7 Auto merge of #10143 - EricWu2003:field_reassign_with_default-FP, r=Manishearth
don't lint field_reassign when field in closure

fixes #10136

This change makes the ContainsName struct visit all interior expressions, which means that ContainsName will return true even if `name` is used in a closure within `expr`.

---

changelog: FP: [`field_reassign_with_default`]: No longer lints cases, where values are initializes from closures capturing struct values
[#10143](https://github.com/rust-lang/rust-clippy/pull/10143)
<!-- changelog_checked -->
2023-01-03 03:16:18 +00:00
Tyler Weaver
0cee2c5095
Don't trigger lint if last method is to_lower/upper 2023-01-02 16:42:56 -07:00
Tyler Weaver
0aa7d73df3
Only remove method from end of recv, indent suggestion source
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-02 16:27:46 -07:00
Tyler Weaver
bd83650e91
Suggest using Path for comparing extensions
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-02 16:27:46 -07:00
bors
1a46dc0b9f Auto merge of #10138 - smoelius:unused_self-typo, r=xFrednet
Fix typo in `unused_self` diagnostic message

changelog: Msg: [`unused_self`]: The message now correctly uses *an*
[#10138](https://github.com/rust-lang/rust-clippy/pull/10138)
<!-- changelog_checked -->
2023-01-02 22:57:27 +00:00
bors
653f5d98d8 Auto merge of #10139 - chansuke:chore/fix-if_chain_ident, r=Jarcho
chore: fix identation of `if_chain` in `filter_map`

This is a really small fix.
If someone could take a look at it, I would appreciate it🙏

---

changelog: none
<!-- changelog_checked -->
2023-01-02 22:44:15 +00:00
Nilstrieb
f53c6e2f15 Correct Gankra's name in the linkedlist lint 2023-01-02 19:58:00 +01:00
Andy Russell
9aef1a264a
reword dbg_macro labels 2023-01-02 12:09:26 -05:00
Max Baumann
7a1a9c8188
empty_structs_with_brackets: not MachineApplicable anymore 2023-01-02 14:58:10 +01:00
Eric Wu
01a2a9df43 [drop_ref]: don't lint idiomatic in match arm 2023-01-01 22:33:18 -05:00
Eric Wu
8de011fdf7 don't lint field_reassign when field in closure
This commit makes the ContainsName struct visit all interior
expressions, which means that ContainsName will return true
even if `name` is used in a closure within `expr`.
2023-01-01 21:41:46 -05:00
chansuke
5b46f2db59 chore: fix identation of if_chain in filter_map 2023-01-02 00:17:52 +09:00
bors
a85e480dd1 Auto merge of #10110 - Niki4tap:needless_anyhow_return, r=Alexendoo
Fix FN in `needless_return`

Fixes #10051

changelog: Enhancement: [`needless_return`]: Now detects more cases for returns of owned values
[#10110](https://github.com/rust-lang/rust-clippy/pull/10110)
<!-- changelog_checked -->
2023-01-01 13:55:29 +00:00
Samuel Moelius
da7c99b81e Fix typo in unused_self diagnostic message 2023-01-01 06:21:28 -05:00
Trevor Gross
ca5f4a1dee option_if_let_else: update known problems wording 2022-12-30 16:10:21 -05:00
bors
6ccd4ebd5b Auto merge of #10115 - rdrpenguin04:master, r=flip1995
Move `mutex_atomic` to `restriction`

By #4295, the general consensus seems to be that `mutex_atomic` is not a useful lint in most cases. If anything, it could be useful as a restriction on code that for whatever reason can't use atomics. Keeping it in `clippy::nursery` is harmful to people attempting to use clippy for soundness.

---

changelog: Moved [`mutex_atomic`] to `restriction`
[#10115](https://github.com/rust-lang/rust-clippy/pull/10115)
<!-- chnagelog_checked -->
2022-12-30 15:49:12 +00:00
Ray Redondo
0298095ac2 add comment about mutex_atomic issue to description 2022-12-29 14:48:36 -06:00
bors
cd579d69ec Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params)
 - #105899 (`./x doc library --open` opens `std`)
 - #106190 (Account for multiple multiline spans with empty padding)
 - #106202 (Trim more paths in obligation types)
 - #106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing)
 - #106236 (docs/test: add docs and a UI test for `E0514` and `E0519`)
 - #106259 (Update Clippy)
 - #106260 (Fix index out of bounds issues in rustdoc)
 - #106263 (Formatter should not try to format non-Rust files)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-29 19:40:06 +00:00
Philipp Krones
4ccafea92d Merge commit '4f3ab69ea0a0908260944443c739426cc384ae1a' into clippyup 2022-12-29 14:28:34 +01:00
bors
22af8fe683 Auto merge of #10060 - alex-semenyuk:match_single_binding_fix, r=llogiq
Fix [match_single_binding] suggestion introduced an extra semicolon

Fix #9725

---

changelog: [`match_single_binding`]: suggestion no longer introduces unneeded semicolons
[#10060](https://github.com/rust-lang/rust-clippy/pull/10060)
<!-- changelog_checked -->
2022-12-29 09:23:03 +00:00
Nilstrieb
c617a8e01c Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
bors
266eef7701 Auto merge of #10119 - koka831:doc/config-default-value, r=xFrednet
fix codeblocks in the document

While I've looked into https://github.com/rust-lang/rust-clippy/issues/9990, I found broken code blocks in the document.

This patch not only improves visibility, but also fixes a potential bug. When a lint description ends with code block, the string will have three backquotes at the end.
Since the current implementation prints the default value immediately after that, the markdown renderer is unable to properly close the code block.

e.g. `arithmetic_side_effects`, we can see code block is not rendered properly, and (I think) it's bit hard to understand what ``"defaults to `[]`"`` is meant.

![2022-12-26_01-51](https://user-images.githubusercontent.com/14945055/209476342-4d0b2e18-44b6-4c74-8c3c-4f4f0904e8ca.png)

In this PR, it will be rendered as:

![image](https://user-images.githubusercontent.com/14945055/209476353-07587b86-1100-445f-946d-41f62f741e51.png)

changelog: none

r? `@xFrednet`
2022-12-28 13:53:34 +00:00
bors
d98e714988 Auto merge of #10113 - EricWu2003:suboptimal_flops_incorrect_suggestion, r=Jarcho
fix incorrect suggestion in `suboptimal_flops`

fixes #10003

There was an error when trying to negate an expression like `x - 1.0`. We used to format it as `-x - 1.0` whereas a proper negation would be `-(x - 1.0)`.

Therefore, we add parentheses around the expression when it is `ExprKind::Binary`.

We also add parentheses around multiply and divide expressions, even though this is not strictly necessary.

changelog: [`suboptimal_flops`]: fix incorrect suggestion caused by an incorrect negation of floating point expressions.
2022-12-26 02:00:26 +00:00
Eric Wu
6bb6dd64d4 fix incorrect suggestion in suboptimal_flops
There was an error when trying to negate an expression
like `x - 1.0`. We used to format it as `-x - 1.0` whereas
a proper negation would be `-(x - 1.0)`.

Therefore, we add parentheses around the expression when it is a
Binary ExprKind.

We also add parentheses around multiply and divide expressions,
even though this is not strictly necessary.
2022-12-25 16:56:46 -05:00
koka
fae19a9a79
Place default values near its definitions
This patch not only improves visibility, but also fixes a potential bug.
When a lint description ends with code block, the string will have three
backquotes at the end.
Since the current implementation prints the default value immediately
after that, the markdown renderer is unable to properly close the code
block.
2022-12-26 01:51:46 +09:00
Trevor Gross
12f2dea229 not_unsafe_ptr_arg_deref update documentation 2022-12-25 07:30:21 -05:00
Ray Redondo
0e5fcb7b7f move mutex_atomic to clippy::restriction 2022-12-24 23:47:14 -06:00
bors
e8703a0ce2 Auto merge of #10098 - lukaslueg:size_of_ref, r=Jarcho
Add size_of_ref lint

This addresses #9995, which is likely raising a valid point about `std::mem::size_of_val()`: It's [very easy to use double-references as the argument](https://github.com/apache/arrow-datafusion/pull/4371#discussion_r1032385224), which the function will happily accept and give back the size of _the reference_, not the size of the value _behind_ the reference. In the worst case, if the value matches the programmer's expectation, this seems to work, while in fact, everything will go horribly wrong e.g. on a different platform.

The size of a `&T` is independent of what `T` is, and people might want to use `std::mem::size_of_val()` to actually get the size of _any_ reference (e.g. via `&&()`). I would rather suggest that this is always bad behavior, though ([instead](https://doc.rust-lang.org/reference/type-layout.html#pointers-and-references-layout), [and](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.BITS)). I, therefore, put this lint into `correctness`.

Since the problem is usually easily fixed by removing extra `&`, I went light on suggesting code.

---

changelog: New lint: [`size_of_ref`]
[#10098](https://github.com/rust-lang/rust-clippy/pull/10098)
<!-- changelog_checked -->
2022-12-24 23:33:13 +00:00
Lukas Lueg
d7b9e195c2 Add size_of_ref lint
Fixes #9995
2022-12-24 23:39:54 +01:00
Niki4tap
a935826071 Fix the actual bug 2022-12-23 00:57:28 +03:00
Niki4tap
0cd9b06125 Small code style adjustments 2022-12-23 00:56:50 +03:00
bors
4fe3727c39 Auto merge of #9701 - smoelius:improve-possible-borrower, r=Jarcho
Improve `possible_borrower`

This PR makes several improvements to `clippy_uitls::mir::possible_borrower`. These changes benefit both `needless_borrow` and `redundant clone`.

1. **Use the compiler's `MaybeStorageLive` analysis**

I could spot not functional differences between the one in the compiler and the one in Clippy's repository. So, I removed the latter in favor of the the former.

2. **Make `PossibleBorrower` a dataflow analysis instead of a visitor**

The main benefit of this change is that allows `possible_borrower` to take advantage of statements' relative locations, which is easier to do in an analysis than in a visitor.

This is easier to illustrate with an example, so consider this one:
```rust
    fn foo(cx: &LateContext<'_>, lint: &'static Lint) {
        cx.struct_span_lint(lint, rustc_span::Span::default(), "", |diag| diag.note(&String::new()));
        //                                                                          ^
    }
```
We would like to flag the `&` pointed to by the `^` for removal. `foo`'s MIR begins like this:
```rust
fn span_lint::foo::{closure#0}(_1: [closure@$DIR/needless_borrow.rs:396:68: 396:74], _2: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>) -> &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()> {
    debug diag => _2;                    // in scope 0 at $DIR/needless_borrow.rs:396:69: 396:73
    let mut _0: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // return place in scope 0 at $DIR/needless_borrow.rs:396:75: 396:75
    let mut _3: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // in scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
    let mut _4: &mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>; // in scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
    let mut _5: &std::string::String;    // in scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
    let _6: std::string::String;         // in scope 0 at $DIR/needless_borrow.rs:396:86: 396:99

    bb0: {
        StorageLive(_3);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        StorageLive(_4);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        _4 = &mut (*_2);                 // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
        StorageLive(_5);                 // scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
        StorageLive(_6);                 // scope 0 at $DIR/needless_borrow.rs:396:86: 396:99
        _6 = std::string::String::new() -> bb1; // scope 0 at $DIR/needless_borrow.rs:396:86: 396:99
                                         // mir::Constant
                                         // + span: $DIR/needless_borrow.rs:396:86: 396:97
                                         // + literal: Const { ty: fn() -> std::string::String {std::string::String::new}, val: Value(<ZST>) }
    }

    bb1: {
        _5 = &_6;                        // scope 0 at $DIR/needless_borrow.rs:396:85: 396:99
        _3 = rustc_errors::diagnostic_builder::DiagnosticBuilder::<'_, ()>::note::<&std::string::String>(move _4, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/needless_borrow.rs:396:75: 396:100
                                         // mir::Constant
                                         // + span: $DIR/needless_borrow.rs:396:80: 396:84
                                         // + literal: Const { ty: for<'a> fn(&'a mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()>, &std::string::String) -> &'a mut rustc_errors::diagnostic_builder::DiagnosticBuilder<'_, ()> {rustc_errors::diagnostic_builder::DiagnosticBuilder::<'_, ()>::note::<&std::string::String>}, val: Value(<ZST>) }
    }
```
The call to `diag.note` appears in `bb1` on the line beginning with `_3 =`. The `String` is owned by `_6`. So, in the call to `diag.note`, we would like to know whether there are any references to `_6` besides `_5`.

The old, visitor approach did not consider the relative locations of statements. So all borrows were treated the same, *even if they occurred after the location of interest*.

For example, before the `_3 = ...` call, the possible borrowers of `_6` would be just `_5`. But after the call, the possible borrowers would include `_2`, `_3`, and `_4`.

So, in a sense, the call from which we are try to remove the needless borrow is trying to prevent us from removing the needless borrow(!).

With an analysis, things do not get so muddled. We can determine the set of possible borrowers at any specific location, e.g., using a `ResultsCursor`.

3. **Change `only_borrowers` to `at_most_borrowers`**

`possible_borrowers` exposed a function `only_borrowers` that determined whether the borrowers of some local were *exactly* some set `S`. But, from what I can tell, this was overkill. For the lints that currently use `possible_borrower` (`needless_borrow` and `redundant_clone`), all we really want to know is whether there are borrowers *other than* those in `S`. (Put another way, we only care about the subset relation in one direction.) The new function `at_most_borrowers` takes this more tailored approach.

4. **Compute relations "on the fly" rather than using `transitive_relation`**

The visitor would compute and store the transitive closure of the possible borrower relation for an entire MIR body.

But with an analysis, there is effectively a different possible borrower relation at each location in the body. Computing and storing a transitive closure at each location would not be practical.

So the new approach is to compute the transitive closure on the fly, as needed. But the new approach might actually be more efficient, as I now explain.

In all current uses of `at_most_borrowers` (previously `only_borrowers`), the size of the set of borrowers `S` is at most 2. So you need only check at most three borrowers to determine whether the subset relation holds. That is, once you have found a third borrower, you can stop, since you know the relation cannot hold.

Note that `transitive_relation` is still used by `clippy_uitls::mir::possible_origin` (a kind of "subroutine" of `possible_borrower`).

cc: `@Jarcho`

---

changelog: [`needless_borrow`], [`redundant_clone`]: Now track references better and detect more cases
[#9701](https://github.com/rust-lang/rust-clippy/pull/9701)
<!-- changelog_checked -->
2022-12-22 15:08:04 +00:00
bors
8a6e6fd623 Auto merge of #10056 - koka831:fix/9993, r=Jarcho
Avoid `match_wildcard_for_single_variants` on guarded wild matches

fix #9993

changelog: FP: [`match_wildcard_for_single_variants`]: No longer lints on wildcards with a guard
[#10056](https://github.com/rust-lang/rust-clippy/pull/10056)
<!-- changelog_checked -->

r? `@Jarcho`
2022-12-22 14:54:50 +00:00
Niki4tap
b6882f6107 Fix FP in needless_return when using yeet 2022-12-22 12:47:39 +03:00
bors
065c6f78e7 Auto merge of #10091 - EricWu2003:manual-filter-FP, r=llogiq
fix manual_filter false positive

fixes #10088
fixes #9766

changelog: FP: [`manual_filter`]: Now ignores if expressions where the else branch has side effects or doesn't return `None`
[#10091](https://github.com/rust-lang/rust-clippy/pull/10091)
<!-- changelog_checked -->
2022-12-21 19:39:32 +00:00
bors
4a09068f87 Auto merge of #10063 - chansuke:issue-9702, r=Alexendoo
add [`permissions_set_readonly_false`] #9702

Add slight modification on [this PR](https://github.com/rust-lang/rust-clippy/pull/9744).

---

changelog: New lint [`permissions_set_readonly_false`]
[#10063](https://github.com/rust-lang/rust-clippy/pull/10063)
<!-- changelog_checked -->
2022-12-20 16:03:11 +00:00
chansuke
b21cc36ee9 hotfix: add help dialog for PermissionExt 2022-12-20 23:43:34 +09:00
Samuel Moelius
26df55112f Fix adjacent code 2022-12-20 05:12:13 -05:00
Samuel Moelius
ed519ad746 Improve possible_borrower 2022-12-20 05:12:13 -05:00
chansuke
e1d3c1e8f1 refactor: fix style 2022-12-20 00:37:53 +09:00
dboso
30e6e85508 add [permissions_set_readonly_false] #9702 2022-12-20 00:37:51 +09:00
Niki4tap
d0ac6ba0b1 Fix overflow ICE in large_stack/const_arrays 2022-12-19 18:27:42 +03:00
bors
b3145fea6a Auto merge of #10099 - Niki4tap:null_fn_lints, r=llogiq
Null fn lints

Adds lints to check for code, that assumes nullable `fn()`.

### Lint examples:

`transmute_null_to_fn`:
```rust
error: transmuting a known null pointer into a function pointer
  --> $DIR/transmute_null_to_fn.rs:9:23
   |
LL |         let _: fn() = std::mem::transmute(std::ptr::null::<()>());
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
```

`fn_null_check`:
```rust
error: function pointer assumed to be nullable, even though it isn't
  --> $DIR/fn_null_check.rs:13:8
   |
LL |     if (fn_ptr as *mut ()).is_null() {}
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
```

Closes #1644

---

changelog: Improvement: [`transmuting_null`]: Now detects `const` pointers to all types
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`transmute_null_to_fn`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`fn_null_check`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
<!-- changelog_checked (This is just a flag for me, please don't add it manually) -->
2022-12-19 12:44:23 +00:00
Niki4tap
691df70bbc Inline some consts 2022-12-19 15:34:55 +03:00
Philipp Krones
62061b8a05
Move manual_clamp to nursery 2022-12-19 09:44:56 +01:00
Niki4tap
cc98574883 Fix comments, use constant instead of raw constant_context 2022-12-18 22:47:02 +03:00
Niki4tap
20f501a9d9 Improve code style further 2022-12-18 22:39:06 +03:00
Niki4tap
9b2fc8e2a2 Make clippy happy 2022-12-18 19:43:26 +03:00
bors
910a97d7ce Auto merge of #10020 - samueltardieu:more-into-iter-removal, r=xFrednet
Identify more cases of useless `into_iter()` calls

changelog: Sugg: [`useless_conversion`]: Now suggests removing calls to `into_iter()` on an expression implementing `Iterator`
[#10020](https://github.com/rust-lang/rust-clippy/pull/10020)
<!-- changelog_checked -->
2022-12-18 16:01:29 +00:00
Niki4tap
b1ca307168 Address some of the code style issues 2022-12-18 18:58:15 +03:00
Niki4tap
dae54fad3e Doc codeblock fixup 2022-12-18 03:20:04 +03:00
Niki4tap
54a9168efb Remove useless pattern matching 2022-12-18 03:02:45 +03:00
Niki4tap
42106e0495 Add lint fn_null_check 2022-12-18 03:02:45 +03:00
Niki4tap
3cc67d0856 Relax clippy_utils::consts::miri_to_const pointer type restrictiveness 2022-12-18 03:02:45 +03:00
Niki4tap
6afe5471cf Add lint transmute_null_to_fn 2022-12-18 03:02:37 +03:00
Samuel Tardieu
af39a8a4a8 Identify more cases of useless into_iter() calls
If the type of the result of a call to `IntoIterator::into_iter()`
and the type of the receiver are the same, then the receiver
implements `Iterator` and `into_iter()` is the identity function.

The call to `into_iter()` may be removed in all but two cases:

- If the receiver implements `Copy`, `into_iter()` will produce
  a copy of the receiver and cannot be removed. For example,
  `x.into_iter().next()` will not advance `x` while `x.next()` will.
- If the receiver is an immutable local variable and the call to
  `into_iter()` appears in a larger expression, removing the call to
  `into_iter()` might cause mutability issues. For example, if `x`
  is an immutable local variable, `x.into_iter().next()` will
  compile while `x.next()` will not as `next()` receives
  `&mut self`.
2022-12-17 16:20:43 +01:00
Philipp Krones
1c422524c7 Merge commit '4bdfb0741dbcecd5279a2635c3280726db0604b5' into clippyup 2022-12-17 14:12:54 +01:00
bors
4bdfb0741d Auto merge of #10097 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

I'm on the train and my internet is too bad to download the necessary toolchain, so I have to use CI to find sync fallout.

changelog: none
<!-- changelog_checked -->
2022-12-17 13:08:47 +00:00
Philipp Krones
1f1d23cf51
Bump Clippy version -> 0.1.68 2022-12-17 13:57:41 +01:00
Philipp Krones
d6488ae144
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-17 13:56:32 +01:00
bors
391b2a6fac Auto merge of #10096 - feniljain:fix-seek-rewind, r=xFrednet
fix: not suggest seek_to_start_instead_of_rewind when expr is used

changelog: [`seek_to_start_instead_of_rewind`]: No longer lints, if the return of `seek` is used.
[#10096](https://github.com/rust-lang/rust-clippy/pull/10096)
<!-- changelog_checked -->

Fixes #10065
2022-12-17 12:35:26 +00:00
feniljain
c39849a34d fix: not suggest seek_to_start_instead_of_rewind when expr is used 2022-12-17 17:31:34 +05:30
Eric Wu
97c12e0460 fix logic in IncrementVisitor
There used to be a logical bug where IncrementVisitor would
completely stop checking an expression/block after seeing a continue
statement. This led to issue #10058 where a variable incremented
(or otherwise modified) after any continue statement would still be
considered incremented only once.

The solution is to continue scanning the expression after seeing a
`continue` statement, but increment self.depth so that the Visitor
thinks that the rest of the loop is within a conditional.
2022-12-16 10:54:12 -05:00
Eric Wu
5b3a6669f7 fix manual_filter false positive
do explicit checks for the other branch being None
2022-12-15 23:53:28 -05:00
bors
3905f51230 Auto merge of #10073 - xFrednet:changelog-1-66, r=Alexendoo
Changelog 1.66

It's really nice to see a changelog with so many suggestion fixes and improvements. Not much else to say. This should be merged with the coming release on 2022-12-15. For the reviewer, please review it and approve it if it looks good. The merge should wait until the release :)

---

changelog: none

<!-- changelog_checked -->
2022-12-15 16:12:12 +00:00
Oli Scherer
fa87abf963 Remove TraitRef::new 2022-12-14 15:36:39 +00:00
Oli Scherer
65069d5c5b Ensure no one constructs AliasTys themselves 2022-12-14 15:36:39 +00:00
bors
be15e60d00 Auto merge of #10053 - naosense:fix_9933, r=xFrednet
improve `manual_is_ascii_check ` check

Sorry, not familiar the api, i can only check the method name of expression `<expr-1>.contains(<expr-2>)` after read clippy book and hints from #9933 . i dont know how to check
1.  if <expr-1> is a specific range
2. <expr-2> is a character

r? `@xFrednet` could you please provide some more hints? 😝️

---

changelog: Enhancement: [`manual_is_ascii_check`]: Now detects ranges with `.contains()` calls
[#10053](https://github.com/rust-lang/rust-clippy/pull/10053)
<!-- changelog_checked -->
2022-12-14 13:48:53 +00:00
xFrednet
2532c56d86
Update version attribute for 1.66 lints 2022-12-13 23:36:47 +01:00
Michael Goulet
957ab6ae52 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
89b8840543 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
a274e7e9a2 ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
ad55e4c972 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
naosense
1f862c2ad3 remove assert macro 2022-12-13 21:43:16 +08:00
naosense
949d0709bd improve document 2022-12-13 16:52:55 +08:00
naosense
55fdd1e78c replace reference with value 2022-12-13 16:52:55 +08:00
naosense
de92da2974 add more test, limits check 2022-12-13 16:52:55 +08:00
naosense
25c9718c04 check ranges with .contains calls 2022-12-13 16:52:55 +08:00
bors
17a092f467 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00:00
alex-semenyuk
3b6bbf7d16 Fix match_single_binding suggestion introduced an extra semicolon 2022-12-10 20:35:49 +03:00
koka
055f349670
Avoid match_wildcard_for_single_variants on guarded wild matches
fix #9993
changlog: [`match_wildcard_for_single_variants`] avoid suggestion on wildcard with guard
2022-12-10 21:05:08 +09:00
Taiki Endo
e5010c996e uninlined_format_args: Ignore assert! and debug_assert! before 2021 edition 2022-12-10 18:35:24 +09:00
Hannah Town
4c80f210c3 Add lint almost_complete_range
This replaces and expands `almost_complete_letter_range`.
2022-12-09 13:29:50 -05:00
bors
3492856c07 Auto merge of #10047 - Alexendoo:collapsible-str-replace-msrv, r=xFrednet
Add 1.58 MSRV for `collapsible_str_replace`

The `Pattern` impl for `[char; N]` was added in 1.58

changelog: Enhancement: [`collapsible_str_replace`]: Now takes MSRV into consideration. The minimal version is 1.58
[#10047](https://github.com/rust-lang/rust-clippy/pull/10047)
2022-12-09 12:05:20 +00:00
bors
5a3a722c05 Auto merge of #10004 - Jarcho:issue_9904, r=llogiq
Don't suggest keeping borrows in `identity_op`

fixes #9904
changelog: `identity_op`: Don't suggest keeping borrows
2022-12-09 11:53:14 +00:00
bors
d4cd91c288 Auto merge of #9826 - Veykril:semi-blocks, r=Alexendoo
Add semicolon-outside/inside-block lints

changelog: Add `semicolon_outside_block` and `semicolon_inside_block` lints

Fixes https://github.com/rust-lang/rust-clippy/issues/7322

An earlier attempt at this can be found here https://github.com/rust-lang/rust-clippy/pull/7564. This PR still implements two separate lints but I am open to merging them into a single one that's configurable.
2022-12-09 11:41:24 +00:00
bors
39f0719a25 Auto merge of #9840 - c410-f3r:arith-2, r=Alexendoo
[`arithmetic-side-effects`]: Consider user-provided pairs

Depends on https://github.com/rust-lang/rust-clippy/pull/9592.

Because of https://github.com/rust-lang/rust-clippy/pull/9559#discussion_r985293523, r? `@Alexendoo`

```
changelog: [`arithmetic-side-effects`]: Consider user-provided pairs
```
2022-12-09 11:27:15 +00:00
Caio
1f92f97e5a [arithmetic-side-effects]: Consider user-provided pairs 2022-12-08 17:41:49 -03:00
Samuel Moelius
2d444a92f6 Fix #10021 2022-12-08 20:09:08 +01:00
Alex Macleod
591c18d2f0 Add 1.58 MSRV for collapsible_str_replace 2022-12-07 17:45:12 +00:00
bors
4129054120 Auto merge of #10023 - Jarcho:issue_10017, r=xFrednet
Fix `zero_ptr` suggestion for `no_std` crates

fixes #10017

---

changelog: Sugg: [`zero_ptr`]: Now suggests `core::` paths for `no_std` crates
[#10023](https://github.com/rust-lang/rust-clippy/pull/10023)
2022-12-06 18:57:05 +00:00
bors
5d70746251 Auto merge of #9920 - naosense:suppress_lint_in_const, r=xFrednet
add `suppress_restriction_lint_in_const` config

According to #9808 , add a new lint `suppress_lint_in_const` to report even in const context. BTW, i am not good at naming either, if anyone have a better idea, i am happy to change it.

This PR is still in progress, so i keep it draft.

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

changelog: Enhancement: [`indexing_slicing`]: add new config `suppress-restriction-lint-in-const` to enable restriction lints, even if the suggestion might not be applicable

r? `@xFrendet`
2022-12-06 18:43:28 +00:00