Skip to content

Commit 223db20

Browse files
committed
Auto merge of #156552 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? Manishearth `Cargo.lock` update due to patch version bump in `ui_test`. One day early, as I won't have access to my laptop from tomorrow till Sunday
2 parents ff9a9ea + 4e3fe3e commit 223db20

102 files changed

Lines changed: 2048 additions & 546 deletions

File tree

Some content is hidden

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

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5948,9 +5948,9 @@ checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
59485948

59495949
[[package]]
59505950
name = "ui_test"
5951-
version = "0.30.4"
5951+
version = "0.30.5"
59525952
source = "registry+https://github.com/rust-lang/crates.io-index"
5953-
checksum = "ada249620d81f010b9a1472b63a5077ac7c722dd0f4bacf6528b313d0b8c15d8"
5953+
checksum = "980133b75aa9a95dc94feaf629d92d22c1172186f1fa1266b91f5b91414cf9a5"
59545954
dependencies = [
59555955
"annotate-snippets 0.11.5",
59565956
"anyhow",

src/tools/clippy/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6805,6 +6805,7 @@ Released 2018-09-13
68056805
[`inline_asm_x86_intel_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_intel_syntax
68066806
[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body
68076807
[`inline_modules`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_modules
6808+
[`inline_trait_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_trait_bounds
68086809
[`inspect_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#inspect_for_each
68096810
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
68106811
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
@@ -6885,6 +6886,7 @@ Released 2018-09-13
68856886
[`manual_c_str_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals
68866887
[`manual_checked_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_checked_ops
68876888
[`manual_clamp`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp
6889+
[`manual_clear`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clear
68886890
[`manual_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_contains
68896891
[`manual_dangling_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_dangling_ptr
68906892
[`manual_div_ceil`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_div_ceil
@@ -7238,6 +7240,7 @@ Released 2018-09-13
72387240
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
72397241
[`sliced_string_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#sliced_string_as_bytes
72407242
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
7243+
[`some_filter`]: https://rust-lang.github.io/rust-clippy/master/index.html#some_filter
72417244
[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
72427245
[`std_instead_of_alloc`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc
72437246
[`std_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core

src/tools/clippy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ anstream = "0.6.18"
3434

3535
[dev-dependencies]
3636
cargo_metadata = "0.23"
37-
ui_test = "0.30.2"
37+
ui_test = "0.30.5"
3838
regex = "1.5.5"
3939
serde = { version = "1.0.145", features = ["derive"] }
4040
serde_json = "1.0.122"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ The different lint groups were defined in the [Clippy 1.0 RFC].
1414

1515
## Correctness
1616

17-
The `clippy::correctness` group is the only lint group in Clippy which lints are
17+
The `clippy::correctness` group is the only lint group in Clippy whose lints are
1818
deny-by-default and abort the compilation when triggered. This is for good
19-
reason: If you see a `correctness` lint, it means that your code is outright
19+
reason: if you see a `correctness` lint, it means that your code is outright
2020
wrong or useless, and you should try to fix it.
2121

2222
Lints in this category are carefully picked and should be free of false

src/tools/clippy/clippy_lints/src/booleans.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ impl<'v> Hir2Qmm<'_, '_, 'v> {
297297
return Err("contains never type".to_owned());
298298
}
299299

300+
let ctxt = e.span.ctxt();
300301
for (n, expr) in self.terminals.iter().enumerate() {
301-
if eq_expr_value(self.cx, e, expr) {
302+
if eq_expr_value(self.cx, ctxt, e, expr) {
302303
#[expect(clippy::cast_possible_truncation)]
303304
return Ok(Bool::Term(n as u8));
304305
}
@@ -307,8 +308,8 @@ impl<'v> Hir2Qmm<'_, '_, 'v> {
307308
&& implements_ord(self.cx, e_lhs)
308309
&& let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind
309310
&& negate(e_binop.node) == Some(expr_binop.node)
310-
&& eq_expr_value(self.cx, e_lhs, expr_lhs)
311-
&& eq_expr_value(self.cx, e_rhs, expr_rhs)
311+
&& eq_expr_value(self.cx, ctxt, e_lhs, expr_lhs)
312+
&& eq_expr_value(self.cx, ctxt, e_rhs, expr_rhs)
312313
{
313314
#[expect(clippy::cast_possible_truncation)]
314315
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));

src/tools/clippy/clippy_lints/src/checked_conversions.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
77
use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, TyKind};
88
use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_session::impl_lint_pass;
10-
use rustc_span::Symbol;
10+
use rustc_span::{Symbol, SyntaxContext};
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
@@ -62,7 +62,8 @@ impl LateLintPass<'_> for CheckedConversions {
6262
},
6363
_ => return,
6464
}
65-
&& !item.span.in_external_macro(cx.sess().source_map())
65+
&& let ctxt = item.span.ctxt()
66+
&& !ctxt.in_external_macro(cx.sess().source_map())
6667
&& !is_in_const_context(cx)
6768
&& let Some(cv) = match op2 {
6869
// todo: check for case signed -> larger unsigned == only x >= 0
@@ -71,7 +72,7 @@ impl LateLintPass<'_> for CheckedConversions {
7172
let upper_lower = |lt1, gt1, lt2, gt2| {
7273
check_upper_bound(lt1, gt1)
7374
.zip(check_lower_bound(lt2, gt2))
74-
.and_then(|(l, r)| l.combine(r, cx))
75+
.and_then(|(l, r)| l.combine(r, cx, ctxt))
7576
};
7677
upper_lower(lt1, gt1, lt2, gt2).or_else(|| upper_lower(lt2, gt2, lt1, gt1))
7778
},
@@ -126,8 +127,8 @@ fn read_le_ge<'tcx>(
126127

127128
impl<'a> Conversion<'a> {
128129
/// Combine multiple conversions if the are compatible
129-
pub fn combine(self, other: Self, cx: &LateContext<'_>) -> Option<Conversion<'a>> {
130-
if self.is_compatible(&other, cx) {
130+
pub fn combine(self, other: Self, cx: &LateContext<'_>, ctxt: SyntaxContext) -> Option<Conversion<'a>> {
131+
if self.is_compatible(&other, cx, ctxt) {
131132
// Prefer a Conversion that contains a type-constraint
132133
Some(if self.to_type.is_some() { self } else { other })
133134
} else {
@@ -137,9 +138,9 @@ impl<'a> Conversion<'a> {
137138

138139
/// Checks if two conversions are compatible
139140
/// same type of conversion, same 'castee' and same 'to type'
140-
pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>) -> bool {
141+
pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>, ctxt: SyntaxContext) -> bool {
141142
(self.cvt == other.cvt)
142-
&& (SpanlessEq::new(cx).eq_expr(self.expr_to_cast, other.expr_to_cast))
143+
&& (SpanlessEq::new(cx).eq_expr(ctxt, self.expr_to_cast, other.expr_to_cast))
143144
&& (self.has_compatible_to_type(other))
144145
}
145146

src/tools/clippy/clippy_lints/src/comparison_chain.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::{BinOpKind, Expr, ExprKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::declare_lint_pass;
9-
use rustc_span::sym;
9+
use rustc_span::{SyntaxContext, sym};
1010

1111
declare_clippy_lint! {
1212
/// ### What it does
@@ -90,8 +90,10 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
9090

9191
// Check that both sets of operands are equal
9292
let mut spanless_eq = SpanlessEq::new(cx);
93-
let same_fixed_operands = spanless_eq.eq_expr(lhs1, lhs2) && spanless_eq.eq_expr(rhs1, rhs2);
94-
let same_transposed_operands = spanless_eq.eq_expr(lhs1, rhs2) && spanless_eq.eq_expr(rhs1, lhs2);
93+
let same_fixed_operands = spanless_eq.eq_expr(SyntaxContext::root(), lhs1, lhs2)
94+
&& spanless_eq.eq_expr(SyntaxContext::root(), rhs1, rhs2);
95+
let same_transposed_operands = spanless_eq.eq_expr(SyntaxContext::root(), lhs1, rhs2)
96+
&& spanless_eq.eq_expr(SyntaxContext::root(), rhs1, lhs2);
9597

9698
if !same_fixed_operands && !same_transposed_operands {
9799
return;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
232232
crate::inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY_INFO,
233233
crate::init_numbered_fields::INIT_NUMBERED_FIELDS_INFO,
234234
crate::inline_fn_without_body::INLINE_FN_WITHOUT_BODY_INFO,
235+
crate::inline_trait_bounds::INLINE_TRAIT_BOUNDS_INFO,
235236
crate::int_plus_one::INT_PLUS_ONE_INFO,
236237
crate::item_name_repetitions::ENUM_VARIANT_NAMES_INFO,
237238
crate::item_name_repetitions::MODULE_INCEPTION_INFO,
@@ -414,6 +415,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
414415
crate::methods::JOIN_ABSOLUTE_PATHS_INFO,
415416
crate::methods::LINES_FILTER_MAP_OK_INFO,
416417
crate::methods::MANUAL_C_STR_LITERALS_INFO,
418+
crate::methods::MANUAL_CLEAR_INFO,
417419
crate::methods::MANUAL_CONTAINS_INFO,
418420
crate::methods::MANUAL_FILTER_MAP_INFO,
419421
crate::methods::MANUAL_FIND_MAP_INFO,
@@ -474,6 +476,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
474476
crate::methods::SINGLE_CHAR_ADD_STR_INFO,
475477
crate::methods::SKIP_WHILE_NEXT_INFO,
476478
crate::methods::SLICED_STRING_AS_BYTES_INFO,
479+
crate::methods::SOME_FILTER_INFO,
477480
crate::methods::STABLE_SORT_PRIMITIVE_INFO,
478481
crate::methods::STR_SPLIT_AT_NEWLINE_INFO,
479482
crate::methods::STRING_EXTEND_CHARS_INFO,

src/tools/clippy/clippy_lints/src/entry.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
498498
}
499499

500500
match try_parse_insert(self.cx, expr) {
501-
Some(insert_expr) if self.spanless_eq.eq_expr(self.map, insert_expr.map) => {
501+
Some(insert_expr) if self.spanless_eq.eq_expr(self.ctxt, self.map, insert_expr.map) => {
502502
self.visit_insert_expr_arguments(&insert_expr);
503503
// Multiple inserts, inserts with a different key, and inserts from a macro can't use the entry api.
504504
if self.is_map_used
505-
|| !self.spanless_eq.eq_expr(self.key, insert_expr.key)
505+
|| !self.spanless_eq.eq_expr(self.ctxt, self.key, insert_expr.key)
506506
|| expr.span.ctxt() != self.ctxt
507507
{
508508
self.can_use_entry = false;
@@ -521,10 +521,10 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
521521
self.visit_non_tail_expr(insert_expr.value);
522522
self.is_single_insert = is_single_insert;
523523
},
524-
_ if is_any_expr_in_map_used(self.cx, &mut self.spanless_eq, self.map, expr) => {
524+
_ if is_any_expr_in_map_used(self.cx, &mut self.spanless_eq, self.ctxt, self.map, expr) => {
525525
self.is_map_used = true;
526526
},
527-
_ if self.spanless_eq.eq_expr(self.key, expr) => {
527+
_ if self.spanless_eq.eq_expr(self.ctxt, self.key, expr) => {
528528
self.is_key_used = true;
529529
},
530530
_ => match expr.kind {
@@ -600,11 +600,12 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
600600
fn is_any_expr_in_map_used<'tcx>(
601601
cx: &LateContext<'tcx>,
602602
spanless_eq: &mut SpanlessEq<'_, 'tcx>,
603+
ctxt: SyntaxContext,
603604
map: &'tcx Expr<'tcx>,
604605
expr: &'tcx Expr<'tcx>,
605606
) -> bool {
606607
for_each_expr(cx, map, |e| {
607-
if spanless_eq.eq_expr(e, expr) {
608+
if spanless_eq.eq_expr(ctxt, e, expr) {
608609
return ControlFlow::Break(());
609610
}
610611
ControlFlow::Continue(())

src/tools/clippy/clippy_lints/src/floating_point_arithmetic/custom_abs.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ use super::SUBOPTIMAL_FLOPS;
1414
/// test is positive or an expression which tests whether or not test
1515
/// is nonnegative.
1616
/// Used for check-custom-abs function below
17-
fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
17+
fn is_testing_positive(cx: &LateContext<'_>, ctxt: SyntaxContext, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
1818
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
1919
match op {
20-
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right, expr.span.ctxt()) && eq_expr_value(cx, left, test),
21-
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, left, expr.span.ctxt()) && eq_expr_value(cx, right, test),
20+
BinOpKind::Gt | BinOpKind::Ge => {
21+
is_zero(cx, right, expr.span.ctxt()) && eq_expr_value(cx, ctxt, left, test)
22+
},
23+
BinOpKind::Lt | BinOpKind::Le => {
24+
is_zero(cx, left, expr.span.ctxt()) && eq_expr_value(cx, ctxt, right, test)
25+
},
2226
_ => false,
2327
}
2428
} else {
@@ -27,11 +31,15 @@ fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -
2731
}
2832

2933
/// See [`is_testing_positive`]
30-
fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
34+
fn is_testing_negative(cx: &LateContext<'_>, ctxt: SyntaxContext, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
3135
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
3236
match op {
33-
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left, expr.span.ctxt()) && eq_expr_value(cx, right, test),
34-
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, right, expr.span.ctxt()) && eq_expr_value(cx, left, test),
37+
BinOpKind::Gt | BinOpKind::Ge => {
38+
is_zero(cx, left, expr.span.ctxt()) && eq_expr_value(cx, ctxt, right, test)
39+
},
40+
BinOpKind::Lt | BinOpKind::Le => {
41+
is_zero(cx, right, expr.span.ctxt()) && eq_expr_value(cx, ctxt, left, test)
42+
},
3543
_ => false,
3644
}
3745
} else {
@@ -55,14 +63,21 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>, ctxt: SyntaxContext) -> bool {
5563
/// one of the two expressions
5664
/// If the two expressions are not negations of each other, then it
5765
/// returns None.
58-
fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> {
66+
fn are_negated<'a>(
67+
cx: &LateContext<'_>,
68+
ctxt: SyntaxContext,
69+
expr1: &'a Expr<'a>,
70+
expr2: &'a Expr<'a>,
71+
) -> Option<(bool, &'a Expr<'a>)> {
5972
if let ExprKind::Unary(UnOp::Neg, expr1_negated) = expr1.kind
60-
&& eq_expr_value(cx, expr1_negated, expr2)
73+
&& expr1_negated.span.ctxt() == ctxt
74+
&& eq_expr_value(cx, ctxt, expr1_negated, expr2)
6175
{
6276
return Some((false, expr2));
6377
}
6478
if let ExprKind::Unary(UnOp::Neg, expr2_negated) = expr2.kind
65-
&& eq_expr_value(cx, expr1, expr2_negated)
79+
&& expr2_negated.span.ctxt() == ctxt
80+
&& eq_expr_value(cx, ctxt, expr1, expr2_negated)
6681
{
6782
return Some((true, expr1));
6883
}
@@ -77,11 +92,12 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
7792
}) = higher::If::hir(expr)
7893
&& let if_body_expr = peel_blocks(then)
7994
&& let else_body_expr = peel_blocks(r#else)
80-
&& let Some((if_expr_positive, body)) = are_negated(cx, if_body_expr, else_body_expr)
95+
&& let ctxt = expr.span.ctxt()
96+
&& let Some((if_expr_positive, body)) = are_negated(cx, ctxt, if_body_expr, else_body_expr)
8197
{
82-
let sugg_positive_abs = if is_testing_positive(cx, cond, body) {
98+
let sugg_positive_abs = if is_testing_positive(cx, ctxt, cond, body) {
8399
if_expr_positive
84-
} else if is_testing_negative(cx, cond, body) {
100+
} else if is_testing_negative(cx, ctxt, cond, body) {
85101
!if_expr_positive
86102
} else {
87103
return;

0 commit comments

Comments
 (0)