Skip to content

Commit 0faf8c7

Browse files
committed
Rename PatKind::Lit to Expr
1 parent 28d2363 commit 0faf8c7

21 files changed

+34
-34
lines changed

Diff for: clippy_lints/src/default_numeric_fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'tcx> Visitor<'tcx> for NumericFallbackVisitor<'_, 'tcx> {
224224

225225
fn visit_pat(&mut self, pat: &'tcx Pat<'_>) {
226226
match pat.kind {
227-
PatKind::Lit(&PatExpr {
227+
PatKind::Expr(&PatExpr {
228228
hir_id,
229229
kind: PatExprKind::Lit { lit, .. },
230230
..

Diff for: clippy_lints/src/equatable_if_let.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5656
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
5757
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
5858
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
59-
PatKind::Path(_) | PatKind::Lit(_) => true,
59+
PatKind::Path(_) | PatKind::Expr(_) => true,
6060
}
6161
}
6262

Diff for: clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
163163
if let ExprKind::Let(lt) = expr.kind
164164
&& match lt.pat.kind {
165165
PatKind::Slice([], None, []) => true,
166-
PatKind::Lit(lit) => match lit.kind {
166+
PatKind::Expr(lit) => match lit.kind {
167167
PatExprKind::Lit { lit, .. } => match lit.node {
168168
LitKind::Str(lit, _) => lit.as_str().is_empty(),
169169
_ => false,

Diff for: clippy_lints/src/manual_range_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl LateLintPass<'_> for ManualRangePatterns {
8989
let mut ranges_found = Vec::new();
9090

9191
for pat in pats {
92-
if let PatKind::Lit(lit) = pat.kind
92+
if let PatKind::Expr(lit) = pat.kind
9393
&& let Some(num) = Num::new(lit)
9494
{
9595
numbers_found.insert(num.val);

Diff for: clippy_lints/src/matches/match_bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>]
2121
move |diag| {
2222
if arms.len() == 2 {
2323
// no guards
24-
let exprs = if let PatKind::Lit(arm_bool) = arms[0].pat.kind {
24+
let exprs = if let PatKind::Expr(arm_bool) = arms[0].pat.kind {
2525
if let PatExprKind::Lit { lit, .. } = arm_bool.kind {
2626
match lit.node {
2727
LitKind::Bool(true) => Some((arms[0].body, arms[1].body)),

Diff for: clippy_lints/src/matches/match_same_arms.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_arena::DroplessArena;
77
use rustc_ast::ast::LitKind;
88
use rustc_errors::Applicability;
99
use rustc_hir::def_id::DefId;
10-
use rustc_hir::{Arm, Expr, PatExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd};
10+
use rustc_hir::{Arm, Expr, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatExprKind, PatKind, RangeEnd};
1111
use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
1212
use rustc_lint::{LateContext, LintContext};
1313
use rustc_middle::ty;
@@ -311,9 +311,9 @@ impl<'a> NormalizedPat<'a> {
311311
);
312312
Self::Tuple(None, pats)
313313
},
314-
PatKind::Lit(e) => match &e.kind {
314+
PatKind::Expr(e) => match &e.kind {
315315
// TODO: Handle negative integers. They're currently treated as a wild match.
316-
PatExprKind::Lit{ lit, negated: false } => match lit.node {
316+
PatExprKind::Lit { lit, negated: false } => match lit.node {
317317
LitKind::Str(sym, _) => Self::LitStr(sym),
318318
LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
319319
LitKind::Byte(val) => Self::LitInt(val.into()),

Diff for: clippy_lints/src/matches/match_str_case_mismatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(
8585
};
8686

8787
for arm in arms {
88-
if let PatKind::Lit(PatExpr {
88+
if let PatKind::Expr(PatExpr {
8989
kind: PatExprKind::Lit { lit, negated: false },
9090
..
9191
}) = arm.pat.kind

Diff for: clippy_lints/src/matches/needless_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
189189
});
190190
},
191191
// Example: `5 => 5`
192-
(PatKind::Lit(pat_expr_expr), ExprKind::Lit(expr_spanned)) => {
192+
(PatKind::Expr(pat_expr_expr), ExprKind::Lit(expr_spanned)) => {
193193
if let PatExprKind::Lit {
194194
lit: pat_spanned,
195195
negated: false,

Diff for: clippy_lints/src/matches/overlapping_arms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
5757
});
5858
}
5959

60-
if let PatKind::Lit(value) = pat.kind {
60+
if let PatKind::Expr(value) = pat.kind {
6161
let value = ConstEvalCtxt::new(cx)
6262
.eval_pat_expr(value)?
6363
.int_value(cx.tcx, cx.typeck_results().node_type(pat.hir_id))?;

Diff for: clippy_lints/src/matches/redundant_pattern_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind;
99
use rustc_errors::Applicability;
1010
use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
1111
use rustc_hir::def::{DefKind, Res};
12-
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp, PatExprKind};
12+
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatExprKind, PatKind, QPath, UnOp};
1313
use rustc_lint::LateContext;
1414
use rustc_middle::ty::{self, GenericArgKind, Ty};
1515
use rustc_span::{Span, Symbol, sym};
@@ -74,8 +74,8 @@ fn find_match_true<'tcx>(
7474
span: Span,
7575
message: &'static str,
7676
) {
77-
if let PatKind::Lit(lit) = pat.kind
78-
&& let PatExprKind::Lit{ lit, negated: false } = lit.kind
77+
if let PatKind::Expr(lit) = pat.kind
78+
&& let PatExprKind::Lit { lit, negated: false } = lit.kind
7979
&& let LitKind::Bool(pat_is_true) = lit.node
8080
{
8181
let mut applicability = Applicability::MachineApplicable;

Diff for: clippy_lints/src/matches/single_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_arena::DroplessArena;
99
use rustc_errors::Applicability;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{Visitor, walk_pat};
12-
use rustc_hir::{Arm, Expr, ExprKind, HirId, Node, Pat, PatKind, QPath, StmtKind, PatExpr, PatExprKind};
12+
use rustc_hir::{Arm, Expr, ExprKind, HirId, Node, Pat, PatExpr, PatExprKind, PatKind, QPath, StmtKind};
1313
use rustc_lint::LateContext;
1414
use rustc_middle::ty::{self, AdtDef, TyCtxt, TypeckResults, VariantDef};
1515
use rustc_span::{Span, sym};
@@ -114,7 +114,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
114114
}
115115

116116
let (pat, pat_ref_count) = peel_hir_pat_refs(arm.pat);
117-
let (msg, sugg) = if let PatKind::Path(_) | PatKind::Lit(_) = pat.kind
117+
let (msg, sugg) = if let PatKind::Path(_) | PatKind::Expr(_) = pat.kind
118118
&& let (ty, ty_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(ex))
119119
&& let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait()
120120
&& let Some(pe_trait_id) = cx.tcx.lang_items().eq_trait()
@@ -126,7 +126,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
126126
// scrutinee derives PartialEq and the pattern is a constant.
127127
let pat_ref_count = match pat.kind {
128128
// string literals are already a reference.
129-
PatKind::Lit(PatExpr {
129+
PatKind::Expr(PatExpr {
130130
kind: PatExprKind::Lit { lit, negated: false },
131131
..
132132
}) if lit.node.is_str() || lit.node.is_bytestr() => pat_ref_count + 1,
@@ -384,7 +384,7 @@ impl<'a> PatState<'a> {
384384

385385
PatKind::Wild
386386
| PatKind::Binding(_, _, _, None)
387-
| PatKind::Lit(_)
387+
| PatKind::Expr(_)
388388
| PatKind::Range(..)
389389
| PatKind::Path(_)
390390
| PatKind::Never

Diff for: clippy_lints/src/string_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<
171171
return ControlFlow::Break(());
172172
}
173173
if arm.pat.walk_short(|pat| match pat.kind {
174-
PatKind::Lit(expr) if let PatExprKind::Lit { lit, negated: false } = expr.kind => {
174+
PatKind::Expr(expr) if let PatExprKind::Lit { lit, negated: false } = expr.kind => {
175175
if let LitKind::Char(_) = lit.node {
176176
set_char_spans.push(lit.span);
177177
}

Diff for: clippy_lints/src/unnested_or_patterns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl EarlyLintPass for UnnestedOrPatterns {
9292
}
9393

9494
fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
95-
if let Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind {
95+
if let Ident(.., None) | Expr(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind {
9696
// This is a leaf pattern, so cloning is unprofitable.
9797
return;
9898
}
@@ -228,7 +228,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
228228
// Therefore they are not some form of constructor `C`,
229229
// with which a pattern `C(p_0)` may be formed,
230230
// which we would want to join with other `C(p_j)`s.
231-
Ident(.., None) | Lit(_) | Wild | Err(_) | Never | Path(..) | Range(..) | Rest | MacCall(_)
231+
Ident(.., None) | Expr(_) | Wild | Err(_) | Never | Path(..) | Range(..) | Rest | MacCall(_)
232232
// Skip immutable refs, as grouping them saves few characters,
233233
// and almost always requires adding parens (increasing noisiness).
234234
// In the case of only two patterns, replacement adds net characters.

Diff for: clippy_lints/src/utils/author.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
738738
kind!("Guard({pat}, {cond})");
739739
self.pat(pat);
740740
self.expr(cond);
741-
}
742-
PatKind::Lit(lit_expr) => {
741+
},
742+
PatKind::Expr(lit_expr) => {
743743
bind!(self, lit_expr);
744-
kind!("Lit({lit_expr})");
744+
kind!("Expr({lit_expr})");
745745
self.pat_expr(lit_expr);
746746
},
747747
PatKind::Range(start, end, end_kind) => {

Diff for: clippy_utils/src/ast_utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
3636
(Paren(l), _) => eq_pat(l, r),
3737
(_, Paren(r)) => eq_pat(l, r),
3838
(Wild, Wild) | (Rest, Rest) => true,
39-
(Lit(l), Lit(r)) => eq_expr(l, r),
39+
(Expr(l), Expr(r)) => eq_expr(l, r),
4040
(Ident(b1, i1, s1), Ident(b2, i2, s2)) => {
4141
b1 == b2 && eq_id(*i1, *i2) && both(s1.as_deref(), s2.as_deref(), eq_pat)
4242
},

Diff for: clippy_utils/src/hir_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl HirEqInterExpr<'_, '_, '_> {
525525
eq
526526
},
527527
(PatKind::Path(l), PatKind::Path(r)) => self.eq_qpath(l, r),
528-
(&PatKind::Lit(l), &PatKind::Lit(r)) => self.eq_pat_expr(l, r),
528+
(&PatKind::Expr(l), &PatKind::Expr(r)) => self.eq_pat_expr(l, r),
529529
(&PatKind::Tuple(l, ls), &PatKind::Tuple(r, rs)) => ls == rs && over(l, r, |l, r| self.eq_pat(l, r)),
530530
(&PatKind::Range(ref ls, ref le, li), &PatKind::Range(ref rs, ref re, ri)) => {
531531
both(ls.as_ref(), rs.as_ref(), |a, b| self.eq_pat_expr(a, b))
@@ -1114,7 +1114,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11141114
}
11151115
},
11161116
PatKind::Box(pat) | PatKind::Deref(pat) => self.hash_pat(pat),
1117-
PatKind::Lit(expr) => self.hash_pat_expr(expr),
1117+
PatKind::Expr(expr) => self.hash_pat_expr(expr),
11181118
PatKind::Or(pats) => {
11191119
for pat in pats {
11201120
self.hash_pat(pat);

Diff for: clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
17771777
},
17781778
}
17791779
},
1780-
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
1780+
PatKind::Expr(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
17811781
}
17821782
}
17831783

Diff for: tests/ui/author/if.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if let StmtKind::Let(local) = stmt.kind
3030
}
3131
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
3232
&& let ExprKind::Let(let_expr) = cond.kind
33-
&& let PatKind::Lit(lit_expr) = let_expr.pat.kind
33+
&& let PatKind::Expr(lit_expr) = let_expr.pat.kind
3434
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
3535
&& let LitKind::Bool(true) = lit.node
3636
&& let ExprKind::Path(ref qpath) = let_expr.init.kind

Diff for: tests/ui/author/loop.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if let Some(higher::While { condition: condition, body: body }) = higher::While:
7676
// report your lint here
7777
}
7878
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
79-
&& let PatKind::Lit(lit_expr) = let_pat.kind
79+
&& let PatKind::Expr(lit_expr) = let_pat.kind
8080
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
8181
&& let LitKind::Bool(true) = lit.node
8282
&& let ExprKind::Path(ref qpath) = let_expr.kind

Diff for: tests/ui/author/matches.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ if let StmtKind::Let(local) = stmt.kind
44
&& let ExprKind::Lit(ref lit) = scrutinee.kind
55
&& let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
66
&& arms.len() == 3
7-
&& let PatKind::Lit(lit_expr) = arms[0].pat.kind
7+
&& let PatKind::Expr(lit_expr) = arms[0].pat.kind
88
&& let PatExprKind::Lit{ref lit1, negated } = lit_expr.kind
99
&& let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
1010
&& arms[0].guard.is_none()
1111
&& let ExprKind::Lit(ref lit2) = arms[0].body.kind
1212
&& let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
13-
&& let PatKind::Lit(lit_expr1) = arms[1].pat.kind
13+
&& let PatKind::Expr(lit_expr1) = arms[1].pat.kind
1414
&& let PatExprKind::Lit{ref lit3, negated1 } = lit_expr1.kind
1515
&& let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
1616
&& arms[1].guard.is_none()

Diff for: tests/ui/author/struct.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
2323
&& match_qpath(qpath, &["Test"])
2424
&& fields.len() == 1
2525
&& fields[0].ident.as_str() == "field"
26-
&& let PatKind::Lit(lit_expr) = fields[0].pat.kind
26+
&& let PatKind::Expr(lit_expr) = fields[0].pat.kind
2727
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
2828
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
2929
&& arm.guard.is_none()
@@ -36,7 +36,7 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
3636
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
3737
&& match_qpath(qpath, &["TestTuple"])
3838
&& fields.len() == 1
39-
&& let PatKind::Lit(lit_expr) = fields[0].kind
39+
&& let PatKind::Expr(lit_expr) = fields[0].kind
4040
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
4141
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
4242
&& arm.guard.is_none()

0 commit comments

Comments
 (0)