Skip to content

Commit ff4b772

Browse files
committed
Auto merge of #108974 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth` cc `@m-ou-se` This sync also includes rust-lang/rust-clippy#10275
2 parents 35a0961 + a87abc2 commit ff4b772

File tree

115 files changed

+2512
-779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2512
-779
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ dependencies = [
738738

739739
[[package]]
740740
name = "clippy"
741-
version = "0.1.69"
741+
version = "0.1.70"
742742
dependencies = [
743743
"clap 4.1.4",
744744
"clippy_lints",
@@ -781,7 +781,7 @@ dependencies = [
781781

782782
[[package]]
783783
name = "clippy_lints"
784-
version = "0.1.69"
784+
version = "0.1.70"
785785
dependencies = [
786786
"cargo_metadata 0.15.3",
787787
"clippy_utils",
@@ -804,7 +804,7 @@ dependencies = [
804804

805805
[[package]]
806806
name = "clippy_utils"
807-
version = "0.1.69"
807+
version = "0.1.70"
808808
dependencies = [
809809
"arrayvec 0.7.0",
810810
"if_chain",
@@ -1150,7 +1150,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
11501150

11511151
[[package]]
11521152
name = "declare_clippy_lint"
1153-
version = "0.1.69"
1153+
version = "0.1.70"
11541154
dependencies = [
11551155
"itertools",
11561156
"quote",

src/tools/clippy/CHANGELOG.md

+151-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,156 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[d822110d...master](https://github.com/rust-lang/rust-clippy/compare/d822110d...master)
9+
[7f27e2e7...master](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...master)
10+
11+
## Rust 1.68
12+
13+
Current stable, released 2023-03-09
14+
15+
[d822110d...7f27e2e7](https://github.com/rust-lang/rust-clippy/compare/d822110d...7f27e2e7)
16+
17+
### New Lints
18+
19+
* [`permissions_set_readonly_false`]
20+
[#10063](https://github.com/rust-lang/rust-clippy/pull/10063)
21+
* [`almost_complete_range`]
22+
[#10043](https://github.com/rust-lang/rust-clippy/pull/10043)
23+
* [`size_of_ref`]
24+
[#10098](https://github.com/rust-lang/rust-clippy/pull/10098)
25+
* [`semicolon_outside_block`]
26+
[#9826](https://github.com/rust-lang/rust-clippy/pull/9826)
27+
* [`semicolon_inside_block`]
28+
[#9826](https://github.com/rust-lang/rust-clippy/pull/9826)
29+
* [`transmute_null_to_fn`]
30+
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
31+
* [`fn_null_check`]
32+
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
33+
34+
### Moves and Deprecations
35+
36+
* Moved [`manual_clamp`] to `nursery` (Now allow-by-default)
37+
[#10101](https://github.com/rust-lang/rust-clippy/pull/10101)
38+
* Moved [`mutex_atomic`] to `restriction`
39+
[#10115](https://github.com/rust-lang/rust-clippy/pull/10115)
40+
* Renamed `derive_hash_xor_eq` to [`derived_hash_with_manual_eq`]
41+
[#10184](https://github.com/rust-lang/rust-clippy/pull/10184)
42+
43+
### Enhancements
44+
45+
* [`collapsible_str_replace`]: Now takes MSRV into consideration. The minimal version is 1.58
46+
[#10047](https://github.com/rust-lang/rust-clippy/pull/10047)
47+
* [`unused_self`]: No longer lints, if the method body contains a `todo!()` call
48+
[#10166](https://github.com/rust-lang/rust-clippy/pull/10166)
49+
* [`derivable_impls`]: Now suggests deriving `Default` for enums with default unit variants
50+
[#10161](https://github.com/rust-lang/rust-clippy/pull/10161)
51+
* [`arithmetic_side_effects`]: Added two new config values
52+
`arithmetic-side-effects-allowed-binary` and `arithmetic-side-effects-allowed-unary`
53+
to allow operation on user types
54+
[#9840](https://github.com/rust-lang/rust-clippy/pull/9840)
55+
* [`large_const_arrays`], [`large_stack_arrays`]: avoid integer overflow when calculating
56+
total array size
57+
[#10103](https://github.com/rust-lang/rust-clippy/pull/10103)
58+
* [`indexing_slicing`]: add new config `suppress-restriction-lint-in-const` to enable
59+
restriction lints, even if the suggestion might not be applicable
60+
[#9920](https://github.com/rust-lang/rust-clippy/pull/9920)
61+
* [`needless_borrow`], [`redundant_clone`]: Now track references better and detect more cases
62+
[#9701](https://github.com/rust-lang/rust-clippy/pull/9701)
63+
* [`derived_hash_with_manual_eq`]: Now allows `#[derive(PartialEq)]` with custom `Hash`
64+
implementations
65+
[#10184](https://github.com/rust-lang/rust-clippy/pull/10184)
66+
* [`manual_is_ascii_check`]: Now detects ranges with `.contains()` calls
67+
[#10053](https://github.com/rust-lang/rust-clippy/pull/10053)
68+
* [`transmuting_null`]: Now detects `const` pointers to all types
69+
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
70+
* [`needless_return`]: Now detects more cases for returns of owned values
71+
[#10110](https://github.com/rust-lang/rust-clippy/pull/10110)
72+
73+
### False Positive Fixes
74+
75+
* [`field_reassign_with_default`]: No longer lints cases, where values are initializes from
76+
closures capturing struct values
77+
[#10143](https://github.com/rust-lang/rust-clippy/pull/10143)
78+
* [`seek_to_start_instead_of_rewind`]: No longer lints, if the return of `seek` is used.
79+
[#10096](https://github.com/rust-lang/rust-clippy/pull/10096)
80+
* [`manual_filter`]: Now ignores if expressions where the else branch has side effects or
81+
doesn't return `None`
82+
[#10091](https://github.com/rust-lang/rust-clippy/pull/10091)
83+
* [`implicit_clone`]: No longer lints if the type doesn't implement clone
84+
[#10022](https://github.com/rust-lang/rust-clippy/pull/10022)
85+
* [`match_wildcard_for_single_variants`]: No longer lints on wildcards with a guard
86+
[#10056](https://github.com/rust-lang/rust-clippy/pull/10056)
87+
* [`drop_ref`]: No longer lints idiomatic expression in `match` arms
88+
[#10142](https://github.com/rust-lang/rust-clippy/pull/10142)
89+
* [`arithmetic_side_effects`]: No longer lints on corner cases with negative number literals
90+
[#9867](https://github.com/rust-lang/rust-clippy/pull/9867)
91+
* [`string_lit_as_bytes`]: No longer lints in scrutinies of `match` statements
92+
[#10012](https://github.com/rust-lang/rust-clippy/pull/10012)
93+
* [`manual_assert`]: No longer lints in `else if` statements
94+
[#10013](https://github.com/rust-lang/rust-clippy/pull/10013)
95+
* [`needless_return`]: don't lint when using `do yeet`
96+
[#10109](https://github.com/rust-lang/rust-clippy/pull/10109)
97+
* All lints: No longer lint in enum discriminant values when the suggestion won't work in a
98+
const context
99+
[#10008](https://github.com/rust-lang/rust-clippy/pull/10008)
100+
* [`single_element_loop`]: No longer lints, if the loop contains a `break` or `continue`
101+
[#10162](https://github.com/rust-lang/rust-clippy/pull/10162)
102+
* [`uninlined_format_args`]: No longer suggests inlining arguments in `assert!` and
103+
`debug_assert!` macros before 2021 edition
104+
[#10055](https://github.com/rust-lang/rust-clippy/pull/10055)
105+
* [`explicit_counter_loop`]: No longer ignores counter changes after `continue` expressions
106+
[#10094](https://github.com/rust-lang/rust-clippy/pull/10094)
107+
* [`from_over_into`]: No longer lints on opaque types
108+
[#9982](https://github.com/rust-lang/rust-clippy/pull/9982)
109+
* [`expl_impl_clone_on_copy`]: No longer lints on `#[repr(packed)]` structs with generic
110+
parameters
111+
[#10189](https://github.com/rust-lang/rust-clippy/pull/10189)
112+
113+
### Suggestion Fixes/Improvements
114+
115+
* [`zero_ptr`]: Now suggests `core::` paths for `no_std` crates
116+
[#10023](https://github.com/rust-lang/rust-clippy/pull/10023)
117+
* [`useless_conversion`]: Now suggests removing calls to `into_iter()` on an expression
118+
implementing `Iterator`
119+
[#10020](https://github.com/rust-lang/rust-clippy/pull/10020)
120+
* [`box_default`]: The suggestion now uses short paths
121+
[#10153](https://github.com/rust-lang/rust-clippy/pull/10153)
122+
* [`default_trait_access`], [`clone_on_copy`]: The suggestion now uses short paths
123+
[#10160](https://github.com/rust-lang/rust-clippy/pull/10160)
124+
* [`comparison_to_empty`]: The suggestion now removes unused deref operations
125+
[#9962](https://github.com/rust-lang/rust-clippy/pull/9962)
126+
* [`manual_let_else`]: Suggestions for or-patterns now include required brackets.
127+
[#9966](https://github.com/rust-lang/rust-clippy/pull/9966)
128+
* [`match_single_binding`]: suggestion no longer introduces unneeded semicolons
129+
[#10060](https://github.com/rust-lang/rust-clippy/pull/10060)
130+
* [`case_sensitive_file_extension_comparisons`]: Now displays a suggestion with `Path`
131+
[#10107](https://github.com/rust-lang/rust-clippy/pull/10107)
132+
* [`empty_structs_with_brackets`]: The suggestion is no longer machine applicable, to avoid
133+
errors when accessing struct fields
134+
[#10141](https://github.com/rust-lang/rust-clippy/pull/10141)
135+
* [`identity_op`]: Removes borrows in the suggestion when needed
136+
[#10004](https://github.com/rust-lang/rust-clippy/pull/10004)
137+
* [`suboptimal_flops`]: The suggestion now includes parentheses when required
138+
[#10113](https://github.com/rust-lang/rust-clippy/pull/10113)
139+
* [`iter_kv_map`]: Now handles `mut` and reference annotations in the suggestion
140+
[#10159](https://github.com/rust-lang/rust-clippy/pull/10159)
141+
* [`redundant_static_lifetimes`]: The suggestion no longer removes `mut` from references
142+
[#10006](https://github.com/rust-lang/rust-clippy/pull/10006)
143+
144+
### ICE Fixes
145+
146+
* [`new_ret_no_self`]: Now avoids a stack overflow for `impl Trait` types
147+
[#10086](https://github.com/rust-lang/rust-clippy/pull/10086)
148+
* [`unnecessary_to_owned`]: Now handles compiler generated notes better
149+
[#10027](https://github.com/rust-lang/rust-clippy/pull/10027)
150+
151+
### Others
152+
153+
* `SYSROOT` and `--sysroot` can now be set at the same time
154+
[#10149](https://github.com/rust-lang/rust-clippy/pull/10149)
10155

11156
## Rust 1.67
12157

13-
Current stable, released 2023-01-26
158+
Released 2023-01-26
14159

15160
[4f142aa1...d822110d](https://github.com/rust-lang/rust-clippy/compare/4f142aa1...d822110d)
16161

@@ -4307,6 +4452,7 @@ Released 2018-09-13
43074452
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
43084453
[`collapsible_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
43094454
[`collapsible_str_replace`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_str_replace
4455+
[`collection_is_never_read`]: https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
43104456
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
43114457
[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
43124458
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
@@ -4497,6 +4643,7 @@ Released 2018-09-13
44974643
[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use
44984644
[`let_underscore_untyped`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped
44994645
[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
4646+
[`let_with_type_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_with_type_underscore
45004647
[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist
45014648
[`logic_bug`]: https://rust-lang.github.io/rust-clippy/master/index.html#logic_bug
45024649
[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal
@@ -4560,6 +4707,7 @@ Released 2018-09-13
45604707
[`mismatching_type_param_order`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatching_type_param_order
45614708
[`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters
45624709
[`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op
4710+
[`missing_assert_message`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_assert_message
45634711
[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
45644712
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
45654713
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames
@@ -4689,6 +4837,7 @@ Released 2018-09-13
46894837
[`read_zero_byte_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_zero_byte_vec
46904838
[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl
46914839
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
4840+
[`redundant_async_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_async_block
46924841
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
46934842
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
46944843
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call

src/tools/clippy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.69"
3+
version = "0.1.70"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ The second part of the motivation is clippy's dependence on unstable
6868
compiler-internal data structures. Clippy lints are currently written against
6969
the compiler's AST / HIR which means that even small changes in these data
7070
structures might break a lot of lints. The second goal of this RFC is to **make
71-
lints independant of the compiler's AST / HIR data structures**.
71+
lints independent of the compiler's AST / HIR data structures**.
7272

7373
# Approach
7474

7575
A lot of complexity in writing lints currently seems to come from having to
7676
manually implement the matching logic (see code samples above). It's an
77-
imparative style that describes *how* to match a syntax tree node instead of
77+
imperative style that describes *how* to match a syntax tree node instead of
7878
specifying *what* should be matched against declaratively. In other areas, it's
7979
common to use declarative patterns to describe desired information and let the
8080
implementation do the actual matching. A well-known example of this approach are
@@ -270,7 +270,7 @@ pattern!{
270270
// matches if expressions that **may or may not** have an else block
271271
// Attn: `If(_, _, _)` matches only ifs that **have** an else block
272272
//
273-
// | if with else block | if witout else block
273+
// | if with else block | if without else block
274274
// If(_, _, _) | match | no match
275275
// If(_, _, _?) | match | match
276276
// If(_, _, ()) | no match | match
@@ -568,7 +568,7 @@ another example, `Array( Lit(_)* )` is a valid pattern because the parameter of
568568
569569
## The IsMatch Trait
570570

571-
The pattern syntax and the *PatternTree* are independant of specific syntax tree
571+
The pattern syntax and the *PatternTree* are independent of specific syntax tree
572572
implementations (rust ast / hir, syn, ...). When looking at the different
573573
pattern examples in the previous sections, it can be seen that the patterns
574574
don't contain any information specific to a certain syntax tree implementation.
@@ -717,7 +717,7 @@ if false {
717717
#### Problems
718718

719719
Extending Rust syntax (which is quite complex by itself) with additional syntax
720-
needed for specifying patterns (alternations, sequences, repetisions, named
720+
needed for specifying patterns (alternations, sequences, repetitions, named
721721
submatches, ...) might become difficult to read and really hard to parse
722722
properly.
723723

@@ -858,7 +858,7 @@ would be evaluated as soon as the `Block(_)#then` was matched.
858858
Another idea in this area would be to introduce a syntax for backreferences.
859859
They could be used to require that multiple parts of a pattern should match the
860860
same value. For example, the `assign_op_pattern` lint that searches for `a = a
861-
op b` and recommends changing it to `a op= b` requires that both occurrances of
861+
op b` and recommends changing it to `a op= b` requires that both occurrences of
862862
`a` are the same. Using `=#...` as syntax for backreferences, the lint could be
863863
implemented like this:
864864

@@ -882,7 +882,7 @@ least two return statements" could be a practical addition.
882882
For patterns like "a literal that is not a boolean literal" one currently needs
883883
to list all alternatives except the boolean case. Introducing a negation
884884
operator that allows to write `Lit(!Bool(_))` might be a good idea. This pattern
885-
would be eqivalent to `Lit( Char(_) | Int(_) )` (given that currently only three
885+
would be equivalent to `Lit( Char(_) | Int(_) )` (given that currently only three
886886
literal types are implemented).
887887

888888
#### Functional composition

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.69"
3+
version = "0.1.70"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/clippy_lints/src/almost_complete_range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare_clippy_lint! {
2424
/// ```rust
2525
/// let _ = 'a'..='z';
2626
/// ```
27-
#[clippy::version = "1.63.0"]
27+
#[clippy::version = "1.68.0"]
2828
pub ALMOST_COMPLETE_RANGE,
2929
suspicious,
3030
"almost complete range"

src/tools/clippy/clippy_lints/src/casts/cast_slice_from_raw_parts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::msrvs::{self, Msrv};
3-
use clippy_utils::source::snippet_with_applicability;
3+
use clippy_utils::source::snippet_with_context;
44
use clippy_utils::{match_def_path, paths};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
@@ -34,15 +34,17 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
3434
if let ExprKind::Path(ref qpath) = fun.kind;
3535
if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id();
3636
if let Some(rpk) = raw_parts_kind(cx, fun_def_id);
37+
let ctxt = expr.span.ctxt();
38+
if cast_expr.span.ctxt() == ctxt;
3739
then {
3840
let func = match rpk {
3941
RawPartsKind::Immutable => "from_raw_parts",
4042
RawPartsKind::Mutable => "from_raw_parts_mut"
4143
};
4244
let span = expr.span;
4345
let mut applicability = Applicability::MachineApplicable;
44-
let ptr = snippet_with_applicability(cx, ptr_arg.span, "ptr", &mut applicability);
45-
let len = snippet_with_applicability(cx, len_arg.span, "len", &mut applicability);
46+
let ptr = snippet_with_context(cx, ptr_arg.span, ctxt, "ptr", &mut applicability).0;
47+
let len = snippet_with_context(cx, len_arg.span, ctxt, "len", &mut applicability).0;
4648
span_lint_and_sugg(
4749
cx,
4850
CAST_SLICE_FROM_RAW_PARTS,

0 commit comments

Comments
 (0)