Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC

use matches!() macro in more places
This commit is contained in:
Dylan DPC 2020-12-28 14:13:12 +01:00 committed by GitHub
commit c51172f38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 137 additions and 266 deletions

View File

@ -167,10 +167,7 @@ pub enum GenericArgs {
impl GenericArgs { impl GenericArgs {
pub fn is_angle_bracketed(&self) -> bool { pub fn is_angle_bracketed(&self) -> bool {
match *self { matches!(self, AngleBracketed(..))
AngleBracketed(..) => true,
_ => false,
}
} }
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
@ -629,10 +626,7 @@ impl Pat {
/// Is this a `..` pattern? /// Is this a `..` pattern?
pub fn is_rest(&self) -> bool { pub fn is_rest(&self) -> bool {
match self.kind { matches!(self.kind, PatKind::Rest)
PatKind::Rest => true,
_ => false,
}
} }
} }
@ -852,10 +846,7 @@ impl BinOpKind {
} }
} }
pub fn lazy(&self) -> bool { pub fn lazy(&self) -> bool {
match *self { matches!(self, BinOpKind::And | BinOpKind::Or)
BinOpKind::And | BinOpKind::Or => true,
_ => false,
}
} }
pub fn is_comparison(&self) -> bool { pub fn is_comparison(&self) -> bool {
@ -963,17 +954,11 @@ impl Stmt {
} }
pub fn is_item(&self) -> bool { pub fn is_item(&self) -> bool {
match self.kind { matches!(self.kind, StmtKind::Item(_))
StmtKind::Item(_) => true,
_ => false,
}
} }
pub fn is_expr(&self) -> bool { pub fn is_expr(&self) -> bool {
match self.kind { matches!(self.kind, StmtKind::Expr(_))
StmtKind::Expr(_) => true,
_ => false,
}
} }
} }
@ -1652,26 +1637,17 @@ pub enum LitKind {
impl LitKind { impl LitKind {
/// Returns `true` if this literal is a string. /// Returns `true` if this literal is a string.
pub fn is_str(&self) -> bool { pub fn is_str(&self) -> bool {
match *self { matches!(self, LitKind::Str(..))
LitKind::Str(..) => true,
_ => false,
}
} }
/// Returns `true` if this literal is byte literal string. /// Returns `true` if this literal is byte literal string.
pub fn is_bytestr(&self) -> bool { pub fn is_bytestr(&self) -> bool {
match self { matches!(self, LitKind::ByteStr(_))
LitKind::ByteStr(_) => true,
_ => false,
}
} }
/// Returns `true` if this is a numeric literal. /// Returns `true` if this is a numeric literal.
pub fn is_numeric(&self) -> bool { pub fn is_numeric(&self) -> bool {
match *self { matches!(self, LitKind::Int(..) | LitKind::Float(..))
LitKind::Int(..) | LitKind::Float(..) => true,
_ => false,
}
} }
/// Returns `true` if this literal has no suffix. /// Returns `true` if this literal has no suffix.
@ -2237,10 +2213,7 @@ impl FnDecl {
self.inputs.get(0).map_or(false, Param::is_self) self.inputs.get(0).map_or(false, Param::is_self)
} }
pub fn c_variadic(&self) -> bool { pub fn c_variadic(&self) -> bool {
self.inputs.last().map_or(false, |arg| match arg.ty.kind { self.inputs.last().map_or(false, |arg| matches!(arg.ty.kind, TyKind::CVarArgs))
TyKind::CVarArgs => true,
_ => false,
})
} }
} }

View File

@ -234,10 +234,7 @@ impl MetaItem {
} }
pub fn is_word(&self) -> bool { pub fn is_word(&self) -> bool {
match self.kind { matches!(self.kind, MetaItemKind::Word)
MetaItemKind::Word => true,
_ => false,
}
} }
pub fn has_name(&self, name: Symbol) -> bool { pub fn has_name(&self, name: Symbol) -> bool {

View File

@ -130,10 +130,7 @@ impl LitKind {
} }
crate fn may_have_suffix(self) -> bool { crate fn may_have_suffix(self) -> bool {
match self { matches!(self, Integer | Float | Err)
Integer | Float | Err => true,
_ => false,
}
} }
} }
@ -305,10 +302,7 @@ impl TokenKind {
} }
pub fn should_end_const_arg(&self) -> bool { pub fn should_end_const_arg(&self) -> bool {
match self { matches!(self, Gt | Ge | BinOp(Shr) | BinOpEq(Shr))
Gt | Ge | BinOp(Shr) | BinOpEq(Shr) => true,
_ => false,
}
} }
} }
@ -346,18 +340,21 @@ impl Token {
} }
pub fn is_op(&self) -> bool { pub fn is_op(&self) -> bool {
match self.kind { !matches!(
OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | Ident(..) self.kind,
| Lifetime(..) | Interpolated(..) | Eof => false, OpenDelim(..)
_ => true, | CloseDelim(..)
} | Literal(..)
| DocComment(..)
| Ident(..)
| Lifetime(..)
| Interpolated(..)
| Eof
)
} }
pub fn is_like_plus(&self) -> bool { pub fn is_like_plus(&self) -> bool {
match self.kind { matches!(self.kind, BinOp(Plus) | BinOpEq(Plus))
BinOp(Plus) | BinOpEq(Plus) => true,
_ => false,
}
} }
/// Returns `true` if the token can appear at the start of an expression. /// Returns `true` if the token can appear at the start of an expression.
@ -379,13 +376,10 @@ impl Token {
ModSep | // global path ModSep | // global path
Lifetime(..) | // labeled loop Lifetime(..) | // labeled loop
Pound => true, // expression attributes Pound => true, // expression attributes
Interpolated(ref nt) => match **nt { Interpolated(ref nt) => matches!(**nt, NtLiteral(..) |
NtLiteral(..) |
NtExpr(..) | NtExpr(..) |
NtBlock(..) | NtBlock(..) |
NtPath(..) => true, NtPath(..)),
_ => false,
},
_ => false, _ => false,
} }
} }
@ -405,10 +399,7 @@ impl Token {
Lifetime(..) | // lifetime bound in trait object Lifetime(..) | // lifetime bound in trait object
Lt | BinOp(Shl) | // associated path Lt | BinOp(Shl) | // associated path
ModSep => true, // global path ModSep => true, // global path
Interpolated(ref nt) => match **nt { Interpolated(ref nt) => matches!(**nt, NtTy(..) | NtPath(..)),
NtTy(..) | NtPath(..) => true,
_ => false,
},
_ => false, _ => false,
} }
} }
@ -417,10 +408,7 @@ impl Token {
pub fn can_begin_const_arg(&self) -> bool { pub fn can_begin_const_arg(&self) -> bool {
match self.kind { match self.kind {
OpenDelim(Brace) => true, OpenDelim(Brace) => true,
Interpolated(ref nt) => match **nt { Interpolated(ref nt) => matches!(**nt, NtExpr(..) | NtBlock(..) | NtLiteral(..)),
NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
_ => false,
},
_ => self.can_begin_literal_maybe_minus(), _ => self.can_begin_literal_maybe_minus(),
} }
} }
@ -436,10 +424,7 @@ impl Token {
/// Returns `true` if the token is any literal. /// Returns `true` if the token is any literal.
pub fn is_lit(&self) -> bool { pub fn is_lit(&self) -> bool {
match self.kind { matches!(self.kind, Literal(..))
Literal(..) => true,
_ => false,
}
} }
/// Returns `true` if the token is any literal, a minus (which can prefix a literal, /// Returns `true` if the token is any literal, a minus (which can prefix a literal,

View File

@ -12,14 +12,14 @@ use crate::ast;
/// |x| 5 /// |x| 5
/// isn't parsed as (if true {...} else {...} | x) | 5 /// isn't parsed as (if true {...} else {...} | x) | 5
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
match e.kind { !matches!(
e.kind,
ast::ExprKind::If(..) ast::ExprKind::If(..)
| ast::ExprKind::Match(..) | ast::ExprKind::Match(..)
| ast::ExprKind::Block(..) | ast::ExprKind::Block(..)
| ast::ExprKind::While(..) | ast::ExprKind::While(..)
| ast::ExprKind::Loop(..) | ast::ExprKind::Loop(..)
| ast::ExprKind::ForLoop(..) | ast::ExprKind::ForLoop(..)
| ast::ExprKind::TryBlock(..) => false, | ast::ExprKind::TryBlock(..)
_ => true, )
}
} }

View File

@ -180,10 +180,8 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
} }
rustc_lexer::TokenKind::BlockComment { doc_style, .. } => { rustc_lexer::TokenKind::BlockComment { doc_style, .. } => {
if doc_style.is_none() { if doc_style.is_none() {
let code_to_the_right = match text[pos + token.len..].chars().next() { let code_to_the_right =
Some('\r' | '\n') => false, !matches!(text[pos + token.len..].chars().next(), Some('\r' | '\n'));
_ => true,
};
let style = match (code_to_the_left, code_to_the_right) { let style = match (code_to_the_left, code_to_the_right) {
(_, true) => CommentStyle::Mixed, (_, true) => CommentStyle::Mixed,
(false, false) => CommentStyle::Isolated, (false, false) => CommentStyle::Isolated,

View File

@ -38,10 +38,9 @@ pub fn expand_deriving_clone(
| ItemKind::Enum(_, Generics { ref params, .. }) => { | ItemKind::Enum(_, Generics { ref params, .. }) => {
let container_id = cx.current_expansion.id.expn_data().parent; let container_id = cx.current_expansion.id.expn_data().parent;
if cx.resolver.has_derive_copy(container_id) if cx.resolver.has_derive_copy(container_id)
&& !params.iter().any(|param| match param.kind { && !params
ast::GenericParamKind::Type { .. } => true, .iter()
_ => false, .any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
})
{ {
bounds = vec![]; bounds = vec![];
is_shallow = true; is_shallow = true;

View File

@ -404,12 +404,10 @@ impl<'a> TraitDef<'a> {
let has_no_type_params = match item.kind { let has_no_type_params = match item.kind {
ast::ItemKind::Struct(_, ref generics) ast::ItemKind::Struct(_, ref generics)
| ast::ItemKind::Enum(_, ref generics) | ast::ItemKind::Enum(_, ref generics)
| ast::ItemKind::Union(_, ref generics) => { | ast::ItemKind::Union(_, ref generics) => !generics
!generics.params.iter().any(|param| match param.kind { .params
ast::GenericParamKind::Type { .. } => true, .iter()
_ => false, .any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })),
})
}
_ => unreachable!(), _ => unreachable!(),
}; };
let container_id = cx.current_expansion.id.expn_data().parent; let container_id = cx.current_expansion.id.expn_data().parent;
@ -868,7 +866,7 @@ impl<'a> MethodDef<'a> {
Self_ if nonstatic => { Self_ if nonstatic => {
self_args.push(arg_expr); self_args.push(arg_expr);
} }
Ptr(ref ty, _) if (if let Self_ = **ty { true } else { false }) && nonstatic => { Ptr(ref ty, _) if matches!(**ty, Self_) && nonstatic => {
self_args.push(cx.expr_deref(trait_.span, arg_expr)) self_args.push(cx.expr_deref(trait_.span, arg_expr))
} }
_ => { _ => {

View File

@ -1044,10 +1044,7 @@ pub fn expand_preparsed_format_args(
let numbered_position_args = pieces.iter().any(|arg: &parse::Piece<'_>| match *arg { let numbered_position_args = pieces.iter().any(|arg: &parse::Piece<'_>| match *arg {
parse::String(_) => false, parse::String(_) => false,
parse::NextArgument(arg) => match arg.position { parse::NextArgument(arg) => matches!(arg.position, parse::Position::ArgumentIs(_)),
parse::Position::ArgumentIs(_) => true,
_ => false,
},
}); });
cx.build_index_map(); cx.build_index_map();

View File

@ -580,10 +580,7 @@ pub mod printf {
} }
fn is_flag(c: &char) -> bool { fn is_flag(c: &char) -> bool {
match c { matches!(c, '0' | '-' | '+' | ' ' | '#' | '\'')
'0' | '-' | '+' | ' ' | '#' | '\'' => true,
_ => false,
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -87,9 +87,11 @@ fn parse_inline_asm<'a>(
// parsed as `llvm_asm!(z)` with `z = "x": y` which is type ascription. // parsed as `llvm_asm!(z)` with `z = "x": y` which is type ascription.
let first_colon = tts let first_colon = tts
.trees() .trees()
.position(|tt| match tt { .position(|tt| {
tokenstream::TokenTree::Token(Token { kind: token::Colon | token::ModSep, .. }) => true, matches!(
_ => false, tt,
tokenstream::TokenTree::Token(Token { kind: token::Colon | token::ModSep, .. })
)
}) })
.unwrap_or(tts.len()); .unwrap_or(tts.len());
let mut p = cx.new_parser_from_tts(tts.trees().skip(first_colon).collect()); let mut p = cx.new_parser_from_tts(tts.trees().skip(first_colon).collect());

View File

@ -256,10 +256,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
// we're just not interested in this item. // we're just not interested in this item.
// //
// If we find one, try to locate a `#[proc_macro_derive]` attribute on it. // If we find one, try to locate a `#[proc_macro_derive]` attribute on it.
let is_fn = match item.kind { let is_fn = matches!(item.kind, ast::ItemKind::Fn(..));
ast::ItemKind::Fn(..) => true,
_ => false,
};
let mut found_attr: Option<&'a ast::Attribute> = None; let mut found_attr: Option<&'a ast::Attribute> = None;

View File

@ -112,12 +112,12 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
}; };
// Allow uses of projections that are ZSTs or from scalar fields. // Allow uses of projections that are ZSTs or from scalar fields.
let is_consume = match context { let is_consume = matches!(
context,
PlaceContext::NonMutatingUse( PlaceContext::NonMutatingUse(
NonMutatingUseContext::Copy | NonMutatingUseContext::Move, NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
) => true, )
_ => false, );
};
if is_consume { if is_consume {
let base_ty = let base_ty =
mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx()); mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx());

View File

@ -132,10 +132,7 @@ impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
[segment] [segment]
if segment if segment
.res .res
.map(|res| match res { .map(|res| matches!(res, Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _)))
Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _) => true,
_ => false,
})
.unwrap_or(false) => .unwrap_or(false) =>
{ {
self.types.push(path.span); self.types.push(path.span);

View File

@ -93,10 +93,7 @@ impl<'tcx> FreeRegionMap<'tcx> {
/// True for free regions other than `'static`. /// True for free regions other than `'static`.
pub fn is_free(&self, r: Region<'_>) -> bool { pub fn is_free(&self, r: Region<'_>) -> bool {
match *r { matches!(r, ty::ReEarlyBound(_) | ty::ReFree(_))
ty::ReEarlyBound(_) | ty::ReFree(_) => true,
_ => false,
}
} }
/// True if `r` is a free region or static of the sort that this /// True if `r` is a free region or static of the sort that this

View File

@ -393,10 +393,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
if self.expand_node(a_region, b_vid, b_data) { if self.expand_node(a_region, b_vid, b_data) {
changes.push(b_vid); changes.push(b_vid);
} }
match *b_data { !matches!(b_data, VarValue::Value(ReStatic) | VarValue::ErrorValue)
VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
_ => true,
}
}); });
} }
} }
@ -972,11 +969,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
} }
VerifyBound::IsEmpty => { VerifyBound::IsEmpty => {
if let ty::ReEmpty(_) = min { matches!(min, ty::ReEmpty(_))
true
} else {
false
}
} }
VerifyBound::AnyBound(bs) => { VerifyBound::AnyBound(bs) => {

View File

@ -42,37 +42,25 @@ trait MaybeFnLike {
impl MaybeFnLike for hir::Item<'_> { impl MaybeFnLike for hir::Item<'_> {
fn is_fn_like(&self) -> bool { fn is_fn_like(&self) -> bool {
match self.kind { matches!(self.kind, hir::ItemKind::Fn(..))
hir::ItemKind::Fn(..) => true,
_ => false,
}
} }
} }
impl MaybeFnLike for hir::ImplItem<'_> { impl MaybeFnLike for hir::ImplItem<'_> {
fn is_fn_like(&self) -> bool { fn is_fn_like(&self) -> bool {
match self.kind { matches!(self.kind, hir::ImplItemKind::Fn(..))
hir::ImplItemKind::Fn(..) => true,
_ => false,
}
} }
} }
impl MaybeFnLike for hir::TraitItem<'_> { impl MaybeFnLike for hir::TraitItem<'_> {
fn is_fn_like(&self) -> bool { fn is_fn_like(&self) -> bool {
match self.kind { matches!(self.kind, hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)))
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
_ => false,
}
} }
} }
impl MaybeFnLike for hir::Expr<'_> { impl MaybeFnLike for hir::Expr<'_> {
fn is_fn_like(&self) -> bool { fn is_fn_like(&self) -> bool {
match self.kind { matches!(self.kind, hir::ExprKind::Closure(..))
hir::ExprKind::Closure(..) => true,
_ => false,
}
} }
} }

View File

@ -118,17 +118,11 @@ impl CoverageKind {
} }
pub fn is_counter(&self) -> bool { pub fn is_counter(&self) -> bool {
match self { matches!(self, Self::Counter { .. })
Self::Counter { .. } => true,
_ => false,
}
} }
pub fn is_expression(&self) -> bool { pub fn is_expression(&self) -> bool {
match self { matches!(self, Self::Expression { .. })
Self::Expression { .. } => true,
_ => false,
}
} }
pub fn is_unreachable(&self) -> bool { pub fn is_unreachable(&self) -> bool {

View File

@ -647,14 +647,11 @@ impl<T> Trait<T> for X {
let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name); let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name);
// We don't want to suggest calling an assoc fn in a scope where that isn't feasible. // We don't want to suggest calling an assoc fn in a scope where that isn't feasible.
let callable_scope = match body_owner { let callable_scope = matches!(body_owner, Some(
Some(
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. }) hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) | hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }), | hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
) => true, ));
_ => false,
};
let impl_comparison = matches!( let impl_comparison = matches!(
cause_code, cause_code,
ObligationCauseCode::CompareImplMethodObligation { .. } ObligationCauseCode::CompareImplMethodObligation { .. }

View File

@ -40,11 +40,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr_span = expr.span; let expr_span = expr.span;
let source_info = this.source_info(expr_span); let source_info = this.source_info(expr_span);
let expr_is_block_or_scope = match expr.kind { let expr_is_block_or_scope = matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. });
ExprKind::Block { .. } => true,
ExprKind::Scope { .. } => true,
_ => false,
};
let schedule_drop = move |this: &mut Self| { let schedule_drop = move |this: &mut Self| {
if let Some(drop_scope) = scope { if let Some(drop_scope) = scope {

View File

@ -501,10 +501,9 @@ impl<'a> Parser<'a> {
pub(super) fn expr_is_valid_const_arg(&self, expr: &P<rustc_ast::Expr>) -> bool { pub(super) fn expr_is_valid_const_arg(&self, expr: &P<rustc_ast::Expr>) -> bool {
match &expr.kind { match &expr.kind {
ast::ExprKind::Block(_, _) | ast::ExprKind::Lit(_) => true, ast::ExprKind::Block(_, _) | ast::ExprKind::Lit(_) => true,
ast::ExprKind::Unary(ast::UnOp::Neg, expr) => match &expr.kind { ast::ExprKind::Unary(ast::UnOp::Neg, expr) => {
ast::ExprKind::Lit(_) => true, matches!(expr.kind, ast::ExprKind::Lit(_))
_ => false, }
},
// We can only resolve single-segment paths at the moment, because multi-segment paths // We can only resolve single-segment paths at the moment, because multi-segment paths
// require type-checking: see `visit_generic_arg` in `src/librustc_resolve/late.rs`. // require type-checking: see `visit_generic_arg` in `src/librustc_resolve/late.rs`.
ast::ExprKind::Path(None, path) ast::ExprKind::Path(None, path)

View File

@ -23,7 +23,8 @@ use rustc_span::symbol::{sym, Symbol};
// function, then we should explore its block to check for codes that // function, then we should explore its block to check for codes that
// may need to be marked as live. // may need to be marked as live.
fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
match tcx.hir().find(hir_id) { matches!(
tcx.hir().find(hir_id),
Some( Some(
Node::Item(..) Node::Item(..)
| Node::ImplItem(..) | Node::ImplItem(..)
@ -32,9 +33,8 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
| Node::Variant(..) | Node::Variant(..)
| Node::AnonConst(..) | Node::AnonConst(..)
| Node::Pat(..), | Node::Pat(..),
) => true, )
_ => false, )
}
} }
struct MarkSymbolVisitor<'tcx> { struct MarkSymbolVisitor<'tcx> {
@ -500,16 +500,16 @@ struct DeadVisitor<'tcx> {
impl DeadVisitor<'tcx> { impl DeadVisitor<'tcx> {
fn should_warn_about_item(&mut self, item: &hir::Item<'_>) -> bool { fn should_warn_about_item(&mut self, item: &hir::Item<'_>) -> bool {
let should_warn = match item.kind { let should_warn = matches!(
item.kind,
hir::ItemKind::Static(..) hir::ItemKind::Static(..)
| hir::ItemKind::Const(..) | hir::ItemKind::Const(..)
| hir::ItemKind::Fn(..) | hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..) | hir::ItemKind::TyAlias(..)
| hir::ItemKind::Enum(..) | hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..) | hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..) => true, | hir::ItemKind::Union(..)
_ => false, );
};
should_warn && !self.symbol_is_live(item.hir_id) should_warn && !self.symbol_is_live(item.hir_id)
} }

View File

@ -367,10 +367,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
} }
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
let is_shorthand = match param.pat.kind { let is_shorthand = matches!(param.pat.kind, rustc_hir::PatKind::Struct(..));
rustc_hir::PatKind::Struct(..) => true,
_ => false,
};
param.pat.each_binding(|_bm, hir_id, _x, ident| { param.pat.each_binding(|_bm, hir_id, _x, ident| {
let var = if is_shorthand { let var = if is_shorthand {
Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true }) Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })

View File

@ -1653,16 +1653,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
for missing in &self.missing_named_lifetime_spots { for missing in &self.missing_named_lifetime_spots {
match missing { match missing {
MissingLifetimeSpot::Generics(generics) => { MissingLifetimeSpot::Generics(generics) => {
let (span, sugg) = if let Some(param) = let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| {
generics.params.iter().find(|p| match p.kind { !matches!(p.kind, hir::GenericParamKind::Type {
hir::GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
.. ..
} => false, } | hir::GenericParamKind::Lifetime {
hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided, kind: hir::LifetimeParamKind::Elided,
} => false, })
_ => true,
}) { }) {
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref)) (param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
} else { } else {

View File

@ -35,10 +35,7 @@ pub enum AutoTraitResult<A> {
#[allow(dead_code)] #[allow(dead_code)]
impl<A> AutoTraitResult<A> { impl<A> AutoTraitResult<A> {
fn is_auto(&self) -> bool { fn is_auto(&self) -> bool {
match *self { matches!(self, AutoTraitResult::PositiveImpl(_) | AutoTraitResult::NegativeImpl)
AutoTraitResult::PositiveImpl(_) | AutoTraitResult::NegativeImpl => true,
_ => false,
}
} }
} }
@ -601,10 +598,7 @@ impl AutoTraitFinder<'tcx> {
} }
fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) -> bool { fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) -> bool {
match *p.ty().skip_binder().kind() { matches!(*p.ty().skip_binder().kind(), ty::Projection(proj) if proj == p.skip_binder().projection_ty)
ty::Projection(proj) if proj == p.skip_binder().projection_ty => true,
_ => false,
}
} }
fn evaluate_nested_obligations( fn evaluate_nested_obligations(

View File

@ -193,10 +193,8 @@ fn overlap_within_probe(
let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes(); let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes();
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes); debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
let involves_placeholder = match selcx.infcx().region_constraints_added_in_snapshot(snapshot) { let involves_placeholder =
Some(true) => true, matches!(selcx.infcx().region_constraints_added_in_snapshot(snapshot), Some(true));
_ => false,
};
Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder }) Some(OverlapResult { impl_header, intercrate_ambiguity_causes, involves_placeholder })
} }

View File

@ -861,10 +861,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| { let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
let arg_length = arguments.len(); let arg_length = arguments.len();
let distinct = match &other[..] { let distinct = matches!(other, &[ArgKind::Tuple(..)]);
&[ArgKind::Tuple(..)] => true,
_ => false,
};
match (arg_length, arguments.get(0)) { match (arg_length, arguments.get(0)) {
(1, Some(&ArgKind::Tuple(_, ref fields))) => { (1, Some(&ArgKind::Tuple(_, ref fields))) => {
format!("a single {}-tuple as argument", fields.len()) format!("a single {}-tuple as argument", fields.len())
@ -1201,12 +1198,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
normalized_ty, data.ty normalized_ty, data.ty
); );
let is_normalized_ty_expected = match &obligation.cause.code { let is_normalized_ty_expected = !matches!(obligation.cause.code, ObligationCauseCode::ItemObligation(_)
ObligationCauseCode::ItemObligation(_)
| ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::BindingObligation(_, _)
| ObligationCauseCode::ObjectCastObligation(_) => false, | ObligationCauseCode::ObjectCastObligation(_));
_ => true,
};
if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp( if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
is_normalized_ty_expected, is_normalized_ty_expected,

View File

@ -323,9 +323,8 @@ pub fn normalize_param_env_or_error<'tcx>(
// This works fairly well because trait matching does not actually care about param-env // This works fairly well because trait matching does not actually care about param-env
// TypeOutlives predicates - these are normally used by regionck. // TypeOutlives predicates - these are normally used by regionck.
let outlives_predicates: Vec<_> = predicates let outlives_predicates: Vec<_> = predicates
.drain_filter(|predicate| match predicate.skip_binders() { .drain_filter(|predicate| {
ty::PredicateAtom::TypeOutlives(..) => true, matches!(predicate.skip_binders(), ty::PredicateAtom::TypeOutlives(..))
_ => false,
}) })
.collect(); .collect();

View File

@ -526,17 +526,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
generics: &ty::Generics, generics: &ty::Generics,
) -> bool { ) -> bool {
let explicit = !seg.infer_args; let explicit = !seg.infer_args;
let impl_trait = let impl_trait = generics.params.iter().any(|param| {
generics.params.iter().any(|param| match param.kind { matches!(param.kind, ty::GenericParamDefKind::Type {
ty::GenericParamDefKind::Type {
synthetic: synthetic:
Some( Some(
hir::SyntheticTyParamKind::ImplTrait hir::SyntheticTyParamKind::ImplTrait
| hir::SyntheticTyParamKind::FromAttr, | hir::SyntheticTyParamKind::FromAttr,
), ),
.. ..
} => true, })
_ => false,
}); });
if explicit && impl_trait { if explicit && impl_trait {

View File

@ -543,10 +543,9 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
if let Some(ty) = prohibit_opaque.break_value() { if let Some(ty) = prohibit_opaque.break_value() {
let is_async = match item.kind { let is_async = match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => match origin { ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
hir::OpaqueTyOrigin::AsyncFn => true, matches!(origin, hir::OpaqueTyOrigin::AsyncFn)
_ => false, }
},
_ => unreachable!(), _ => unreachable!(),
}; };
@ -1321,10 +1320,7 @@ pub fn check_enum<'tcx>(
} }
if tcx.adt_def(def_id).repr.int.is_none() && tcx.features().arbitrary_enum_discriminant { if tcx.adt_def(def_id).repr.int.is_none() && tcx.features().arbitrary_enum_discriminant {
let is_unit = |var: &hir::Variant<'_>| match var.data { let is_unit = |var: &hir::Variant<'_>| matches!(var.data, hir::VariantData::Unit(..));
hir::VariantData::Unit(..) => true,
_ => false,
};
let has_disr = |var: &hir::Variant<'_>| var.disr_expr.is_some(); let has_disr = |var: &hir::Variant<'_>| var.disr_expr.is_some();
let has_non_units = vs.iter().any(|var| !is_unit(var)); let has_non_units = vs.iter().any(|var| !is_unit(var));

View File

@ -325,10 +325,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.warn_if_unreachable(arg.hir_id, arg.span, "expression"); self.warn_if_unreachable(arg.hir_id, arg.span, "expression");
} }
let is_closure = match arg.kind { let is_closure = matches!(arg.kind, ExprKind::Closure(..));
ExprKind::Closure(..) => true,
_ => false,
};
if is_closure != check_closures { if is_closure != check_closures {
continue; continue;

View File

@ -354,10 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
hir_id: hir::HirId, hir_id: hir::HirId,
) { ) {
assert!( assert!(
match fk { matches!(fk, intravisit::FnKind::Closure(..)),
intravisit::FnKind::Closure(..) => true,
_ => false,
},
"visit_fn invoked for something other than a closure" "visit_fn invoked for something other than a closure"
); );

View File

@ -156,10 +156,10 @@ crate fn placeholder_type_error(
if let Some(span) = span { if let Some(span) = span {
sugg.push((span, format!("<{}>", type_name))); sugg.push((span, format!("<{}>", type_name)));
} }
} else if let Some(arg) = generics.iter().find(|arg| match arg.name { } else if let Some(arg) = generics
hir::ParamName::Plain(Ident { name: kw::Underscore, .. }) => true, .iter()
_ => false, .find(|arg| matches!(arg.name, hir::ParamName::Plain(Ident { name: kw::Underscore, .. })))
}) { {
// Account for `_` already present in cases like `struct S<_>(_);` and suggest // Account for `_` already present in cases like `struct S<_>(_);` and suggest
// `struct S<T>(T);` instead of `struct S<_, T>(T);`. // `struct S<T>(T);` instead of `struct S<_, T>(T);`.
sugg.push((arg.span, (*type_name).to_string())); sugg.push((arg.span, (*type_name).to_string()));

View File

@ -595,10 +595,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
let upvars = self.tcx().upvars_mentioned(self.body_owner); let upvars = self.tcx().upvars_mentioned(self.body_owner);
// For purposes of this function, generator and closures are equivalent. // For purposes of this function, generator and closures are equivalent.
let body_owner_is_closure = match self.tcx().type_of(self.body_owner.to_def_id()).kind() { let body_owner_is_closure = matches!(
ty::Closure(..) | ty::Generator(..) => true, self.tcx().type_of(self.body_owner.to_def_id()).kind(),
_ => false, ty::Closure(..) | ty::Generator(..)
}; );
if let Some(min_captures) = self.mc.typeck_results.closure_min_captures.get(&closure_def_id) if let Some(min_captures) = self.mc.typeck_results.closure_min_captures.get(&closure_def_id)
{ {