Rollup merge of #76995 - LingMan:middle_matches, r=varkor
Reduce boilerplate with the matches! macro Replaces simple bool `match`es of the form match $expr { $pattern => true _ => false } and their inverse with invocations of the matches! macro. Limited to rustc_middle for now to get my feet wet.
This commit is contained in:
commit
d50349ba8d
13 changed files with 140 additions and 269 deletions
|
@ -535,15 +535,15 @@ impl<'hir> Map<'hir> {
|
||||||
Some(Node::Binding(_)) => (),
|
Some(Node::Binding(_)) => (),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
}
|
}
|
||||||
match self.find(self.get_parent_node(id)) {
|
matches!(
|
||||||
|
self.find(self.get_parent_node(id)),
|
||||||
Some(
|
Some(
|
||||||
Node::Item(_)
|
Node::Item(_)
|
||||||
| Node::TraitItem(_)
|
| Node::TraitItem(_)
|
||||||
| Node::ImplItem(_)
|
| Node::ImplItem(_)
|
||||||
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
|
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
|
||||||
) => true,
|
)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
||||||
|
@ -554,10 +554,10 @@ impl<'hir> Map<'hir> {
|
||||||
|
|
||||||
/// Whether `hir_id` corresponds to a `mod` or a crate.
|
/// Whether `hir_id` corresponds to a `mod` or a crate.
|
||||||
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
|
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
|
||||||
match self.get_entry(hir_id).node {
|
matches!(
|
||||||
Node::Item(Item { kind: ItemKind::Mod(_), .. }) | Node::Crate(..) => true,
|
self.get_entry(hir_id).node,
|
||||||
_ => false,
|
Node::Item(Item { kind: ItemKind::Mod(_), .. }) | Node::Crate(..)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
|
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
|
||||||
|
|
|
@ -486,10 +486,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
|
// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
|
||||||
// However, formatting code relies on function identity (see #58320), so we only do
|
// However, formatting code relies on function identity (see #58320), so we only do
|
||||||
// this for generic functions. Lifetime parameters are ignored.
|
// this for generic functions. Lifetime parameters are ignored.
|
||||||
let is_generic = instance.substs.into_iter().any(|kind| match kind.unpack() {
|
let is_generic = instance
|
||||||
GenericArgKind::Lifetime(_) => false,
|
.substs
|
||||||
_ => true,
|
.into_iter()
|
||||||
});
|
.any(|kind| !matches!(kind.unpack(), GenericArgKind::Lifetime(_)));
|
||||||
if is_generic {
|
if is_generic {
|
||||||
// Get a fresh ID.
|
// Get a fresh ID.
|
||||||
let mut alloc_map = self.alloc_map.lock();
|
let mut alloc_map = self.alloc_map.lock();
|
||||||
|
|
|
@ -445,19 +445,13 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||||
/// Do not call this method! Dispatch based on the type instead.
|
/// Do not call this method! Dispatch based on the type instead.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_bits(self) -> bool {
|
pub fn is_bits(self) -> bool {
|
||||||
match self {
|
matches!(self, Scalar::Raw { .. })
|
||||||
Scalar::Raw { .. } => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do not call this method! Dispatch based on the type instead.
|
/// Do not call this method! Dispatch based on the type instead.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ptr(self) -> bool {
|
pub fn is_ptr(self) -> bool {
|
||||||
match self {
|
matches!(self, Scalar::Ptr(_))
|
||||||
Scalar::Ptr(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_bool(self) -> InterpResult<'tcx, bool> {
|
pub fn to_bool(self) -> InterpResult<'tcx, bool> {
|
||||||
|
|
|
@ -971,67 +971,59 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
/// - `let x = ...`,
|
/// - `let x = ...`,
|
||||||
/// - or `match ... { C(x) => ... }`
|
/// - or `match ... { C(x) => ... }`
|
||||||
pub fn can_be_made_mutable(&self) -> bool {
|
pub fn can_be_made_mutable(&self) -> bool {
|
||||||
match self.local_info {
|
matches!(
|
||||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
|
self.local_info,
|
||||||
binding_mode: ty::BindingMode::BindByValue(_),
|
Some(box LocalInfo::User(ClearCrossCrate::Set(
|
||||||
opt_ty_info: _,
|
BindingForm::Var(VarBindingForm {
|
||||||
opt_match_place: _,
|
binding_mode: ty::BindingMode::BindByValue(_),
|
||||||
pat_span: _,
|
opt_ty_info: _,
|
||||||
})))) => true,
|
opt_match_place: _,
|
||||||
|
pat_span: _,
|
||||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(
|
})
|
||||||
ImplicitSelfKind::Imm,
|
| BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
|
||||||
)))) => true,
|
)))
|
||||||
|
)
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if local is definitely not a `ref ident` or
|
/// Returns `true` if local is definitely not a `ref ident` or
|
||||||
/// `ref mut ident` binding. (Such bindings cannot be made into
|
/// `ref mut ident` binding. (Such bindings cannot be made into
|
||||||
/// mutable bindings, but the inverse does not necessarily hold).
|
/// mutable bindings, but the inverse does not necessarily hold).
|
||||||
pub fn is_nonref_binding(&self) -> bool {
|
pub fn is_nonref_binding(&self) -> bool {
|
||||||
match self.local_info {
|
matches!(
|
||||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
|
self.local_info,
|
||||||
binding_mode: ty::BindingMode::BindByValue(_),
|
Some(box LocalInfo::User(ClearCrossCrate::Set(
|
||||||
opt_ty_info: _,
|
BindingForm::Var(VarBindingForm {
|
||||||
opt_match_place: _,
|
binding_mode: ty::BindingMode::BindByValue(_),
|
||||||
pat_span: _,
|
opt_ty_info: _,
|
||||||
})))) => true,
|
opt_match_place: _,
|
||||||
|
pat_span: _,
|
||||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(_)))) => true,
|
})
|
||||||
|
| BindingForm::ImplicitSelf(_),
|
||||||
_ => false,
|
)))
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this variable is a named variable or function
|
/// Returns `true` if this variable is a named variable or function
|
||||||
/// parameter declared by the user.
|
/// parameter declared by the user.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_user_variable(&self) -> bool {
|
pub fn is_user_variable(&self) -> bool {
|
||||||
match self.local_info {
|
matches!(self.local_info, Some(box LocalInfo::User(_)))
|
||||||
Some(box LocalInfo::User(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this is a reference to a variable bound in a `match`
|
/// Returns `true` if this is a reference to a variable bound in a `match`
|
||||||
/// expression that is used to access said variable for the guard of the
|
/// expression that is used to access said variable for the guard of the
|
||||||
/// match arm.
|
/// match arm.
|
||||||
pub fn is_ref_for_guard(&self) -> bool {
|
pub fn is_ref_for_guard(&self) -> bool {
|
||||||
match self.local_info {
|
matches!(
|
||||||
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard))) => true,
|
self.local_info,
|
||||||
_ => false,
|
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard)))
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some` if this is a reference to a static item that is used to
|
/// Returns `Some` if this is a reference to a static item that is used to
|
||||||
/// access that static
|
/// access that static
|
||||||
pub fn is_ref_to_static(&self) -> bool {
|
pub fn is_ref_to_static(&self) -> bool {
|
||||||
match self.local_info {
|
matches!(self.local_info, Some(box LocalInfo::StaticRef { .. }))
|
||||||
Some(box LocalInfo::StaticRef { .. }) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some` if this is a reference to a static item that is used to
|
/// Returns `Some` if this is a reference to a static item that is used to
|
||||||
|
@ -2164,10 +2156,7 @@ pub enum BinOp {
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
pub fn is_checkable(self) -> bool {
|
pub fn is_checkable(self) -> bool {
|
||||||
use self::BinOp::*;
|
use self::BinOp::*;
|
||||||
match self {
|
matches!(self, Add | Sub | Mul | Shl | Shr)
|
||||||
Add | Sub | Mul | Shl | Shr => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1164,82 +1164,63 @@ pub enum PlaceContext {
|
||||||
impl PlaceContext {
|
impl PlaceContext {
|
||||||
/// Returns `true` if this place context represents a drop.
|
/// Returns `true` if this place context represents a drop.
|
||||||
pub fn is_drop(&self) -> bool {
|
pub fn is_drop(&self) -> bool {
|
||||||
match *self {
|
matches!(self, PlaceContext::MutatingUse(MutatingUseContext::Drop))
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::Drop) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a borrow.
|
/// Returns `true` if this place context represents a borrow.
|
||||||
pub fn is_borrow(&self) -> bool {
|
pub fn is_borrow(&self) -> bool {
|
||||||
match *self {
|
matches!(
|
||||||
|
self,
|
||||||
PlaceContext::NonMutatingUse(
|
PlaceContext::NonMutatingUse(
|
||||||
NonMutatingUseContext::SharedBorrow
|
NonMutatingUseContext::SharedBorrow
|
||||||
| NonMutatingUseContext::ShallowBorrow
|
| NonMutatingUseContext::ShallowBorrow
|
||||||
| NonMutatingUseContext::UniqueBorrow,
|
| NonMutatingUseContext::UniqueBorrow
|
||||||
)
|
) | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
|
||||||
| PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
|
)
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a storage live or storage dead marker.
|
/// Returns `true` if this place context represents a storage live or storage dead marker.
|
||||||
pub fn is_storage_marker(&self) -> bool {
|
pub fn is_storage_marker(&self) -> bool {
|
||||||
match *self {
|
matches!(
|
||||||
PlaceContext::NonUse(NonUseContext::StorageLive | NonUseContext::StorageDead) => true,
|
self,
|
||||||
_ => false,
|
PlaceContext::NonUse(NonUseContext::StorageLive | NonUseContext::StorageDead)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a storage live marker.
|
/// Returns `true` if this place context represents a storage live marker.
|
||||||
pub fn is_storage_live_marker(&self) -> bool {
|
pub fn is_storage_live_marker(&self) -> bool {
|
||||||
match *self {
|
matches!(self, PlaceContext::NonUse(NonUseContext::StorageLive))
|
||||||
PlaceContext::NonUse(NonUseContext::StorageLive) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a storage dead marker.
|
/// Returns `true` if this place context represents a storage dead marker.
|
||||||
pub fn is_storage_dead_marker(&self) -> bool {
|
pub fn is_storage_dead_marker(&self) -> bool {
|
||||||
match *self {
|
matches!(self, PlaceContext::NonUse(NonUseContext::StorageDead))
|
||||||
PlaceContext::NonUse(NonUseContext::StorageDead) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a use that potentially changes the value.
|
/// Returns `true` if this place context represents a use that potentially changes the value.
|
||||||
pub fn is_mutating_use(&self) -> bool {
|
pub fn is_mutating_use(&self) -> bool {
|
||||||
match *self {
|
matches!(self, PlaceContext::MutatingUse(..))
|
||||||
PlaceContext::MutatingUse(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a use that does not change the value.
|
/// Returns `true` if this place context represents a use that does not change the value.
|
||||||
pub fn is_nonmutating_use(&self) -> bool {
|
pub fn is_nonmutating_use(&self) -> bool {
|
||||||
match *self {
|
matches!(self, PlaceContext::NonMutatingUse(..))
|
||||||
PlaceContext::NonMutatingUse(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a use.
|
/// Returns `true` if this place context represents a use.
|
||||||
pub fn is_use(&self) -> bool {
|
pub fn is_use(&self) -> bool {
|
||||||
match *self {
|
!matches!(self, PlaceContext::NonUse(..))
|
||||||
PlaceContext::NonUse(..) => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents an assignment statement.
|
/// Returns `true` if this place context represents an assignment statement.
|
||||||
pub fn is_place_assignment(&self) -> bool {
|
pub fn is_place_assignment(&self) -> bool {
|
||||||
match *self {
|
matches!(
|
||||||
|
self,
|
||||||
PlaceContext::MutatingUse(
|
PlaceContext::MutatingUse(
|
||||||
MutatingUseContext::Store
|
MutatingUseContext::Store
|
||||||
| MutatingUseContext::Call
|
| MutatingUseContext::Call
|
||||||
| MutatingUseContext::AsmOutput,
|
| MutatingUseContext::AsmOutput,
|
||||||
) => true,
|
)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,7 @@ pub enum Node {
|
||||||
|
|
||||||
impl<'tcx> Node {
|
impl<'tcx> Node {
|
||||||
pub fn is_from_trait(&self) -> bool {
|
pub fn is_from_trait(&self) -> bool {
|
||||||
match *self {
|
matches!(self, Node::Trait(..))
|
||||||
Node::Trait(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the items defined directly by the given (impl or trait) node.
|
/// Iterate over the items defined directly by the given (impl or trait) node.
|
||||||
|
|
|
@ -85,10 +85,7 @@ pub struct Adjustment<'tcx> {
|
||||||
|
|
||||||
impl Adjustment<'tcx> {
|
impl Adjustment<'tcx> {
|
||||||
pub fn is_region_borrow(&self) -> bool {
|
pub fn is_region_borrow(&self) -> bool {
|
||||||
match self.kind {
|
matches!(self.kind, Adjust::Borrow(AutoBorrow::Ref(..)))
|
||||||
Adjust::Borrow(AutoBorrow::Ref(..)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -588,10 +588,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.type_dependent_defs().get(expr.hir_id) {
|
matches!(self.type_dependent_defs().get(expr.hir_id), Some(Ok((DefKind::AssocFn, _))))
|
||||||
Some(Ok((DefKind::AssocFn, _))) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> {
|
pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> {
|
||||||
|
|
|
@ -11,21 +11,16 @@ use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate};
|
||||||
impl<'tcx> TyS<'tcx> {
|
impl<'tcx> TyS<'tcx> {
|
||||||
/// Similar to `TyS::is_primitive`, but also considers inferred numeric values to be primitive.
|
/// Similar to `TyS::is_primitive`, but also considers inferred numeric values to be primitive.
|
||||||
pub fn is_primitive_ty(&self) -> bool {
|
pub fn is_primitive_ty(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(
|
||||||
Bool
|
self.kind(),
|
||||||
| Char
|
Bool | Char | Str | Int(_) | Uint(_) | Float(_)
|
||||||
| Str
|
|
||||||
| Int(_)
|
|
||||||
| Uint(_)
|
|
||||||
| Float(_)
|
|
||||||
| Infer(
|
| Infer(
|
||||||
InferTy::IntVar(_)
|
InferTy::IntVar(_)
|
||||||
| InferTy::FloatVar(_)
|
| InferTy::FloatVar(_)
|
||||||
| InferTy::FreshIntTy(_)
|
| InferTy::FreshIntTy(_)
|
||||||
| InferTy::FreshFloatTy(_),
|
| InferTy::FreshFloatTy(_)
|
||||||
) => true,
|
)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the type is succinctly representable as a type instead of just referred to with a
|
/// Whether the type is succinctly representable as a type instead of just referred to with a
|
||||||
|
@ -64,11 +59,16 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
/// Whether the type can be safely suggested during error recovery.
|
/// Whether the type can be safely suggested during error recovery.
|
||||||
pub fn is_suggestable(&self) -> bool {
|
pub fn is_suggestable(&self) -> bool {
|
||||||
match self.kind() {
|
!matches!(
|
||||||
Opaque(..) | FnDef(..) | FnPtr(..) | Dynamic(..) | Closure(..) | Infer(..)
|
self.kind(),
|
||||||
| Projection(..) => false,
|
Opaque(..)
|
||||||
_ => true,
|
| FnDef(..)
|
||||||
}
|
| FnPtr(..)
|
||||||
|
| Dynamic(..)
|
||||||
|
| Closure(..)
|
||||||
|
| Infer(..)
|
||||||
|
| Projection(..)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,10 +184,10 @@ impl<'tcx> InstanceDef<'tcx> {
|
||||||
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
|
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
|
||||||
_ => return true,
|
_ => return true,
|
||||||
};
|
};
|
||||||
match tcx.def_key(def_id).disambiguated_data.data {
|
matches!(
|
||||||
DefPathData::Ctor | DefPathData::ClosureExpr => true,
|
tcx.def_key(def_id).disambiguated_data.data,
|
||||||
_ => false,
|
DefPathData::Ctor | DefPathData::ClosureExpr
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the machine code for this instance is instantiated in
|
/// Returns `true` if the machine code for this instance is instantiated in
|
||||||
|
|
|
@ -2610,10 +2610,7 @@ where
|
||||||
target.target_os == "linux" && target.arch == "sparc64" && target_env_gnu_like;
|
target.target_os == "linux" && target.arch == "sparc64" && target_env_gnu_like;
|
||||||
let linux_powerpc_gnu_like =
|
let linux_powerpc_gnu_like =
|
||||||
target.target_os == "linux" && target.arch == "powerpc" && target_env_gnu_like;
|
target.target_os == "linux" && target.arch == "powerpc" && target_env_gnu_like;
|
||||||
let rust_abi = match sig.abi {
|
let rust_abi = matches!(sig.abi, RustIntrinsic | PlatformIntrinsic | Rust | RustCall);
|
||||||
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle safe Rust thin and fat pointers.
|
// Handle safe Rust thin and fat pointers.
|
||||||
let adjust_for_rust_scalar = |attrs: &mut ArgAttributes,
|
let adjust_for_rust_scalar = |attrs: &mut ArgAttributes,
|
||||||
|
|
|
@ -2681,15 +2681,15 @@ impl<'tcx> ClosureKind {
|
||||||
/// Returns `true` if a type that impls this closure kind
|
/// Returns `true` if a type that impls this closure kind
|
||||||
/// must also implement `other`.
|
/// must also implement `other`.
|
||||||
pub fn extends(self, other: ty::ClosureKind) -> bool {
|
pub fn extends(self, other: ty::ClosureKind) -> bool {
|
||||||
match (self, other) {
|
matches!(
|
||||||
(ClosureKind::Fn, ClosureKind::Fn) => true,
|
(self, other),
|
||||||
(ClosureKind::Fn, ClosureKind::FnMut) => true,
|
(ClosureKind::Fn, ClosureKind::Fn)
|
||||||
(ClosureKind::Fn, ClosureKind::FnOnce) => true,
|
| (ClosureKind::Fn, ClosureKind::FnMut)
|
||||||
(ClosureKind::FnMut, ClosureKind::FnMut) => true,
|
| (ClosureKind::Fn, ClosureKind::FnOnce)
|
||||||
(ClosureKind::FnMut, ClosureKind::FnOnce) => true,
|
| (ClosureKind::FnMut, ClosureKind::FnMut)
|
||||||
(ClosureKind::FnOnce, ClosureKind::FnOnce) => true,
|
| (ClosureKind::FnMut, ClosureKind::FnOnce)
|
||||||
_ => false,
|
| (ClosureKind::FnOnce, ClosureKind::FnOnce)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the representative scalar type for this closure kind.
|
/// Returns the representative scalar type for this closure kind.
|
||||||
|
@ -2815,15 +2815,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> {
|
pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> {
|
||||||
let is_associated_item = if let Some(def_id) = def_id.as_local() {
|
let is_associated_item = if let Some(def_id) = def_id.as_local() {
|
||||||
match self.hir().get(self.hir().local_def_id_to_hir_id(def_id)) {
|
matches!(
|
||||||
Node::TraitItem(_) | Node::ImplItem(_) => true,
|
self.hir().get(self.hir().local_def_id_to_hir_id(def_id)),
|
||||||
_ => false,
|
Node::TraitItem(_) | Node::ImplItem(_)
|
||||||
}
|
)
|
||||||
} else {
|
} else {
|
||||||
match self.def_kind(def_id) {
|
matches!(
|
||||||
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
|
self.def_kind(def_id),
|
||||||
_ => false,
|
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy
|
||||||
}
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
is_associated_item.then(|| self.associated_item(def_id))
|
is_associated_item.then(|| self.associated_item(def_id))
|
||||||
|
|
|
@ -1763,10 +1763,7 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_never(&self) -> bool {
|
pub fn is_never(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Never)
|
||||||
Never => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether a type is definitely uninhabited. This is
|
/// Checks whether a type is definitely uninhabited. This is
|
||||||
|
@ -1823,34 +1820,22 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_adt(&self) -> bool {
|
pub fn is_adt(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Adt(..))
|
||||||
Adt(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ref(&self) -> bool {
|
pub fn is_ref(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Ref(..))
|
||||||
Ref(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ty_var(&self) -> bool {
|
pub fn is_ty_var(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Infer(TyVar(_)))
|
||||||
Infer(TyVar(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ty_infer(&self) -> bool {
|
pub fn is_ty_infer(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Infer(_))
|
||||||
Infer(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1880,20 +1865,14 @@ impl<'tcx> TyS<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_slice(&self) -> bool {
|
pub fn is_slice(&self) -> bool {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.kind() {
|
RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => matches!(ty.kind(), Slice(_) | Str),
|
||||||
Slice(_) | Str => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_array(&self) -> bool {
|
pub fn is_array(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Array(..))
|
||||||
Array(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1940,27 +1919,21 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_region_ptr(&self) -> bool {
|
pub fn is_region_ptr(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Ref(..))
|
||||||
Ref(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_mutable_ptr(&self) -> bool {
|
pub fn is_mutable_ptr(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(
|
||||||
|
self.kind(),
|
||||||
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mut, .. })
|
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mut, .. })
|
||||||
| Ref(_, _, hir::Mutability::Mut) => true,
|
| Ref(_, _, hir::Mutability::Mut)
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_unsafe_ptr(&self) -> bool {
|
pub fn is_unsafe_ptr(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), RawPtr(_))
|
||||||
RawPtr(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
|
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
|
||||||
|
@ -1990,35 +1963,22 @@ impl<'tcx> TyS<'tcx> {
|
||||||
/// contents are abstract to rustc.)
|
/// contents are abstract to rustc.)
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_scalar(&self) -> bool {
|
pub fn is_scalar(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(
|
||||||
Bool
|
self.kind(),
|
||||||
| Char
|
Bool | Char | Int(_) | Float(_) | Uint(_) | FnDef(..) | FnPtr(_) | RawPtr(_)
|
||||||
| Int(_)
|
|
||||||
| Float(_)
|
|
||||||
| Uint(_)
|
|
||||||
| Infer(IntVar(_) | FloatVar(_))
|
| Infer(IntVar(_) | FloatVar(_))
|
||||||
| FnDef(..)
|
)
|
||||||
| FnPtr(_)
|
|
||||||
| RawPtr(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this type is a floating point type.
|
/// Returns `true` if this type is a floating point type.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_floating_point(&self) -> bool {
|
pub fn is_floating_point(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Float(_) | Infer(FloatVar(_)))
|
||||||
Float(_) | Infer(FloatVar(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_trait(&self) -> bool {
|
pub fn is_trait(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Dynamic(..))
|
||||||
Dynamic(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2031,52 +1991,32 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_closure(&self) -> bool {
|
pub fn is_closure(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Closure(..))
|
||||||
Closure(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_generator(&self) -> bool {
|
pub fn is_generator(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Generator(..))
|
||||||
Generator(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_integral(&self) -> bool {
|
pub fn is_integral(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Infer(IntVar(_)) | Int(_) | Uint(_))
|
||||||
Infer(IntVar(_)) | Int(_) | Uint(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fresh_ty(&self) -> bool {
|
pub fn is_fresh_ty(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Infer(FreshTy(_)))
|
||||||
Infer(FreshTy(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fresh(&self) -> bool {
|
pub fn is_fresh(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Infer(FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_)))
|
||||||
Infer(FreshTy(_)) => true,
|
|
||||||
Infer(FreshIntTy(_)) => true,
|
|
||||||
Infer(FreshFloatTy(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_char(&self) -> bool {
|
pub fn is_char(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Char)
|
||||||
Char => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2086,34 +2026,22 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_signed(&self) -> bool {
|
pub fn is_signed(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Int(_))
|
||||||
Int(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ptr_sized_integral(&self) -> bool {
|
pub fn is_ptr_sized_integral(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize))
|
||||||
Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_machine(&self) -> bool {
|
pub fn is_machine(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Int(..) | Uint(..) | Float(..))
|
||||||
Int(..) | Uint(..) | Float(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_concrete_skeleton(&self) -> bool {
|
pub fn has_concrete_skeleton(&self) -> bool {
|
||||||
match self.kind() {
|
!matches!(self.kind(), Param(_) | Infer(_) | Error(_))
|
||||||
Param(_) | Infer(_) | Error(_) => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the type and mutability of `*ty`.
|
/// Returns the type and mutability of `*ty`.
|
||||||
|
@ -2156,26 +2084,17 @@ impl<'tcx> TyS<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fn(&self) -> bool {
|
pub fn is_fn(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), FnDef(..) | FnPtr(_))
|
||||||
FnDef(..) | FnPtr(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_fn_ptr(&self) -> bool {
|
pub fn is_fn_ptr(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), FnPtr(_))
|
||||||
FnPtr(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_impl_trait(&self) -> bool {
|
pub fn is_impl_trait(&self) -> bool {
|
||||||
match self.kind() {
|
matches!(self.kind(), Opaque(..))
|
||||||
Opaque(..) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue