1
Fork 0

Rename PatKind::Lit to Expr

This commit is contained in:
Oli Scherer 2025-01-07 08:56:23 +00:00
parent c9365dd09f
commit 4a8773a3af
45 changed files with 79 additions and 79 deletions

View file

@ -623,7 +623,7 @@ impl Pat {
PatKind::Wild PatKind::Wild
| PatKind::Rest | PatKind::Rest
| PatKind::Never | PatKind::Never
| PatKind::Lit(_) | PatKind::Expr(_)
| PatKind::Range(..) | PatKind::Range(..)
| PatKind::Ident(..) | PatKind::Ident(..)
| PatKind::Path(..) | PatKind::Path(..)
@ -801,8 +801,8 @@ pub enum PatKind {
/// A reference pattern (e.g., `&mut (a, b)`). /// A reference pattern (e.g., `&mut (a, b)`).
Ref(P<Pat>, Mutability), Ref(P<Pat>, Mutability),
/// A literal. /// A literal, const block or path.
Lit(P<Expr>), Expr(P<Expr>),
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`). /// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>), Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),

View file

@ -1512,7 +1512,7 @@ pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
vis.visit_ident(ident); vis.visit_ident(ident);
visit_opt(sub, |sub| vis.visit_pat(sub)); visit_opt(sub, |sub| vis.visit_pat(sub));
} }
PatKind::Lit(e) => vis.visit_expr(e), PatKind::Expr(e) => vis.visit_expr(e),
PatKind::TupleStruct(qself, path, elems) => { PatKind::TupleStruct(qself, path, elems) => {
vis.visit_qself(qself); vis.visit_qself(qself);
vis.visit_path(path); vis.visit_path(path);

View file

@ -680,7 +680,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
try_visit!(visitor.visit_ident(ident)); try_visit!(visitor.visit_ident(ident));
visit_opt!(visitor, visit_pat, optional_subpattern); visit_opt!(visitor, visit_pat, optional_subpattern);
} }
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)), PatKind::Expr(expression) => try_visit!(visitor.visit_expr(expression)),
PatKind::Range(lower_bound, upper_bound, _end) => { PatKind::Range(lower_bound, upper_bound, _end) => {
visit_opt!(visitor, visit_expr, lower_bound); visit_opt!(visitor, visit_expr, lower_bound);
visit_opt!(visitor, visit_expr, upper_bound); visit_opt!(visitor, visit_expr, upper_bound);

View file

@ -38,8 +38,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
lower_sub, lower_sub,
); );
} }
PatKind::Lit(e) => { PatKind::Expr(e) => {
break hir::PatKind::Lit(self.lower_expr_within_pat(e, false)); break hir::PatKind::Expr(self.lower_expr_within_pat(e, false));
} }
PatKind::TupleStruct(qself, path, pats) => { PatKind::TupleStruct(qself, path, pats) => {
let qpath = self.lower_qpath( let qpath = self.lower_qpath(

View file

@ -1701,7 +1701,7 @@ impl<'a> State<'a> {
self.print_pat(inner); self.print_pat(inner);
} }
} }
PatKind::Lit(e) => self.print_expr(e, FixupContext::default()), PatKind::Expr(e) => self.print_expr(e, FixupContext::default()),
PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => { PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
if let Some(e) = begin { if let Some(e) = begin {
self.print_expr(e, FixupContext::default()); self.print_expr(e, FixupContext::default());

View file

@ -522,7 +522,7 @@ impl MacResult for MacEager {
return Some(P(ast::Pat { return Some(P(ast::Pat {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: e.span, span: e.span,
kind: PatKind::Lit(e), kind: PatKind::Expr(e),
tokens: None, tokens: None,
})); }));
} }

View file

@ -486,7 +486,7 @@ impl<'a> ExtCtxt<'a> {
self.pat(span, PatKind::Wild) self.pat(span, PatKind::Wild)
} }
pub fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> { pub fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
self.pat(span, PatKind::Lit(expr)) self.pat(span, PatKind::Expr(expr))
} }
pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> { pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> {
self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE) self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE)

View file

@ -1386,7 +1386,7 @@ impl<'hir> Pat<'hir> {
use PatKind::*; use PatKind::*;
match self.kind { match self.kind {
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true, Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true,
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it), Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it),
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)), Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
@ -1413,7 +1413,7 @@ impl<'hir> Pat<'hir> {
use PatKind::*; use PatKind::*;
match self.kind { match self.kind {
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {} Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {}
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it), Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)), Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
@ -1583,8 +1583,8 @@ pub enum PatKind<'hir> {
/// A reference pattern (e.g., `&mut (a, b)`). /// A reference pattern (e.g., `&mut (a, b)`).
Ref(&'hir Pat<'hir>, Mutability), Ref(&'hir Pat<'hir>, Mutability),
/// A literal. /// A literal, const block or path.
Lit(&'hir PatExpr<'hir>), Expr(&'hir PatExpr<'hir>),
/// A guard pattern (e.g., `x if guard(x)`). /// A guard pattern (e.g., `x if guard(x)`).
Guard(&'hir Pat<'hir>, &'hir Expr<'hir>), Guard(&'hir Pat<'hir>, &'hir Expr<'hir>),

View file

@ -688,7 +688,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V:
try_visit!(visitor.visit_ident(ident)); try_visit!(visitor.visit_ident(ident));
visit_opt!(visitor, visit_pat, optional_subpattern); visit_opt!(visitor, visit_pat, optional_subpattern);
} }
PatKind::Lit(ref expression) => try_visit!(visitor.visit_pat_expr(expression)), PatKind::Expr(ref expression) => try_visit!(visitor.visit_pat_expr(expression)),
PatKind::Range(ref lower_bound, ref upper_bound, _) => { PatKind::Range(ref lower_bound, ref upper_bound, _) => {
visit_opt!(visitor, visit_pat_expr, lower_bound); visit_opt!(visitor, visit_pat_expr, lower_bound);
visit_opt!(visitor, visit_pat_expr, upper_bound); visit_opt!(visitor, visit_pat_expr, upper_bound);

View file

@ -704,7 +704,7 @@ fn resolve_local<'tcx>(
| PatKind::Wild | PatKind::Wild
| PatKind::Never | PatKind::Never
| PatKind::Path(_) | PatKind::Path(_)
| PatKind::Lit(_) | PatKind::Expr(_)
| PatKind::Range(_, _, _) | PatKind::Range(_, _, _)
| PatKind::Err(_) => false, | PatKind::Err(_) => false,
} }

View file

@ -1980,7 +1980,7 @@ impl<'a> State<'a> {
self.pclose(); self.pclose();
} }
} }
PatKind::Lit(e) => self.print_pat_expr(e), PatKind::Expr(e) => self.print_pat_expr(e),
PatKind::Range(begin, end, end_kind) => { PatKind::Range(begin, end, end_kind) => {
if let Some(expr) = begin { if let Some(expr) = begin {
self.print_pat_expr(expr); self.print_pat_expr(expr);

View file

@ -485,7 +485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| hir::PatKind::Box(_) | hir::PatKind::Box(_)
| hir::PatKind::Ref(_, _) | hir::PatKind::Ref(_, _)
| hir::PatKind::Deref(_) | hir::PatKind::Deref(_)
| hir::PatKind::Lit(_) | hir::PatKind::Expr(_)
| hir::PatKind::Range(_, _, _) | hir::PatKind::Range(_, _, _)
| hir::PatKind::Slice(_, _, _) | hir::PatKind::Slice(_, _, _)
| hir::PatKind::Err(_) => true, | hir::PatKind::Err(_) => true,

View file

@ -595,7 +595,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
let place_ty = place.place.ty(); let place_ty = place.place.ty();
needs_to_be_read |= self.is_multivariant_adt(place_ty, pat.span); needs_to_be_read |= self.is_multivariant_adt(place_ty, pat.span);
} }
PatKind::Lit(_) | PatKind::Range(..) => { PatKind::Expr(_) | PatKind::Range(..) => {
// If the PatKind is a Lit or a Range then we want // If the PatKind is a Lit or a Range then we want
// to borrow discr. // to borrow discr.
needs_to_be_read = true; needs_to_be_read = true;
@ -1803,7 +1803,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
PatKind::Path(_) PatKind::Path(_)
| PatKind::Binding(.., None) | PatKind::Binding(.., None)
| PatKind::Lit(..) | PatKind::Expr(..)
| PatKind::Range(..) | PatKind::Range(..)
| PatKind::Never | PatKind::Never
| PatKind::Wild | PatKind::Wild

View file

@ -271,7 +271,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
PatKind::Wild | PatKind::Err(_) => expected, PatKind::Wild | PatKind::Err(_) => expected,
// We allow any type here; we ensure that the type is uninhabited during match checking. // We allow any type here; we ensure that the type is uninhabited during match checking.
PatKind::Never => expected, PatKind::Never => expected,
PatKind::Lit(lt) => self.check_pat_lit(pat.span, lt, expected, ti), PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti), PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
PatKind::Binding(ba, var_id, ident, sub) => { PatKind::Binding(ba, var_id, ident, sub) => {
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info) self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
@ -399,7 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// As a result, we allow `if let 0 = &&0 {}` but not `if let "foo" = &&"foo" {}`. // As a result, we allow `if let 0 = &&0 {}` but not `if let "foo" = &&"foo" {}`.
// //
// Call `resolve_vars_if_possible` here for inline const blocks. // Call `resolve_vars_if_possible` here for inline const blocks.
PatKind::Lit(lt) => match self.resolve_vars_if_possible(self.check_pat_expr_unadjusted(lt)).kind() { PatKind::Expr(lt) => match self.resolve_vars_if_possible(self.check_pat_expr_unadjusted(lt)).kind() {
ty::Ref(..) => AdjustMode::Pass, ty::Ref(..) => AdjustMode::Pass,
_ => AdjustMode::Peel, _ => AdjustMode::Peel,
}, },
@ -943,7 +943,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| PatKind::Box(..) | PatKind::Box(..)
| PatKind::Deref(_) | PatKind::Deref(_)
| PatKind::Ref(..) | PatKind::Ref(..)
| PatKind::Lit(..) | PatKind::Expr(..)
| PatKind::Range(..) | PatKind::Range(..)
| PatKind::Err(_) => break 'block None, | PatKind::Err(_) => break 'block None,
}, },
@ -1837,7 +1837,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} else if inexistent_fields.len() == 1 { } else if inexistent_fields.len() == 1 {
match pat_field.pat.kind { match pat_field.pat.kind {
PatKind::Lit(_) PatKind::Expr(_)
if !self.may_coerce( if !self.may_coerce(
self.typeck_results.borrow().node_type(pat_field.pat.hir_id), self.typeck_results.borrow().node_type(pat_field.pat.hir_id),
self.field_ty(field.span, field_def, args), self.field_ty(field.span, field_def, args),

View file

@ -1220,7 +1220,7 @@ impl EarlyLintPass for UnusedParens {
// Do not lint on `(..)` as that will result in the other arms being useless. // Do not lint on `(..)` as that will result in the other arms being useless.
Paren(_) Paren(_)
// The other cases do not contain sub-patterns. // The other cases do not contain sub-patterns.
| Wild | Never | Rest | Lit(..) | MacCall(..) | Range(..) | Ident(.., None) | Path(..) | Err(_) => {}, | Wild | Never | Rest | Expr(..) | MacCall(..) | Range(..) | Ident(.., None) | Path(..) | Err(_) => {},
// These are list-like patterns; parens can always be removed. // These are list-like patterns; parens can always be removed.
TupleStruct(_, _, ps) | Tuple(ps) | Slice(ps) | Or(ps) => for p in ps { TupleStruct(_, _, ps) | Tuple(ps) | Slice(ps) | Or(ps) => for p in ps {
self.check_unused_parens_pat(cx, p, false, false, keep_space); self.check_unused_parens_pat(cx, p, false, false, keep_space);

View file

@ -324,7 +324,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
hir::PatKind::Never => PatKind::Never, hir::PatKind::Never => PatKind::Never,
hir::PatKind::Lit(value) => self.lower_lit(value), hir::PatKind::Expr(value) => self.lower_lit(value),
hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => { hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => {
let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref()); let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref());

View file

@ -656,14 +656,14 @@ impl<'a> Parser<'a> {
fn visit_pat(&mut self, p: &'a Pat) -> Self::Result { fn visit_pat(&mut self, p: &'a Pat) -> Self::Result {
match &p.kind { match &p.kind {
// Base expression // Base expression
PatKind::Err(_) | PatKind::Lit(_) => { PatKind::Err(_) | PatKind::Expr(_) => {
self.maybe_add_suggestions_then_emit(p.span, p.span, false) self.maybe_add_suggestions_then_emit(p.span, p.span, false)
} }
// Sub-patterns // Sub-patterns
// FIXME: this doesn't work with recursive subpats (`&mut &mut <err>`) // FIXME: this doesn't work with recursive subpats (`&mut &mut <err>`)
PatKind::Box(subpat) | PatKind::Ref(subpat, _) PatKind::Box(subpat) | PatKind::Ref(subpat, _)
if matches!(subpat.kind, PatKind::Err(_) | PatKind::Lit(_)) => if matches!(subpat.kind, PatKind::Err(_) | PatKind::Expr(_)) =>
{ {
self.maybe_add_suggestions_then_emit(subpat.span, p.span, false) self.maybe_add_suggestions_then_emit(subpat.span, p.span, false)
} }
@ -766,7 +766,7 @@ impl<'a> Parser<'a> {
if let Some(re) = self.parse_range_end() { if let Some(re) = self.parse_range_end() {
self.parse_pat_range_begin_with(const_expr, re)? self.parse_pat_range_begin_with(const_expr, re)?
} else { } else {
PatKind::Lit(const_expr) PatKind::Expr(const_expr)
} }
} else if self.is_builtin() { } else if self.is_builtin() {
self.parse_pat_builtin()? self.parse_pat_builtin()?
@ -833,7 +833,7 @@ impl<'a> Parser<'a> {
.struct_span_err(self_.token.span, msg) .struct_span_err(self_.token.span, msg)
.with_span_label(self_.token.span, format!("expected {expected}")) .with_span_label(self_.token.span, format!("expected {expected}"))
}); });
PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit))) PatKind::Expr(self.mk_expr(lo, ExprKind::Lit(lit)))
} else { } else {
// Try to parse everything else as literal with optional minus // Try to parse everything else as literal with optional minus
match self.parse_literal_maybe_minus() { match self.parse_literal_maybe_minus() {
@ -845,7 +845,7 @@ impl<'a> Parser<'a> {
match self.parse_range_end() { match self.parse_range_end() {
Some(form) => self.parse_pat_range_begin_with(begin, form)?, Some(form) => self.parse_pat_range_begin_with(begin, form)?,
None => PatKind::Lit(begin), None => PatKind::Expr(begin),
} }
} }
Err(err) => return self.fatal_unexpected_non_pat(err, expected), Err(err) => return self.fatal_unexpected_non_pat(err, expected),
@ -989,7 +989,7 @@ impl<'a> Parser<'a> {
match &pat.kind { match &pat.kind {
// recover ranges with parentheses around the `(start)..` // recover ranges with parentheses around the `(start)..`
PatKind::Lit(begin) PatKind::Expr(begin)
if self.may_recover() if self.may_recover()
&& let Some(form) = self.parse_range_end() => && let Some(form) = self.parse_range_end() =>
{ {

View file

@ -304,7 +304,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
Box, Box,
Deref, Deref,
Ref, Ref,
Lit, Expr,
Guard, Guard,
Range, Range,
Slice, Slice,
@ -587,7 +587,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
Box, Box,
Deref, Deref,
Ref, Ref,
Lit, Expr,
Range, Range,
Slice, Slice,
Rest, Rest,

View file

@ -314,9 +314,9 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
PatKind::Box(p) => return name_from_pat(p), PatKind::Box(p) => return name_from_pat(p),
PatKind::Deref(p) => format!("deref!({})", name_from_pat(p)), PatKind::Deref(p) => format!("deref!({})", name_from_pat(p)),
PatKind::Ref(p, _) => return name_from_pat(p), PatKind::Ref(p, _) => return name_from_pat(p),
PatKind::Lit(..) => { PatKind::Expr(..) => {
warn!( warn!(
"tried to get argument name from PatKind::Lit, which is silly in function arguments" "tried to get argument name from PatKind::Expr, which is silly in function arguments"
); );
return Symbol::intern("()"); return Symbol::intern("()");
} }

View file

@ -224,7 +224,7 @@ impl<'tcx> Visitor<'tcx> for NumericFallbackVisitor<'_, 'tcx> {
fn visit_pat(&mut self, pat: &'tcx Pat<'_>) { fn visit_pat(&mut self, pat: &'tcx Pat<'_>) {
match pat.kind { match pat.kind {
PatKind::Lit(&PatExpr { PatKind::Expr(&PatExpr {
hir_id, hir_id,
kind: PatExprKind::Lit { lit, .. }, kind: PatExprKind::Lit { lit, .. },
.. ..

View file

@ -56,7 +56,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a), PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x), PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
PatKind::Path(_) | PatKind::Lit(_) => true, PatKind::Path(_) | PatKind::Expr(_) => true,
} }
} }

View file

@ -163,7 +163,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
if let ExprKind::Let(lt) = expr.kind if let ExprKind::Let(lt) = expr.kind
&& match lt.pat.kind { && match lt.pat.kind {
PatKind::Slice([], None, []) => true, PatKind::Slice([], None, []) => true,
PatKind::Lit(lit) => match lit.kind { PatKind::Expr(lit) => match lit.kind {
PatExprKind::Lit { lit, .. } => match lit.node { PatExprKind::Lit { lit, .. } => match lit.node {
LitKind::Str(lit, _) => lit.as_str().is_empty(), LitKind::Str(lit, _) => lit.as_str().is_empty(),
_ => false, _ => false,

View file

@ -89,7 +89,7 @@ impl LateLintPass<'_> for ManualRangePatterns {
let mut ranges_found = Vec::new(); let mut ranges_found = Vec::new();
for pat in pats { for pat in pats {
if let PatKind::Lit(lit) = pat.kind if let PatKind::Expr(lit) = pat.kind
&& let Some(num) = Num::new(lit) && let Some(num) = Num::new(lit)
{ {
numbers_found.insert(num.val); numbers_found.insert(num.val);

View file

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

View file

@ -7,7 +7,7 @@ use rustc_arena::DroplessArena;
use rustc_ast::ast::LitKind; use rustc_ast::ast::LitKind;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{Arm, Expr, PatExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd}; use rustc_hir::{Arm, Expr, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatExprKind, PatKind, RangeEnd};
use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::ty; use rustc_middle::ty;
@ -311,9 +311,9 @@ impl<'a> NormalizedPat<'a> {
); );
Self::Tuple(None, pats) Self::Tuple(None, pats)
}, },
PatKind::Lit(e) => match &e.kind { PatKind::Expr(e) => match &e.kind {
// TODO: Handle negative integers. They're currently treated as a wild match. // TODO: Handle negative integers. They're currently treated as a wild match.
PatExprKind::Lit{ lit, negated: false } => match lit.node { PatExprKind::Lit { lit, negated: false } => match lit.node {
LitKind::Str(sym, _) => Self::LitStr(sym), LitKind::Str(sym, _) => Self::LitStr(sym),
LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
LitKind::Byte(val) => Self::LitInt(val.into()), LitKind::Byte(val) => Self::LitInt(val.into()),

View file

@ -85,7 +85,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(
}; };
for arm in arms { for arm in arms {
if let PatKind::Lit(PatExpr { if let PatKind::Expr(PatExpr {
kind: PatExprKind::Lit { lit, negated: false }, kind: PatExprKind::Lit { lit, negated: false },
.. ..
}) = arm.pat.kind }) = arm.pat.kind

View file

@ -189,7 +189,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
}); });
}, },
// Example: `5 => 5` // Example: `5 => 5`
(PatKind::Lit(pat_expr_expr), ExprKind::Lit(expr_spanned)) => { (PatKind::Expr(pat_expr_expr), ExprKind::Lit(expr_spanned)) => {
if let PatExprKind::Lit { if let PatExprKind::Lit {
lit: pat_spanned, lit: pat_spanned,
negated: false, negated: false,

View file

@ -57,7 +57,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
}); });
} }
if let PatKind::Lit(value) = pat.kind { if let PatKind::Expr(value) = pat.kind {
let value = ConstEvalCtxt::new(cx) let value = ConstEvalCtxt::new(cx)
.eval_pat_expr(value)? .eval_pat_expr(value)?
.int_value(cx.tcx, cx.typeck_results().node_type(pat.hir_id))?; .int_value(cx.tcx, cx.typeck_results().node_type(pat.hir_id))?;

View file

@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp, PatExprKind}; use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatExprKind, PatKind, QPath, UnOp};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_middle::ty::{self, GenericArgKind, Ty};
use rustc_span::{Span, Symbol, sym}; use rustc_span::{Span, Symbol, sym};
@ -74,8 +74,8 @@ fn find_match_true<'tcx>(
span: Span, span: Span,
message: &'static str, message: &'static str,
) { ) {
if let PatKind::Lit(lit) = pat.kind if let PatKind::Expr(lit) = pat.kind
&& let PatExprKind::Lit{ lit, negated: false } = lit.kind && let PatExprKind::Lit { lit, negated: false } = lit.kind
&& let LitKind::Bool(pat_is_true) = lit.node && let LitKind::Bool(pat_is_true) = lit.node
{ {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;

View file

@ -9,7 +9,7 @@ use rustc_arena::DroplessArena;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Visitor, walk_pat}; use rustc_hir::intravisit::{Visitor, walk_pat};
use rustc_hir::{Arm, Expr, ExprKind, HirId, Node, Pat, PatKind, QPath, StmtKind, PatExpr, PatExprKind}; use rustc_hir::{Arm, Expr, ExprKind, HirId, Node, Pat, PatExpr, PatExprKind, PatKind, QPath, StmtKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::{self, AdtDef, TyCtxt, TypeckResults, VariantDef}; use rustc_middle::ty::{self, AdtDef, TyCtxt, TypeckResults, VariantDef};
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
@ -114,7 +114,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
} }
let (pat, pat_ref_count) = peel_hir_pat_refs(arm.pat); let (pat, pat_ref_count) = peel_hir_pat_refs(arm.pat);
let (msg, sugg) = if let PatKind::Path(_) | PatKind::Lit(_) = pat.kind let (msg, sugg) = if let PatKind::Path(_) | PatKind::Expr(_) = pat.kind
&& let (ty, ty_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(ex)) && let (ty, ty_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(ex))
&& let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait() && let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait()
&& let Some(pe_trait_id) = cx.tcx.lang_items().eq_trait() && 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
// scrutinee derives PartialEq and the pattern is a constant. // scrutinee derives PartialEq and the pattern is a constant.
let pat_ref_count = match pat.kind { let pat_ref_count = match pat.kind {
// string literals are already a reference. // string literals are already a reference.
PatKind::Lit(PatExpr { PatKind::Expr(PatExpr {
kind: PatExprKind::Lit { lit, negated: false }, kind: PatExprKind::Lit { lit, negated: false },
.. ..
}) if lit.node.is_str() || lit.node.is_bytestr() => pat_ref_count + 1, }) if lit.node.is_str() || lit.node.is_bytestr() => pat_ref_count + 1,
@ -384,7 +384,7 @@ impl<'a> PatState<'a> {
PatKind::Wild PatKind::Wild
| PatKind::Binding(_, _, _, None) | PatKind::Binding(_, _, _, None)
| PatKind::Lit(_) | PatKind::Expr(_)
| PatKind::Range(..) | PatKind::Range(..)
| PatKind::Path(_) | PatKind::Path(_)
| PatKind::Never | PatKind::Never

View file

@ -171,7 +171,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<
return ControlFlow::Break(()); return ControlFlow::Break(());
} }
if arm.pat.walk_short(|pat| match pat.kind { if arm.pat.walk_short(|pat| match pat.kind {
PatKind::Lit(expr) if let PatExprKind::Lit { lit, negated: false } = expr.kind => { PatKind::Expr(expr) if let PatExprKind::Lit { lit, negated: false } = expr.kind => {
if let LitKind::Char(_) = lit.node { if let LitKind::Char(_) = lit.node {
set_char_spans.push(lit.span); set_char_spans.push(lit.span);
} }

View file

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

View file

@ -738,10 +738,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Guard({pat}, {cond})"); kind!("Guard({pat}, {cond})");
self.pat(pat); self.pat(pat);
self.expr(cond); self.expr(cond);
} },
PatKind::Lit(lit_expr) => { PatKind::Expr(lit_expr) => {
bind!(self, lit_expr); bind!(self, lit_expr);
kind!("Lit({lit_expr})"); kind!("Expr({lit_expr})");
self.pat_expr(lit_expr); self.pat_expr(lit_expr);
}, },
PatKind::Range(start, end, end_kind) => { PatKind::Range(start, end, end_kind) => {

View file

@ -36,7 +36,7 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
(Paren(l), _) => eq_pat(l, r), (Paren(l), _) => eq_pat(l, r),
(_, Paren(r)) => eq_pat(l, r), (_, Paren(r)) => eq_pat(l, r),
(Wild, Wild) | (Rest, Rest) => true, (Wild, Wild) | (Rest, Rest) => true,
(Lit(l), Lit(r)) => eq_expr(l, r), (Expr(l), Expr(r)) => eq_expr(l, r),
(Ident(b1, i1, s1), Ident(b2, i2, s2)) => { (Ident(b1, i1, s1), Ident(b2, i2, s2)) => {
b1 == b2 && eq_id(*i1, *i2) && both(s1.as_deref(), s2.as_deref(), eq_pat) b1 == b2 && eq_id(*i1, *i2) && both(s1.as_deref(), s2.as_deref(), eq_pat)
}, },

View file

@ -525,7 +525,7 @@ impl HirEqInterExpr<'_, '_, '_> {
eq eq
}, },
(PatKind::Path(l), PatKind::Path(r)) => self.eq_qpath(l, r), (PatKind::Path(l), PatKind::Path(r)) => self.eq_qpath(l, r),
(&PatKind::Lit(l), &PatKind::Lit(r)) => self.eq_pat_expr(l, r), (&PatKind::Expr(l), &PatKind::Expr(r)) => self.eq_pat_expr(l, r),
(&PatKind::Tuple(l, ls), &PatKind::Tuple(r, rs)) => ls == rs && over(l, r, |l, r| self.eq_pat(l, r)), (&PatKind::Tuple(l, ls), &PatKind::Tuple(r, rs)) => ls == rs && over(l, r, |l, r| self.eq_pat(l, r)),
(&PatKind::Range(ref ls, ref le, li), &PatKind::Range(ref rs, ref re, ri)) => { (&PatKind::Range(ref ls, ref le, li), &PatKind::Range(ref rs, ref re, ri)) => {
both(ls.as_ref(), rs.as_ref(), |a, b| self.eq_pat_expr(a, b)) 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> {
} }
}, },
PatKind::Box(pat) | PatKind::Deref(pat) => self.hash_pat(pat), PatKind::Box(pat) | PatKind::Deref(pat) => self.hash_pat(pat),
PatKind::Lit(expr) => self.hash_pat_expr(expr), PatKind::Expr(expr) => self.hash_pat_expr(expr),
PatKind::Or(pats) => { PatKind::Or(pats) => {
for pat in pats { for pat in pats {
self.hash_pat(pat); self.hash_pat(pat);

View file

@ -1777,7 +1777,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
}, },
} }
}, },
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true, PatKind::Expr(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
} }
} }

View file

@ -30,7 +30,7 @@ if let StmtKind::Let(local) = stmt.kind
} }
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
&& let ExprKind::Let(let_expr) = cond.kind && let ExprKind::Let(let_expr) = cond.kind
&& let PatKind::Lit(lit_expr) = let_expr.pat.kind && let PatKind::Expr(lit_expr) = let_expr.pat.kind
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind && let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
&& let LitKind::Bool(true) = lit.node && let LitKind::Bool(true) = lit.node
&& let ExprKind::Path(ref qpath) = let_expr.init.kind && let ExprKind::Path(ref qpath) = let_expr.init.kind

View file

@ -76,7 +76,7 @@ if let Some(higher::While { condition: condition, body: body }) = higher::While:
// report your lint here // report your lint here
} }
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr) if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
&& let PatKind::Lit(lit_expr) = let_pat.kind && let PatKind::Expr(lit_expr) = let_pat.kind
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind && let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
&& let LitKind::Bool(true) = lit.node && let LitKind::Bool(true) = lit.node
&& let ExprKind::Path(ref qpath) = let_expr.kind && let ExprKind::Path(ref qpath) = let_expr.kind

View file

@ -4,13 +4,13 @@ if let StmtKind::Let(local) = stmt.kind
&& let ExprKind::Lit(ref lit) = scrutinee.kind && let ExprKind::Lit(ref lit) = scrutinee.kind
&& let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node && let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
&& arms.len() == 3 && arms.len() == 3
&& let PatKind::Lit(lit_expr) = arms[0].pat.kind && let PatKind::Expr(lit_expr) = arms[0].pat.kind
&& let PatExprKind::Lit{ref lit1, negated } = lit_expr.kind && let PatExprKind::Lit{ref lit1, negated } = lit_expr.kind
&& let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node && let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
&& arms[0].guard.is_none() && arms[0].guard.is_none()
&& let ExprKind::Lit(ref lit2) = arms[0].body.kind && let ExprKind::Lit(ref lit2) = arms[0].body.kind
&& let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node && let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
&& let PatKind::Lit(lit_expr1) = arms[1].pat.kind && let PatKind::Expr(lit_expr1) = arms[1].pat.kind
&& let PatExprKind::Lit{ref lit3, negated1 } = lit_expr1.kind && let PatExprKind::Lit{ref lit3, negated1 } = lit_expr1.kind
&& let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node && let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
&& arms[1].guard.is_none() && arms[1].guard.is_none()

View file

@ -23,7 +23,7 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
&& match_qpath(qpath, &["Test"]) && match_qpath(qpath, &["Test"])
&& fields.len() == 1 && fields.len() == 1
&& fields[0].ident.as_str() == "field" && fields[0].ident.as_str() == "field"
&& let PatKind::Lit(lit_expr) = fields[0].pat.kind && let PatKind::Expr(lit_expr) = fields[0].pat.kind
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind && let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
&& arm.guard.is_none() && arm.guard.is_none()
@ -36,7 +36,7 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
&& match_qpath(qpath, &["TestTuple"]) && match_qpath(qpath, &["TestTuple"])
&& fields.len() == 1 && fields.len() == 1
&& let PatKind::Lit(lit_expr) = fields[0].kind && let PatKind::Expr(lit_expr) = fields[0].kind
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind && let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
&& arm.guard.is_none() && arm.guard.is_none()

View file

@ -42,7 +42,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
| ast::PatKind::Never | ast::PatKind::Never
| ast::PatKind::Wild | ast::PatKind::Wild
| ast::PatKind::Err(_) | ast::PatKind::Err(_)
| ast::PatKind::Lit(_) => true, | ast::PatKind::Expr(_) => true,
ast::PatKind::Ident(_, _, ref pat) => pat.is_none(), ast::PatKind::Ident(_, _, ref pat) => pat.is_none(),
ast::PatKind::Struct(..) ast::PatKind::Struct(..)
| ast::PatKind::MacCall(..) | ast::PatKind::MacCall(..)
@ -293,7 +293,7 @@ impl Rewrite for Pat {
let path_str = rewrite_path(context, PathContext::Expr, q_self, path, shape)?; let path_str = rewrite_path(context, PathContext::Expr, q_self, path, shape)?;
rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape) rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape)
} }
PatKind::Lit(ref expr) => expr.rewrite_result(context, shape), PatKind::Expr(ref expr) => expr.rewrite_result(context, shape),
PatKind::Slice(ref slice_pat) PatKind::Slice(ref slice_pat)
if context.config.style_edition() <= StyleEdition::Edition2021 => if context.config.style_edition() <= StyleEdition::Edition2021 =>
{ {
@ -530,7 +530,7 @@ pub(crate) fn can_be_overflowed_pat(
ast::PatKind::Ref(ref p, _) | ast::PatKind::Box(ref p) => { ast::PatKind::Ref(ref p, _) | ast::PatKind::Box(ref p) => {
can_be_overflowed_pat(context, &TuplePatField::Pat(p), len) can_be_overflowed_pat(context, &TuplePatField::Pat(p), len)
} }
ast::PatKind::Lit(ref expr) => can_be_overflowed_expr(context, expr, len), ast::PatKind::Expr(ref expr) => can_be_overflowed_expr(context, expr, len),
_ => false, _ => false,
}, },
TuplePatField::Dotdot(..) => false, TuplePatField::Dotdot(..) => false,

View file

@ -569,7 +569,7 @@ fn test_pat() {
c1!(pat, [ &pat ], "&pat"); c1!(pat, [ &pat ], "&pat");
c1!(pat, [ &mut pat ], "&mut pat"); c1!(pat, [ &mut pat ], "&mut pat");
// PatKind::Lit // PatKind::Expr
c1!(pat, [ 1_000_i8 ], "1_000_i8"); c1!(pat, [ 1_000_i8 ], "1_000_i8");
// PatKind::Range // PatKind::Range

View file

@ -6,7 +6,7 @@ macro_rules! enum_number {
fn foo(value: i32) -> Option<$name> { fn foo(value: i32) -> Option<$name> {
match value { match value {
$( $value => Some($name::$variant), )* // PatKind::Lit $( $value => Some($name::$variant), )* // PatKind::Expr
$( $value ..= 42 => Some($name::$variant), )* // PatKind::Range $( $value ..= 42 => Some($name::$variant), )* // PatKind::Range
_ => None _ => None
} }

View file

@ -651,8 +651,8 @@ mod patterns {
let &mut pat; let &mut pat;
} }
/// PatKind::Lit /// PatKind::Expr
fn pat_lit() { fn pat_expr() {
let 1_000_i8; let 1_000_i8;
let -""; let -"";
} }

View file

@ -567,8 +567,8 @@ mod patterns {
fn pat_deref() { let deref!(pat); } fn pat_deref() { let deref!(pat); }
/// PatKind::Ref /// PatKind::Ref
fn pat_ref() { let &pat; let &mut pat; } fn pat_ref() { let &pat; let &mut pat; }
/// PatKind::Lit /// PatKind::Expr
fn pat_lit() { let 1_000_i8; let -""; } fn pat_expr() { let 1_000_i8; let -""; }
/// PatKind::Range /// PatKind::Range
fn pat_range() { let ..1; let 0..; let 0..1; let 0..=1; let -2..=-1; } fn pat_range() { let ..1; let 0..; let 0..1; let 0..=1; let -2..=-1; }
/// PatKind::Slice /// PatKind::Slice