Skip to content

Commit bace62d

Browse files
authored
Rollup merge of rust-lang#136645 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? `@Manishearth`
2 parents 1d7505a + daa82a1 commit bace62d

File tree

106 files changed

+2680
-565
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

+2680
-565
lines changed

src/tools/clippy/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5765,6 +5765,7 @@ Released 2018-09-13
57655765
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
57665766
[`manual_ok_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err
57675767
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
5768+
[`manual_option_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice
57685769
[`manual_pattern_char_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison
57695770
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
57705771
[`manual_range_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns
@@ -5773,6 +5774,7 @@ Released 2018-09-13
57735774
[`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain
57745775
[`manual_rotate`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rotate
57755776
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
5777+
[`manual_slice_fill`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill
57765778
[`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation
57775779
[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once
57785780
[`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat
@@ -5954,6 +5956,7 @@ Released 2018-09-13
59545956
[`positional_named_format_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#positional_named_format_parameters
59555957
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
59565958
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
5959+
[`precedence_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence_bits
59575960
[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl
59585961
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
59595962
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
@@ -6026,6 +6029,7 @@ Released 2018-09-13
60266029
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
60276030
[`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err
60286031
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used
6032+
[`return_and_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_and_then
60296033
[`return_self_not_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use
60306034
[`reverse_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#reverse_range_loop
60316035
[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges

src/tools/clippy/book/src/attribs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ To do this, Clippy provides attributes that can be applied to items in the 3rd p
55

66
## `#[clippy::format_args]`
77

8-
_Available since Clippy v1.84_
8+
_Available since Clippy v1.85_
99

1010
This attribute can be added to a macro that supports `format!`, `println!`, or similar syntax.
1111
It tells Clippy that the macro is a formatting macro, and that the arguments to the macro

src/tools/clippy/book/src/lint_configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
752752
* [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid)
753753
* [`manual_repeat_n`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n)
754754
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
755+
* [`manual_slice_fill`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill)
755756
* [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once)
756757
* [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat)
757758
* [`manual_strip`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip)

src/tools/clippy/book/src/lints.md

+13
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,18 @@ The `clippy::cargo` group gives you suggestions on how to improve your
101101
your crate and are not sure if you have all useful information in your
102102
`Cargo.toml`.
103103

104+
## Nursery
105+
106+
The `clippy::nursery` group contains lints which are buggy or need more work. It is **not**
107+
recommended to enable the whole group, but rather cherry-pick lints that are useful for your
108+
code base and your use case.
109+
110+
## Deprecated
111+
112+
The `clippy::deprecated` is empty lints that exist to ensure that `#[allow(lintname)]` still
113+
compiles after the lint was deprecated. Deprecation "removes" lints by removing their
114+
functionality and marking them as deprecated, which may cause further warnings but cannot
115+
cause a compiler error.
116+
104117
[Clippy lint documentation]: https://rust-lang.github.io/rust-clippy/
105118
[Clippy 1.0 RFC]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories

src/tools/clippy/clippy_config/src/conf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ define_Conf! {
621621
manual_rem_euclid,
622622
manual_repeat_n,
623623
manual_retain,
624+
manual_slice_fill,
624625
manual_split_once,
625626
manual_str_repeat,
626627
manual_strip,

src/tools/clippy/clippy_dev/src/new_lint.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
255255
let name_camel = to_camel_case(lint.name);
256256
let name_upper = lint_name.to_uppercase();
257257

258-
result.push_str(&if enable_msrv {
259-
formatdoc!(
258+
if enable_msrv {
259+
let _: fmt::Result = writedoc!(
260+
result,
260261
r"
261262
use clippy_utils::msrvs::{{self, Msrv}};
262263
use clippy_config::Conf;
@@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
265266
use rustc_session::impl_lint_pass;
266267
267268
"
268-
)
269+
);
269270
} else {
270-
formatdoc!(
271+
let _: fmt::Result = writedoc!(
272+
result,
271273
r"
272274
{pass_import}
273275
use rustc_lint::{{{context_import}, {pass_type}}};
274276
use rustc_session::declare_lint_pass;
275277
276278
"
277-
)
278-
});
279+
);
280+
}
279281

280282
let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category));
281283

282-
result.push_str(&if enable_msrv {
283-
formatdoc!(
284+
if enable_msrv {
285+
let _: fmt::Result = writedoc!(
286+
result,
284287
r"
285288
pub struct {name_camel} {{
286289
msrv: Msrv,
@@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
301304
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
302305
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
303306
"
304-
)
307+
);
305308
} else {
306-
formatdoc!(
309+
let _: fmt::Result = writedoc!(
310+
result,
307311
r"
308312
declare_lint_pass!({name_camel} => [{name_upper}]);
309313
310314
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
311315
"
312-
)
313-
});
316+
);
317+
}
314318

315319
result
316320
}

src/tools/clippy/clippy_dev/src/update_lints.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -985,17 +985,23 @@ mod tests {
985985
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
986986
];
987987
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
988-
expected.insert("group1".to_string(), vec![
989-
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
990-
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
991-
]);
992-
expected.insert("group2".to_string(), vec![Lint::new(
993-
"should_assert_eq2",
994-
"group2",
995-
"\"abc\"",
996-
"module_name",
997-
Range::default(),
998-
)]);
988+
expected.insert(
989+
"group1".to_string(),
990+
vec![
991+
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
992+
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
993+
],
994+
);
995+
expected.insert(
996+
"group2".to_string(),
997+
vec![Lint::new(
998+
"should_assert_eq2",
999+
"group2",
1000+
"\"abc\"",
1001+
"module_name",
1002+
Range::default(),
1003+
)],
1004+
);
9991005
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
10001006
}
10011007
}

src/tools/clippy/clippy_lints/src/declared_lints.rs

+4
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
292292
crate::loops::MANUAL_FIND_INFO,
293293
crate::loops::MANUAL_FLATTEN_INFO,
294294
crate::loops::MANUAL_MEMCPY_INFO,
295+
crate::loops::MANUAL_SLICE_FILL_INFO,
295296
crate::loops::MANUAL_WHILE_LET_SOME_INFO,
296297
crate::loops::MISSING_SPIN_LOOP_INFO,
297298
crate::loops::MUT_RANGE_BOUND_INFO,
@@ -321,6 +322,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
321322
crate::manual_let_else::MANUAL_LET_ELSE_INFO,
322323
crate::manual_main_separator_str::MANUAL_MAIN_SEPARATOR_STR_INFO,
323324
crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO,
325+
crate::manual_option_as_slice::MANUAL_OPTION_AS_SLICE_INFO,
324326
crate::manual_range_patterns::MANUAL_RANGE_PATTERNS_INFO,
325327
crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO,
326328
crate::manual_retain::MANUAL_RETAIN_INFO,
@@ -463,6 +465,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
463465
crate::methods::REPEAT_ONCE_INFO,
464466
crate::methods::RESULT_FILTER_MAP_INFO,
465467
crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO,
468+
crate::methods::RETURN_AND_THEN_INFO,
466469
crate::methods::SEARCH_IS_SOME_INFO,
467470
crate::methods::SEEK_FROM_CURRENT_INFO,
468471
crate::methods::SEEK_TO_START_INSTEAD_OF_REWIND_INFO,
@@ -626,6 +629,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
626629
crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO,
627630
crate::pointers_in_nomem_asm_block::POINTERS_IN_NOMEM_ASM_BLOCK_INFO,
628631
crate::precedence::PRECEDENCE_INFO,
632+
crate::precedence::PRECEDENCE_BITS_INFO,
629633
crate::ptr::CMP_NULL_INFO,
630634
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
631635
crate::ptr::MUT_FROM_REF_INFO,

src/tools/clippy/clippy_lints/src/dereference.rs

+41-26
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
291291
&& let Some(ty) = use_node.defined_ty(cx)
292292
&& TyCoercionStability::for_defined_ty(cx, ty, use_node.is_return()).is_deref_stable()
293293
{
294-
self.state = Some((State::ExplicitDeref { mutability: None }, StateData {
295-
first_expr: expr,
296-
adjusted_ty,
297-
}));
294+
self.state = Some((
295+
State::ExplicitDeref { mutability: None },
296+
StateData {
297+
first_expr: expr,
298+
adjusted_ty,
299+
},
300+
));
298301
}
299302
},
300303
RefOp::Method { mutbl, is_ufcs }
@@ -456,10 +459,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
456459
&& next_adjust.is_none_or(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
457460
&& iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
458461
{
459-
self.state = Some((State::Borrow { mutability }, StateData {
460-
first_expr: expr,
461-
adjusted_ty,
462-
}));
462+
self.state = Some((
463+
State::Borrow { mutability },
464+
StateData {
465+
first_expr: expr,
466+
adjusted_ty,
467+
},
468+
));
463469
}
464470
},
465471
_ => {},
@@ -503,10 +509,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
503509
let stability = state.stability;
504510
report(cx, expr, State::DerefedBorrow(state), data, typeck);
505511
if stability.is_deref_stable() {
506-
self.state = Some((State::Borrow { mutability }, StateData {
507-
first_expr: expr,
508-
adjusted_ty,
509-
}));
512+
self.state = Some((
513+
State::Borrow { mutability },
514+
StateData {
515+
first_expr: expr,
516+
adjusted_ty,
517+
},
518+
));
510519
}
511520
},
512521
(Some((State::DerefedBorrow(state), data)), RefOp::Deref) => {
@@ -531,10 +540,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
531540
} else if stability.is_deref_stable()
532541
&& let Some(parent) = get_parent_expr(cx, expr)
533542
{
534-
self.state = Some((State::ExplicitDeref { mutability: None }, StateData {
535-
first_expr: parent,
536-
adjusted_ty,
537-
}));
543+
self.state = Some((
544+
State::ExplicitDeref { mutability: None },
545+
StateData {
546+
first_expr: parent,
547+
adjusted_ty,
548+
},
549+
));
538550
}
539551
},
540552

@@ -1124,17 +1136,20 @@ impl<'tcx> Dereferencing<'tcx> {
11241136
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
11251137
if let Some(pat) = outer_pat {
11261138
// Check for auto-deref
1127-
if !matches!(cx.typeck_results().expr_adjustments(e), [
1128-
Adjustment {
1129-
kind: Adjust::Deref(_),
1130-
..
1131-
},
1132-
Adjustment {
1133-
kind: Adjust::Deref(_),
1139+
if !matches!(
1140+
cx.typeck_results().expr_adjustments(e),
1141+
[
1142+
Adjustment {
1143+
kind: Adjust::Deref(_),
1144+
..
1145+
},
1146+
Adjustment {
1147+
kind: Adjust::Deref(_),
1148+
..
1149+
},
11341150
..
1135-
},
1136-
..
1137-
]) {
1151+
]
1152+
) {
11381153
match get_parent_expr(cx, e) {
11391154
// Field accesses are the same no matter the number of references.
11401155
Some(Expr {

src/tools/clippy/clippy_lints/src/doc/empty_line_after.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,13 @@ fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool {
233233
if let Some(owner) = cx.last_node_with_lint_attrs.as_owner() {
234234
let def_id = owner.to_def_id();
235235
let def_descr = cx.tcx.def_descr(def_id);
236-
diag.span_label(cx.tcx.def_span(def_id), match kind {
237-
StopKind::Attr => format!("the attribute applies to this {def_descr}"),
238-
StopKind::Doc(_) => format!("the comment documents this {def_descr}"),
239-
});
236+
diag.span_label(
237+
cx.tcx.def_span(def_id),
238+
match kind {
239+
StopKind::Attr => format!("the attribute applies to this {def_descr}"),
240+
StopKind::Doc(_) => format!("the comment documents this {def_descr}"),
241+
},
242+
);
240243
}
241244

242245
diag.multipart_suggestion_with_style(

src/tools/clippy/clippy_lints/src/endian_bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
66
use rustc_middle::ty::Ty;
77
use rustc_session::declare_lint_pass;
88
use rustc_span::Symbol;
9+
use std::fmt::Write;
910

1011
declare_clippy_lint! {
1112
/// ### What it does
@@ -183,7 +184,7 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
183184
help_str.push_str("either of ");
184185
}
185186

186-
help_str.push_str(&format!("`{ty}::{}` ", lint.as_name(prefix)));
187+
write!(help_str, "`{ty}::{}` ", lint.as_name(prefix)).unwrap();
187188

188189
if i != len && !only_one {
189190
help_str.push_str("or ");

src/tools/clippy/clippy_lints/src/eta_reduction.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::higher::VecArgs;
3-
use clippy_utils::source::snippet_opt;
3+
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
44
use clippy_utils::ty::get_type_diagnostic_name;
55
use clippy_utils::usage::{local_used_after_expr, local_used_in};
66
use clippy_utils::{
77
get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id,
88
};
99
use rustc_errors::Applicability;
10-
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind};
10+
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind};
1111
use rustc_infer::infer::TyCtxtInferExt;
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_middle::ty::{
@@ -239,6 +239,11 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
239239
&& !cx.tcx.has_attr(method_def_id, sym::track_caller)
240240
&& check_sig(closure_sig, cx.tcx.fn_sig(method_def_id).skip_binder().skip_binder())
241241
{
242+
let mut app = Applicability::MachineApplicable;
243+
let generic_args = match path.args.and_then(GenericArgs::span_ext) {
244+
Some(span) => format!("::{}", snippet_with_applicability(cx, span, "<..>", &mut app)),
245+
None => String::new(),
246+
};
242247
span_lint_and_then(
243248
cx,
244249
REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
@@ -251,8 +256,8 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
251256
diag.span_suggestion(
252257
expr.span,
253258
"replace the closure with the method itself",
254-
format!("{}::{}", type_name, path.ident.name),
255-
Applicability::MachineApplicable,
259+
format!("{}::{}{}", type_name, path.ident.name, generic_args),
260+
app,
256261
);
257262
},
258263
);

src/tools/clippy/clippy_lints/src/excessive_nesting.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ struct NestingVisitor<'conf, 'cx> {
124124

125125
impl NestingVisitor<'_, '_> {
126126
fn check_indent(&mut self, span: Span, id: NodeId) -> bool {
127-
if self.nest_level > self.conf.excessive_nesting_threshold && !span.in_external_macro(self.cx.sess().source_map()) {
127+
if self.nest_level > self.conf.excessive_nesting_threshold
128+
&& !span.in_external_macro(self.cx.sess().source_map())
129+
{
128130
self.conf.nodes.insert(id);
129131

130132
return true;

0 commit comments

Comments
 (0)