mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rename PatKind::Lit to Expr
This commit is contained in:
@@ -623,7 +623,7 @@ pub fn walk(&self, it: &mut impl FnMut(&Pat) -> bool) {
|
||||
PatKind::Wild
|
||||
| PatKind::Rest
|
||||
| PatKind::Never
|
||||
| PatKind::Lit(_)
|
||||
| PatKind::Expr(_)
|
||||
| PatKind::Range(..)
|
||||
| PatKind::Ident(..)
|
||||
| PatKind::Path(..)
|
||||
@@ -801,8 +801,8 @@ pub enum PatKind {
|
||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||
Ref(P<Pat>, Mutability),
|
||||
|
||||
/// A literal.
|
||||
Lit(P<Expr>),
|
||||
/// A literal, const block or path.
|
||||
Expr(P<Expr>),
|
||||
|
||||
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
|
||||
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),
|
||||
|
||||
@@ -1512,7 +1512,7 @@ pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
|
||||
vis.visit_ident(ident);
|
||||
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) => {
|
||||
vis.visit_qself(qself);
|
||||
vis.visit_path(path);
|
||||
|
||||
@@ -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));
|
||||
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) => {
|
||||
visit_opt!(visitor, visit_expr, lower_bound);
|
||||
visit_opt!(visitor, visit_expr, upper_bound);
|
||||
|
||||
@@ -38,8 +38,8 @@ fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
|
||||
lower_sub,
|
||||
);
|
||||
}
|
||||
PatKind::Lit(e) => {
|
||||
break hir::PatKind::Lit(self.lower_expr_within_pat(e, false));
|
||||
PatKind::Expr(e) => {
|
||||
break hir::PatKind::Expr(self.lower_expr_within_pat(e, false));
|
||||
}
|
||||
PatKind::TupleStruct(qself, path, pats) => {
|
||||
let qpath = self.lower_qpath(
|
||||
|
||||
@@ -1701,7 +1701,7 @@ fn print_pat(&mut self, pat: &ast::Pat) {
|
||||
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, .. }) => {
|
||||
if let Some(e) = begin {
|
||||
self.print_expr(e, FixupContext::default());
|
||||
|
||||
@@ -522,7 +522,7 @@ fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
|
||||
return Some(P(ast::Pat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: e.span,
|
||||
kind: PatKind::Lit(e),
|
||||
kind: PatKind::Expr(e),
|
||||
tokens: None,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ pub fn pat_wild(&self, span: Span) -> P<ast::Pat> {
|
||||
self.pat(span, PatKind::Wild)
|
||||
}
|
||||
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> {
|
||||
self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE)
|
||||
|
||||
@@ -1386,7 +1386,7 @@ fn walk_short_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) -> bool {
|
||||
|
||||
use PatKind::*;
|
||||
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),
|
||||
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)),
|
||||
@@ -1413,7 +1413,7 @@ fn walk_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) {
|
||||
|
||||
use PatKind::*;
|
||||
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),
|
||||
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)),
|
||||
@@ -1583,8 +1583,8 @@ pub enum PatKind<'hir> {
|
||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||
Ref(&'hir Pat<'hir>, Mutability),
|
||||
|
||||
/// A literal.
|
||||
Lit(&'hir PatExpr<'hir>),
|
||||
/// A literal, const block or path.
|
||||
Expr(&'hir PatExpr<'hir>),
|
||||
|
||||
/// A guard pattern (e.g., `x if guard(x)`).
|
||||
Guard(&'hir Pat<'hir>, &'hir Expr<'hir>),
|
||||
|
||||
@@ -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));
|
||||
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, _) => {
|
||||
visit_opt!(visitor, visit_pat_expr, lower_bound);
|
||||
visit_opt!(visitor, visit_pat_expr, upper_bound);
|
||||
|
||||
@@ -704,7 +704,7 @@ fn is_binding_pat(pat: &hir::Pat<'_>) -> bool {
|
||||
| PatKind::Wild
|
||||
| PatKind::Never
|
||||
| PatKind::Path(_)
|
||||
| PatKind::Lit(_)
|
||||
| PatKind::Expr(_)
|
||||
| PatKind::Range(_, _, _)
|
||||
| PatKind::Err(_) => false,
|
||||
}
|
||||
|
||||
@@ -1980,7 +1980,7 @@ fn print_pat(&mut self, pat: &hir::Pat<'_>) {
|
||||
self.pclose();
|
||||
}
|
||||
}
|
||||
PatKind::Lit(e) => self.print_pat_expr(e),
|
||||
PatKind::Expr(e) => self.print_pat_expr(e),
|
||||
PatKind::Range(begin, end, end_kind) => {
|
||||
if let Some(expr) = begin {
|
||||
self.print_pat_expr(expr);
|
||||
|
||||
@@ -485,7 +485,7 @@ pub(super) fn pat_guaranteed_to_constitute_read_for_never(&self, pat: &hir::Pat<
|
||||
| hir::PatKind::Box(_)
|
||||
| hir::PatKind::Ref(_, _)
|
||||
| hir::PatKind::Deref(_)
|
||||
| hir::PatKind::Lit(_)
|
||||
| hir::PatKind::Expr(_)
|
||||
| hir::PatKind::Range(_, _, _)
|
||||
| hir::PatKind::Slice(_, _, _)
|
||||
| hir::PatKind::Err(_) => true,
|
||||
|
||||
@@ -595,7 +595,7 @@ fn maybe_read_scrutinee<'t>(
|
||||
let place_ty = place.place.ty();
|
||||
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
|
||||
// to borrow discr.
|
||||
needs_to_be_read = true;
|
||||
@@ -1803,7 +1803,7 @@ fn cat_pattern<F>(
|
||||
|
||||
PatKind::Path(_)
|
||||
| PatKind::Binding(.., None)
|
||||
| PatKind::Lit(..)
|
||||
| PatKind::Expr(..)
|
||||
| PatKind::Range(..)
|
||||
| PatKind::Never
|
||||
| PatKind::Wild
|
||||
|
||||
@@ -271,7 +271,7 @@ fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<
|
||||
PatKind::Wild | PatKind::Err(_) => expected,
|
||||
// We allow any type here; we ensure that the type is uninhabited during match checking.
|
||||
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::Binding(ba, var_id, ident, sub) => {
|
||||
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
|
||||
@@ -399,7 +399,7 @@ fn calc_adjust_mode(&self, pat: &'tcx Pat<'tcx>, opt_path_res: Option<Res>) -> A
|
||||
// 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.
|
||||
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,
|
||||
_ => AdjustMode::Peel,
|
||||
},
|
||||
@@ -943,7 +943,7 @@ fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
|
||||
| PatKind::Box(..)
|
||||
| PatKind::Deref(_)
|
||||
| PatKind::Ref(..)
|
||||
| PatKind::Lit(..)
|
||||
| PatKind::Expr(..)
|
||||
| PatKind::Range(..)
|
||||
| PatKind::Err(_) => break 'block None,
|
||||
},
|
||||
@@ -1837,7 +1837,7 @@ fn error_inexistent_fields(
|
||||
}
|
||||
} else if inexistent_fields.len() == 1 {
|
||||
match pat_field.pat.kind {
|
||||
PatKind::Lit(_)
|
||||
PatKind::Expr(_)
|
||||
if !self.may_coerce(
|
||||
self.typeck_results.borrow().node_type(pat_field.pat.hir_id),
|
||||
self.field_ty(field.span, field_def, args),
|
||||
|
||||
@@ -1220,7 +1220,7 @@ fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &ast::Pat) {
|
||||
// Do not lint on `(..)` as that will result in the other arms being useless.
|
||||
Paren(_)
|
||||
// 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.
|
||||
TupleStruct(_, _, ps) | Tuple(ps) | Slice(ps) | Or(ps) => for p in ps {
|
||||
self.check_unused_parens_pat(cx, p, false, false, keep_space);
|
||||
|
||||
@@ -324,7 +324,7 @@ fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tc
|
||||
|
||||
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) => {
|
||||
let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref());
|
||||
|
||||
@@ -656,14 +656,14 @@ fn visit_pat_field(&mut self, fp: &'a PatField) -> Self::Result {
|
||||
fn visit_pat(&mut self, p: &'a Pat) -> Self::Result {
|
||||
match &p.kind {
|
||||
// Base expression
|
||||
PatKind::Err(_) | PatKind::Lit(_) => {
|
||||
PatKind::Err(_) | PatKind::Expr(_) => {
|
||||
self.maybe_add_suggestions_then_emit(p.span, p.span, false)
|
||||
}
|
||||
|
||||
// Sub-patterns
|
||||
// FIXME: this doesn't work with recursive subpats (`&mut &mut <err>`)
|
||||
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)
|
||||
}
|
||||
@@ -766,7 +766,7 @@ fn parse_pat_with_range_pat(
|
||||
if let Some(re) = self.parse_range_end() {
|
||||
self.parse_pat_range_begin_with(const_expr, re)?
|
||||
} else {
|
||||
PatKind::Lit(const_expr)
|
||||
PatKind::Expr(const_expr)
|
||||
}
|
||||
} else if self.is_builtin() {
|
||||
self.parse_pat_builtin()?
|
||||
@@ -833,7 +833,7 @@ fn parse_pat_with_range_pat(
|
||||
.struct_span_err(self_.token.span, msg)
|
||||
.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 {
|
||||
// Try to parse everything else as literal with optional minus
|
||||
match self.parse_literal_maybe_minus() {
|
||||
@@ -845,7 +845,7 @@ fn parse_pat_with_range_pat(
|
||||
|
||||
match self.parse_range_end() {
|
||||
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),
|
||||
@@ -989,7 +989,7 @@ fn parse_pat_tuple_or_parens(&mut self) -> PResult<'a, PatKind> {
|
||||
|
||||
match &pat.kind {
|
||||
// recover ranges with parentheses around the `(start)..`
|
||||
PatKind::Lit(begin)
|
||||
PatKind::Expr(begin)
|
||||
if self.may_recover()
|
||||
&& let Some(form) = self.parse_range_end() =>
|
||||
{
|
||||
|
||||
@@ -304,7 +304,7 @@ fn visit_pat(&mut self, p: &'v hir::Pat<'v>) {
|
||||
Box,
|
||||
Deref,
|
||||
Ref,
|
||||
Lit,
|
||||
Expr,
|
||||
Guard,
|
||||
Range,
|
||||
Slice,
|
||||
@@ -587,7 +587,7 @@ fn visit_pat(&mut self, p: &'v ast::Pat) {
|
||||
Box,
|
||||
Deref,
|
||||
Ref,
|
||||
Lit,
|
||||
Expr,
|
||||
Range,
|
||||
Slice,
|
||||
Rest,
|
||||
|
||||
@@ -314,9 +314,9 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
|
||||
PatKind::Box(p) => return name_from_pat(p),
|
||||
PatKind::Deref(p) => format!("deref!({})", name_from_pat(p)),
|
||||
PatKind::Ref(p, _) => return name_from_pat(p),
|
||||
PatKind::Lit(..) => {
|
||||
PatKind::Expr(..) => {
|
||||
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("()");
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
|
||||
fn visit_pat(&mut self, pat: &'tcx Pat<'_>) {
|
||||
match pat.kind {
|
||||
PatKind::Lit(&PatExpr {
|
||||
PatKind::Expr(&PatExpr {
|
||||
hir_id,
|
||||
kind: PatExprKind::Lit { lit, .. },
|
||||
..
|
||||
|
||||
@@ -56,7 +56,7 @@ fn array_rec(pats: &[Pat<'_>]) -> bool {
|
||||
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::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
|
||||
PatKind::Path(_) | PatKind::Lit(_) => true,
|
||||
PatKind::Path(_) | PatKind::Expr(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Let(lt) = expr.kind
|
||||
&& match lt.pat.kind {
|
||||
PatKind::Slice([], None, []) => true,
|
||||
PatKind::Lit(lit) => match lit.kind {
|
||||
PatKind::Expr(lit) => match lit.kind {
|
||||
PatExprKind::Lit { lit, .. } => match lit.node {
|
||||
LitKind::Str(lit, _) => lit.as_str().is_empty(),
|
||||
_ => false,
|
||||
|
||||
@@ -89,7 +89,7 @@ fn check_pat(&mut self, cx: &LateContext<'_>, pat: &'_ rustc_hir::Pat<'_>) {
|
||||
let mut ranges_found = Vec::new();
|
||||
|
||||
for pat in pats {
|
||||
if let PatKind::Lit(lit) = pat.kind
|
||||
if let PatKind::Expr(lit) = pat.kind
|
||||
&& let Some(num) = Num::new(lit)
|
||||
{
|
||||
numbers_found.insert(num.val);
|
||||
|
||||
@@ -21,7 +21,7 @@ pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>]
|
||||
move |diag| {
|
||||
if arms.len() == 2 {
|
||||
// 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 {
|
||||
match lit.node {
|
||||
LitKind::Bool(true) => Some((arms[0].body, arms[1].body)),
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
use rustc_ast::ast::LitKind;
|
||||
use rustc_errors::Applicability;
|
||||
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::{LateContext, LintContext};
|
||||
use rustc_middle::ty;
|
||||
@@ -311,9 +311,9 @@ fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) ->
|
||||
);
|
||||
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.
|
||||
PatExprKind::Lit{ lit, negated: false } => match lit.node {
|
||||
PatExprKind::Lit { lit, negated: false } => match lit.node {
|
||||
LitKind::Str(sym, _) => Self::LitStr(sym),
|
||||
LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
|
||||
LitKind::Byte(val) => Self::LitInt(val.into()),
|
||||
|
||||
@@ -85,7 +85,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(
|
||||
};
|
||||
|
||||
for arm in arms {
|
||||
if let PatKind::Lit(PatExpr {
|
||||
if let PatKind::Expr(PatExpr {
|
||||
kind: PatExprKind::Lit { lit, negated: false },
|
||||
..
|
||||
}) = arm.pat.kind
|
||||
|
||||
@@ -189,7 +189,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
|
||||
});
|
||||
},
|
||||
// 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 {
|
||||
lit: pat_spanned,
|
||||
negated: false,
|
||||
|
||||
@@ -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)
|
||||
.eval_pat_expr(value)?
|
||||
.int_value(cx.tcx, cx.typeck_results().node_type(pat.hir_id))?;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
|
||||
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_middle::ty::{self, GenericArgKind, Ty};
|
||||
use rustc_span::{Span, Symbol, sym};
|
||||
@@ -74,8 +74,8 @@ fn find_match_true<'tcx>(
|
||||
span: Span,
|
||||
message: &'static str,
|
||||
) {
|
||||
if let PatKind::Lit(lit) = pat.kind
|
||||
&& let PatExprKind::Lit{ lit, negated: false } = lit.kind
|
||||
if let PatKind::Expr(lit) = pat.kind
|
||||
&& let PatExprKind::Lit { lit, negated: false } = lit.kind
|
||||
&& let LitKind::Bool(pat_is_true) = lit.node
|
||||
{
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
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_middle::ty::{self, AdtDef, TyCtxt, TypeckResults, VariantDef};
|
||||
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 (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 Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_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.
|
||||
let pat_ref_count = match pat.kind {
|
||||
// string literals are already a reference.
|
||||
PatKind::Lit(PatExpr {
|
||||
PatKind::Expr(PatExpr {
|
||||
kind: PatExprKind::Lit { lit, negated: false },
|
||||
..
|
||||
}) if lit.node.is_str() || lit.node.is_bytestr() => pat_ref_count + 1,
|
||||
@@ -384,7 +384,7 @@ fn add_pat<'tcx>(&mut self, cx: &'a PatCtxt<'tcx>, pat: &'tcx Pat<'_>) -> bool {
|
||||
|
||||
PatKind::Wild
|
||||
| PatKind::Binding(_, _, _, None)
|
||||
| PatKind::Lit(_)
|
||||
| PatKind::Expr(_)
|
||||
| PatKind::Range(..)
|
||||
| PatKind::Path(_)
|
||||
| PatKind::Never
|
||||
|
||||
@@ -171,7 +171,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
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 {
|
||||
set_char_spans.push(lit.span);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ fn check_local(&mut self, cx: &EarlyContext<'_>, l: &ast::Local) {
|
||||
}
|
||||
|
||||
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.
|
||||
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`,
|
||||
// with which a pattern `C(p_0)` may be formed,
|
||||
// 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,
|
||||
// and almost always requires adding parens (increasing noisiness).
|
||||
// In the case of only two patterns, replacement adds net characters.
|
||||
|
||||
@@ -738,10 +738,10 @@ macro_rules! kind {
|
||||
kind!("Guard({pat}, {cond})");
|
||||
self.pat(pat);
|
||||
self.expr(cond);
|
||||
}
|
||||
PatKind::Lit(lit_expr) => {
|
||||
},
|
||||
PatKind::Expr(lit_expr) => {
|
||||
bind!(self, lit_expr);
|
||||
kind!("Lit({lit_expr})");
|
||||
kind!("Expr({lit_expr})");
|
||||
self.pat_expr(lit_expr);
|
||||
},
|
||||
PatKind::Range(start, end, end_kind) => {
|
||||
|
||||
@@ -36,7 +36,7 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
|
||||
(Paren(l), _) => eq_pat(l, r),
|
||||
(_, Paren(r)) => eq_pat(l, r),
|
||||
(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)) => {
|
||||
b1 == b2 && eq_id(*i1, *i2) && both(s1.as_deref(), s2.as_deref(), eq_pat)
|
||||
},
|
||||
|
||||
@@ -525,7 +525,7 @@ fn eq_pat(&mut self, left: &Pat<'_>, right: &Pat<'_>) -> bool {
|
||||
eq
|
||||
},
|
||||
(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::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))
|
||||
@@ -1114,7 +1114,7 @@ pub fn hash_pat(&mut self, 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) => {
|
||||
for pat in pats {
|
||||
self.hash_pat(pat);
|
||||
|
||||
@@ -1777,7 +1777,7 @@ fn are_refutable<'a, I: IntoIterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>,
|
||||
},
|
||||
}
|
||||
},
|
||||
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
|
||||
PatKind::Expr(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ if let StmtKind::Let(local) = stmt.kind
|
||||
}
|
||||
if let ExprKind::If(cond, then, Some(else_expr)) = expr.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 LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.init.kind
|
||||
|
||||
@@ -76,7 +76,7 @@ if let Some(higher::While { condition: condition, body: body }) = higher::While:
|
||||
// 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)
|
||||
&& 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 LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.kind
|
||||
|
||||
@@ -4,13 +4,13 @@ if let StmtKind::Let(local) = stmt.kind
|
||||
&& let ExprKind::Lit(ref lit) = scrutinee.kind
|
||||
&& let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
|
||||
&& 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 LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
|
||||
&& arms[0].guard.is_none()
|
||||
&& let ExprKind::Lit(ref lit2) = arms[0].body.kind
|
||||
&& 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 LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
|
||||
&& arms[1].guard.is_none()
|
||||
|
||||
@@ -23,7 +23,7 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
|
||||
&& match_qpath(qpath, &["Test"])
|
||||
&& fields.len() == 1
|
||||
&& 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 LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& 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
|
||||
&& match_qpath(qpath, &["TestTuple"])
|
||||
&& 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 LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& arm.guard.is_none()
|
||||
|
||||
@@ -42,7 +42,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
|
||||
| ast::PatKind::Never
|
||||
| ast::PatKind::Wild
|
||||
| ast::PatKind::Err(_)
|
||||
| ast::PatKind::Lit(_) => true,
|
||||
| ast::PatKind::Expr(_) => true,
|
||||
ast::PatKind::Ident(_, _, ref pat) => pat.is_none(),
|
||||
ast::PatKind::Struct(..)
|
||||
| ast::PatKind::MacCall(..)
|
||||
@@ -293,7 +293,7 @@ fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteR
|
||||
let path_str = rewrite_path(context, PathContext::Expr, q_self, path, 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)
|
||||
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) => {
|
||||
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,
|
||||
},
|
||||
TuplePatField::Dotdot(..) => false,
|
||||
|
||||
@@ -569,7 +569,7 @@ fn test_pat() {
|
||||
c1!(pat, [ &pat ], "&pat");
|
||||
c1!(pat, [ &mut pat ], "&mut pat");
|
||||
|
||||
// PatKind::Lit
|
||||
// PatKind::Expr
|
||||
c1!(pat, [ 1_000_i8 ], "1_000_i8");
|
||||
|
||||
// PatKind::Range
|
||||
|
||||
@@ -6,7 +6,7 @@ enum $name {
|
||||
|
||||
fn foo(value: i32) -> Option<$name> {
|
||||
match value {
|
||||
$( $value => Some($name::$variant), )* // PatKind::Lit
|
||||
$( $value => Some($name::$variant), )* // PatKind::Expr
|
||||
$( $value ..= 42 => Some($name::$variant), )* // PatKind::Range
|
||||
_ => None
|
||||
}
|
||||
|
||||
@@ -651,8 +651,8 @@ fn pat_ref() {
|
||||
let &mut pat;
|
||||
}
|
||||
|
||||
/// PatKind::Lit
|
||||
fn pat_lit() {
|
||||
/// PatKind::Expr
|
||||
fn pat_expr() {
|
||||
let 1_000_i8;
|
||||
let -"";
|
||||
}
|
||||
|
||||
@@ -567,8 +567,8 @@ mod patterns {
|
||||
fn pat_deref() { let deref!(pat); }
|
||||
/// PatKind::Ref
|
||||
fn pat_ref() { let &pat; let &mut pat; }
|
||||
/// PatKind::Lit
|
||||
fn pat_lit() { let 1_000_i8; let -""; }
|
||||
/// PatKind::Expr
|
||||
fn pat_expr() { let 1_000_i8; let -""; }
|
||||
/// PatKind::Range
|
||||
fn pat_range() { let ..1; let 0..; let 0..1; let 0..=1; let -2..=-1; }
|
||||
/// PatKind::Slice
|
||||
|
||||
Reference in New Issue
Block a user