Skip to content

Commit aa3247c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents 1a5db18 + 9524cff commit aa3247c

File tree

106 files changed

+2719
-549
lines changed

Some content is hidden

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

106 files changed

+2719
-549
lines changed

.github/ISSUE_TEMPLATE/new_lint.yml

-23
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,6 @@ body:
1212
description: What does this lint do?
1313
validations:
1414
required: true
15-
- type: input
16-
id: lint-name
17-
attributes:
18-
label: Lint Name
19-
description: Please provide the lint name.
20-
- type: dropdown
21-
id: category
22-
attributes:
23-
label: Category
24-
description: >
25-
What category should this lint go into? If you're unsure you can select
26-
multiple categories. You can find a category description in the
27-
`README`.
28-
multiple: true
29-
options:
30-
- correctness
31-
- suspicious
32-
- style
33-
- complexity
34-
- perf
35-
- pedantic
36-
- restriction
37-
- cargo
3815
- type: textarea
3916
id: advantage
4017
attributes:

CHANGELOG.md

+129-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,132 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)
9+
[83e42a23...master](https://github.com/rust-lang/rust-clippy/compare/83e42a23...master)
10+
11+
## Rust 1.70
12+
13+
Current beta, released 2023-06-01
14+
15+
[149392b0...83e42a23](https://github.com/rust-lang/rust-clippy/compare/149392b0...83e42a23)
16+
17+
### New Lints
18+
19+
* [`large_futures`]
20+
[#10414](https://github.com/rust-lang/rust-clippy/pull/10414)
21+
* [`missing_assert_message`]
22+
[#10362](https://github.com/rust-lang/rust-clippy/pull/10362)
23+
* [`clear_with_drain`]
24+
[#10528](https://github.com/rust-lang/rust-clippy/pull/10528)
25+
* [`redundant_async_block`]
26+
[#10448](https://github.com/rust-lang/rust-clippy/pull/10448)
27+
* [`collection_is_never_read`]
28+
[#10415](https://github.com/rust-lang/rust-clippy/pull/10415)
29+
* [`let_with_type_underscore`]
30+
[#10467](https://github.com/rust-lang/rust-clippy/pull/10467)
31+
* [`tests_outside_test_module`]
32+
[#10543](https://github.com/rust-lang/rust-clippy/pull/10543)
33+
* [`allow_attributes`]
34+
[#10481](https://github.com/rust-lang/rust-clippy/pull/10481)
35+
* [`suspicious_doc_comments`]
36+
[#10497](https://github.com/rust-lang/rust-clippy/pull/10497)
37+
* [`unnecessary_box_returns`]
38+
[#9102](https://github.com/rust-lang/rust-clippy/pull/9102)
39+
* [`manual_main_separator_str`]
40+
[#10483](https://github.com/rust-lang/rust-clippy/pull/10483)
41+
* [`unnecessary_struct_initialization`]
42+
[#10489](https://github.com/rust-lang/rust-clippy/pull/10489)
43+
* [`manual_slice_size_calculation`]
44+
[#10601](https://github.com/rust-lang/rust-clippy/pull/10601)
45+
* [`lines_filter_map_ok`]
46+
[#10534](https://github.com/rust-lang/rust-clippy/pull/10534)
47+
48+
### Moves and Deprecations
49+
50+
* Moved [`let_underscore_untyped`] to `restriction`
51+
[#10442](https://github.com/rust-lang/rust-clippy/pull/10442)
52+
53+
### Enhancements
54+
55+
* [`extra_unused_type_parameters`]: No longer lints on public items if `avoid-breaking-exported-api` is set
56+
[#10536](https://github.com/rust-lang/rust-clippy/pull/10536)
57+
* [`len_without_is_empty`]: Now also detects `async` functions
58+
[#10359](https://github.com/rust-lang/rust-clippy/pull/10359)
59+
* [`arithmetic_side_effects`]: Now correctly handles divisions and modulo expressions if the right-hand-side
60+
is unknown
61+
[#10585](https://github.com/rust-lang/rust-clippy/pull/10585)
62+
* [`nonminimal_bool`]: No longer ignores `#[allow]` attributes
63+
[#10588](https://github.com/rust-lang/rust-clippy/pull/10588)
64+
* [`uninit_vec`], [`uninit_assumed_init`]: Now uses a better heuristic
65+
[#10520](https://github.com/rust-lang/rust-clippy/pull/10520)
66+
* [`ifs_same_cond`]: Now also detects immutable method calls.
67+
[#10350](https://github.com/rust-lang/rust-clippy/pull/10350)
68+
* [`arithmetic_side_effects`]: No longer lints on right or left shifts with constant integers, as the
69+
compiler warns about them
70+
[#10309](https://github.com/rust-lang/rust-clippy/pull/10309)
71+
* [`items_after_statements`]: `#[allow(items_after_statements)]` now works on items
72+
[#10542](https://github.com/rust-lang/rust-clippy/pull/10542)
73+
* [`significant_drop_tightening`]: Was optimized
74+
[#10533](https://github.com/rust-lang/rust-clippy/pull/10533)
75+
76+
### False Positive Fixes
77+
78+
* [`single_component_path_imports`]: No longer lints if the import is used relative to `self`
79+
[#10566](https://github.com/rust-lang/rust-clippy/pull/10566)
80+
* [`derivable_impls`]: No longer suggests deriving `Default` on generics with implicit arguments
81+
[#10399](https://github.com/rust-lang/rust-clippy/pull/10399)
82+
* [`let_unit_value`]: No longer lints if the expression contains an `await`
83+
[#10439](https://github.com/rust-lang/rust-clippy/pull/10439)
84+
* [`double_must_use`]: Now ignores `async` functions
85+
[#10589](https://github.com/rust-lang/rust-clippy/pull/10589)
86+
* [`manual_clamp`]: No longer lints in constant context
87+
[#10479](https://github.com/rust-lang/rust-clippy/pull/10479)
88+
* [`almost_swapped`]: Now ignores external macros
89+
[#10502](https://github.com/rust-lang/rust-clippy/pull/10502)
90+
* [`nonminimal_bool`]: Now ignores macros
91+
[#10527](https://github.com/rust-lang/rust-clippy/pull/10527)
92+
* [`needless_return`]: No longer lints match statements with incompatible branches
93+
[#10593](https://github.com/rust-lang/rust-clippy/pull/10593)
94+
* [`use_self`]: Do not suggest using `Self` in const generic parameters
95+
[#10375](https://github.com/rust-lang/rust-clippy/pull/10375)
96+
* [`mem_replace_option_with_none`]: No longer lints on field expressions
97+
[#10594](https://github.com/rust-lang/rust-clippy/pull/10594)
98+
* [`items_after_statements`]: No longer lints on times from macros
99+
[#10542](https://github.com/rust-lang/rust-clippy/pull/10542)
100+
* [`print_literal`], [`write_literal`]: No longer lint strings coming from the `file!()` macro
101+
[#10573](https://github.com/rust-lang/rust-clippy/pull/10573)
102+
* [`uninit_vec`], [`uninit_assumed_init`]: Now check the types inside arrays and tuples
103+
[#10553](https://github.com/rust-lang/rust-clippy/pull/10553)
104+
* [`almost_swapped`]: No longer lints if a variable is assigned to itself
105+
[#10499](https://github.com/rust-lang/rust-clippy/pull/10499)
106+
* [`missing_docs_in_private_items`]: No longer lints on public items
107+
[#10324](https://github.com/rust-lang/rust-clippy/pull/10324)
108+
109+
### Suggestion Fixes/Improvements
110+
111+
* [`extra_unused_type_parameters`]: The suggestion is now machine applicable
112+
[#10536](https://github.com/rust-lang/rust-clippy/pull/10536)
113+
* [`match_single_binding`]: Now adds a semicolon after the suggestion
114+
[#10470](https://github.com/rust-lang/rust-clippy/pull/10470)
115+
* [`missing_const_for_fn`]: Now includes a note if the change could break compatibility
116+
[#10618](https://github.com/rust-lang/rust-clippy/pull/10618)
117+
* [`cast_possible_truncation`]: Corrected suggestion for float and wildcard casts
118+
[#10496](https://github.com/rust-lang/rust-clippy/pull/10496)
119+
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now includes parentheses when they are required
120+
[#10454](https://github.com/rust-lang/rust-clippy/pull/10454)
121+
122+
### ICE Fixes
123+
124+
* [`needless_borrow`]: No longer panics on ambiguous projections
125+
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
126+
* [`multiple_unsafe_ops_per_block`]: Fix ICE when calling a function-like object in an unsafe block
127+
[#10405](https://github.com/rust-lang/rust-clippy/pull/10405)
128+
129+
### Others
130+
131+
* `clippy-driver` now searches parent directories for `clippy.toml` files
132+
[#10592](https://github.com/rust-lang/rust-clippy/pull/10592)
133+
* Fixed a deserialization error for the `array-size-threshold` config value
134+
[#10423](https://github.com/rust-lang/rust-clippy/pull/10423)
10135

11136
## Rust 1.69
12137

@@ -4838,6 +4963,7 @@ Released 2018-09-13
48384963
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
48394964
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames
48404965
[`missing_errors_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc
4966+
[`missing_fields_in_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_fields_in_debug
48414967
[`missing_inline_in_public_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_inline_in_public_items
48424968
[`missing_panics_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
48434969
[`missing_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
@@ -4874,6 +5000,7 @@ Released 2018-09-13
48745000
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
48755001
[`needless_continue`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
48765002
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
5003+
[`needless_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_else
48775004
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
48785005
[`needless_late_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
48795006
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
@@ -4949,6 +5076,7 @@ Released 2018-09-13
49495076
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
49505077
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
49515078
[`ptr_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr
5079+
[`ptr_cast_constness`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness
49525080
[`ptr_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
49535081
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
49545082
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names

Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ walkdir = "2.3"
3535
# This is used by the `collect-metadata` alias.
3636
filetime = "0.2"
3737

38-
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
39-
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
40-
# for more information.
41-
rustc-workspace-hack = "1.0"
42-
4338
# UI test dependencies
4439
clap = { version = "4.1.4", features = ["derive"] }
4540
clippy_utils = { path = "clippy_utils" }

book/src/configuration.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
> **Note:** The configuration file is unstable and may be deprecated in the future.
44
5-
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a
6-
basic `variable = value` mapping e.g.
5+
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`, which is searched for in:
6+
7+
1. The directory specified by the `CLIPPY_CONF_DIR` environment variable, or
8+
2. The directory specified by the
9+
[CARGO_MANIFEST_DIR](https://doc.rust-lang.org/cargo/reference/environment-variables.html) environment variable, or
10+
3. The current directory.
11+
12+
It contains a basic `variable = value` mapping e.g.
713

814
```toml
915
avoid-breaking-exported-api = false

book/src/development/adding_lints.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,14 @@ Before submitting your PR make sure you followed all the basic requirements:
630630

631631
## Adding configuration to a lint
632632

633-
Clippy supports the configuration of lints values using a `clippy.toml` file in
634-
the workspace directory. Adding a configuration to a lint can be useful for
633+
Clippy supports the configuration of lints values using a `clippy.toml` file which is searched for in:
634+
635+
1. The directory specified by the `CLIPPY_CONF_DIR` environment variable, or
636+
2. The directory specified by the
637+
[CARGO_MANIFEST_DIR](https://doc.rust-lang.org/cargo/reference/environment-variables.html) environment variable, or
638+
3. The current directory.
639+
640+
Adding a configuration to a lint can be useful for
635641
thresholds or to constrain some behavior that can be seen as a false positive
636642
for some users. Adding a configuration is done in the following steps:
637643

clippy_dev/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use clap::{Arg, ArgAction, ArgMatches, Command};
66
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
77
use indoc::indoc;
8+
use std::convert::Infallible;
89

910
fn main() {
1011
let matches = get_clap_config();
@@ -180,7 +181,8 @@ fn get_clap_config() -> ArgMatches {
180181
.short('n')
181182
.long("name")
182183
.help("Name of the new lint in snake case, ex: fn_too_long")
183-
.required(true),
184+
.required(true)
185+
.value_parser(|name: &str| Ok::<_, Infallible>(name.replace('-', "_"))),
184186
Arg::new("category")
185187
.short('c')
186188
.long("category")

clippy_lints/Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ quine-mc_cluskey = "0.2"
2020
regex-syntax = "0.7"
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = { version = "1.0", optional = true }
23-
tempfile = { version = "3.2", optional = true }
23+
tempfile = { version = "3.3.0", optional = true }
2424
toml = "0.5"
2525
unicode-normalization = "0.1"
2626
unicode-script = { version = "0.5", default-features = false }
2727
semver = "1.0"
2828
rustc-semver = "1.1"
29-
# NOTE: cargo requires serde feat in its url dep
30-
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
31-
url = { version = "2.2", features = ["serde"] }
29+
url = "2.2"
3230

3331
[features]
3432
deny-warnings = ["clippy_utils/deny-warnings"]

clippy_lints/src/allow_attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare_clippy_lint! {
4040
/// a.len()
4141
/// }
4242
/// ```
43-
#[clippy::version = "1.69.0"]
43+
#[clippy::version = "1.70.0"]
4444
pub ALLOW_ATTRIBUTES,
4545
restriction,
4646
"`#[allow]` will not trigger if a warning isn't found. `#[expect]` triggers if there are no warnings."

clippy_lints/src/blocks_in_if_conditions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
8585
);
8686
}
8787
} else {
88-
let span =
89-
block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
88+
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
9089
if span.from_expansion() || expr.span.from_expansion() {
9190
return;
9291
}

clippy_lints/src/booleans.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
8888
NonminimalBoolVisitor { cx }.visit_body(body);
8989
}
9090
}
91-
9291
struct NonminimalBoolVisitor<'a, 'tcx> {
9392
cx: &'a LateContext<'tcx>,
9493
}
@@ -473,6 +472,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
473472
self.bool_expr(e);
474473
},
475474
ExprKind::Unary(UnOp::Not, inner) => {
475+
if let ExprKind::Unary(UnOp::Not, ex) = inner.kind &&
476+
!self.cx.typeck_results().node_types()[ex.hir_id].is_bool() {
477+
return;
478+
}
476479
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
477480
self.bool_expr(e);
478481
}

clippy_lints/src/casts/mod.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod fn_to_numeric_cast;
1717
mod fn_to_numeric_cast_any;
1818
mod fn_to_numeric_cast_with_truncation;
1919
mod ptr_as_ptr;
20+
mod ptr_cast_constness;
2021
mod unnecessary_cast;
2122
mod utils;
2223

@@ -363,7 +364,7 @@ declare_clippy_lint! {
363364
/// namely `*const T` to `*const U` and `*mut T` to `*mut U`.
364365
///
365366
/// ### Why is this bad?
366-
/// Though `as` casts between raw pointers is not terrible, `pointer::cast` is safer because
367+
/// Though `as` casts between raw pointers are not terrible, `pointer::cast` is safer because
367368
/// it cannot accidentally change the pointer's mutability nor cast the pointer to other types like `usize`.
368369
///
369370
/// ### Example
@@ -386,6 +387,34 @@ declare_clippy_lint! {
386387
"casting using `as` from and to raw pointers that doesn't change its mutability, where `pointer::cast` could take the place of `as`"
387388
}
388389

390+
declare_clippy_lint! {
391+
/// ### What it does
392+
/// Checks for `as` casts between raw pointers which change its constness, namely `*const T` to
393+
/// `*mut T` and `*mut T` to `*const T`.
394+
///
395+
/// ### Why is this bad?
396+
/// Though `as` casts between raw pointers are not terrible, `pointer::cast_mut` and
397+
/// `pointer::cast_const` are safer because they cannot accidentally cast the pointer to another
398+
/// type.
399+
///
400+
/// ### Example
401+
/// ```rust
402+
/// let ptr: *const u32 = &42_u32;
403+
/// let mut_ptr = ptr as *mut u32;
404+
/// let ptr = mut_ptr as *const u32;
405+
/// ```
406+
/// Use instead:
407+
/// ```rust
408+
/// let ptr: *const u32 = &42_u32;
409+
/// let mut_ptr = ptr.cast_mut();
410+
/// let ptr = mut_ptr.cast_const();
411+
/// ```
412+
#[clippy::version = "1.71.0"]
413+
pub PTR_CAST_CONSTNESS,
414+
pedantic,
415+
"casting using `as` from and to raw pointers to change constness when specialized methods apply"
416+
}
417+
389418
declare_clippy_lint! {
390419
/// ### What it does
391420
/// Checks for casts from an enum type to an integral type which will definitely truncate the
@@ -652,6 +681,7 @@ impl_lint_pass!(Casts => [
652681
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
653682
CHAR_LIT_AS_U8,
654683
PTR_AS_PTR,
684+
PTR_CAST_CONSTNESS,
655685
CAST_ENUM_TRUNCATION,
656686
CAST_ENUM_CONSTRUCTOR,
657687
CAST_ABS_TO_UNSIGNED,
@@ -685,6 +715,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
685715
return;
686716
}
687717
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
718+
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
688719
as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
689720
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
690721
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);

0 commit comments

Comments
 (0)