Skip to content

Commit 6e98e78

Browse files
committed
Auto merge of #139336 - matthiaskrgr:rollup-zsi8pgf, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #138017 (Tighten up assignment operator representations.) - #138462 (Dedup `&mut *` reborrow suggestion in loops) - #138610 (impl !PartialOrd for HirId) - #138767 (Allow boolean literals in `check-cfg`) - #139068 (io: Avoid marking some bytes as uninit) - #139255 (Remove unused variables generated in merged doctests) - #139270 (Add a mailmap entry for myself) - #139303 (Put Noratrieb on vacation) - #139312 (add Marco Ieni to mailmap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c1b7cc + 57adb48 commit 6e98e78

21 files changed

+107
-61
lines changed

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) {
199199
&& !expr.span.from_expansion()
200200
&& !inner.span.from_expansion()
201201
&& let Some(suggestion) = simplify_not(cx, msrv, inner)
202-
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
202+
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).level != Level::Allow
203203
{
204204
use clippy_utils::sugg::{Sugg, has_enclosing_paren};
205205
let maybe_par = if let Some(sug) = Sugg::hir_opt(cx, inner) {
@@ -605,7 +605,7 @@ impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> {
605605
}
606606
}
607607
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
608-
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
608+
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).level != Level::Allow {
609609
suggestions.sort();
610610
span_lint_hir_and_then(
611611
self.cx,

clippy_lints/src/disallowed_script_idents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl EarlyLintPass for DisallowedScriptIdents {
6969
// Implementation is heavily inspired by the implementation of [`non_ascii_idents`] lint:
7070
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/non_ascii_idents.rs
7171

72-
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).0 != Level::Allow;
72+
let check_disallowed_script_idents = cx.builder.lint_level(DISALLOWED_SCRIPT_IDENTS).level != Level::Allow;
7373
if !check_disallowed_script_idents {
7474
return;
7575
}

clippy_lints/src/duplicate_mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind};
33
use rustc_errors::MultiSpan;
44
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
5+
use rustc_middle::lint::LevelAndSource;
56
use rustc_session::impl_lint_pass;
67
use rustc_span::{FileName, Span};
78
use std::collections::BTreeMap;
@@ -45,11 +46,10 @@ declare_clippy_lint! {
4546
"file loaded as module multiple times"
4647
}
4748

48-
#[derive(PartialOrd, Ord, PartialEq, Eq)]
4949
struct Modules {
5050
local_path: PathBuf,
5151
spans: Vec<Span>,
52-
lint_levels: Vec<Level>,
52+
lint_levels: Vec<LevelAndSource>,
5353
}
5454

5555
#[derive(Default)]
@@ -95,11 +95,11 @@ impl EarlyLintPass for DuplicateMod {
9595
.iter()
9696
.zip(lint_levels)
9797
.filter_map(|(span, lvl)| {
98-
if let Some(id) = lvl.get_expectation_id() {
98+
if let Some(id) = lvl.lint_id {
9999
cx.fulfill_expectation(id);
100100
}
101101

102-
(!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span)
102+
(!matches!(lvl.level, Level::Allow | Level::Expect)).then_some(*span)
103103
})
104104
.collect();
105105

clippy_lints/src/format_push_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::higher;
33
use clippy_utils::ty::is_type_lang_item;
4-
use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem, MatchSource};
4+
use rustc_hir::{AssignOpKind, Expr, ExprKind, LangItem, MatchSource};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
77
use rustc_span::sym;
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatPushString {
7777
return;
7878
}
7979
},
80-
ExprKind::AssignOp(op, left, arg) if op.node == BinOpKind::Add && is_string(cx, left) => arg,
80+
ExprKind::AssignOp(op, left, arg) if op.node == AssignOpKind::AddAssign && is_string(cx, left) => arg,
8181
_ => return,
8282
};
8383
if is_format(cx, arg) {

clippy_lints/src/implicit_saturating_add.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::snippet_with_context;
55
use rustc_ast::ast::{LitIntType, LitKind};
66
use rustc_data_structures::packed::Pu128;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
8+
use rustc_hir::{AssignOpKind, BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::{IntTy, Ty, UintTy};
1111
use rustc_session::declare_lint_pass;
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
6868
&& ex.span.ctxt() == ctxt
6969
&& expr1.span.ctxt() == ctxt
7070
&& clippy_utils::SpanlessEq::new(cx).eq_expr(l, target)
71-
&& BinOpKind::Add == op1.node
71+
&& AssignOpKind::AddAssign == op1.node
7272
&& let ExprKind::Lit(lit) = value.kind
7373
&& let LitKind::Int(Pu128(1), LitIntType::Unsuffixed) = lit.node
7474
&& block.expr.is_none()

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
use rustc_ast::ast::LitKind;
99
use rustc_data_structures::packed::Pu128;
1010
use rustc_errors::Applicability;
11-
use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath};
11+
use rustc_hir::{AssignOpKind, BinOp, BinOpKind, Expr, ExprKind, QPath};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_session::impl_lint_pass;
1414
use rustc_span::Span;
@@ -366,7 +366,7 @@ fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a Exp
366366
match peel_blocks_with_stmt(expr).kind {
367367
ExprKind::AssignOp(ref op1, target, value) => {
368368
// Check if literal being subtracted is one
369-
(BinOpKind::Sub == op1.node && is_integer_literal(value, 1)).then_some(target)
369+
(AssignOpKind::SubAssign == op1.node && is_integer_literal(value, 1)).then_some(target)
370370
},
371371
ExprKind::Assign(target, value, _) => {
372372
if let ExprKind::Binary(ref op1, left1, right1) = value.kind

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ mod zombie_processes;
408408

409409
use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation};
410410
use clippy_utils::macros::FormatArgsStorage;
411-
use utils::attr_collector::{AttrCollector, AttrStorage};
412411
use rustc_data_structures::fx::FxHashSet;
413412
use rustc_lint::{Lint, LintId};
413+
use utils::attr_collector::{AttrCollector, AttrStorage};
414414

415415
/// Register all pre expansion lints
416416
///

clippy_lints/src/loops/utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc
33
use rustc_ast::ast::{LitIntType, LitKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::intravisit::{Visitor, walk_expr, walk_local};
6-
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
6+
use rustc_hir::{
7+
AssignOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind
8+
};
79
use rustc_lint::LateContext;
810
use rustc_middle::hir::nested_filter;
911
use rustc_middle::ty::{self, Ty};
@@ -58,7 +60,7 @@ impl<'tcx> Visitor<'tcx> for IncrementVisitor<'_, 'tcx> {
5860
match parent.kind {
5961
ExprKind::AssignOp(op, lhs, rhs) => {
6062
if lhs.hir_id == expr.hir_id {
61-
*state = if op.node == BinOpKind::Add
63+
*state = if op.node == AssignOpKind::AddAssign
6264
&& is_integer_const(self.cx, rhs, 1)
6365
&& *state == IncrementVisitorVarState::Initial
6466
&& self.depth == 0

clippy_lints/src/macro_use.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ impl LateLintPass<'_> for MacroUseImports {
153153
[] | [_] => return,
154154
[root, item] => {
155155
if !check_dup.contains(&(*item).to_string()) {
156-
used.entry(((*root).to_string(), span, hir_id))
157-
.or_insert_with(Vec::new)
158-
.push((*item).to_string());
156+
used.entry((
157+
(*root).to_string(),
158+
span,
159+
hir_id.local_id,
160+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
161+
))
162+
.or_insert_with(|| (vec![], hir_id))
163+
.0
164+
.push((*item).to_string());
159165
check_dup.push((*item).to_string());
160166
}
161167
},
@@ -171,15 +177,27 @@ impl LateLintPass<'_> for MacroUseImports {
171177
}
172178
})
173179
.collect::<Vec<_>>();
174-
used.entry(((*root).to_string(), span, hir_id))
175-
.or_insert_with(Vec::new)
176-
.push(filtered.join("::"));
180+
used.entry((
181+
(*root).to_string(),
182+
span,
183+
hir_id.local_id,
184+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
185+
))
186+
.or_insert_with(|| (vec![], hir_id))
187+
.0
188+
.push(filtered.join("::"));
177189
check_dup.extend(filtered);
178190
} else {
179191
let rest = rest.to_vec();
180-
used.entry(((*root).to_string(), span, hir_id))
181-
.or_insert_with(Vec::new)
182-
.push(rest.join("::"));
192+
used.entry((
193+
(*root).to_string(),
194+
span,
195+
hir_id.local_id,
196+
cx.tcx.def_path_hash(hir_id.owner.def_id.into()),
197+
))
198+
.or_insert_with(|| (vec![], hir_id))
199+
.0
200+
.push(rest.join("::"));
183201
check_dup.extend(rest.iter().map(ToString::to_string));
184202
}
185203
},
@@ -190,7 +208,7 @@ impl LateLintPass<'_> for MacroUseImports {
190208
// If mac_refs is not empty we have encountered an import we could not handle
191209
// such as `std::prelude::v1::foo` or some other macro that expands to an import.
192210
if self.mac_refs.is_empty() {
193-
for ((root, span, hir_id), path) in used {
211+
for ((root, span, ..), (path, hir_id)) in used {
194212
let import = if let [single] = &path[..] {
195213
format!("{root}::{single}")
196214
} else {

clippy_lints/src/missing_asserts_for_indexing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::{LitKind, RangeLimits};
1010
use rustc_data_structures::packed::Pu128;
1111
use rustc_data_structures::unhash::UnindexMap;
1212
use rustc_errors::{Applicability, Diag};
13-
use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp};
13+
use rustc_hir::{BinOpKind, Block, Body, Expr, ExprKind, UnOp};
1414
use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_session::declare_lint_pass;
1616
use rustc_span::source_map::Spanned;
@@ -97,7 +97,7 @@ enum LengthComparison {
9797
///
9898
/// E.g. for `v.len() > 5` this returns `Some((LengthComparison::IntLessThanLength, 5, v.len()))`
9999
fn len_comparison<'hir>(
100-
bin_op: BinOp,
100+
bin_op: BinOpKind,
101101
left: &'hir Expr<'hir>,
102102
right: &'hir Expr<'hir>,
103103
) -> Option<(LengthComparison, usize, &'hir Expr<'hir>)> {
@@ -112,7 +112,7 @@ fn len_comparison<'hir>(
112112

113113
// normalize comparison, `v.len() > 4` becomes `4 < v.len()`
114114
// this simplifies the logic a bit
115-
let (op, left, right) = normalize_comparison(bin_op.node, left, right)?;
115+
let (op, left, right) = normalize_comparison(bin_op, left, right)?;
116116
match (op, left.kind, right.kind) {
117117
(Rel::Lt, int_lit_pat!(left), _) => Some((LengthComparison::IntLessThanLength, left as usize, right)),
118118
(Rel::Lt, _, int_lit_pat!(right)) => Some((LengthComparison::LengthLessThanInt, right as usize, left)),
@@ -138,7 +138,7 @@ fn assert_len_expr<'hir>(
138138
&& let ExprKind::Unary(UnOp::Not, condition) = &cond.kind
139139
&& let ExprKind::Binary(bin_op, left, right) = &condition.kind
140140

141-
&& let Some((cmp, asserted_len, slice_len)) = len_comparison(*bin_op, left, right)
141+
&& let Some((cmp, asserted_len, slice_len)) = len_comparison(bin_op.node, left, right)
142142
&& let ExprKind::MethodCall(method, recv, [], _) = &slice_len.kind
143143
&& cx.typeck_results().expr_ty_adjusted(recv).peel_refs().is_slice()
144144
&& method.ident.name == sym::len

0 commit comments

Comments
 (0)