Skip to content

Commit ba7b12e

Browse files
committed
Update rustc_pattern_analysis dependency
1 parent c2d2124 commit ba7b12e

File tree

4 files changed

+77
-62
lines changed

4 files changed

+77
-62
lines changed

Cargo.lock

Lines changed: 23 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ra-ap-rustc_lexer = { version = "0.35.0", default-features = false }
8383
ra-ap-rustc_parse_format = { version = "0.35.0", default-features = false }
8484
ra-ap-rustc_index = { version = "0.35.0", default-features = false }
8585
ra-ap-rustc_abi = { version = "0.35.0", default-features = false }
86-
ra-ap-rustc_pattern_analysis = { version = "0.33.0", default-features = false }
86+
ra-ap-rustc_pattern_analysis = { version = "0.36.0", default-features = false }
8787

8888
# local crates that aren't published to crates.io. These should not have versions.
8989
sourcegen = { path = "./crates/sourcegen" }

crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl ExprValidator {
207207
}
208208

209209
let report = match compute_match_usefulness(
210-
rustc_pattern_analysis::MatchCtxt { tycx: &cx },
210+
&cx,
211211
m_arms.as_slice(),
212212
scrut_ty.clone(),
213213
ValidityConstraint::ValidOnly,

crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ pub(crate) struct MatchCheckCtx<'p> {
4343
pub(crate) pattern_arena: &'p Arena<DeconstructedPat<'p>>,
4444
ty_arena: &'p Arena<Ty>,
4545
exhaustive_patterns: bool,
46+
min_exhaustive_patterns: bool,
47+
}
48+
49+
#[derive(Clone)]
50+
pub(crate) struct PatData<'p> {
51+
/// Keep db around so that we can print variant names in `Debug`.
52+
pub(crate) db: &'p dyn HirDatabase,
4653
}
4754

4855
impl<'p> MatchCheckCtx<'p> {
@@ -55,7 +62,17 @@ impl<'p> MatchCheckCtx<'p> {
5562
) -> Self {
5663
let def_map = db.crate_def_map(module.krate());
5764
let exhaustive_patterns = def_map.is_unstable_feature_enabled("exhaustive_patterns");
58-
Self { module, body, db, pattern_arena, exhaustive_patterns, ty_arena }
65+
let min_exhaustive_patterns =
66+
def_map.is_unstable_feature_enabled("min_exhaustive_patterns");
67+
Self {
68+
module,
69+
body,
70+
db,
71+
pattern_arena,
72+
exhaustive_patterns,
73+
min_exhaustive_patterns,
74+
ty_arena,
75+
}
5976
}
6077

6178
fn is_uninhabited(&self, ty: &Ty) -> bool {
@@ -238,7 +255,8 @@ impl<'p> MatchCheckCtx<'p> {
238255
fields = self.pattern_arena.alloc_extend(subpats);
239256
}
240257
}
241-
DeconstructedPat::new(ctor, fields, pat.ty.clone(), ())
258+
let data = PatData { db: self.db };
259+
DeconstructedPat::new(ctor, fields, pat.ty.clone(), data)
242260
}
243261

244262
pub(crate) fn hoist_witness_pat(&self, pat: &WitnessPat<'p>) -> Pat {
@@ -304,11 +322,14 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
304322
type VariantIdx = EnumVariantId;
305323
type StrLit = Void;
306324
type ArmData = ();
307-
type PatData = ();
325+
type PatData = PatData<'p>;
308326

309327
fn is_exhaustive_patterns_feature_on(&self) -> bool {
310328
self.exhaustive_patterns
311329
}
330+
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
331+
self.min_exhaustive_patterns
332+
}
312333

313334
fn ctor_arity(
314335
&self,
@@ -344,16 +365,16 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
344365
}
345366
}
346367

347-
fn ctor_sub_tys(
348-
&self,
349-
ctor: &rustc_pattern_analysis::constructor::Constructor<Self>,
350-
ty: &Self::Ty,
351-
) -> &[Self::Ty] {
368+
fn ctor_sub_tys<'a>(
369+
&'a self,
370+
ctor: &'a rustc_pattern_analysis::constructor::Constructor<Self>,
371+
ty: &'a Self::Ty,
372+
) -> impl Iterator<Item = Self::Ty> + ExactSizeIterator + Captures<'a> {
352373
use std::iter::once;
353374
fn alloc<'a>(cx: &'a MatchCheckCtx<'_>, iter: impl Iterator<Item = Ty>) -> &'a [Ty] {
354375
cx.ty_arena.alloc_extend(iter)
355376
}
356-
match ctor {
377+
let slice = match ctor {
357378
Struct | Variant(_) | UnionField => match ty.kind(Interner) {
358379
TyKind::Tuple(_, substs) => {
359380
let tys = substs.iter(Interner).map(|ty| ty.assert_ty_ref(Interner));
@@ -391,7 +412,8 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
391412
never!("called `Fields::wildcards` on an `Or` ctor");
392413
&[]
393414
}
394-
}
415+
};
416+
slice.into_iter().cloned()
395417
}
396418

397419
fn ctors_for_ty(
@@ -453,11 +475,27 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
453475
})
454476
}
455477

456-
fn debug_pat(
457-
_f: &mut fmt::Formatter<'_>,
458-
_pat: &rustc_pattern_analysis::pat::DeconstructedPat<'_, Self>,
478+
fn write_variant_name(
479+
f: &mut fmt::Formatter<'_>,
480+
pat: &rustc_pattern_analysis::pat::DeconstructedPat<'_, Self>,
459481
) -> fmt::Result {
460-
// FIXME: implement this, as using `unimplemented!()` causes panics in `tracing`.
482+
let variant =
483+
pat.ty().as_adt().and_then(|(adt, _)| Self::variant_id_for_adt(pat.ctor(), adt));
484+
485+
let db = pat.data().unwrap().db;
486+
if let Some(variant) = variant {
487+
match variant {
488+
VariantId::EnumVariantId(v) => {
489+
write!(f, "{}", db.enum_variant_data(v).name.display(db.upcast()))?;
490+
}
491+
VariantId::StructId(s) => {
492+
write!(f, "{}", db.struct_data(s).name.display(db.upcast()))?
493+
}
494+
VariantId::UnionId(u) => {
495+
write!(f, "{}", db.union_data(u).name.display(db.upcast()))?
496+
}
497+
}
498+
}
461499
Ok(())
462500
}
463501

0 commit comments

Comments
 (0)