Update rustc_pattern_analysis dependency

This commit is contained in:
Nadrieril 2024-02-06 05:06:23 +01:00
parent c2d21242aa
commit ba7b12e062
4 changed files with 84 additions and 69 deletions

83
Cargo.lock generated
View file

@ -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]]

View file

@ -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" }

View file

@ -207,7 +207,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,

View file

@ -43,6 +43,13 @@ pub(crate) struct MatchCheckCtx<'p> {
pub(crate) pattern_arena: &'p Arena<DeconstructedPat<'p>>, pub(crate) pattern_arena: &'p Arena<DeconstructedPat<'p>>,
ty_arena: &'p Arena<Ty>, 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> {
@ -55,7 +62,17 @@ impl<'p> MatchCheckCtx<'p> {
) -> 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,
ty_arena,
}
} }
fn is_uninhabited(&self, ty: &Ty) -> bool { fn is_uninhabited(&self, ty: &Ty) -> bool {
@ -238,7 +255,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 {
@ -304,11 +322,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,
@ -344,16 +365,16 @@ 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; use std::iter::once;
fn alloc<'a>(cx: &'a MatchCheckCtx<'_>, iter: impl Iterator<Item = Ty>) -> &'a [Ty] { fn alloc<'a>(cx: &'a MatchCheckCtx<'_>, iter: impl Iterator<Item = Ty>) -> &'a [Ty] {
cx.ty_arena.alloc_extend(iter) cx.ty_arena.alloc_extend(iter)
} }
match ctor { let slice = 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));
@ -391,7 +412,8 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
never!("called `Fields::wildcards` on an `Or` ctor"); never!("called `Fields::wildcards` on an `Or` ctor");
&[] &[]
} }
} };
slice.into_iter().cloned()
} }
fn ctors_for_ty( fn ctors_for_ty(
@ -453,11 +475,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(())
} }