Skip to content

Commit 26ac6aa

Browse files
committed
Auto merge of rust-lang#12130 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 87ff58d + 7d8b6e4 commit 26ac6aa

Some content is hidden

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

51 files changed

+163
-252
lines changed

clippy_config/src/msrvs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Msrv {
109109
if let Some(duplicate) = msrv_attrs.last() {
110110
sess.dcx()
111111
.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
112-
.span_note(msrv_attr.span, "first definition found here")
112+
.with_span_note(msrv_attr.span, "first definition found here")
113113
.emit();
114114
}
115115

clippy_lints/src/casts/unnecessary_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub(super) fn check<'tcx>(
145145
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
146146
if let Some(id) = path_to_local(cast_expr)
147147
&& let Some(span) = cx.tcx.hir().opt_span(id)
148-
&& span.ctxt() != cast_expr.span.ctxt()
148+
&& !span.eq_ctxt(cast_expr.span)
149149
{
150150
// Binding context is different than the identifiers context.
151151
// Weird macro wizardry could be involved here.

clippy_lints/src/copies.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_errors::Applicability;
1212
use rustc_hir::def_id::DefIdSet;
1313
use rustc_hir::{intravisit, BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind};
1414
use rustc_lint::{LateContext, LateLintPass};
15-
use rustc_middle::query::Key;
1615
use rustc_session::impl_lint_pass;
1716
use rustc_span::hygiene::walk_chain;
1817
use rustc_span::source_map::SourceMap;
@@ -574,7 +573,7 @@ fn method_caller_is_mutable(cx: &LateContext<'_>, caller_expr: &Expr<'_>, ignore
574573
let caller_ty = cx.typeck_results().expr_ty(caller_expr);
575574
// Check if given type has inner mutability and was not set to ignored by the configuration
576575
let is_inner_mut_ty = is_interior_mut_ty(cx, caller_ty)
577-
&& !matches!(caller_ty.ty_adt_id(), Some(adt_id) if ignored_ty_ids.contains(&adt_id));
576+
&& !matches!(caller_ty.ty_adt_def(), Some(adt) if ignored_ty_ids.contains(&adt.did()));
578577

579578
is_inner_mut_ty
580579
|| caller_ty.is_mutable_ptr()

clippy_lints/src/doc/missing_headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn check(
7272
&& let body = cx.tcx.hir().body(body_id)
7373
&& let ret_ty = typeck.expr_ty(body.value)
7474
&& implements_trait(cx, ret_ty, future, &[])
75-
&& let ty::Coroutine(_, subs, _) = ret_ty.kind()
75+
&& let ty::Coroutine(_, subs) = ret_ty.kind()
7676
&& is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result)
7777
{
7878
span_lint(

clippy_lints/src/doc/needless_doctest_main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST};
55
use clippy_utils::diagnostics::span_lint;
66
use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
77
use rustc_data_structures::sync::Lrc;
8-
use rustc_errors::emitter::EmitterWriter;
8+
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::DiagCtxt;
1010
use rustc_lint::LateContext;
1111
use rustc_parse::maybe_new_parser_from_source_str;
@@ -44,7 +44,7 @@ pub fn check(
4444

4545
let fallback_bundle =
4646
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
47-
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle);
47+
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);
4848
let dcx = DiagCtxt::with_emitter(Box::new(emitter)).disable_warnings();
4949
#[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx
5050
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));

clippy_lints/src/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::fmt::{self, Write};
88
use rustc_errors::Applicability;
99
use rustc_hir::hir_id::HirIdSet;
1010
use rustc_hir::intravisit::{walk_expr, Visitor};
11-
use rustc_hir::{Block, Expr, ExprKind, Guard, HirId, Let, Pat, Stmt, StmtKind, UnOp};
11+
use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_session::declare_lint_pass;
1414
use rustc_span::{Span, SyntaxContext, DUMMY_SP};
@@ -465,7 +465,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
465465
let mut is_map_used = self.is_map_used;
466466
for arm in arms {
467467
self.visit_pat(arm.pat);
468-
if let Some(Guard::If(guard) | Guard::IfLet(&Let { init: guard, .. })) = arm.guard {
468+
if let Some(guard) = arm.guard {
469469
self.visit_non_tail_expr(guard);
470470
}
471471
is_map_used |= self.visit_cond_arm(arm.body);

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
118118
vis.visit_ty(impl_.self_ty);
119119

120120
for target in &vis.found {
121-
if item.span.ctxt() != target.span().ctxt() {
121+
if !item.span.eq_ctxt(target.span()) {
122122
return;
123123
}
124124

clippy_lints/src/implicit_return.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
225225
_: LocalDefId,
226226
) {
227227
if (!matches!(kind, FnKind::Closure) && matches!(decl.output, FnRetTy::DefaultReturn(_)))
228-
|| span.ctxt() != body.value.span.ctxt()
228+
|| !span.eq_ctxt(body.value.span)
229229
|| in_external_macro(cx.sess(), span)
230230
{
231231
return;

clippy_lints/src/manual_clamp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use clippy_utils::{
1111
use itertools::Itertools;
1212
use rustc_errors::{Applicability, Diagnostic};
1313
use rustc_hir::def::Res;
14-
use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, Guard, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind};
14+
use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind};
1515
use rustc_lint::{LateContext, LateLintPass};
1616
use rustc_middle::ty::Ty;
1717
use rustc_session::impl_lint_pass;
@@ -394,7 +394,7 @@ fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opt
394394
// Find possible min/max branches
395395
let minmax_values = |a: &'tcx Arm<'tcx>| {
396396
if let PatKind::Binding(_, var_hir_id, _, None) = &a.pat.kind
397-
&& let Some(Guard::If(e)) = a.guard
397+
&& let Some(e) = a.guard
398398
{
399399
Some((e, var_hir_id, a.body))
400400
} else {

clippy_lints/src/matches/collapsible_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::{
77
};
88
use rustc_errors::MultiSpan;
99
use rustc_hir::LangItem::OptionNone;
10-
use rustc_hir::{Arm, Expr, Guard, HirId, Let, Pat, PatKind};
10+
use rustc_hir::{Arm, Expr, HirId, Pat, PatKind};
1111
use rustc_lint::LateContext;
1212
use rustc_span::Span;
1313

@@ -16,7 +16,7 @@ use super::COLLAPSIBLE_MATCH;
1616
pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
1717
if let Some(els_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) {
1818
for arm in arms {
19-
check_arm(cx, true, arm.pat, arm.body, arm.guard.as_ref(), Some(els_arm.body));
19+
check_arm(cx, true, arm.pat, arm.body, arm.guard, Some(els_arm.body));
2020
}
2121
}
2222
}
@@ -35,7 +35,7 @@ fn check_arm<'tcx>(
3535
outer_is_match: bool,
3636
outer_pat: &'tcx Pat<'tcx>,
3737
outer_then_body: &'tcx Expr<'tcx>,
38-
outer_guard: Option<&'tcx Guard<'tcx>>,
38+
outer_guard: Option<&'tcx Expr<'tcx>>,
3939
outer_else_body: Option<&'tcx Expr<'tcx>>,
4040
) {
4141
let inner_expr = peel_blocks_with_stmt(outer_then_body);
@@ -71,7 +71,7 @@ fn check_arm<'tcx>(
7171
// the binding must not be used in the if guard
7272
&& outer_guard.map_or(
7373
true,
74-
|(Guard::If(e) | Guard::IfLet(Let { init: e, .. }))| !is_local_used(cx, *e, binding_id)
74+
|e| !is_local_used(cx, e, binding_id)
7575
)
7676
// ...or anywhere in the inner expression
7777
&& match inner {

clippy_lints/src/matches/match_like_matches.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability;
44
use clippy_utils::{is_lint_allowed, is_wild, span_contains_comment};
55
use rustc_ast::{Attribute, LitKind};
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Guard, Pat, PatKind, QPath};
7+
use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Pat, PatKind, QPath};
88
use rustc_lint::{LateContext, LintContext};
99
use rustc_middle::ty;
1010
use rustc_span::source_map::Spanned;
@@ -41,14 +41,8 @@ pub(super) fn check_match<'tcx>(
4141
find_matches_sugg(
4242
cx,
4343
scrutinee,
44-
arms.iter().map(|arm| {
45-
(
46-
cx.tcx.hir().attrs(arm.hir_id),
47-
Some(arm.pat),
48-
arm.body,
49-
arm.guard.as_ref(),
50-
)
51-
}),
44+
arms.iter()
45+
.map(|arm| (cx.tcx.hir().attrs(arm.hir_id), Some(arm.pat), arm.body, arm.guard)),
5246
e,
5347
false,
5448
)
@@ -67,14 +61,7 @@ where
6761
I: Clone
6862
+ DoubleEndedIterator
6963
+ ExactSizeIterator
70-
+ Iterator<
71-
Item = (
72-
&'a [Attribute],
73-
Option<&'a Pat<'b>>,
74-
&'a Expr<'b>,
75-
Option<&'a Guard<'b>>,
76-
),
77-
>,
64+
+ Iterator<Item = (&'a [Attribute], Option<&'a Pat<'b>>, &'a Expr<'b>, Option<&'a Expr<'b>>)>,
7865
{
7966
if !span_contains_comment(cx.sess().source_map(), expr.span)
8067
&& iter.len() >= 2
@@ -115,7 +102,7 @@ where
115102
})
116103
.join(" | ")
117104
};
118-
let pat_and_guard = if let Some(Guard::If(g)) = first_guard {
105+
let pat_and_guard = if let Some(g) = first_guard {
119106
format!(
120107
"{pat} if {}",
121108
snippet_with_applicability(cx, g.span, "..", &mut applicability)

clippy_lints/src/matches/needless_match.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
};
99
use rustc_errors::Applicability;
1010
use rustc_hir::LangItem::OptionNone;
11-
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, Guard, ItemKind, Node, Pat, PatKind, Path, QPath};
11+
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatKind, Path, QPath};
1212
use rustc_lint::LateContext;
1313
use rustc_span::sym;
1414

@@ -66,18 +66,9 @@ fn check_all_arms(cx: &LateContext<'_>, match_expr: &Expr<'_>, arms: &[Arm<'_>])
6666
let arm_expr = peel_blocks_with_stmt(arm.body);
6767

6868
if let Some(guard_expr) = &arm.guard {
69-
match guard_expr {
70-
// gives up if `pat if expr` can have side effects
71-
Guard::If(if_cond) => {
72-
if if_cond.can_have_side_effects() {
73-
return false;
74-
}
75-
},
76-
// gives up `pat if let ...` arm
77-
Guard::IfLet(_) => {
78-
return false;
79-
},
80-
};
69+
if guard_expr.can_have_side_effects() {
70+
return false;
71+
}
8172
}
8273

8374
if let PatKind::Wild = arm.pat.kind {

clippy_lints/src/matches/redundant_guards.rs

+21-29
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::visitors::{for_each_expr, is_local_used};
55
use rustc_ast::{BorrowKind, LitKind};
66
use rustc_errors::Applicability;
77
use rustc_hir::def::{DefKind, Res};
8-
use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, Guard, MatchSource, Node, Pat, PatKind};
8+
use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, MatchSource, Node, Pat, PatKind};
99
use rustc_lint::LateContext;
1010
use rustc_span::symbol::Ident;
1111
use rustc_span::{Span, Symbol};
@@ -21,20 +21,19 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
2121
};
2222

2323
// `Some(x) if matches!(x, y)`
24-
if let Guard::If(if_expr) = guard
25-
&& let ExprKind::Match(
26-
scrutinee,
27-
[
28-
arm,
29-
Arm {
30-
pat: Pat {
31-
kind: PatKind::Wild, ..
32-
},
33-
..
24+
if let ExprKind::Match(
25+
scrutinee,
26+
[
27+
arm,
28+
Arm {
29+
pat: Pat {
30+
kind: PatKind::Wild, ..
3431
},
35-
],
36-
MatchSource::Normal,
37-
) = if_expr.kind
32+
..
33+
},
34+
],
35+
MatchSource::Normal,
36+
) = guard.kind
3837
&& let Some(binding) = get_pat_binding(cx, scrutinee, outer_arm)
3938
{
4039
let pat_span = match (arm.pat.kind, binding.byref_ident) {
@@ -45,14 +44,14 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
4544
emit_redundant_guards(
4645
cx,
4746
outer_arm,
48-
if_expr.span,
47+
guard.span,
4948
snippet(cx, pat_span, "<binding>"),
5049
&binding,
5150
arm.guard,
5251
);
5352
}
5453
// `Some(x) if let Some(2) = x`
55-
else if let Guard::IfLet(let_expr) = guard
54+
else if let ExprKind::Let(let_expr) = guard.kind
5655
&& let Some(binding) = get_pat_binding(cx, let_expr.init, outer_arm)
5756
{
5857
let pat_span = match (let_expr.pat.kind, binding.byref_ident) {
@@ -71,8 +70,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
7170
}
7271
// `Some(x) if x == Some(2)`
7372
// `Some(x) if Some(2) == x`
74-
else if let Guard::If(if_expr) = guard
75-
&& let ExprKind::Binary(bin_op, local, pat) = if_expr.kind
73+
else if let ExprKind::Binary(bin_op, local, pat) = guard.kind
7674
&& matches!(bin_op.node, BinOpKind::Eq)
7775
// Ensure they have the same type. If they don't, we'd need deref coercion which isn't
7876
// possible (currently) in a pattern. In some cases, you can use something like
@@ -96,16 +94,15 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>]) {
9694
emit_redundant_guards(
9795
cx,
9896
outer_arm,
99-
if_expr.span,
97+
guard.span,
10098
snippet(cx, pat_span, "<binding>"),
10199
&binding,
102100
None,
103101
);
104-
} else if let Guard::If(if_expr) = guard
105-
&& let ExprKind::MethodCall(path, recv, args, ..) = if_expr.kind
102+
} else if let ExprKind::MethodCall(path, recv, args, ..) = guard.kind
106103
&& let Some(binding) = get_pat_binding(cx, recv, outer_arm)
107104
{
108-
check_method_calls(cx, outer_arm, path.ident.name, recv, args, if_expr, &binding);
105+
check_method_calls(cx, outer_arm, path.ident.name, recv, args, guard, &binding);
109106
}
110107
}
111108
}
@@ -216,7 +213,7 @@ fn emit_redundant_guards<'tcx>(
216213
guard_span: Span,
217214
binding_replacement: Cow<'static, str>,
218215
pat_binding: &PatBindingInfo,
219-
inner_guard: Option<Guard<'_>>,
216+
inner_guard: Option<&Expr<'_>>,
220217
) {
221218
span_lint_and_then(
222219
cx,
@@ -242,12 +239,7 @@ fn emit_redundant_guards<'tcx>(
242239
(
243240
guard_span.source_callsite().with_lo(outer_arm.pat.span.hi()),
244241
inner_guard.map_or_else(String::new, |guard| {
245-
let (prefix, span) = match guard {
246-
Guard::If(e) => ("if", e.span),
247-
Guard::IfLet(l) => ("if let", l.span),
248-
};
249-
250-
format!(" {prefix} {}", snippet(cx, span, "<guard>"))
242+
format!(" if {}", snippet(cx, guard.span, "<guard>"))
251243
}),
252244
),
253245
],

0 commit comments

Comments
 (0)