Skip to content

Clippy subtree update #136645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 75 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a7adb82
Move `format_push_string` and `format_collect` to pedantic
smoelius Dec 29, 2024
65b95a2
fix escaping problem in `write_literal` and `print_literal` lint
lapla-cogito Jan 12, 2025
87f7e21
Address review comments
smoelius Jan 14, 2025
bbd58d1
Do not trigger `[size_of_in_element_count]` for `u8`
samueltardieu Jan 16, 2025
5bd989a
Update version for unneeded_struct_pattern
alex-semenyuk Jan 19, 2025
7aae4f4
auto-fix for redundant_else lint
lapla-cogito Jan 3, 2025
f0b99b2
`needless_option_take`: add autofix
samueltardieu Jan 20, 2025
13be95a
new `manual_option_as_slice` lint
llogiq Dec 29, 2024
9da9ddb
Merge commit '51d49c1ae2785b24ef18a46ef233fc1d91844666' into clippy-s…
flip1995 Jan 28, 2025
9ede32f
`needless_option_take`: add autofix (#14042)
llogiq Jan 28, 2025
abb3e8e
Make item self/non-self bound naming less whack
compiler-errors Jan 22, 2025
d7874f4
Refactor FnKind variant to hold &Fn
celinval Jan 28, 2025
6a209cd
Fix escaping problem in `write_literal` and `print_literal` lint sugg…
Centri3 Jan 28, 2025
e02c885
Move `format_push_string` and `format_collect` to pedantic (#13894)
Centri3 Jan 28, 2025
e84c8b8
Rollup merge of #135902 - compiler-errors:item-non-self-bound-in-new-…
fmease Jan 29, 2025
a4eff9d
Rollup merge of #136164 - celinval:chores-fnkind, r=oli-obk
fmease Jan 29, 2025
7eefa76
Eliminate PatKind::Path
oli-obk Dec 12, 2024
84fb6b1
Add new lint `return_and_then`
aaron-ang Jan 26, 2025
78d6b2e
Do not remove semicolon if it changes the block type
samueltardieu Jan 29, 2025
e4505fb
Include generic arguments when suggesting a closure η-reduction
samueltardieu Jan 29, 2025
88a00a8
autofix for `redundant_else` lint (#13936)
blyxyas Jan 30, 2025
ad05bc0
Include generic arguments when suggesting a closure η-reduction (#14105)
llogiq Jan 30, 2025
f8be518
Move mutex_integer to restriction and improve mutex_{integer,atomic} …
taiki-e Jan 30, 2025
8db9ecf
New lint: `precedence_bits`, with recent additions to `precedence`
samueltardieu Jan 30, 2025
7399338
introduce `ty::Value`
Jan 27, 2025
33bb8af
Fix expand/collapse all on site, make highlightjs lazier
Alexendoo Jan 19, 2025
d49b1ff
Implement --perf flag to lintcheck for benchmarking
blyxyas Jan 30, 2025
fc00cdc
Actually make --perf imply -j=1, review comments
blyxyas Jan 30, 2025
f51e18d
feat: new lint for `and_then` when returning Option or Result (#14051)
Centri3 Jan 30, 2025
5aa8bc1
`sliced_string_as_bytes`: fix typo in lint description
samueltardieu Jan 30, 2025
398a5c2
New lint: `precedence_bits`, with recent additions to `precedence` (#…
llogiq Jan 30, 2025
e188c7d
`sliced_string_as_bytes`: fix typo in lint description (#14117)
Centri3 Jan 30, 2025
d79f862
Do not remove semicolon if it changes the block type (#14103)
dswij Jan 31, 2025
27454db
Insert null checks for pointer dereferences when debug assertions are…
1c3t3a Dec 17, 2024
48ae7ec
Adress review comments
blyxyas Jan 31, 2025
9c8fe30
Auto merge of #134424 - 1c3t3a:null-checks, r=saethlin
bors Jan 31, 2025
62c68e1
Implement MIR, CTFE, and codegen for unsafe binders
compiler-errors Jan 31, 2025
a9434c0
Enforce unsafe binders must be Copy (for now)
compiler-errors Jan 31, 2025
64fcb00
Rename `tcx.ensure()` to `tcx.ensure_ok()`
Zalathar Jan 30, 2025
7848488
Use a better message for `toplevel_ref_arg` lint
samueltardieu Feb 1, 2025
7e5cfbe
Use a better message for `toplevel_ref_arg` lint (#14132)
Manishearth Feb 1, 2025
984cc68
Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obk
matthiaskrgr Feb 1, 2025
c607f78
Fix expand/collapse all on site, make highlightjs lazier (#14038)
blyxyas Feb 1, 2025
3155dab
add autofix for `cmp_null`
lapla-cogito Jan 31, 2025
b8d0b16
autofix for `cmp_null` (#14122)
Alexendoo Feb 1, 2025
d30f045
Convert two `rustc_middle::lint` functions to `Span` methods.
nnethercote Feb 2, 2025
56b5d11
Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obk
matthiaskrgr Feb 2, 2025
af18dce
remove "Known problems" of `verbose_bit_mask`
lapla-cogito Feb 2, 2025
0d3fd98
remove "Known problems" of `verbose_bit_mask` (#14137)
llogiq Feb 2, 2025
6d1482c
Implement --perf flag to lintcheck for benchmarking (#14116)
Alexendoo Feb 2, 2025
abdee77
Some cleanups around EarlyDiagCtxt
bjorn3 Feb 2, 2025
f8d702b
Rollup merge of #136422 - nnethercote:convert-lint-functions, r=Norat…
matthiaskrgr Feb 2, 2025
1a8e9b9
Rollup merge of #136445 - bjorn3:diag_ctxt_cleanup, r=oli-obk
matthiaskrgr Feb 2, 2025
3d6e090
add `SLICE_FILL` to msrv
lapla-cogito Jan 27, 2025
e82b1f4
add `manual_slice_fill` lint
lapla-cogito Jan 27, 2025
07ede9c
ignore `manual_slice_fill` in other test files
lapla-cogito Jan 30, 2025
2c51951
add `manual_slice_fill` lint (#14082)
llogiq Feb 3, 2025
c1e4249
Use a different hir type for patterns in pattern types than we use in…
oli-obk Jan 7, 2025
1112801
Contracts core intrinsics.
pnkfelix Dec 2, 2024
0a8331f
Express contracts as part of function header and lower it to the cont…
celinval Jan 9, 2025
c5218d5
new `manual_option_as_slice` lint (#13901)
blyxyas Feb 3, 2025
75e3a2e
Move mutex_integer to restriction and improve mutex_{integer,atomic} …
Jarcho Feb 4, 2025
270e52f
fix: manual_unwrap_or_default
profetia Feb 5, 2025
4c11087
Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk
fmease Feb 5, 2025
e6d9641
fix: `manual_unwrap_or_default` suggests falsely when condition type …
llogiq Feb 5, 2025
390286d
Update version for unneeded_struct_pattern (#14031)
Alexendoo Feb 5, 2025
c718ae8
Add Nursery and Deprecated lints section at Book
alex-semenyuk Dec 26, 2024
f09701a
Do not trigger `[size_of_in_element_count]` for `u8` (#14011)
blyxyas Feb 5, 2025
694b245
Fix docs for `#[clippy::format_args]`
nyurik Feb 6, 2025
ee1c15e
Add Nursery and Deprecated groups section at Book (#13926)
flip1995 Feb 6, 2025
660d861
Fix docs for `#[clippy::format_args]` (#14161)
flip1995 Feb 6, 2025
f549562
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Feb 6, 2025
9f31768
Bump nightly version -> 2025-02-06
flip1995 Feb 6, 2025
3e3715c
Rustup (#14163)
flip1995 Feb 6, 2025
daa82a1
Merge commit '3e3715c31236bff56f1c63a1de2c7bbdfcfb0923' into clippy-s…
flip1995 Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5765,6 +5765,7 @@ Released 2018-09-13
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
[`manual_ok_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
[`manual_option_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice
[`manual_pattern_char_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
[`manual_range_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns
@@ -5773,6 +5774,7 @@ Released 2018-09-13
[`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain
[`manual_rotate`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rotate
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
[`manual_slice_fill`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill
[`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation
[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once
[`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat
@@ -5954,6 +5956,7 @@ Released 2018-09-13
[`positional_named_format_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#positional_named_format_parameters
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
[`precedence_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence_bits
[`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl
[`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
[`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr
@@ -6026,6 +6029,7 @@ Released 2018-09-13
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
[`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used
[`return_and_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_and_then
[`return_self_not_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use
[`reverse_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#reverse_range_loop
[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/attribs.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ To do this, Clippy provides attributes that can be applied to items in the 3rd p

## `#[clippy::format_args]`

_Available since Clippy v1.84_
_Available since Clippy v1.85_

This attribute can be added to a macro that supports `format!`, `println!`, or similar syntax.
It tells Clippy that the macro is a formatting macro, and that the arguments to the macro
1 change: 1 addition & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
@@ -752,6 +752,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
* [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid)
* [`manual_repeat_n`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n)
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
* [`manual_slice_fill`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill)
* [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once)
* [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat)
* [`manual_strip`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip)
13 changes: 13 additions & 0 deletions src/tools/clippy/book/src/lints.md
Original file line number Diff line number Diff line change
@@ -101,5 +101,18 @@ The `clippy::cargo` group gives you suggestions on how to improve your
your crate and are not sure if you have all useful information in your
`Cargo.toml`.

## Nursery

The `clippy::nursery` group contains lints which are buggy or need more work. It is **not**
recommended to enable the whole group, but rather cherry-pick lints that are useful for your
code base and your use case.

## Deprecated

The `clippy::deprecated` is empty lints that exist to ensure that `#[allow(lintname)]` still
compiles after the lint was deprecated. Deprecation "removes" lints by removing their
functionality and marking them as deprecated, which may cause further warnings but cannot
cause a compiler error.

[Clippy lint documentation]: https://rust-lang.github.io/rust-clippy/
[Clippy 1.0 RFC]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
@@ -621,6 +621,7 @@ define_Conf! {
manual_rem_euclid,
manual_repeat_n,
manual_retain,
manual_slice_fill,
manual_split_once,
manual_str_repeat,
manual_strip,
28 changes: 16 additions & 12 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
@@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
let name_camel = to_camel_case(lint.name);
let name_upper = lint_name.to_uppercase();

result.push_str(&if enable_msrv {
formatdoc!(
if enable_msrv {
let _: fmt::Result = writedoc!(
result,
r"
use clippy_utils::msrvs::{{self, Msrv}};
use clippy_config::Conf;
@@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
use rustc_session::impl_lint_pass;

"
)
);
} else {
formatdoc!(
let _: fmt::Result = writedoc!(
result,
r"
{pass_import}
use rustc_lint::{{{context_import}, {pass_type}}};
use rustc_session::declare_lint_pass;

"
)
});
);
}

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

result.push_str(&if enable_msrv {
formatdoc!(
if enable_msrv {
let _: fmt::Result = writedoc!(
result,
r"
pub struct {name_camel} {{
msrv: Msrv,
@@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
"
)
);
} else {
formatdoc!(
let _: fmt::Result = writedoc!(
result,
r"
declare_lint_pass!({name_camel} => [{name_upper}]);

impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
"
)
});
);
}

result
}
28 changes: 17 additions & 11 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
@@ -985,17 +985,23 @@ mod tests {
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
];
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
expected.insert("group1".to_string(), vec![
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
]);
expected.insert("group2".to_string(), vec![Lint::new(
"should_assert_eq2",
"group2",
"\"abc\"",
"module_name",
Range::default(),
)]);
expected.insert(
"group1".to_string(),
vec![
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
],
);
expected.insert(
"group2".to_string(),
vec![Lint::new(
"should_assert_eq2",
"group2",
"\"abc\"",
"module_name",
Range::default(),
)],
);
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
}
}
4 changes: 4 additions & 0 deletions src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
@@ -292,6 +292,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::loops::MANUAL_FIND_INFO,
crate::loops::MANUAL_FLATTEN_INFO,
crate::loops::MANUAL_MEMCPY_INFO,
crate::loops::MANUAL_SLICE_FILL_INFO,
crate::loops::MANUAL_WHILE_LET_SOME_INFO,
crate::loops::MISSING_SPIN_LOOP_INFO,
crate::loops::MUT_RANGE_BOUND_INFO,
@@ -321,6 +322,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::manual_let_else::MANUAL_LET_ELSE_INFO,
crate::manual_main_separator_str::MANUAL_MAIN_SEPARATOR_STR_INFO,
crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO,
crate::manual_option_as_slice::MANUAL_OPTION_AS_SLICE_INFO,
crate::manual_range_patterns::MANUAL_RANGE_PATTERNS_INFO,
crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO,
crate::manual_retain::MANUAL_RETAIN_INFO,
@@ -463,6 +465,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::methods::REPEAT_ONCE_INFO,
crate::methods::RESULT_FILTER_MAP_INFO,
crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO,
crate::methods::RETURN_AND_THEN_INFO,
crate::methods::SEARCH_IS_SOME_INFO,
crate::methods::SEEK_FROM_CURRENT_INFO,
crate::methods::SEEK_TO_START_INSTEAD_OF_REWIND_INFO,
@@ -626,6 +629,7 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO,
crate::pointers_in_nomem_asm_block::POINTERS_IN_NOMEM_ASM_BLOCK_INFO,
crate::precedence::PRECEDENCE_INFO,
crate::precedence::PRECEDENCE_BITS_INFO,
crate::ptr::CMP_NULL_INFO,
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
crate::ptr::MUT_FROM_REF_INFO,
67 changes: 41 additions & 26 deletions src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
@@ -291,10 +291,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
&& let Some(ty) = use_node.defined_ty(cx)
&& TyCoercionStability::for_defined_ty(cx, ty, use_node.is_return()).is_deref_stable()
{
self.state = Some((State::ExplicitDeref { mutability: None }, StateData {
first_expr: expr,
adjusted_ty,
}));
self.state = Some((
State::ExplicitDeref { mutability: None },
StateData {
first_expr: expr,
adjusted_ty,
},
));
}
},
RefOp::Method { mutbl, is_ufcs }
@@ -456,10 +459,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
&& next_adjust.is_none_or(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
&& iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
{
self.state = Some((State::Borrow { mutability }, StateData {
first_expr: expr,
adjusted_ty,
}));
self.state = Some((
State::Borrow { mutability },
StateData {
first_expr: expr,
adjusted_ty,
},
));
}
},
_ => {},
@@ -503,10 +509,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
let stability = state.stability;
report(cx, expr, State::DerefedBorrow(state), data, typeck);
if stability.is_deref_stable() {
self.state = Some((State::Borrow { mutability }, StateData {
first_expr: expr,
adjusted_ty,
}));
self.state = Some((
State::Borrow { mutability },
StateData {
first_expr: expr,
adjusted_ty,
},
));
}
},
(Some((State::DerefedBorrow(state), data)), RefOp::Deref) => {
@@ -531,10 +540,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
} else if stability.is_deref_stable()
&& let Some(parent) = get_parent_expr(cx, expr)
{
self.state = Some((State::ExplicitDeref { mutability: None }, StateData {
first_expr: parent,
adjusted_ty,
}));
self.state = Some((
State::ExplicitDeref { mutability: None },
StateData {
first_expr: parent,
adjusted_ty,
},
));
}
},

@@ -1124,17 +1136,20 @@ impl<'tcx> Dereferencing<'tcx> {
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
if let Some(pat) = outer_pat {
// Check for auto-deref
if !matches!(cx.typeck_results().expr_adjustments(e), [
Adjustment {
kind: Adjust::Deref(_),
..
},
Adjustment {
kind: Adjust::Deref(_),
if !matches!(
cx.typeck_results().expr_adjustments(e),
[
Adjustment {
kind: Adjust::Deref(_),
..
},
Adjustment {
kind: Adjust::Deref(_),
..
},
..
},
..
]) {
]
) {
match get_parent_expr(cx, e) {
// Field accesses are the same no matter the number of references.
Some(Expr {
11 changes: 7 additions & 4 deletions src/tools/clippy/clippy_lints/src/doc/empty_line_after.rs
Original file line number Diff line number Diff line change
@@ -233,10 +233,13 @@ fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool {
if let Some(owner) = cx.last_node_with_lint_attrs.as_owner() {
let def_id = owner.to_def_id();
let def_descr = cx.tcx.def_descr(def_id);
diag.span_label(cx.tcx.def_span(def_id), match kind {
StopKind::Attr => format!("the attribute applies to this {def_descr}"),
StopKind::Doc(_) => format!("the comment documents this {def_descr}"),
});
diag.span_label(
cx.tcx.def_span(def_id),
match kind {
StopKind::Attr => format!("the attribute applies to this {def_descr}"),
StopKind::Doc(_) => format!("the comment documents this {def_descr}"),
},
);
}

diag.multipart_suggestion_with_style(
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_lints/src/endian_bytes.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::Ty;
use rustc_session::declare_lint_pass;
use rustc_span::Symbol;
use std::fmt::Write;

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

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

if i != len && !only_one {
help_str.push_str("or ");
13 changes: 9 additions & 4 deletions src/tools/clippy/clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::higher::VecArgs;
use clippy_utils::source::snippet_opt;
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
use clippy_utils::ty::get_type_diagnostic_name;
use clippy_utils::usage::{local_used_after_expr, local_used_in};
use clippy_utils::{
get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id,
};
use rustc_errors::Applicability;
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind};
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{
@@ -239,6 +239,11 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
&& !cx.tcx.has_attr(method_def_id, sym::track_caller)
&& check_sig(closure_sig, cx.tcx.fn_sig(method_def_id).skip_binder().skip_binder())
{
let mut app = Applicability::MachineApplicable;
let generic_args = match path.args.and_then(GenericArgs::span_ext) {
Some(span) => format!("::{}", snippet_with_applicability(cx, span, "<..>", &mut app)),
None => String::new(),
};
span_lint_and_then(
cx,
REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
@@ -251,8 +256,8 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
diag.span_suggestion(
expr.span,
"replace the closure with the method itself",
format!("{}::{}", type_name, path.ident.name),
Applicability::MachineApplicable,
format!("{}::{}{}", type_name, path.ident.name, generic_args),
app,
);
},
);
4 changes: 3 additions & 1 deletion src/tools/clippy/clippy_lints/src/excessive_nesting.rs
Original file line number Diff line number Diff line change
@@ -124,7 +124,9 @@ struct NestingVisitor<'conf, 'cx> {

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

return true;
Loading