Skip to content

Commit 97a49c0

Browse files
authored
Merge branch 'master' into string_lit_as_bytes_changes
2 parents dc35d84 + c976ad0 commit 97a49c0

File tree

743 files changed

+1535
-1221
lines changed

Some content is hidden

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

743 files changed

+1535
-1221
lines changed

CHANGELOG.md

+117-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,126 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[7f27e2e7...master](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...master)
9+
[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)
10+
11+
## Rust 1.69
12+
13+
Current stable, released 2023-04-20
14+
15+
[7f27e2e7...149392b0](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...149392b0)
16+
17+
### New Lints
18+
19+
* [`no_mangle_with_rust_abi`]
20+
[#10369](https://github.com/rust-lang/rust-clippy/pull/10369)
21+
* [`significant_drop_tightening`]
22+
[#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
23+
* [`suspicious_command_arg_space`]
24+
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
25+
* [`let_underscore_untyped`]
26+
[#10356](https://github.com/rust-lang/rust-clippy/pull/10356)
27+
* [`question_mark_used`]
28+
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
29+
* [`extra_unused_type_parameters`]
30+
[#10028](https://github.com/rust-lang/rust-clippy/pull/10028)
31+
* [`impl_trait_in_params`]
32+
[10197](https://github.com/rust-lang/rust-clippy/pull/10197)
33+
* [`transmute_int_to_non_zero`]
34+
[#10360](https://github.com/rust-lang/rust-clippy/pull/10360)
35+
* [`multiple_unsafe_ops_per_block`]
36+
[#10206](https://github.com/rust-lang/rust-clippy/pull/10206)
37+
38+
### Moves and Deprecations
39+
40+
* Moved [`uninlined_format_args`] to `pedantic` (Now allow-by-default)
41+
[#10265](https://github.com/rust-lang/rust-clippy/pull/10265)
42+
* Moved [`unchecked_duration_subtraction`] to `pedantic` (Now allow-by-default)
43+
[#10194](https://github.com/rust-lang/rust-clippy/pull/10194)
44+
45+
### Enhancements
46+
47+
* [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
48+
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
49+
* [`needless_lifetimes`]: Now works in local macros
50+
[#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
51+
* [`unused_io_amount`]: Now detects usages of `is_ok` and `is_err`
52+
[#10225](https://github.com/rust-lang/rust-clippy/pull/10225)
53+
* [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint
54+
on items visible within the current crate. For example, `pub(crate)` items.
55+
[#10303](https://github.com/rust-lang/rust-clippy/pull/10303)
56+
* [`almost_swapped`]: Now detects almost swaps using `let` statements
57+
[#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
58+
* [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
59+
[#10250](https://github.com/rust-lang/rust-clippy/pull/10250)
60+
61+
### False Positive Fixes
62+
63+
* [`explicit_auto_deref`]: Now considers projections, when determining if auto deref is applicable
64+
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
65+
* [`manual_let_else`]: Now considers side effects of branches, before linting
66+
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
67+
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
68+
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
69+
* [`needless_lifetimes`]: No longer lints signatures in macros, if the lifetime is a metavariable
70+
[#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
71+
* [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
72+
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
73+
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes, to reduce false
74+
positives
75+
[#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
76+
* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
77+
[#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
78+
* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
79+
in test functions, if `allow-expect-in-tests` is set
80+
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
81+
* [`unnecessary_safety_comment`]: No longer lints code inside macros
82+
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
83+
* [`never_loop`]: No longer lints, for statements following break statements for outer blocks.
84+
[#10311](https://github.com/rust-lang/rust-clippy/pull/10311)
85+
86+
### Suggestion Fixes/Improvements
87+
88+
* [`box_default`]: The suggestion now includes the type for trait objects, when needed
89+
[#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
90+
* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
91+
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
92+
* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
93+
now show the complete error
94+
[#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
95+
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works, if the base type is borrowed
96+
[#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
97+
* [`needless_return`]: Now removes all semicolons on the same line
98+
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
99+
* [`suspicious_to_owned`]: The suggestion now shows all options clearly
100+
[#10295](https://github.com/rust-lang/rust-clippy/pull/10295)
101+
* [`bytes_nth`]: Now suggests the correct replacement based on the context
102+
[#10361](https://github.com/rust-lang/rust-clippy/pull/10361)
103+
* [`bool_assert_comparison`]: The suggestion is now machine applicable
104+
[#10218](https://github.com/rust-lang/rust-clippy/pull/10218)
105+
* [`cast_possible_truncation`]: Corrected the lint name in the help message
106+
[#10330](https://github.com/rust-lang/rust-clippy/pull/10330)
107+
* [`needless_return`]: The suggestion now works on if sequences
108+
[#10345](https://github.com/rust-lang/rust-clippy/pull/10345)
109+
* [`needless_lifetimes`]: The suggestion is now machine applicable
110+
[#10222](https://github.com/rust-lang/rust-clippy/pull/10222)
111+
* [`map_entry`]: The suggestion no longer expands macros
112+
[#10346](https://github.com/rust-lang/rust-clippy/pull/10346)
113+
114+
### ICE Fixes
115+
116+
* [`needless_pass_by_value`]: Fixed an ICE, caused by how late bounds were handled
117+
[#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
118+
* [`needless_borrow`]: No longer panics on ambiguous projections
119+
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
120+
121+
### Documentation Improvements
122+
123+
* All configurations are now documented in the Clippy Book
124+
[#10199](https://github.com/rust-lang/rust-clippy/pull/10199)
10125

11126
## Rust 1.68
12127

13-
Current stable, released 2023-03-09
128+
Released 2023-03-09
14129

15130
[d822110d...7f27e2e7](https://github.com/rust-lang/rust-clippy/compare/d822110d...7f27e2e7)
16131

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tempfile = { version = "3.2", optional = true }
2828
termize = "0.1"
2929

3030
[dev-dependencies]
31-
compiletest_rs = { version = "0.9", features = ["tmp"] }
31+
compiletest_rs = { version = "0.10", features = ["tmp"] }
3232
tester = "0.9"
3333
regex = "1.5"
3434
toml = "0.5"

book/src/development/adding_lints.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ The process of generating the `.stderr` file is the same, and prepending the
164164
## Rustfix tests
165165

166166
If the lint you are working on is making use of structured suggestions, the test
167-
file should include a `// run-rustfix` comment at the top. This will
167+
file should include a `//@run-rustfix` comment at the top. This will
168168
additionally run [rustfix] for that test. Rustfix will apply the suggestions
169169
from the lint to the code of the test file and compare that to the contents of a
170170
`.fixed` file.

book/src/lint_configuration.md

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Please use that command to update the file and do not edit it by hand.
5555
| [suppress-restriction-lint-in-const](#suppress-restriction-lint-in-const) | `false` |
5656
| [missing-docs-in-crate-items](#missing-docs-in-crate-items) | `false` |
5757
| [future-size-threshold](#future-size-threshold) | `16384` |
58+
| [unnecessary-box-size](#unnecessary-box-size) | `128` |
5859

5960
### arithmetic-side-effects-allowed
6061
Suppress checking of the passed type names in all types of operations.
@@ -561,4 +562,12 @@ The maximum byte size a `Future` can have, before it triggers the `clippy::large
561562
* [large_futures](https://rust-lang.github.io/rust-clippy/master/index.html#large_futures)
562563

563564

565+
### unnecessary-box-size
566+
The byte size a `T` in `Box<T>` can have, below which it triggers the `clippy::unnecessary_box` lint
567+
568+
**Default Value:** `128` (`u64`)
569+
570+
* [unnecessary_box_returns](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns)
571+
572+
564573

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String {
741741
fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String {
742742
let mut seen_lints = HashSet::new();
743743
let mut res: String = GENERATED_FILE_COMMENT.into();
744-
res.push_str("// run-rustfix\n\n");
744+
res.push_str("//@run-rustfix\n\n");
745745
for lint in lints {
746746
if seen_lints.insert(&lint.new_name) {
747747
writeln!(res, "#![allow({})]", lint.new_name).unwrap();

clippy_lints/src/functions/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ declare_clippy_lint! {
348348
/// // [...]
349349
/// }
350350
/// ```
351-
#[clippy::version = "1.68.0"]
351+
#[clippy::version = "1.69.0"]
352352
pub IMPL_TRAIT_IN_PARAMS,
353353
restriction,
354354
"`impl Trait` is used in the function's parameters"

clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
950950
store.register_late_pass(|_| Box::new(allow_attributes::AllowAttribute));
951951
store.register_late_pass(move |_| Box::new(manual_main_separator_str::ManualMainSeparatorStr::new(msrv())));
952952
store.register_late_pass(|_| Box::new(unnecessary_struct_initialization::UnnecessaryStruct));
953+
let unnecessary_box_size = conf.unnecessary_box_size;
953954
store.register_late_pass(move |_| {
954955
Box::new(unnecessary_box_returns::UnnecessaryBoxReturns::new(
955956
avoid_breaking_exported_api,
957+
unnecessary_box_size,
956958
))
957959
});
958960
store.register_late_pass(|_| Box::new(lines_filter_map_ok::LinesFilterMapOk));

clippy_lints/src/manual_slice_size_calculation.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-rustfix
21
use clippy_utils::diagnostics::span_lint_and_sugg;
32
use clippy_utils::source::snippet_with_context;
43
use clippy_utils::{expr_or_init, in_constant, std_or_core};
@@ -45,6 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualSliceSizeCalculation {
4544
if !in_constant(cx, expr.hir_id)
4645
&& let ExprKind::Binary(ref op, left, right) = expr.kind
4746
&& BinOpKind::Mul == op.node
47+
&& !expr.span.from_expansion()
4848
&& let Some(receiver) = simplify(cx, left, right)
4949
{
5050
let ctxt = expr.span.ctxt();
@@ -55,12 +55,12 @@ impl<'tcx> LateLintPass<'tcx> for ManualSliceSizeCalculation {
5555
span_lint_and_sugg(
5656
cx,
5757
MANUAL_SLICE_SIZE_CALCULATION,
58-
expr.span,
59-
"manual slice size calculation",
60-
"try",
61-
format!("{sugg}::mem::size_of_val({val_name})"),
62-
Applicability::MachineApplicable,
63-
);
58+
expr.span,
59+
"manual slice size calculation",
60+
"try",
61+
format!("{sugg}::mem::size_of_val({val_name})"),
62+
app,
63+
);
6464
}
6565
}
6666
}
@@ -81,9 +81,9 @@ fn simplify_half<'tcx>(
8181
expr1: &'tcx Expr<'tcx>,
8282
expr2: &'tcx Expr<'tcx>,
8383
) -> Option<&'tcx Expr<'tcx>> {
84-
if
84+
if !expr1.span.from_expansion()
8585
// expr1 is `[T1].len()`?
86-
let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
86+
&& let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
8787
&& method_path.ident.name == sym::len
8888
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
8989
&& let ty::Slice(ty1) = receiver_ty.peel_refs().kind()

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3185,7 +3185,7 @@ declare_clippy_lint! {
31853185
/// ```rust
31863186
/// std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap();
31873187
/// ```
3188-
#[clippy::version = "1.67.0"]
3188+
#[clippy::version = "1.69.0"]
31893189
pub SUSPICIOUS_COMMAND_ARG_SPACE,
31903190
suspicious,
31913191
"single command line argument that looks like it should be multiple arguments"

clippy_lints/src/methods/obfuscated_if_else.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run-rustfix
2-
31
use super::OBFUSCATED_IF_ELSE;
42
use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_with_applicability};
53
use rustc_errors::Applicability;

clippy_lints/src/multiple_unsafe_ops_per_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ declare_clippy_lint! {
5959
/// unsafe { char::from_u32_unchecked(int_value) }
6060
/// }
6161
/// ```
62-
#[clippy::version = "1.68.0"]
62+
#[clippy::version = "1.69.0"]
6363
pub MULTIPLE_UNSAFE_OPS_PER_BLOCK,
6464
restriction,
6565
"more than one unsafe operation per `unsafe` block"

clippy_lints/src/operators/arithmetic_side_effects.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::ARITHMETIC_SIDE_EFFECTS;
2+
use clippy_utils::is_from_proc_macro;
23
use clippy_utils::{
34
consts::{constant, constant_simple, Constant},
45
diagnostics::span_lint,
@@ -10,7 +11,10 @@ use rustc_hir as hir;
1011
use rustc_lint::{LateContext, LateLintPass};
1112
use rustc_middle::ty::Ty;
1213
use rustc_session::impl_lint_pass;
13-
use rustc_span::source_map::{Span, Spanned};
14+
use rustc_span::{
15+
source_map::{Span, Spanned},
16+
Symbol,
17+
};
1418

1519
const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[
1620
["f32", "f32"],
@@ -20,6 +24,7 @@ const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[
2024
["std::string::String", "&str"],
2125
];
2226
const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"];
27+
const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"];
2328

2429
#[derive(Debug)]
2530
pub struct ArithmeticSideEffects {
@@ -28,6 +33,7 @@ pub struct ArithmeticSideEffects {
2833
// Used to check whether expressions are constants, such as in enum discriminants and consts
2934
const_span: Option<Span>,
3035
expr_span: Option<Span>,
36+
integer_methods: FxHashSet<Symbol>,
3137
}
3238

3339
impl_lint_pass!(ArithmeticSideEffects => [ARITHMETIC_SIDE_EFFECTS]);
@@ -53,6 +59,7 @@ impl ArithmeticSideEffects {
5359
allowed_unary,
5460
const_span: None,
5561
expr_span: None,
62+
integer_methods: INTEGER_METHODS.iter().map(|el| Symbol::intern(el)).collect(),
5663
}
5764
}
5865

@@ -184,6 +191,33 @@ impl ArithmeticSideEffects {
184191
}
185192
}
186193

194+
/// There are some integer methods like `wrapping_div` that will panic depending on the
195+
/// provided input.
196+
fn manage_method_call<'tcx>(
197+
&mut self,
198+
args: &[hir::Expr<'tcx>],
199+
cx: &LateContext<'tcx>,
200+
ps: &hir::PathSegment<'tcx>,
201+
receiver: &hir::Expr<'tcx>,
202+
) {
203+
let Some(arg) = args.first() else { return; };
204+
if constant_simple(cx, cx.typeck_results(), receiver).is_some() {
205+
return;
206+
}
207+
let instance_ty = cx.typeck_results().expr_ty(receiver);
208+
if !Self::is_integral(instance_ty) {
209+
return;
210+
}
211+
if !self.integer_methods.contains(&ps.ident.name) {
212+
return;
213+
}
214+
let (actual_arg, _) = peel_hir_expr_refs(arg);
215+
match Self::literal_integer(cx, actual_arg) {
216+
None | Some(0) => self.issue_lint(cx, arg),
217+
Some(_) => {},
218+
}
219+
}
220+
187221
fn manage_unary_ops<'tcx>(
188222
&mut self,
189223
cx: &LateContext<'tcx>,
@@ -206,8 +240,9 @@ impl ArithmeticSideEffects {
206240
self.issue_lint(cx, expr);
207241
}
208242

209-
fn should_skip_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
243+
fn should_skip_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) -> bool {
210244
is_lint_allowed(cx, ARITHMETIC_SIDE_EFFECTS, expr.hir_id)
245+
|| is_from_proc_macro(cx, expr)
211246
|| self.expr_span.is_some()
212247
|| self.const_span.map_or(false, |sp| sp.contains(expr.span))
213248
}
@@ -222,6 +257,9 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
222257
hir::ExprKind::AssignOp(op, lhs, rhs) | hir::ExprKind::Binary(op, lhs, rhs) => {
223258
self.manage_bin_ops(cx, expr, op, lhs, rhs);
224259
},
260+
hir::ExprKind::MethodCall(ps, receiver, args, _) => {
261+
self.manage_method_call(args, cx, ps, receiver);
262+
},
225263
hir::ExprKind::Unary(un_op, un_expr) => {
226264
self.manage_unary_ops(cx, expr, un_expr, *un_op);
227265
},

clippy_lints/src/operators/numeric_arithmetic.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use super::{FLOAT_ARITHMETIC, INTEGER_ARITHMETIC};
12
use clippy_utils::consts::constant_simple;
23
use clippy_utils::diagnostics::span_lint;
4+
use clippy_utils::is_from_proc_macro;
35
use clippy_utils::is_integer_literal;
46
use rustc_hir as hir;
57
use rustc_lint::LateContext;
68
use rustc_span::source_map::Span;
79

8-
use super::{FLOAT_ARITHMETIC, INTEGER_ARITHMETIC};
9-
1010
#[derive(Default)]
1111
pub struct Context {
1212
expr_id: Option<hir::HirId>,
@@ -47,6 +47,9 @@ impl Context {
4747

4848
let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
4949
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
50+
if is_from_proc_macro(cx, expr) {
51+
return;
52+
}
5053
match op {
5154
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
5255
hir::ExprKind::Lit(_lit) => (),
@@ -79,6 +82,9 @@ impl Context {
7982
let ty = cx.typeck_results().expr_ty(arg);
8083
if constant_simple(cx, cx.typeck_results(), expr).is_none() {
8184
if ty.is_integral() {
85+
if is_from_proc_macro(cx, expr) {
86+
return;
87+
}
8288
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
8389
self.expr_id = Some(expr.hir_id);
8490
} else if ty.is_floating_point() {

0 commit comments

Comments
 (0)