Auto merge of #16499 - Nadrieril:update-pat-ana, r=lnicola
internal: Update rustc_pattern_analysis dependency Just bumping the dependency, as I've been making API changes over on the rustc side. More API changes incoming in the coming weeks. One benefit of this: we no longer abort in the `DeconstructedPat: Debug` impl, which means we can use `tracing` to investigate issues.
This commit is contained in:
commit
6671d3c9a3
83
Cargo.lock
generated
83
Cargo.lock
generated
@ -167,7 +167,7 @@ checksum = "5676cea088c32290fe65c82895be9d06dd21e0fa49bb97ca840529e9417ab71a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -313,17 +313,6 @@ dependencies = [
|
|||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "derivative"
|
|
||||||
version = "2.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_arbitrary"
|
name = "derive_arbitrary"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@ -332,7 +321,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1436,17 +1425,6 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ra-ap-rustc_index"
|
|
||||||
version = "0.33.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5e5313d7f243b63ef9e58d94355b11aa8499f1328055f1f58adf0a5ea7d2faca"
|
|
||||||
dependencies = [
|
|
||||||
"arrayvec",
|
|
||||||
"ra-ap-rustc_index_macros 0.33.0",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_index"
|
name = "ra-ap-rustc_index"
|
||||||
version = "0.35.0"
|
version = "0.35.0"
|
||||||
@ -1459,15 +1437,14 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_index_macros"
|
name = "ra-ap-rustc_index"
|
||||||
version = "0.33.0"
|
version = "0.36.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a83108ebf3e73dde205b9c25706209bcd7736480820f90ded28eabaf8b469f25"
|
checksum = "f8a41dee58608b1fc93779ea365edaa70ac9927e3335ae914b675be0fa063cd7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"arrayvec",
|
||||||
"quote",
|
"ra-ap-rustc_index_macros 0.36.0",
|
||||||
"syn 2.0.39",
|
"smallvec",
|
||||||
"synstructure",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1478,7 +1455,19 @@ checksum = "054e25eac52f0506c1309ca4317c11ad4925d7b99eb897f71aa7c3cbafb46c2b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ra-ap-rustc_index_macros"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fbfe98def54c4337a2f7d8233850bd5d5349972b185fe8a0db2b979164b30ed8"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1504,12 +1493,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_pattern_analysis"
|
name = "ra-ap-rustc_pattern_analysis"
|
||||||
version = "0.33.0"
|
version = "0.36.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6c4085e0c771fd4b883930b599ef42966b855762bbe4052c17673b3253421a6d"
|
checksum = "b5529bffec7530b4a3425640bfdfd9b95d87c4c620f740266c0de6572561aab4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derivative",
|
"ra-ap-rustc_index 0.36.0",
|
||||||
"ra-ap-rustc_index 0.33.0",
|
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -1649,7 +1637,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1736,7 +1724,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1759,7 +1747,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1836,17 +1824,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.39"
|
version = "2.0.39"
|
||||||
@ -1866,7 +1843,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1955,7 +1932,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2056,7 +2033,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.39",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -83,7 +83,7 @@ ra-ap-rustc_lexer = { version = "0.35.0", default-features = false }
|
|||||||
ra-ap-rustc_parse_format = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_parse_format = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_index = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_index = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_abi = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_abi = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_pattern_analysis = { version = "0.33.0", default-features = false }
|
ra-ap-rustc_pattern_analysis = { version = "0.36.0", default-features = false }
|
||||||
|
|
||||||
# local crates that aren't published to crates.io. These should not have versions.
|
# local crates that aren't published to crates.io. These should not have versions.
|
||||||
sourcegen = { path = "./crates/sourcegen" }
|
sourcegen = { path = "./crates/sourcegen" }
|
||||||
|
@ -153,14 +153,7 @@ impl ExprValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let pattern_arena = Arena::new();
|
let pattern_arena = Arena::new();
|
||||||
let ty_arena = Arena::new();
|
let cx = MatchCheckCtx::new(self.owner.module(db.upcast()), self.owner, db, &pattern_arena);
|
||||||
let cx = MatchCheckCtx::new(
|
|
||||||
self.owner.module(db.upcast()),
|
|
||||||
self.owner,
|
|
||||||
db,
|
|
||||||
&pattern_arena,
|
|
||||||
&ty_arena,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut m_arms = Vec::with_capacity(arms.len());
|
let mut m_arms = Vec::with_capacity(arms.len());
|
||||||
let mut has_lowering_errors = false;
|
let mut has_lowering_errors = false;
|
||||||
@ -207,7 +200,7 @@ impl ExprValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let report = match compute_match_usefulness(
|
let report = match compute_match_usefulness(
|
||||||
rustc_pattern_analysis::MatchCtxt { tycx: &cx },
|
&cx,
|
||||||
m_arms.as_slice(),
|
m_arms.as_slice(),
|
||||||
scrut_ty.clone(),
|
scrut_ty.clone(),
|
||||||
ValidityConstraint::ValidOnly,
|
ValidityConstraint::ValidOnly,
|
||||||
|
@ -9,7 +9,7 @@ use rustc_pattern_analysis::{
|
|||||||
index::IdxContainer,
|
index::IdxContainer,
|
||||||
Captures, TypeCx,
|
Captures, TypeCx,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::{smallvec, SmallVec};
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
use typed_arena::Arena;
|
use typed_arena::Arena;
|
||||||
|
|
||||||
@ -41,8 +41,14 @@ pub(crate) struct MatchCheckCtx<'p> {
|
|||||||
body: DefWithBodyId,
|
body: DefWithBodyId,
|
||||||
pub(crate) db: &'p dyn HirDatabase,
|
pub(crate) db: &'p dyn HirDatabase,
|
||||||
pub(crate) pattern_arena: &'p Arena<DeconstructedPat<'p>>,
|
pub(crate) pattern_arena: &'p Arena<DeconstructedPat<'p>>,
|
||||||
ty_arena: &'p Arena<Ty>,
|
|
||||||
exhaustive_patterns: bool,
|
exhaustive_patterns: bool,
|
||||||
|
min_exhaustive_patterns: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub(crate) struct PatData<'p> {
|
||||||
|
/// Keep db around so that we can print variant names in `Debug`.
|
||||||
|
pub(crate) db: &'p dyn HirDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'p> MatchCheckCtx<'p> {
|
impl<'p> MatchCheckCtx<'p> {
|
||||||
@ -51,11 +57,12 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
body: DefWithBodyId,
|
body: DefWithBodyId,
|
||||||
db: &'p dyn HirDatabase,
|
db: &'p dyn HirDatabase,
|
||||||
pattern_arena: &'p Arena<DeconstructedPat<'p>>,
|
pattern_arena: &'p Arena<DeconstructedPat<'p>>,
|
||||||
ty_arena: &'p Arena<Ty>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let def_map = db.crate_def_map(module.krate());
|
let def_map = db.crate_def_map(module.krate());
|
||||||
let exhaustive_patterns = def_map.is_unstable_feature_enabled("exhaustive_patterns");
|
let exhaustive_patterns = def_map.is_unstable_feature_enabled("exhaustive_patterns");
|
||||||
Self { module, body, db, pattern_arena, exhaustive_patterns, ty_arena }
|
let min_exhaustive_patterns =
|
||||||
|
def_map.is_unstable_feature_enabled("min_exhaustive_patterns");
|
||||||
|
Self { module, body, db, pattern_arena, exhaustive_patterns, min_exhaustive_patterns }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_uninhabited(&self, ty: &Ty) -> bool {
|
fn is_uninhabited(&self, ty: &Ty) -> bool {
|
||||||
@ -75,18 +82,15 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variant_id_for_adt(&self, ctor: &Constructor<Self>, adt: hir_def::AdtId) -> VariantId {
|
fn variant_id_for_adt(ctor: &Constructor<Self>, adt: hir_def::AdtId) -> Option<VariantId> {
|
||||||
match ctor {
|
match ctor {
|
||||||
&Variant(id) => id.into(),
|
&Variant(id) => Some(id.into()),
|
||||||
Struct | UnionField => {
|
Struct | UnionField => match adt {
|
||||||
assert!(!matches!(adt, hir_def::AdtId::EnumId(_)));
|
hir_def::AdtId::EnumId(_) => None,
|
||||||
match adt {
|
hir_def::AdtId::StructId(id) => Some(id.into()),
|
||||||
hir_def::AdtId::EnumId(_) => unreachable!(),
|
hir_def::AdtId::UnionId(id) => Some(id.into()),
|
||||||
hir_def::AdtId::StructId(id) => id.into(),
|
},
|
||||||
hir_def::AdtId::UnionId(id) => id.into(),
|
_ => panic!("bad constructor {ctor:?} for adt {adt:?}"),
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => panic!("bad constructor {self:?} for adt {adt:?}"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +204,7 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
Wildcard
|
Wildcard
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let variant = self.variant_id_for_adt(&ctor, adt.0);
|
let variant = Self::variant_id_for_adt(&ctor, adt.0).unwrap();
|
||||||
let fields_len = variant.variant_data(self.db.upcast()).fields().len();
|
let fields_len = variant.variant_data(self.db.upcast()).fields().len();
|
||||||
// For each field in the variant, we store the relevant index into `self.fields` if any.
|
// For each field in the variant, we store the relevant index into `self.fields` if any.
|
||||||
let mut field_id_to_id: Vec<Option<usize>> = vec![None; fields_len];
|
let mut field_id_to_id: Vec<Option<usize>> = vec![None; fields_len];
|
||||||
@ -241,7 +245,8 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
fields = self.pattern_arena.alloc_extend(subpats);
|
fields = self.pattern_arena.alloc_extend(subpats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeconstructedPat::new(ctor, fields, pat.ty.clone(), ())
|
let data = PatData { db: self.db };
|
||||||
|
DeconstructedPat::new(ctor, fields, pat.ty.clone(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn hoist_witness_pat(&self, pat: &WitnessPat<'p>) -> Pat {
|
pub(crate) fn hoist_witness_pat(&self, pat: &WitnessPat<'p>) -> Pat {
|
||||||
@ -266,7 +271,7 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
|
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
|
||||||
}
|
}
|
||||||
TyKind::Adt(adt, substs) => {
|
TyKind::Adt(adt, substs) => {
|
||||||
let variant = self.variant_id_for_adt(pat.ctor(), adt.0);
|
let variant = Self::variant_id_for_adt(pat.ctor(), adt.0).unwrap();
|
||||||
let subpatterns = self
|
let subpatterns = self
|
||||||
.list_variant_nonhidden_fields(pat.ty(), variant)
|
.list_variant_nonhidden_fields(pat.ty(), variant)
|
||||||
.zip(subpatterns)
|
.zip(subpatterns)
|
||||||
@ -307,11 +312,14 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
type VariantIdx = EnumVariantId;
|
type VariantIdx = EnumVariantId;
|
||||||
type StrLit = Void;
|
type StrLit = Void;
|
||||||
type ArmData = ();
|
type ArmData = ();
|
||||||
type PatData = ();
|
type PatData = PatData<'p>;
|
||||||
|
|
||||||
fn is_exhaustive_patterns_feature_on(&self) -> bool {
|
fn is_exhaustive_patterns_feature_on(&self) -> bool {
|
||||||
self.exhaustive_patterns
|
self.exhaustive_patterns
|
||||||
}
|
}
|
||||||
|
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
|
||||||
|
self.min_exhaustive_patterns
|
||||||
|
}
|
||||||
|
|
||||||
fn ctor_arity(
|
fn ctor_arity(
|
||||||
&self,
|
&self,
|
||||||
@ -327,7 +335,7 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
// patterns. If we're here we can assume this is a box pattern.
|
// patterns. If we're here we can assume this is a box pattern.
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
let variant = self.variant_id_for_adt(ctor, adt);
|
let variant = Self::variant_id_for_adt(ctor, adt).unwrap();
|
||||||
self.list_variant_nonhidden_fields(ty, variant).count()
|
self.list_variant_nonhidden_fields(ty, variant).count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,54 +355,51 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ctor_sub_tys(
|
fn ctor_sub_tys<'a>(
|
||||||
&self,
|
&'a self,
|
||||||
ctor: &rustc_pattern_analysis::constructor::Constructor<Self>,
|
ctor: &'a rustc_pattern_analysis::constructor::Constructor<Self>,
|
||||||
ty: &Self::Ty,
|
ty: &'a Self::Ty,
|
||||||
) -> &[Self::Ty] {
|
) -> impl Iterator<Item = Self::Ty> + ExactSizeIterator + Captures<'a> {
|
||||||
use std::iter::once;
|
let single = |ty| smallvec![ty];
|
||||||
fn alloc<'a>(cx: &'a MatchCheckCtx<'_>, iter: impl Iterator<Item = Ty>) -> &'a [Ty] {
|
let tys: SmallVec<[_; 2]> = match ctor {
|
||||||
cx.ty_arena.alloc_extend(iter)
|
|
||||||
}
|
|
||||||
match ctor {
|
|
||||||
Struct | Variant(_) | UnionField => match ty.kind(Interner) {
|
Struct | Variant(_) | UnionField => match ty.kind(Interner) {
|
||||||
TyKind::Tuple(_, substs) => {
|
TyKind::Tuple(_, substs) => {
|
||||||
let tys = substs.iter(Interner).map(|ty| ty.assert_ty_ref(Interner));
|
let tys = substs.iter(Interner).map(|ty| ty.assert_ty_ref(Interner));
|
||||||
alloc(self, tys.cloned())
|
tys.cloned().collect()
|
||||||
}
|
}
|
||||||
TyKind::Ref(.., rty) => alloc(self, once(rty.clone())),
|
TyKind::Ref(.., rty) => single(rty.clone()),
|
||||||
&TyKind::Adt(AdtId(adt), ref substs) => {
|
&TyKind::Adt(AdtId(adt), ref substs) => {
|
||||||
if is_box(self.db, adt) {
|
if is_box(self.db, adt) {
|
||||||
// The only legal patterns of type `Box` (outside `std`) are `_` and box
|
// The only legal patterns of type `Box` (outside `std`) are `_` and box
|
||||||
// patterns. If we're here we can assume this is a box pattern.
|
// patterns. If we're here we can assume this is a box pattern.
|
||||||
let subst_ty = substs.at(Interner, 0).assert_ty_ref(Interner).clone();
|
let subst_ty = substs.at(Interner, 0).assert_ty_ref(Interner).clone();
|
||||||
alloc(self, once(subst_ty))
|
single(subst_ty)
|
||||||
} else {
|
} else {
|
||||||
let variant = self.variant_id_for_adt(ctor, adt);
|
let variant = Self::variant_id_for_adt(ctor, adt).unwrap();
|
||||||
let tys = self.list_variant_nonhidden_fields(ty, variant).map(|(_, ty)| ty);
|
self.list_variant_nonhidden_fields(ty, variant).map(|(_, ty)| ty).collect()
|
||||||
alloc(self, tys)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty_kind => {
|
ty_kind => {
|
||||||
never!("Unexpected type for `{:?}` constructor: {:?}", ctor, ty_kind);
|
never!("Unexpected type for `{:?}` constructor: {:?}", ctor, ty_kind);
|
||||||
alloc(self, once(ty.clone()))
|
single(ty.clone())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ref => match ty.kind(Interner) {
|
Ref => match ty.kind(Interner) {
|
||||||
TyKind::Ref(.., rty) => alloc(self, once(rty.clone())),
|
TyKind::Ref(.., rty) => single(rty.clone()),
|
||||||
ty_kind => {
|
ty_kind => {
|
||||||
never!("Unexpected type for `{:?}` constructor: {:?}", ctor, ty_kind);
|
never!("Unexpected type for `{:?}` constructor: {:?}", ctor, ty_kind);
|
||||||
alloc(self, once(ty.clone()))
|
single(ty.clone())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Slice(_) => unreachable!("Found a `Slice` constructor in match checking"),
|
Slice(_) => unreachable!("Found a `Slice` constructor in match checking"),
|
||||||
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||||
| NonExhaustive | Hidden | Missing | Wildcard => &[],
|
| NonExhaustive | Hidden | Missing | Wildcard => smallvec![],
|
||||||
Or => {
|
Or => {
|
||||||
never!("called `Fields::wildcards` on an `Or` ctor");
|
never!("called `Fields::wildcards` on an `Or` ctor");
|
||||||
&[]
|
smallvec![]
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
tys.into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ctors_for_ty(
|
fn ctors_for_ty(
|
||||||
@ -456,11 +461,27 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_pat(
|
fn write_variant_name(
|
||||||
_f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
_pat: &rustc_pattern_analysis::pat::DeconstructedPat<'_, Self>,
|
pat: &rustc_pattern_analysis::pat::DeconstructedPat<'_, Self>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
// FIXME: implement this, as using `unimplemented!()` causes panics in `tracing`.
|
let variant =
|
||||||
|
pat.ty().as_adt().and_then(|(adt, _)| Self::variant_id_for_adt(pat.ctor(), adt));
|
||||||
|
|
||||||
|
let db = pat.data().unwrap().db;
|
||||||
|
if let Some(variant) = variant {
|
||||||
|
match variant {
|
||||||
|
VariantId::EnumVariantId(v) => {
|
||||||
|
write!(f, "{}", db.enum_variant_data(v).name.display(db.upcast()))?;
|
||||||
|
}
|
||||||
|
VariantId::StructId(s) => {
|
||||||
|
write!(f, "{}", db.struct_data(s).name.display(db.upcast()))?
|
||||||
|
}
|
||||||
|
VariantId::UnionId(u) => {
|
||||||
|
write!(f, "{}", db.union_data(u).name.display(db.upcast()))?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user